From 87275ca223c44b3a80ed66c22de072361e07c8f0 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Mon, 8 Jun 2015 23:57:17 +0200 Subject: [PATCH] Properly set up traps Also don't attempt to delete the temporary file twice. --- examples/playlist-logger.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/playlist-logger.sh b/examples/playlist-logger.sh index bfe5f52..4f38b2b 100755 --- a/examples/playlist-logger.sh +++ b/examples/playlist-logger.sh @@ -49,6 +49,10 @@ LOGFILE="ezstream.log" _myname="$(basename $0)" +# Ignore SIGHUP, and exit 1 on SIGINT and SIGTERM +trap '' 1 +trap 'exit 1' 2 15 + # Check configuration above: if [ -z "${STATE_DIR}" -o ! -d "${STATE_DIR}" ]; then echo "${_myname}: STATE_DIR is not configured, does not exist or is not a directory." >&2 @@ -67,8 +71,8 @@ if [ $? -ne 0 ]; then echo "${_myname}: Unable to create temporary file." >&2 exit 1 fi +# Delete temporary file on exit trap 'rm -f ${_playlist}' 0 -trap 'rm -f ${_playlist}; exit 1' 2 15 # Strip comments and empty lines from PLAYLIST, to support .m3u: sed -e 's,#.*,,g' < ${PLAYLIST} | grep -v '^[[:space:]]*$' >> ${_playlist}