--- ./ddclient.orig	2011-07-25 19:41:39.000000000 -0700
+++ ./ddclient	2011-07-25 19:41:48.000000000 -0700
@@ -1,4 +1,3 @@
-#!/usr/bin/perl -w
 #!/usr/local/bin/perl -w
 ######################################################################
 # $Id: ddclient 130 2011-07-11 21:02:07Z wimpunk $
@@ -19,6 +18,7 @@
 use Getopt::Long;
 use Sys::Hostname;
 use IO::Socket;
+use POSIX 'setsid';
 
 my ($VERSION) = q$Revision: 130 $ =~ /(\d+)/;
 
@@ -668,6 +668,9 @@
     ;
 } elsif (opt('daemon')) {
     $SIG{'CHLD'}   = 'IGNORE';
+    chdir '/';
+    open(STDIN,  "</dev/null");
+    open(STDOUT, ">/dev/null");
     my $pid = fork;
     if ($pid < 0) {
 	print STDERR "${program}: can not fork ($!)\n";
@@ -675,10 +678,9 @@
     } elsif ($pid) {
 	exit 0;
     }
+    setsid;
     $SIG{'CHLD'}   = 'DEFAULT';
-    open(STDOUT, ">/dev/null");
-    open(STDERR, ">/dev/null");
-    open(STDIN,  "</dev/null");
+    open(STDERR, "&STDOUT");
 }
 
 # write out the pid file if we're daemon'ized
@@ -1463,17 +1465,17 @@
     ## execute the command.
     local *FD;
     if (! open(FD, $cmd)) {
-	printf STDERR "$program: cannot execute command %s.\n", $cmd;
+	warning("$program: cannot execute command %s.\n", $cmd);
 
     } elsif ($stdin && (! print FD "$stdin\n")) {
-	printf STDERR "$program: failed writting to %s.\n", $cmd;
+	warning("$program: failed writing to %s.\n", $cmd);
 	close(FD);
 
     } elsif (! close(FD)) {
-	printf STDERR "$program: failed closing %s.($@)\n", $cmd;
+	warning("$program: failed closing %s.($@)\n", $cmd);
 
     } elsif (opt('exec') && $?) {
-	printf STDERR "$program: failed %s. ($@)\n", $cmd;
+	warning("$program: failed %s. ($@)\n", $cmd);
 
     } else {
 	$ok = 1;
