-#elif defined(SIGTSTP) /* BSD */
- /* change process group */
-#ifndef __EMX__
- setpgrp(0, getpid());
-#endif
- /* lose controlling tty */
- if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
- ioctl(fd, TIOCNOTTY, (char *) 0);
- close(fd); /* not checking should be safe, there were no writes */
- }
-#else /* SVR3 and older */
- /* change process group */
-#ifndef __EMX__
- setpgrp();
-#endif
-
- /* lose controlling tty */
-#ifndef HAVE_SIGACTION
- signal(SIGHUP, SIG_IGN);
-#else
- sigaction (SIGHUP, &sa_new, NULL);
-#endif /* HAVE_SIGACTION */
- if ((childpid = fork()) < 0) {
- report(stderr, "fork (%)\n", strerror(errno));
+
+nottyDetach:
+
+ (void)close(0);
+
+ /* Reopen stdin descriptor on /dev/null */
+ if (open("/dev/null", O_RDWR) < 0) { /* stdin */
+ report(stderr, "cannot open /dev/null: %s\n", strerror(errno));