Changeset 414


Ignore:
Timestamp:
11/16/11 09:46:41 (12 years ago)
Author:
nanardon
Message:
  • add runas and pidfile options
File:
1 edited

Legend:

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

    r412 r414  
    1212 
    1313GetOptions( 
    14     'c=s'      => \my $configfile, 
    15     'bdelay=i' => \my $updated_inotify, 
    16     'd|daemon' => \my $daemon, 
    17     'u|url=s'  => \my $server, 
    18     'l=s'      => \my $login, 
    19     'p=s'      => \my $pass, 
    20     'proxy=s'  => \my $proxy, 
     14    'c=s'       => \my $configfile, 
     15    'bdelay=i'  => \my $updated_inotify, 
     16    'd|daemon'  => \my $daemon, 
     17    'u|url=s'   => \my $server, 
     18    'l=s'       => \my $login, 
     19    'p=s'       => \my $pass, 
     20    'proxy=s'   => \my $proxy, 
     21    'pidfile=s' => \my $pidfile, 
     22    'runas=s'   => \my $runas, 
    2123) or die "Wrong options"; 
    2224 
     
    2931    $pass        ||= $config{pass}; 
    3032    $proxy       ||= $config{proxy}; 
     33    $pidfile     ||= $config{pidfile}; 
     34    $runas       ||= $config{runas}; 
    3135} 
    3236 
    3337$updated_inotify ||= 500; 
     38 
     39my $sc = Sophie::Client->new( 
     40    server     => $server, 
     41    login      => $login, 
     42    password   => $pass, 
     43    proxy      => $proxy, 
     44) or die "Can't access to sophie web site"; 
     45 
     46if ($runas) { 
     47    my ($login,$pass,$uid,$gid) = $runas =~ /^\d/ 
     48    ? getpwuid($runas) 
     49    : getpwnam($runas); 
     50 
     51    $> = $uid; $) = $gid; 
     52    if ($> ne $uid) { 
     53        die "Cannot change to user $runas\n"; 
     54    } 
     55} 
     56 
    3457 
    3558if ($daemon) { 
     
    3962} 
    4063 
    41 my $sc = Sophie::Client->new( 
    42     server     => $server, 
    43     login      => $login, 
    44     password   => $pass, 
    45     proxy      => $proxy, 
    46 ); 
     64if ($pidfile) { 
     65    if (open(my $handle, '>', $pidfile)) { 
     66        print $handle $$ . "\n"; 
     67        close($handle); 
     68    } else { 
     69    } 
     70} 
    4771 
    4872my $update = 1; 
Note: See TracChangeset for help on using the changeset viewer.