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

     1  // This file originates from Docker/Moby,
     2  // https://github.com/moby/moby/blob/master/pkg/reexec/reexec_deprecated.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  
    11  package reexec
    12  
    13  import (
    14  	"fmt"
    15  	"os"
    16  )
    17  
    18  var registeredInitializers = make(map[string]func())
    19  
    20  // Register adds an initialization func under the specified name
    21  func Register(name string, initializer func()) {
    22  	if _, exists := registeredInitializers[name]; exists {
    23  		panic(fmt.Sprintf("reexec func already registered under name %q", name))
    24  	}
    25  	registeredInitializers[name] = initializer
    26  }
    27  
    28  // Init is called as the first part of the exec process and returns true if an
    29  // initialization function was called.
    30  func Init() bool {
    31  	if initializer, ok := registeredInitializers[os.Args[0]]; ok {
    32  		initializer()
    33  		return true
    34  	}
    35  	return false
    36  }