diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-30 23:50:48 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-30 23:50:48 +0000 |
commit | 96e1b38586e80a0f014038bf4fdf4689c668fbd6 (patch) | |
tree | d7f6a7866700601598cfcc006b7dcb6cb4a7c07e /runit | |
parent | deabacdf91c6d1c3cfcdb4cd06780807193de81d (diff) | |
download | busybox-w32-96e1b38586e80a0f014038bf4fdf4689c668fbd6.tar.gz busybox-w32-96e1b38586e80a0f014038bf4fdf4689c668fbd6.tar.bz2 busybox-w32-96e1b38586e80a0f014038bf4fdf4689c668fbd6.zip |
introduce and use close_on_exec_on(fd). -50 bytes.
Diffstat (limited to 'runit')
-rw-r--r-- | runit/runit_lib.c | 5 | ||||
-rw-r--r-- | runit/runit_lib.h | 2 | ||||
-rw-r--r-- | runit/runsv.c | 24 | ||||
-rw-r--r-- | runit/runsvdir.c | 6 | ||||
-rw-r--r-- | runit/svlogd.c | 10 |
5 files changed, 20 insertions, 27 deletions
diff --git a/runit/runit_lib.c b/runit/runit_lib.c index 4b7950ca3..2ed9054fd 100644 --- a/runit/runit_lib.c +++ b/runit/runit_lib.c | |||
@@ -50,11 +50,6 @@ unsigned byte_chr(char *s,unsigned n,int c) | |||
50 | return t - s; | 50 | return t - s; |
51 | } | 51 | } |
52 | 52 | ||
53 | int coe(int fd) | ||
54 | { | ||
55 | return fcntl(fd, F_SETFD, FD_CLOEXEC); | ||
56 | } | ||
57 | |||
58 | #ifdef UNUSED | 53 | #ifdef UNUSED |
59 | static /* as it isn't used anywhere else */ | 54 | static /* as it isn't used anywhere else */ |
60 | void tai_pack(char *s, const struct tai *t) | 55 | void tai_pack(char *s, const struct tai *t) |
diff --git a/runit/runit_lib.h b/runit/runit_lib.h index c644f5b9d..4b9482024 100644 --- a/runit/runit_lib.h +++ b/runit/runit_lib.h | |||
@@ -27,8 +27,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
27 | 27 | ||
28 | extern unsigned byte_chr(char *s,unsigned n,int c); | 28 | extern unsigned byte_chr(char *s,unsigned n,int c); |
29 | 29 | ||
30 | extern int coe(int); | ||
31 | |||
32 | #define direntry struct dirent | 30 | #define direntry struct dirent |
33 | 31 | ||
34 | //struct tai { | 32 | //struct tai { |
diff --git a/runit/runsv.c b/runit/runsv.c index 1ee3dda01..7cf142d8a 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -454,8 +454,8 @@ int runsv_main(int argc, char **argv) | |||
454 | dir = argv[1]; | 454 | dir = argv[1]; |
455 | 455 | ||
456 | xpipe(selfpipe); | 456 | xpipe(selfpipe); |
457 | coe(selfpipe[0]); | 457 | close_on_exec_on(selfpipe[0]); |
458 | coe(selfpipe[1]); | 458 | close_on_exec_on(selfpipe[1]); |
459 | ndelay_on(selfpipe[0]); | 459 | ndelay_on(selfpipe[0]); |
460 | ndelay_on(selfpipe[1]); | 460 | ndelay_on(selfpipe[1]); |
461 | 461 | ||
@@ -491,8 +491,8 @@ int runsv_main(int argc, char **argv) | |||
491 | if (stat("log/down", &s) != -1) | 491 | if (stat("log/down", &s) != -1) |
492 | svd[1].want = W_DOWN; | 492 | svd[1].want = W_DOWN; |
493 | xpipe(logpipe); | 493 | xpipe(logpipe); |
494 | coe(logpipe[0]); | 494 | close_on_exec_on(logpipe[0]); |
495 | coe(logpipe[1]); | 495 | close_on_exec_on(logpipe[1]); |
496 | } | 496 | } |
497 | } | 497 | } |
498 | 498 | ||
@@ -512,7 +512,7 @@ int runsv_main(int argc, char **argv) | |||
512 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); | 512 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); |
513 | if (lock_exnb(svd[0].fdlock) == -1) | 513 | if (lock_exnb(svd[0].fdlock) == -1) |
514 | fatal_cannot("lock supervise/lock"); | 514 | fatal_cannot("lock supervise/lock"); |
515 | coe(svd[0].fdlock); | 515 | close_on_exec_on(svd[0].fdlock); |
516 | if (haslog) { | 516 | if (haslog) { |
517 | if (mkdir("log/supervise", 0700) == -1) { | 517 | if (mkdir("log/supervise", 0700) == -1) { |
518 | r = readlink("log/supervise", buf, 256); | 518 | r = readlink("log/supervise", buf, 256); |
@@ -536,30 +536,30 @@ int runsv_main(int argc, char **argv) | |||
536 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); | 536 | O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); |
537 | if (lock_ex(svd[1].fdlock) == -1) | 537 | if (lock_ex(svd[1].fdlock) == -1) |
538 | fatal_cannot("lock log/supervise/lock"); | 538 | fatal_cannot("lock log/supervise/lock"); |
539 | coe(svd[1].fdlock); | 539 | close_on_exec_on(svd[1].fdlock); |
540 | } | 540 | } |
541 | 541 | ||
542 | mkfifo("log/supervise/control"+4, 0600); | 542 | mkfifo("log/supervise/control"+4, 0600); |
543 | svd[0].fdcontrol = xopen("log/supervise/control"+4, O_RDONLY|O_NDELAY); | 543 | svd[0].fdcontrol = xopen("log/supervise/control"+4, O_RDONLY|O_NDELAY); |
544 | coe(svd[0].fdcontrol); | 544 | close_on_exec_on(svd[0].fdcontrol); |
545 | svd[0].fdcontrolwrite = xopen("log/supervise/control"+4, O_WRONLY|O_NDELAY); | 545 | svd[0].fdcontrolwrite = xopen("log/supervise/control"+4, O_WRONLY|O_NDELAY); |
546 | coe(svd[0].fdcontrolwrite); | 546 | close_on_exec_on(svd[0].fdcontrolwrite); |
547 | update_status(&svd[0]); | 547 | update_status(&svd[0]); |
548 | if (haslog) { | 548 | if (haslog) { |
549 | mkfifo("log/supervise/control", 0600); | 549 | mkfifo("log/supervise/control", 0600); |
550 | svd[1].fdcontrol = xopen("log/supervise/control", O_RDONLY|O_NDELAY); | 550 | svd[1].fdcontrol = xopen("log/supervise/control", O_RDONLY|O_NDELAY); |
551 | coe(svd[1].fdcontrol); | 551 | close_on_exec_on(svd[1].fdcontrol); |
552 | svd[1].fdcontrolwrite = xopen("log/supervise/control", O_WRONLY|O_NDELAY); | 552 | svd[1].fdcontrolwrite = xopen("log/supervise/control", O_WRONLY|O_NDELAY); |
553 | coe(svd[1].fdcontrolwrite); | 553 | close_on_exec_on(svd[1].fdcontrolwrite); |
554 | update_status(&svd[1]); | 554 | update_status(&svd[1]); |
555 | } | 555 | } |
556 | mkfifo("log/supervise/ok"+4, 0600); | 556 | mkfifo("log/supervise/ok"+4, 0600); |
557 | fd = xopen("log/supervise/ok"+4, O_RDONLY|O_NDELAY); | 557 | fd = xopen("log/supervise/ok"+4, O_RDONLY|O_NDELAY); |
558 | coe(fd); | 558 | close_on_exec_on(fd); |
559 | if (haslog) { | 559 | if (haslog) { |
560 | mkfifo("log/supervise/ok", 0600); | 560 | mkfifo("log/supervise/ok", 0600); |
561 | fd = xopen("log/supervise/ok", O_RDONLY|O_NDELAY); | 561 | fd = xopen("log/supervise/ok", O_RDONLY|O_NDELAY); |
562 | coe(fd); | 562 | close_on_exec_on(fd); |
563 | } | 563 | } |
564 | for (;;) { | 564 | for (;;) { |
565 | struct pollfd x[3]; | 565 | struct pollfd x[3]; |
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 8d25923d4..924f771b7 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
@@ -190,8 +190,8 @@ static int setup_log(void) | |||
190 | warnx("cannot create pipe for log"); | 190 | warnx("cannot create pipe for log"); |
191 | return -1; | 191 | return -1; |
192 | } | 192 | } |
193 | coe(logpipe[1]); | 193 | close_on_exec_on(logpipe[1]); |
194 | coe(logpipe[0]); | 194 | close_on_exec_on(logpipe[0]); |
195 | ndelay_on(logpipe[0]); | 195 | ndelay_on(logpipe[0]); |
196 | ndelay_on(logpipe[1]); | 196 | ndelay_on(logpipe[1]); |
197 | if (dup2(logpipe[1], 2) == -1) { | 197 | if (dup2(logpipe[1], 2) == -1) { |
@@ -245,7 +245,7 @@ int runsvdir_main(int argc, char **argv) | |||
245 | curdir = open_read("."); | 245 | curdir = open_read("."); |
246 | if (curdir == -1) | 246 | if (curdir == -1) |
247 | fatal2_cannot("open current directory", ""); | 247 | fatal2_cannot("open current directory", ""); |
248 | coe(curdir); | 248 | close_on_exec_on(curdir); |
249 | 249 | ||
250 | stampcheck = monotonic_sec(); | 250 | stampcheck = monotonic_sec(); |
251 | 251 | ||
diff --git a/runit/svlogd.c b/runit/svlogd.c index b5eed15ab..cdf4e424b 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -361,7 +361,7 @@ static unsigned rotate(struct logdir *ld) | |||
361 | /* we presume this cannot fail */ | 361 | /* we presume this cannot fail */ |
362 | ld->filecur = fdopen(ld->fdcur, "a"); //// | 362 | ld->filecur = fdopen(ld->fdcur, "a"); //// |
363 | setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// | 363 | setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// |
364 | coe(ld->fdcur); | 364 | close_on_exec_on(ld->fdcur); |
365 | ld->size = 0; | 365 | ld->size = 0; |
366 | while (fchmod(ld->fdcur, 0644) == -1) | 366 | while (fchmod(ld->fdcur, 0644) == -1) |
367 | pause2cannot("set mode of current", ld->name); | 367 | pause2cannot("set mode of current", ld->name); |
@@ -482,7 +482,7 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
482 | warn2("cannot open log directory", (char*)fn); | 482 | warn2("cannot open log directory", (char*)fn); |
483 | return 0; | 483 | return 0; |
484 | } | 484 | } |
485 | coe(ld->fddir); | 485 | close_on_exec_on(ld->fddir); |
486 | if (fchdir(ld->fddir) == -1) { | 486 | if (fchdir(ld->fddir) == -1) { |
487 | logdir_close(ld); | 487 | logdir_close(ld); |
488 | warn2("cannot change directory", (char*)fn); | 488 | warn2("cannot change directory", (char*)fn); |
@@ -498,7 +498,7 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
498 | pause1cannot("change to initial working directory"); | 498 | pause1cannot("change to initial working directory"); |
499 | return 0; | 499 | return 0; |
500 | } | 500 | } |
501 | coe(ld->fdlock); | 501 | close_on_exec_on(ld->fdlock); |
502 | 502 | ||
503 | ld->size = 0; | 503 | ld->size = 0; |
504 | ld->sizemax = 1000000; | 504 | ld->sizemax = 1000000; |
@@ -624,7 +624,7 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
624 | ld->filecur = fdopen(ld->fdcur, "a"); //// | 624 | ld->filecur = fdopen(ld->fdcur, "a"); //// |
625 | setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// | 625 | setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// |
626 | 626 | ||
627 | coe(ld->fdcur); | 627 | close_on_exec_on(ld->fdcur); |
628 | while (fchmod(ld->fdcur, 0644) == -1) | 628 | while (fchmod(ld->fdcur, 0644) == -1) |
629 | pause2cannot("set mode of current", ld->name); | 629 | pause2cannot("set mode of current", ld->name); |
630 | 630 | ||
@@ -851,7 +851,7 @@ int svlogd_main(int argc, char **argv) | |||
851 | if (dirn <= 0) usage(); | 851 | if (dirn <= 0) usage(); |
852 | ////if (buflen <= linemax) usage(); | 852 | ////if (buflen <= linemax) usage(); |
853 | fdwdir = xopen(".", O_RDONLY|O_NDELAY); | 853 | fdwdir = xopen(".", O_RDONLY|O_NDELAY); |
854 | coe(fdwdir); | 854 | close_on_exec_on(fdwdir); |
855 | dir = xzalloc(dirn * sizeof(struct logdir)); | 855 | dir = xzalloc(dirn * sizeof(struct logdir)); |
856 | for (i = 0; i < dirn; ++i) { | 856 | for (i = 0; i < dirn; ++i) { |
857 | dir[i].fddir = -1; | 857 | dir[i].fddir = -1; |