You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the nice sample code of a simple bash -based 'server' that takes commands from a remote client.
When play_stdin_server.sh exits abnormally (control-C, for example), the /tmp/play_stdin_server pipe is left lying around.
Not a huge deal, but it would be cleaner if the script removed it. If I run the script, do a control-C and run it again, I get an error message as the script tries to create the already existing pipe.
Use the 'trap on EXIT' feature of bash to ensure a cleanup function is run no matter how the script exits - both normally and abnormally
Just before "#Create the pipe", add:
always_run_on_exit () {
# Use -f so that there is no error if the pipe does not yet exist or was already removed
rm -f $CONTROLLER_PIP_FILE
}
# No matter how the script exits, ensure pipe gets removed
trap always_run_on_exit EXIT
Then you can remove the 'rm $CONTROLLER_PIPE_FILE' from server_exit() too. Although there's no harm in leaving it there as the 'cleanup_server_fifo' function uses 'rm -f' which won't report an error when trying to remove something that's not there.
The text was updated successfully, but these errors were encountered:
Thanks for the nice sample code of a simple bash -based 'server' that takes commands from a remote client.
When play_stdin_server.sh exits abnormally (control-C, for example), the /tmp/play_stdin_server pipe is left lying around.
Not a huge deal, but it would be cleaner if the script removed it. If I run the script, do a control-C and run it again, I get an error message as the script tries to create the already existing pipe.
Use the 'trap on EXIT' feature of bash to ensure a cleanup function is run no matter how the script exits - both normally and abnormally
Just before "#Create the pipe", add:
Then you can remove the 'rm $CONTROLLER_PIPE_FILE' from server_exit() too. Although there's no harm in leaving it there as the 'cleanup_server_fifo' function uses 'rm -f' which won't report an error when trying to remove something that's not there.
The text was updated successfully, but these errors were encountered: