[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: umask change in Perl daemon example code



On Fri, Dec 24, 2004 at 08:00:37PM +0100, Florian Weimer wrote:
> Bug #287119 is caused by the "umask(0);" line in the following code
> snippet:
> 
> sub become_daemon {
>   my $child = fork;
>   die "Can't fork: $!" unless defined($child);
>   exit(0) if $child;    # parent dies;
>   POSIX::setsid();     # become session leader
>   open(STDIN,"</dev/null");
>   open(STDOUT,">/dev/null");
>   open(STDERR, '>&STDOUT');

Shouldn't the other descriptors be closed too?  Are there any
circumstances under which it would make a sense not to close all?

>   chdir '/';           # change working directory
>   umask(0);            # forget file mode creation mask
>   $ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin';
>   delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
>   $SIG{CHLD} = \&reap_child;
> 
>   # signal handler for child die events
>   $SIG{TERM} = $SIG{INT} = \&do_term;
>   $SIG{HUP}  = \&do_hup;
> }
> 
> Apparently, this is part of some standard Perl example for
> implementing daemons, which means other packages might be affected as
> well.  Symptoms are files which are created world-writable.  For
> pperl, I'm going to remove the line and add a regression test.

Come on, it's not a bug, once it's a part of the documentation!!</sarcasm>

-- 
 )^o-o^|    jabber: rdancer@NJS.NetLab.Cz
 | .v  K    e-mail: jjminar FastMail FM
 `  - .'     phone: +44(0)7981 738 696
  \ __/Jan     icq: 345 355 493
 __|o|__Minář  irc: rdancer@IRC.FreeNode.Net

Attachment: pgpep5QK8i9Sz.pgp
Description: PGP signature


Reply to: