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

Set IFS to default before use in compiler. #734

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/orchestrator_runtime/pash_prepare_call_compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ else
pash_runtime_return_code=1
fi

# save IFS to restore after field splitting
[ -n "${IFS+x}" ] && saved_IFS=$IFS
unset IFS
# Get assigned process id
# We need to split the daemon response into elements of an array by
# shell's field splitting.
# shellcheck disable=SC2206
response_args=($daemon_response)
process_id=${response_args[1]}

[ -n "${saved_IFS+x}" ] && IFS="$saved_IFS"

pash_redir_output echo "$$: (2) Compiler exited with code: $pash_runtime_return_code"

## only when --assert_all_regions_parallellizable is used do we care about all regions being parallelizable
Expand Down
10 changes: 6 additions & 4 deletions compiler/orchestrator_runtime/speculative/speculative_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ daemon_response=$(pash_spec_communicate_scheduler "$msg") # Blocking step, daemo

## Receive an exit code
if [[ "$daemon_response" == *"OK:"* ]]; then
# save IFS to restore after field splitting
[ -n "${IFS+set}" ] && saved_IFS=$IFS
unset IFS
# shellcheck disable=SC2206
response_args=($daemon_response)
[ -n "${saved_IFS+set}" ] && IFS=$saved_IFS
pash_redir_output echo "$$: (2) Scheduler responded: $daemon_response"
cmd_exit_code=${response_args[1]}
output_variable_file=${response_args[2]}
Expand All @@ -46,10 +50,8 @@ elif [[ "$daemon_response" == *"UNSAFE:"* ]]; then
## KK 2023-06-01 Does `eval` work in general? We need to be precise
## about which commands are unsafe to determine how to execute them.
cmd=$(cat "$PASH_SPEC_NODE_DIRECTORY/$pash_speculative_command_id")
## KK 2023-06-01 Not sure if this shellcheck warning must be resolved:
## > note: Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2086
eval $cmd
## Word splitting isn't needed since eval combines all the arguments into a single string
eval "$cmd"
cmd_exit_code=$?
elif [ -z "$daemon_response" ]; then
## Trouble... Daemon crashed, rip
Expand Down
7 changes: 7 additions & 0 deletions evaluation/tests/interface_tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ test_redir_dup()
$shell redir-dup.sh
}

test_IFS()
{
local shell=$1
$shell test-IFS.sh
}

## We run all tests composed with && to exit on the first that fails
if [ "$#" -eq 0 ]; then
run_test test1
Expand Down Expand Up @@ -365,6 +371,7 @@ if [ "$#" -eq 0 ]; then
run_test test_star
run_test test_env_vars
run_test test_redir_dup
run_test test_IFS
else
for testname in $@
do
Expand Down
5 changes: 5 additions & 0 deletions evaluation/tests/interface_tests/test-IFS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
IFS=/
curr_dir=/home/bolun/programming/pash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could "deanonymize" this by making this string to be /test1/test2/test3/test4?

for name in $curr_dir; do
echo "$name"
done
2 changes: 1 addition & 1 deletion runtime/wait_for_output_and_sigpipe_rest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export internal_exec_status=$?
# This value may contains multiple pids as a whitespace-separated string, and
# we must split it as multiple pids by shell's field splitting.
# shellcheck disable=SC2086
(> /dev/null 2>&1 kill -SIGPIPE $pids_to_kill || true)
(unset IFS; > /dev/null 2>&1 kill -SIGPIPE $pids_to_kill || true)

##
## Old way of waiting, very inefficient.
Expand Down
Loading