aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicm <nicm>2020-10-30 18:54:23 +0000
committernicm <nicm>2020-10-30 18:54:23 +0000
commit95841ba16acafa8c1a516712ad0f2b48e34357e6 (patch)
tree6bf01605a4b1f6c4e97ed17ca8fea84d5580ca84
parent9726c4454e29cb5b9c6681abfb5c99972a9bd574 (diff)
downloadrtmux-95841ba16acafa8c1a516712ad0f2b48e34357e6.tar.gz
rtmux-95841ba16acafa8c1a516712ad0f2b48e34357e6.tar.bz2
rtmux-95841ba16acafa8c1a516712ad0f2b48e34357e6.zip
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.
-rw-r--r--client.c9
-rw-r--r--server-client.c2
2 files changed, 8 insertions, 3 deletions
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:
diff --git a/server-client.c b/server-client.c
index 190897ff..3e256a92 100644
--- a/server-client.c
+++ b/server-client.c
@@ -2025,7 +2025,7 @@ server_client_dispatch(struct imsg *imsg, void *arg)
break;
c->flags &= ~CLIENT_SUSPENDED;
- if (c->fd == -1) /* exited in the meantime */
+ if (c->fd == -1 || c->session == NULL) /* exited already */
break;
s = c->session;