Changeset 426


Ignore:
Timestamp:
06/23/12 14:29:07 (12 years ago)
Author:
nanardon
Message:
  • write pid file soon enough to still have root access
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/trunk/bin/sophie-notify

    • Property svn:executable set to *
    r425 r426  
    3636$configfile ||= '/etc/sophie/sophie-notify.conf'; 
    3737 
    38 if (-f $configfile && (my $conf = Config::General->new($configfile))) { 
    39     my %config = $conf->getall; 
    40     $server      ||= $config{url}; 
    41     $login       ||= $config{login}; 
    42     $pass        ||= $config{pass}; 
    43     $proxy       ||= $config{proxy}; 
    44     $pidfile     ||= $config{pidfile}; 
    45     $runas       ||= $config{runas}; 
     38if (-f $configfile) { 
     39    if (my $conf = Config::General->new($configfile)) { 
     40        my %config = $conf->getall; 
     41        $server      ||= $config{url}; 
     42        $login       ||= $config{login}; 
     43        $pass        ||= $config{pass}; 
     44        $proxy       ||= $config{proxy}; 
     45        $pidfile     ||= $config{pidfile}; 
     46        $runas       ||= $config{runas}; 
     47    } else { 
     48        die "Cannot ope configuration file $configfile\n"; 
     49    } 
    4650} 
    4751 
    4852$updated_inotify ||= 500; 
     53 
     54if ($daemon) { 
     55    if (fork()) { 
     56        exit(0); 
     57    } 
     58} 
     59 
     60if ($pidfile) { 
     61    if (open(my $handle, '>', $pidfile)) { 
     62        print $handle $$ . "\n"; 
     63        close($handle); 
     64    } else { 
     65    } 
     66} 
     67 
    4968 
    5069if ($runas) { 
     
    5675    if ($> ne $uid) { 
    5776        die "Cannot change to user $runas\n"; 
    58     } 
    59 } 
    60  
    61  
    62 if ($daemon) { 
    63     if (fork()) { 
    64         exit(0); 
    6577    } 
    6678} 
     
    7688    warn "Can't access to sophie web site, waiting 60s before retry\n"; 
    7789    sleep 60; 
    78 } 
    79  
    80 if ($pidfile) { 
    81     if (open(my $handle, '>', $pidfile)) { 
    82         print $handle $$ . "\n"; 
    83         close($handle); 
    84     } else { 
    85     } 
    8690} 
    8791 
Note: See TracChangeset for help on using the changeset viewer.