.rhavin has asked for the wisdom of the Perl Monks concerning the following question:
In order to spawn a deamon from cgi, all filehandles must get closed to completely detach from httpd. In this case, carpout'ing error log shiftet the original (and therefore still open) STDERR to CGI::Carp::SAVEERR and had to get closed also.
# ------------------------------------------------ # spawn completely detached deamon sub BaseForkDeamon { return 1 if (fork()); POSIX::setsid(); close STDOUT; close STDIN; close STDERR; close CGI::Carp::SAVEERR; # <-- close LOG return 0; };
Hello monks... after reading for 3h thru google i still got no clue how to solve this problem ... or at least: how to do it in perl;-)
It's like this: # ------------------------------------------------ # spawns a deamon sub ForkDeamon { return 1 if (fork()); POSIX::setsid(); close STDOUT; close STDIN; close STDERR; return 0; };
That fn should fork a deamon and detach it from the calling browser in a web/cgi-skript. the problem is: it still blocks the handling httpd.
What i did understand from reading (belive to understand?) is that on fork *all* handles become copied and so my deamon still has the ports open socket. So my next try would be to close that socket and i did some googling for 'perl get port handle', because i also dont know how to obtain the HANDLE for the already open PORT and to make things a litle bit worser (at least for a non-native-speaker like me), 'port' is not a very specific search-word (i dont want to get info about how to port from/to perl) and what i really want to do is something like 'please close ALL currently open handles' - but i dont know how to do that either;-)
So, a solution for my problem would be ... nice.
The webserver of my ISP runs Apache/2.2.3 (Debian), the only Apache modules for perl i have are Apache::SOAP and Apache::XMLRPC::Lite.
thx,
~.rhavin;)
PS: should i have infringed some well known rules here, please bear in mind: it's my first posting...;-/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fork/web-cgi: how do i close all open sockets in deamon?
by almut (Canon) on Jan 25, 2010 at 11:31 UTC | |
by .rhavin (Initiate) on Jan 25, 2010 at 11:47 UTC | |
by .rhavin (Initiate) on Jan 25, 2010 at 12:02 UTC |