summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/job.c15
-rw-r--r--usr.bin/tmux/tmux.h8
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;