From 86d6ac2f0695b02bdbef542cce3cdb0cca39160e Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 22 Sep 2020 05:23:34 +0000 Subject: Fix warnings on some platforms with %llx and add a new message to handle 64-bit client flags. --- client.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index 852b09ce..f08d6f29 100644 --- a/client.c +++ b/client.c @@ -59,7 +59,8 @@ static struct client_files client_files = RB_INITIALIZER(&client_files); static __dead void client_exec(const char *,const char *); static int client_get_lock(char *); -static int client_connect(struct event_base *, const char *, int); +static int client_connect(struct event_base *, const char *, + uint64_t); static void client_send_identify(const char *, const char *, int); static void client_signal(int); static void client_dispatch(struct imsg *, void *); @@ -100,7 +101,7 @@ client_get_lock(char *lockfile) /* Connect client to server. */ static int -client_connect(struct event_base *base, const char *path, int flags) +client_connect(struct event_base *base, const char *path, uint64_t flags) { struct sockaddr_un sa; size_t size; @@ -238,7 +239,8 @@ client_exit(void) /* Client main loop. */ int -client_main(struct event_base *base, int argc, char **argv, int flags, int feat) +client_main(struct event_base *base, int argc, char **argv, uint64_t flags, + int feat) { struct cmd_parse_result *pr; struct msg_command *data; @@ -284,7 +286,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags, int feat) /* Save the flags. */ client_flags = flags; - log_debug("flags are %#llx", client_flags); + log_debug("flags are %#llx", (unsigned long long)client_flags); /* Initialize the client socket and start the server. */ fd = client_connect(base, socket_path, client_flags); @@ -440,6 +442,8 @@ client_send_identify(const char *ttynam, const char *cwd, int feat) pid_t pid; proc_send(client_peer, MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags); + proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &client_flags, + sizeof client_flags); if ((s = getenv("TERM")) == NULL) s = ""; @@ -889,7 +893,8 @@ client_dispatch_wait(struct imsg *imsg) fatalx("bad MSG_FLAGS string"); memcpy(&client_flags, data, sizeof client_flags); - log_debug("new flags are %#llx", client_flags); + log_debug("new flags are %#llx", + (unsigned long long)client_flags); break; case MSG_SHELL: if (datalen == 0 || data[datalen - 1] != '\0') @@ -942,7 +947,8 @@ client_dispatch_attached(struct imsg *imsg) fatalx("bad MSG_FLAGS string"); memcpy(&client_flags, data, sizeof client_flags); - log_debug("new flags are %#llx", client_flags); + log_debug("new flags are %#llx", + (unsigned long long)client_flags); break; case MSG_DETACH: case MSG_DETACHKILL: -- cgit From 95841ba16acafa8c1a516712ad0f2b48e34357e6 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 30 Oct 2020 18:54:23 +0000 Subject: With csh, a tmux client gets SIGTERM before SIGCONT when killed with "kill %%", so when the client tells the server it got SIGCONT, don't use bits that may already have been freed when it got SIGTERM. Also don't print anything on exit if we get SIGTERM while suspended. Reported by Theo. --- client.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index f08d6f29..dcbc0d18 100644 --- a/client.c +++ b/client.c @@ -36,6 +36,7 @@ static struct tmuxproc *client_proc; static struct tmuxpeer *client_peer; static uint64_t client_flags; +static int client_suspended; static enum { CLIENT_EXIT_NONE, CLIENT_EXIT_DETACHED, @@ -221,7 +222,7 @@ static void client_exit(void) { struct client_file *cf; - size_t left; + size_t left; int waiting = 0; RB_FOREACH (cf, client_files, &client_files) { @@ -763,6 +764,7 @@ client_signal(int sig) struct sigaction sigact; int status; + log_debug("%s: %s", __func__, strsignal(sig)); if (sig == SIGCHLD) waitpid(WAIT_ANY, &status, WNOHANG); else if (!client_attached) { @@ -776,7 +778,8 @@ client_signal(int sig) proc_send(client_peer, MSG_EXITING, -1, NULL, 0); break; case SIGTERM: - client_exitreason = CLIENT_EXIT_TERMINATED; + if (!client_suspended) + client_exitreason = CLIENT_EXIT_TERMINATED; client_exitval = 1; proc_send(client_peer, MSG_EXITING, -1, NULL, 0); break; @@ -791,6 +794,7 @@ client_signal(int sig) if (sigaction(SIGTSTP, &sigact, NULL) != 0) fatal("sigaction failed"); proc_send(client_peer, MSG_WAKEUP, -1, NULL, 0); + client_suspended = 0; break; } } @@ -1003,6 +1007,7 @@ client_dispatch_attached(struct imsg *imsg) sigact.sa_handler = SIG_DFL; if (sigaction(SIGTSTP, &sigact, NULL) != 0) fatal("sigaction failed"); + client_suspended = 1; kill(getpid(), SIGTSTP); break; case MSG_LOCK: -- cgit