diff options
author | joerg <joerg@pkgsrc.org> | 2008-01-27 14:01:23 +0000 |
---|---|---|
committer | joerg <joerg@pkgsrc.org> | 2008-01-27 14:01:23 +0000 |
commit | e09da90e38df623dd9bf2b1f3414ec4f2adb168c (patch) | |
tree | 1ad3c9659d93efbc7e4f882ca2da73366d8607a9 /pkgtools/pbulk | |
parent | df583faa81ffb50d8761e6dce2f2603b80c18512 (diff) | |
download | pkgsrc-e09da90e38df623dd9bf2b1f3414ec4f2adb168c.tar.gz |
pbulk-0.27:
When running the start script in master mode, already accept incoming
connections. This makes the start script more useful when using more
clients than the default listen back log.
Diffstat (limited to 'pkgtools/pbulk')
-rw-r--r-- | pkgtools/pbulk/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pbulk/files/pbulk/pbuild/master.c | 55 | ||||
-rw-r--r-- | pkgtools/pbulk/files/pbulk/pscan/master.c | 57 |
3 files changed, 84 insertions, 32 deletions
diff --git a/pkgtools/pbulk/Makefile b/pkgtools/pbulk/Makefile index 74ff6281084..493bd21a37a 100644 --- a/pkgtools/pbulk/Makefile +++ b/pkgtools/pbulk/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.33 2008/01/26 23:44:08 joerg Exp $ +# $NetBSD: Makefile,v 1.34 2008/01/27 14:01:23 joerg Exp $ -DISTNAME= pbulk-0.26 +DISTNAME= pbulk-0.27 CATEGORIES= pkgtools MASTER_SITES= # empty DISTFILES= # empty diff --git a/pkgtools/pbulk/files/pbulk/pbuild/master.c b/pkgtools/pbulk/files/pbulk/pbuild/master.c index 040dce3622c..08ab55e65b6 100644 --- a/pkgtools/pbulk/files/pbulk/pbuild/master.c +++ b/pkgtools/pbulk/files/pbulk/pbuild/master.c @@ -1,4 +1,4 @@ -/* $NetBSD: master.c,v 1.6 2008/01/26 00:34:57 joerg Exp $ */ +/* $NetBSD: master.c,v 1.7 2008/01/27 14:01:23 joerg Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. @@ -54,9 +54,12 @@ #include "pbulk.h" #include "pbuild.h" +static int clients_started; static LIST_HEAD(, build_peer) active_peers, inactive_peers, unassigned_peers; static struct event listen_event; static int listen_event_socket; +static struct event child_event; +static pid_t child_pid; struct build_peer { LIST_ENTRY(build_peer) peer_link; @@ -205,10 +208,10 @@ assign_job(void *arg) LIST_REMOVE(peer, peer_link); - peer->job = get_job(); + peer->job = clients_started ? get_job() : NULL; if (peer->job == NULL) { LIST_INSERT_HEAD(&unassigned_peers, peer, peer_link); - if (LIST_EMPTY(&active_peers)) + if (LIST_EMPTY(&active_peers) && clients_started) shutdown_master(); return; } @@ -265,6 +268,29 @@ listen_handler(int sock, short event, void *arg) recv_command(peer); } +static void +child_handler(int dummy, short event, void *arg) +{ + struct build_peer *peer; + int status; + + if (waitpid(child_pid, &status, WNOHANG) == -1) { + if (errno == ECHILD) + return; + err(1, "Could not wait for child"); + } + if (status != 0) + err(1, "Start script failed"); + + clients_started = 1; + signal_del(&child_event); + + if ((peer = LIST_FIRST(&inactive_peers)) != NULL) { + LIST_REMOVE(peer, peer_link); + assign_job(peer); + } +} + void master_mode(const char *master_port, const char *start_script) { @@ -292,25 +318,24 @@ master_mode(const char *master_port, const char *start_script) if (listen(fd, 5) == -1) err(1, "Could not listen on socket"); + event_set(&listen_event, fd, EV_READ | EV_PERSIST, listen_handler, NULL); + event_add(&listen_event, NULL); + listen_event_socket = fd; + if (start_script) { - pid_t child; - int status; - - if ((child = vfork()) == 0) { + signal_set(&child_event, SIGCHLD, child_handler, NULL); + signal_add(&child_event, NULL); + + if ((child_pid = vfork()) == 0) { execlp(start_script, start_script, (char *)NULL); _exit(255); } - if (child == -1) + if (child_pid == -1) err(1, "Could not fork start script"); - waitpid(child, &status, 0); - if (status != 0) - err(1, "Start script failed"); + } else { + clients_started = 1; } - event_set(&listen_event, fd, EV_READ | EV_PERSIST, listen_handler, NULL); - event_add(&listen_event, NULL); - listen_event_socket = fd; - event_dispatch(); (void)close(fd); diff --git a/pkgtools/pbulk/files/pbulk/pscan/master.c b/pkgtools/pbulk/files/pbulk/pscan/master.c index ebaa67f6731..b68b7eb5fd4 100644 --- a/pkgtools/pbulk/files/pbulk/pscan/master.c +++ b/pkgtools/pbulk/files/pbulk/pscan/master.c @@ -1,4 +1,4 @@ -/* $NetBSD: master.c,v 1.5 2008/01/26 00:34:57 joerg Exp $ */ +/* $NetBSD: master.c,v 1.6 2008/01/27 14:01:23 joerg Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. @@ -54,9 +54,12 @@ #include "pbulk.h" #include "pscan.h" +static int clients_started; static LIST_HEAD(, scan_peer) active_peers, inactive_peers; static struct event listen_event; static int listen_event_socket; +static struct event child_event; +static pid_t child_pid; struct scan_peer { LIST_ENTRY(scan_peer) peer_link; @@ -169,10 +172,10 @@ assign_job(struct scan_peer *peer) size_t job_len; uint16_t net_job_len; - peer->job = get_job(); + peer->job = clients_started ? get_job() : NULL; if (peer->job == NULL) { LIST_INSERT_HEAD(&inactive_peers, peer, peer_link); - if (LIST_EMPTY(&active_peers)) + if (LIST_EMPTY(&active_peers) && clients_started) shutdown_master(); return; } @@ -215,6 +218,31 @@ listen_handler(int sock, short event, void *arg) assign_job(peer); } +static void +child_handler(int dummy, short event, void *arg) +{ + struct scan_peer *peer; + int status; + + if (waitpid(child_pid, &status, WNOHANG) == -1) { + if (errno == ECHILD) + return; + err(1, "Could not wait for child"); + } + if (status != 0) + err(1, "Start script failed"); + + clients_started = 1; + signal_del(&child_event); + + while ((peer = LIST_FIRST(&inactive_peers)) != NULL) { + LIST_REMOVE(peer, peer_link); + assign_job(peer); + if (peer-> job == NULL) + break; + } +} + void master_mode(const char *master_port, const char *start_script) { @@ -241,25 +269,24 @@ master_mode(const char *master_port, const char *start_script) if (listen(fd, 5) == -1) err(1, "Could not listen on socket"); + event_set(&listen_event, fd, EV_READ | EV_PERSIST, listen_handler, NULL); + event_add(&listen_event, NULL); + listen_event_socket = fd; + if (start_script) { - pid_t child; - int status; - - if ((child = vfork()) == 0) { + signal_set(&child_event, SIGCHLD, child_handler, NULL); + signal_add(&child_event, NULL); + + if ((child_pid = vfork()) == 0) { execlp(start_script, start_script, (char *)NULL); _exit(255); } - if (child == -1) + if (child_pid == -1) err(1, "Could not fork start script"); - waitpid(child, &status, 0); - if (status != 0) - err(1, "Start script failed"); + } else { + clients_started = 1; } - event_set(&listen_event, fd, EV_READ | EV_PERSIST, listen_handler, NULL); - event_add(&listen_event, NULL); - listen_event_socket = fd; - event_dispatch(); (void)close(fd); |