Add error message when child exits whit error

Master proccess was not showing any error message when the child
died with an error, and it was very confusing for the user (for
example with incorrect -e command).
This commit is contained in:
Roberto E. Vargas Caballero 2014-08-04 22:07:04 +02:00
parent 769d481807
commit ec3268961d
1 changed files with 5 additions and 6 deletions

11
st.c
View File

@ -1176,16 +1176,15 @@ execsh(void) {
void void
sigchld(int a) { sigchld(int a) {
int stat = 0; int stat, ret;
if(waitpid(pid, &stat, 0) < 0) if(waitpid(pid, &stat, 0) < 0)
die("Waiting for pid %hd failed: %s\n", pid, strerror(errno)); die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
if(WIFEXITED(stat)) { ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE;
exit(WEXITSTATUS(stat)); if (ret != EXIT_SUCCESS)
} else { die("child finished with error '%d'\n", stat);
exit(EXIT_FAILURE); exit(EXIT_SUCCESS);
}
} }
void void