mountlib: correctly daemonize for compatibility with automount - #5593

This patch will:
- add --daemon-wait flag to control the time to wait for background mount
- remove dependency on sevlyar/go-daemon and implement backgrounding directly
- avoid setsid during backgrounding as it can result in race under Automount
- provide a fallback PATH to correctly run `fusermount` under systemd as it
  runs mount units without standard environment variables
- correctly handle ^C pressed while background process is being setting up
This commit is contained in:
Ivan Andreev 2021-08-18 14:07:09 +03:00
parent 8c10dee510
commit 8b8a943dd8
9 changed files with 192 additions and 74 deletions

21
fs/daemon_unix.go Normal file
View file

@ -0,0 +1,21 @@
// Daemonization interface for Unix platforms (common definitions)
//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js
package fs
import (
"os"
)
// We use a special environment variable to let the child process know its role.
const (
DaemonMarkVar = "_RCLONE_DAEMON_"
DaemonMarkChild = "_rclone_daemon_"
)
// IsDaemon returns true if this process runs in background
func IsDaemon() bool {
return os.Getenv(DaemonMarkVar) == DaemonMarkChild
}