Skip to content

Commit

Permalink
pbulk-0.24:
Browse files Browse the repository at this point in the history
When all jobs are processed in master mode, close the listen socket
and shutdown(2) all peers. Give them a second to close(2) the
connection themselve, so that the port remains usable on the master.
This is the standard compliant fix for PR 37002.
  • Loading branch information
jsonn committed Jan 26, 2008
1 parent 54a10d8 commit dd28887
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkgtools/pbulk/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.30 2008/01/21 13:11:56 tnn Exp $
# $NetBSD: Makefile,v 1.31 2008/01/26 00:34:57 joerg Exp $

DISTNAME= pbulk-0.23
DISTNAME= pbulk-0.24
CATEGORIES= pkgtools
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
23 changes: 20 additions & 3 deletions pkgtools/pbulk/files/pbulk/pbuild/master.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: master.c,v 1.5 2008/01/15 21:43:32 joerg Exp $ */
/* $NetBSD: master.c,v 1.6 2008/01/26 00:34:57 joerg Exp $ */

/*-
* Copyright (c) 2007 Joerg Sonnenberger <[email protected]>.
Expand Down Expand Up @@ -55,6 +55,8 @@
#include "pbuild.h"

static LIST_HEAD(, build_peer) active_peers, inactive_peers, unassigned_peers;
static struct event listen_event;
static int listen_event_socket;

struct build_peer {
LIST_ENTRY(build_peer) peer_link;
Expand Down Expand Up @@ -169,6 +171,21 @@ send_build_stats(struct build_peer *peer)
deferred_write(peer->fd, peer->buf, 7 * 4, peer, sent_build_stats, kill_peer);
}

static void
shutdown_master(void)
{
struct timeval tv;
struct build_peer *peer;

event_del(&listen_event);
(void)close(listen_event_socket);
LIST_FOREACH(peer, &inactive_peers, peer_link)
(void)shutdown(peer->fd, SHUT_RDWR);
tv.tv_sec = 1;
tv.tv_usec = 0;
event_loopexit(&tv);
}

static void
assign_job(void *arg)
{
Expand All @@ -192,7 +209,7 @@ assign_job(void *arg)
if (peer->job == NULL) {
LIST_INSERT_HEAD(&unassigned_peers, peer, peer_link);
if (LIST_EMPTY(&active_peers))
event_loopexit(NULL);
shutdown_master();
return;
}

Expand Down Expand Up @@ -251,7 +268,6 @@ listen_handler(int sock, short event, void *arg)
void
master_mode(const char *master_port, const char *start_script)
{
struct event listen_event;
struct sockaddr_in dst;
int fd;

Expand Down Expand Up @@ -293,6 +309,7 @@ master_mode(const char *master_port, const char *start_script)

event_set(&listen_event, fd, EV_READ | EV_PERSIST, listen_handler, NULL);
event_add(&listen_event, NULL);
listen_event_socket = fd;

event_dispatch();

Expand Down
23 changes: 20 additions & 3 deletions pkgtools/pbulk/files/pbulk/pscan/master.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: master.c,v 1.4 2007/07/21 15:36:36 tnn Exp $ */
/* $NetBSD: master.c,v 1.5 2008/01/26 00:34:57 joerg Exp $ */

/*-
* Copyright (c) 2007 Joerg Sonnenberger <[email protected]>.
Expand Down Expand Up @@ -55,6 +55,8 @@
#include "pscan.h"

static LIST_HEAD(, scan_peer) active_peers, inactive_peers;
static struct event listen_event;
static int listen_event_socket;

struct scan_peer {
LIST_ENTRY(scan_peer) peer_link;
Expand Down Expand Up @@ -146,6 +148,21 @@ send_job_path(void *arg)
kill_peer);
}

static void
shutdown_master(void)
{
struct timeval tv;
struct scan_peer *peer;

event_del(&listen_event);
(void)close(listen_event_socket);
LIST_FOREACH(peer, &inactive_peers, peer_link)
(void)shutdown(peer->fd, SHUT_RDWR);
tv.tv_sec = 1;
tv.tv_usec = 0;
event_loopexit(&tv);
}

static void
assign_job(struct scan_peer *peer)
{
Expand All @@ -156,7 +173,7 @@ assign_job(struct scan_peer *peer)
if (peer->job == NULL) {
LIST_INSERT_HEAD(&inactive_peers, peer, peer_link);
if (LIST_EMPTY(&active_peers))
event_loopexit(NULL);
shutdown_master();
return;
}

Expand Down Expand Up @@ -201,7 +218,6 @@ listen_handler(int sock, short event, void *arg)
void
master_mode(const char *master_port, const char *start_script)
{
struct event listen_event;
struct sockaddr_in dst;
int fd;

Expand Down Expand Up @@ -242,6 +258,7 @@ master_mode(const char *master_port, const char *start_script)

event_set(&listen_event, fd, EV_READ | EV_PERSIST, listen_handler, NULL);
event_add(&listen_event, NULL);
listen_event_socket = fd;

event_dispatch();

Expand Down

0 comments on commit dd28887

Please sign in to comment.