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