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

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