From 529226a6676d7a38c58612383569efbd62239e0b Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Tue, 16 Nov 1999 04:37:18 +0000 Subject: [PATCH] Initial revision --- src/lib/Spong/Daemon.pm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 src/lib/Spong/Daemon.pm 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; + -- 2.30.2