From: Janani Venkataraman <jananive@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: amwang@redhat.com, procps@freelists.org, rdunlap@xenotime.net,
james.hogan@imgtec.com, aravinda@linux.vnet.ibm.com, hch@lst.de,
mhiramat@redhat.com, jeremy.fitzhardinge@citrix.com,
xemul@parallels.com, d.hatayama@jp.fujitsu.com,
coreutils@gnu.org, kosaki.motohiro@jp.fujitsu.com,
adobriyan@gmail.com, util-linux@vger.kernel.org,
tarundsk@linux.vnet.ibm.com, vapier@gentoo.org,
roland@hack.frob.com, ananth@linux.vnet.ibm.com,
gorcunov@openvz.org, avagin@openvz.org, oleg@redhat.com,
eparis@redhat.com, suzuki@linux.vnet.ibm.com,
andi@firstfloor.org, tj@kernel.org, akpm@linux-foundation.org,
torvalds@linux-foundation.org
Subject: [PATCH 10/33] Populates PRPS info
Date: Thu, 20 Mar 2014 15:10:32 +0530 [thread overview]
Message-ID: <20140320094032.14878.79807.stgit@localhost.localdomain> (raw)
In-Reply-To: <20140320093040.14878.903.stgit@localhost.localdomain>
Populates the prps_info by reading /proc/pid/stat and /proc/pid/cmdline.
Signed-off-by: Janani Venkataraman <jananive@linux.vnet.ibm.com>
---
src/coredump.h | 10 +++++++++
src/elf-compat.h | 48 +++++++++++++++++++++++++++++++++++++++++++++
src/elf.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/elf32.c | 1 +
src/elf64.c | 1 +
5 files changed, 118 insertions(+)
create mode 100644 src/elf-compat.h
diff --git a/src/coredump.h b/src/coredump.h
index 9b19f19..d5562fe 100644
--- a/src/coredump.h
+++ b/src/coredump.h
@@ -1,9 +1,19 @@
#define COMM_LEN 17 /* Maximum length of command line */
#define NUM_STAT_FEILDS 30 /* Number of fields read from /proc/pid/stat */
+#define PPID 0 /* Index for parent process ID */
+#define PGRP 1 /* Index for process group ID */
+#define SID 2 /* Index for session ID */
+#define FLAG 5 /* Index for flags */
+#define NICE 15 /* Index for nice value */
#define THREAD_COUNT_IDX 16 /* Index for number of threads */
#define __ps_thread_count ps_num[THREAD_COUNT_IDX] /* Process Information */
+#define __ps_ppid ps_num[PPID] /* Process PID */
+#define __ps_pgrp ps_num[PGRP] /* Process Group ID */
+#define __ps_sid ps_num[SID] /* Process Session ID */
+#define __ps_flag ps_num[FLAG] /* Process Flags */
+#define __ps_nice ps_num[NICE] /* Process Nice Value */
/* Status of the dump */
extern int status;
diff --git a/src/elf-compat.h b/src/elf-compat.h
new file mode 100644
index 0000000..463070a
--- /dev/null
+++ b/src/elf-compat.h
@@ -0,0 +1,48 @@
+/*
+ * ELF structures for gencore
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2013
+ *
+ * Authors:
+ * Janani Venkataraman <jananve@in.ibm.com>
+ */
+
+#if defined(__PPC64__) || defined(__PPC__)
+typedef unsigned int compat_id;
+#endif
+
+#if defined(__s390x__) || defined(__s390__)
+typedef unsigned short compat_id;
+#endif
+
+#if defined(__x86_64) || defined(__i386)
+typedef unsigned short compat_id;
+#endif
+
+/* Compat structure for PRPS_INFO */
+struct compat_elf_prpsinfo {
+ char pr_state;
+ char pr_sname;
+ char pr_zomb;
+ char pr_nice;
+ unsigned int pr_flag;
+ compat_id pr_uid;
+ compat_id pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ char pr_fname[16];
+ char pr_psargs[ELF_PRARGSZ];
+};
diff --git a/src/elf.c b/src/elf.c
index dfcb1d7..18bbeeb 100644
--- a/src/elf.c
+++ b/src/elf.c
@@ -27,7 +27,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
+#include <sys/procfs.h>
#include <linux/elf.h>
+#include "elf-compat.h"
#include "coredump.h"
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
@@ -187,6 +189,57 @@ static int fill_elf_header(int pid, struct core_proc *cp)
return 0;
}
+/* Populates PRPS_INFO */
+static int get_prpsinfo(int pid, struct core_proc *cp)
+{
+ char filename[40];
+ int ret;
+ FILE *fin;
+ struct Elf_prpsinfo prps;
+ struct pid_stat p;
+
+ ret = get_pid_stat(pid, &p);
+ if (ret)
+ return -1;
+
+ prps.pr_pid = p.ps_pid;
+ strcpy(prps.pr_fname, p.ps_comm);
+ prps.pr_state = p.ps_state;
+ prps.pr_ppid = p.__ps_ppid;
+ prps.pr_pgrp = p.__ps_pgrp;
+ prps.pr_sid = p.__ps_sid;
+ prps.pr_flag = p.__ps_flag;
+ prps.pr_nice = p.__ps_nice;
+
+ prps.pr_sname = prps.pr_state;
+ if (prps.pr_sname == 'z')
+ prps.pr_zomb = 1;
+ else
+ prps.pr_zomb = 0;
+
+ snprintf(filename, 40, "/proc/%d/cmdline", pid);
+ fin = fopen(filename, "r");
+ if (fin == NULL) {
+ status = errno;
+ gencore_log("Failure while fetching command line arguments from %s.\n", filename);
+ return -1;
+ }
+
+ /* Getting CMDLINE arguments */
+ ret = fread(prps.pr_psargs, ELF_PRARGSZ, 1, fin);
+ if (ret == -1) {
+ status = errno;
+ gencore_log("Failure while fetching command line arguments from %s.\n", filename);
+ fclose(fin);
+ return -1;
+ }
+
+ fclose(fin);
+
+ /* Adding PRPSINFO */
+ return add_note("CORE", NT_PRPSINFO, sizeof(prps), &prps, cp);
+}
+
int do_elf_coredump(int pid, struct core_proc *cp)
{
int ret;
@@ -196,5 +249,10 @@ int do_elf_coredump(int pid, struct core_proc *cp)
if (ret)
return -1;
+ /* Get prps_info */
+ ret = get_prpsinfo(pid, cp);
+ if (ret)
+ return -1;
+
return 0;
}
diff --git a/src/elf32.c b/src/elf32.c
index 01b3923..8778bed 100644
--- a/src/elf32.c
+++ b/src/elf32.c
@@ -34,5 +34,6 @@
#define Elf_Phdr Elf32_Phdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Nhdr Elf32_Nhdr
+#define Elf_prpsinfo compat_elf_prpsinfo
#include "elf.c"
diff --git a/src/elf64.c b/src/elf64.c
index a99a73b..d062888 100644
--- a/src/elf64.c
+++ b/src/elf64.c
@@ -34,5 +34,6 @@
#define Elf_Phdr Elf64_Phdr
#define Elf_Shdr Elf64_Shdr
#define Elf_Nhdr Elf64_Nhdr
+#define Elf_prpsinfo elf_prpsinfo
#include "elf.c"
next prev parent reply other threads:[~2014-03-20 9:40 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-20 9:39 [PATCH 00/33] [RFC] Non disruptive application core dump infrastructure Janani Venkataraman
2014-03-20 9:39 ` [PATCH 01/33] Configure and Make files Janani Venkataraman
2014-03-20 9:39 ` [PATCH 02/33] Validity of arguments Janani Venkataraman
2014-03-20 9:39 ` [PATCH 03/33] Process Status Janani Venkataraman
2014-03-20 9:39 ` [PATCH 04/33] Hold threads Janani Venkataraman
2014-03-20 19:01 ` Pavel Emelyanov
2014-03-25 6:58 ` Janani Venkataraman
2014-03-20 9:39 ` [PATCH 05/33] Fetching Memory maps Janani Venkataraman
2014-03-20 9:39 ` [PATCH 06/33] Check ELF class Janani Venkataraman
2014-03-20 9:39 ` [PATCH 07/33] Do elf_coredump Janani Venkataraman
2014-03-20 9:40 ` [PATCH 08/33] Fills elf header Janani Venkataraman
2014-03-20 9:40 ` [PATCH 09/33] Adding notes infrastructure Janani Venkataraman
2014-03-20 9:40 ` Janani Venkataraman [this message]
2014-03-20 9:40 ` [PATCH 11/33] Populate AUXV Janani Venkataraman
2014-03-20 9:40 ` [PATCH 12/33] Fetch File maps Janani Venkataraman
2014-03-20 9:41 ` [PATCH 13/33] Fetching thread specific Notes Janani Venkataraman
2014-03-20 9:41 ` [PATCH 14/33] Populating Program Headers Janani Venkataraman
2014-03-20 9:41 ` [PATCH 15/33] Updating Offset Janani Venkataraman
2014-03-20 9:41 ` [PATCH 16/33] Writing to core file Janani Venkataraman
2014-03-20 9:41 ` [PATCH 17/33] Daemonizing the Process Janani Venkataraman
2014-03-20 9:41 ` [PATCH 18/33] Socket operations Janani Venkataraman
2014-03-20 9:41 ` [PATCH 19/33] Block till request Janani Venkataraman
2014-03-20 9:41 ` [PATCH 20/33] Handling Requests Janani Venkataraman
2014-03-20 9:41 ` [PATCH 21/33] Get Clients PID Janani Venkataraman
2014-03-20 9:41 ` [PATCH 22/33] Dump the task Janani Venkataraman
2014-03-20 9:42 ` [PATCH 23/33] Handling SIG TERM of the daemon Janani Venkataraman
2014-03-20 9:42 ` [PATCH 24/33] Handling SIG TERM of the child Janani Venkataraman
2014-03-20 9:42 ` [PATCH 25/33] Systemd Socket ID retrieval Janani Venkataraman
2014-03-20 9:42 ` [PATCH 26/33] [libgencore] Setting up Connection Janani Venkataraman
2014-03-20 9:42 ` [PATCH 27/33] [libgencore] Request for dump Janani Venkataraman
2014-03-20 9:43 ` [PATCH 28/33] Man pages Janani Venkataraman
2014-03-20 9:43 ` [PATCH 29/33] Automake files for the doc folder Janani Venkataraman
2014-03-20 9:43 ` [PATCH 30/33] README, COPYING, Changelog Janani Venkataraman
2014-03-20 9:43 ` [PATCH 31/33] Spec file Janani Venkataraman
2014-03-20 9:43 ` [PATCH 32/33] Socket and Service files Janani Venkataraman
2014-03-20 9:44 ` [PATCH 33/33] Support check Janani Venkataraman
2014-03-20 10:24 ` [PATCH 00/33] [RFC] Non disruptive application core dump infrastructure Pádraig Brady
2014-03-21 8:17 ` Karel Zak
2014-03-21 15:02 ` Phillip Susi
2014-03-24 9:43 ` Janani Venkataraman
2014-03-24 13:54 ` Phillip Susi
2014-07-03 12:59 ` Suzuki K. Poulose
2014-03-24 9:38 ` Janani Venkataraman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140320094032.14878.79807.stgit@localhost.localdomain \
--to=jananive@linux.vnet.ibm.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=amwang@redhat.com \
--cc=ananth@linux.vnet.ibm.com \
--cc=andi@firstfloor.org \
--cc=aravinda@linux.vnet.ibm.com \
--cc=avagin@openvz.org \
--cc=coreutils@gnu.org \
--cc=d.hatayama@jp.fujitsu.com \
--cc=eparis@redhat.com \
--cc=gorcunov@openvz.org \
--cc=hch@lst.de \
--cc=james.hogan@imgtec.com \
--cc=jeremy.fitzhardinge@citrix.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@redhat.com \
--cc=oleg@redhat.com \
--cc=procps@freelists.org \
--cc=rdunlap@xenotime.net \
--cc=roland@hack.frob.com \
--cc=suzuki@linux.vnet.ibm.com \
--cc=tarundsk@linux.vnet.ibm.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=util-linux@vger.kernel.org \
--cc=vapier@gentoo.org \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox