aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-27 22:21:12 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-27 22:21:12 +0000
commitc6bbd895662dff96ca89c577623e8f1c234b015f (patch)
treeda3276ab5bc224a64fb9f7d7d2a8a046816ec533
parent68382a06482269331d897fa1a178bbc9625ae10c (diff)
downloadbusybox-w32-c6bbd895662dff96ca89c577623e8f1c234b015f.tar.gz
busybox-w32-c6bbd895662dff96ca89c577623e8f1c234b015f.tar.bz2
busybox-w32-c6bbd895662dff96ca89c577623e8f1c234b015f.zip
use bb_sanitize_stdio() where appropriate
git-svn-id: svn://busybox.net/trunk/busybox@17557 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/nohup.c32
-rw-r--r--libbb/xfuncs.c2
-rw-r--r--loginutils/getty.c7
-rw-r--r--networking/traceroute.c6
-rw-r--r--networking/udhcp/common.c16
5 files changed, 27 insertions, 36 deletions
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index 21adfc1c3..317d2a8ae 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -14,16 +14,18 @@
14 14
15int nohup_main(int argc, char **argv) 15int nohup_main(int argc, char **argv)
16{ 16{
17 int temp, nullfd; 17 int nullfd;
18 char *nohupout, *home = NULL; 18 const char *nohupout;
19 char *home = NULL;
19 20
20 xfunc_error_retval = 127; 21 xfunc_error_retval = 127;
21 22
22 if (argc<2) bb_show_usage(); 23 if (argc < 2) bb_show_usage();
23 24
24 nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND); 25 nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
25 /* If stdin is a tty, detach from it. */ 26 /* If stdin is a tty, detach from it. */
26 if (isatty(STDIN_FILENO)) dup2(nullfd, STDIN_FILENO); 27 if (isatty(STDIN_FILENO))
28 dup2(nullfd, STDIN_FILENO);
27 29
28 nohupout = "nohup.out"; 30 nohupout = "nohup.out";
29 /* Redirect stdout to nohup.out, either in "." or in "$HOME". */ 31 /* Redirect stdout to nohup.out, either in "." or in "$HOME". */
@@ -38,16 +40,20 @@ int nohup_main(int argc, char **argv)
38 } 40 }
39 } else dup2(nullfd, STDOUT_FILENO); 41 } else dup2(nullfd, STDOUT_FILENO);
40 42
41 /* If we have a tty on strderr, announce filename and redirect to stdout. 43 /* If we have a tty on stderr, announce filename and redirect to stdout.
42 * Else redirect to /dev/null. 44 * Else redirect to /dev/null.
43 */ 45 */
44 temp = isatty(STDERR_FILENO); 46 if (isatty(STDERR_FILENO)) {
45 if (temp) bb_error_msg("appending to %s", nohupout); 47 bb_error_msg("appending to %s", nohupout);
46 dup2(temp ? STDOUT_FILENO : nullfd, STDERR_FILENO); 48 dup2(STDOUT_FILENO, STDERR_FILENO);
47 close(nullfd); 49 } else dup2(nullfd, STDERR_FILENO);
48 signal (SIGHUP, SIG_IGN); 50
49 51 if (nullfd > 2)
50 execvp(argv[1],argv+1); 52 close(nullfd);
51 if (00 && ENABLE_FEATURE_CLEAN_UP && home) free(nohupout); 53 signal(SIGHUP, SIG_IGN);
54
55 execvp(argv[1], argv+1);
56 if (ENABLE_FEATURE_CLEAN_UP && home)
57 free((char*)nohupout);
52 bb_perror_msg_and_die("%s", argv[1]); 58 bb_perror_msg_and_die("%s", argv[1]);
53} 59}
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index f7300a6d9..54d291ab1 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -518,7 +518,7 @@ void bb_sanitize_stdio_maybe_daemonize(int daemonize)
518 int fd; 518 int fd;
519 /* Mega-paranoid */ 519 /* Mega-paranoid */
520 fd = xopen(bb_dev_null, O_RDWR); 520 fd = xopen(bb_dev_null, O_RDWR);
521 while (fd < 2) 521 while ((unsigned)fd < 2)
522 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ 522 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */
523 if (daemonize) { 523 if (daemonize) {
524 pid_t pid = fork(); 524 pid_t pid = fork();
diff --git a/loginutils/getty.c b/loginutils/getty.c
index be4938972..f2c2b4afb 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -264,7 +264,7 @@ static void open_tty(char *tty, struct termios *tp, int local)
264 */ 264 */
265 265
266 if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR) 266 if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR)
267 bb_error_msg_and_die("%s: not open for read/write", tty); 267 bb_error_msg_and_die("stdin is not open for read/write");
268 } 268 }
269 269
270 /* Replace current standard output/error fd's with new ones */ 270 /* Replace current standard output/error fd's with new ones */
@@ -314,7 +314,8 @@ static void open_tty(char *tty, struct termios *tp, int local)
314 strcpy(vcsa, "vcsa"); 314 strcpy(vcsa, "vcsa");
315 strcpy(vcsa + 4, tty + 3); 315 strcpy(vcsa + 4, tty + 3);
316 316
317 id = (gr = getgrnam("sys")) ? gr->gr_gid : 0; 317 gr = getgrnam("sys");
318 id = gr ? gr->gr_gid : 0;
318 chown(vcs, 0, id); 319 chown(vcs, 0, id);
319 chmod(vcs, 0600); 320 chmod(vcs, 0600);
320 chown(vcsa, 0, id); 321 chown(vcsa, 0, id);
@@ -628,8 +629,8 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
628 tp->c_cflag |= CS7; 629 tp->c_cflag |= CS7;
629 break; 630 break;
630 } 631 }
631 /* Account for upper case without lower case. */
632 632
633 /* Account for upper case without lower case. */
633#ifdef HANDLE_ALLCAPS 634#ifdef HANDLE_ALLCAPS
634 if (cp->capslock) { 635 if (cp->capslock) {
635 tp->c_iflag |= IUCLC; 636 tp->c_iflag |= IUCLC;
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 47775aa8a..25c6569bb 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -1040,10 +1040,8 @@ traceroute_main(int argc, char *argv[])
1040 bb_show_usage(); 1040 bb_show_usage();
1041 } 1041 }
1042 1042
1043 /* Insure the socket fds won't be 0, 1 or 2 */ 1043 /* Ensure the socket fds won't be 0, 1 or 2 */
1044 do n = xopen(bb_dev_null, O_RDONLY); while (n < 2); 1044 bb_sanitize_stdio();
1045 while (n > 2)
1046 close(n--);
1047 1045
1048 s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP); 1046 s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
1049 1047
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index 3e916f422..3704ba71a 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -22,20 +22,6 @@ long uptime(void)
22 return info.uptime; 22 return info.uptime;
23} 23}
24 24
25/*
26 * This function makes sure our first socket calls
27 * aren't going to fd 1 (printf badness...) and are
28 * not later closed by daemon()
29 */
30static inline void sanitize_fds(void)
31{
32 int fd = xopen(bb_dev_null, O_RDWR);
33 while (fd < 3)
34 fd = dup(fd);
35 close(fd);
36}
37
38
39void udhcp_background(const char *pidfile) 25void udhcp_background(const char *pidfile)
40{ 26{
41#ifdef __uClinux__ 27#ifdef __uClinux__
@@ -57,7 +43,7 @@ void udhcp_start_log_and_pid(const char *pidfile)
57 int pid_fd; 43 int pid_fd;
58 44
59 /* Make sure our syslog fd isn't overwritten */ 45 /* Make sure our syslog fd isn't overwritten */
60 sanitize_fds(); 46 bb_sanitize_stdio();
61 47
62 /* do some other misc startup stuff while we are here to save bytes */ 48 /* do some other misc startup stuff while we are here to save bytes */
63 pid_fd = pidfile_acquire(pidfile); 49 pid_fd = pidfile_acquire(pidfile);