diff options
author | nicm <nicm> | 2015-06-17 16:44:49 +0000 |
---|---|---|
committer | nicm <nicm> | 2015-06-17 16:44:49 +0000 |
commit | 021cdbe1c0111951a1f63b09b41c9e3db3793db5 (patch) | |
tree | 2716f2d6a0a572603511d239420a34919904b54f | |
parent | d96ab3401960ab4a7c9434dfda1ebdc5204873e0 (diff) | |
download | rtmux-021cdbe1c0111951a1f63b09b41c9e3db3793db5.tar.gz rtmux-021cdbe1c0111951a1f63b09b41c9e3db3793db5.tar.bz2 rtmux-021cdbe1c0111951a1f63b09b41c9e3db3793db5.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-- | job.c | 13 | ||||
-rw-r--r-- | tmux.h | 6 |
2 files changed, 14 insertions, 5 deletions
@@ -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; + } } @@ -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; |