diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-05-03 16:06:33 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-05-03 16:06:33 +0000 |
commit | 72a6f023642c24ed068b6564472df9d7ccec30cf (patch) | |
tree | 3dd1b2f8b660cfe7c21ab37745c45e4aceb91e44 /usr.bin/tmux/tmux.c | |
parent | b216f11b658d51a71040b8ed7718b8f019686022 (diff) |
Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.
Diffstat (limited to 'usr.bin/tmux/tmux.c')
-rw-r--r-- | usr.bin/tmux/tmux.c | 81 |
1 files changed, 17 insertions, 64 deletions
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 1af7849c447..13d7889849b 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.75 2010/04/28 18:22:32 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.76 2010/05/03 16:06:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -18,6 +18,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/wait.h> #include <errno.h> #include <event.h> @@ -41,6 +42,8 @@ struct options global_s_options; /* session options */ struct options global_w_options; /* window options */ struct environ global_environ; +struct event_base *ev_base; + int debug_level; time_t start_time; char *socket_path; @@ -58,11 +61,8 @@ char *makesockpath(const char *); __dead void shell_exec(const char *, const char *); struct imsgbuf *main_ibuf; -struct event main_ev_sigterm; int main_exitval; -void main_set_signals(void); -void main_clear_signals(void); void main_signal(int, short, unused void *); void main_callback(int, short, void *); void main_dispatch(const char *); @@ -238,7 +238,6 @@ main(int argc, char **argv) struct keylist *keylist; struct env_data envdata; struct msg_command_data cmddata; - struct sigaction sigact; char *s, *shellcmd, *path, *label, *home, *cause; char cwd[MAXPATHLEN], **var; void *buf; @@ -538,23 +537,21 @@ main(int argc, char **argv) exit(1); } - /* Catch SIGCHLD to avoid a zombie when starting the server. */ - memset(&sigact, 0, sizeof sigact); - sigemptyset(&sigact.sa_mask); - sigact.sa_handler = SIG_IGN; - if (sigaction(SIGCHLD, &sigact, NULL) != 0) - fatal("sigaction failed"); - /* Initialise the client socket/start the server. */ if ((main_ibuf = client_init(path, cmdflags, flags)) == NULL) exit(1); xfree(path); - event_init(); + ev_base = event_init(); - imsg_compose(main_ibuf, msg, PROTOCOL_VERSION, -1, -1, buf, len); + set_signals(main_signal); - main_set_signals(); + /* Initialise the client socket/start the server. */ + if ((main_ibuf = client_init(path, cmdflags, flags)) == NULL) + exit(1); + xfree(path); + + imsg_compose(main_ibuf, msg, PROTOCOL_VERSION, -1, -1, buf, len); events = EV_READ; if (main_ibuf->w.queued > 0) @@ -564,58 +561,11 @@ main(int argc, char **argv) main_exitval = 0; event_dispatch(); - main_clear_signals(); + clear_signals(); client_main(); /* doesn't return */ } -void -main_set_signals(void) -{ - struct sigaction sigact; - - memset(&sigact, 0, sizeof sigact); - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_RESTART; - sigact.sa_handler = SIG_IGN; - if (sigaction(SIGINT, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGPIPE, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGUSR1, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGUSR2, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGTSTP, &sigact, NULL) != 0) - fatal("sigaction failed"); - - signal_set(&main_ev_sigterm, SIGTERM, main_signal, NULL); - signal_add(&main_ev_sigterm, NULL); -} - -void -main_clear_signals(void) -{ - struct sigaction sigact; - - memset(&sigact, 0, sizeof sigact); - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_RESTART; - sigact.sa_handler = SIG_DFL; - if (sigaction(SIGINT, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGPIPE, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGUSR1, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGUSR2, &sigact, NULL) != 0) - fatal("sigaction failed"); - if (sigaction(SIGTSTP, &sigact, NULL) != 0) - fatal("sigaction failed"); - - event_del(&main_ev_sigterm); -} - /* ARGSUSED */ void main_signal(int sig, unused short events, unused void *data) @@ -623,6 +573,9 @@ main_signal(int sig, unused short events, unused void *data) switch (sig) { case SIGTERM: exit(1); + case SIGCHLD: + waitpid(WAIT_ANY, NULL, WNOHANG); + break; } } @@ -701,7 +654,7 @@ main_dispatch(const char *shellcmd) memcpy(&shelldata, imsg.data, sizeof shelldata); shelldata.shell[(sizeof shelldata.shell) - 1] = '\0'; - main_clear_signals(); + clear_signals(); shell_exec(shelldata.shell, shellcmd); default: |