You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
subprocess: sh -c 'echo err 1>&2 && false' must return 1 #32574
changed the title [-]`system_tests/run_command` test fails on illumos OS[/-][+]subprocess: `sh -c 'echo err 1>&2 && false` must return `1`[/+]on May 23, 2025
I couldn't find an explanation of the underlying issue, but looking at this more, I think I maybe understand the problem. The test code that is failing looks like:
And the specific checks that are failing are on line 54 and 55 as reported initially.
What the test is trying to do here is execute the command sh -c 'echo err 1>&2 && false on the current system.
Then line 54 is checking trying to look for the RunCommandParseJSON error thrown when the command returns a nonzero exit code. Apparently this check is failing because on illumos the command returns a 0 exit code?
And line 55 is checking for the string "err" somewhere in the same error message. But that check also fails for the same reason.
The fact that these BOOST_CHECK statements are failing inside the BOOST_CHECK_EXCEPTION check for a std::runtime_error exception probably indicates that some std::runtime_error exception is being thrown, so it is probably just the one thrown when the command returns invalid json
The test seems pretty broken currently, so not surprising that it returns inconsistent results on different operating systems.
Because we are not enabling the subprocess module's shell option, the subprocess module is attempting to parse the command line sh -c 'echo err 1>&2 && false' itself. And it looks like it does that pretty poorly splitting the command up into an argv array consisting of ["sh", "-c", "'echo", "err", "1>&2", "&&", "false'"] arguments. On linux, because 'echo is not a valid shell script, the bash shell returns exit code 2 and error message err: -c: line 1: unexpected EOF while looking for matching `''. The reason why the bash message begins with "err" is that bash interprets the trailing arguments "'echo", "err", "1>&2", ... as $0, $1, $2, .... arguments to the bash script, so it treating "err" as $0 as the name of the script it thinks it is executing and using that script name in its error message.
So that explains why the test is passing on linux with bash, even if its not checking for a particularly meaningful condition.
It is unclear what exactly is causing the behavior on illumos, but my guess would be that illumos shell might be just treating sh -c "'echo" "err" "1>&2" "&&" "false'" as an echo command and returning success and not bothering to complain that the 'echo quote is unterminated.
In any case, I couldn't think of any way to fix this test to use RunCommandParseJSON to run a command printing to stderr on linux, because the split function splits on spaces and tabs and it's hard to write a shell script that doesn't include spaces or tabs.
We could change RunCommandParseJSON to actually execute full shell commands as was done in 4837fdc from #32577. But ultimately the best approach for our use-case might be to avoid even more joining and splitting and unnecessary use of shell and just make RunCommandParseJSON take an vector<string> array that it can pass to the subprocess library, instead of passing any string that needs to be parsed
Activity
hebasto commentedon May 23, 2025
The underlying issue is not specific to illumos.
With the following patch:
it becomes evident that the command
sh -c 'echo err 1>&2 && false'does not exit with status1.[-]`system_tests/run_command` test fails on illumos OS[/-][+]subprocess: `sh -c 'echo err 1>&2 && false` must return `1`[/+][-]subprocess: `sh -c 'echo err 1>&2 && false` must return `1`[/-][+]subprocess: `sh -c 'echo err 1>&2 && false'` must return `1`[/+]ryanofsky commentedon May 23, 2025
I couldn't find an explanation of the underlying issue, but looking at this more, I think I maybe understand the problem. The test code that is failing looks like:
And the specific checks that are failing are on line 54 and 55 as reported initially.
What the test is trying to do here is execute the command
sh -c 'echo err 1>&2 && falseon the current system.Then line 54 is checking trying to look for the RunCommandParseJSON error thrown when the command returns a nonzero exit code. Apparently this check is failing because on illumos the command returns a 0 exit code?
And line 55 is checking for the string "err" somewhere in the same error message. But that check also fails for the same reason.
The fact that these BOOST_CHECK statements are failing inside the BOOST_CHECK_EXCEPTION check for a std::runtime_error exception probably indicates that some std::runtime_error exception is being thrown, so it is probably just the one thrown when the command returns invalid json
The test seems pretty broken currently, so not surprising that it returns inconsistent results on different operating systems.
Because we are not enabling the subprocess module's shell option, the subprocess module is attempting to parse the command line
sh -c 'echo err 1>&2 && false'itself. And it looks like it does that pretty poorly splitting the command up into an argv array consisting of["sh", "-c", "'echo", "err", "1>&2", "&&", "false'"]arguments. On linux, because'echois not a valid shell script, the bash shell returns exit code 2 and error messageerr: -c: line 1: unexpected EOF while looking for matching `''. The reason why the bash message begins with "err" is that bash interprets the trailing arguments "'echo", "err", "1>&2", ... as $0, $1, $2, .... arguments to the bash script, so it treating "err" as $0 as the name of the script it thinks it is executing and using that script name in its error message.So that explains why the test is passing on linux with bash, even if its not checking for a particularly meaningful condition.
It is unclear what exactly is causing the behavior on illumos, but my guess would be that illumos shell might be just treating
sh -c "'echo" "err" "1>&2" "&&" "false'"as an echo command and returning success and not bothering to complain that the'echoquote is unterminated.In any case, I couldn't think of any way to fix this test to use RunCommandParseJSON to run a command printing to stderr on linux, because the split function splits on spaces and tabs and it's hard to write a shell script that doesn't include spaces or tabs.
We could change RunCommandParseJSON to actually execute full shell commands as was done in 4837fdc from #32577. But ultimately the best approach for our use-case might be to avoid even more joining and splitting and unnecessary use of shell and just make RunCommandParseJSON take an
vector<string>array that it can pass to the subprocess library, instead of passing any string that needs to be parsedmaflcko commentedon Jan 20, 2026
Fixed in #34349
Merge bitcoin/bitcoin#34349: util: Remove brittle and confusing sp::P…
OmniOS, OpenIndiana: Enable `system_tests`
Merge bitcoin/bitcoin#34349: util: Remove brittle and confusing sp::P…
Merge bitcoin/bitcoin#34349: util: Remove brittle and confusing sp::P…
Merge bitcoin/bitcoin#34349: util: Remove brittle and confusing sp::P…