You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.7 KiB

#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#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
_entrance_wait_action(int sig, siginfo_t * si __UNUSED__, void *data __UNUSED__)
{
kill_wait();
setenv("ENTRANCE_QUIT", "1", 1);
}
static void
9 years ago
kill_wait(void)
{
kill(_x_pid, SIGTERM);
}
int
main (int argc __UNUSED__, char **argv __UNUSED__)
{
int status = 0;
char *pid;
char *sid;
struct sigaction action;
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");
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);
while ((rpid = wait(&status)))
{
if (rpid == -1)
{
if ((errno == ECHILD) || (errno == EINVAL))
return -1;
}
else if (rpid == _x_pid)
{
break;
}
else if (rpid == spid)
{
kill_wait();
}
}
if (WIFEXITED(status) && WEXITSTATUS(status))
setenv("ENTRANCE_QUIT", "1", 1);
execlp(PACKAGE_SBIN_DIR"/entrance", PACKAGE_SBIN_DIR"/entrance", "--nodaemon", NULL);
return -1;
}