diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-07-01 01:29:44 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-07-01 01:29:44 +0000 |
commit | b38100974030617ec4fe5b20b38a045df6e92d2d (patch) | |
tree | 084306b7326243a616937e327b3c148edfc2b698 | |
parent | f413e241baa8a1dba0472a0c00e60315a831d315 (diff) | |
download | busybox-w32-b38100974030617ec4fe5b20b38a045df6e92d2d.tar.gz busybox-w32-b38100974030617ec4fe5b20b38a045df6e92d2d.tar.bz2 busybox-w32-b38100974030617ec4fe5b20b38a045df6e92d2d.zip |
2005-06-30 Shaun Jackman <sjackman@gmail.com>
* loginutils/getty.c: (open_tty): Use dup2 instead of close/dup.
-rw-r--r-- | loginutils/getty.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c index d123d4965..9648a1742 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -25,13 +25,14 @@ | |||
25 | #include <fcntl.h> | 25 | #include <fcntl.h> |
26 | #include <stdarg.h> | 26 | #include <stdarg.h> |
27 | #include <ctype.h> | 27 | #include <ctype.h> |
28 | #ifdef CONFIG_FEATURE_UTMP | ||
29 | #include <utmp.h> | ||
30 | #endif | ||
31 | #include <getopt.h> | 28 | #include <getopt.h> |
32 | #include <termios.h> | 29 | #include <termios.h> |
33 | #include "busybox.h" | 30 | #include "busybox.h" |
34 | 31 | ||
32 | #ifdef CONFIG_FEATURE_UTMP | ||
33 | #include <utmp.h> | ||
34 | #endif | ||
35 | |||
35 | #define _PATH_LOGIN "/bin/login" | 36 | #define _PATH_LOGIN "/bin/login" |
36 | 37 | ||
37 | /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */ | 38 | /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */ |
@@ -153,7 +154,7 @@ struct options { | |||
153 | 154 | ||
154 | /* Storage for things detected while the login name was read. */ | 155 | /* Storage for things detected while the login name was read. */ |
155 | 156 | ||
156 | static struct chardata { | 157 | struct chardata { |
157 | int erase; /* erase character */ | 158 | int erase; /* erase character */ |
158 | int kill; /* kill character */ | 159 | int kill; /* kill character */ |
159 | int eol; /* end-of-line character */ | 160 | int eol; /* end-of-line character */ |
@@ -233,9 +234,11 @@ static int caps_lock(const char *s); | |||
233 | static int bcode(char *s); | 234 | static int bcode(char *s); |
234 | static void error(const char *fmt, ...) __attribute__ ((noreturn)); | 235 | static void error(const char *fmt, ...) __attribute__ ((noreturn)); |
235 | 236 | ||
237 | #ifdef SYSV_STYLE | ||
236 | #ifdef CONFIG_FEATURE_UTMP | 238 | #ifdef CONFIG_FEATURE_UTMP |
237 | static void update_utmp(char *line); | 239 | static void update_utmp(char *line); |
238 | #endif | 240 | #endif |
241 | #endif | ||
239 | 242 | ||
240 | /* The following is used for understandable diagnostics. */ | 243 | /* The following is used for understandable diagnostics. */ |
241 | 244 | ||
@@ -552,16 +555,11 @@ static void update_utmp(char *line) | |||
552 | /* open_tty - set up tty as standard { input, output, error } */ | 555 | /* open_tty - set up tty as standard { input, output, error } */ |
553 | static void open_tty(char *tty, struct termio *tp, int local) | 556 | static void open_tty(char *tty, struct termio *tp, int local) |
554 | { | 557 | { |
555 | /* Get rid of the present standard { output, error} if any. */ | ||
556 | |||
557 | (void) close(1); | ||
558 | (void) close(2); | ||
559 | errno = 0; /* ignore above errors */ | ||
560 | |||
561 | /* Set up new standard input, unless we are given an already opened port. */ | 558 | /* Set up new standard input, unless we are given an already opened port. */ |
562 | 559 | ||
563 | if (strcmp(tty, "-")) { | 560 | if (strcmp(tty, "-")) { |
564 | struct stat st; | 561 | struct stat st; |
562 | int fd; | ||
565 | 563 | ||
566 | /* Sanity checks... */ | 564 | /* Sanity checks... */ |
567 | 565 | ||
@@ -574,12 +572,11 @@ static void open_tty(char *tty, struct termio *tp, int local) | |||
574 | 572 | ||
575 | /* Open the tty as standard input. */ | 573 | /* Open the tty as standard input. */ |
576 | 574 | ||
577 | (void) close(0); | ||
578 | errno = 0; /* ignore close(2) errors */ | ||
579 | |||
580 | debug("open(2)\n"); | 575 | debug("open(2)\n"); |
581 | if (open(tty, O_RDWR | O_NONBLOCK, 0) != 0) | 576 | fd = open(tty, O_RDWR | O_NONBLOCK, 0); |
577 | if (dup2(fd, STDIN_FILENO) == -1) | ||
582 | error("/dev/%s: cannot open as standard input: %m", tty); | 578 | error("/dev/%s: cannot open as standard input: %m", tty); |
579 | close(fd); | ||
583 | 580 | ||
584 | } else { | 581 | } else { |
585 | 582 | ||
@@ -592,9 +589,10 @@ static void open_tty(char *tty, struct termio *tp, int local) | |||
592 | error("%s: not open for read/write", tty); | 589 | error("%s: not open for read/write", tty); |
593 | } | 590 | } |
594 | 591 | ||
595 | /* Set up standard output and standard error file descriptors. */ | 592 | /* Replace current standard output/error fd's with new ones */ |
596 | debug("duping\n"); | 593 | debug("duping\n"); |
597 | if (dup(0) != 1 || dup(0) != 2) /* set up stdout and stderr */ | 594 | if (dup2(STDIN_FILENO, STDOUT_FILENO) == -1 || |
595 | dup2(STDIN_FILENO, STDERR_FILENO) == -1) | ||
598 | error("%s: dup problem: %m", tty); /* we have a problem */ | 596 | error("%s: dup problem: %m", tty); /* we have a problem */ |
599 | 597 | ||
600 | /* | 598 | /* |