r74851 - in /trunk/libproc-daemon-perl: Changes MANIFEST META.yml README debian/changelog lib/Proc/Daemon.pm lib/Proc/Daemon.pod

carnil at users.alioth.debian.org carnil at users.alioth.debian.org
Tue May 24 17:51:12 UTC 2011


Author: carnil
Date: Tue May 24 17:51:05 2011
New Revision: 74851

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=74851
Log:
New upstream release

Modified:
    trunk/libproc-daemon-perl/Changes
    trunk/libproc-daemon-perl/MANIFEST
    trunk/libproc-daemon-perl/META.yml
    trunk/libproc-daemon-perl/README
    trunk/libproc-daemon-perl/debian/changelog
    trunk/libproc-daemon-perl/lib/Proc/Daemon.pm
    trunk/libproc-daemon-perl/lib/Proc/Daemon.pod

Modified: trunk/libproc-daemon-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/Changes?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/Changes (original)
+++ trunk/libproc-daemon-perl/Changes Tue May 24 17:51:05 2011
@@ -1,7 +1,19 @@
 Revision history for Perl module Proc::Daemon.
 
+0.11  Mon Mai 23 2011
+	- Init() didn't close all filehandles reliably (see also bug report at
+	  http://rt.perl.org/rt3/Ticket/Display.html?id=72526). Thanks to Rob Brown
+	  for reporting and offering a patch.
+	- Attributes 'dont_close_fh' AND 'dont_close_fd' added so we can define
+	  file handles and descriptors that must be preserved from the parent into
+	  the child (daemon).
+	- Updated the documentation.
+	- In some environment it is not allowed to open anonymous files. In this
+	  case now a 'pid_file' must be defined. Thanks to Holger Gläss for
+	  reporting.
+
 0.10  Fri Apr 01 2011
-	- improvement how Init() determines whether it was passed a blessed object
+	- Improvement how Init() determines whether it was passed a blessed object
 
 0.09  Tue Mar 15 2011
 	- Fix for a possibly not reseted numbered match variable ($1).
@@ -25,10 +37,10 @@
 	  behavior of process-group Signals.
 
 0.05  Thu Okt 28 2010
-	- fixed a problem when using the old method of calling Proc::Daemon::Init
+	- Fixed a problem when using the old method of calling Proc::Daemon::Init
 	  without object (reported by Alex Samorukov). The parent process didn't
 	  exit.
-	- fixed a problem with Proc::ProcessTable 0.44: Under some conditions
+	- Fixed a problem with Proc::ProcessTable 0.44: Under some conditions
 	  'cmndline' retruns with space and/or other characters at the end.
 	- Update and small fixes in the documentation.
 
@@ -54,4 +66,4 @@
 	- Added Fork() and OpenMax() functions.
 
 0.01  Thu Jan 27 1998
-	- initial bundled release.
+	- Initial bundled release.

Modified: trunk/libproc-daemon-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/MANIFEST?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/MANIFEST (original)
+++ trunk/libproc-daemon-perl/MANIFEST Tue May 24 17:51:05 2011
@@ -1,9 +1,9 @@
-Changes
-lib/Proc/Daemon.pm
-lib/Proc/Daemon.pod
-Makefile.PL
-MANIFEST
-META.yml			Module meta-data (added by MakeMaker)
-README
-t/01_loadmodule.t
-t/02_testmodule.t
+Changes
+lib/Proc/Daemon.pm
+lib/Proc/Daemon.pod
+Makefile.PL
+MANIFEST
+README
+t/01_loadmodule.t
+t/02_testmodule.t
+META.yml                                 Module meta-data (added by MakeMaker)

Modified: trunk/libproc-daemon-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/META.yml?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/META.yml (original)
+++ trunk/libproc-daemon-perl/META.yml Tue May 24 17:51:05 2011
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                Proc-Daemon
-version:             0.10
+version:             0.11
 abstract:            ~
 license:             perl
 author:              

