Skip to content
Browse files

Merge pull request #11 from doherty/string-for-uid-and-gid

Find the numeric uid/gid if given strings
  • Loading branch information...
2 parents d939cae + f7b4d07 commit d5b9461a0bf0162098d32cb947db405cef1363fa @symkat committed Apr 15, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/Daemon/Control.pm
View
12 lib/Daemon/Control.pm
@@ -43,6 +43,12 @@ sub new {
$self->{$accessor} = delete $args->{$accessor};
}
}
+ # Get numeric uid/gid if we were given strings
+ $self->{uid} = scalar getpwnam($self->{uid})
+ if $self->{uid} and $self->{uid} =~ /[a-z]/;
+ $self->{gid} = scalar getgrnam($self->{gid})
+ if $self->{gid} and $self->{gid} =~ /[a-z]/;
+
die "Unknown arguments to the constructor: " . join( " ", keys %$args )
if keys( %$args );
@@ -484,17 +490,19 @@ $daemon->program_args( [ '--switch', 'argument' ] );
If provided, the UID that the program will drop to when forked. This is
ONLY supported in double-fork mode and will only work if you are running
-as root. This takes the numerical UID (grep user /etc/passwd )
+as root. Accepts numeric UID, or finds it if given a username as a string.
$daemon->uid( 1001 );
+$daemon->uid('www-data');
=head2 gid
If provided, the GID that the program will drop to when forked. This is
ONLY supported in double-fork mode and will only work if you are running
-as root. This takes the numerical GID ( grep group /etc/groups )
+as root. Accepts numeric GID, or finds it if given a group name as a string.
$daemon->gid( 1001 );
+$daemon->gid('www-data');
=head2 directory

0 comments on commit d5b9461

Please sign in to comment.
Something went wrong with that request. Please try again.