#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
-
#include <mLib/dstr.h>
#include "util.h"
-#include <sys/ioctl.h>
-
/*----- Main code ---------------------------------------------------------*/
/* --- @u_quotify@ --- *
}
}
-/* --- @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);
-}
-
/*----- That's all, folks -------------------------------------------------*/