Blame 0058-cli-robustize-abrt-console-notification.sh.patch

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