1 --- a/src/utils/os_unix.c
2 +++ b/src/utils/os_unix.c
10 #include <sys/capability.h>
11 @@ -179,59 +180,46 @@ int os_gmtime(os_time_t t, struct os_tm
18 -static int os_daemon(int nochdir, int noclose)
19 +int os_daemonize(const char *pid_file)
22 + int pid = 0, i, devnull;
26 +#if defined(__uClinux__) || defined(__sun__)
28 +#else /* defined(__uClinux__) || defined(__sun__) */
30 - devnull = open("/dev/null", O_RDWR);
38 - if (dup2(devnull, STDIN_FILENO) < 0) {
43 + FILE *f = fopen(pid_file, "w");
45 + fprintf(f, "%u\n", pid);
52 - if (dup2(devnull, STDOUT_FILENO) < 0) {
58 - if (dup2(devnull, STDERR_FILENO) < 0) {
66 -#else /* __APPLE__ */
67 -#define os_daemon daemon
68 -#endif /* __APPLE__ */
71 -int os_daemonize(const char *pid_file)
73 -#if defined(__uClinux__) || defined(__sun__)
75 -#else /* defined(__uClinux__) || defined(__sun__) */
76 - if (os_daemon(0, 0)) {
78 + devnull = open("/dev/null", O_RDWR);
84 - FILE *f = fopen(pid_file, "w");
86 - fprintf(f, "%u\n", getpid());
90 + for (i = 0; i <= STDERR_FILENO; i++)
97 #endif /* defined(__uClinux__) || defined(__sun__) */