Modified: trunk/libproc-daemon-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/README?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/README (original)
+++ trunk/libproc-daemon-perl/README Tue May 24 17:51:05 2011
@@ -1,55 +1,55 @@
-README for Proc::Daemon
-
----------------------------------------------------------------------------
-SUMMARY
-
-Proc::Daemon provides the capability for a Perl program to run
-as a Unix daemon process.
-
----------------------------------------------------------------------------
-INSTALLATION
-
-This module can be installed on Perl 5.8.
-It was not tested on older versions but it might work.
-
-You should be able to install the module with the following:
-
-    perl Makefile.PL
-    make
-    make test
-    make install
-
-If you want to install in a specific directory, try:
-
-    perl Makefile.PL PREFIX=/tmp/myperl5
-    ...
-
-If you'd like to see the raw output of the tests, try:
-
-    ...
-    make test TEST_VERBOSE=1
-    ...
-
----------------------------------------------------------------------------
-DOCUMENTATION
-
-Documentation is in the Daemon.pod file and should automatically get installed
-with the module.
-
----------------------------------------------------------------------------
-COPYRIGHT (C) 1997-2011
-
-Earl Hood
-earl at earlhood.com
-http://www.earlhood.com/
-
-and
-
-Detlef Pilzecker
-deti at cpan.org
-http://www.secure-sip-server.net/
-
-All rights reserved.
-
-This module is free software. It may be used, redistributed and/or modified
-under the same terms as Perl itself.
+README for Proc::Daemon
+
+---------------------------------------------------------------------------
+SUMMARY
+
+Proc::Daemon provides the capability for a Perl program to run
+as a Unix daemon process.
+
+---------------------------------------------------------------------------
+INSTALLATION
+
+This module can be installed on Perl 5.8.
+It was not tested on older versions but it might work.
+
+You should be able to install the module with the following:
+
+    perl Makefile.PL
+    make
+    make test
+    make install
+
+If you want to install in a specific directory, try:
+
+    perl Makefile.PL PREFIX=/tmp/myperl5
+    ...
+
+If you'd like to see the raw output of the tests, try:
+
+    ...
+    make test TEST_VERBOSE=1
+    ...
+
+---------------------------------------------------------------------------
+DOCUMENTATION
+
+Documentation is in the Daemon.pod file and should automatically get installed
+with the module.
+
+---------------------------------------------------------------------------
+COPYRIGHT (C) 1997-2011
+
+Earl Hood
+earl at earlhood.com
+http://www.earlhood.com/
+
+and
+
+Detlef Pilzecker
+deti at cpan.org
+http://www.secure-sip-server.net/
+
+All rights reserved.
+
+This module is free software. It may be used, redistributed and/or modified
+under the same terms as Perl itself.

Modified: trunk/libproc-daemon-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/debian/changelog?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/debian/changelog (original)
+++ trunk/libproc-daemon-perl/debian/changelog Tue May 24 17:51:05 2011
@@ -1,3 +1,9 @@
+libproc-daemon-perl (0.11-1) UNRELEASED; urgency=low
+
+  * New upstream release
+
+ -- Salvatore Bonaccorso <carnil at debian.org>  Tue, 24 May 2011 19:50:52 +0200
+
 libproc-daemon-perl (0.10-1) unstable; urgency=low
 
   * New upstream release

Modified: trunk/libproc-daemon-perl/lib/Proc/Daemon.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/lib/Proc/Daemon.pm?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/lib/Proc/Daemon.pm (original)
+++ trunk/libproc-daemon-perl/lib/Proc/Daemon.pm Tue May 24 17:51:05 2011
@@ -21,7 +21,9 @@
 use strict;
 use POSIX();
 
-$Proc::Daemon::VERSION = '0.10';
+$Proc::Daemon::VERSION = '0.11';
+
+my %memory;
 
 
 ################################################################################
@@ -33,8 +35,12 @@
 #     child_STDIN  => '/path/to/daemon/STDIN.file'  -> defautls to '</dev/null'
 #     child_STDOUT => '/path/to/daemon/STDOUT.file' -> defaults to '+>/dev/null'
 #     child_STDERR => '/path/to/daemon/STDERR.file' -> defaults to '+>/dev/null'
+#     dont_close_fh => [ 'main::DATA', 'PackageName::DATA', 'STDOUT', ... ]
+#       -> arrayref with file handles you do not want to be closed in the daemon.
+#     dont_close_fd => [ 5, 8, ... ]                -> arrayref with file
+#       descriptors you do not want to be closed in the daemon.
 #     pid_file =>     '/path/to/pid/file.txt'       -> defaults to
-#       undef (= write no file)
+#       undef (= write no file).
 #     exec_command => 'perl /home/script.pl'        -> execute a system command
 #       via Perls *exec PROGRAM* at the end of the Init routine and never return.
 #       Must be an arrayref if you want to create several daemons at once.
