Revise check for open files in scan_incoming
authorJacob Bachmeyer <jcb@gnu.org>
Sat, 15 Oct 2022 03:24:04 +0000 (22:24 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Sat, 15 Oct 2022 03:24:04 +0000 (22:24 -0500)
The old code would incorrectly assume that no files are open if the
lsof program fails to run; this new code uses a list-form pipe open
introduced in Perl 5.8.0 instead of an implied fork.

Also use File::Spec to form the arguments to lsof.

gatekeeper.pl

index 4706e3ca6440a027ba4531d59e679074b41d96cb..d26db21792a07a0309f48ad2c7ac46c23bf1434b 100755 (executable)
@@ -937,29 +937,23 @@ sub scan_incoming {
   # the open files because they are owned by another user.
   # On modern (Debian) systems, condition a) is not met.
   my @lsof_args = (LSOF_BIN, "-Fn",
-       map { "$directory/$_" } keys %possible);
-  ftp_syslog('debug', "DEBUG: "
-            ."lsof command line: " . join(' ',@lsof_args))
+       map { File::Spec->catfile($directory, $_) } keys %possible);
+  ftp_syslog('debug', "DEBUG: lsof command line: " . join(' ',@lsof_args))
     if DEBUG;
-  my $pid = open (LSOF, "-|");
 
-  if ($pid) {      # parent
-    while (defined (my $line = <LSOF>)) {
-      ftp_syslog('debug', "DEBUG: " . "lsof output: $line")
-       if DEBUG;
-      # only look at the name lines.
-      next unless $line =~ /^n${directory}\/(.+)$/;
-      ftp_syslog('debug', "DEBUG: "
-                ."upload in progress for $1, ignoring during this run")
-       if DEBUG;
-      delete ($possible{$1})
-       or ftp_warn("WARNING: lsof found unrequested but open $1?!");
-    }
-    close (LSOF);
-  } else {       # child
-    exec (@lsof_args)
-      or ftp_die("FATAL: cannot exec lsof: $!");
+  open LSOF, '-|', @lsof_args
+    or ftp_die("FATAL: cannot spawn lsof: $!");;
+  while (<LSOF>) {
+    ftp_syslog('debug', "DEBUG: lsof output: $_") if DEBUG;
+    # only look at the name lines
+    next unless /^n${directory}\/(.+)$/;
+    ftp_syslog('debug', "DEBUG: "
+              ."upload in progress for $1, ignoring during this run")
+      if DEBUG;
+    delete ($possible{$1})
+      or ftp_warn("WARNING: lsof found unrequested but open $1?!");
   }
+  close (LSOF);
 
   my @ret;