ash - problem/bug with redirection and internal command

Jean Wolter jw5 at os.inf.tu-dresden.de
Fri May 5 11:23:39 UTC 2006


Hello,

the following sequence behaves not as expected:

# write some file on sysfs
echo "+bond0" > /sys/class/net/bonding_masters
while true; do
      echo "this statement is supposed to be executed endlessly"
done

The body of the while loop is never executed under certain
circumstances, since "true" returns false:

    - open on /sys/class/net/bonding_masters succeeds
    - the following write fails for some data written to the file

After this "true" and every other builtin command return false. The
following diff points to the source of the problem:

--- busybox-1.1.2/shell/ash.c.orig	2006-04-21 17:19:07.000000000 +0200
+++ busybox-1.1.2/shell/ash.c	2006-04-21 17:19:16.000000000 +0200
@@ -3458,7 +3458,11 @@
 	exitstatus = (*cmd->builtin)(argc, argv);
 	flushall();
 cmddone:
-	exitstatus |= ferror(stdout);
+	if (ferror(stdout)) {
+		clearerr(stdout);
+		if (!exitstatus)
+			exitstatus = 1;
+	}
 	commandname = savecmdname;
 	exsig = 0;
 	handler = savehandler;

I am not sure whether this is the right fix.

regards,
Jean



More information about the busybox mailing list