diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-18 08:34:23 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-18 08:34:23 +0000 |
commit | c50abd069038115a9946520c2d8d0a103fcbbe48 (patch) | |
tree | 800c9dea4847a4ec80db9734c944277cc5150f6a /usr.bin/tmux/client.c | |
parent | 1edc1e683741f2cac0146a729e56c9ecfdd6018b (diff) |
Add a flag to make a client wait for an empty line before exiting in
control mode to avoid stray commands ending up in the shell.
Diffstat (limited to 'usr.bin/tmux/client.c')
-rw-r--r-- | usr.bin/tmux/client.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index 3c3106194d7..228f4ac6531 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.147 2020/06/10 07:27:10 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.148 2020/06/18 08:34:22 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -35,7 +35,7 @@ static struct tmuxproc *client_proc; static struct tmuxpeer *client_peer; -static int client_flags; +static uint64_t client_flags; static enum { CLIENT_EXIT_NONE, CLIENT_EXIT_DETACHED, @@ -247,7 +247,9 @@ client_main(struct event_base *base, int argc, char **argv, int flags, int feat) pid_t ppid; enum msgtype msg; struct termios tio, saved_tio; - size_t size; + size_t size, linesize = 0; + ssize_t linelen; + char *line = NULL; /* Ignore SIGCHLD now or daemon() in the server will leave a zombie. */ signal(SIGCHLD, SIG_IGN); @@ -276,13 +278,14 @@ client_main(struct event_base *base, int argc, char **argv, int flags, int feat) free(pr->error); } - /* Save the flags. */ - client_flags = flags; - /* Create client process structure (starts logging). */ client_proc = proc_start("client"); proc_set_signals(client_proc, client_signal); + /* Save the flags. */ + client_flags = flags; + log_debug("flags are %#llx", client_flags); + /* Initialize the client socket and start the server. */ fd = client_connect(base, socket_path, client_flags); if (fd == -1) { @@ -406,8 +409,19 @@ client_main(struct event_base *base, int argc, char **argv, int flags, int feat) printf("%%exit %s\n", client_exit_message()); else printf("%%exit\n"); + fflush(stdout); + if (client_flags & CLIENT_CONTROL_WAITEXIT) { + setvbuf(stdin, NULL, _IOLBF, 0); + for (;;) { + linelen = getline(&line, &linesize, stdin); + if (linelen <= 1) + break; + } + free(line); + } if (client_flags & CLIENT_CONTROLCONTROL) { printf("\033\\"); + fflush(stdout); tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio); } } else if (client_exitreason != CLIENT_EXIT_NONE) @@ -870,6 +884,13 @@ client_dispatch_wait(struct imsg *imsg) client_exitval = 1; proc_exit(client_proc); break; + case MSG_FLAGS: + if (datalen != sizeof client_flags) + fatalx("bad MSG_FLAGS string"); + + memcpy(&client_flags, data, sizeof client_flags); + log_debug("new flags are %#llx", client_flags); + break; case MSG_SHELL: if (datalen == 0 || data[datalen - 1] != '\0') fatalx("bad MSG_SHELL string"); @@ -916,6 +937,13 @@ client_dispatch_attached(struct imsg *imsg) datalen = imsg->hdr.len - IMSG_HEADER_SIZE; switch (imsg->hdr.type) { + case MSG_FLAGS: + if (datalen != sizeof client_flags) + fatalx("bad MSG_FLAGS string"); + + memcpy(&client_flags, data, sizeof client_flags); + log_debug("new flags are %#llx", client_flags); + break; case MSG_DETACH: case MSG_DETACHKILL: if (datalen == 0 || data[datalen - 1] != '\0') |