Blame SOURCES/0003-ccpp-add-h-and-e-parameter-into-abrt-hook-ccpp.patch

8f9a28
From a8a22295837aaadf39bfede6c92e9f9047bcaa34 Mon Sep 17 00:00:00 2001
8f9a28
From: Matej Habrnal <mhabrnal@redhat.com>
8f9a28
Date: Wed, 6 Jun 2018 14:04:09 +0200
8f9a28
Subject: [PATCH] ccpp: add %h and %e parameter into abrt-hook-ccpp
8f9a28
8f9a28
Without this commit core_pattern's parameter %h and %e was not
8f9a28
translated at all.
8f9a28
8f9a28
If there is a white space in executable filename, %e replaced only by
8f9a28
the first part of executable name (till the space). Hence we decided
8f9a28
to get executable name from /proc/PID/exe symlink exist.
8f9a28
8f9a28
Example:
8f9a28
If 'core_pattern = core.%h.%p.%t.%e' the result was
8f9a28
core.%h.26284.1469805542.sleep not
8f9a28
core.myshostmane.26284.1469805542.sleep with spaces
8f9a28
8f9a28
Related to #1587891
8f9a28
8f9a28
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
8f9a28
---
8f9a28
 src/hooks/abrt-hook-ccpp.c          | 36 ++++++++++++++++++++++++------------
8f9a28
 src/hooks/abrt-install-ccpp-hook.in |  2 +-
8f9a28
 2 files changed, 25 insertions(+), 13 deletions(-)
8f9a28
8f9a28
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
8f9a28
index 1c4e45e..40117fc 100644
8f9a28
--- a/src/hooks/abrt-hook-ccpp.c
8f9a28
+++ b/src/hooks/abrt-hook-ccpp.c
8f9a28
@@ -65,13 +65,13 @@ static struct dump_dir *dd;
8f9a28
  * %t - UNIX time of dump
8f9a28
  * %P - global pid
8f9a28
  * %I - crash thread tid
8f9a28
- * %e - executable filename (can contain white spaces)
8f9a28
+ * %h - hostname
8f9a28
+ * %e - executable filename (can contain white spaces, must be placed at the end)
8f9a28
  * %% - output one "%"
8f9a28
  */
8f9a28
 /* Hook must be installed with exactly the same sequence of %c specifiers.
8f9a28
- * Last one, %h, may be omitted (we can find it out).
8f9a28
  */
8f9a28
-static const char percent_specifiers[] = "%scpugtePi";
8f9a28
+static const char percent_specifiers[] = "%scpugtPIhe";
8f9a28
 static char *core_basename = (char*) "core";
8f9a28
 
8f9a28
 static DIR *open_cwd(pid_t pid)
8f9a28
@@ -146,7 +146,8 @@ static int setfscreatecon_raw(security_context_t context)
8f9a28
 }
8f9a28
 #endif
8f9a28
 
