doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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