mirror of
https://github.com/rclone/rclone.git
synced 2025-08-12 15:07:24 +02:00
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:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user