Deleted Added
sdiff udiff text old ( 181905 ) new ( 185548 )
full compact
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 $
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
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;
137 int error, name[4];
138 unsigned int i;
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
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");
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 ---