Skip to content

Commit

Permalink
Merge pull request microsoft#297 from jstarks/ctty
Browse files Browse the repository at this point in the history
gcs: Prevent GCS crashing when external process exits
  • Loading branch information
jstarks authored Apr 22, 2019
2 parents e979295 + 7009c9e commit 92d537f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion init/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ int reap_until(pid_t until_pid) {
}
return WEXITSTATUS(status);
}
fputs("child exited by signal\n", stderr);
fputs("child exited by signal: ", stderr);
fputs(strsignal(WTERMSIG(status)), stderr);
fputs("\n", stderr);
return 128 + WTERMSIG(status);
}
}
Expand Down
9 changes: 8 additions & 1 deletion service/gcs/core/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (c *gcsCore) RunExternalProcess(params prot.ProcessParameters, conSettings
}()

var console *os.File
console, err = os.OpenFile(consolePath, os.O_RDWR, 0777)
console, err = os.OpenFile(consolePath, os.O_RDWR|syscall.O_NOCTTY, 0777)
if err != nil {
return -1, errors.Wrap(err, "failed to open console file for external process")
}
Expand All @@ -597,6 +597,13 @@ func (c *gcsCore) RunExternalProcess(params prot.ProcessParameters, conSettings
cmd.Stdin = console
cmd.Stdout = console
cmd.Stderr = console
// Make the child process a session leader and adopt the pty as
// the controlling terminal.
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
Setctty: true,
Ctty: syscall.Stdin,
}
} else {
var fileSet *stdio.FileSet
fileSet, err = stdioSet.Files()
Expand Down

0 comments on commit 92d537f

Please sign in to comment.