tele-watch.pl
changeset 53 d08f47fd8542
parent 52 8215da26b2fe
parent 44 21cf0d0ca51b
--- a/tele-watch.pl	Thu Apr 26 11:45:09 2018 +0200
+++ b/tele-watch.pl	Thu Apr 26 11:46:36 2018 +0200
@@ -57,6 +57,8 @@
 		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";
 			for ('public') {
 				mkdir $_;
@@ -68,7 +70,6 @@
 				chown($uid, $gid, $_);
 				chmod($mode & 07777, $_);
 			}, ".bzr");
-			exec "true";	# avoid execution of END{ } blocks
 		}
 		wait;
 	},
@@ -90,7 +91,13 @@
 	},
 );
 
+my %clean_pids;
+
 MAIN: {
+
+    # avoid execution of END{ } blocks
+    $clean_pids{$$} = 1;
+
     my @_ARGV = @ARGV;
     my %TARGET;
 
@@ -150,6 +157,9 @@
 
     # cleanup code
     END {
+        
+        return if delete $clean_pids{$$};
+
         foreach (keys %TARGET) {
             if (readf("$_/.watched") || 0 == $$) {
                 unlink "$_/.watched";
@@ -185,9 +195,8 @@
         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 = "";
+            # detect (u)mounts over watchpoints/targets
             exit 0;
         }
         setsid();