@@ -88,13 +94,41 @@
     }
 
 
-    # Open a filehandle to the anonymous temporary pid file.
-    open( my $FH_MEMORY, "+>", undef ) || die "Can not open anonymous temporary pidfile: $!";
+    # Open a filehandle to an anonymous temporary pid file. If this is not
+    # possible (some environments do not allow all users to use anonymous
+    # temporary files), use the pid_file(s) to retrieve the PIDs for the parent.
+    my $FH_MEMORY;
+    unless ( open( $FH_MEMORY, "+>", undef ) || $self->{pid_file} ) {
+        die "Can not <open> anonymous temporary pidfile ('$!'), therefore you must add 'pid_file' as an Init() argument, e.g. to: '/tmp/proc_daemon_pids'";
+    }
+
+
+    # Get the file descriptors the user does not want to close.
+    my %dont_close_fd;
+    if ( defined $self->{dont_close_fd} ) {
+        die "The argument 'dont_close_fd' must be arrayref!"
+            if ref( $self->{dont_close_fd} ) ne 'ARRAY';
+        foreach ( @{ $self->{dont_close_fd} } ) {
+            die "All entries in 'dont_close_fd' must be numeric ('$_')!" if $_ =~ /\D/;
+            $dont_close_fd{ $_ } = 1;
+        }
+    }
+    # Get the file descriptors of the handles the user does not want to close.
+    if ( defined $self->{dont_close_fh} ) {
+        die "The argument 'dont_close_fh' must be arrayref!"
+            if ref( $self->{dont_close_fh} ) ne 'ARRAY';
+        foreach ( @{ $self->{dont_close_fh} } ) {
+            if ( defined ( my $fn = fileno $_ ) ) {
+                $dont_close_fd{ $fn } = 1;
+            }
+        }
+    }
 
 
     # If system commands are to be executed, put them in a list.
     my @exec_command = ref( $self->{exec_command} ) eq 'ARRAY' ? @{ $self->{exec_command} } : ( $self->{exec_command} );
     $#exec_command = 0 if $#exec_command < 0;
