-/* --- @u_detach@ --- *
- *
- * Arguments: ---
- *
- * Returns: ---
- *
- * Use: Detaches from the current terminal and ensures it can never
- * acquire a new one. Calls @fork@.
- */
-
-void u_detach(void)
-{
-#ifdef TIOCNOTTY
- {
- int fd;
- if ((fd = open("/dev/tty", O_RDONLY)) >= 0) {
- ioctl(fd, TIOCNOTTY);
- close(fd);
- }
- }
-#endif
- setsid();
- if (fork() > 0)
- _exit(0);
-}
-
-/* --- @u_daemon@ --- *
- *
- * Arguments: ---
- *
- * Returns: Zero if OK, nonzero on failure.
- *
- * Use: Becomes a daemon.
- */
-
-int u_daemon(void)
-{
- pid_t kid;
-
- if ((kid = fork()) < 0)
- return (-1);
- if (kid)
- _exit(0);
- u_detach();
- return (0);
-}
-