Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (3)
    As of 2014-07-13 07:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (248 votes), past polls