aboutsummaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-19 21:19:35 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-19 21:19:35 +0000
commit9af7c9d6b62ceb07a9ba24cee0cf4a08c689235e (patch)
tree69a650a8cd686f21087fc572a995420b6ac632cc /loginutils
parentf8c11aa65df2af4ab20c0effc42997bbd7357cc3 (diff)
downloadbusybox-w32-9af7c9d6b62ceb07a9ba24cee0cf4a08c689235e.tar.gz
busybox-w32-9af7c9d6b62ceb07a9ba24cee0cf4a08c689235e.tar.bz2
busybox-w32-9af7c9d6b62ceb07a9ba24cee0cf4a08c689235e.zip
openvt,getty,vfork_daemon_rexec,mount: tighten up fd cleanup code
(will close all fd's > 2 on daemonization now) getty: fix "getty -" support, and also do not try to chown/chmod "-" telnetd: fix "lost ctty" bug Yet another attempt on saner function names: bb_sanitize_server_stdio(0/1) -> bb_sanitize_stdio() + bb_daemonize();
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/getty.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 5ceaefcac..be4938972 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -211,7 +211,7 @@ static void parse_args(int argc, char **argv, struct options *op)
211 bb_show_usage(); 211 bb_show_usage();
212 212
213 /* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */ 213 /* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
214 if ('0' <= argv[0][0] && argv[0][0] <= '9') { 214 if (isdigit(argv[0][0])) {
215 /* a number first, assume it's a speed (BSD style) */ 215 /* a number first, assume it's a speed (BSD style) */
216 parse_speeds(op, argv[0]); /* baud rate(s) */ 216 parse_speeds(op, argv[0]); /* baud rate(s) */
217 op->tty = argv[1]; /* tty name */ 217 op->tty = argv[1]; /* tty name */
@@ -255,10 +255,8 @@ static void open_tty(char *tty, struct termios *tp, int local)
255 255
256 debug("open(2)\n"); 256 debug("open(2)\n");
257 fd = xopen(tty, O_RDWR | O_NONBLOCK); 257 fd = xopen(tty, O_RDWR | O_NONBLOCK);
258 if (fd) { 258 xdup2(fd, 0, tty);
259 xdup2(fd, 0, tty); 259 while (fd > 2) close(fd--);
260 close(fd);
261 }
262 } else { 260 } else {
263 /* 261 /*
264 * Standard input should already be connected to an open port. Make 262 * Standard input should already be connected to an open port. Make
@@ -327,8 +325,10 @@ static void open_tty(char *tty, struct termios *tp, int local)
327 } 325 }
328 } 326 }
329#else 327#else
330 chown(tty, 0, 0); /* root, sys */ 328 if (NOT_LONE_DASH(tty)) {
331 chmod(tty, 0622); /* crw--w--w- */ 329 chown(tty, 0, 0); /* 0:0 */
330 chmod(tty, 0622); /* crw--w--w- */
331 }
332#endif 332#endif
333 if (chdir_to_root) 333 if (chdir_to_root)
334 xchdir("/"); 334 xchdir("/");
@@ -736,22 +736,14 @@ int getty_main(int argc, char **argv)
736 /* Already too late because of theoretical 736 /* Already too late because of theoretical
737 * possibility of getty --help somehow triggered 737 * possibility of getty --help somehow triggered
738 * inadvertently before we reach this. Oh well. */ 738 * inadvertently before we reach this. Oh well. */
739 close(0);
740 close(1);
741 close(2);
742 logmode = LOGMODE_NONE; 739 logmode = LOGMODE_NONE;
743#ifdef __linux__
744 setsid(); 740 setsid();
745#endif
746 /* Was "/dev/console". Why should we spam *system console*
747 * if there is a problem with getty on /dev/ttyS15?... */
748 nullfd = xopen(bb_dev_null, O_RDWR); 741 nullfd = xopen(bb_dev_null, O_RDWR);
749 if (nullfd) { 742 /* dup2(nullfd, 0); - no, because of possible "getty - 9600" */
750 dup2(nullfd, 0); 743 /* open_tty() will take care of fd# 0 anyway */
751 close(nullfd); 744 dup2(nullfd, 1);
752 } 745 dup2(nullfd, 2);
753 dup2(0, 1); 746 while (nullfd > 2) close(nullfd--);
754 dup2(0, 2);
755 /* We want special flavor of error_msg_and_die */ 747 /* We want special flavor of error_msg_and_die */
756 die_sleep = 10; 748 die_sleep = 10;
757 msg_eol = "\r\n"; 749 msg_eol = "\r\n";