From 9af7c9d6b62ceb07a9ba24cee0cf4a08c689235e Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Fri, 19 Jan 2007 21:19:35 +0000 Subject: 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(); --- networking/fakeidentd.c | 2 ++ networking/inetd.c | 4 ++-- networking/isrv_identd.c | 2 +- networking/telnetd.c | 12 ++++++++---- networking/zcip.c | 5 +++-- 5 files changed, 16 insertions(+), 9 deletions(-) (limited to 'networking') diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c index 8c07082fc..6f766a827 100644 --- a/networking/fakeidentd.c +++ b/networking/fakeidentd.c @@ -1,3 +1,5 @@ +/* NB: this file is to be removed soon. See isrv_identd.c */ + /* vi: set sw=4 ts=4: */ /* * A fake identd server diff --git a/networking/inetd.c b/networking/inetd.c index 370dcbbe0..218f85e53 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -1292,9 +1292,9 @@ inetd_main(int argc, char *argv[]) /* reexec for vfork() do continue parent */ vfork_daemon_rexec(0, 0, argc, argv, "-f"); } - bb_sanitize_server_stdio(0); + bb_sanitize_stdio(); #else - bb_sanitize_server_stdio(!(opt & 2)); + bb_sanitize_stdio_maybe_daemonize(!(opt & 2)); #endif openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON); logmode = LOGMODE_SYSLOG; diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index e757d7c29..2d4399cea 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c @@ -111,7 +111,7 @@ int fakeidentd_main(int argc, char **argv) bogouser = argv[optind]; /* Daemonize if no -f and no -i and no -w */ - bb_sanitize_server_stdio(!(opt & OPT_fiw)); + bb_sanitize_stdio_maybe_daemonize(!(opt & OPT_fiw)); /* Where to log in inetd modes? "Classic" inetd * probably has its stderr /dev/null'ed (we need log to syslog?), * but daemontools-like utilities usually expect that children diff --git a/networking/telnetd.c b/networking/telnetd.c index 51bd0c012..25cba3eb0 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c @@ -283,15 +283,19 @@ make_new_session( /* child */ + /* make new process group */ + setsid(); + tcsetpgrp(0, getpid()); + /* ^^^ strace says: "ioctl(0, TIOCSPGRP, [pid]) = -1 ENOTTY" -- ??! */ + /* open the child's side of the tty. */ - fd = xopen(tty_name, O_RDWR /*| O_NOCTTY*/); + /* NB: setsid() disconnects from any previous ctty's. Therefore + * we must open child's side of the tty AFTER setsid! */ + fd = xopen(tty_name, O_RDWR); /* becomes our ctty */ dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); while (fd > 2) close(fd--); - /* make new process group */ - setsid(); - tcsetpgrp(0, getpid()); /* The pseudo-terminal allocated to the client is configured to operate in * cooked mode, and with XTABS CRMOD enabled (see tty(4)). */ diff --git a/networking/zcip.c b/networking/zcip.c index 27e281c93..5d57c4287 100644 --- a/networking/zcip.c +++ b/networking/zcip.c @@ -221,7 +221,8 @@ int zcip_main(int argc, char *argv[]) } if (opts & 4) { // -r n.n.n.n if (inet_aton(r_opt, &ip) == 0 - || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { + || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR + ) { bb_error_msg_and_die("invalid link address"); } } @@ -270,7 +271,7 @@ int zcip_main(int argc, char *argv[]) // daemonize now; don't delay system startup if (!FOREGROUND) { setsid(); - xdaemon(0, 0); + bb_daemonize(); bb_info_msg("start, interface %s", intf); } -- cgit v1.2.3