-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core/process] Big refactor of redirect / FD handling.
Feature: - Enforce that FDs only have 2 digits, e.g. echo 99>&1 is allowed but echo 100>&1 isn't. Wrote a test to show that all shells do this except bash. Addresses issue #674. Refactoring that preserves the new move, close, and named FD features. That is, 3>&1- and 3>&- and {fd}> - Use exceptions for error handling within a redirect. There are a bunch of failure cases scattered throughout, and this simplifies the code. - Removed _PushMove in favor of _PushDup and some more code - Removed duplicate code for >file.txt - Get rid of _GetFreeDescriptor(). That was replaced by F_DUPFD, which tells the *kernel* to get a free descriptor (above a certain range). - Script to strace shells (incomplete, but may be useful later.) - Add more test cases. All spec tests still pass. This is most of #223, although there a few more things I'd like to clean up.
- Loading branch information
Andy Chu
committed
Mar 22, 2020
1 parent
4aca10f
commit 536f350
Showing
4 changed files
with
187 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
# | ||
# Usage: | ||
# ./strace-redirects.sh <function name> | ||
|
||
set -o nounset | ||
set -o pipefail | ||
set -o errexit | ||
|
||
rtrace() { | ||
### trace relevant calls | ||
#strace -e open,fcntl,dup2,close -P _tmp/out.txt -- "$@" | ||
strace -e open,fcntl,dup2,close -- "$@" | ||
} | ||
|
||
invalid() { | ||
local sh=$1 | ||
local code='true 9> _tmp/out.txt' | ||
local code='true > _tmp/out.txt' | ||
#local code='exec 3>_tmp/3.txt; echo hello >&3; exec 3>&-; cat _tmp/3.txt' | ||
|
||
#local code='exec 4>_tmp/4.txt; echo hello >&4; exec 4>&-; cat _tmp/4.txt' | ||
#local code='true 2>&1' | ||
|
||
sh -c "$code" | ||
|
||
|
||
echo | ||
echo "--- $sh ---" | ||
echo | ||
rtrace $sh -c "$code" | ||
} | ||
|
||
"$@" |
Oops, something went wrong.