-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]>. | ||
|
@@ -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; | ||
|
@@ -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) | ||
{ | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]>. | ||
|
@@ -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; | ||
|
@@ -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) | ||
{ | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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(); | ||
|
||
|