Blame SOURCES/0149-abrt-install-ccpp-hook-check-configuration.patch

47a88a
From fb05144fada665ac319b0d9fa1af7bc9f42e8c26 Mon Sep 17 00:00:00 2001
47a88a
From: Martin Milata <mmilata@redhat.com>
47a88a
Date: Thu, 16 Jul 2015 16:10:49 +0200
47a88a
Subject: [PATCH] abrt-install-ccpp-hook check configuration
47a88a
47a88a
Check that either full coredump or core backtrace are configured to be
47a88a
saved, fail init script if neither is.
47a88a
47a88a
Related to #829.
47a88a
47a88a
Signed-off-by: Martin Milata <mmilata@redhat.com>
47a88a
---
47a88a
 src/hooks/abrt-hook-ccpp.c          | 63 +++++++++++++++++++++++--------------
47a88a
 src/hooks/abrt-install-ccpp-hook.in |  5 +++
47a88a
 2 files changed, 44 insertions(+), 24 deletions(-)
47a88a
47a88a
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
47a88a
index b5f00f6..d95228f 100644
47a88a
--- a/src/hooks/abrt-hook-ccpp.c
47a88a
+++ b/src/hooks/abrt-hook-ccpp.c
47a88a
@@ -626,6 +626,18 @@ finito:
47a88a
     return err;
47a88a
 }
47a88a
 
47a88a
+static int test_configuration(bool setting_SaveFullCore, bool setting_CreateCoreBacktrace)
47a88a
+{
47a88a
+    if (!setting_SaveFullCore && !setting_CreateCoreBacktrace)
47a88a
+    {
47a88a
+        fprintf(stderr, "Both SaveFullCore and CreateCoreBacktrace are disabled - "
47a88a
+                        "at least one of them is needed for useful report.\n");
47a88a
+        return 1;
47a88a
+    }
47a88a
+
47a88a
+    return 0;
47a88a
+}
47a88a
+
47a88a
 int main(int argc, char** argv)
47a88a
 {
47a88a
     int err = 1;
47a88a
@@ -636,31 +648,9 @@ int main(int argc, char** argv)
47a88a
      */
47a88a
     int fd = xopen("/dev/null", O_RDWR);
47a88a
     while (fd < 2)
47a88a
-	fd = xdup(fd);
47a88a
+        fd = xdup(fd);
47a88a
     if (fd > 2)
47a88a
-	close(fd);
47a88a
-
47a88a
-    if (argc < 8)
47a88a
-    {
47a88a
-        /* percent specifier:         %s   %c              %p  %u  %g  %t   %e          %i */
47a88a
-        /* argv:                  [0] [1]  [2]             [3] [4] [5] [6]  [7]         [8]*/
47a88a
-        error_msg_and_die("Usage: %s SIGNO CORE_SIZE_LIMIT PID UID GID TIME BINARY_NAME [TID]", argv[0]);
47a88a
-    }
47a88a
-
47a88a
-    /* Not needed on 2.6.30.
47a88a
-     * At least 2.6.18 has a bug where
47a88a
-     * argv[1] = "SIGNO CORE_SIZE_LIMIT PID ..."
47a88a
-     * argv[2] = "CORE_SIZE_LIMIT PID ..."
47a88a
-     * and so on. Fixing it:
47a88a
-     */
47a88a
-    if (strchr(argv[1], ' '))
47a88a
-    {
47a88a
-        int i;
47a88a
-        for (i = 1; argv[i]; i++)
47a88a
-        {
47a88a
-            strchrnul(argv[i], ' ')[0] = '\0';
47a88a
-        }
47a88a
-    }
47a88a
+        close(fd);
47a88a
 
47a88a
     logmode = LOGMODE_JOURNAL;
47a88a
 
47a88a
@@ -689,6 +679,31 @@ int main(int argc, char** argv)
47a88a
         free_map_string(settings);
47a88a
     }
47a88a
 
47a88a
+    if (argc == 2 && strcmp(argv[1], "--config-test"))
47a88a
+        return test_configuration(setting_SaveFullCore, setting_CreateCoreBacktrace);
47a88a
+
47a88a
+    if (argc < 8)
47a88a
+    {
47a88a
+        /* percent specifier:         %s   %c              %p  %u  %g  %t   %e          %i */
47a88a
+        /* argv:                  [0] [1]  [2]             [3] [4] [5] [6]  [7]         [8]*/
47a88a
+        error_msg_and_die("Usage: %s SIGNO CORE_SIZE_LIMIT PID UID GID TIME BINARY_NAME [TID]", argv[0]);
47a88a
+    }
47a88a
+
47a88a
+    /* Not needed on 2.6.30.
47a88a
+     * At least 2.6.18 has a bug where
47a88a
+     * argv[1] = "SIGNO CORE_SIZE_LIMIT PID ..."
47a88a
+     * argv[2] = "CORE_SIZE_LIMIT PID ..."
47a88a
+     * and so on. Fixing it:
47a88a
+     */
47a88a
+    if (strchr(argv[1], ' '))
47a88a
+    {
47a88a
+        int i;
47a88a
+        for (i = 1; argv[i]; i++)
47a88a
+        {
47a88a
+            strchrnul(argv[i], ' ')[0] = '\0';
47a88a
+        }
47a88a
+    }
47a88a
+
47a88a
     errno = 0;
47a88a
     const char* signal_str = argv[1];
47a88a
     int signal_no = xatoi_positive(signal_str);
47a88a
diff --git a/src/hooks/abrt-install-ccpp-hook.in b/src/hooks/abrt-install-ccpp-hook.in
47a88a
index d4ed4a5..fff0a33 100755
47a88a
--- a/src/hooks/abrt-install-ccpp-hook.in
47a88a
+++ b/src/hooks/abrt-install-ccpp-hook.in
47a88a
@@ -31,6 +31,11 @@ CORE_PIPE_LIMIT_FILE="/proc/sys/kernel/core_pipe_limit"
47a88a
 CORE_PIPE_LIMIT="4"
47a88a
 
47a88a
 start() {
47a88a
+	if ! $HOOK_BIN --test-config; then
47a88a
+		echo "Invalid configuration."
47a88a
+		exit 1
47a88a
+	fi
47a88a
+
47a88a
 	cur=`cat "$PATTERN_FILE"`
47a88a
 	cur_first=`printf "%s" "$cur" | sed 's/ .*//'`
47a88a
 
47a88a
-- 
47a88a
2.4.3
47a88a