+
 
     # Create a daemon for every system command.
     foreach my $exec_command ( @exec_command ) {
@@ -178,16 +212,41 @@
                 # Here the second child is running.
 
 
-                # Close open file handles/descriptors.
-                # $FH_MEMORY also will be closed here.
-                foreach ( 0 .. OpenMax() ) { POSIX::close( $_ ) }
-
-                # Reopen STDIN, STDOUT and STDERR to '..._path' or to /dev/null.
-                # Data written on a null special file is discarded. Reads from
-                # the null special file always return end of file.
-                open( STDIN,  $self->{child_STDIN}  || "</dev/null" );
-                open( STDOUT, $self->{child_STDOUT} || "+>/dev/null" );
-                open( STDERR, $self->{child_STDERR} || "+>/dev/null" );
+                # Close all file handles and descriptors the user does not want
+                # to preserve.
+                my $count;
+                close $FH_MEMORY;
+                foreach ( 0 .. OpenMax() ) {
+                    unless ( $dont_close_fd{ $_ } ) {
+                        if    ( $_ == 0 ) { close STDIN  }
+                        elsif ( $_ == 1 ) { close STDOUT }
+                        elsif ( $_ == 2 ) { close STDERR }
+                        else { $count++ if POSIX::close( $_ ) }
+                    }
+                }
+
+                # Reopen STDIN, STDOUT and STDERR to 'child_STD...'-path or to
+                # /dev/null. Data written on a null special file is discarded.
+                # Reads from the null special file always return end of file.
+                open( STDIN,  $self->{child_STDIN}  || "</dev/null" )  unless $dont_close_fd{ 0 };
+                open( STDOUT, $self->{child_STDOUT} || "+>/dev/null" ) unless $dont_close_fd{ 1 };
+                open( STDERR, $self->{child_STDERR} || "+>/dev/null" ) unless $dont_close_fd{ 2 };
+
+                # Since <POSIX::close(FD)> is in some cases "secretly" closing
+                # file descriptors without telling it to perl, we need to
+                # re<open> and <CORE::close(FH)> as many files as we closed with
+                # <POSIX::close(FD)>. Otherwise it can happen (especially with
+                # FH opened by __DATA__ or __END__) that there will be two perl
+                # handles associated with one file, what can cause some
+                # confusion.   :-)
+                # see: http://rt.perl.org/rt3/Ticket/Display.html?id=72526
+                if ( $count ) {
+                    my @fh;
+                    foreach ( 1 .. $count ) { open $fh[ $_ ], "</dev/null" }
+                    # Perl will try to close all handles when @fh leaves scope
+                    # here, but the rude ones will sacrifice themselves to avoid
+                    # potential damage later.
+                }
 
 
                 # Execute a system command and never return.
@@ -208,11 +267,12 @@
 
 
             # Print the PID of the second child into ...
+            $pid ||= '';
             # ... the anonymous temporary pid file.
-            $pid ||= '';
-            print $FH_MEMORY "$pid\n";
-            close $FH_MEMORY;
-
+            if ( $FH_MEMORY ) {
+                print $FH_MEMORY "$pid\n";
+                close $FH_MEMORY;
+            }
             # ... the real 'pid_file'.
             if ( $self->{pid_file} ) {
                 open( my $FH_PIDFILE, "+>", $self->{pid_file} ) ||
@@ -243,15 +303,25 @@
 
     # Only first parent runs here.
 
-
-    # Get the daemon PIDs out of the anonymous temporary pid file.
-    seek( $FH_MEMORY, 0, 0 );
-    my @pid = map { chomp $_; $_ eq '' ? undef : $_ } <$FH_MEMORY>;
-    close $FH_MEMORY;
-
-
     # Exit if the context is looking for no value (void context).
     exit 0 unless defined wantarray;
+
+    # Get the daemon PIDs out of the anonymous temporary pid file
+    # or out of the real pid-file(s)
+    my @pid;
+    if ( $FH_MEMORY ) {
+        seek( $FH_MEMORY, 0, 0 );
+        @pid = map { chomp $_; $_ eq '' ? undef : $_ } <$FH_MEMORY>;
+        close $FH_MEMORY;
+    }
+    else {
+        foreach ( keys %{ $memory{'pid_file'} } ) {
+            open( $FH_MEMORY, "<", $_ ) || die "Can not open pid_file '<$_': $!";
+            push( @pid, <$FH_MEMORY> );
+            close $FH_MEMORY;
+        }
+    }
+
     # Return the daemon PIDs (from second child/ren) to the first parent.
     return ( wantarray ? @pid : $pid[0] );
 }
@@ -297,7 +367,6 @@
 #                 path/filename; false = no MODE to check
 # Returns: nothing
 ################################################################################
-my %memory;
 sub fix_filename {
     my Proc::Daemon $self = shift;
     my $key  = shift;

Modified: trunk/libproc-daemon-perl/lib/Proc/Daemon.pod
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-daemon-perl/lib/Proc/Daemon.pod?rev=74851&op=diff
==============================================================================
--- trunk/libproc-daemon-perl/lib/Proc/Daemon.pod (original)
+++ trunk/libproc-daemon-perl/lib/Proc/Daemon.pod Tue May 24 17:51:05 2011
@@ -79,7 +79,8 @@
 
 =item 6
 
-The second child closes all open file descriptors.
+The second child closes all open file descriptors (unless you define
+C<dont_close_fh> and/or C<dont_close_fd>).
 
 
 =item 7
@@ -149,6 +150,29 @@
 C</dev/null>. Default Mode is '+>' (write/read). You can define other Mode the
 same way as you do using Perls C<open> in a two-argument form, see example
 below.
+
+
+=item dont_close_fh
+
+If you define it, it must be an arrayref with file handles you want to preserve
+from the parent into the child (daemon). This may be the case if you have code
+below a C<__DATA__> token in your script or module called by C<use> or
+C<require>.
+
+    dont_close_fh => [ 'main::DATA', 'PackageName::DATA', ... ],
+
+You can add any kind of file handle to the array (expression in single quotes or
+a scalar variable), including 'STDIN', 'STDOUT' and 'STDERR'. Logically the path
+settings from above (C<child_STDIN>, ...) will be ignored in this case.
+
+DISCLAIMER: Using this argument may not detach your daemon fully from the
+parent! Use it at your own risk.
+
+
+=item dont_close_fd
+
+Same function and disclaimer as C<dont_close_fh>, but instead of file handles
+you write the numeric file descriptors inside the arrayref.
 
 
 =item pid_file




More information about the Pkg-perl-cvs-commits mailing list