2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

add ns_os_deamonize()

This commit is contained in:
Bob Halley
2000-01-26 21:12:33 +00:00
parent 6bfaefc3fd
commit 2aa67e804d
2 changed files with 36 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
#include <unistd.h>
#include <errno.h>
#include <syslog.h>
#include <fcntl.h>
#include <isc/result.h>
@@ -92,6 +93,38 @@ ns_os_init(void) {
return (ISC_R_SUCCESS);
}
isc_result_t
ns_os_daemonize(void) {
pid_t pid;
int fd;
pid = fork();
if (pid == -1)
return (ISC_R_FAILURE);
if (pid != 0)
_exit(0);
/*
* We're the child.
*/
if (setsid() == -1)
return (ISC_R_FAILURE);
/*
* Try to set stdin, stdout, and stderr to /dev/null, but press
* on even if it fails.
*/
fd = open("/dev/null", O_RDWR, 0);
if (fd != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
}
return (ISC_R_SUCCESS);
}
void
ns_os_shutdown(void) {
closelog();