diff options
Diffstat (limited to 'FS')
| -rw-r--r-- | FS/FS/UID.pm | 13 | ||||
| -rw-r--r-- | FS/bin/freeside-queued | 50 | 
2 files changed, 44 insertions, 19 deletions
| diff --git a/FS/FS/UID.pm b/FS/FS/UID.pm index f80156e97..f81d8dcdd 100644 --- a/FS/FS/UID.pm +++ b/FS/FS/UID.pm @@ -15,8 +15,8 @@ use DBI;  use FS::Conf;  @ISA = qw(Exporter); -@EXPORT_OK = qw(checkeuid checkruid cgisuidsetup -                adminsuidsetup getotaker dbh datasrc getsecrets driver_name ); +@EXPORT_OK = qw(checkeuid checkruid cgisuidsetup adminsuidsetup forksuidsetup +                getotaker dbh datasrc getsecrets driver_name );  $freeside_uid = scalar(getpwnam('freeside')); @@ -65,7 +65,11 @@ Returns the DBI database handle (usually you don't need this).  =cut  sub adminsuidsetup { +  $dbh->disconnect if $dbh; +  &forksuidsetup(@_); +} +sub forksuidsetup {    $user = shift;    croak "fatal: adminsuidsetup called without arguements" unless $user; @@ -78,7 +82,6 @@ sub adminsuidsetup {    croak "Not running uid freeside!" unless checkeuid();    getsecrets; -  $dbh->disconnect if $dbh;    $dbh = DBI->connect($datasrc,$db_user,$db_pass, {                            'AutoCommit' => 0,                            'ChopBlanks' => 1, @@ -118,7 +121,7 @@ Returns the CGI (see L<CGI>) object.  =cut  sub cgi { -  #carp "warning: \$FS::UID::cgi isa Apache" if $cgi->isa('Apache'); +  carp "warning: \$FS::UID::cgi isa Apache" if $cgi->isa('Apache');    $cgi;  } @@ -249,7 +252,7 @@ coderef into the hash %FS::UID::callback :  =head1 VERSION -$Id: UID.pm,v 1.9 2001-09-06 20:41:59 ivan Exp $ +$Id: UID.pm,v 1.10 2001-09-24 03:23:34 ivan Exp $  =head1 BUGS diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 42d638f4c..1eef00c5c 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -7,7 +7,7 @@ use Fcntl qw(:flock);  use POSIX qw(setsid);  use Date::Format;  use IO::File; -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup forksuidsetup);  use FS::Record qw(qsearchs);  use FS::queue; @@ -29,6 +29,9 @@ my $user = shift or die &usage;  $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; };  $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; +#pickup zombie status +$SIG{CHLD} = sub { wait; }; +  $> = $FS::UID::freeside_uid unless $>;  $< = $>;  $ENV{HOME} = (getpwuid($>))[7]; #for ssh @@ -61,21 +64,40 @@ while (1) {    my @args = $ljob->args; -  #fork a child for each job (up to some maximum perhaps?) -  #single-threaded for now. - -  my $eval = "&". $ljob->job. '(@args);'; -  warn "running $eval"; -  eval $eval; -  if ( $@ ) { -    warn "job $eval failed"; -    my %hash = $ljob->hash; +  # number of children limit? +  defined( my $pid = fork ) or do { +    warn "WARNING: can't fork: $!\n"; +    my %hash = $job->hash;      $hash{'status'} = 'failed'; -    my $fjob = new FS::queue( \%hash ); -    my $error = $fjob->replace($ljob); +    my $ljob = new FS::queue ( \%hash ); +    my $error = $ljob->replace($job);      die $error if $error; -  } else { -    $ljob->delete; +  }; + +  unless ( $pid ) { #kid time + +    #get new db handles +    $FS::UID::dbh->{InactiveDestroy} = 1; +    $FS::svc_acct::icradius_dbh->{InactiveDestroy} +      if $FS::svc_acct::icradius_dbh; +    forksuidsetup($user); + +    my $eval = "&". $ljob->job. '(@args);'; +    warn "running $eval"; +    eval $eval; +    if ( $@ ) { +      warn "job $eval failed"; +      my %hash = $ljob->hash; +      $hash{'status'} = 'failed'; +      my $fjob = new FS::queue( \%hash ); +      my $error = $fjob->replace($ljob); +      die $error if $error; +    } else { +      $ljob->delete; +    } + +    exit; +    #end-of-kid    }  } continue { | 
