shithub: trueawk

Download patch

ref: 230a480b2b1bae274f2c46294a8347df664a0016
parent: fbd1d5b712e27a9bb527e39ed6e9bf3b9afbb1df
author: Arnold D. Robbins <arnold@skeeve.com>
date: Mon Nov 27 01:54:35 EST 2023

Fix exit status of system on MacOS.

--- a/bugs-fixed/REGRESS
+++ b/bugs-fixed/REGRESS
@@ -11,6 +11,7 @@
 	echo === $i
 	OUT=${i%.awk}.OUT
 	OK=${i%.awk}.ok
+	OK2=${i%.awk}.ok2
 	IN=${i%.awk}.in
 	input=
 	if [ -f $IN ]
@@ -22,7 +23,10 @@
 	if cmp -s $OK $OUT
 	then
 		rm -f $OUT
+	elif [ -f $OK2 ] && cmp -s $OK2 $OUT
+	then
+		rm -f $OUT
 	else
-		echo ++++ $i failed!
+		echo '++++ $i failed!'
 	fi
 done
--- /dev/null
+++ b/bugs-fixed/system-status.ok2
@@ -1,0 +1,3 @@
+normal status 42
+death by signal status 257
+death by signal with core dump status 262
--- a/run.c
+++ b/run.c
@@ -2065,6 +2065,7 @@
 	Node *nextarg;
 	FILE *fp;
 	int status = 0;
+	int estatus = 0;
 
 	t = ptoi(a[0]);
 	x = execute(a[1]);
@@ -2108,19 +2109,19 @@
 	case FSYSTEM:
 		fflush(stdout);		/* in case something is buffered already */
 		status = system(getsval(x));
-		u = status;
 		if (status != -1) {
 			if (WIFEXITED(status)) {
-				u = WEXITSTATUS(status);
+				estatus = WEXITSTATUS(status);
 			} else if (WIFSIGNALED(status)) {
-				u = WTERMSIG(status) + 256;
+				estatus = WTERMSIG(status) + 256;
 #ifdef WCOREDUMP
 				if (WCOREDUMP(status))
-					u += 256;
+					estatus += 256;
 #endif
 			} else	/* something else?!? */
-				u = 0;
+				estatus = 0;
 		}
+		u = estatus;
 		break;
 	case FRAND:
 		/* random() returns numbers in [0..2^31-1]
--