Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jfilak
Contributor
|
||
| 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" | ||
Note that
&>isn't a portable syntax, it's a Bash 4 feature. Using the clunkier>"$ABRT_DEBUG_LOG" 2>&1will be more reliable in case a user has dash or some other mere Bourne-compatible shell.(ditto on line 36)