Repository navigation
fix(gawk): exit a BEGIN-only awk program without reading input - #2095
Open
atharvamhaske wants to merge 1 commit into
Open
atharvamhaske wants to merge 1 commit into
atharvamhaske wants to merge 1 commit into
Conversation
`awk 'BEGIN { print "AWK" }'` printed its output and then blocked reading
stdin until EOF. Through `vm.process.exec` stdin stays open, so the call
ran until its timeout and returned `timed_out` with exit 137.
POSIX awk exits after a program made only of BEGIN actions without
reading input. The wrapper now runs such a program with no input. awk-rs
never feeds the main input to a plain `getline`, so this loses nothing.
Named input files are not opened either, as with other awk versions.
Fixes rivet-dev#2088
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2088.
awk 'BEGIN { print "AWK" }'printed its output and then waited to read stdin until EOF.vm.process.execleaves stdin open, so the call ran until its timeout and returnedtimed_outwith exit 137.POSIX awk exits after a program made only of BEGIN actions without reading input. The wrapper in
software/gawk/native/crates/awk/src/lib.rsnow checks the parsed program. If every rule is a BEGIN rule, it runs the program with no input. awk-rs returns 0 for a plaingetlineand never feeds it the main input, so skipping the input loses nothing.A BEGIN-only program also no longer opens the files named on the command line.
awk 'BEGIN { print "x" }' /nonexistentnow printsxand exits 0 instead of failing with exit 2. macOSawkdoes the same.Testing
cargo test -p agentos-awk: the newbegin_only_programs_do_not_read_inputtest checks that BEGIN-only programs skip input and that programs with an END rule, a main rule or a pattern still read it.cmd-awkon the host and ranawk 'BEGIN { print "AWK" }'with its stdin pipe held open. The patched binary printedAWKand exited 0 in 0.68 s. The binary built frommainhad not exited after 10 minutes.printf 'a b\nc d\n' | awk '{ print $2 } END { print NR }'still printsb,d,2.I did not rerun the issue's VM repro. The issue also notes that
stdin: ''does not help. That points tovm.process.execnot closing the guest's stdin when given an empty string, which this PR does not change.