summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2018-03-08 08:09:11 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2018-03-08 08:09:11 +0000
commite87803d86d8cdec8de078a2eeee905149dfa1f70 (patch)
tree7f0585a1f3e2af7ca0dd745da10443cc846eefbb /usr.bin/tmux
parent37d8a41c4989cb786999f0e17af7bb32db8cfdcc (diff)
Add a missing client-detached hook when the server shuts down, and do
not exit until jobs started from run-shell/if-shell have finished (add a job flags member and a flag to indicate other jobs). GitHub issue 1245.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-if-shell.c4
-rw-r--r--usr.bin/tmux/cmd-run-shell.c4
-rw-r--r--usr.bin/tmux/format.c4
-rw-r--r--usr.bin/tmux/job.c5
-rw-r--r--usr.bin/tmux/server-client.c4
-rw-r--r--usr.bin/tmux/server.c13
-rw-r--r--usr.bin/tmux/tmux.h7
-rw-r--r--usr.bin/tmux/window-copy.c4
8 files changed, 30 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c
index 1ec6c25a522..6740546601f 100644
--- a/usr.bin/tmux/cmd-if-shell.c
+++ b/usr.bin/tmux/cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-if-shell.c,v 1.56 2017/04/25 11:49:35 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.57 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -129,7 +129,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
job_run(shellcmd, s, cwd, NULL, cmd_if_shell_callback,
- cmd_if_shell_free, cdata);
+ cmd_if_shell_free, cdata, 0);
free(shellcmd);
if (args_has(args, 'b'))
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index bb80e2c95db..0950c81bd8b 100644
--- a/usr.bin/tmux/cmd-run-shell.c
+++ b/usr.bin/tmux/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-run-shell.c,v 1.51 2017/08/30 10:33:57 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.52 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -111,7 +111,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
cdata->item = item;
job_run(cdata->cmd, s, cwd, NULL, cmd_run_shell_callback,
- cmd_run_shell_free, cdata);
+ cmd_run_shell_free, cdata, 0);
if (args_has(args, 'b'))
return (CMD_RETURN_NORMAL);
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 83ebb7b1f21..c6640977ebb 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.152 2018/02/20 10:43:46 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.153 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -295,7 +295,7 @@ format_job_get(struct format_tree *ft, const char *cmd)
t = time(NULL);
if (fj->job == NULL && (force || fj->last != t)) {
fj->job = job_run(expanded, NULL, NULL, format_job_update,
- format_job_complete, NULL, fj);
+ format_job_complete, NULL, fj, JOB_NOWAIT);
if (fj->job == NULL) {
free(fj->out);
xasprintf(&fj->out, "<'%s' didn't start>", fj->cmd);
diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c
index 37e111b0c0e..b47655e3d89 100644
--- a/usr.bin/tmux/job.c
+++ b/usr.bin/tmux/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.48 2017/07/14 18:49:07 nicm Exp $ */
+/* $OpenBSD: job.c,v 1.49 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -44,7 +44,7 @@ struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
struct job *
job_run(const char *cmd, struct session *s, const char *cwd,
job_update_cb updatecb, job_complete_cb completecb, job_free_cb freecb,
- void *data)
+ void *data, int flags)
{
struct job *job;
struct environ *env;
@@ -111,6 +111,7 @@ job_run(const char *cmd, struct session *s, const char *cwd,
job = xmalloc(sizeof *job);
job->state = JOB_RUNNING;
+ job->flags = flags;
job->cmd = xstrdup(cmd);
job->pid = pid;
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index d509d7e9221..2ff84e0ea4a 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.248 2018/02/22 10:58:12 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.249 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1279,6 +1279,8 @@ server_client_check_exit(struct client *c)
if (EVBUFFER_LENGTH(c->stderr_data) != 0)
return;
+ if (c->flags & CLIENT_ATTACHED)
+ notify_client("client-detached", c);
proc_send(c->peer, MSG_EXIT, -1, &c->retval, sizeof c->retval);
c->flags &= ~CLIENT_EXIT;
}
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 7056838b90d..c3c39c31399 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.179 2018/02/22 10:54:51 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.180 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -244,6 +244,7 @@ server_loop(void)
{
struct client *c;
u_int items;
+ struct job *job;
do {
items = cmdq_next(NULL);
@@ -276,6 +277,11 @@ server_loop(void)
if (!TAILQ_EMPTY(&clients))
return (0);
+ LIST_FOREACH(job, &all_jobs, entry) {
+ if ((~job->flags & JOB_NOWAIT) && job->state == JOB_RUNNING)
+ return (0);
+ }
+
return (1);
}
@@ -291,8 +297,11 @@ server_send_exit(void)
TAILQ_FOREACH_SAFE(c, &clients, entry, c1) {
if (c->flags & CLIENT_SUSPENDED)
server_client_lost(c);
- else
+ else {
+ if (c->flags & CLIENT_ATTACHED)
+ notify_client("client-detached", c);
proc_send(c->peer, MSG_SHUTDOWN, -1, NULL, 0);
+ }
c->session = NULL;
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index f8d2c32bccc..4647d869612 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.820 2018/02/28 08:55:44 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.821 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -622,6 +622,9 @@ struct job {
JOB_CLOSED
} state;
+ int flags;
+#define JOB_NOWAIT 0x1
+
char *cmd;
pid_t pid;
int status;
@@ -1649,7 +1652,7 @@ extern const struct options_table_entry options_table[];
/* job.c */
extern struct joblist all_jobs;
struct job *job_run(const char *, struct session *, const char *,
- job_update_cb, job_complete_cb, job_free_cb, void *);
+ job_update_cb, job_complete_cb, job_free_cb, void *, int);
void job_free(struct job *);
void job_died(struct job *, int);
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 08ef4c49af8..903298bba1f 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.186 2017/11/16 11:16:15 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.187 2018/03/08 08:09:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1677,7 +1677,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *s,
return;
expanded = format_single(NULL, arg, NULL, s, NULL, wp);
- job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL);
+ job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL, JOB_NOWAIT);
bufferevent_write(job->event, buf, len);
free(expanded);