github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/internal/reexec/reexec.go (about) 1 // This file originates from Docker/Moby, 2 // https://github.com/moby/moby/blob/master/pkg/reexec/reexec.go 3 // Licensed under Apache License 2.0: https://github.com/moby/moby/blob/master/LICENSE 4 // Copyright 2013-2018 Docker, Inc. 5 // 6 // Package reexec facilitates the busybox style reexec of the docker binary that 7 // we require because of the forking limitations of using Go. Handlers can be 8 // registered with a name and the argv 0 of the exec of the binary will be used 9 // to find and execute custom init paths. 10 package reexec 11 12 import ( 13 "fmt" 14 "os" 15 ) 16 17 var registeredInitializers = make(map[string]func()) 18 19 // Register adds an initialization func under the specified name 20 func Register(name string, initializer func()) { 21 if _, exists := registeredInitializers[name]; exists { 22 panic(fmt.Sprintf("reexec func already registered under name %q", name)) 23 } 24 registeredInitializers[name] = initializer 25 } 26 27 // Init is called as the first part of the exec process and returns true if an 28 // initialization function was called. 29 func Init() bool { 30 if initializer, ok := registeredInitializers[os.Args[0]]; ok { 31 initializer() 32 return true 33 } 34 return false 35 }