public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2009-03-15  9:23 Mike Frysinger (vapier)
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger (vapier) @ 2009-03-15  9:23 UTC (permalink / raw
  To: gentoo-commits

vapier      09/03/15 09:23:30

  Modified:             pspax.c
  Log:
  fixup warning about caps code -- caps_free() does not take a const

Revision  Changes    Path
1.45                 pax-utils/pspax.c

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

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- pspax.c	15 Mar 2009 08:51:42 -0000	1.44
+++ pspax.c	15 Mar 2009 09:23:30 -0000	1.45
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char *rcsid = "$Id: pspax.c,v 1.44 2009/03/15 08:51:42 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.45 2009/03/15 09:23:30 vapier Exp $";
 const char * const argv0 = "pspax";
 
 #include "paxinc.h"
@@ -298,13 +298,12 @@
 	int have_attr, have_addr, wx;
 	struct passwd *pwd;
 	struct stat st;
-	const char *pax, *type, *name, *caps, *attr, *addr;
-	WRAP_SYSCAP(ssize_t length; cap_t cap_d;);
+	const char *pax, *type, *name, *attr, *addr;
+	char *caps;
+	WRAP_SYSCAP(ssize_t length; cap_t cap_d;)
 
 	WRAP_SYSCAP(cap_d = cap_init());
 
-	caps = NULL;
-
 	dir = opendir(PROC_DIR);
 	if (dir == NULL || chdir(PROC_DIR))
 		errp(PROC_DIR);
@@ -365,6 +364,7 @@
 					continue;
 
 			/* this is a non-POSIX function */
+			caps = NULL;
 			WRAP_SYSCAP(capgetp(pid, cap_d));
 			WRAP_SYSCAP(caps = cap_to_text(cap_d, &length));
 






^ permalink raw reply	[flat|nested] 7+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2013-04-10 21:54 Mike Frysinger (vapier)
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger (vapier) @ 2013-04-10 21:54 UTC (permalink / raw
  To: gentoo-commits

vapier      13/04/10 21:54:44

  Modified:             pspax.c
  Log:
  pspax: fix signed compare warning gcc throws up

Revision  Changes    Path
1.52                 pax-utils/pspax.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/pspax.c?rev=1.52&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/pspax.c?rev=1.52&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/pspax.c?r1=1.51&r2=1.52

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- pspax.c	18 Nov 2012 07:39:45 -0000	1.51
+++ pspax.c	10 Apr 2013 21:54:44 -0000	1.52
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char rcsid[] = "$Id: pspax.c,v 1.51 2012/11/18 07:39:45 vapier Exp $";
+static const char rcsid[] = "$Id: pspax.c,v 1.52 2013/04/10 21:54:44 vapier Exp $";
 const char argv0[] = "pspax";
 
 #include "paxinc.h"
@@ -38,8 +38,8 @@
 static char writeexec = 1;
 static char wide_output = 0;
 static pid_t show_pid = 0;
-static uid_t show_uid = -1;
-static gid_t show_gid = -1;
+static uid_t show_uid = (uid_t)-1;
+static gid_t show_gid = (gid_t)-1;
 
 static FILE *proc_fopen(pid_t pid, const char *file)
 {
@@ -371,13 +371,15 @@
 			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)
-					continue;
-
-			if (show_gid != -1 && pwd)
-				if (pwd->pw_gid != show_gid)
-					continue;
+			if (pwd) {
+				if (show_uid != (uid_t)-1)
+					if (pwd->pw_uid != show_uid)
+						continue;
+
+				if (show_gid != (gid_t)-1)
+					if (pwd->pw_gid != show_gid)
+						continue;
+			}
 
 			/* this is a non-POSIX function */
 			caps = NULL;





^ permalink raw reply	[flat|nested] 7+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2010-02-28 19:12 Ned Ludd (solar)
  0 siblings, 0 replies; 7+ messages in thread
From: Ned Ludd (solar) @ 2010-02-28 19:12 UTC (permalink / raw
  To: gentoo-commits

solar       10/02/28 19:12:40

  Modified:             pspax.c
  Log:
  Introduce -W,--wide flags to get full cmdline output display for pspax

Revision  Changes    Path
1.46                 pax-utils/pspax.c

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

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- pspax.c	15 Mar 2009 09:23:30 -0000	1.45
+++ pspax.c	28 Feb 2010 19:12:39 -0000	1.46
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char *rcsid = "$Id: pspax.c,v 1.45 2009/03/15 09:23:30 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.46 2010/02/28 19:12:39 solar Exp $";
 const char * const argv0 = "pspax";
 
 #include "paxinc.h"
@@ -36,7 +36,7 @@
 static char show_addr = 0;
 static char noexec = 1;
 static char writeexec = 1;
-
+static char wide_output = 0;
 static pid_t show_pid = 0;
 static uid_t show_uid = -1;
 static gid_t show_gid = -1;
@@ -49,11 +49,30 @@
 	return fopen(path, "r");
 }
 
+static char *get_proc_name_cmdline(pid_t pid)
+{
+	FILE *fp;
+	static char str[1024];
+
+	fp = proc_fopen(pid, "cmdline");
+	if (fp == NULL)
+		return NULL;
+
+	if (fscanf(fp, "%s.1023", str) != 1) {
+		fclose(fp);
+		return NULL;
+	}
+	return (str);
+}
+
 static char *get_proc_name(pid_t pid)
 {
 	FILE *fp;
 	static char str[BUFSIZ];
 
+	if (wide_output)
+		return get_proc_name_cmdline(pid);
+
 	fp = proc_fopen(pid, "stat");
 	if (fp == NULL)
 		return NULL;
@@ -397,7 +416,7 @@
 }
 
 /* usage / invocation handling functions */
-#define PARSE_FLAGS "aeip:u:g:nwvBhV"
+#define PARSE_FLAGS "aeip:u:g:nwWvBhV"
 #define a_argument required_argument
 static struct option const long_opts[] = {
 	{"all",       no_argument, NULL, 'a'},
@@ -408,12 +427,14 @@
 	{"group",      a_argument, NULL, 'g'},
 	{"nx",        no_argument, NULL, 'n'},
 	{"wx",        no_argument, NULL, 'w'},
+	{"wide",      no_argument, NULL, 'W'},
 	{"verbose",   no_argument, NULL, 'v'},
 	{"nobanner",  no_argument, NULL, 'B'},
 	{"help",      no_argument, NULL, 'h'},
 	{"version",   no_argument, NULL, 'V'},
 	{NULL,        no_argument, NULL, 0x0}
 };
+
 static const char *opts_help[] = {
 	"Show all processes",
 	"Print GNU_STACK/PT_LOAD markings",
@@ -423,6 +444,7 @@
 	"Process group/gid #",
 	"Only display w^x processes",
 	"Only display w|x processes",
+	"Wide output display of cmdline",
 	"Be verbose about executable mappings",
 	"Don't display the header",
 	"Print this help and exit",
@@ -474,6 +496,7 @@
 		case 'p': show_pid = atoi(optarg); break;
 		case 'n': noexec = 1; writeexec = 0; break;
 		case 'w': noexec = 0; writeexec = 1; break;
+		case 'W': wide_output = 1; break;
 		case 'v': verbose++; break;
 		case 'u':
 			show_uid = atoi(optarg);






^ permalink raw reply	[flat|nested] 7+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2009-03-15  8:51 Mike Frysinger (vapier)
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger (vapier) @ 2009-03-15  8:51 UTC (permalink / raw
  To: gentoo-commits

vapier      09/03/15 08:51:43

  Modified:             pspax.c
  Log:
  check return values of fscanf() and chdir() since gcc whines about it now

Revision  Changes    Path
1.44                 pax-utils/pspax.c

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

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- pspax.c	30 Dec 2008 13:50:04 -0000	1.43
+++ pspax.c	15 Mar 2009 08:51:42 -0000	1.44
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char *rcsid = "$Id: pspax.c,v 1.43 2008/12/30 13:50:04 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.44 2009/03/15 08:51:42 vapier Exp $";
 const char * const argv0 = "pspax";
 
 #include "paxinc.h"
@@ -54,10 +54,15 @@
 	FILE *fp;
 	static char str[BUFSIZ];
 
-	if ((fp = proc_fopen(pid, "stat")) == NULL)
+	fp = proc_fopen(pid, "stat");
+	if (fp == NULL)
 		return NULL;
 
-	fscanf(fp, "%*d %s.16", str);
+	if (fscanf(fp, "%*d %s.16", str) != 1) {
+		fclose(fp);
+		return NULL;
+	}
+
 	if (*str) {
 		str[strlen(str) - 1] = '\0';
 		str[16] = 0;
@@ -300,11 +305,9 @@
 
 	caps = NULL;
 
-	chdir(PROC_DIR);
-	if (!(dir = opendir(PROC_DIR))) {
-		perror(PROC_DIR);
-		exit(EXIT_FAILURE);
-	}
+	dir = opendir(PROC_DIR);
+	if (dir == NULL || chdir(PROC_DIR))
+		errp(PROC_DIR);
 
 	if (access("/proc/self/attr/current", R_OK) != -1)
 		have_attr = 1;






^ permalink raw reply	[flat|nested] 7+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2008-12-30 13:50 Mike Frysinger (vapier)
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger (vapier) @ 2008-12-30 13:50 UTC (permalink / raw
  To: gentoo-commits

vapier      08/12/30 13:50:05

  Modified:             pspax.c
  Log:
  cleanup pspax code a bit

Revision  Changes    Path
1.43                 pax-utils/pspax.c

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

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- pspax.c	30 Dec 2008 13:13:15 -0000	1.42
+++ pspax.c	30 Dec 2008 13:50:04 -0000	1.43
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char *rcsid = "$Id: pspax.c,v 1.42 2008/12/30 13:13:15 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.43 2008/12/30 13:50:04 vapier Exp $";
 const char * const argv0 = "pspax";
 
 #include "paxinc.h"
@@ -41,35 +41,38 @@
 static uid_t show_uid = -1;
 static gid_t show_gid = -1;
 
+static FILE *proc_fopen(pid_t pid, const char *file)
+{
+	char path[__PAX_UTILS_PATH_MAX];
+	snprintf(path, sizeof(path), PROC_DIR "/%u/%s", pid, file);
+	path[sizeof(path) - 1] = '\0';
+	return fopen(path, "r");
+}
+
 static char *get_proc_name(pid_t pid)
 {
 	FILE *fp;
-	static char str[__PAX_UTILS_PATH_MAX];
-	memset(&str, 0, sizeof(str));
+	static char str[BUFSIZ];
 
-	snprintf(str, sizeof(str), PROC_DIR "/%u/stat", pid);
-	if ((fp = fopen(str, "r")) == NULL)
+	if ((fp = proc_fopen(pid, "stat")) == NULL)
 		return NULL;
 
-	memset(&str, 0, sizeof(str));
-
 	fscanf(fp, "%*d %s.16", str);
 	if (*str) {
 		str[strlen(str) - 1] = '\0';
 		str[16] = 0;
 	}
 	fclose(fp);
+
 	return (str+1);
 }
 
 static int get_proc_maps(pid_t pid)
 {
-	static char str[__PAX_UTILS_PATH_MAX];
 	FILE *fp;
+	static char str[BUFSIZ];
 
-	snprintf(str, sizeof(str), PROC_DIR "/%u/maps", pid);
-
-	if ((fp = fopen(str, "r")) == NULL)
+	if ((fp = proc_fopen(pid, "maps")) == NULL)
 		return -1;
 
 	while (fgets(str, sizeof(str), fp)) {
@@ -96,17 +99,16 @@
 		}
 	}
 	fclose(fp);
+
 	return 0;
 }
 
 static int print_executable_mappings(pid_t pid)
 {
-	static char str[__PAX_UTILS_PATH_MAX];
 	FILE *fp;
+	static char str[BUFSIZ];
 
-	snprintf(str, sizeof(str), PROC_DIR "/%u/maps", pid);
-
-	if ((fp = fopen(str, "r")) == NULL)
+	if ((fp = proc_fopen(pid, "maps")) == NULL)
 		return -1;
 
 	while (fgets(str, sizeof(str), fp)) {
@@ -131,6 +133,7 @@
 		}
 	}
 	fclose(fp);
+
 	return 0;
 }
 
@@ -147,13 +150,14 @@
 {
 	struct stat st;
 	struct passwd *pwd;
-	static char str[__PAX_UTILS_PATH_MAX];
+	char path[__PAX_UTILS_PATH_MAX];
 
-	snprintf(str, sizeof(str), PROC_DIR "/%u/stat", pid);
+	snprintf(path, sizeof(path), PROC_DIR "/%u/stat", pid);
 
-	if (stat(str, &st) != -1)
+	if (stat(path, &st) != -1)
 		if ((pwd = getpwuid(st.st_uid)) != NULL)
 			return pwd;
+
 	return NULL;
 }
 
@@ -161,10 +165,9 @@
 {
 	FILE *fp;
 	size_t len;
-	static char str[__PAX_UTILS_PATH_MAX];
+	static char str[BUFSIZ];
 
-	snprintf(str, sizeof(str), PROC_DIR "/%u/status", pid);
-	if ((fp = fopen(str, "r")) == NULL)
+	if ((fp = proc_fopen(pid, "status")) == NULL)
 		return NULL;
 
 	len = strlen(name);
@@ -178,6 +181,7 @@
 		}
 	}
 	fclose(fp);
+
 	return NULL;
 }
 
@@ -185,18 +189,16 @@
 {
 	FILE *fp;
 	char *p;
-	char str[32];
 	static char buf[BUFSIZ];
 
-	memset(buf, 0, sizeof(buf));
-
-	snprintf(str, sizeof(str), PROC_DIR "/%u/attr/current", pid);
-	if ((fp = fopen(str, "r")) == NULL)
+	if ((fp = proc_fopen(pid, "attr/current")) == NULL)
 		return NULL;
+
 	if (fgets(buf, sizeof(buf), fp) != NULL)
 		if ((p = strchr(buf, '\n')) != NULL)
 			*p = 0;
 	fclose(fp);
+
 	return buf;
 }
 
@@ -204,31 +206,29 @@
 {
 	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)
+	if ((fp = proc_fopen(pid, "ipaddr")) == 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];
-	elfobj *elf = NULL;
-	char *ret = NULL;
+	elfobj *elf;
+	const char *ret;
 
 	snprintf(fname, sizeof(fname), PROC_DIR "/%u/exe", pid);
 	if ((elf = readelf(fname)) == NULL)
-		return ret;
-	ret = (char *)get_elfetype(elf);
+		return NULL;
+	ret = get_elfetype(elf);
 	unreadelf(elf);
 	return ret;
 }
@@ -273,13 +273,13 @@
 static const char *get_proc_phdr(pid_t pid)
 {
 	char fname[32];
-	elfobj *elf = NULL;
-	char *ret = NULL;
+	elfobj *elf;
+	const char *ret;
 
 	snprintf(fname, sizeof(fname), PROC_DIR "/%u/exe", pid);
 	if ((elf = readelf(fname)) == NULL)
-		return ret;
-	ret = (char *) scanelf_file_phdr(elf);
+		return NULL;
+	ret = scanelf_file_phdr(elf);
 	unreadelf(elf);
 	return ret;
 }






^ permalink raw reply	[flat|nested] 7+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2008-03-20 19:08 Ned Ludd (solar)
  0 siblings, 0 replies; 7+ messages in thread
From: Ned Ludd (solar) @ 2008-03-20 19:08 UTC (permalink / raw
  To: gentoo-commits

solar       08/03/20 19:08:17

  Modified:             pspax.c
  Log:
  - keep username alingment when username exceeds 8 standard chars

Revision  Changes    Path
1.41                 pax-utils/pspax.c

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

Index: pspax.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- pspax.c	17 Jan 2008 04:37:19 -0000	1.40
+++ pspax.c	20 Mar 2008 19:08:16 -0000	1.41
@@ -12,7 +12,7 @@
  *  cc -o pspax pspax.c -DWANT_SYSCAP -lcap
  */
 
-static const char *rcsid = "$Id: pspax.c,v 1.40 2008/01/17 04:37:19 solar Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.41 2008/03/20 19:08:16 solar Exp $";
 const char * const argv0 = "pspax";
 
 #include "paxinc.h"
@@ -364,6 +364,9 @@
 			WRAP_SYSCAP(capgetp(pid, cap_d));
 			WRAP_SYSCAP(caps = cap_to_text(cap_d, &length));
 
+			if (pwd && strlen(pwd->pw_name) >= 8)
+				pwd->pw_name[8] = 0;
+
 			if (show_all || type) {
 				printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s\n",
 				       pwd  ? pwd->pw_name : "--------",



-- 
gentoo-commits@lists.gentoo.org mailing list



^ permalink raw reply	[flat|nested] 7+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
@ 2007-09-18  5:22 gecos missing (solar)
  0 siblings, 0 replies; 7+ messages in thread
From: gecos missing (solar) @ 2007-09-18  5:22 UTC (permalink / raw
  To: gentoo-commits

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-04-10 21:54 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox