Skip to content

Commit

Permalink
Fix gcs init args wrapping when ConsolePipe is enabled (microsoft#1334)
Browse files Browse the repository at this point in the history
GCS init fails to parse the entropy socket when enabling ConsolePipe.
Fix by separating entropy parameters from the rest init args and
wrapping only init args with `sh -c`.

Changes:
`/init sh -c "-e 1 /bin/vsockexec -e 109 /bin/gcs -v4 -log-format json -loglevel debug & exec sh"`
to
`/init -e 1 sh -c "/bin/vsockexec -e 109 /bin/gcs -v4 -log-format json -loglevel debug & exec sh"`

Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl authored Mar 22, 2022
1 parent 925676c commit d33801f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions uvm/create_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,18 +639,18 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs
}

// Inject initial entropy over vsock during init launch.
initArgs := fmt.Sprintf("-e %d", entropyVsockPort)
entropyArgs := fmt.Sprintf("-e %d", entropyVsockPort)

// With default options, run GCS with stderr pointing to the vsock port
// created below in order to forward guest logs to logrus.
initArgs += " /bin/vsockexec"
execCmdArgs := "/bin/vsockexec"

if opts.ForwardStdout {
initArgs += fmt.Sprintf(" -o %d", linuxLogVsockPort)
execCmdArgs += fmt.Sprintf(" -o %d", linuxLogVsockPort)
}

if opts.ForwardStderr {
initArgs += fmt.Sprintf(" -e %d", linuxLogVsockPort)
execCmdArgs += fmt.Sprintf(" -e %d", linuxLogVsockPort)
}

if opts.DisableTimeSyncService {
Expand All @@ -661,15 +661,16 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs
opts.ExecCommandLine += " --scrub-logs"
}

initArgs += " " + opts.ExecCommandLine
execCmdArgs += " " + opts.ExecCommandLine

if opts.ProcessDumpLocation != "" {
initArgs += " -core-dump-location " + opts.ProcessDumpLocation
execCmdArgs += " -core-dump-location " + opts.ProcessDumpLocation
}

initArgs := fmt.Sprintf("%s %s", entropyArgs, execCmdArgs)
if vmDebugging {
// Launch a shell on the console.
initArgs = `sh -c "` + initArgs + ` & exec sh"`
initArgs = entropyArgs + ` sh -c "` + execCmdArgs + ` & exec sh"`
}

kernelArgs += fmt.Sprintf(" nr_cpus=%d", opts.ProcessorCount)
Expand All @@ -696,8 +697,9 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs
return doc, nil
}

// Creates an HCS compute system representing a utility VM. It consumes a set of options derived
// from various defaults and options expressed as annotations.
// CreateLCOW creates an HCS compute system representing a utility VM. It
// consumes a set of options derived from various defaults and options
// expressed as annotations.
func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error) {
ctx, span := trace.StartSpan(ctx, "uvm::CreateLCOW")
defer span.End()
Expand Down

0 comments on commit d33801f

Please sign in to comment.