added wmii_signal handler, changed spawn to single-fork, because wmii_signal handles SIGCHLD, thus zombies should not occur

This commit is contained in:
Anselm R. Garbe 2006-02-08 10:50:09 +01:00
parent 7726569e92
commit 5ec38ca782
9 changed files with 82 additions and 12 deletions

View File

@ -826,7 +826,7 @@ xwrite(IXPConn *c, Fcall *fcall)
switch(m->qid.dtype) {
case Droot:
if(!strncmp(buf, "quit", 5))
srv.running = 0;
quit();
else if(!strncmp(buf, "pager", 6))
pager();
else if(!strncmp(buf, "detached", 9))

View File

@ -30,6 +30,12 @@ usage()
exit(1);
}
void
quit()
{
srv.running = 0;
}
static void
scale_rect(XRectangle * from_dim, XRectangle * to_dim,
XRectangle * src, XRectangle * tgt)
@ -572,6 +578,8 @@ ungrab_window(Window w, unsigned long mod, unsigned int button)
}
}
int
main(int argc, char *argv[])
{
@ -639,6 +647,8 @@ main(int argc, char *argv[])
exit(1);
}
wmii_signal(quit);
/* IXP server */
ixp_server_open_conn(&srv, i, new_ixp_conn, ixp_server_close_conn);
root_qid.type = IXP_QTDIR;

View File

@ -230,4 +230,5 @@ void pager();
void detached_clients();
void attach_detached_client();
void select_page(char *arg);
void quit();

View File

@ -89,6 +89,12 @@ dummy_error_handler(Display * dpy, XErrorEvent * err)
return 0;
}
static void
quit()
{
srv.running = 0;
}
static Item *
new_item()
{
@ -659,7 +665,7 @@ xwrite(IXPConn *c, Fcall *fcall)
memcpy(buf, fcall->data, 4);
buf[4] = 0;
if(!strncmp(buf, "quit", 5)) {
srv.running = 0;
quit();
break;
}
}
@ -842,6 +848,8 @@ main(int argc, char *argv[])
exit(1);
}
wmii_signal(quit);
/* IXP server */
ixp_server_open_conn(&srv, i, new_ixp_conn, ixp_server_close_conn);
root_qid.type = IXP_QTDIR;

View File

@ -78,6 +78,12 @@ usage()
exit(1);
}
static void
quit()
{
srv.running = 0;
}
/* X stuff */
static void
@ -864,6 +870,8 @@ main(int argc, char *argv[])
exit(1);
}
wmii_signal(quit);
/* IXP server */
ixp_server_open_conn(&srv, i, new_ixp_conn, ixp_server_close_conn);
root_qid.type = IXP_QTDIR;

View File

@ -6,7 +6,7 @@ include ../config.mk
CFLAGS += -I../liblitz -I../libixp -I../libcext
LDFLAGS += -L../liblitz -llitz -L../libixp -lixp -L../libcext -lcext
SRC = ixp.c spawn.c wm.c
SRC = ixp.c signal.c spawn.c wm.c
OBJ = ${SRC:.c=.o}

40
libwmii/signal.c Normal file
View File

@ -0,0 +1,40 @@
/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "wmii.h"
static void (*sigchld)() = 0;
static void
sig_handler(int signal)
{
switch (signal)
{
case SIGINT:
case SIGTERM:
case SIGHUP:
if(sigchld)
sigchld();
break;
case SIGCHLD:
wait(0);
break;
}
}
void
wmii_signal(void (*sigchld_handler)())
{
sigchld = sigchld_handler;
signal(SIGTERM, sig_handler);
signal(SIGINT, sig_handler);
signal(SIGHUP, sig_handler);
signal(SIGCHLD, sig_handler);
}

View File

@ -15,18 +15,18 @@
void
wmii_spawn(void *dpy, char *cmd)
{
if(!cmd)
return;
/* the questionable double-fork is done to catch all zombies */
if(fork() == 0) {
if(fork() == 0) {
pid_t pid = fork();
switch (pid)
{
case 0:
setsid();
close(ConnectionNumber(dpy));
execlp("rc", "rc", "-c", cmd, (char *) 0);
exit(1);
perror("failed");
exit(1);
}
exit(0);
}
wait(0);
case -1:
perror("can't fork");
}
}

View File

@ -19,6 +19,9 @@ char *wmii_ixp_version(IXPConn *c, Fcall *fcall);
char *wmii_ixp_attach(IXPConn *c, Fcall *fcall);
char *wmii_ixp_clunk(IXPConn *c, Fcall *fcall);
/* signal.c */
void wmii_signal(void (*sigchld_handler)());
/* spawn.c */
void wmii_spawn(void *dpy, char *cmd);