Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix process substitution combined with redirection #40

Merged
merged 1 commit into from
Jun 23, 2020

Conversation

JohnoKing
Copy link

@JohnoKing JohnoKing commented Jun 23, 2020

The code for handling process substitution with redirection was never being run because IORAW is usually set when IOPROCSUB is set. This pull request fixes the problem by moving the required code out of the !IORAW if statement. The following command now prints 'good' instead of writing 'ok' to a bizarre file:

$ ksh -c 'echo ok > >(sed s/ok/good/); wait'
good

This pull request also fixes a bug that caused the process ID of the asynchronous process to print when the shell was in interactive mode. The fix is to temporarily turn off the shell's interactive state while in a process substitution. The following command no longer prints a process ID, behaving like in Bash and zsh:

$ echo >(/bin/true)
/dev/fd/5

@JohnoKing JohnoKing force-pushed the fix-process-substitution branch 2 times, most recently from 3e0d97c to 829cd42 Compare June 23, 2020 16:37
@McDutchie
Copy link

Very nice work, thanks for that! So, this will be the first ksh93 version with that whopper of a bug fixed.

There are a few things with the regression tests, though. Here's a patch. Summary:

  • These tests seem better placed in io.sh along with other I/O-related stuff, so I moved them.
  • I prefer to use backticks in Markdown and 'normal single quotes' in plain text.
  • The second test depended on an unportable /bin/true path (e.g. the Mac has /usr/bin/true). The test still works when using the true built-in.
  • Variable assignments don't require quoting, as that is a scalar context in which split/glob are never performed.
  • OTOH, several expansions that should be quoted were left unquoted, including $tmp which is based on $TMPDIR which could well contain spaces. (I'm aware there are loads more unsafely unquoted expansions in the pre-existing tests as well as other scripts. I intend to either fix all those at some point, or just run the whole thing with split and glob globally disabled as they're barely actually used.)
  • >> /dev/null looks like a workaround for some broken shells (such as NetBSD sh before 9.0) that can't do >/dev/null when set -C/set -o noclobber is active. POSIXly, device files are exempt from noclobber, and so they are in ksh. So just use >/dev/null, because if that ever breaks, we want it to fail.
  • It now prints the expected and actual values on failure for easier debugging.
  • I reactivated and tweaked the pretty-printing of times output in shtests and made it subject to a bug/feature test for compatibility with old ksh versions.

@JohnoKing JohnoKing force-pushed the fix-process-substitution branch from 829cd42 to a8e6034 Compare June 23, 2020 21:32
@JohnoKing
Copy link
Author

The pull request has been updated with your patch. Thanks for pointing out the times pretty-printing in shtests, I missed that by accident.

@McDutchie
Copy link

McDutchie commented Jun 23, 2020

Almost done. Current version removes an empty line in basic.sh for no apparent reason.

edit: which was caused by my own patch, sorry about that.

The code for handling process substitution with redirection was
never being run because IORAW is usually set when IOPROCSUB is
set. This commit fixes the problem by moving the required code
out of the !IORAW if statement. The following command now prints
'good' instead of writing 'ok' to a bizzare file:

$ ksh -c 'echo ok > >(sed s/ok/good/); wait'
good

This commit also fixes a bug that caused the process ID of the
asynchronous process to print when the shell was in interactive
mode. The following command no longer prints a process ID,
behaving like in Bash and zsh:

$ echo >(/bin/true)
/dev/fd/5

src/cmd/ksh93/sh/args.c:
 - Temporarily turn off the interactive state while in a process
   substitution to prevent the shell from printing the PID of
   the asynchronous process.

src/cmd/ksh93/sh/io.c:
 - Move the code for process substitution with redirection into
   a separate if statement.

src/cmd/ksh93/tests/io.sh:
 - Add two tests for both process substitution bugs fixed by this
   commit.

src/cmd/ksh93/tests/shtests:
 - Update shtests with a patch from Martijn Dekker to use
   pretty-printing for the output from the times builtin (if it
   is available).

Fixes ksh93#2
@JohnoKing JohnoKing force-pushed the fix-process-substitution branch from a8e6034 to 0f6ec4c Compare June 23, 2020 21:57
@JohnoKing
Copy link
Author

The pull request no longer changes basic.sh.

@McDutchie McDutchie merged commit 0aa9e03 into ksh93:master Jun 23, 2020
@JohnoKing JohnoKing deleted the fix-process-substitution branch June 23, 2020 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants