Deleted Added
full compact
procstat_bin.c (233952) procstat_bin.c (250871)
1/*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: stable/9/usr.bin/procstat/procstat_bin.c 233952 2012-04-06 16:31:29Z trociny $
26 * $FreeBSD: stable/9/usr.bin/procstat/procstat_bin.c 250871 2013-05-21 19:05:27Z trociny $
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31#include <sys/user.h>
32
33#include <err.h>
34#include <errno.h>
35#include <libprocstat.h>
36#include <limits.h>
37#include <stdio.h>
38#include <string.h>
39
40#include "procstat.h"
41
42void
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31#include <sys/user.h>
32
33#include <err.h>
34#include <errno.h>
35#include <libprocstat.h>
36#include <limits.h>
37#include <stdio.h>
38#include <string.h>
39
40#include "procstat.h"
41
42void
43procstat_bin(struct kinfo_proc *kipp)
43procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp)
44{
44{
45 char pathname[PATH_MAX];
46 int error, osrel, name[4];
47 size_t len;
45 int osrel;
46 static char pathname[PATH_MAX];
48
49 if (!hflag)
50 printf("%5s %-16s %8s %s\n", "PID", "COMM", "OSREL", "PATH");
51
47
48 if (!hflag)
49 printf("%5s %-16s %8s %s\n", "PID", "COMM", "OSREL", "PATH");
50
52 name[0] = CTL_KERN;
53 name[1] = KERN_PROC;
54 name[2] = KERN_PROC_PATHNAME;
55 name[3] = kipp->ki_pid;
56
57 len = sizeof(pathname);
58 error = sysctl(name, 4, pathname, &len, NULL, 0);
59 if (error < 0 && errno != ESRCH) {
60 warn("sysctl: kern.proc.pathname: %d", kipp->ki_pid);
51 if (procstat_getpathname(prstat, kipp, pathname, sizeof(pathname)) != 0)
61 return;
52 return;
62 }
63 if (error < 0)
64 return;
65 if (len == 0 || strlen(pathname) == 0)
53 if (strlen(pathname) == 0)
66 strcpy(pathname, "-");
54 strcpy(pathname, "-");
67
68 name[2] = KERN_PROC_OSREL;
69
70 len = sizeof(osrel);
71 error = sysctl(name, 4, &osrel, &len, NULL, 0);
72 if (error < 0 && errno != ESRCH) {
73 warn("sysctl: kern.proc.osrel: %d", kipp->ki_pid);
55 if (procstat_getosrel(prstat, kipp, &osrel) != 0)
74 return;
56 return;
75 }
76 if (error < 0)
77 return;
78
79 printf("%5d ", kipp->ki_pid);
80 printf("%-16s ", kipp->ki_comm);
81 printf("%8d ", osrel);
82 printf("%s\n", pathname);
83}
57
58 printf("%5d ", kipp->ki_pid);
59 printf("%-16s ", kipp->ki_comm);
60 printf("%8d ", osrel);
61 printf("%s\n", pathname);
62}