mirror of
https://github.com/troglobit/finit.git
synced 2026-10-29 12:40:44 +00:00
Use smurfy's /dev/initctl handler
If we handle it using pselect() in the parent process we'll end up with a lot of zombie processes because SIGCHLD is not handled correctly. Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
1 parent
33469873a5
commit
4e8be438e9
1 file changed
+42
-38
+42
-38
@@ -139,6 +139,43 @@ static void build_cmd(char *cmd, char *x, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef LISTEN_INITCTL
|
||||||
|
static void listen_initctl()
|
||||||
|
{
|
||||||
|
if (!fork()) {
|
||||||
|
int ctl;
|
||||||
|
fd_set fds;
|
||||||
|
struct init_request request;
|
||||||
|
|
||||||
|
mkfifo("/dev/initctl", 0600);
|
||||||
|
ctl = open("/dev/initctl", O_RDONLY);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
FD_ZERO(&fds);
|
||||||
|
FD_SET(ctl, &fds);
|
||||||
|
if (select(ctl + 1, &fds, NULL, NULL, NULL) <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
read(ctl, &request, sizeof(request));
|
||||||
|
|
||||||
|
if (request.magic != INIT_MAGIC)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (request.cmd == INIT_CMD_RUNLVL) {
|
||||||
|
switch (request.runlevel) {
|
||||||
|
case '0':
|
||||||
|
raise(SIGUSR2);
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
raise(SIGUSR1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -152,11 +189,6 @@ int main()
|
|||||||
char username[USERNAME_SIZE] = DEFUSER;
|
char username[USERNAME_SIZE] = DEFUSER;
|
||||||
char hostname[HOSTNAME_SIZE] = "eviltwin";
|
char hostname[HOSTNAME_SIZE] = "eviltwin";
|
||||||
char cmd[CMD_SIZE];
|
char cmd[CMD_SIZE];
|
||||||
#ifdef LISTEN_INITCTL
|
|
||||||
fd_set rfds;
|
|
||||||
int ctl;
|
|
||||||
struct init_request req;
|
|
||||||
#endif
|
|
||||||
#ifdef RUNLEVEL
|
#ifdef RUNLEVEL
|
||||||
struct utmp entry;
|
struct utmp entry;
|
||||||
#endif
|
#endif
|
||||||
@@ -424,6 +456,10 @@ int main()
|
|||||||
|
|
||||||
touch("/tmp/nologin");
|
touch("/tmp/nologin");
|
||||||
|
|
||||||
|
#ifdef LISTEN_INITCTL
|
||||||
|
listen_initctl();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef AGPDRV
|
#ifdef AGPDRV
|
||||||
system("/sbin/modprobe agpgart");
|
system("/sbin/modprobe agpgart");
|
||||||
system("/sbin/modprobe " AGPDRV);
|
system("/sbin/modprobe " AGPDRV);
|
||||||
@@ -449,45 +485,13 @@ int main()
|
|||||||
|
|
||||||
/* parent process */
|
/* parent process */
|
||||||
|
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
system("/usr/sbin/services.sh &>/dev/null&");
|
system("/usr/sbin/services.sh &>/dev/null&");
|
||||||
|
|
||||||
#ifdef LISTEN_INITCTL
|
|
||||||
mkfifo("/dev/initctl", 0600);
|
|
||||||
ctl = open("/dev/initctl", O_RDONLY);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sigemptyset(&nmask);
|
sigemptyset(&nmask);
|
||||||
#ifdef LISTEN_INITCTL
|
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(ctl, &rfds);
|
|
||||||
|
|
||||||
if (ctl < 0) {
|
|
||||||
pselect(0, NULL, NULL, NULL, NULL, &nmask);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pselect(ctl + 1, &rfds, NULL, NULL, NULL, &nmask) <= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
read(ctl, &req, sizeof (req));
|
|
||||||
|
|
||||||
if (req.magic == INIT_MAGIC) {
|
|
||||||
switch (req.cmd) {
|
|
||||||
case INIT_CMD_RUNLVL:
|
|
||||||
switch (req.runlevel) {
|
|
||||||
case '0':
|
|
||||||
raise(SIGUSR2);
|
|
||||||
break;
|
|
||||||
case '6':
|
|
||||||
raise(SIGUSR1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
pselect(0, NULL, NULL, NULL, NULL, &nmask);
|
pselect(0, NULL, NULL, NULL, NULL, &nmask);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user