]>
git.proxmox.com Git - mirror_qemu.git/blob - bsd-user/freebsd/os-proc.c
2 * FreeBSD process related emulation code
4 * Copyright (c) 2013-15 Stacey D. Son
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
21 #include <sys/param.h>
22 #include <sys/queue.h>
23 #include <sys/sysctl.h>
25 #include <libprocstat.h>
30 * Get the filename for the given file descriptor.
31 * Note that this may return NULL (fail) if no longer cached in the kernel.
34 get_filename_from_fd(pid_t pid
, int fd
, char *filename
, size_t len
);
36 get_filename_from_fd(pid_t pid
, int fd
, char *filename
, size_t len
)
40 struct procstat
*procstat
= NULL
;
41 struct kinfo_proc
*kp
= NULL
;
42 struct filestat_list
*head
= NULL
;
45 procstat
= procstat_open_sysctl();
46 if (procstat
== NULL
) {
50 kp
= procstat_getprocs(procstat
, KERN_PROC_PID
, pid
, &cnt
);
55 head
= procstat_getfiles(procstat
, kp
, 0);
60 STAILQ_FOREACH(fst
, head
, next
) {
61 if (fd
== fst
->fs_fd
) {
62 if (fst
->fs_path
!= NULL
) {
63 (void)strlcpy(filename
, fst
->fs_path
, len
);
72 procstat_freefiles(procstat
, head
);
75 procstat_freeprocs(procstat
, kp
);
77 if (procstat
!= NULL
) {
78 procstat_close(procstat
);