daemon: also wait for the end of the session process

This commit is contained in:
Marcel Hollerbach 2015-08-03 13:18:05 +02:00
parent 2023bae199
commit 8d688c93a1
2 changed files with 28 additions and 9 deletions

View File

@ -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

View File

@ -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;
}