Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Daemon module stop working 5.8.? by sth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found