Changeset 11239
- Timestamp:
- 08/19/08 15:38:38 (5 months ago)
- Location:
- branches/remote-services/ebox
- Files:
-
- 1 added
- 1 modified
-
debian/ebox.runnerd.upstart (added)
-
src/libexec/ebox-runnerd (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/remote-services/ebox/src/libexec/ebox-runnerd
r11237 r11239 4 4 use EBox::Config; 5 5 use EBox::Exceptions::External; 6 use Getopt::Long; 6 7 use Linux::Inotify2; 7 8 use POSIX qw(SIG_IGN SIGHUP); … … 16 17 # Stevens chapter 13 coding rules 17 18 # 19 # Parameters: 20 # 21 # foreground - Boolean indicating if the daemon must be launched 22 # in foreground *(Optional)* Default value: false 23 # 24 # 18 25 sub _daemonise 19 26 { 27 my ($foreground) = @_; 28 20 29 # Clear the file creation mask 21 30 umask(0); 31 32 unless ( $foreground ) { 22 33 # Become a session leader to lose controlling TTY 23 my $pid = fork(); 24 if ( $pid < 0 ) { 25 throw EBox::Exceptions::External( "Cannot fork: $!"); 26 } elsif ( $pid != 0 ) { 27 # Parent must throw EBox::Exceptions::External( 28 exit(0); 34 my $pid = fork(); 35 if ( $pid < 0 ) { 36 throw EBox::Exceptions::External( "Cannot fork: $!"); 37 } elsif ( $pid != 0 ) { 38 # Parent must throw EBox::Exceptions::External( 39 exit(0); 40 } 41 POSIX::setsid(); 29 42 } 30 POSIX::setsid();31 43 32 44 # Ensure future opens won't allocate controlling TTYs 33 45 POSIX::sigaction(POSIX::SIGHUP, POSIX::SigAction->new( POSIX::SIG_IGN )) 34 46 or throw EBox::Exceptions::External( "Cannot ignore SIGHUP: $!"); 35 my $pid = fork(); 36 if ( $pid < 0 ) { 37 throw EBox::Exceptions::External( "Cannot fork: $!"); 38 } elsif ( $pid != 0 ) { 39 # Parent must die 40 exit(0); 47 unless ( $foreground ) { 48 my $pid = fork(); 49 if ( $pid < 0 ) { 50 throw EBox::Exceptions::External( "Cannot fork: $!"); 51 } elsif ( $pid != 0 ) { 52 # Parent must die 53 exit(0); 54 } 41 55 } 42 56 … … 106 120 107 121 # MAIN 122 123 # Get arguments 124 my ($foreground) = (0); 125 my $result = GetOptions( 'foreground' => \$foreground ); 126 108 127 EBox::init(); 109 _daemonise( );128 _daemonise($foreground); 110 129 111 130 my $incomingSub = sub {
