mount: notice daemon dying much quicker

Before this change we waited until until the timeout to check the
daemon was alive.

Now we check it every 100ms like we do the mount status.

This also fixes compiling on all platforms which was broken by the
previous change

9bfbf2a4a mount: fix macOS not noticing errors with --daemon

See: https://forum.rclone.org/t/rclone-mount-daemon-exits-successfully-even-when-mount-fails/43146
This commit is contained in:
Nick Craig-Wood
2023-11-29 15:11:11 +00:00
parent 97d7945cef
commit caf5dd9d5e
5 changed files with 66 additions and 45 deletions

View File

@ -1,15 +1,16 @@
//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js
//go:build unix
// Package daemonize provides daemonization interface for Unix platforms.
package daemonize
import (
"fmt"
"os"
"strings"
"syscall"
"github.com/rclone/rclone/fs"
"golang.org/x/sys/unix"
)
// StartDaemon runs background twin of current process.
@ -108,3 +109,20 @@ func argsToEnv(origArgs, origEnv []string) (args, env []string) {
}
return
}
// Check returns non nil if the daemon process has died
func Check(daemon *os.Process) error {
var status unix.WaitStatus
wpid, err := unix.Wait4(daemon.Pid, &status, unix.WNOHANG, nil)
// fs.Debugf(nil, "wait4 returned wpid=%d, err=%v, status=%d", wpid, err, status)
if err != nil {
return err
}
if wpid == 0 {
return nil
}
if status.Exited() {
return fmt.Errorf("daemon exited with error code %d", status.ExitStatus())
}
return nil
}