http://www.perlmonks.org?node_id=1037794

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

Hi all,

I am trying to fork a daemon process off whenever a user logs into my web application. I am currently trying to do it using a system call to call a script that does the actual forking, but it doesn't seem to be working. I also can't figure out how to get more visibility into the problem. All I know is when I do a test-login, Dancer seems to go through everything fine, but all I get from the system call is 256. Here's the code from the web app:

sub start_client_handler { my ($user_no) = @_; + my $cmd = '/usr/bin/perl' + . ' /home/username/workspace/Space/bin/start_client_handle +r_daemon.pl' . " $user_no" + . $ENV{IS_TEST} ? ' test' : ''; + system($cmd); }

And here's the code that is supposed to fork the daemon. When I call it by itself (not from my Dancer web app), it seems to work fine. Not sure what's going wrong when I call it from the app...

#!/usr/bin/perl use strict; use warnings; use AnyEvent; use Proc::Daemon; use Space::Handler; my $user_no = shift @ARGV; my $base_dir = '/home/username/workspace/Space'; die "Error: user_no must be provided to the client handler." unless $u +ser_no; $ENV{IS_TEST} = !! grep { lc($_) eq 'test' } @ARGV; $| = 1 if $ENV{IS_TEST}; my $daemon = Proc::Daemon->new( work_dir => "$base_dir/bin", child_STDOUT => "$base_dir/logs/client_handler_$user_no.log", child_STDERR => "+>>$base_dir/logs/errors/client_handler_$user_no. +log", ); $daemon->Init(); my $handler = Space::Handler->new( user_no => $user_no, daemon => $daemon, ); $handler->run(); my $keep_alive = AnyEvent->condvar; $keep_alive->wait;

Any guidance/direction would be much appreciated!