From b27a175519cd5a94f2b1e259f9ceae8a585faf2c Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 15 Jun 2023 11:47:39 -0700 Subject: ipc: handle a case when c.cmd.ProcessState is nil (#3967) This can happen when c.cmd.Wait returns an error. Signed-off-by: Andrei Vagin --- pkg/ipc/ipc.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'pkg/ipc') diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index 5485fd5dd..f30b0afeb 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -816,22 +816,27 @@ func (c *command) exec(opts *ExecOpts, progData []byte) (output []byte, hanged b } c.cmd.Process.Kill() output = <-c.readDone - if err := c.wait(); <-hang { + err := c.wait() + if err != nil { + output = append(output, err.Error()...) + output = append(output, '\n') + } + if <-hang { hanged = true - if err != nil { - output = append(output, err.Error()...) - output = append(output, '\n') - } return } if exitStatus == -1 { - exitStatus = osutil.ProcessExitStatus(c.cmd.ProcessState) + if c.cmd.ProcessState == nil { + exitStatus = statusFail + } else { + exitStatus = osutil.ProcessExitStatus(c.cmd.ProcessState) + } } // Ignore all other errors. // Without fork server executor can legitimately exit (program contains exit_group), // with fork server the top process can exit with statusFail if it wants special handling. if exitStatus == statusFail { - err0 = fmt.Errorf("executor %v: exit status %d\n%s", c.pid, exitStatus, output) + err0 = fmt.Errorf("executor %v: exit status %d err %s\n%s", c.pid, exitStatus, err, output) } return } -- cgit mrf-deployment