Script-Daemonizer
view release on metacpan or search on metacpan
t/02-methods.t view on Meta::CPAN
#!perl -T
use Test::More tests => 9;
use File::Spec;
use Script::Daemonizer;
my $gid = (split " ", $( )[0];
my $user = getpwuid($<);
my $euser = getpwuid($>);
my $group = getgrgid($gid);
# ------------------------------------------------------------------------------
# Call drop_privileges() with parameters passed to the function
# ------------------------------------------------------------------------------
eval qq(
my \$daemon = new Script::Daemonizer();
\$daemon->drop_privileges(
euid => $>,
egid => $gid,
uid => $<,
gid => $gid,
);
);
ok (! $@, "call to drop_privileges() with explicit parameters failed: $@");
# ------------------------------------------------------------------------------
# Call drop_privileges() with parameters passed to the constructor
# ------------------------------------------------------------------------------
eval qq(
my \$daemon = new Script::Daemonizer(
drop_privileges => {
euid => $>,
egid => $gid,
uid => $<,
gid => $gid,
},
);
\$daemon->drop_privileges();
);
ok (! $@, "call to drop_privileges() with implicit parameters failed: $@");
# ------------------------------------------------------------------------------
# Call drop_privileges() with names instead of numerical values
# ------------------------------------------------------------------------------
SKIP: {
skip("No login name, skipping drop_privileges() test with names", 1)
unless defined $user && defined $euser && defined $group;
eval qq(
my \$daemon = new Script::Daemonizer(
drop_privileges => {
euser => '$user',
egroup => '$group',
user => '$euser',
group => '$group',
},
);
\$daemon->drop_privileges();
);
ok (! $@, "call to drop_privileges() with names failed: $@");
( run in 0.974 second using v1.01-cache-2.11-cpan-e1769b4cff6 )