start weed with mount in background

This commit is contained in:
danielflira 2021-06-20 02:48:46 -03:00
parent b3eb4fecc7
commit f1d207a0fe

View file

@ -22,6 +22,7 @@ func runFuse(cmd *Command, args []string) bool {
rawArgsLen := len(rawArgs)
option := strings.Builder{}
options := []parameter{}
masterProcess := true
// first parameter
i := 0
@ -98,6 +99,8 @@ func runFuse(cmd *Command, args []string) bool {
parameter := options[i]
switch parameter.name {
case "child":
masterProcess = false
case "arg0":
mountOptions.dir = &parameter.value
case "filer":
@ -187,6 +190,27 @@ func runFuse(cmd *Command, args []string) bool {
}
}
// the master start the child, release it then finish himself
if masterProcess {
arg0 := os.Args[0]
argv := append(os.Args, "-o", "child")
attr := os.ProcAttr{}
child, err := os.StartProcess(arg0, argv, &attr)
if err != nil {
panic(fmt.Errorf("master process can not start child process: %s", err))
}
err = child.Release()
if err != nil {
panic(fmt.Errorf("master process can not release child process: %s", err))
}
return true
}
// I don't know why PATH environment variable is lost
if err := os.Setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"); err != nil {
panic(fmt.Errorf("setenv: %s", err))