public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "gecos missing (solar)" <solar@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
Date: Tue, 18 Sep 2007 05:22:49 +0000	[thread overview]
Message-ID: <E1IXVXt-0006Bf-6R@stork.gentoo.org> (raw)

solar       07/09/18 05:22:49

  Modified:             pspax.c
  Log:
  - add /proc/pid/ipaddr support with the -i flag (grsec kernels only)

Revision  Changes    Path
1.39                 pax-utils/pspax.c

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?rev=1.39&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?rev=1.39&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?r1=1.38&r2=1.39

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- pspax.c	20 Aug 2007 09:54:15 -0000	1.38
+++ pspax.c	18 Sep 2007 05:22:48 -0000	1.39
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char *rcsid = "$Id: pspax.c,v 1.38 2007/08/20 09:54:15 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.39 2007/09/18 05:22:48 solar Exp $";
 const char * const argv0 = "pspax";
 
 #include "paxinc.h"
@@ -35,6 +35,7 @@
 static char verbose = 0;
 static char show_banner = 1;
 static char show_phdr = 0;
+static char show_addr = 0;
 static char noexec = 1;
 static char writeexec = 1;
 
@@ -201,6 +202,25 @@
 	return buf;
 }
 
+static char *get_pid_addr(pid_t pid)
+{
+	FILE *fp;
+	char *p;
+	char str[32];
+	static char buf[BUFSIZ];
+
+	memset(buf, 0, sizeof(buf));
+
+	snprintf(str, sizeof(str), PROC_DIR "/%u/ipaddr", pid);
+	if ((fp = fopen(str, "r")) == NULL)
+		return NULL;
+	if (fgets(buf, sizeof(buf), fp) != NULL)
+		if ((p = strchr(buf, '\n')) != NULL)
+			*p = 0;
+	fclose(fp);
+	return buf;
+}
+
 static const char *get_proc_type(pid_t pid)
 {
 	char fname[32];
@@ -273,10 +293,10 @@
 	register struct dirent *de;
 	pid_t pid;
 	pid_t ppid = show_pid;
-	int have_attr, wx;
+	int have_attr, have_addr, wx;
 	struct passwd *pwd;
 	struct stat st;
-	const char *pax, *type, *name, *caps, *attr;
+	const char *pax, *type, *name, *caps, *attr, *addr;
 	WRAP_SYSCAP(ssize_t length; cap_t cap_d;);
 
 	WRAP_SYSCAP(cap_d = cap_init());
@@ -294,9 +314,15 @@
 	else
 		have_attr = 0;
 
+	if ((access("/proc/self/ipaddr", R_OK) != (-1)) && show_addr)
+		have_addr = 1;
+	else
+		have_addr = 0;
+
 	if (show_banner)
-		printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s\n",
-		       "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", "ATTR", show_phdr ? "STACK LOAD" : "");
+		printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s %s\n",
+		       "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", have_attr ? "ATTR" : "",
+			have_addr ? "IPADDR" : "", show_phdr ? "STACK LOAD" : "");
 
 	while ((de = readdir(dir))) {
 		errno = 0;
@@ -327,6 +353,7 @@
 			type = get_proc_type(pid);
 			name = get_proc_name(pid);
 			attr = (have_attr ? get_pid_attr(pid) : NULL);
+			addr = (have_addr ? get_pid_addr(pid) : NULL);
 
 			if (show_uid != (-1) && pwd)
 				if (pwd->pw_uid != show_uid)
@@ -341,7 +368,7 @@
 			WRAP_SYSCAP(caps = cap_to_text(cap_d, &length));
 
 			if (show_all || type) {
-				printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s\n",
+				printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s\n",
 				       pwd  ? pwd->pw_name : "--------",
 				       pid,
 				       pax  ? pax  : "---",
@@ -349,7 +376,9 @@
 				       type ? type : "-------",
 				       name ? name : "-----",
 				       caps ? caps : " = ",
-				       attr ? attr : "-", show_phdr ? get_proc_phdr(pid) : "");
+				       attr ? attr : "",
+				       addr ? addr : "",
+				       show_phdr ? get_proc_phdr(pid) : "");
 				if (verbose && wx)
 					print_executable_mappings(pid);
 			}
@@ -366,11 +395,12 @@
 
 
 /* usage / invocation handling functions */
-#define PARSE_FLAGS "aep:u:g:nwvBhV"
+#define PARSE_FLAGS "aeip:u:g:nwvBhV"
 #define a_argument required_argument
 static struct option const long_opts[] = {
 	{"all",       no_argument, NULL, 'a'},
 	{"header",    no_argument, NULL, 'e'},
+	{"ipaddr",    no_argument, NULL, 'i'},
 	{"pid",        a_argument, NULL, 'p'},
 	{"user",       a_argument, NULL, 'u'},
 	{"group",      a_argument, NULL, 'g'},
@@ -385,6 +415,7 @@
 static const char *opts_help[] = {
 	"Show all processes",
 	"Print GNU_STACK/PT_LOAD markings",
+	"Print ipaddr info if supported",
 	"Process ID/pid #",
 	"Process user/uid #",
 	"Process group/gid #",
@@ -437,6 +468,7 @@
 		case 'B': show_banner = 0; break;
 		case 'a': show_all = 1; break;
 		case 'e': show_phdr = 1; break;
+		case 'i': show_addr = 1; break;
 		case 'p': show_pid = atoi(optarg); break;
 		case 'n': noexec = 1; writeexec = 0; break;
 		case 'w': noexec = 0; writeexec = 1; break;



-- 
gentoo-commits@gentoo.org mailing list



             reply	other threads:[~2007-09-18  5:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-18  5:22 gecos missing (solar) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-03-20 19:08 [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c Ned Ludd (solar)
2008-12-30 13:50 Mike Frysinger (vapier)
2009-03-15  8:51 Mike Frysinger (vapier)
2009-03-15  9:23 Mike Frysinger (vapier)
2010-02-28 19:12 Ned Ludd (solar)
2013-04-10 21:54 Mike Frysinger (vapier)

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=E1IXVXt-0006Bf-6R@stork.gentoo.org \
    --to=solar@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /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