aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/server.c b/server.c
index ef8fa755..999389cc 100644
--- a/server.c
+++ b/server.c
@@ -113,10 +113,11 @@ server_create_socket(void)
int
server_start(char *path)
{
- struct client *c;
- int pair[2];
- char *cause, rpathbuf[MAXPATHLEN];
- struct timeval tv;
+ struct window_pane *wp;
+ int pair[2], retval;
+ char rpathbuf[MAXPATHLEN];
+ struct timeval tv;
+ u_int i;
/* The first client is special and gets a socketpair; create it. */
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
@@ -166,15 +167,31 @@ server_start(char *path)
server_fd = server_create_socket();
server_client_create(pair[1]);
- if (access(SYSTEM_CFG, R_OK) == 0) {
- if (load_cfg(SYSTEM_CFG, NULL, &cause) != 0)
- goto error;
- } else if (errno != ENOENT) {
- xasprintf(&cause, "%s: %s", strerror(errno), SYSTEM_CFG);
- goto error;
+ retval = 0;
+ if (access(SYSTEM_CFG, R_OK) == 0)
+ load_cfg(SYSTEM_CFG, NULL, &cfg_ncauses, &cfg_causes);
+ else if (errno != ENOENT) {
+ cfg_add_cause(&cfg_ncauses, &cfg_causes,
+ "%s: %s", strerror(errno), SYSTEM_CFG);
}
- if (cfg_file != NULL && load_cfg(cfg_file, NULL, &cause) != 0)
- goto error;
+ if (cfg_file != NULL)
+ load_cfg(cfg_file, NULL, &cfg_ncauses, &cfg_causes);
+
+ /*
+ * If there is a session already, put the current window and pane into
+ * more mode.
+ */
+ if (!ARRAY_EMPTY(&sessions) && cfg_ncauses != 0) {
+ wp = ARRAY_FIRST(&sessions)->curw->window->active;
+ window_pane_set_mode(wp, &window_more_mode);
+ for (i = 0; i < cfg_ncauses; i++) {
+ window_more_add(wp, "%s", cfg_causes[i]);
+ xfree(cfg_causes[i]);
+ }
+ xfree(cfg_causes);
+ cfg_ncauses = 0;
+ }
+ cfg_finished = 1;
event_set(&server_ev_accept,
server_fd, EV_READ|EV_PERSIST, server_accept_callback, NULL);
@@ -188,20 +205,6 @@ server_start(char *path)
server_signal_set();
server_loop();
exit(0);
-
-error:
- /* Write the error and shutdown the server. */
- c = ARRAY_FIRST(&clients);
-
- server_write_error(c, cause);
- server_write_client(c, MSG_EXIT, NULL, 0);
- xfree(cause);
-
- server_shutdown = 1;
-
- server_signal_set();
- server_loop();
- exit(1);
}
/* Main server loop. */