summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-09-23 08:21:58 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-09-23 08:21:58 +0000
commit912d1c2733ea9814250621b8ef0192d17275b7f4 (patch)
tree7b7cd49f69f05af557e00870552cb32b16a8adc3 /usr.bin/tmux
parent3c4316fd36273c63968f470148fcf4d5a1f5d0eb (diff)
On SIGTERM, just abandon any suspended/locked clients and leave them to it,
otherwise the server will hang around (refusing new connections) until they exit properly.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/server.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 51d12c98fee..6fbd75cb642 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.41 2009/09/23 06:18:47 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.42 2009/09/23 08:21:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -49,6 +49,7 @@ void server_create_client(int);
int server_create_socket(void);
int server_main(int);
void server_shutdown(void);
+int server_should_shutdown(void);
void server_child_signal(void);
void server_fill_windows(struct pollfd **);
void server_handle_windows(struct pollfd **);
@@ -244,7 +245,7 @@ server_main(int srv_fd)
struct window *w;
struct pollfd *pfds, *pfd;
int nfds, xtimeout;
- u_int i, n;
+ u_int i;
time_t now, last;
siginit();
@@ -258,6 +259,10 @@ server_main(int srv_fd)
if (sigterm)
server_shutdown();
+ /* Stop if no sessions or clients left. */
+ if (server_should_shutdown())
+ break;
+
/* Handle child exit. */
if (sigchld) {
server_child_signal();
@@ -337,22 +342,6 @@ server_main(int srv_fd)
/* Collect dead clients and sessions. */
server_clean_dead();
-
- /*
- * If we have no sessions and clients left, let's get out
- * of here...
- */
- n = 0;
- for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
- if (ARRAY_ITEM(&sessions, i) != NULL)
- n++;
- }
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- if (ARRAY_ITEM(&clients, i) != NULL)
- n++;
- }
- if (n == 0)
- break;
}
if (pfds != NULL)
xfree(pfds);
@@ -391,6 +380,16 @@ server_shutdown(void)
struct client *c;
u_int i, j;
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL) {
+ if (c->flags & (CLIENT_BAD|CLIENT_SUSPENDED))
+ server_lost_client(c);
+ else
+ server_write_client(c, MSG_SHUTDOWN, NULL, 0);
+ }
+ }
+
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
s = ARRAY_ITEM(&sessions, i);
for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
@@ -403,16 +402,23 @@ server_shutdown(void)
if (s != NULL)
session_destroy(s);
}
+}
+/* Check if the server should be shutting down (no more clients or windows). */
+int
+server_should_shutdown(void)
+{
+ u_int i;
+
+ for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
+ if (ARRAY_ITEM(&sessions, i) != NULL)
+ return (0);
+ }
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL) {
- if (c->flags & CLIENT_BAD)
- server_lost_client(c);
- else
- server_write_client(c, MSG_SHUTDOWN, NULL, 0);
- }
+ if (ARRAY_ITEM(&clients, i) != NULL)
+ return (0);
}
+ return (1);
}
/* Handle SIGCHLD. */