Skip to content

Commit

Permalink
Merge pull request firecracker-microvm#94 from superfly/jailer-cfg-st…
Browse files Browse the repository at this point in the history
…douterr

Allow setting stdout and stderr with a JailerCfg
  • Loading branch information
xibz committed May 6, 2019
2 parents 4f11ac7 + 7e97bde commit 3b02734
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions jailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ type JailerConfig struct {

// ChrootStrategy will dictate how files are transfered to the root drive.
ChrootStrategy HandlersAdapter

// Stdout specifies the IO writer for STDOUT to use when spawning the jailer.
Stdout io.Writer
// Stderr specifies the IO writer for STDERR to use when spawning the jailer.
Stderr io.Writer
}

// JailerCommandBuilder will build a jailer command. This can be used to
Expand Down Expand Up @@ -291,6 +296,17 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
}

cfg.SocketPath = filepath.Join(rootfs, "api.socket")

stdout := cfg.JailerCfg.Stdout
if stdout == nil {
stdout = os.Stdout
}

stderr := cfg.JailerCfg.Stderr
if stderr == nil {
stderr = os.Stderr
}

m.cmd = NewJailerCommandBuilder().
WithID(cfg.JailerCfg.ID).
WithUID(*cfg.JailerCfg.UID).
Expand All @@ -300,8 +316,8 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
WithChrootBaseDir(cfg.JailerCfg.ChrootBaseDir).
WithDaemonize(cfg.JailerCfg.Daemonize).
WithSeccompLevel(cfg.JailerCfg.SeccompLevel).
WithStdout(os.Stdout).
WithStderr(os.Stderr).
WithStdout(stdout).
WithStderr(stderr).
Build(ctx)

if err := cfg.JailerCfg.ChrootStrategy.AdaptHandlers(&m.Handlers); err != nil {
Expand Down

0 comments on commit 3b02734

Please sign in to comment.