From 743e61e8c6aee0a70eb3015e1665a9dcd32a04ac Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 17 Mar 2003 02:41:36 +0000 Subject: Add daemon logic svn:r185 --- src/or/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/or/main.c b/src/or/main.c index fe2de2ebc..fc310424f 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -607,6 +607,24 @@ void dump_directory_to_string(char *s, int maxlen) { } +void daemonize() { + /* Fork; parent exits. */ + if (fork()) + exit(0); + + /* Create new session; make sure we never get a terminal */ + setsid(); + if (fork()) + exit(0); + + chdir("/"); + umask(000); + + fclose(stdin); + fclose(stdout); + fclose(stderr); +} + int main(int argc, char *argv[]) { int retval = 0; @@ -615,6 +633,9 @@ int main(int argc, char *argv[]) { log(options.loglevel,NULL); /* assign logging severity level from options */ global_role = options.Role; /* assign global_role from options. FIXME: remove from global namespace later. */ + if (options.Daemon) + daemonize(); + if(options.Role & ROLE_OR_LISTEN) { /* only spawn dns handlers if we're a router */ if(dns_master_start() < 0) { log(LOG_ERR,"main(): We're running without a dns handler. Bad news."); -- cgit v1.2.3