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();
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)). */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user