From: Stephen L Johnson Date: Tue, 16 Nov 1999 04:37:18 +0000 (+0000) Subject: Initial import X-Git-Tag: start~19 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d830f0ebd14b4e49497cb17adf31d2a5d0fce8c;p=spong.git Initial import --- diff --git a/src/lib/Spong/Daemon.pm b/src/lib/Spong/Daemon.pm new file mode 100755 index 0000000..10ace60 --- /dev/null +++ b/src/lib/Spong/Daemon.pm @@ -0,0 +1,39 @@ +#!/usr/local/bin/perl +# +# This package is a provide the spong programs a standard way to daemonize + +package Spong::Daemon; + +use strict; + + +use POSIX qw(setsid); +use Carp; + + +# Daemonize myself + +sub Daemonize { + my($pid, $sid); + + if ( ! defined($pid = fork()) ) { + croak "ERROR: Could not fork: $!"; + } elsif ( $pid ) { + # I'm the parent, just exit gracefully + exit(0); + } else { + # I'm the child + + open(STDIN,"/dev/null"); + open(STDERR,">/dev/null"); + + # Become session group leader + POSIX::setsid(); + + } + +} + +1; +