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

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