Deleted Added
full compact
procstat_files.c (181905) procstat_files.c (185548)
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: head/usr.bin/procstat/procstat_files.c 181905 2008-08-20 08:31:58Z ed $
26 * $FreeBSD: head/usr.bin/procstat/procstat_files.c 185548 2008-12-02 06:50:26Z peter $
27 */
28
29#include <sys/types.h>
30#include <sys/socket.h>
31#include <sys/sysctl.h>
32#include <sys/un.h>
33#include <sys/user.h>
34
35#include <netinet/in.h>
36
37#include <arpa/inet.h>
38
39#include <err.h>
40#include <inttypes.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
27 */
28
29#include <sys/types.h>
30#include <sys/socket.h>
31#include <sys/sysctl.h>
32#include <sys/un.h>
33#include <sys/user.h>
34
35#include <netinet/in.h>
36
37#include <arpa/inet.h>
38
39#include <err.h>
40#include <inttypes.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <libutil.h>
44
45#include "procstat.h"
46
47static const char *
48protocol_to_string(int domain, int type, int protocol)
49{
50
51 switch (domain) {

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

129 addr_to_string(ss, addr, sizeof(addr));
130 printf("%s", addr);
131}
132
133void
134procstat_files(pid_t pid, struct kinfo_proc *kipp)
135{
136 struct kinfo_file *freep, *kif;
45
46#include "procstat.h"
47
48static const char *
49protocol_to_string(int domain, int type, int protocol)
50{
51
52 switch (domain) {

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

130 addr_to_string(ss, addr, sizeof(addr));
131 printf("%s", addr);
132}
133
134void
135procstat_files(pid_t pid, struct kinfo_proc *kipp)
136{
137 struct kinfo_file *freep, *kif;
137 int error, name[4];
138 unsigned int i;
138 int i, cnt;
139 const char *str;
139 const char *str;
140 size_t len;
141
142 if (!hflag)
143 printf("%5s %-16s %4s %1s %1s %-8s %3s %7s %-3s %-12s\n",
144 "PID", "COMM", "FD", "T", "V", "FLAGS", "REF", "OFFSET",
145 "PRO", "NAME");
146
140
141 if (!hflag)
142 printf("%5s %-16s %4s %1s %1s %-8s %3s %7s %-3s %-12s\n",
143 "PID", "COMM", "FD", "T", "V", "FLAGS", "REF", "OFFSET",
144 "PRO", "NAME");
145
147 name[0] = CTL_KERN;
148 name[1] = KERN_PROC;
149 name[2] = KERN_PROC_FILEDESC;
150 name[3] = pid;
151
152 error = sysctl(name, 4, NULL, &len, NULL, 0);
153 if (error < 0 && errno != ESRCH && errno != EPERM) {
154 warn("sysctl: kern.proc.filedesc: %d", pid);
155 return;
156 }
157 if (error < 0)
158 return;
159
160 freep = kif = malloc(len);
161 if (kif == NULL)
162 err(-1, "malloc");
163
164 if (sysctl(name, 4, kif, &len, NULL, 0) < 0) {
165 warn("sysctl: kern.proc.filedesc %d", pid);
166 free(freep);
167 return;
168 }
169
170 for (i = 0; i < len / sizeof(*kif); i++, kif++) {
171 if (kif->kf_structsize != sizeof(*kif))
172 errx(-1, "kinfo_file mismatch");
146 freep = kinfo_getfile(pid, &cnt);
147 for (i = 0; i < cnt; i++) {
148 kif = &freep[i];
149
173 printf("%5d ", pid);
174 printf("%-16s ", kipp->ki_comm);
175 switch (kif->kf_fd) {
176 case KF_FD_TYPE_CWD:
177 printf(" cwd ");
178 break;
179
180 case KF_FD_TYPE_ROOT:

--- 162 unchanged lines hidden ---
150 printf("%5d ", pid);
151 printf("%-16s ", kipp->ki_comm);
152 switch (kif->kf_fd) {
153 case KF_FD_TYPE_CWD:
154 printf(" cwd ");
155 break;
156
157 case KF_FD_TYPE_ROOT:

--- 162 unchanged lines hidden ---