diff options
author | 2015-06-17 16:44:49 +0000 | |
---|---|---|
committer | 2015-06-17 16:44:49 +0000 | |
commit | 7ef73ed3f277d336c450548fbd91891fae8c6ef3 (patch) | |
tree | 8e7972338f27c5aed4367271a2f8d02df8381ead | |
parent | add DST Root CA X3 certificate, already present in most browser cert stores. (diff) | |
download | wireguard-openbsd-7ef73ed3f277d336c450548fbd91891fae8c6ef3.tar.xz wireguard-openbsd-7ef73ed3f277d336c450548fbd91891fae8c6ef3.zip |
Use an explicit job state instead of avoid closing our side of the
socketpair and setting it to -1 to mark when the other side is
closed. This avoids closing it while the libevent bufferevent still has
it (it could try to add it to the polled set which some mechanisms don't
like). Fixes part a problem reported by Bruno Sutic.
-rw-r--r-- | usr.bin/tmux/job.c | 15 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 8 |
2 files changed, 16 insertions, 7 deletions
diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c index 7995b6dea54..a461f5cbf5b 100644 --- a/usr.bin/tmux/job.c +++ b/usr.bin/tmux/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.35 2015/04/24 22:19:36 nicm Exp $ */ +/* $OpenBSD: job.c,v 1.36 2015/06/17 16:44:49 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -100,6 +100,8 @@ job_run(const char *cmd, struct session *s, int cwd, close(out[1]); job = xmalloc(sizeof *job); + job->state = JOB_RUNNING; + job->cmd = xstrdup(cmd); job->pid = pid; job->status = 0; @@ -167,14 +169,13 @@ job_callback(unused struct bufferevent *bufev, unused short events, void *data) log_debug("job error %p: %s, pid %ld", job, job->cmd, (long) job->pid); - if (job->pid == -1) { + if (job->state == JOB_DEAD) { if (job->callbackfn != NULL) job->callbackfn(job); job_free(job); } else { bufferevent_disable(job->event, EV_READ); - close(job->fd); - job->fd = -1; + job->state = JOB_CLOSED; } } @@ -186,10 +187,12 @@ job_died(struct job *job, int status) job->status = status; - if (job->fd == -1) { + if (job->state == JOB_CLOSED) { if (job->callbackfn != NULL) job->callbackfn(job); job_free(job); - } else + } else { job->pid = -1; + job->state = JOB_DEAD; + } } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ce057af9360..36a9648dfc1 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.524 2015/06/15 10:58:01 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.525 2015/06/17 16:44:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -714,6 +714,12 @@ struct options { /* Scheduled job. */ struct job { + enum { + JOB_RUNNING, + JOB_DEAD, + JOB_CLOSED + } state; + char *cmd; pid_t pid; int status; |