Advertisement
Guest User

synerr

a guest
Jul 21st, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.56 KB | None | 0 0
  1. $tmp = select(SEXTANT_DAEMON_LOG);
  2. $| = 1;
  3. select(SEXTANT_DAEMON_LOG);
  4.  
  5. if ($daemon_mode) {
  6.     log_message('daemon mode started, attempting to fork...', 1);
  7.     defined($cpid1 = fork()) or die "pid$$[" . localtime(time()) . "] unable to fork: $!\n";
  8.     if ($cpid1) {
  9.         log_message('fork1 successful, child PID=' . $cpid1 . ', exiting...', 1);
  10.             close(SEXTANT_DAEMON_LOG);
  11.         $MAIN_DBH->disconnect();
  12.         exit(0);
  13.     }
  14.     POSIX::setsid() or die "pid$$[" . localtime(time()) . "] unable to set session leader\n";
  15.     defined($cpid2 = fork()) or die "pid$$[" . localtime(time()) . "] unable to fork: $!\n";
  16.     if ($cpid2) {
  17.         log_message('fork2 successful, child PID=' . $cpid2 . ', exiting...', 1);
  18.         close(SEXTANT_DAEMON_LOG);
  19.         $MAIN_DBH->disconnect();
  20.         exit(0);
  21.     }
  22.     log_message('child (daemon) started', 1);
  23.     chdir('/');
  24.     umask(0);
  25.     open(STDIN, '<', '/dev/null') or die "pid$$[" . localtime(time()) . "] unable to open stdin stream to /dev/null, exiting...";
  26.     open(STDOUT, '>>', $fs_logfile) or die "pid$$[" . localtime(time()) . "] unable to open stdout stream to $fs_logfile, exiting...";
  27.     open(STDERR, '>>', $fs_logfile) or die "pid$$[" . localtime(time()) . "] unable to open stderr stream to $fs_logfile, exiting...";
  28. }
  29. else {
  30.     log_message('non-daemon mode started', 1);
  31. }
  32. getScriptName(\$script_name);
  33. $SEXTANT_DAEMON_LOCKFILE = checkLock($script_name);
  34. $MAIN_DBH = getConnection('Main');
  35. $FS_DBH = getConnection('Sextant');
  36. $HDS_DBH = getConnection('hds');
  37. $MS_DBH = undef;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement