From 93b2871cab399388a16ace64d8dfb9a8e2143543 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 21 Apr 2015 22:32:40 +0000 Subject: [PATCH] Do not die on USR1 if any of the socket parent directories are missing. Reported by Robin Powell. --- server.c | 22 ++++++++++++++-------- tmux.1 | 6 ++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/server.c b/server.c index 26bfddfe..c8101775 100644 --- a/server.c +++ b/server.c @@ -79,24 +79,22 @@ server_create_socket(void) size = strlcpy(sa.sun_path, socket_path, sizeof sa.sun_path); if (size >= sizeof sa.sun_path) { errno = ENAMETOOLONG; - fatal("socket failed"); + return (-1); } unlink(sa.sun_path); if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) - fatal("socket failed"); + return (-1); mask = umask(S_IXUSR|S_IXGRP|S_IRWXO); if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) - fatal("bind failed"); + return (-1); umask(mask); if (listen(fd, 16) == -1) - fatal("listen failed"); + return (-1); setblocking(fd, 0); - server_update_socket(); - return (fd); } @@ -155,6 +153,9 @@ server_start(int lockfd, char *lockfile) setproctitle("server (%s)", socket_path); server_fd = server_create_socket(); + if (server_fd == -1) + fatal("couldn't create socket"); + server_update_socket(); server_client_create(pair[1]); unlink(lockfile); @@ -387,6 +388,7 @@ server_add_accept(int timeout) void server_signal_callback(int sig, unused short events, unused void *data) { + int fd; switch (sig) { case SIGTERM: server_shutdown = 1; @@ -397,8 +399,12 @@ server_signal_callback(int sig, unused short events, unused void *data) break; case SIGUSR1: event_del(&server_ev_accept); - close(server_fd); - server_fd = server_create_socket(); + fd = server_create_socket(); + if (fd != -1) { + close(server_fd); + server_fd = fd; + server_update_socket(); + } server_add_accept(0); break; } diff --git a/tmux.1 b/tmux.1 index ab762387..68e9b9de 100644 --- a/tmux.1 +++ b/tmux.1 @@ -163,7 +163,8 @@ If the socket is accidentally removed, the .Dv SIGUSR1 signal may be sent to the .Nm -server process to recreate it. +server process to recreate it (note that this will fail if any parent +directories are missing). .It Fl l Behave as a login shell. This flag currently has no effect and is for compatibility with other shells @@ -2004,7 +2005,8 @@ is bound in .Ar mode-table : the binding for command mode with .Fl c -or for normal mode without. See the +or for normal mode without. +See the .Sx WINDOWS AND PANES section and the .Ic list-keys