r63024 - in /branches/upstream/libproc-daemon-perl: ./ current/ current/Changes current/Daemon.pm current/MANIFEST current/Makefile.PL current/README current/t/ current/t/00modload.t current/t/01filecreate.t
zugschlus at users.alioth.debian.org
zugschlus at users.alioth.debian.org
Tue Sep 28 12:37:33 UTC 2010
Author: zugschlus
Date: Tue Sep 28 12:37:22 2010
New Revision: 63024
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=63024
Log:
[svn-inject] Installing original source of libproc-daemon-perl (0.03)
Added:
branches/upstream/libproc-daemon-perl/
branches/upstream/libproc-daemon-perl/current/
branches/upstream/libproc-daemon-perl/current/Changes
branches/upstream/libproc-daemon-perl/current/Daemon.pm
branches/upstream/libproc-daemon-perl/current/MANIFEST
branches/upstream/libproc-daemon-perl/current/Makefile.PL
branches/upstream/libproc-daemon-perl/current/README
branches/upstream/libproc-daemon-perl/current/t/
branches/upstream/libproc-daemon-perl/current/t/00modload.t
branches/upstream/libproc-daemon-perl/current/t/01filecreate.t
Added: branches/upstream/libproc-daemon-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/Changes?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/Changes (added)
+++ branches/upstream/libproc-daemon-perl/current/Changes Tue Sep 28 12:37:22 2010
@@ -1,0 +1,15 @@
+Revision history for Perl extension Proc::Daemon.
+
+0.03 Thu Jun 19 2003
+ - Licensing is more explicit: Either GPL or Artistic.
+ - Updated author contact information.
+
+0.02 Sat Apr 17 1999
+ - init() function superceded by Init() function.
+ - All open files are closed during daemonization.
+ - A double fork is now down to avoid the potential of acquiring
+ a controlling terminal.
+ - Added Fork() and OpenMax() functions.
+
+0.01 Thu Jan 27 1998
+ - initial bundled release
Added: branches/upstream/libproc-daemon-perl/current/Daemon.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/Daemon.pm?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/Daemon.pm (added)
+++ branches/upstream/libproc-daemon-perl/current/Daemon.pm Tue Sep 28 12:37:22 2010
@@ -1,0 +1,232 @@
+##---------------------------------------------------------------------------##
+## File:
+## @(#) Daemon.pm 1.3 03/06/19 17:50:34
+## Author:
+## Earl Hood earl at earlhood.com
+## Description:
+## POD at end-of-file.
+##---------------------------------------------------------------------------##
+## Copyright (C) 1997-1999 Earl Hood, earl at earlhood.com
+## All rights reserved.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of either:
+##
+## a) the GNU General Public License as published by the Free Software
+## Foundation; either version 1, or (at your option) any later
+## version, or
+##
+## b) the "Artistic License" which comes with Perl.
+##---------------------------------------------------------------------------##
+
+package Proc::Daemon;
+
+use strict;
+use vars qw( $VERSION @ISA @EXPORT_OK );
+use Exporter;
+ at ISA = qw( Exporter );
+
+$VERSION = "0.03";
+ at EXPORT_OK = qw( Fork OpenMax );
+
+##---------------------------------------------------------------------------##
+
+use Carp;
+use POSIX;
+
+##---------------------------------------------------------------------------##
+## Fork(): Try to fork if at all possible. Function will croak
+## if unable to fork.
+##
+sub Fork {
+ my($pid);
+ FORK: {
+ if (defined($pid = fork)) {
+ return $pid;
+ } elsif ($! =~ /No more process/) {
+ sleep 5;
+ redo FORK;
+ } else {
+ croak "Can't fork: $!";
+ }
+ }
+}
+
+##---------------------------------------------------------------------------##
+## OpenMax(): Return the maximum number of possible file descriptors.
+## If sysconf() does not give us value, we punt with our own value.
+##
+sub OpenMax {
+ my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
+ (!defined($openmax) || $openmax < 0) ? 64 : $openmax;
+}
+
+##---------------------------------------------------------------------------##
+## Init(): Become a daemon.
+##
+sub Init {
+ my $oldmode = shift || 0;
+ my($pid, $sess_id, $i);
+
+ ## Fork and exit parent
+ if ($pid = Fork) { exit 0; }
+
+ ## Detach ourselves from the terminal
+ croak "Cannot detach from controlling terminal"
+ unless $sess_id = POSIX::setsid();
+
+ ## Prevent possibility of acquiring a controling terminal
+ if (!$oldmode) {
+ $SIG{'HUP'} = 'IGNORE';
+ if ($pid = Fork) { exit 0; }
+ }
+
+ ## Change working directory
+ chdir "/";
+
+ ## Clear file creation mask
+ umask 0;
+
+ ## Close open file descriptors
+ foreach $i (0 .. OpenMax) { POSIX::close($i); }
+
+ ## Reopen stderr, stdout, stdin to /dev/null
+ open(STDIN, "+>/dev/null");
+ open(STDOUT, "+>&STDIN");
+ open(STDERR, "+>&STDIN");
+
+ $oldmode ? $sess_id : 0;
+}
+*init = \&Init;
+
+##---------------------------------------------------------------------------##
+
+1;
+
+__END__
+
+=head1 NAME
+
+Proc::Daemon - Run Perl program as a daemon process
+
+=head1 SYNOPSIS
+
+ use Proc::Daemon;
+ Proc::Daemon::Init;
+
+=head1 DESCRIPTION
+
+This module contains the routine B<Init> which can be called by
+a Perl program to initialize itself as a daemon. A daemon is a
+process that runs in the background with no controlling terminal.
+Generally servers (like FTP and HTTP servers) run as daemon processes.
+Note, do not make the mistake that a daemon == server.
+
+The B<Proc::Daemon::Init> function does the following:
+
+=over 4
+
+=item 1
+
+Forks a child and exits the parent process.
+
+=item 2
+
+Becomes a session leader (which detaches the program from
+the controlling terminal).
+
+=item 3
+
+Forks another child process and exits first child. This prevents
+the potential of acquiring a controlling terminal.
+
+=item 4
+
+Changes the current working directory to "/".
+
+=item 5
+
+Clears the file creation mask.
+
+=item 6
+
+Closes all open file descriptors.
+
+=back
+
+You will notice that no logging facility, or other functionality
+is performed. B<Proc::Daemon::Init> just performs the main steps
+to initialize a program as daemon. Since other funtionality can vary
+depending on the nature of the program, B<Proc::Daemon> leaves
+the implementation of other desired functionality to the
+caller, or other module/library (like B<Sys::Syslog>).
+
+There is no meaningful return value B<Proc::Daemon::Init>. If an
+error occurs in B<Init> so it cannot perform the above steps, than
+it croaks with an error message. One can prevent program termination
+by using eval.
+
+=head1 OTHER FUNCTIONS
+
+B<Proc::Daemon> also defines some other functions. These functions
+can be imported into the callers name space if the function names
+are specified during the B<use> declaration:
+
+=head2 Fork
+
+B<Fork> is like the built-in B<fork>, but will try to fork if at all
+possible, retrying if necessary. If not possible, B<Fork> will
+croak.
+
+=head2 OpenMax
+
+B<OpenMax> returns the maximum file descriptor number.
+If undetermined, 64 will be returned.
+
+=head1 NOTES
+
+=over 4
+
+=item *
+
+B<Proc::Daemon::init> is still available for backwards capatibilty.
+However, it will not perform the double fork, and will return the
+session ID.
+
+=back
+
+=head1 AUTHOR
+
+Earl Hood, earl at earlhood.com
+
+http://www.earlhood.com/
+
+=head1 CREDITS
+
+Implementation of B<Proc::Daemon> derived from the following sources:
+
+=over 4
+
+=item *
+
+B<Advanced Programming in the UNIX Environment>, by W. Richard Stevens.
+Addison-Wesley, Copyright 1992.
+
+=item *
+
+B<UNIX Network Progamming>, Vol 1, by W. Richard Stevens.
+Prentice-Hall PTR, Copyright 1998.
+
+=back
+
+=head1 DEPENDENCIES
+
+B<Carp>, B<POSIX>.
+
+=head1 SEE ALSO
+
+L<POSIX>,
+L<Sys::Syslog>
+
+=cut
+
Added: branches/upstream/libproc-daemon-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/MANIFEST?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/MANIFEST (added)
+++ branches/upstream/libproc-daemon-perl/current/MANIFEST Tue Sep 28 12:37:22 2010
@@ -1,0 +1,7 @@
+Changes
+Daemon.pm
+MANIFEST
+Makefile.PL
+README
+t/00modload.t
+t/01filecreate.t
Added: branches/upstream/libproc-daemon-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/Makefile.PL?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/Makefile.PL (added)
+++ branches/upstream/libproc-daemon-perl/current/Makefile.PL Tue Sep 28 12:37:22 2010
@@ -1,0 +1,9 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+ NAME => 'Proc::Daemon',
+ DISTNAME => 'Proc-Daemon',
+ VERSION_FROM => 'Daemon.pm', # finds $VERSION
+ dist => { COMPRESS => 'gzip', SUFFIX => 'gz'},
+);
Added: branches/upstream/libproc-daemon-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/README?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/README (added)
+++ branches/upstream/libproc-daemon-perl/current/README Tue Sep 28 12:37:22 2010
@@ -1,0 +1,48 @@
+README for Proc::Daemon v0.03
+
+---------------------------------------------------------------------------
+ Copyright (C) 1997-1999 Earl Hood, earl at earlhood.com
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of either:
+
+ a) the GNU General Public License as published by the Free Software
+ Foundation; either version 1, or (at your option) any later
+ version, or
+
+ b) the "Artistic License" which comes with Perl.
+
+---------------------------------------------------------------------------
+SUMMARY
+
+Proc::Daemon provides the capability for a Perl program to run
+as a Unix daemon process.
+
+---------------------------------------------------------------------------
+INSTALLATION
+
+You should be able to install the module(s) 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
+ make
+ make test
+ make install
+
+---------------------------------------------------------------------------
+DOCUMENTATION
+
+Documentation is in POD format and should automatically get installed
+with the module(s).
+
+---------------------------------------------------------------------------
+Earl Hood, earl at earlhood.com
+<http://www.earlhood.com/>
+03/06/19 17:50:50
Added: branches/upstream/libproc-daemon-perl/current/t/00modload.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/t/00modload.t?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/t/00modload.t (added)
+++ branches/upstream/libproc-daemon-perl/current/t/00modload.t Tue Sep 28 12:37:22 2010
@@ -1,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n"; }
+END {print "not ok 1\n" unless $loaded;}
+use Proc::Daemon;
+$loaded = 1;
+print "ok 1\n";
Added: branches/upstream/libproc-daemon-perl/current/t/01filecreate.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libproc-daemon-perl/current/t/01filecreate.t?rev=63024&op=file
==============================================================================
--- branches/upstream/libproc-daemon-perl/current/t/01filecreate.t (added)
+++ branches/upstream/libproc-daemon-perl/current/t/01filecreate.t Tue Sep 28 12:37:22 2010
@@ -1,0 +1,32 @@
+print "1..1\n";
+
+use Proc::Daemon;
+use Cwd;
+
+## Since a daemon will not be able to print terminal output, we
+## have a test daemon create a file, and another process test for
+## its existence.
+
+## Try to make sure we are in the test directory
+my $cwd = Cwd::cwd();
+ chdir 't' if ($cwd !~ m|/t$|);
+ $cwd = Cwd::cwd();
+
+## Test filename
+my $file = join('/', $cwd, ',im_alive');
+
+## Parent process will check if file created. Child becomes the daemon.
+my $pid;
+if ($pid = Proc::Daemon::Fork) {
+ sleep(5); # Punt on sleep time, 5 seconds should be enough
+ if (-e $file) {
+ unlink $file;
+ print "ok 1\n";
+ } else {
+ print "not ok 1\n";
+ }
+} else {
+ Proc::Daemon::Init;
+ open(FILE, ">$file") || die;
+ close(FILE);
+}
More information about the Pkg-perl-cvs-commits
mailing list