NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/46327 (sh background commands have old return value)

The following reply was made to PR bin/46327; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
Subject: Re: bin/46327 (sh background commands have old return value)
Date: Sun, 21 Feb 2016 13:59:41 +0700

 I have been looking at the sh tests, and came across the test
 which was added due to this PR, which caused me to look at the
 PR (open sh PRs are of interest right now...)
 Since it is years ago, for the benefit of those reading this
 on the list, I will summarise the issue:
 	true; true & echo $?
 	false; true & echo $?
 incorrect - $? should come from the "true &" not from the preceding "false"
 (ksh (/bin/ksh on NetBSD), bash, and zsh, at least, all get this correct.)
 A reply to the PR states ...
 	This does not seem to occur with '-c':
 but that's incorrect, it does ...
 	sh -c 'false; true & echo $?'
 the PR response (incorrectly) used ...
 	/bin/sh -c "false; true & echo $?"
 which (of course) expands $? from the calling shell, and results in
 	/bin/sh -c "false; true & echo 0"
 from which it is no surprise that it prints "0" ...
 To compound matters, even though ...
 	Although this does not fail, add a case for the discussion
         in PR bin/46327.
 was done, adding an ATF test that should have detected the bug, the
 test added was ...
         atf_check -s exit:0 -o ignore -e ignore -x "false; true & echo $?"
 which checks that the exit value from "echo" is 0 (isn't it always?) and
 otherwise ignores the output which because of the incorrect quoting, would
 not detect the error anyway.   The atf-check man page does
 warn about use of -x because of quoting issues, but this one (and
 the incorrect result test) is about as simple as it gets!
 I think it should be something like
 	atf_check -o match:0 -e empty -x 'false; true & echo $?'
 (and the same for the preceding "true; true &" test, though that one
 is not expected to fail either way).
 I will add this bug as one to look for (and hopefully fix) in the
 sh sources (the bug is still there in sh from current), but perhaps someone
 else can fix the test (someone who understands atf better than I, and
 can fix it the best way.)   For now it probably also needs an atf_expect_fail.
 For now, I am running the tests (src/tests/bin/sh/ with
 this in the code ...
 background_body() {
         atf_check -o match:0 -e empty -x 'true; true & echo $?'
         atf_expect_fail "PR bin/46327"
         atf_check -o match:0 -e empty -x 'false; true & echo $?'
 and it appears to be doing as expected.

Home | Main Index | Thread Index | Old Index