Sync OpenBSD patchset 382:

Collect status from dead jobs and don't invoke the callback until both
all input (the socket is closed) and status is available.
pull/1/head
Tiago Cunha 2009-10-12 00:21:08 +00:00
parent b26ea8462e
commit 1b03bc2404
3 changed files with 38 additions and 9 deletions

7
job.c
View File

@ -1,4 +1,4 @@
/* $Id: job.c,v 1.3 2009-10-12 00:12:32 tcunha Exp $ */ /* $Id: job.c,v 1.4 2009-10-12 00:21:08 tcunha Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -104,6 +104,8 @@ job_add(struct jobs *jobs, struct client *c, const char *cmd,
job->freefn = freefn; job->freefn = freefn;
job->data = data; job->data = data;
job->flags = JOB_DONE;
RB_INSERT(jobs, jobs, job); RB_INSERT(jobs, jobs, job);
SLIST_INSERT_HEAD(&all_jobs, job, lentry); SLIST_INSERT_HEAD(&all_jobs, job, lentry);
@ -132,8 +134,9 @@ job_run(struct job *job)
{ {
int nullfd, out[2], mode; int nullfd, out[2], mode;
if (job->fd != -1) if (!(job->flags & JOB_DONE))
return (0); return (0);
job->flags &= ~JOB_DONE;
if (pipe(out) != 0) if (pipe(out) != 0)
return (-1); return (-1);

View File

@ -1,4 +1,4 @@
/* $Id: server.c,v 1.203 2009-10-12 00:18:19 tcunha Exp $ */ /* $Id: server.c,v 1.204 2009-10-12 00:21:08 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -87,6 +87,7 @@ void server_check_window(struct window *);
void server_check_redraw(struct client *); void server_check_redraw(struct client *);
void server_set_title(struct client *); void server_set_title(struct client *);
void server_check_timers(struct client *); void server_check_timers(struct client *);
void server_check_jobs(void);
void server_lock_server(void); void server_lock_server(void);
void server_lock_sessions(void); void server_lock_sessions(void);
void server_check_clients(void); void server_check_clients(void);
@ -373,7 +374,8 @@ server_main(int srv_fd)
sigusr1 = 0; sigusr1 = 0;
} }
/* Process client actions. */ /* Collect any jobs that have died and process clients. */
server_check_jobs();
server_check_clients(); server_check_clients();
/* Initialise pollfd array and add server socket. */ /* Initialise pollfd array and add server socket. */
@ -392,7 +394,6 @@ server_main(int srv_fd)
/* Do the poll. */ /* Do the poll. */
pfds = server_poll_flatten(&nfds); pfds = server_poll_flatten(&nfds);
log_debug("polling %d", nfds);
if (poll(pfds, nfds, xtimeout) == -1) { if (poll(pfds, nfds, xtimeout) == -1) {
if (errno == EAGAIN || errno == EINTR) if (errno == EAGAIN || errno == EINTR)
continue; continue;
@ -513,6 +514,7 @@ server_child_signal(void)
{ {
struct window *w; struct window *w;
struct window_pane *wp; struct window_pane *wp;
struct job *job;
int status; int status;
pid_t pid; pid_t pid;
u_int i; u_int i;
@ -526,8 +528,15 @@ server_child_signal(void)
case 0: case 0:
return; return;
} }
if (!WIFSTOPPED(status)) if (!WIFSTOPPED(status)) {
SLIST_FOREACH(job, &all_jobs, lentry) {
if (pid == job->pid) {
job->pid = -1;
job->status = status;
}
}
continue; continue;
}
if (WSTOPSIG(status) == SIGTTIN || WSTOPSIG(status) == SIGTTOU) if (WSTOPSIG(status) == SIGTTIN || WSTOPSIG(status) == SIGTTOU)
continue; continue;
@ -795,12 +804,25 @@ server_handle_jobs(void)
if (buffer_poll(pfd, job->out, NULL) != 0) { if (buffer_poll(pfd, job->out, NULL) != 0) {
close(job->fd); close(job->fd);
job->fd = -1; job->fd = -1;
if (job->callbackfn != NULL)
job->callbackfn(job);
} }
} }
} }
/* Handle job fds. */
void
server_check_jobs(void)
{
struct job *job;
SLIST_FOREACH(job, &all_jobs, lentry) {
if (job->flags & JOB_DONE || job->fd != -1 || job->pid != -1)
continue;
if (job->callbackfn != NULL)
job->callbackfn(job);
job->flags |= JOB_DONE;
}
}
/* Handle client pollfds. */ /* Handle client pollfds. */
void void
server_handle_clients(void) server_handle_clients(void)

6
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.467 2009-10-12 00:18:19 tcunha Exp $ */ /* $Id: tmux.h,v 1.468 2009-10-12 00:21:08 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -565,6 +565,7 @@ ARRAY_DECL(keylist, int);
struct job { struct job {
char *cmd; char *cmd;
pid_t pid; pid_t pid;
int status;
struct client *client; struct client *client;
@ -575,6 +576,9 @@ struct job {
void (*freefn)(void *); void (*freefn)(void *);
void *data; void *data;
int flags;
#define JOB_DONE 0x1
RB_ENTRY(job) entry; RB_ENTRY(job) entry;
SLIST_ENTRY(job) lentry; SLIST_ENTRY(job) lentry;
}; };