zprocess

package
v0.0.0-...-0521b85 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: BSD-3-Clause Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MainThreadExeCh chan func()
)
View Source
var SSHPassDefaultOptions = &SSHPassOptions{
	ExpectedPrompt:              "password:",
	ExpectedFailure:             "denied",
	Timeout:                     time.Second * 10,
	AutoConfirmHostAuthenticity: true,
	Shell:                       "",
}

Functions

func ConsumeOutAndError

func ConsumeOutAndError(outPipe, errPipe io.ReadCloser, ctx context.Context, dump func(isErr bool, line string))

func FindParameterAfterFlag

func FindParameterAfterFlag(got *string, args []string, flag string) bool

func GetAppProgramPath

func GetAppProgramPath(appName string) string

func GetChildrenForPID

func GetChildrenForPID(parentPID int64) []int64

func GetOpenFileCount

func GetOpenFileCount() int

func GetPIDsForAppName

func GetPIDsForAppName(app string, excludeZombies bool) []int64

GetPIDsForAppName returns the pid for all processes with executable name *app*. *excludeZombies* checks if it has a ps Z state and doesn't add it to list then. This can take quite a long time.

func GetRunningProcessUserName

func GetRunningProcessUserName() (string, error)

func MakeCommand

func MakeCommand(command string, ctx context.Context, start bool, inPipe *io.WriteCloser, args ...any) (cmd *exec.Cmd, outPipe, errPipe io.ReadCloser, err error)

func MemoryBytesUsedByProcess

func MemoryBytesUsedByProcess(processID int64) int64

func OnDarwin

func OnDarwin() bool

func OnLinux

func OnLinux() bool

func OnThreadExecutor

func OnThreadExecutor(c *chan func(), rest func()) chan func()

func PoolWorkOnItems

func PoolWorkOnItems[T any](all []T, poolSize int, do func(t *T))

PoolWorkOnItems runs jobs with do(), processing all in goroutines, But up to max poolSize at a time.

func PopProcess

func PopProcess(p *proc)

func PushProcess

func PushProcess(timeoutSecs float64, info string) *proc

func RepeatLogProcessUse

func RepeatLogProcessUse()

func RepeatPrintInOutRequests

func RepeatPrintInOutRequests()

func RestartSelf

func RestartSelf() error

func RunAndWaitForFuncInMainThread

func RunAndWaitForFuncInMainThread(f func())

func RunApp

func RunApp(appName string, ctx context.Context, args ...any) (cmd *exec.Cmd, outPipe, errPipe io.ReadCloser, inPipe io.WriteCloser, err error)

RunApp runs appName in Applications (for mac), and returns the exec.Cmd and out/err readers and in writer. If ctx is nil, the command it run without a context. using exec.Command in MakeCommand.

func RunAppleScript

func RunAppleScript(command string, timeoutSecs float64) (string, error)

func RunBashCommand

func RunBashCommand(command string, timeoutSecs float64) (string, error)

func RunCommand

func RunCommand(command string, timeoutSecs float64, args ...any) (string, error)

func RunCommandWithSSHPass

func RunCommandWithSSHPass(cmd string, passwords []string, options *SSHPassOptions) error

Run attempts to run the provided command and insert the given passwords one by one when prompted.

func RunCommandWithSudo

func RunCommandWithSudo(command, password string, args ...any) (string, error)

RunCommandWithSudo runs command with args on the shell, using sudo and stdin to 'type' password to sudo.

func RunFuncInMainThread

func RunFuncInMainThread(f func())

func RunFuncUntilContextDone

func RunFuncUntilContextDone(ctx context.Context, do func()) (completed bool)

RunFuncUntilContextDone waits for do() to finish or the context to be done If it finishes it returns completed = true, otherwise the goroutine continues, but it returns with false.

func RunFuncUntilTimeoutSecs

func RunFuncUntilTimeoutSecs(secs float64, do func()) (completed bool)

RunFuncUntilTimeoutSecs uses RunFuncUntilContextDone to wait secs for a function to finish, or returns while it's still running in a goroutine.

func SetNumberOfOpenFiles

func SetNumberOfOpenFiles(n int)

func StartMainThreadExecutor

func StartMainThreadExecutor(rest func())

func TerminateAppsByName

func TerminateAppsByName(name string, force, children bool) (oerr error)

func WaitTimeout

func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool

Types

type Installer

type Installer struct {
	Company     string
	ProductName string
	Domain      string
	UserName    string // username to set owner of file/dirs
}

func (*Installer) BinPath

func (i *Installer) BinPath(isFile bool, parts ...string) string

func (*Installer) ID

func (i *Installer) ID() string

func (*Installer) InstallProgramWithLauncher

func (i *Installer) InstallProgramWithLauncher(args []string, copyBinary bool) error

func (*Installer) OptPath

func (i *Installer) OptPath(isFile bool, parts ...string) string

func (*Installer) VarPath

func (i *Installer) VarPath(isFile bool, parts ...string) string

type OnceWait

type OnceWait struct {
	// contains filtered or unexported fields
}

OnceWait is something you call Wait() on and it waits until Done() is called on it. Once. Use to wait for some global data to be inited for example. TODO: Check if a semaphore could be used.

func (*OnceWait) Done

func (o *OnceWait) Done()

func (*OnceWait) Wait

func (o *OnceWait) Wait()

type SSHPassOptions

type SSHPassOptions struct {
	ExpectedPrompt              string        // ExpectedPrompt is the string to treat as the password prompt e.g. "Password: "
	ExpectedFailure             string        // ExpectedFailure is the string to treat as an indication of failure e.g. "Incorrect password"
	Timeout                     time.Duration // Timeout is the duration to wait for a prompt/failure before giving up
	AutoConfirmHostAuthenticity bool          // AutoConfirmHostAuthenticity will type 'yes' on host authenticity confirmations when set
	Shell                       string        // Shell is a path to the shell to use e.g. /bin/bash - leave blank to use user shell
}

Jump to

Keyboard shortcuts

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