diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go index ae541518757bcb4d5ddc35af9131b315fa189d75..640eba1f1e81a3444f3d1a629457f488be600366 100644 --- a/go/cmd/gitlab-shell/main.go +++ b/go/cmd/gitlab-shell/main.go @@ -12,11 +12,15 @@ import ( var ( binDir string rootDir string + initErr error ) func init() { - binDir = filepath.Dir(os.Args[0]) - rootDir = filepath.Dir(binDir) + ex, initErr := os.Executable() + if initErr == nil { + binDir = filepath.Dir(ex) + rootDir = filepath.Dir(binDir) + } } func migrate(*config.Config) (int, bool) { @@ -38,6 +42,10 @@ func execRuby() { } func main() { + if initErr != nil { + fmt.Fprintln(os.Stderr, "Failed to determine configuration file or ruby executable paths, exiting") + os.Exit(1) + } // Fall back to Ruby in case of problems reading the config, but issue a // warning as this isn't something we can sustain indefinitely config, err := config.NewFromDir(rootDir)