Add a couple of helper functions, and flush imsgs on exit.

This commit is contained in:
nicm
2021-02-11 09:39:29 +00:00
parent 79e1984962
commit 2b58c226db
5 changed files with 67 additions and 35 deletions

View File

@ -156,35 +156,22 @@ int
server_start(struct tmuxproc *client, int flags, struct event_base *base,
int lockfd, char *lockfile)
{
int pair[2];
sigset_t set, oldset;
struct client *c = NULL;
char *cause = NULL;
int fd;
sigset_t set, oldset;
struct client *c = NULL;
char *cause = NULL;
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, &oldset);
if (~flags & CLIENT_NOFORK) {
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
fatal("socketpair failed");
switch (fork()) {
case -1:
fatal("fork failed");
case 0:
break;
default:
if (proc_fork_and_daemon(&fd) != 0) {
sigprocmask(SIG_SETMASK, &oldset, NULL);
close(pair[1]);
return (pair[0]);
return (fd);
}
close(pair[0]);
if (daemon(1, 0) != 0)
fatal("daemon failed");
}
server_client_flags = flags;
proc_clear_signals(client, 0);
server_client_flags = flags;
if (event_reinit(base) != 0)
fatalx("event_reinit failed");
@ -213,7 +200,7 @@ server_start(struct tmuxproc *client, int flags, struct event_base *base,
if (server_fd != -1)
server_update_socket();
if (~flags & CLIENT_NOFORK)
c = server_client_create(pair[1]);
c = server_client_create(fd);
else
options_set_number(global_options, "exit-empty", 0);