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'));
=cut
sub adminsuidsetup {
+ $dbh->disconnect if $dbh;
+ &forksuidsetup(@_);
+}
+sub forksuidsetup {
$user = shift;
croak "fatal: adminsuidsetup called without arguements" unless $user;
croak "Not running uid freeside!" unless checkeuid();
getsecrets;
- $dbh->disconnect if $dbh;
$dbh = DBI->connect($datasrc,$db_user,$db_pass, {
'AutoCommit' => 0,
'ChopBlanks' => 1,
=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;
}
=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
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;
$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
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 {