github.com/ethereum/go-ethereum@v1.14.3/internal/reexec/self_others.go (about)

     1  // This file originates from Docker/Moby,
     2  // https://github.com/moby/moby/blob/master/pkg/reexec/
     3  // Licensed under Apache License 2.0: https://github.com/moby/moby/blob/master/LICENSE
     4  // Copyright 2013-2018 Docker, Inc.
     5  
     6  //go:build !linux
     7  
     8  package reexec
     9  
    10  import (
    11  	"os"
    12  	"os/exec"
    13  	"path/filepath"
    14  )
    15  
    16  // Self returns the path to the current process's binary.
    17  // Uses os.Args[0].
    18  func Self() string {
    19  	name := os.Args[0]
    20  	if filepath.Base(name) == name {
    21  		if lp, err := exec.LookPath(name); err == nil {
    22  			return lp
    23  		}
    24  	}
    25  	// handle conversion of relative paths to absolute
    26  	if absName, err := filepath.Abs(name); err == nil {
    27  		return absName
    28  	}
    29  	// if we couldn't get absolute name, return original
    30  	// (NOTE: Go only errors on Abs() if os.Getwd fails)
    31  	return name
    32  }