Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Does something in Dancer prevent using the system call?

by Riales (Hermit)
on Jun 08, 2013 at 04:41 UTC ( #1037794=perlquestion: print w/replies, xml ) Need Help??
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' . " $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!

Replies are listed 'Best First'.
Re: Does something in Dancer prevent using the system call?
by Old_Gray_Bear (Bishop) on Jun 08, 2013 at 05:11 UTC
    From the Fine Documentation (perldoc -f system):
    The return value is the exit status of the program as returned by the "wait" call. To get the actual exit value, shift right by eight (see below). See also "exec". This is *not* what you want to use to capture the output from a command; for that you should use merely backticks or "qx//", as described in "`STRING`" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).
    Your return value is 0x0080. Shift out the low-order eight bits gives you 0x00.

    I Go Back to Sleep, Now.


      Thanks for the reply! Doesn't returning with a zero mean that the script returned successfully? I actually don't need to capture any output--I was just trying to gain visibility into why the daemon wasn't starting. Unfortunately, it seems that I'm still stumped. :(
Re: Does something in Dancer prevent using the system call?
by Riales (Hermit) on Jun 09, 2013 at 21:47 UTC

    So, I figured this one out, and it makes me feel really, really, really stupid.

    The script that forks the daemon was fine. Using system from my webapp was fine. The problem lay in how I constructed the command before passing it to system:

    my $cmd = '/usr/bin/perl' + . ' /home/username/workspace/Space/bin/start_client_handle' . " $user_no" + . $ENV{IS_TEST} ? ' test' : ''

    Staggeringly obvious in parentheses around that last line, so Perl was actually concatenating the first two strings together with $ENV{IS_TEST} and setting $cmd to ' test'.

    Anyways, I forgot to check the basics and immediately assumed the problem must lay in some more complex part of the code. Lesson learned (hopefully!).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1037794]
Approved by Old_Gray_Bear
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2018-06-22 19:15 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.