Skip to content

Commit

Permalink
Ensure remaining console output is echoed when init dies
Browse files Browse the repository at this point in the history
This avoids a race which can be demonstrated by

  echo foo | contain /image /file/not/found

where without this final copy from the pty master to stdout, the

  contain: exec: No such file or directory

error message is lost.
  • Loading branch information
arachsys committed Aug 27, 2015
1 parent 5efca40 commit 37679b5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,15 @@ int supervise(pid_t child, int console) {

close(signals);
close(slave);

while ((length = read(console, buffer, sizeof(buffer)))) {
if (length < 0 && errno != EAGAIN && errno != EINTR)
break;
for (offset = 0; length > 0; offset += count, length -= count)
while ((count = write(STDOUT_FILENO, buffer + offset, length)) < 0)
if (errno != EAGAIN && errno != EINTR)
error(1, errno, "write");
}

return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE;
}

0 comments on commit 37679b5

Please sign in to comment.