benchmarks/vendor/forever/node_modules/daemon/src/daemon.cc
//
// Go through special routines to become a daemon.
// if successful, returns daemon pid
//
Go through special routines to become a daemon.
if successful, returns daemon pid
Go through special routines to become a daemon . if successful returns daemon pid
static Handle<Value> Start(const Arguments& args) {
  HandleScope scope;
  pid_t sid, pid = fork();
  int i, new_fd;
  if (pid < 0)      exit(1);
  else if (pid > 0) exit(0);
  if (pid == 0) {
     See: http:pod.tst.eu/http:cvs.schmorp.de/libev/ev.pod#code_ev_fork_code_the_audacity_to_re
    ev_default_fork();
    sid = setsid();
    if(sid < 0) exit(1);
     Close stdin
    freopen("/dev/null", "r", stdin);
    if (args.Length() > 0 && args[0]->IsInt32()) {
      new_fd = args[0]->Int32Value();
      dup2(new_fd, STDOUT_FILENO);
      dup2(new_fd, STDERR_FILENO);
    }
    else {
      freopen("/dev/null", "w", stderr);
      freopen("/dev/null", "w", stdout);
    } 
  }
  return scope.Close(Number::New(getpid()));
}
static Handle < Value > Start ( const Arguments & args ) { HandleScope scope ; pid_t sid , pid = fork ( ) ; int i , new_fd ; if ( pid < 0 ) exit ( 1 ) ; else if ( pid > 0 ) exit ( 0 ) ; if ( pid == 0 ) { ev_default_fork ( ) ; sid = setsid ( ) ; if ( sid < 0 ) exit ( 1 ) ; freopen ( " " , " " , stdin ) ; if ( args . Length ( ) > 0 && args [ 0 ] -> IsInt32 ( ) ) { new_fd = args [ 0 ] -> Int32Value ( ) ; dup2 ( new_fd , STDOUT_FILENO ) ; dup2 ( new_fd , STDERR_FILENO ) ; } else { freopen ( " " , " " , stderr ) ; freopen ( " " , " " , stdout ) ; } } return scope . Close ( Number :: New ( getpid ( ) ) ) ; }
Go through special routines to become a daemon.
Go through special routines to become a daemon .
// Child process: We need to tell libev that we are forking because // kqueue can't deal with this gracefully. // // See: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_fork_code_the_audacity_to_re // Close stdin