/*#define DEBUG 1 */
#define DEBUG 0
-#include "busybox.h"
+#include "libbb.h"
#if DEBUG
#define TELCMDS
/* child */
+ /* make new process group */
+ setsid();
+
/* 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());
+ tcsetpgrp(0, getpid()); /* comment? */
/* The pseudo-terminal allocated to the client is configured to operate in
* cooked mode, and with XTABS CRMOD enabled (see tty(4)). */
#endif
-int
-telnetd_main(int argc, char **argv)
+int telnetd_main(int argc, char **argv);
+int telnetd_main(int argc, char **argv)
{
fd_set rdfdset, wrfdset;
unsigned opt;
master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
xlisten(master_fd, 1);
if (!(opt & OPT_FOREGROUND))
- xdaemon(0, 0);
+ bb_daemonize(DAEMON_CHDIR_ROOT);
}
#else
sessions = make_new_session();