|
|
a60cd7 |
From 9492af5e0e09dd66e179ccd8a505ce0b79978c83 Mon Sep 17 00:00:00 2001
|
|
|
a60cd7 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
a60cd7 |
Date: Mon, 15 Sep 2014 08:40:05 +0200
|
|
|
a60cd7 |
Subject: [ABRT PATCH 58/66] cli: robustize abrt-console-notification.sh
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- don't show any notifications without a terminal connected to stdout
|
|
|
a60cd7 |
- don't continue without writable $HOME directory
|
|
|
a60cd7 |
- forward all error messages to /dev/null
|
|
|
a60cd7 |
|
|
|
a60cd7 |
Resolves rhbz#1139001
|
|
|
a60cd7 |
|
|
|
a60cd7 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
a60cd7 |
---
|
|
|
a60cd7 |
src/cli/abrt-console-notification.sh | 30 ++++++++++++++++++++++++------
|
|
|
a60cd7 |
1 file changed, 24 insertions(+), 6 deletions(-)
|
|
|
a60cd7 |
|
|
|
a60cd7 |
diff --git a/src/cli/abrt-console-notification.sh b/src/cli/abrt-console-notification.sh
|
|
|
a60cd7 |
index 937abb0..849273c 100755
|
|
|
a60cd7 |
--- a/src/cli/abrt-console-notification.sh
|
|
|
a60cd7 |
+++ b/src/cli/abrt-console-notification.sh
|
|
|
a60cd7 |
@@ -1,21 +1,39 @@
|
|
|
a60cd7 |
+# If shell is not connect to a terminal, exit immediately, because this script
|
|
|
a60cd7 |
+# should print out ABRT's status and it is senseless to continue without
|
|
|
a60cd7 |
+# terminal.
|
|
|
a60cd7 |
+tty -s || exit 0
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+# If $HOME is not set, a non human user is logging in to shell but this script
|
|
|
a60cd7 |
+# should provide information to human users, therefore exiting immediately
|
|
|
a60cd7 |
+# without showing the notification.
|
|
|
a60cd7 |
+if [ -z "$HOME" ]; then
|
|
|
a60cd7 |
+ exit 0
|
|
|
a60cd7 |
+fi
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+if [ -z "$ABRT_DEBUG_LOG" ]; then
|
|
|
a60cd7 |
+ ABRT_DEBUG_LOG="/dev/null"
|
|
|
a60cd7 |
+fi
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
LPATHDIR="$HOME/.cache/abrt"
|
|
|
a60cd7 |
SINCEFILE="$LPATHDIR/lastnotification"
|
|
|
a60cd7 |
|
|
|
a60cd7 |
if [ ! -f "$LPATHDIR" ]; then
|
|
|
a60cd7 |
- mkdir -p "$LPATHDIR"
|
|
|
a60cd7 |
+ # It might happen that user doesn't have write access on his home.
|
|
|
a60cd7 |
+ mkdir -p "$LPATHDIR" >"$ABRT_DEBUG_LOG" 2>&1 || exit 0
|
|
|
a60cd7 |
fi
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-TMPPATH=`mktemp --tmpdir="$LPATHDIR" lastnotification.XXXXXXXX 2> /dev/null`
|
|
|
a60cd7 |
+TMPPATH=`mktemp --tmpdir="$LPATHDIR" lastnotification.XXXXXXXX 2> "$ABRT_DEBUG_LOG"`
|
|
|
a60cd7 |
|
|
|
a60cd7 |
SINCE=0
|
|
|
a60cd7 |
if [ -f "$SINCEFILE" ]; then
|
|
|
a60cd7 |
- SINCE=`cat $SINCEFILE 2> /dev/null`
|
|
|
a60cd7 |
+ SINCE=`cat $SINCEFILE 2>"$ABRT_DEBUG_LOG"`
|
|
|
a60cd7 |
fi
|
|
|
a60cd7 |
|
|
|
a60cd7 |
# always update the lastnotification
|
|
|
a60cd7 |
if [ -f "$TMPPATH" ]; then
|
|
|
a60cd7 |
- date +%s > "$TMPPATH"
|
|
|
a60cd7 |
- mv -f "$TMPPATH" "$SINCEFILE"
|
|
|
a60cd7 |
+ # Be quite in case of errors and don't scare users by strange error messages.
|
|
|
a60cd7 |
+ date +%s > "$TMPPATH" 2>"$ABRT_DEBUG_LOG"
|
|
|
a60cd7 |
+ mv -f "$TMPPATH" "$SINCEFILE" >"$ABRT_DEBUG_LOG" 2>&1
|
|
|
a60cd7 |
fi
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-abrt-cli status --since="$SINCE" 2> /dev/null
|
|
|
a60cd7 |
+abrt-cli status --since="$SINCE" 2>"$ABRT_DEBUG_LOG"
|
|
|
a60cd7 |
--
|
|
|
a60cd7 |
1.8.3.1
|
|
|
a60cd7 |
|