diff --git a/cmd/cmd_config.go b/cmd/cmd_config.go index 439415c..f59d858 100644 --- a/cmd/cmd_config.go +++ b/cmd/cmd_config.go @@ -56,6 +56,7 @@ func build(path string, optionsPath string) error { if optionsPath != "" { optionsPath = filepath.Join(workingDir, optionsPath) } + os.Chdir(workingDir) } options, err := readConfigAt(path) if err != nil { diff --git a/custom/custom.go b/custom/custom.go index ba822a8..d311ceb 100644 --- a/custom/custom.go +++ b/custom/custom.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "os" + "path/filepath" "time" "unsafe" @@ -100,6 +101,7 @@ func generateConfig(path *C.char) (res *C.char) { } func generateConfigFromFile(path string, configOpt config.ConfigOptions) (string, error) { + os.Chdir(filepath.Dir(path)) content, err := os.ReadFile(path) if err != nil { return "", err @@ -146,6 +148,7 @@ func startService(delayStart bool) error { if err != nil { return stopAndAlert(EmptyConfiguration, err) } + os.Chdir(filepath.Dir(*activeConfigPath)) var patchedOptions *option.Options patchedOptions, err = config.BuildConfig(*configOptions, options) if err != nil { diff --git a/custom/service.go b/custom/service.go index d8ca677..32dc131 100644 --- a/custom/service.go +++ b/custom/service.go @@ -25,6 +25,7 @@ var ( func Setup(basePath string, workingPath string, tempPath string) { libbox.Setup(basePath, workingPath, tempPath, false) sWorkingPath = workingPath + os.Chdir(sWorkingPath) sTempPath = tempPath sUserID = os.Getuid() sGroupID = os.Getgid() diff --git a/mobile/mobile.go b/mobile/mobile.go index bbb1241..2a52f9c 100644 --- a/mobile/mobile.go +++ b/mobile/mobile.go @@ -3,6 +3,7 @@ package mobile import ( "encoding/json" "os" + "path/filepath" "github.com/hiddify/libcore/config" _ "github.com/sagernet/gomobile" @@ -18,6 +19,7 @@ func Parse(path string, tempPath string, debug bool) error { } func BuildConfig(path string, configOptionsJson string) (string, error) { + os.Chdir(filepath.Dir(path)) fileContent, err := os.ReadFile(path) if err != nil { return "", err