2012-08-09 13:15:30 -07:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2014-10-02 15:57:38 -07:00
|
|
|
#include <stdio.h>
|
2012-08-09 13:15:30 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void _entrance_wait_action(int sig, siginfo_t *si, void *data);
|
|
|
|
static void kill_wait();
|
|
|
|
|
|
|
|
|
|
|
|
static pid_t _x_pid = 0;
|
|
|
|
|
|
|
|
static void
|
2015-08-03 05:39:31 -07:00
|
|
|
_entrance_wait_action(int sig __UNUSED__, siginfo_t * si __UNUSED__, void *data __UNUSED__)
|
2012-08-09 13:15:30 -07:00
|
|
|
{
|
|
|
|
kill_wait();
|
2015-08-03 04:22:05 -07:00
|
|
|
setenv("ENTRANCE_QUIT", "1", 1);
|
2012-08-09 13:15:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-08 15:04:44 -08:00
|
|
|
kill_wait(void)
|
2012-08-09 13:15:30 -07:00
|
|
|
{
|
|
|
|
kill(_x_pid, SIGTERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc __UNUSED__, char **argv __UNUSED__)
|
|
|
|
{
|
|
|
|
int status = 0;
|
2014-02-06 02:30:27 -08:00
|
|
|
char *pid;
|
2015-08-03 04:18:05 -07:00
|
|
|
char *sid;
|
2012-08-09 13:15:30 -07:00
|
|
|
struct sigaction action;
|
|
|
|
|
2015-08-03 04:18:05 -07:00
|
|
|
pid_t rpid, spid;
|
2012-08-09 13:15:30 -07:00
|
|
|
pid = getenv("ENTRANCE_XPID");
|
2015-08-03 04:18:05 -07:00
|
|
|
sid = getenv("ENTRANCE_SPID");
|
2012-08-09 13:15:30 -07:00
|
|
|
if (!pid) return -1;
|
2015-08-03 04:18:05 -07:00
|
|
|
if (!sid) return -1;
|
|
|
|
spid = atoi(sid);
|
2012-08-09 13:15:30 -07:00
|
|
|
_x_pid = atoi(pid);
|
2014-10-02 15:57:38 -07:00
|
|
|
printf("waiting\n");
|
2012-08-09 13:15:30 -07:00
|
|
|
|
|
|
|
action.sa_sigaction = _entrance_wait_action;
|
|
|
|
action.sa_flags = SA_RESTART | SA_SIGINFO;
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
sigaction(SIGQUIT, &action, NULL);
|
|
|
|
sigaction(SIGTERM, &action, NULL);
|
|
|
|
sigaction(SIGKILL, &action, NULL);
|
|
|
|
sigaction(SIGINT, &action, NULL);
|
|
|
|
sigaction(SIGHUP, &action, NULL);
|
|
|
|
sigaction(SIGPIPE, &action, NULL);
|
|
|
|
sigaction(SIGALRM, &action, NULL);
|
|
|
|
|
2015-08-03 04:18:05 -07:00
|
|
|
while ((rpid = wait(&status)))
|
2012-08-09 13:15:30 -07:00
|
|
|
{
|
|
|
|
if (rpid == -1)
|
|
|
|
{
|
|
|
|
if ((errno == ECHILD) || (errno == EINVAL))
|
2015-08-03 04:18:05 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2015-08-03 05:02:54 -07:00
|
|
|
else if (rpid == _x_pid)
|
2015-08-03 04:18:05 -07:00
|
|
|
{
|
2015-08-03 05:02:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (rpid == spid)
|
|
|
|
{
|
|
|
|
kill_wait();
|
2012-08-09 13:15:30 -07:00
|
|
|
}
|
|
|
|
}
|
2015-08-03 04:18:05 -07:00
|
|
|
|
|
|
|
if (WIFEXITED(status) && WEXITSTATUS(status))
|
|
|
|
setenv("ENTRANCE_QUIT", "1", 1);
|
|
|
|
execlp(PACKAGE_SBIN_DIR"/entrance", PACKAGE_SBIN_DIR"/entrance", "--nodaemon", NULL);
|
|
|
|
|
2012-08-09 13:15:30 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|