Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cli: robustize abrt-console-notification.sh
- don't show any notifications without a terminal connected to stdout
- don't continue without writable $HOME directory
- forward all error messages to /dev/null

Resolves rhbz#1141485
Related to rhbz#1139001

Signed-off-by: Jakub Filak <jfilak@redhat.com>
  • Loading branch information
Jakub Filak committed Sep 15, 2014
1 parent 06321d2 commit 592b7e1
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/cli/abrt-console-notification.sh
@@ -1,21 +1,39 @@
# If shell is not connect to a terminal, exit immediately, because this script
# should print out ABRT's status and it is senseless to continue without
# terminal.
tty -s || exit 0

# If $HOME is not set, a non human user is logging in to shell but this script
# should provide information to human users, therefore exiting immediately
# without showing the notification.
if [ -z "$HOME" ]; then
exit 0
fi

if [ -z "$ABRT_DEBUG_LOG" ]; then
ABRT_DEBUG_LOG="/dev/null"
fi

LPATHDIR="$HOME/.cache/abrt"
SINCEFILE="$LPATHDIR/lastnotification"

if [ ! -f "$LPATHDIR" ]; then
mkdir -p "$LPATHDIR"
# It might happen that user doesn't have write access on his home.
mkdir -p "$LPATHDIR" &> "$ABRT_DEBUG_LOG" || exit 0

This comment has been minimized.

Copy link
@domcleal

domcleal Sep 15, 2014

Note that &> isn't a portable syntax, it's a Bash 4 feature. Using the clunkier >"$ABRT_DEBUG_LOG" 2>&1 will be more reliable in case a user has dash or some other mere Bourne-compatible shell.

(ditto on line 36)

This comment has been minimized.

Copy link
@jfilak

jfilak Sep 15, 2014

Contributor

Thanks! I never use '&>' and I don't know why I used it here. Hopefully, this commit 119fb61 fixes the issue correctly.

This comment has been minimized.

Copy link
@domcleal

domcleal Sep 15, 2014

Looks good, thanks!

fi

TMPPATH=`mktemp --tmpdir="$LPATHDIR" lastnotification.XXXXXXXX 2> /dev/null`
TMPPATH=`mktemp --tmpdir="$LPATHDIR" lastnotification.XXXXXXXX 2> "$ABRT_DEBUG_LOG"`

SINCE=0
if [ -f "$SINCEFILE" ]; then
SINCE=`cat $SINCEFILE 2> /dev/null`
SINCE=`cat $SINCEFILE 2> "$ABRT_DEBUG_LOG"`
fi

# always update the lastnotification
if [ -f "$TMPPATH" ]; then
date +%s > "$TMPPATH"
mv -f "$TMPPATH" "$SINCEFILE"
# Be quite in case of errors and don't scare users by strange error messages.
date +%s > "$TMPPATH" 2> "$ABRT_DEBUG_LOG"
mv -f "$TMPPATH" "$SINCEFILE" &> "$ABRT_DEBUG_LOG"
fi

abrt-cli status --since="$SINCE" 2> /dev/null
abrt-cli status --since="$SINCE" 2> "$ABRT_DEBUG_LOG"

0 comments on commit 592b7e1

Please sign in to comment.