aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-10-12 00:21:08 +0000
committerTiago Cunha <tcunha@gmx.com>2009-10-12 00:21:08 +0000
commit1b03bc2404a0892b9434b43603fc43282e6e36de (patch)
treed3f1d878151a512a252175edf09f6d13528efd98 /server.c
parentb26ea8462ec0bb7d3d5cbeed115f6f4bbd4e1072 (diff)
downloadrtmux-1b03bc2404a0892b9434b43603fc43282e6e36de.tar.gz
rtmux-1b03bc2404a0892b9434b43603fc43282e6e36de.tar.bz2
rtmux-1b03bc2404a0892b9434b43603fc43282e6e36de.zip
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.
Diffstat (limited to 'server.c')
-rw-r--r--server.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/server.c b/server.c
index cd855b98..4158044e 100644
--- a/server.c
+++ b/server.c
@@ -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>
@@ -87,6 +87,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);
@@ -373,7 +374,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. */
@@ -392,7 +394,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;
@@ -513,6 +514,7 @@ server_child_signal(void)
{
struct window *w;
struct window_pane *wp;
+ struct job *job;
int status;
pid_t pid;
u_int i;
@@ -526,8 +528,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;
@@ -795,12 +804,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)