Skip to content

Commit

Permalink
upgrade-2.x: avoid log function blocking execution
Browse files Browse the repository at this point in the history
Appending to /dev/stderr can cause the script to block if the device
is not available.

Also, always include the script name in the logs.

Change-type: patch
Signed-off-by: Alex Gonzalez <[email protected]>
  • Loading branch information
alexgg committed Apr 26, 2024
1 parent 2ce06a4 commit 046fd01
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions upgrade-2.x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ function log {
loglevel=INFO
;;
esac
echo "${1}" | systemd-cat --level-prefix=0 --identifier="$(basename "$0")" --priority="${priority}" 2> /dev/null || true
echo "${1}" | systemd-cat --level-prefix=0 --identifier="${SCRIPTNAME}" --priority="${priority}" 2> /dev/null || true
endtime=$(date +%s)
printf "[%s][%09d%s%s\n" "$SCRIPTNAME" "$((endtime - starttime))" "][$loglevel]" "$1"
if [ "$loglevel" == "ERROR" ]; then
printf "[%09d%s%s\n" "$((endtime - starttime))" "][$loglevel]" "$1" >> /dev/stderr
exit 1
else
printf "[%09d%s%s\n" "$((endtime - starttime))" "][$loglevel]" "$1"
fi
}

Expand Down

0 comments on commit 046fd01

Please sign in to comment.