pbulk-base-0.47: Portability fixes - Prefer fcntl FD_CLOEXEC to ioctl FIOCLEX. - Reset SIGPIPE action to default for the build child, avoids 'yes' spinning indefinitely on EPIPE in Solaris builds, notably for print/pdf2djvu.diff -r1.10 -r1.11 pkgsrc/pkgtools/pbulk-base/Makefile
(jperkin)
@@ -1,16 +1,16 @@ | @@ -1,16 +1,16 @@ | |||
1 | # $NetBSD: Makefile,v 1.10 2012/11/23 12:13:35 joerg Exp $ | 1 | # $NetBSD: Makefile,v 1.11 2013/01/14 14:33:29 jperkin Exp $ | |
2 | 2 | |||
3 | DISTNAME= pbulk-base-0.46 | 3 | DISTNAME= pbulk-base-0.47 | |
4 | COMMENT= Core components of the modular bulk build framework | 4 | COMMENT= Core components of the modular bulk build framework | |
5 | 5 | |||
6 | .include "../../pkgtools/pbulk/Makefile.common" | 6 | .include "../../pkgtools/pbulk/Makefile.common" | |
7 | 7 | |||
8 | USE_FEATURES= nbcompat | 8 | USE_FEATURES= nbcompat | |
9 | USE_TOOLS+= groff nroff | 9 | USE_TOOLS+= groff nroff | |
10 | 10 | |||
11 | INSTALLATION_DIRS= bin ${PKGMANDIR}/cat1 ${PKGMANDIR}/man1 | 11 | INSTALLATION_DIRS= bin ${PKGMANDIR}/cat1 ${PKGMANDIR}/man1 | |
12 | USE_BSD_MAKEFILE= yes | 12 | USE_BSD_MAKEFILE= yes | |
13 | 13 | |||
14 | CONFLICTS= pbulk<0.39 | 14 | CONFLICTS= pbulk<0.39 | |
15 | 15 | |||
16 | .include "../../mk/bsd.prefs.mk" | 16 | .include "../../mk/bsd.prefs.mk" |
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: master.c,v 1.8 2009/01/31 23:25:38 joerg Exp $ */ | 1 | /* $NetBSD: master.c,v 1.9 2013/01/14 14:33:28 jperkin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. | 4 | * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code was developed as part of Google's Summer of Code 2007 program. | 7 | * This code was developed as part of Google's Summer of Code 2007 program. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * | 12 | * | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -25,34 +25,32 @@ | @@ -25,34 +25,32 @@ | |||
25 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <nbcompat.h> | 34 | #include <nbcompat.h> | |
35 | 35 | |||
36 | #include <nbcompat/types.h> | 36 | #include <nbcompat/types.h> | |
37 | #include <sys/ioctl.h> | 37 | #include <sys/ioctl.h> | |
38 | #ifdef __sun | |||
39 | #include <sys/filio.h> | |||
40 | #endif | |||
41 | #include <nbcompat/queue.h> | 38 | #include <nbcompat/queue.h> | |
42 | #include <sys/socket.h> | 39 | #include <sys/socket.h> | |
43 | #include <nbcompat/time.h> | 40 | #include <nbcompat/time.h> | |
44 | #include <sys/wait.h> | 41 | #include <sys/wait.h> | |
45 | #include <nbcompat/err.h> | 42 | #include <nbcompat/err.h> | |
43 | #include <fcntl.h> | |||
46 | #include <signal.h> | 44 | #include <signal.h> | |
47 | #include <nbcompat/stdlib.h> | 45 | #include <nbcompat/stdlib.h> | |
48 | #include <nbcompat/stdio.h> | 46 | #include <nbcompat/stdio.h> | |
49 | #include <nbcompat/string.h> | 47 | #include <nbcompat/string.h> | |
50 | 48 | |||
51 | #include <arpa/inet.h> | 49 | #include <arpa/inet.h> | |
52 | 50 | |||
53 | #include "pbulk.h" | 51 | #include "pbulk.h" | |
54 | #include "pbuild.h" | 52 | #include "pbuild.h" | |
55 | 53 | |||
56 | static int clients_started; | 54 | static int clients_started; | |
57 | static LIST_HEAD(, build_peer) active_peers, inactive_peers, unassigned_peers; | 55 | static LIST_HEAD(, build_peer) active_peers, inactive_peers, unassigned_peers; | |
58 | static struct event listen_event; | 56 | static struct event listen_event; | |
@@ -298,30 +296,28 @@ master_mode(const char *master_port, con | @@ -298,30 +296,28 @@ master_mode(const char *master_port, con | |||
298 | 296 | |||
299 | LIST_INIT(&active_peers); | 297 | LIST_INIT(&active_peers); | |
300 | LIST_INIT(&inactive_peers); | 298 | LIST_INIT(&inactive_peers); | |
301 | LIST_INIT(&unassigned_peers); | 299 | LIST_INIT(&unassigned_peers); | |
302 | 300 | |||
303 | event_init(); | 301 | event_init(); | |
304 | 302 | |||
305 | if (parse_sockaddr_in(master_port, &dst)) | 303 | if (parse_sockaddr_in(master_port, &dst)) | |
306 | errx(1, "Could not parse addr/port"); | 304 | errx(1, "Could not parse addr/port"); | |
307 | 305 | |||
308 | fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 306 | fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | |
309 | if (fd == -1) | 307 | if (fd == -1) | |
310 | err(1, "Could not create socket"); | 308 | err(1, "Could not create socket"); | |
311 | #ifdef FIOCLEX | 309 | if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) | |
312 | if (ioctl(fd, FIOCLEX, NULL) == -1) | |||
313 | err(1, "Could not set close-on-exec flag"); | 310 | err(1, "Could not set close-on-exec flag"); | |
314 | #endif | |||
315 | if (bind(fd, (struct sockaddr *)&dst, sizeof(dst)) == -1) | 311 | if (bind(fd, (struct sockaddr *)&dst, sizeof(dst)) == -1) | |
316 | err(1, "Could not bind socket"); | 312 | err(1, "Could not bind socket"); | |
317 | if (listen(fd, 5) == -1) | 313 | if (listen(fd, 5) == -1) | |
318 | err(1, "Could not listen on socket"); | 314 | err(1, "Could not listen on socket"); | |
319 | 315 | |||
320 | event_add(&listen_event, fd, 0, 1, listen_handler, NULL); | 316 | event_add(&listen_event, fd, 0, 1, listen_handler, NULL); | |
321 | listen_event_socket = fd; | 317 | listen_event_socket = fd; | |
322 | 318 | |||
323 | if (start_script) { | 319 | if (start_script) { | |
324 | signal_add(&child_event, SIGCHLD, child_handler); | 320 | signal_add(&child_event, SIGCHLD, child_handler); | |
325 | 321 | |||
326 | if ((child_pid = vfork()) == 0) { | 322 | if ((child_pid = vfork()) == 0) { | |
327 | execlp(start_script, start_script, (char *)NULL); | 323 | execlp(start_script, start_script, (char *)NULL); |
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: pbuild.c,v 1.5 2007/08/05 14:15:55 joerg Exp $ */ | 1 | /* $NetBSD: pbuild.c,v 1.6 2013/01/14 14:33:28 jperkin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. | 4 | * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code was developed as part of Google's Summer of Code 2007 program. | 7 | * This code was developed as part of Google's Summer of Code 2007 program. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * | 12 | * | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -164,26 +164,27 @@ main(int argc, char **argv) | @@ -164,26 +164,27 @@ main(int argc, char **argv) | |||
164 | master_mode(master_port, start_script); | 164 | master_mode(master_port, start_script); | |
165 | else | 165 | else | |
166 | standalone_mode(); | 166 | standalone_mode(); | |
167 | 167 | |||
168 | if (report_file) | 168 | if (report_file) | |
169 | finish_build(report_file); | 169 | finish_build(report_file); | |
170 | 170 | |||
171 | return 0; | 171 | return 0; | |
172 | } | 172 | } | |
173 | 173 | |||
174 | int | 174 | int | |
175 | build_package(const char *build_info, size_t len) | 175 | build_package(const char *build_info, size_t len) | |
176 | { | 176 | { | |
177 | struct sigaction sa; | |||
177 | int input[2]; | 178 | int input[2]; | |
178 | pid_t child; | 179 | pid_t child; | |
179 | 180 | |||
180 | if (pipe(input) == -1) | 181 | if (pipe(input) == -1) | |
181 | err(1, "Failed to create pipe"); | 182 | err(1, "Failed to create pipe"); | |
182 | 183 | |||
183 | child = vfork(); | 184 | child = vfork(); | |
184 | if (child == -1) | 185 | if (child == -1) | |
185 | err(1, "Failed to create child"); | 186 | err(1, "Failed to create child"); | |
186 | if (child != 0) { | 187 | if (child != 0) { | |
187 | ssize_t bytes_written; | 188 | ssize_t bytes_written; | |
188 | const char *begin; | 189 | const char *begin; | |
189 | size_t bytes_left; | 190 | size_t bytes_left; | |
@@ -200,26 +201,35 @@ build_package(const char *build_info, si | @@ -200,26 +201,35 @@ build_package(const char *build_info, si | |||
200 | (void)close(input[1]); | 201 | (void)close(input[1]); | |
201 | (void)kill(child, SIGTERM); | 202 | (void)kill(child, SIGTERM); | |
202 | (void)waitpid(child, &ret, 0); | 203 | (void)waitpid(child, &ret, 0); | |
203 | return 1; | 204 | return 1; | |
204 | } | 205 | } | |
205 | bytes_left -= bytes_written; | 206 | bytes_left -= bytes_written; | |
206 | begin += bytes_written; | 207 | begin += bytes_written; | |
207 | } | 208 | } | |
208 | (void)close(input[1]); | 209 | (void)close(input[1]); | |
209 | (void)waitpid(child, &ret, 0); | 210 | (void)waitpid(child, &ret, 0); | |
210 | return ret; | 211 | return ret; | |
211 | } | 212 | } | |
212 | 213 | |||
214 | /* Reset SIGPIPE handling for child */ | |||
215 | #if !defined(__INTERIX) | |||
216 | sa.sa_sigaction = NULL; | |||
217 | #endif | |||
218 | sa.sa_handler = SIG_DFL; | |||
219 | sa.sa_flags = 0; | |||
220 | (void)sigemptyset(&sa.sa_mask); | |||
221 | (void)sigaction(SIGPIPE, (struct sigaction *)&sa, NULL); | |||
222 | ||||
213 | (void)close(input[1]); | 223 | (void)close(input[1]); | |
214 | if (dup2(input[0], 0) == -1) { | 224 | if (dup2(input[0], 0) == -1) { | |
215 | const char err_msg[] = "dup failed for stdin\n"; | 225 | const char err_msg[] = "dup failed for stdin\n"; | |
216 | 226 | |||
217 | (void)write(STDERR_FILENO, err_msg, sizeof(err_msg) - 1); | 227 | (void)write(STDERR_FILENO, err_msg, sizeof(err_msg) - 1); | |
218 | _exit(255); | 228 | _exit(255); | |
219 | } | 229 | } | |
220 | 230 | |||
221 | (void)execl(build_path, build_cmd, (char *)NULL); | 231 | (void)execl(build_path, build_cmd, (char *)NULL); | |
222 | _exit(255); | 232 | _exit(255); | |
223 | } | 233 | } | |
224 | 234 | |||
225 | static void | 235 | static void |
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: master.c,v 1.7 2009/01/31 23:25:38 joerg Exp $ */ | 1 | /* $NetBSD: master.c,v 1.8 2013/01/14 14:33:28 jperkin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. | 4 | * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code was developed as part of Google's Summer of Code 2007 program. | 7 | * This code was developed as part of Google's Summer of Code 2007 program. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * | 12 | * | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -26,34 +26,32 @@ | @@ -26,34 +26,32 @@ | |||
26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <nbcompat.h> | 34 | #include <nbcompat.h> | |
35 | 35 | |||
36 | #include <nbcompat/types.h> | 36 | #include <nbcompat/types.h> | |
37 | #include <nbcompat/queue.h> | 37 | #include <nbcompat/queue.h> | |
38 | #include <sys/ioctl.h> | 38 | #include <sys/ioctl.h> | |
39 | #ifdef __sun | |||
40 | #include <sys/filio.h> | |||
41 | #endif | |||
42 | #include <sys/socket.h> | 39 | #include <sys/socket.h> | |
43 | #include <nbcompat/time.h> | 40 | #include <nbcompat/time.h> | |
44 | #include <sys/wait.h> | 41 | #include <sys/wait.h> | |
45 | #include <nbcompat/err.h> | 42 | #include <nbcompat/err.h> | |
46 | #include <signal.h> | 43 | #include <signal.h> | |
44 | #include <fcntl.h> | |||
47 | #include <nbcompat/stdlib.h> | 45 | #include <nbcompat/stdlib.h> | |
48 | #include <nbcompat/stdio.h> | 46 | #include <nbcompat/stdio.h> | |
49 | #include <nbcompat/string.h> | 47 | #include <nbcompat/string.h> | |
50 | 48 | |||
51 | #include <arpa/inet.h> | 49 | #include <arpa/inet.h> | |
52 | 50 | |||
53 | #include "pbulk.h" | 51 | #include "pbulk.h" | |
54 | #include "pscan.h" | 52 | #include "pscan.h" | |
55 | 53 | |||
56 | static int clients_started; | 54 | static int clients_started; | |
57 | static LIST_HEAD(, scan_peer) active_peers, inactive_peers; | 55 | static LIST_HEAD(, scan_peer) active_peers, inactive_peers; | |
58 | static struct event listen_event; | 56 | static struct event listen_event; | |
59 | static int listen_event_socket; | 57 | static int listen_event_socket; | |
@@ -249,30 +247,28 @@ master_mode(const char *master_port, con | @@ -249,30 +247,28 @@ master_mode(const char *master_port, con | |||
249 | int fd; | 247 | int fd; | |
250 | 248 | |||
251 | LIST_INIT(&active_peers); | 249 | LIST_INIT(&active_peers); | |
252 | LIST_INIT(&inactive_peers); | 250 | LIST_INIT(&inactive_peers); | |
253 | 251 | |||
254 | event_init(); | 252 | event_init(); | |
255 | 253 | |||
256 | if (parse_sockaddr_in(master_port, &dst)) | 254 | if (parse_sockaddr_in(master_port, &dst)) | |
257 | errx(1, "Could not parse addr/port"); | 255 | errx(1, "Could not parse addr/port"); | |
258 | 256 | |||
259 | fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 257 | fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | |
260 | if (fd == -1) | 258 | if (fd == -1) | |
261 | err(1, "Could not create socket"); | 259 | err(1, "Could not create socket"); | |
262 | #ifdef FIOCLEX | 260 | if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) | |
263 | if (ioctl(fd, FIOCLEX, NULL) == -1) | |||
264 | err(1, "Could not set close-on-exec flag"); | 261 | err(1, "Could not set close-on-exec flag"); | |
265 | #endif | |||
266 | if (bind(fd, (struct sockaddr *)&dst, sizeof(dst)) == -1) | 262 | if (bind(fd, (struct sockaddr *)&dst, sizeof(dst)) == -1) | |
267 | err(1, "Could not bind socket"); | 263 | err(1, "Could not bind socket"); | |
268 | if (listen(fd, 5) == -1) | 264 | if (listen(fd, 5) == -1) | |
269 | err(1, "Could not listen on socket"); | 265 | err(1, "Could not listen on socket"); | |
270 | 266 | |||
271 | event_add(&listen_event, fd, 0, 1, listen_handler, NULL); | 267 | event_add(&listen_event, fd, 0, 1, listen_handler, NULL); | |
272 | listen_event_socket = fd; | 268 | listen_event_socket = fd; | |
273 | 269 | |||
274 | if (start_script) { | 270 | if (start_script) { | |
275 | signal_add(&child_event, SIGCHLD, child_handler); | 271 | signal_add(&child_event, SIGCHLD, child_handler); | |
276 | 272 | |||
277 | if ((child_pid = vfork()) == 0) { | 273 | if ((child_pid = vfork()) == 0) { | |
278 | execlp(start_script, start_script, (char *)NULL); | 274 | execlp(start_script, start_script, (char *)NULL); |