tele-watch.pl
branchfoerste
changeset 43 f38791e4991c
parent 37 1b66d7a6cbdf
child 44 21cf0d0ca51b
--- a/tele-watch.pl	Wed Feb 18 14:06:16 2015 +0100
+++ b/tele-watch.pl	Fri Feb 20 15:32:54 2015 +0100
@@ -56,19 +56,26 @@
 		my ($uid, $gid, $mode) = (stat $dir)[4, 5, 2];
 		defined(my $pid = fork()) or die "Can't fork: $!\n";
 		if ($pid == 0) {
+			# avoid execution of END{ } blocks
+                        $clean_pids{$$} = 1;
 			chdir $dir or die "Can't chdir to $dir: $!\n";
 			system("bzr init");
 			finddepth(sub {
 				chown($uid, $gid, $_);
 				chmod($mode & 07777, $_);
 			}, ".bzr");
-			exec "true";	# avoid execution of END{ } blocks
 		}
 		wait;
 	},
 );
 
+my %clean_pids;
+
 MAIN: {
+
+    # avoid execution of END{ } blocks
+    $clean_pids{$$} = 1;
+
     my @_ARGV = @ARGV;
     my %TARGET;
 
@@ -128,6 +135,9 @@
 
     # cleanup code
     END {
+        
+        return if delete $clean_pids{$$};
+
         foreach (keys %TARGET) {
             if (readf("$_/.watched") || 0 == $$) {
                 unlink "$_/.watched";
@@ -163,9 +173,7 @@
         open(STDOUT, ">/dev/null") or die "Can't redir STDOUT: $!\n";
         defined(my $pid = fork()) or die "Can't fork: $!\n";
         if ($pid) {
-            %TARGET = ();
             notice "child is $pid";
-            $opt_pidfile = "";
             exit 0;
         }
         setsid();