fix: handle job being nil (first sh exec case)

pull/128/head
TorchedSammy 2022-03-21 21:25:43 -04:00
parent f27d60f827
commit 1e884e7c89
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 8 additions and 5 deletions

13
exec.go
View File

@ -261,11 +261,14 @@ func execCommand(cmd string) error {
}
err = cmd.Start()
job := jobs.getLatest()
job.setHandle(cmd.Process)
var j *job
if bg {
j = jobs.getLatest()
j.setHandle(cmd.Process)
}
if err == nil {
if bg {
job.start(cmd.Process.Pid)
j.start(cmd.Process.Pid)
}
if done := ctx.Done(); done != nil {
@ -321,8 +324,8 @@ func execCommand(cmd string) error {
}
end:
if bg {
job.exitCode = int(exit)
job.finish()
j.exitCode = int(exit)
j.finish()
}
return interp.NewExitStatus(exit)
}