hinrik/app-evalserver — Issue #1: modularize _be_safe() into an external module
Author: ironcamel
Created: 2012-01-20 20:11:45+00:00
State: open

What do you think about pulling out App::EvalServer::Child::_be_safe into its own module. I think it would be extremely useful for anyone wanting to run commands in a safe manner. You (or I) could easily pull out that function into a module called Proc::BeSafe or something like that. I'm not sure what the best name should be.

Ideally, you would use that module in App::EvalServer. That way any improvements to that code would benefit everyone, not just App::EvalServer. There is only one slightly tricky issue, which is that you call the private _fail function, but there is an easy workaround for that. There could be an optional $fail anonymous sub passed in:

sub _be_safe {
my ($jail, $user, $limit, $fail) = @_;
$fail = sub { die @_ } unless $fail;

my $new_uid = getpwnam($user);
$fail->("Can't find uid for '$user'") if !defined $new_uid;

...

}

What do you think?