Gentoo Archives: gentoo-commits

From: "gecos missing (solar)" <solar@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c
Date: Tue, 18 Sep 2007 05:30:30
Message-Id: E1IXVXt-0006Bf-6R@stork.gentoo.org
1 solar 07/09/18 05:22:49
2
3 Modified: pspax.c
4 Log:
5 - add /proc/pid/ipaddr support with the -i flag (grsec kernels only)
6
7 Revision Changes Path
8 1.39 pax-utils/pspax.c
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?rev=1.39&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?rev=1.39&content-type=text/plain
12 diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?r1=1.38&r2=1.39
13
14 Index: pspax.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v
17 retrieving revision 1.38
18 retrieving revision 1.39
19 diff -u -r1.38 -r1.39
20 --- pspax.c 20 Aug 2007 09:54:15 -0000 1.38
21 +++ pspax.c 18 Sep 2007 05:22:48 -0000 1.39
22 @@ -12,7 +12,7 @@
23 * cc -o pspax pspax.c -DWANT_SYSCAP -lcap
24 */
25
26 -static const char *rcsid = "$Id: pspax.c,v 1.38 2007/08/20 09:54:15 vapier Exp $";
27 +static const char *rcsid = "$Id: pspax.c,v 1.39 2007/09/18 05:22:48 solar Exp $";
28 const char * const argv0 = "pspax";
29
30 #include "paxinc.h"
31 @@ -35,6 +35,7 @@
32 static char verbose = 0;
33 static char show_banner = 1;
34 static char show_phdr = 0;
35 +static char show_addr = 0;
36 static char noexec = 1;
37 static char writeexec = 1;
38
39 @@ -201,6 +202,25 @@
40 return buf;
41 }
42
43 +static char *get_pid_addr(pid_t pid)
44 +{
45 + FILE *fp;
46 + char *p;
47 + char str[32];
48 + static char buf[BUFSIZ];
49 +
50 + memset(buf, 0, sizeof(buf));
51 +
52 + snprintf(str, sizeof(str), PROC_DIR "/%u/ipaddr", pid);
53 + if ((fp = fopen(str, "r")) == NULL)
54 + return NULL;
55 + if (fgets(buf, sizeof(buf), fp) != NULL)
56 + if ((p = strchr(buf, '\n')) != NULL)
57 + *p = 0;
58 + fclose(fp);
59 + return buf;
60 +}
61 +
62 static const char *get_proc_type(pid_t pid)
63 {
64 char fname[32];
65 @@ -273,10 +293,10 @@
66 register struct dirent *de;
67 pid_t pid;
68 pid_t ppid = show_pid;
69 - int have_attr, wx;
70 + int have_attr, have_addr, wx;
71 struct passwd *pwd;
72 struct stat st;
73 - const char *pax, *type, *name, *caps, *attr;
74 + const char *pax, *type, *name, *caps, *attr, *addr;
75 WRAP_SYSCAP(ssize_t length; cap_t cap_d;);
76
77 WRAP_SYSCAP(cap_d = cap_init());
78 @@ -294,9 +314,15 @@
79 else
80 have_attr = 0;
81
82 + if ((access("/proc/self/ipaddr", R_OK) != (-1)) && show_addr)
83 + have_addr = 1;
84 + else
85 + have_addr = 0;
86 +
87 if (show_banner)
88 - printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s\n",
89 - "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", "ATTR", show_phdr ? "STACK LOAD" : "");
90 + printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s %s\n",
91 + "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", have_attr ? "ATTR" : "",
92 + have_addr ? "IPADDR" : "", show_phdr ? "STACK LOAD" : "");
93
94 while ((de = readdir(dir))) {
95 errno = 0;
96 @@ -327,6 +353,7 @@
97 type = get_proc_type(pid);
98 name = get_proc_name(pid);
99 attr = (have_attr ? get_pid_attr(pid) : NULL);
100 + addr = (have_addr ? get_pid_addr(pid) : NULL);
101
102 if (show_uid != (-1) && pwd)
103 if (pwd->pw_uid != show_uid)
104 @@ -341,7 +368,7 @@
105 WRAP_SYSCAP(caps = cap_to_text(cap_d, &length));
106
107 if (show_all || type) {
108 - printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s\n",
109 + printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s\n",
110 pwd ? pwd->pw_name : "--------",
111 pid,
112 pax ? pax : "---",
113 @@ -349,7 +376,9 @@
114 type ? type : "-------",
115 name ? name : "-----",
116 caps ? caps : " = ",
117 - attr ? attr : "-", show_phdr ? get_proc_phdr(pid) : "");
118 + attr ? attr : "",
119 + addr ? addr : "",
120 + show_phdr ? get_proc_phdr(pid) : "");
121 if (verbose && wx)
122 print_executable_mappings(pid);
123 }
124 @@ -366,11 +395,12 @@
125
126
127 /* usage / invocation handling functions */
128 -#define PARSE_FLAGS "aep:u:g:nwvBhV"
129 +#define PARSE_FLAGS "aeip:u:g:nwvBhV"
130 #define a_argument required_argument
131 static struct option const long_opts[] = {
132 {"all", no_argument, NULL, 'a'},
133 {"header", no_argument, NULL, 'e'},
134 + {"ipaddr", no_argument, NULL, 'i'},
135 {"pid", a_argument, NULL, 'p'},
136 {"user", a_argument, NULL, 'u'},
137 {"group", a_argument, NULL, 'g'},
138 @@ -385,6 +415,7 @@
139 static const char *opts_help[] = {
140 "Show all processes",
141 "Print GNU_STACK/PT_LOAD markings",
142 + "Print ipaddr info if supported",
143 "Process ID/pid #",
144 "Process user/uid #",
145 "Process group/gid #",
146 @@ -437,6 +468,7 @@
147 case 'B': show_banner = 0; break;
148 case 'a': show_all = 1; break;
149 case 'e': show_phdr = 1; break;
150 + case 'i': show_addr = 1; break;
151 case 'p': show_pid = atoi(optarg); break;
152 case 'n': noexec = 1; writeexec = 0; break;
153 case 'w': noexec = 0; writeexec = 1; break;
154
155
156
157 --
158 gentoo-commits@g.o mailing list