From 264a5227ded9318a458b9baedcc20d5841e0efcd Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 1 Mar 2007 21:19:01 +0000 Subject: [PATCH] move daemonizing to common.c --- src/common.c | 10 ++++++++++ src/common.h | 1 + src/iodine.c | 6 +----- src/iodined.c | 6 +----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/common.c b/src/common.c index be5b744..74c3491 100644 --- a/src/common.c +++ b/src/common.c @@ -21,6 +21,7 @@ #endif #include #include +#include #include #include #include @@ -78,3 +79,12 @@ do_chroot(char *newroot) setuid(getuid()); } } + +void +do_detach() +{ + printf("Detaching from terminal...\n"); + daemon(0, 0); + umask(0); + alarm(0); +} diff --git a/src/common.h b/src/common.h index b3e1dd3..5e41a74 100644 --- a/src/common.h +++ b/src/common.h @@ -46,5 +46,6 @@ int open_dns(int, in_addr_t); void close_dns(int); void do_chroot(char *); +void do_detach(); #endif diff --git a/src/iodine.c b/src/iodine.c index cfca361..bb2410b 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -571,10 +570,7 @@ main(int argc, char **argv) do_chroot(newroot); if (!foreground) { - printf("Detaching from terminal...\n"); - daemon(0, 0); - umask(0); - alarm(0); + do_detach(); } if (username) { diff --git a/src/iodined.c b/src/iodined.c index 7245604..d0d6212 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -538,10 +537,7 @@ main(int argc, char **argv) do_chroot(newroot); if (!foreground) { - printf("Detaching from terminal...\n"); - daemon(0, 0); - umask(0); - alarm(0); + do_detach(); } signal(SIGINT, sigint);