Commit 569bc524 authored by Salvatore Bonaccorso's avatar Salvatore Bonaccorso

Merge tag 'upstream/0.21'

Upstream version 0.21
parents db470083 d5b02ea1
Revision history for Perl extension App::Daemon.
0.21 (04/28/2014)
(ms) Nicolai Langfeldt added -g option to switch to specified group
when app was started as root.
(ms) Makefile.PL now dies on Win32 to save the CPAN smoke testers
some grief with hanging tests ([rt.cpan.org #81980])
0.20 (11/11/2013)
(ms) [rt.cpan.org #61428] Fixed bug in detach() which no longer attempts
to write to a non-existing pid file.
......
......@@ -2,7 +2,7 @@ package App::Daemon;
use strict;
use warnings;
our $VERSION = '0.20';
our $VERSION = '0.21';
use Getopt::Std;
use Pod::Usage;
......@@ -22,7 +22,7 @@ use constant LSB_NOT_RUNNING => 3;
use constant LSB_UNKNOWN => 4;
use constant ALREADY_RUNNING => 150;
our ($pidfile, $logfile, $l4p_conf, $as_user, $background,
our ($pidfile, $logfile, $l4p_conf, $as_user, $as_group, $background,
$loglevel, $action, $appname, $default_pid_dir, $default_log_dir);
$action = "";
$appname = appname();
......@@ -66,9 +66,17 @@ sub cmd_line_parse {
$as_user ||= 'nobody';
}
if(my $_as_group = find_option('-g', 1)) {
$as_group = $_as_group;
}
else {
$as_group ||= 'nogroup';
}
if($> != 0) {
# Not root? Then we're ourselves
($as_user) = getpwuid($>);
($as_user) = getpwuid($>);
($as_group) = getgrgid(POSIX::getgid());
}
$background = 1 if(!defined $background);
......@@ -177,6 +185,8 @@ sub daemonize {
if( $background ) {
detach( $as_user );
} elsif ($as_user) {
id_switch();
}
my $prev_sig = $SIG{__DIE__};
......@@ -240,7 +250,7 @@ sub detach {
}
if($as_user) {
user_switch();
id_switch();
}
# close std file descriptors
......@@ -260,10 +270,20 @@ sub detach {
}
###########################################
sub user_switch {
sub id_switch {
###########################################
if($> == 0) {
# If we're root, become the user set as 'as_user';
# If we're root, become user set as 'as_user' and the group in
# 'as_group'.
# Set the group first because it only works when still root
my ($group,undef,$gid) = getgrnam($as_group);
if(! defined $group) {
LOGDIE "Cannot switch to group $as_group";
}
POSIX::setgid($gid);
my ($name,$passwd,$uid) = getpwnam($as_user);
if(! defined $name) {
LOGDIE "Cannot switch to user $as_user";
......@@ -639,6 +659,10 @@ to somewhere within C</var/log> for production use.
User to run as if started as root. Defaults to 'nobody'.
=item -g as_group
Group to run as if started as root. Defaults to 'nogroup'.
=item -l4p l4p.conf
Path to Log4perl configuration file. Note that in this case the -v option
......@@ -674,6 +698,7 @@ variables:
$App::Daemon::l4p_conf = "myconf.l4p";
$App::Daemon::background = 1;
$App::Daemon::as_user = "nobody";
$App::Daemon::as_group = "nogroup";
use Log::Log4perl qw(:levels);
$App::Daemon::loglevel = $DEBUG;
......
......@@ -14,5 +14,4 @@ t/002Params.t
t/003CmdLine.t
t/004Pidfile.t
t/005Detach.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
META.yml Module meta-data (added by MakeMaker)
{
"abstract" : "Start an Application as a Daemon",
"author" : [
"Mike Schilli <m@perlmeister.com>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.132140",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "App-Daemon",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"File::Basename" : "0",
"File::Pid" : "0",
"File::Temp" : "0",
"Getopt::Std" : "0",
"Log::Log4perl" : "1.0",
"Pod::Usage" : "0",
"Sysadm::Install" : "0.37",
"Test::More" : "0"
}
}
},
"release_status" : "stable",
"resources" : {
"repository" : {
"url" : "http://github.com/mschilli/app-daemon"
}
},
"version" : "0.20"
}
---
abstract: 'Start an Application as a Daemon'
--- #YAML:1.0
name: App-Daemon
version: 0.21
abstract: Start an Application as a Daemon
author:
- 'Mike Schilli <m@perlmeister.com>'
build_requires:
ExtUtils::MakeMaker: 0
- Mike Schilli <m@perlmeister.com>
license: unknown
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.132140'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: App-Daemon
no_index:
directory:
- t
- inc
ExtUtils::MakeMaker: 0
build_requires:
ExtUtils::MakeMaker: 0
requires:
File::Basename: 0
File::Pid: 0
File::Temp: 0
Getopt::Std: 0
Log::Log4perl: 1.0
Pod::Usage: 0
Sysadm::Install: 0.37
Test::More: 0
File::Basename: 0
File::Pid: 0
File::Temp: 0
Getopt::Std: 0
Log::Log4perl: 1.0
Pod::Usage: 0
Sysadm::Install: 0.37
Test::More: 0
resources:
repository: http://github.com/mschilli/app-daemon
version: 0.20
repository: http://github.com/mschilli/app-daemon
no_index:
directory:
- t
- inc
generated_by: ExtUtils::MakeMaker version 6.57_05
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
......@@ -10,6 +10,10 @@ my $meta_merge = {
}
};
if( $^O eq "MSWin32" ) {
die "$^O: OS unsupported";
}
WriteMakefile(
NAME => 'App::Daemon',
VERSION_FROM => 'Daemon.pm', # finds $VERSION
......
######################################################################
App::Daemon 0.20
App::Daemon 0.21
######################################################################
NAME
......@@ -156,6 +156,9 @@ DESCRIPTION
-u as_user
User to run as if started as root. Defaults to 'nobody'.
-g as_group
Group to run as if started as root. Defaults to 'nogroup'.
-l4p l4p.conf
Path to Log4perl configuration file. Note that in this case the -v
option will be ignored.
......@@ -182,6 +185,7 @@ DESCRIPTION
$App::Daemon::l4p_conf = "myconf.l4p";
$App::Daemon::background = 1;
$App::Daemon::as_user = "nobody";
$App::Daemon::as_group = "nogroup";
use Log::Log4perl qw(:levels);
$App::Daemon::loglevel = $DEBUG;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment