From 1acc8a33558bd0f492eb230e0faec4ebd32b15a4 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Sat, 7 May 2016 12:00:44 -0700 Subject: [PATCH] Implement a Windows-specific UniversalExecutor `wait()` --- client/driver/executor/executor_windows.go | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/client/driver/executor/executor_windows.go b/client/driver/executor/executor_windows.go index e93f936e7..ccaed7830 100644 --- a/client/driver/executor/executor_windows.go +++ b/client/driver/executor/executor_windows.go @@ -1,5 +1,37 @@ package executor +import ( + "os/exec" + "time" + + "golang.org/x/sys/windows" +) + func (e *UniversalExecutor) LaunchSyslogServer(ctx *ExecutorContext) (*SyslogServerState, error) { return nil, nil } + +func (e *UniversalExecutor) wait() { + defer close(e.processExited) + err := e.cmd.Wait() + ic := &cstructs.IsolationConfig{Cgroup: e.groups, CgroupPaths: e.cgPaths} + if err == nil { + e.exitState = &ProcessState{Pid: 0, ExitCode: 0, IsolationConfig: ic, Time: time.Now()} + return + } + exitCode := 1 + var signal int + if exitErr, ok := err.(*exec.ExitError); ok { + if status, ok := exitErr.Sys().(windows.WaitStatus); ok { + exitCode = status.ExitStatus() + if status.Signaled() { + signal = int(status.Signal()) + exitCode = 128 + signal + } + } + } else { + e.logger.Printf("[DEBUG] executor: unexpected Wait() error type: %v", err) + } + + e.exitState = &ProcessState{Pid: 0, ExitCode: exitCode, Signal: signal, IsolationConfig: ic, Time: time.Now()} +}