]> git.etc.gen.nz Git - spong.git/commitdiff
Initial revision
authorStephen L Johnson <sjohnson@monsters.org>
Tue, 16 Nov 1999 04:37:18 +0000 (04:37 +0000)
committerStephen L Johnson <sjohnson@monsters.org>
Tue, 16 Nov 1999 04:37:18 +0000 (04:37 +0000)
src/lib/Spong/Daemon.pm [new file with mode: 0755]

diff --git a/src/lib/Spong/Daemon.pm b/src/lib/Spong/Daemon.pm
new file mode 100755 (executable)
index 0000000..10ace60
--- /dev/null
@@ -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(STDOUT,">/dev/null");
+      open(STDERR,">/dev/null");
+
+   # Become session group leader
+   POSIX::setsid();
+
+   }
+
+}
+
+1;
+