From 8d688c93a1b2d8a7b4069cebc46efa129ae4c1cc Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Mon, 3 Aug 2015 13:18:05 +0200 Subject: [PATCH] daemon: also wait for the end of the session process --- src/daemon/entrance_session.c | 12 ++++++++++++ src/daemon/entrance_wait.c | 25 ++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/daemon/entrance_session.c b/src/daemon/entrance_session.c index 3a9727f..159d9ef 100644 --- a/src/daemon/entrance_session.c +++ b/src/daemon/entrance_session.c @@ -188,6 +188,14 @@ _entrance_session_run(struct passwd *pwd, const char *cmd, const char *cookie) execle(pwd->pw_shell, pwd->pw_shell, "--login", "-c", buf, NULL, env); PT("The Xsessions are not launched :("); } + else if (pid > 0) + { + entrance_session_pid_set(pid); + } + else + { + ERR("Failed to start session"); + } } void @@ -217,8 +225,12 @@ entrance_session_close(const Eina_Bool opened) void entrance_session_pid_set(pid_t pid) { + char buf[PATH_MAX]; + PT("%s: session pid %d", PACKAGE, pid); _session_pid = pid; + snprintf(buf, sizeof(buf), "%d", pid); + setenv("ENTRANCE_SPID", buf, 1); } pid_t diff --git a/src/daemon/entrance_wait.c b/src/daemon/entrance_wait.c index 2a3f0f5..b34e913 100644 --- a/src/daemon/entrance_wait.c +++ b/src/daemon/entrance_wait.c @@ -33,11 +33,15 @@ main (int argc __UNUSED__, char **argv __UNUSED__) { int status = 0; char *pid; + char *sid; struct sigaction action; - pid_t rpid; + pid_t rpid, spid; pid = getenv("ENTRANCE_XPID"); + sid = getenv("ENTRANCE_SPID"); if (!pid) return -1; + if (!sid) return -1; + spid = atoi(sid); _x_pid = atoi(pid); printf("waiting\n"); @@ -53,20 +57,23 @@ main (int argc __UNUSED__, char **argv __UNUSED__) sigaction(SIGPIPE, &action, NULL); sigaction(SIGALRM, &action, NULL); - while ((rpid = wait(&status)) != _x_pid) + while ((rpid = wait(&status))) { if (rpid == -1) { if ((errno == ECHILD) || (errno == EINVAL)) - break; + return -1; + } + else if (rpid == _x_pid || rpid == spid) + { + break; } } - if (_x_pid == rpid) - { - if (WIFEXITED(status) && WEXITSTATUS(status)) - setenv("ENTRANCE_QUIT", "1", 1); - execlp(PACKAGE_SBIN_DIR"/entrance", PACKAGE_SBIN_DIR"/entrance", "--nodaemon", NULL); - } + + if (WIFEXITED(status) && WEXITSTATUS(status)) + setenv("ENTRANCE_QUIT", "1", 1); + execlp(PACKAGE_SBIN_DIR"/entrance", PACKAGE_SBIN_DIR"/entrance", "--nodaemon", NULL); + return -1; }