未验证 提交 0a8e622a 编写于 作者: D Davies Liu 提交者: GitHub

support relative path in daemon mode (#266)

上级 3a890d48
......@@ -214,6 +214,21 @@ func mount(c *cli.Context) error {
vfs.Init(conf, m, store)
if c.Bool("background") && os.Getenv("JFS_FOREGROUND") == "" {
if runtime.GOOS != "windows" {
d := c.String("cache-dir")
if d != "memory" && !strings.HasPrefix(d, "/") {
ad, err := filepath.Abs(d)
if err != nil {
logger.Fatalf("cache-dir should be absolute path in daemon mode")
} else {
for i, a := range os.Args {
if a == d || a == "--cache-dir="+d {
os.Args[i] = a[:len(a)-len(d)] + ad
}
}
}
}
}
// The default log to syslog is only in daemon mode.
utils.InitLoggers(!c.Bool("no-syslog"))
err := makeDaemon(conf.Format.Name, conf.Mountpoint)
......
......@@ -19,6 +19,7 @@ package main
import (
"os"
"path/filepath"
"syscall"
"time"
......@@ -51,6 +52,21 @@ func makeDaemon(name, mp string) error {
logger.Fatalf("fail to mount after 10 seconds, please mount in foreground")
return nil
}
// the current dir will be changed to root in daemon,
// so the mount point has to be an absolute path.
if godaemon.Stage() == 0 {
for i, a := range os.Args {
if a == mp {
amp, err := filepath.Abs(mp)
if err == nil {
os.Args[i] = amp
} else {
logger.Warnf("abs of %s: %s", mp, err)
}
}
}
}
_, _, err := godaemon.MakeDaemon(&godaemon.DaemonAttr{OnExit: onExit})
return err
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册