| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.21 2011/06/23 22:50:53 christos Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.22 2011/10/18 20:54:56 jym Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Brown. | | 8 | * by Andrew Brown. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __RCSID("$NetBSD: main.c,v 1.21 2011/06/23 22:50:53 christos Exp $"); | | 34 | __RCSID("$NetBSD: main.c,v 1.22 2011/10/18 20:54:56 jym Exp $"); |
35 | #endif | | 35 | #endif |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | | | 38 | |
39 | #ifndef __NetBSD_Version__ | | 39 | #ifndef __NetBSD_Version__ |
40 | #error go away, you fool | | 40 | #error go away, you fool |
41 | #elif (__NetBSD_Version__ < 105000000) | | 41 | #elif (__NetBSD_Version__ < 105000000) |
42 | #error only works with uvm | | 42 | #error only works with uvm |
43 | #endif | | 43 | #endif |
44 | | | 44 | |
45 | #include <fcntl.h> | | 45 | #include <fcntl.h> |
46 | #include <errno.h> | | 46 | #include <errno.h> |
47 | #include <unistd.h> | | 47 | #include <unistd.h> |
| @@ -298,35 +298,43 @@ main(int argc, char *argv[]) | | | @@ -298,35 +298,43 @@ main(int argc, char *argv[]) |
298 | if (pid < 0) | | 298 | if (pid < 0) |
299 | errno = EINVAL; | | 299 | errno = EINVAL; |
300 | if (*t != '\0') | | 300 | if (*t != '\0') |
301 | errx(1, "%s is not a valid pid", | | 301 | errx(1, "%s is not a valid pid", |
302 | argv[0]); | | 302 | argv[0]); |
303 | if (errno != 0) | | 303 | if (errno != 0) |
304 | err(1, "%s is not a valid pid", | | 304 | err(1, "%s is not a valid pid", |
305 | argv[0]); | | 305 | argv[0]); |
306 | argv++; | | 306 | argv++; |
307 | argc--; | | 307 | argc--; |
308 | } | | 308 | } |
309 | } | | 309 | } |
310 | | | 310 | |
| | | 311 | /* |
| | | 312 | * Only print mappings for processes we can send a signal(7) |
| | | 313 | * to, or kernel mappings if we are root |
| | | 314 | */ |
| | | 315 | if (kill(pid, 0) == -1 || |
| | | 316 | (pid == 0 && getuid() != 0)) { |
| | | 317 | errno = EPERM; |
| | | 318 | warn("%d", pid); |
| | | 319 | pid = -1; |
| | | 320 | continue; |
| | | 321 | |
| | | 322 | } |
| | | 323 | |
311 | /* find the process id */ | | 324 | /* find the process id */ |
312 | if (pid == 0) | | 325 | if (pid == 0) |
313 | kproc = NULL; | | 326 | kproc = NULL; |
314 | else { | | 327 | else { |
315 | if (kill(pid, 0) == -1) { | | | |
316 | warn("%d", pid); | | | |
317 | pid = -1; | | | |
318 | continue; | | | |
319 | } | | | |
320 | kproc = kvm_getproc2(kd, KERN_PROC_PID, pid, | | 328 | kproc = kvm_getproc2(kd, KERN_PROC_PID, pid, |
321 | sizeof(struct kinfo_proc2), &rc); | | 329 | sizeof(struct kinfo_proc2), &rc); |
322 | if (kproc == NULL || rc == 0) { | | 330 | if (kproc == NULL || rc == 0) { |
323 | errno = ESRCH; | | 331 | errno = ESRCH; |
324 | warn("%d", pid); | | 332 | warn("%d", pid); |
325 | pid = -1; | | 333 | pid = -1; |
326 | continue; | | 334 | continue; |
327 | } | | 335 | } |
328 | } | | 336 | } |
329 | | | 337 | |
330 | /* dump it */ | | 338 | /* dump it */ |
331 | if (many) { | | 339 | if (many) { |
332 | if (kproc) | | 340 | if (kproc) |