-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove dependency on docker - by vendoring
reexec
(#11334)
- Loading branch information
1 parent
547cb95
commit b39f0e6
Showing
7 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// This file originates from Docker/Moby, | ||
// https://github.com/moby/moby/blob/master/pkg/reexec/reexec.go | ||
// Licensed under Apache License 2.0: https://github.com/moby/moby/blob/master/LICENSE | ||
// Copyright 2013-2018 Docker, Inc. | ||
// | ||
// Package reexec facilitates the busybox style reexec of the docker binary that | ||
// we require because of the forking limitations of using Go. Handlers can be | ||
// registered with a name and the argv 0 of the exec of the binary will be used | ||
// to find and execute custom init paths. | ||
package reexec | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var registeredInitializers = make(map[string]func()) | ||
|
||
// Register adds an initialization func under the specified name | ||
func Register(name string, initializer func()) { | ||
if _, exists := registeredInitializers[name]; exists { | ||
panic(fmt.Sprintf("reexec func already registered under name %q", name)) | ||
} | ||
registeredInitializers[name] = initializer | ||
} | ||
|
||
// Init is called as the first part of the exec process and returns true if an | ||
// initialization function was called. | ||
func Init() bool { | ||
if initializer, ok := registeredInitializers[os.Args[0]]; ok { | ||
initializer() | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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 | ||
|
||
// Self returns the path to the current process's binary. | ||
// Returns "/proc/self/exe". | ||
func Self() string { | ||
return "/proc/self/exe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters