Commit 743e61e8 authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

Add daemon logic


svn:r185
parent 5dc443a8
Loading
Loading
Loading
Loading
+21 −0
Changes for src/or/main.c: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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.");