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

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