Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Daemon module stop working 5.8.?

by sth (Priest)
on Apr 29, 2004 at 21:07 UTC ( #349273=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Daemon module stop working 5.8.?
Select or Download Code
Re: Daemon module stop working 5.8.?
by Zaxo (Archbishop) on Apr 29, 2004 at 23:18 UTC

    I don't see anything wrong on first reading. How about opening *STDERR to a log file? That should encourage the daemon itself to tell you what's the trouble.

    After Compline,
    Zaxo

      Thanks Zaxo, that's a good idea. I don't see anything wrong either, that is why I am perplexed. I will try it in the morning and post any findings.

      sth

Re: Daemon module stop working 5.8.?
by Thelonius (Curate) on Apr 30, 2004 at 03:05 UTC

      Thelonius,

      Thank you very very much! That was driving me nuts!

      sth

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://349273]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-09-18 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (125 votes), past polls