...

Source file src/github.com/Microsoft/hcsshim/internal/exec/options.go

Documentation: github.com/Microsoft/hcsshim/internal/exec

     1  //go:build windows
     2  
     3  package exec
     4  
     5  import (
     6  	"github.com/Microsoft/hcsshim/internal/conpty"
     7  	"github.com/Microsoft/hcsshim/internal/jobobject"
     8  	"golang.org/x/sys/windows"
     9  )
    10  
    11  type ExecOpts func(e *execConfig) error
    12  
    13  type execConfig struct {
    14  	dir                   string
    15  	env                   []string
    16  	stdout, stderr, stdin bool
    17  
    18  	job          *jobobject.JobObject
    19  	cpty         *conpty.Pty
    20  	token        windows.Token
    21  	processFlags uint32
    22  }
    23  
    24  // WithDir will use `dir` as the working directory for the process.
    25  func WithDir(dir string) ExecOpts {
    26  	return func(e *execConfig) error {
    27  		e.dir = dir
    28  		return nil
    29  	}
    30  }
    31  
    32  // WithStdio will hook up stdio for the process to a pipe, the other end of which can be retrieved by calling Stdout(), stdErr(), or Stdin()
    33  // respectively on the Exec object. Stdio will be hooked up to the NUL device otherwise.
    34  func WithStdio(stdout, stderr, stdin bool) ExecOpts {
    35  	return func(e *execConfig) error {
    36  		e.stdout = stdout
    37  		e.stderr = stderr
    38  		e.stdin = stdin
    39  		return nil
    40  	}
    41  }
    42  
    43  // WithEnv will use the passed in environment variables for the new process.
    44  func WithEnv(env []string) ExecOpts {
    45  	return func(e *execConfig) error {
    46  		e.env = env
    47  		return nil
    48  	}
    49  }
    50  
    51  // WithJobObject will launch the newly created process in the passed in job.
    52  func WithJobObject(job *jobobject.JobObject) ExecOpts {
    53  	return func(e *execConfig) error {
    54  		e.job = job
    55  		return nil
    56  	}
    57  }
    58  
    59  // WithConPty will launch the created process with a pseudo console attached to the process.
    60  func WithConPty(cpty *conpty.Pty) ExecOpts {
    61  	return func(e *execConfig) error {
    62  		e.cpty = cpty
    63  		return nil
    64  	}
    65  }
    66  
    67  // WithToken will run the process as the user that `token` represents.
    68  func WithToken(token windows.Token) ExecOpts {
    69  	return func(e *execConfig) error {
    70  		e.token = token
    71  		return nil
    72  	}
    73  }
    74  
    75  // WithProcessFlags will pass `flags` to CreateProcess's creationFlags parameter.
    76  func WithProcessFlags(flags uint32) ExecOpts {
    77  	return func(e *execConfig) error {
    78  		e.processFlags = flags
    79  		return nil
    80  	}
    81  }
    82  

View as plain text