arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

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

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