14807: Fix crunch-run --list output when /var/lock is a symlink.
authorTom Clegg <tclegg@veritasgenetics.com>
Wed, 13 Feb 2019 16:11:03 +0000 (11:11 -0500)
committerTom Clegg <tclegg@veritasgenetics.com>
Fri, 15 Feb 2019 21:13:19 +0000 (16:13 -0500)
filepath.Walk(/var/lock) does not return entries inside /var/lock if
/var/lock is a symlink, as it is on debian:9.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

services/crunch-run/background.go

index a50853837085f6b7a6fd89bb61eba381dc9f6098..0d4612908c6c13a7f33243b3b76b1c2edd87af64 100644 (file)
@@ -155,8 +155,11 @@ func kill(uuid string, signal syscall.Signal, stdout, stderr io.Writer) error {
 
 // List UUIDs of active crunch-run processes.
 func ListProcesses(stdout, stderr io.Writer) int {
-       return exitcode(stderr, filepath.Walk(lockdir, func(path string, info os.FileInfo, err error) error {
-               if info.IsDir() {
+       // filepath.Walk does not follow symlinks, so we must walk
+       // lockdir+"/." in case lockdir itself is a symlink.
+       walkdir := lockdir + "/."
+       return exitcode(stderr, filepath.Walk(walkdir, func(path string, info os.FileInfo, err error) error {
+               if info.IsDir() && path != walkdir {
                        return filepath.SkipDir
                }
                if name := info.Name(); !strings.HasPrefix(name, lockprefix) || !strings.HasSuffix(name, locksuffix) {