mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 07:35:26 +00:00
add ns_os_deamonize()
This commit is contained in:
@@ -23,6 +23,9 @@
|
|||||||
isc_result_t
|
isc_result_t
|
||||||
ns_os_init(void);
|
ns_os_init(void);
|
||||||
|
|
||||||
|
isc_result_t
|
||||||
|
ns_os_daemonize(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
ns_os_shutdown(void);
|
ns_os_shutdown(void);
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <isc/result.h>
|
#include <isc/result.h>
|
||||||
|
|
||||||
@@ -92,6 +93,38 @@ ns_os_init(void) {
|
|||||||
return (ISC_R_SUCCESS);
|
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
|
void
|
||||||
ns_os_shutdown(void) {
|
ns_os_shutdown(void) {
|
||||||
closelog();
|
closelog();
|
||||||
|
Reference in New Issue
Block a user