浏览代码

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).
Roberto E. Vargas Caballero 10 年之前
父节点
当前提交
ec3268961d
共有 1 个文件被更改,包括 5 次插入6 次删除
  1. 5 6
      st.c

+ 5 - 6
st.c

@@ -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)) {
-		exit(WEXITSTATUS(stat));
-	} else {
-		exit(EXIT_FAILURE);
-	}
+	ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE;
+	if (ret != EXIT_SUCCESS)
+		die("child finished with error '%d'\n", stat);
+	exit(EXIT_SUCCESS);
 }
 }
 
 
 void
 void