summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2002-08-07 23:33:33 +0000
committerPeter Palfrader <peter@palfrader.org>2002-08-07 23:33:33 +0000
commit91e83685fe324c7fa8648e987295d094089dbfec (patch)
tree50588515ed0772e21ef34338d201741b9fece77a
parentcf28f8dc58c855261ceb624dab6bbab642887daf (diff)
Detach correctly now
-rwxr-xr-xpingd26
1 files changed, 14 insertions, 12 deletions
diff --git a/pingd b/pingd
index 01999fb..5d872ef 100755
--- a/pingd
+++ b/pingd
@@ -3,7 +3,7 @@
$| = 1;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: pingd,v 1.53 2002/08/05 17:46:17 weasel Exp $
+# $Id: pingd,v 1.54 2002/08/07 23:33:33 weasel Exp $
#
=pod
@@ -276,6 +276,7 @@ use Echolot::Pinger;
use Echolot::Stats;
use Echolot::Commands;
use Echolot::Thesaurus;
+use POSIX qw(setsid);
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
@@ -616,17 +617,18 @@ if ($COMMAND eq 'add' || $COMMAND eq 'delete') {
make_dirs();
if ($params->{'detach'}) {
print "Detaching.\n";
- unless (fork()) {
- close STDOUT;
- close STDERR;
- open (STDOUT, ">>output") or die ("Cannot open 'output' as STDOUT\n");
- open (STDERR, ">&STDOUT") or die ("Cannot dup STDOUT as STDERR\n");
- close STDIN;
- $redirected_stdio = 1;
- print "Startup at ".scalar localtime().".\n";
- daemon_run( $params->{'process'} );
- print "done at ".scalar localtime().".\n";
- };
+ exit(0) if (fork());
+ POSIX::setsid();
+ exit(0) if (fork());
+ close STDOUT;
+ close STDERR;
+ open (STDOUT, ">>output") or die ("Cannot open 'output' as STDOUT\n");
+ open (STDERR, ">&STDOUT") or die ("Cannot dup STDOUT as STDERR\n");
+ close STDIN;
+ $redirected_stdio = 1;
+ print "Startup at ".scalar localtime().".\n";
+ daemon_run( $params->{'process'} );
+ print "done at ".scalar localtime().".\n";
} else {
daemon_run( $params->{'process'} );
};