summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/server.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-05-03 16:06:33 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-05-03 16:06:33 +0000
commit72a6f023642c24ed068b6564472df9d7ccec30cf (patch)
tree3dd1b2f8b660cfe7c21ab37745c45e4aceb91e44 /usr.bin/tmux/server.c
parentb216f11b658d51a71040b8ed7718b8f019686022 (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/server.c')
-rw-r--r--usr.bin/tmux/server.c70
1 files changed, 8 insertions, 62 deletions
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 470d5703f87..ba059815660 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.85 2010/04/06 21:35:44 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.86 2010/05/03 16:06:32 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -49,9 +49,6 @@ struct clients dead_clients;
int server_fd;
int server_shutdown;
struct event server_ev_accept;
-struct event server_ev_sigterm;
-struct event server_ev_sigusr1;
-struct event server_ev_sigchld;
struct event server_ev_second;
int server_create_socket(void);
@@ -134,6 +131,12 @@ server_start(char *path)
}
close(pair[0]);
+ /* event_init() was called by the parent, need to reinit. */
+ if (event_reinit(ev_base) != 0)
+ fatal("event_reinit failed");
+
+ clear_signals();
+
/*
* Must daemonise before loading configuration as the PID changes so
* $TMUX would be wrong for sessions created in the config file.
@@ -162,8 +165,6 @@ server_start(char *path)
log_debug("socket path %s", socket_path);
setproctitle("server (%s)", rpathbuf);
- event_init();
-
server_fd = server_create_socket();
server_client_create(pair[1]);
@@ -202,7 +203,7 @@ server_start(char *path)
evtimer_set(&server_ev_second, server_second_callback, NULL);
evtimer_add(&server_ev_second, &tv);
- server_signal_set();
+ set_signals(server_signal_callback);
server_loop();
exit(0);
}
@@ -341,61 +342,6 @@ server_accept_callback(int fd, short events, unused void *data)
server_client_create(newfd);
}
-/* Set up server signal handling. */
-void
-server_signal_set(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(SIGUSR2, &sigact, NULL) != 0)
- fatal("sigaction failed");
- if (sigaction(SIGTSTP, &sigact, NULL) != 0)
- fatal("sigaction failed");
- if (sigaction(SIGHUP, &sigact, NULL) != 0)
- fatal("sigaction failed");
-
- signal_set(&server_ev_sigchld, SIGCHLD, server_signal_callback, NULL);
- signal_add(&server_ev_sigchld, NULL);
- signal_set(&server_ev_sigterm, SIGTERM, server_signal_callback, NULL);
- signal_add(&server_ev_sigterm, NULL);
- signal_set(&server_ev_sigusr1, SIGUSR1, server_signal_callback, NULL);
- signal_add(&server_ev_sigusr1, NULL);
-}
-
-/* Destroy server signal events. */
-void
-server_signal_clear(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(SIGUSR2, &sigact, NULL) != 0)
- fatal("sigaction failed");
- if (sigaction(SIGTSTP, &sigact, NULL) != 0)
- fatal("sigaction failed");
- if (sigaction(SIGHUP, &sigact, NULL) != 0)
- fatal("sigaction failed");
-
- signal_del(&server_ev_sigchld);
- signal_del(&server_ev_sigterm);
- signal_del(&server_ev_sigusr1);
-}
-
/* Signal handler. */
/* ARGSUSED */
void