mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 19:40:36 +00:00
233db64cc1
a little copying is better than a little dependency -- go proverb We have this dependency on docker, a.k.a moby: a gigantic library, and we only need ~70 LOC, so here I tried moving it inline instead. Co-authored-by: Felix Lange <fjl@twurst.com>
33 lines
774 B
Go
33 lines
774 B
Go
// This file originates from Docker/Moby,
|
|
// https://github.com/moby/moby/blob/master/pkg/reexec/
|
|
// Licensed under Apache License 2.0: https://github.com/moby/moby/blob/master/LICENSE
|
|
// Copyright 2013-2018 Docker, Inc.
|
|
|
|
//go:build !linux
|
|
|
|
package reexec
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Self returns the path to the current process's binary.
|
|
// Uses os.Args[0].
|
|
func Self() string {
|
|
name := os.Args[0]
|
|
if filepath.Base(name) == name {
|
|
if lp, err := exec.LookPath(name); err == nil {
|
|
return lp
|
|
}
|
|
}
|
|
// handle conversion of relative paths to absolute
|
|
if absName, err := filepath.Abs(name); err == nil {
|
|
return absName
|
|
}
|
|
// if we couldn't get absolute name, return original
|
|
// (NOTE: Go only errors on Abs() if os.Getwd fails)
|
|
return name
|
|
}
|