aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/server.c b/server.c
index f372de4f..9b11e019 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $OpenBSD$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -50,8 +50,6 @@ int server_shutdown;
struct event server_ev_accept;
struct event server_ev_second;
-struct paste_stack global_buffers;
-
int server_create_socket(void);
void server_loop(void);
int server_should_shutdown(void);
@@ -112,6 +110,7 @@ server_start(int lockfd, char *lockfile)
/* The first client is special and gets a socketpair; create it. */
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
fatal("socketpair failed");
+ log_debug("starting server");
switch (fork()) {
case -1:
@@ -146,7 +145,6 @@ server_start(int lockfd, char *lockfile)
RB_INIT(&sessions);
RB_INIT(&dead_sessions);
TAILQ_INIT(&session_groups);
- ARRAY_INIT(&global_buffers);
mode_key_init_trees();
key_bindings_init();
utf8_build();
@@ -168,25 +166,18 @@ server_start(int lockfd, char *lockfile)
cfg_cmd_q->emptyfn = cfg_default_done;
cfg_finished = 0;
cfg_references = 1;
- ARRAY_INIT(&cfg_causes);
cfg_client = ARRAY_FIRST(&clients);
if (cfg_client != NULL)
cfg_client->references++;
if (access(TMUX_CONF, R_OK) == 0) {
- if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) {
- xasprintf(&cause, "%s: %s", TMUX_CONF, cause);
- ARRAY_ADD(&cfg_causes, cause);
- }
- } else if (errno != ENOENT) {
- xasprintf(&cause, "%s: %s", TMUX_CONF, strerror(errno));
- ARRAY_ADD(&cfg_causes, cause);
- }
+ if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1)
+ cfg_add_cause("%s: %s", TMUX_CONF, cause);
+ } else if (errno != ENOENT)
+ cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
if (cfg_file != NULL) {
- if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) {
- xasprintf(&cause, "%s: %s", cfg_file, cause);
- ARRAY_ADD(&cfg_causes, cause);
- }
+ if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
+ cfg_add_cause("%s: %s", cfg_file, cause);
}
cmdq_continue(cfg_cmd_q);
@@ -212,25 +203,38 @@ server_loop(void)
server_window_loop();
server_client_loop();
- key_bindings_clean();
server_clean_dead();
}
}
-/* Check if the server should be shutting down (no more clients or sessions). */
+/* Check if the server should exit (no more clients or sessions). */
int
server_should_shutdown(void)
{
- u_int i;
+ struct client *c;
+ u_int i;
if (!options_get_number(&global_options, "exit-unattached")) {
if (!RB_EMPTY(&sessions))
return (0);
}
+
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL && c->session != NULL)
+ return (0);
+ }
+
+ /*
+ * No attached clients therefore want to exit - flush any waiting
+ * clients but don't actually exit until they've gone.
+ */
+ cmd_wait_for_flush();
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
if (ARRAY_ITEM(&clients, i) != NULL)
return (0);
}
+
return (1);
}
@@ -242,6 +246,8 @@ server_send_shutdown(void)
struct session *s, *next_s;
u_int i;
+ cmd_wait_for_flush();
+
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL) {
@@ -436,6 +442,7 @@ server_child_exited(pid_t pid, int status)
continue;
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp->pid == pid) {
+ wp->status = status;
server_destroy_pane(wp);
break;
}