process

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EscapeXML *strings.Replacer
)
View Source
var FuncIO = struct {
	key int64
}{vix.CommandMagicWord}

FuncIO is the Context key to access optional ProcessIO

Functions

This section is empty.

Types

type Error

type Error struct {
	Err      error
	ExitCode int32
}

Error can be returned by the Process.Wait function to propagate ExitCode to process State.

func (*Error) Error

func (e *Error) Error() string

type File

type File struct {
	io.Reader
	io.Writer
	io.Closer
	// contains filtered or unexported fields
}

File implements the os.FileInfo interface to enable toolbox interaction with virtual files.

func (*File) IsDir

func (a *File) IsDir() bool

IsDir implementation of the os.FileInfo interface method.

func (*File) ModTime

func (a *File) ModTime() time.Time

ModTime implementation of the os.FileInfo interface method.

func (*File) Mode

func (a *File) Mode() os.FileMode

Mode implementation of the os.FileInfo interface method.

func (*File) Name

func (a *File) Name() string

Name implementation of the os.FileInfo interface method.

func (*File) Size

func (a *File) Size() int64

Size implementation of the os.FileInfo interface method.

func (*File) Sys

func (a *File) Sys() interface{}

Sys implementation of the os.FileInfo interface method.

type IO

type IO struct {
	In struct {
		io.Writer
		io.Reader
		io.Closer // Closer for the write side of the pipe, can be closed via hgfs ops (FileTranfserToGuest)
	}

	Out *bytes.Buffer
	Err *bytes.Buffer
}

IO encapsulates IO for Go functions and OS commands such that they can interact via the OperationsManager without file system disk IO.

type Manager

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

Manager manages processes within the guest. See: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.vm.guest.Manager.html

func NewManager

func NewManager() *Manager

NewManager creates a new process Manager instance.

func (*Manager) Kill

func (m *Manager) Kill(pid int64) bool

Kill cancels the Process Context. Returns true if pid exists in the process table, false otherwise.

func (*Manager) List

func (m *Manager) List(pids []int64) []State

List the process State for the given pids.

func (*Manager) ListProcesses

func (m *Manager) ListProcesses(pids []int64) []byte

ListProcesses marshals the process State for the given pids. If no pids are specified, all current processes are included. The return value can be used for responding to a VixMsgListProcessesExRequest.

func (*Manager) Open

func (m *Manager) Open(u *url.URL, mode int32) (hgfs.File, error)

Open implements hgfs.FileHandler.Open

func (*Manager) Start

func (m *Manager) Start(r *vix.StartProgramRequest, p *Process) (int64, error)

Start calls the Process.Start function, returning the pid on success or an error. A goroutine is started that calls the Process.Wait function. After Process.Wait has returned, the process State EndTime and ExitCode fields are set. The process state can be queried via ListProcessesInGuest until it is removed, 5 minutes after Wait returns.

func (*Manager) Stat

func (m *Manager) Stat(u *url.URL) (os.FileInfo, error)

Stat implements hgfs.FileHandler.Stat

type Process

type Process struct {
	State

	Start func(*Process, *vix.StartProgramRequest) (int64, error)
	Wait  func() error
	Kill  context.CancelFunc
	// contains filtered or unexported fields
}

Process managed by the process Manager.

func New

func New() *Process

New creates a new Process, where the Start function use exec.CommandContext to create and start the process. The Wait function waits for the process to finish and returns the error returned by exec.Cmd.Wait(). Prior to Wait returning, the exec.Cmd.Wait() error is used to set the Process.ExitCode, if error is of type exec.ExitError. The ctx param may be used to kill the process via the process Manager.Kill method. The VixMsgStartProgramRequest param fields are mapped to the exec.Cmd counterpart fields. Processes are started within a sub-shell, allowing for i/o redirection, just as with the C version of vmware-tools.

func NewFunc

func NewFunc(run func(ctx context.Context, args string) error) *Process

NewFunc creates a new Process, where the Start function calls the given run function within a goroutine. The Wait function waits for the goroutine to finish and returns the error returned by run. The run ctx param may be used to return early via the process Manager.Kill method. The run args command is that of the VixMsgStartProgramRequest.Arguments field.

func NewRoundTrip

func NewRoundTrip() *Process

NewRoundTrip starts a Go function to implement a toolbox backed http.RoundTripper

func (*Process) WithIO

func (p *Process) WithIO() *Process

WithIO enables toolbox Process IO without file system disk IO.

type State

type State struct {
	StartTime int64 // (keep first to ensure 64-bit alignment)
	EndTime   int64 // (keep first to ensure 64-bit alignment)

	Name     string
	Args     string
	Owner    string
	Pid      int64
	ExitCode int32

	IO *IO
}

State is the toolbox representation of the GuestProcessInfo type

Jump to

Keyboard shortcuts

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