Skip to content

Commit

Permalink
Merge pull request #1782 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
all: make vendored copy of reexec
  • Loading branch information
ucwong authored Oct 30, 2023
2 parents 0bc581d + 524f459 commit 3527b2a
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 2,735 deletions.
2 changes: 1 addition & 1 deletion cmd/cortex/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"

"github.com/CortexFoundation/CortexTheseus/internal/cmdtest"
"github.com/docker/docker/pkg/reexec"
"github.com/CortexFoundation/CortexTheseus/internal/reexec"
)

func tmpdir(t *testing.T) string {
Expand Down
2 changes: 1 addition & 1 deletion cmd/keytools/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"

"github.com/CortexFoundation/CortexTheseus/internal/cmdtest"
"github.com/docker/docker/pkg/reexec"
"github.com/CortexFoundation/CortexTheseus/internal/reexec"
)

type testCortexkey struct {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
github.com/crate-crypto/go-kzg-4844 v0.7.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckarep/golang-set/v2 v2.3.1
github.com/docker/docker v24.0.6+incompatible
github.com/dop251/goja v0.0.0-20231024180952-594410467bc6
github.com/ethereum/c-kzg-4844 v0.4.0
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e
Expand Down Expand Up @@ -234,7 +233,6 @@ require (
golang.org/x/net v0.17.0 // indirect
golang.org/x/term v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
modernc.org/libc v1.22.3 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnm
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v24.0.6+incompatible h1:hceabKCtUgDqPu+qm0NgsaXf28Ljf4/pWFL7xjWWDgE=
github.com/docker/docker v24.0.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
Expand Down Expand Up @@ -1780,8 +1778,6 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
3 changes: 1 addition & 2 deletions internal/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bufio"
"bytes"
"fmt"
"github.com/CortexFoundation/CortexTheseus/internal/reexec"
"io"
"os"
"os/exec"
Expand All @@ -29,8 +30,6 @@ import (
"testing"
"text/template"
"time"

"github.com/docker/docker/pkg/reexec"
)

func NewTestCmd(t *testing.T, data interface{}) *TestCmd {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// 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 "github.com/docker/docker/pkg/reexec"
package reexec

import (
"fmt"
"os"
"os/exec"
"path/filepath"
)

var registeredInitializers = make(map[string]func())
Expand All @@ -18,34 +21,15 @@ 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 {
initializer, exists := registeredInitializers[os.Args[0]]
if exists {
if initializer, ok := registeredInitializers[os.Args[0]]; ok {
initializer()

return true
}
return false
}

func naiveSelf() 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
}
14 changes: 14 additions & 0 deletions internal/reexec/self_linux.go
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"
}
32 changes: 32 additions & 0 deletions internal/reexec/self_others.go
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
}
2 changes: 1 addition & 1 deletion p2p/simulations/adapters/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import (
"syscall"
"time"

"github.com/CortexFoundation/CortexTheseus/internal/reexec"
"github.com/CortexFoundation/CortexTheseus/log"
"github.com/CortexFoundation/CortexTheseus/node"
"github.com/CortexFoundation/CortexTheseus/p2p"
"github.com/CortexFoundation/CortexTheseus/p2p/enode"
"github.com/CortexFoundation/CortexTheseus/rpc"
"github.com/docker/docker/pkg/reexec"
"github.com/gorilla/websocket"
)

Expand Down
2 changes: 1 addition & 1 deletion p2p/simulations/adapters/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
"strconv"

"github.com/CortexFoundation/CortexTheseus/crypto"
"github.com/CortexFoundation/CortexTheseus/internal/reexec"
"github.com/CortexFoundation/CortexTheseus/log"
"github.com/CortexFoundation/CortexTheseus/node"
"github.com/CortexFoundation/CortexTheseus/p2p"
"github.com/CortexFoundation/CortexTheseus/p2p/enode"
"github.com/CortexFoundation/CortexTheseus/p2p/enr"
"github.com/CortexFoundation/CortexTheseus/rpc"
"github.com/docker/docker/pkg/reexec"
"github.com/gorilla/websocket"
)

Expand Down
Loading

0 comments on commit 3527b2a

Please sign in to comment.