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

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