aboutsummaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/main.c')
-rw-r--r--src/or/main.c21
1 files changed, 21 insertions, 0 deletions
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.");