diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/job.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 34 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 6 |
3 files changed, 38 insertions, 9 deletions
diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c index b54cf40eb03..23b183d4094 100644 --- a/usr.bin/tmux/job.c +++ b/usr.bin/tmux/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.2 2009/10/10 18:42:14 nicm Exp $ */ +/* $OpenBSD: job.c,v 1.3 2009/10/11 07:20:16 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -105,6 +105,8 @@ job_add(struct jobs *jobs, struct client *c, const char *cmd, job->freefn = freefn; job->data = data; + job->flags = JOB_DONE; + RB_INSERT(jobs, jobs, job); SLIST_INSERT_HEAD(&all_jobs, job, lentry); @@ -133,8 +135,9 @@ job_run(struct job *job) { int nullfd, out[2], mode; - if (job->fd != -1) + if (!(job->flags & JOB_DONE)) return (0); + job->flags &= ~JOB_DONE; if (pipe(out) != 0) return (-1); diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index 2396639f516..b3bb7b7222a 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.52 2009/10/11 07:01:10 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.53 2009/10/11 07:20:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -88,6 +88,7 @@ void server_check_window(struct window *); void server_check_redraw(struct client *); void server_set_title(struct client *); void server_check_timers(struct client *); +void server_check_jobs(void); void server_lock_server(void); void server_lock_sessions(void); void server_check_clients(void); @@ -370,7 +371,8 @@ server_main(int srv_fd) sigusr1 = 0; } - /* Process client actions. */ + /* Collect any jobs that have died and process clients. */ + server_check_jobs(); server_check_clients(); /* Initialise pollfd array and add server socket. */ @@ -389,7 +391,6 @@ server_main(int srv_fd) /* Do the poll. */ pfds = server_poll_flatten(&nfds); - log_debug("polling %d", nfds); if (poll(pfds, nfds, xtimeout) == -1) { if (errno == EAGAIN || errno == EINTR) continue; @@ -510,6 +511,7 @@ server_child_signal(void) { struct window *w; struct window_pane *wp; + struct job *job; int status; pid_t pid; u_int i; @@ -523,8 +525,15 @@ server_child_signal(void) case 0: return; } - if (!WIFSTOPPED(status)) + if (!WIFSTOPPED(status)) { + SLIST_FOREACH(job, &all_jobs, lentry) { + if (pid == job->pid) { + job->pid = -1; + job->status = status; + } + } continue; + } if (WSTOPSIG(status) == SIGTTIN || WSTOPSIG(status) == SIGTTOU) continue; @@ -792,12 +801,25 @@ server_handle_jobs(void) if (buffer_poll(pfd, job->out, NULL) != 0) { close(job->fd); 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. */ void server_handle_clients(void) diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index f3518de76eb..8e0b32866e0 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.129 2009/10/11 07:01:10 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.130 2009/10/11 07:20:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -567,6 +567,7 @@ ARRAY_DECL(keylist, int); struct job { char *cmd; pid_t pid; + int status; struct client *client; @@ -577,6 +578,9 @@ struct job { void (*freefn)(void *); void *data; + int flags; +#define JOB_DONE 0x1 + RB_ENTRY(job) entry; SLIST_ENTRY(job) lentry; }; |