Skip to content

Commit

Permalink
Use just X server display number in shm.id filename, instead of full …
Browse files Browse the repository at this point in the history
…$DISPLAY

Full $DISPLAY is ambiguous - for example :0 and :0.0 means the same. And
indeed X server cmdline contains ":0", while $DISPLAY - ":0.0". So, get
only display number to get the same value regardless of the format. This
also get rid of ":" from the filename for aesthetic reasons.

Fixes "Use shm.id.$DISPLAY to allow more than single X server"
  • Loading branch information
marmarek committed Jan 18, 2017
1 parent f7caa24 commit 291eb80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gui-daemon/xside.c
Original file line number Diff line number Diff line change
Expand Up @@ -3195,6 +3195,7 @@ int main(int argc, char **argv)
char cmd_tmp[256];
struct stat stat_buf;
char *display_str;
int display_num;

load_default_config_values(&ghandles);
/* get the VM name to read the right section in config file */
Expand Down Expand Up @@ -3230,8 +3231,13 @@ int main(int argc, char **argv)
fprintf(stderr, "No DISPLAY in environment\n");
exit(1);
}
if (sscanf(display_str, ":%d.%*d", &display_num) != 1 &&
sscanf(display_str, ":%d", &display_num) != 1) {
fprintf(stderr, "DISPLAY parse error, expected format like :0 or :0.0\n");
exit(1);
}
snprintf(shmid_filename, SHMID_FILENAME_LEN,
SHMID_FILENAME_PREFIX "%s", display_str);
SHMID_FILENAME_PREFIX "%d", display_num);
f = fopen(shmid_filename, "r");
if (!f) {
fprintf(stderr,
Expand Down
5 changes: 5 additions & 0 deletions shmoverride/shmoverride.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ void get_display()
fprintf(stderr, "cmdline DISPLAY parsing failed\n");
exit(1);
}

/* post-processing: drop leading ':' */
res = strlen(display_str);
for (in_arg = 0; in_arg < res; in_arg++)
display_str[in_arg] = display_str[in_arg+1];
}

int __attribute__ ((constructor)) initfunc()
Expand Down

0 comments on commit 291eb80

Please sign in to comment.