reexec

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 16

Documentation

Overview

Package reexec facilitates the busybox style reexec of a binary.

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.

It is used to work around forking limitations when using Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(args ...string) *exec.Cmd

Command returns an *exec.Cmd with its Path set to the path of the current binary using the result of Self.

On Linux, the Pdeathsig of *exec.Cmd.SysProcAttr is set to SIGTERM. This signal is sent to the process when the OS thread that created the process dies.

It is the caller's responsibility to ensure that the creating thread is not terminated prematurely. See https://go.dev/issue/27505 for more details.

func Init

func Init() bool

Init is called as the first part of the exec process and returns true if an initialization function was called.

func Register

func Register(name string, initializer func())

Register adds an initialization func under the specified name. It panics if the given name is already registered.

func Self

func Self() string

Self returns the path to the current process's binary.

On Linux, it returns "/proc/self/exe", which provides the in-memory version of the current binary. This makes it safe to delete or replace the on-disk binary (os.Args[0]).

On Other platforms, it attempts to look up the absolute path for os.Args[0], or otherwise returns os.Args[0] as-is. For example if current binary is "my-binary" at "/usr/bin/" (or "my-binary.exe" at "C:\" on Windows), then it returns "/usr/bin/my-binary" and "C:\my-binary.exe" respectively.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL