move daemonizing to common.c

This commit is contained in:
Erik Ekman 2007-03-01 21:19:01 +00:00
parent baf1ab4201
commit 264a5227de
4 changed files with 13 additions and 10 deletions

View File

@ -21,6 +21,7 @@
#endif #endif
#include <time.h> #include <time.h>
#include <err.h> #include <err.h>
#include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -78,3 +79,12 @@ do_chroot(char *newroot)
setuid(getuid()); setuid(getuid());
} }
} }
void
do_detach()
{
printf("Detaching from terminal...\n");
daemon(0, 0);
umask(0);
alarm(0);
}

View File

@ -46,5 +46,6 @@ int open_dns(int, in_addr_t);
void close_dns(int); void close_dns(int);
void do_chroot(char *); void do_chroot(char *);
void do_detach();
#endif #endif

View File

@ -24,7 +24,6 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <err.h> #include <err.h>
#include <pwd.h> #include <pwd.h>
@ -571,10 +570,7 @@ main(int argc, char **argv)
do_chroot(newroot); do_chroot(newroot);
if (!foreground) { if (!foreground) {
printf("Detaching from terminal...\n"); do_detach();
daemon(0, 0);
umask(0);
alarm(0);
} }
if (username) { if (username) {

View File

@ -22,7 +22,6 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <err.h> #include <err.h>
#include <time.h> #include <time.h>
@ -538,10 +537,7 @@ main(int argc, char **argv)
do_chroot(newroot); do_chroot(newroot);
if (!foreground) { if (!foreground) {
printf("Detaching from terminal...\n"); do_detach();
daemon(0, 0);
umask(0);
alarm(0);
} }
signal(SIGINT, sigint); signal(SIGINT, sigint);