pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pbulk pbulk-0.27:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3d134d6b48e9
branches:  trunk
changeset: 538072:3d134d6b48e9
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Jan 27 14:01:23 2008 +0000

description:
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:

 pkgtools/pbulk/Makefile                    |   4 +-
 pkgtools/pbulk/files/pbulk/pbuild/master.c |  55 +++++++++++++++++++++-------
 pkgtools/pbulk/files/pbulk/pscan/master.c  |  57 ++++++++++++++++++++++-------
 3 files changed, 84 insertions(+), 32 deletions(-)

diffs (218 lines):

diff -r 98590dd4159a -r 3d134d6b48e9 pkgtools/pbulk/Makefile
--- a/pkgtools/pbulk/Makefile   Sun Jan 27 12:35:35 2008 +0000
+++ b/pkgtools/pbulk/Makefile   Sun Jan 27 14:01:23 2008 +0000
@@ -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 -r 98590dd4159a -r 3d134d6b48e9 pkgtools/pbulk/files/pbulk/pbuild/master.c
--- a/pkgtools/pbulk/files/pbulk/pbuild/master.c        Sun Jan 27 12:35:35 2008 +0000
+++ b/pkgtools/pbulk/files/pbulk/pbuild/master.c        Sun Jan 27 14:01:23 2008 +0000
@@ -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@localhost>.
@@ -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 @@
 
        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 @@
        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 @@
        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 -r 98590dd4159a -r 3d134d6b48e9 pkgtools/pbulk/files/pbulk/pscan/master.c
--- a/pkgtools/pbulk/files/pbulk/pscan/master.c Sun Jan 27 12:35:35 2008 +0000
+++ b/pkgtools/pbulk/files/pbulk/pscan/master.c Sun Jan 27 14:01:23 2008 +0000
@@ -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@localhost>.
@@ -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 @@
        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 @@
        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 @@
        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);



Home | Main Index | Thread Index | Old Index