summaryrefslogtreecommitdiffstats
path: root/server.c
Side-by-side diff
Diffstat (limited to 'server.c') (more/less context) (ignore whitespace changes)
-rw-r--r--server.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/server.c b/server.c
index cc3270e..df1aecb 100644
--- a/server.c
+++ b/server.c
@@ -55,28 +55,39 @@ void server_lost_client(struct client *);
void server_lost_window(struct window *);
/* Fork new server. */
-int
+pid_t
server_start(const char *path)
{
struct sockaddr_un sa;
size_t size;
mode_t mask;
int n, fd, mode;
+ pid_t pid;
char *cause;
- switch (fork()) {
+ switch (pid = fork()) {
case -1:
fatal("fork");
case 0:
break;
default:
- return (0);
+ return (pid);
}
#ifdef DEBUG
xmalloc_clear();
#endif
+ ARRAY_INIT(&windows);
+ ARRAY_INIT(&clients);
+ ARRAY_INIT(&sessions);
+ key_bindings_init();
+
+ if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) {
+ log_warnx("%s", cause);
+ exit(1);
+ }
+
logfile("server");
#ifndef NO_SETPROCTITLE
setproctitle("server (%s)", path);
@@ -110,17 +121,10 @@ server_start(const char *path)
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
fatal("fcntl failed");
- /* Load configuration. */
- if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) {
- log_warnx("%s", cause);
- xfree(cause);
- exit(1);
- }
-
if (daemon(1, 1) != 0)
fatal("daemon failed");
log_debug("server daemonised, pid now %ld", (long) getpid());
-
+
n = server_main(path, fd);
#ifdef DEBUG
xmalloc_report(getpid(), "server");
@@ -137,12 +141,6 @@ server_main(const char *srv_path, int srv_fd)
u_int i;
siginit();
-
- ARRAY_INIT(&windows);
- ARRAY_INIT(&clients);
- ARRAY_INIT(&sessions);
-
- key_bindings_init();
pfds = NULL;
while (!sigterm) {