-/* $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>
close(out[1]);
job = xmalloc(sizeof *job);
+ job->state = JOB_RUNNING;
+
job->cmd = xstrdup(cmd);
job->pid = pid;
job->status = 0;
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;
}
}
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;
+ }
}
-/* $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>
/* Scheduled job. */
struct job {
+ enum {
+ JOB_RUNNING,
+ JOB_DEAD,
+ JOB_CLOSED
+ } state;
+
char *cmd;
pid_t pid;
int status;