Skip to content

Commit ab53137

Browse files
authored
Merge pull request #38 from kpedro88/call_host_fixes
Call host fixes
2 parents 8361e19 + 4804e02 commit ab53137

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ or placed in a file `~/.callhostrc` (automatically detected and sourced by `call
135135
```
136136
* Using the `ENV()` function in the JDL file may not function as intended, since it will be evaluated on the host node, rather than inside the container with your environment set up.
137137
* Commands that require tty input (such as `nano` or `emacs -nw`) will not work with `call_host`.
138-
* Calling multiple commands at once with `call_host` can break the pipe if the commands are separated by semicolons and a non-final command fails.
139-
The symptom of this will be that subsequent host commands hang, and pressing ctrl+C will give the error message "Interrupted system call".
138+
* Occasionally, if a command fails (especially when calling multiple commands separated by semicolons), the pipe will break and the terminal will appear to hang. The message "Interrupted system call" may be shown.
140139
It is necessary to exit and reenter the container (in order to create a new pipe) if this occurs.
141-
To avoid this, chain multiple commands using logical operators (`&&` or `||`), or surround all the commands in `()` (thereby running them in a subshell).
142-
* Stopping a command in progress with ctrl+C will also break the pipe (as described in the previous item).
140+
To prevent this, chain multiple commands using logical operators (`&&` or `||`), or surround all the commands in `()` (thereby running them in a subshell).
141+
* Stopping a command in progress with ctrl+C is disabled (to avoid breaking the pipe as described in the previous item).
142+
* Suspending a command with ctrl+Z is not supported and may break the session.
143143
144144
## `bind_condor.sh`
145145

call_host.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# check for configuration
55
CALL_HOST_CONFIG=~/.callhostrc
66
if [ -f "$CALL_HOST_CONFIG" ]; then
7-
# shellcheck source=/dev/null
7+
# shellcheck source=/dev/null
88
source "$CALL_HOST_CONFIG"
99
fi
1010

@@ -58,11 +58,14 @@ export -f call_host_disable
5858
listenhost(){
5959
# stop when host pipe is removed
6060
while [ -e "$1" ]; do
61-
# "|| true" is necessary to stop "Interrupted system call"
62-
# must be *inside* eval to ensure EOF once command finishes
61+
# "|| true" is necessary to stop "Interrupted system call" when running commands like 'command1; command2; command3'
6362
# now replaced with assignment of exit code to local variable (which also returns true)
63+
# using { bash -c ... } >& is less fragile than eval
6464
tmpexit=0
65-
eval "$(cat "$1") || tmpexit="'$?' >& "$2"
65+
cmd="$(cat "$1")"
66+
{
67+
bash -c "$cmd" || tmpexit=$?
68+
} >& "$2"
6669
echo "$tmpexit" > "$3"
6770
done
6871
}
@@ -89,6 +92,8 @@ export -f startpipe
8992

9093
# sends function to host, then listens for output, and provides exit code from function
9194
call_host(){
95+
# disable ctrl+c to prevent "Interrupted system call"
96+
trap "" SIGINT
9297
if [ "${FUNCNAME[0]}" = "call_host" ]; then
9398
FUNCTMP=
9499
else

0 commit comments

Comments
 (0)