()
| 73 | } |
| 74 | |
| 75 | func (jm *JobCmd) waitForProcess() { |
| 76 | if jm.cmd == nil || jm.cmd.Process == nil { |
| 77 | return |
| 78 | } |
| 79 | err := jm.cmd.Wait() |
| 80 | jm.lock.Lock() |
| 81 | defer jm.lock.Unlock() |
| 82 | |
| 83 | jm.processExited = true |
| 84 | jm.exitTs = time.Now().UnixMilli() |
| 85 | jm.exitErr = err |
| 86 | if err != nil { |
| 87 | if exitErr, ok := err.(*exec.ExitError); ok { |
| 88 | if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { |
| 89 | if status.Signaled() { |
| 90 | jm.exitSignal = unixutil.GetSignalName(status.Signal()) |
| 91 | } else if status.Exited() { |
| 92 | code := status.ExitStatus() |
| 93 | jm.exitCode = &code |
| 94 | } else { |
| 95 | log.Printf("Invalid WaitStatus, not exited or signaled: %v", status) |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } else { |
| 100 | code := 0 |
| 101 | jm.exitCode = &code |
| 102 | } |
| 103 | exitCodeStr := "nil" |
| 104 | if jm.exitCode != nil { |
| 105 | exitCodeStr = fmt.Sprintf("%d", *jm.exitCode) |
| 106 | } |
| 107 | log.Printf("process exited: exitcode=%s, signal=%s, err=%v\n", exitCodeStr, jm.exitSignal, jm.exitErr) |
| 108 | |
| 109 | go WshCmdJobManager.sendJobExited() |
| 110 | } |
| 111 | |
| 112 | func (jm *JobCmd) GetCmd() (*exec.Cmd, pty.Pty) { |
| 113 | jm.lock.Lock() |
no test coverage detected