8f9a28
-static int open_user_core(uid_t uid, uid_t fsuid, gid_t fsgid, pid_t pid, char **percent_values)
8f9a28
+static int open_user_core(uid_t uid, uid_t fsuid, gid_t fsgid, pid_t pid,
8f9a28
+                          char **percent_values, const char *executable_filename)
8f9a28
 {
8f9a28
     proc_cwd = open_cwd(pid);
8f9a28
     if (proc_cwd == NULL)
8f9a28
@@ -196,7 +197,13 @@ static int open_user_core(uid_t uid, uid_t fsuid, gid_t fsgid, pid_t pid, char *
8f9a28
             {
8f9a28
                 const char *val = "%";
8f9a28
                 if (specifier_num > 0) /* not %% */
8f9a28
+                {
8f9a28
                     val = percent_values[specifier_num - 1];
8f9a28
+                    /* if %e (executable filename), use executable from
8f9a28
+                     * /proc/PID/exe symlink if exists */
8f9a28
+                    if (percent_specifiers[specifier_num] == 'e' && executable_filename)
8f9a28
+                        val = executable_filename;
8f9a28
+                }
8f9a28
                 //log_warning("c:'%c'", c);
8f9a28
                 //log_warning("val:'%s'", val);
8f9a28
 
8f9a28
@@ -917,9 +924,9 @@ int main(int argc, char** argv)
8f9a28
 
8f9a28
     if (argc < 8)
8f9a28
     {
8f9a28
-        /* percent specifier:         %s   %c              %p  %u  %g  %t   %P         %T        */
8f9a28
-        /* argv:                  [0] [1]  [2]             [3] [4] [5] [6]  [7]        [8]       */
8f9a28
-        error_msg_and_die("Usage: %s SIGNO CORE_SIZE_LIMIT PID UID GID TIME GLOBAL_PID GLOBAL_TID", argv[0]);
8f9a28
+        /* percent specifier:         %s   %c              %p  %u  %g  %t   %P         %I         %h       %e   */
8f9a28
+        /* argv:                  [0] [1]  [2]             [3] [4] [5] [6]  [7]        [8]        [9]      [10] */
8f9a28
+        error_msg_and_die("Usage: %s SIGNO CORE_SIZE_LIMIT PID UID GID TIME GLOBAL_PID GLOBAL_TID HOSTNAME BINARY_NAME", argv[0]);
8f9a28
     }
8f9a28
 
8f9a28
     /* Not needed on 2.6.30.
8f9a28
@@ -1016,13 +1023,21 @@ int main(int argc, char** argv)
8f9a28
 
8f9a28
     snprintf(path, sizeof(path), "%s/last-ccpp", g_settings_dump_location);
8f9a28
 
8f9a28
+    char *executable = get_executable_at(pid_proc_fd);
8f9a28
+    const char *last_slash = NULL;
8f9a28
+    if (executable)
8f9a28
+    {
8f9a28
+        last_slash = strrchr(executable, '/');
8f9a28
+        /* if the last_slash was found, skip it */
8f9a28
+        if (last_slash) ++last_slash;
8f9a28
+    }
8f9a28
+
8f9a28
     /* Open a fd to compat coredump, if requested and is possible */
8f9a28
     int user_core_fd = -1;
8f9a28
     if (setting_MakeCompatCore && ulimit_c != 0)
8f9a28
         /* note: checks "user_pwd == NULL" inside; updates core_basename */
8f9a28
-        user_core_fd = open_user_core(uid, fsuid, fsgid, pid, &argv[1]);
8f9a28
+        user_core_fd = open_user_core(uid, fsuid, fsgid, pid, &argv[1], (const char *)last_slash);
8f9a28
 
8f9a28
-    char *executable = get_executable_at(pid_proc_fd);
8f9a28
     if (executable == NULL)
8f9a28
     {
8f9a28
         /* readlink on /proc/$PID/exe failed, don't create abrt dump dir */
8f9a28
@@ -1031,9 +1046,6 @@ int main(int argc, char** argv)
8f9a28
         return create_user_core(user_core_fd, pid, ulimit_c);
8f9a28
     }
8f9a28
 
8f9a28
-    const char *last_slash = strrchr(executable, '/');
8f9a28
-    /* if the last_slash was found, skip it */
8f9a28
-    if (last_slash) ++last_slash;
8f9a28
 
8f9a28
     /* ignoring crashes */
8f9a28
     if (executable && is_path_ignored(setting_ignored_paths, executable))
8f9a28
diff --git a/src/hooks/abrt-install-ccpp-hook.in b/src/hooks/abrt-install-ccpp-hook.in
8f9a28
index 660c209..f8c0c61 100755
8f9a28
--- a/src/hooks/abrt-install-ccpp-hook.in
8f9a28
+++ b/src/hooks/abrt-install-ccpp-hook.in
8f9a28
@@ -11,7 +11,7 @@ SAVED_PATTERN_DIR="@VAR_RUN@/abrt"
8f9a28
 SAVED_PATTERN_FILE="@VAR_RUN@/abrt/saved_core_pattern"
8f9a28
 HOOK_BIN="@libexecdir@/abrt-hook-ccpp"
8f9a28
 # Must match percent_specifiers[] order in abrt-hook-ccpp.c:
8f9a28
-PATTERN="|$HOOK_BIN %s %c %p %u %g %t %P %I"
8f9a28
+PATTERN="|$HOOK_BIN %s %c %p %u %g %t %P %I %h %e"
8f9a28
 
8f9a28
 # core_pipe_limit specifies how many dump_helpers can run at the same time
8f9a28
 # 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing
8f9a28
-- 
8f9a28
1.8.3.1
8f9a28