Blob Blame Raw
From 051448283b05c26ceb5ae561be4b0805d7075b2e Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Wed, 9 Sep 2015 14:02:57 +0200
Subject: [PATCH] ccpp: Use Global PID

Related: #1261036

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 src/hooks/abrt-hook-ccpp.c          | 20 ++++++++++++--------
 src/hooks/abrt-install-ccpp-hook.in |  4 ++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
index f5200dc..12b3f118 100644
--- a/src/hooks/abrt-hook-ccpp.c
+++ b/src/hooks/abrt-hook-ccpp.c
@@ -161,12 +161,13 @@ static struct dump_dir *dd;
  * %t - UNIX time of dump
  * %e - executable filename
  * %I - global crash thread tid
+ * %P - global pid
  * %% - output one "%"
  */
 /* Hook must be installed with exactly the same sequence of %c specifiers.
  * Last one, %h, may be omitted (we can find it out).
  */
-static const char percent_specifiers[] = "%scpugteI";
+static const char percent_specifiers[] = "%scpugtePI";
 static char *core_basename = (char*) "core";
 
 static char* get_executable(pid_t pid, int *fd_p)
@@ -688,9 +689,9 @@ int main(int argc, char** argv)
 
     if (argc < 8)
     {
-        /* percent specifier:         %s   %c              %p  %u  %g  %t   %e          %I */
-        /* argv:                  [0] [1]  [2]             [3] [4] [5] [6]  [7]         [8]*/
-        error_msg_and_die("Usage: %s SIGNO CORE_SIZE_LIMIT PID UID GID TIME BINARY_NAME [TID]", argv[0]);
+        /* percent specifier:         %s   %c              %p  %u  %g  %t   %e          %P         %I*/
+        /* argv:                  [0] [1]  [2]             [3] [4] [5] [6]  [7]         [8]        [9]*/
+        error_msg_and_die("Usage: %s SIGNO CORE_SIZE_LIMIT PID UID GID TIME BINARY_NAME GLOBAL_PID [TID]", argv[0]);
     }
 
     /* Not needed on 2.6.30.
@@ -718,9 +719,9 @@ int main(int argc, char** argv)
         ulimit_c = ~((off_t)1 << (sizeof(off_t)*8-1));
     }
     const char *pid_str = argv[3];
-    pid_t pid = xatoi_positive(argv[3]);
+    pid_t local_pid = xatoi_positive(argv[3]);
     uid_t uid = xatoi_positive(argv[4]);
-    if (errno || pid <= 0)
+    if (errno || local_pid <= 0)
     {
         perror_msg_and_die("PID '%s' or limit '%s' is bogus", argv[3], argv[2]);
     }
@@ -733,11 +734,13 @@ int main(int argc, char** argv)
         else
             free(s);
     }
+    const char *global_pid_str = argv[8];
+    pid_t pid = xatoi_positive(argv[8]);
 
     pid_t tid = 0;
-    if (argv[8])
+    if (argv[9])
     {
-        tid = xatoi_positive(argv[8]);
+        tid = xatoi_positive(argv[9]);
     }
 
     char path[PATH_MAX];
@@ -914,6 +917,7 @@ int main(int argc, char** argv)
         dd_save_text(dd, FILENAME_TYPE, "CCpp");
         dd_save_text(dd, FILENAME_EXECUTABLE, executable);
         dd_save_text(dd, FILENAME_PID, pid_str);
+        dd_save_text(dd, /*FILENAME_GLOBAL_PID*/"global_pid", global_pid_str);
         dd_save_text(dd, FILENAME_PROC_PID_STATUS, proc_pid_status);
         if (user_pwd)
             dd_save_text(dd, FILENAME_PWD, user_pwd);
diff --git a/src/hooks/abrt-install-ccpp-hook.in b/src/hooks/abrt-install-ccpp-hook.in
index 65f771f..707c57d 100755
--- a/src/hooks/abrt-install-ccpp-hook.in
+++ b/src/hooks/abrt-install-ccpp-hook.in
@@ -11,9 +11,9 @@ SAVED_PATTERN_DIR="@VAR_RUN@/abrt"
 SAVED_PATTERN_FILE="@VAR_RUN@/abrt/saved_core_pattern"
 HOOK_BIN="@libexecdir@/abrt-hook-ccpp"
 # Must match percent_specifiers[] order in abrt-hook-ccpp.c:
-PATTERN="|$HOOK_BIN %s %c %p %u %g %t %e %I"
+PATTERN="|$HOOK_BIN %s %c %p %u %g %t %e %P %I"
 # Same, but with bogus "executable name" parameter
-PATTERN1="|$HOOK_BIN %s %c %p %u %g %t e %I"
+PATTERN1="|$HOOK_BIN %s %c %p %u %g %t e %P %I"
 
 # core_pipe_limit specifies how many dump_helpers can run at the same time
 # 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing
-- 
2.4.3