http://qs321.pair.com?node_id=349273

sth has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am hopping someone else has run into this, or can shed some light on what is going on. I have an app server that runs as a daemon process. I used the Dameon.pm from Lincoln Stein's Book "Network Programming with Perl". I made some minor modifications and was up and running. This app server was running on numerous servers without any problem, perl-5.6.1. When I started upgrading the servers to 5.8.1 the server would start up handle one request and exit. Because of a lack of time, I started the servers using 5.6.1 version of Perl. Well now I am trying to figure out why the server won't stay running under Perl 5.8.? . I even tried running under version 5.8.4 and still no luck. So something was fixed or changed in the 5.8 versions of Perl, I just can't figure out what it is. I will probably convert to POE, or a least try it, sometime, but right now I need to figure out what is going on here.

This basically the app server code,
# signal handler for child die events $SIG{TERM} = $SIG{INT} = \&do_term; $SIG{HUP} = \&do_hup; our($listen_socket); $listen_socket = HTTP::Daemon->new(LocalPort => PORT) or die "Can't create a listening socket: $@" unless $listen_socket; my $pid = init_server(PIDFILE, USER, @groups); my $port = PORT; log_notice("App Server accepting connections on port $port\n"); while (my $connection = $listen_socket->accept) { my $host = $connection->peerhost; my $child = launch_child(undef, undef); if ($child == 0) { $listen_socket->close; log_notice("App Srv : Accepting a connection from $host\n"); my ($fnm, $prg) = launch_app($connection); my $child = launch_child(undef, undef); if ($child == 0) { log_notice("Otools App Srv : Running $prg\n"); ($<, $>) = ($>, $<); # Switch EUid & RUid. $> = $<; log_notice("Uid = $< : Eid = $>\n"); log_notice("Gid = $( : EGid = $)\n"); exec($prg, $fnm, $host) or log_die("App Srv : Exec failed. Died"); } log_notice("App Srv : Connection from $host finished\n"); exit 0; } } continue { $connection->close; }
I am using HTTP::Daemon to listen for posts on a port and I use the Daemon.pm launch the children, initialize, ...etc. I was debugging the server so I commented out the become_daemon() sub and ran in the debugger. Of course the server stayed running, not exiting after one request. As soon as I put the become_daemon() back into the code and start the server, it quits after handling one request. Here is the become_daemon() sub from Lincoln's book,
sub become_daemon { croak "Can't fork" unless defined (my $child = fork); exit 0 if $child; # parent dies; POSIX::setsid(); # become session leader open(STDIN,"</dev/null"); open(STDOUT,">/dev/null"); open(STDERR,">&STDOUT"); $CWD = getcwd; # remember working directory chdir '/'; # change working directory umask(0); # forget file mode creation mask $ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; $SIG{CHLD} = \&reap_child; }

Any help would be much appreciated!

sth