From: Stephen L Johnson Date: Tue, 16 Nov 1999 04:37:18 +0000 (+0000) Subject: Initial revision X-Git-Tag: spong-2_6-beta7~24 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=529226a6676d7a38c58612383569efbd62239e0b;p=spong.git Initial revision --- 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; +