Skip to content

Commit

Permalink
Use RUNTIME_DIR and work with X11
Browse files Browse the repository at this point in the history
  • Loading branch information
bachradsusi committed Jan 25, 2024
1 parent 1a4f2c2 commit a685ed3
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions sandbox/seunshare.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ int main(int argc, char **argv) {
char *tmpdir_r = NULL; /* tmpdir created by seunshare */
char *runuserdir_s = NULL; /* /var/run/user/UID spec'd by user in argv[] */
char *runuserdir_r = NULL; /* /var/run/user/UID created by seunshare */
char *wayland_path = NULL; /* /run/user/UID/wayland-0 */

struct stat st_curhomedir;
struct stat st_homedir;
Expand Down Expand Up @@ -793,11 +792,17 @@ int main(int argc, char **argv) {

if (child == 0) {
char *display = NULL;
char *wayland_display = NULL;
char *LANG = NULL;
char *RUNTIME_DIR = NULL;
char *XDG_SESSION_TYPE = NULL;
int rc = -1;
char *resolved_path = NULL;
char *wayland_path_s = NULL; /* /tmp/.../wayland-0 */
char *wayland_path = NULL; /* /run/user/UID/wayland-0 */
char *pipewire_path_s = NULL; /* /tmp/.../wayland-0 */
char *pipewire_path = NULL; /* /run/user/UID/wayland-0 */


if (unshare(CLONE_NEWNS) < 0) {
perror(_("Failed to unshare"));
Expand Down Expand Up @@ -841,18 +846,32 @@ int main(int argc, char **argv) {
}
}

printf("XDG_SESSION_TYPE=%s, runuserdir_s=%s\n", XDG_SESSION_TYPE, runuserdir_s);
if (runuserdir_s) {
if (XDG_SESSION_TYPE && strcmp(XDG_SESSION_TYPE, "wayland") == 0) {
if ((wayland_display = getenv("WAYLAND_DISPLAY")) != NULL) {
if ((wayland_display = strdup(wayland_display)) == NULL) {
perror(_("Out of memory"));
goto childerr;
}
}

if (asprintf(&wayland_path_s, "%s/%s", runuserdir_s, wayland_display) == -1) {
perror(_("Out of memory"));
goto childerr;
}

if (runuserdir_s && XDG_SESSION_TYPE && strcmp(XDG_SESSION_TYPE, "wayland") == 0) {
asprintf(&wayland_path, "%s/%s", runuserdir_s, "wayland-0");
printf("wayland_path=%s\n", wayland_path);
system("ls /run/user/1000");
seunshare_mount_file("/run/user/1000/wayland-0", wayland_path);
asprintf(&wayland_path, "%s/%s", runuserdir_s, "pipewire-0");
printf("wayland_path=%s\n", wayland_path);
system("ls /run/user/1000");
seunshare_mount_file("/run/user/1000/pipewire-0", wayland_path);
if (asprintf(&wayland_path, "%s/%s", RUNTIME_DIR, wayland_display) == -1) {
perror(_("Out of memory"));
goto childerr;
}

if (seunshare_mount_file(wayland_path, wayland_path_s) == -1)
goto childerr;
}

asprintf(&pipewire_path_s, "%s/%s", runuserdir_s, "pipewire-0");
asprintf(&pipewire_path, "%s/pipewire-0", RUNTIME_DIR);
seunshare_mount_file(pipewire_path, pipewire_path_s);
}

/* mount homedir, runuserdir and tmpdir, in this order */
Expand All @@ -869,8 +888,8 @@ int main(int argc, char **argv) {
/* construct a new environment */

if (XDG_SESSION_TYPE && strcmp(XDG_SESSION_TYPE, "wayland") == 0) {
if ((display = getenv("WAYLAND_DISPLAY")) != NULL) {
if ((display = strdup(display)) == NULL) {
if (wayland_display == NULL && (wayland_display = getenv("WAYLAND_DISPLAY")) != NULL) {
if ((wayland_display = strdup(wayland_display)) == NULL) {
perror(_("Out of memory"));
goto childerr;
}
Expand All @@ -886,15 +905,6 @@ int main(int argc, char **argv) {
}
}

#if 0
if ((display = getenv("WAYLAND_DISPLAY")) != NULL) {
if ((display = strdup(display)) == NULL) {
perror(_("Out of memory"));
goto childerr;
}
}
#endif

/* construct a new environment */
if ((LANG = getenv("LANG")) != NULL) {
if ((LANG = strdup(LANG)) == NULL) {
Expand All @@ -908,11 +918,12 @@ int main(int argc, char **argv) {
goto childerr;
}
if (display) {
if (XDG_SESSION_TYPE && strcmp(XDG_SESSION_TYPE, "wayland") == 0)
rc |= setenv("WAYLAND_DISPLAY", display, 1);
else
rc |= setenv("DISPLAY", display, 1);
rc |= setenv("DISPLAY", display, 1);
}
if (wayland_display) {
rc |= setenv("WAYLAND_DISPLAY", wayland_display, 1);
}

if (XDG_SESSION_TYPE)
rc |= setenv("XDG_SESSION_TYPE", XDG_SESSION_TYPE, 1);

Expand Down Expand Up @@ -953,7 +964,12 @@ int main(int argc, char **argv) {
fprintf(stderr, _("Failed to execute command %s: %s\n"), argv[optind], strerror(errno));
childerr:
free(resolved_path);
free(wayland_path);
free(wayland_path_s);
free(pipewire_path);
free(pipewire_path_s);
free(display);
free(wayland_display);
free(LANG);
free(RUNTIME_DIR);
exit(-1);
Expand Down

0 comments on commit a685ed3

Please sign in to comment.