Deleted Added
full compact
libprocstat.c (249674) libprocstat.c (249676)
1/*-
2 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/lib/libprocstat/libprocstat.c 249674 2013-04-20 07:59:44Z trociny $");
36__FBSDID("$FreeBSD: head/lib/libprocstat/libprocstat.c 249676 2013-04-20 08:02:43Z trociny $");
37
38#include <sys/param.h>
39#include <sys/time.h>
40#include <sys/resourcevar.h>
41#include <sys/proc.h>
42#include <sys/user.h>
43#include <sys/stat.h>
44#include <sys/vnode.h>

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

131static int to_filestat_flags(int flags);
132static int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst,
133 struct vnstat *vn, char *errbuf);
134static int procstat_get_vnode_info_sysctl(struct filestat *fst,
135 struct vnstat *vn, char *errbuf);
136static gid_t *procstat_getgroups_core(struct procstat_core *core,
137 unsigned int *count);
138static gid_t *procstat_getgroups_sysctl(pid_t pid, unsigned int *count);
37
38#include <sys/param.h>
39#include <sys/time.h>
40#include <sys/resourcevar.h>
41#include <sys/proc.h>
42#include <sys/user.h>
43#include <sys/stat.h>
44#include <sys/vnode.h>

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

131static int to_filestat_flags(int flags);
132static int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst,
133 struct vnstat *vn, char *errbuf);
134static int procstat_get_vnode_info_sysctl(struct filestat *fst,
135 struct vnstat *vn, char *errbuf);
136static gid_t *procstat_getgroups_core(struct procstat_core *core,
137 unsigned int *count);
138static gid_t *procstat_getgroups_sysctl(pid_t pid, unsigned int *count);
139static int procstat_getpathname_core(struct procstat_core *core,
140 char *pathname, size_t maxlen);
141static int procstat_getpathname_sysctl(pid_t pid, char *pathname,
142 size_t maxlen);
139static int procstat_getrlimit_core(struct procstat_core *core, int which,
140 struct rlimit* rlimit);
141static int procstat_getrlimit_sysctl(pid_t pid, int which,
142 struct rlimit* rlimit);
143static int procstat_getumask_core(struct procstat_core *core,
144 unsigned short *maskp);
145static int procstat_getumask_sysctl(pid_t pid, unsigned short *maskp);
146static int vntype2psfsttype(int type);

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

1775 return (procstat_getrlimit_sysctl(kp->ki_pid, which, rlimit));
1776 case PROCSTAT_CORE:
1777 return (procstat_getrlimit_core(procstat->core, which, rlimit));
1778 default:
1779 warnx("unknown access method: %d", procstat->type);
1780 return (-1);
1781 }
1782}
143static int procstat_getrlimit_core(struct procstat_core *core, int which,
144 struct rlimit* rlimit);
145static int procstat_getrlimit_sysctl(pid_t pid, int which,
146 struct rlimit* rlimit);
147static int procstat_getumask_core(struct procstat_core *core,
148 unsigned short *maskp);
149static int procstat_getumask_sysctl(pid_t pid, unsigned short *maskp);
150static int vntype2psfsttype(int type);

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

1779 return (procstat_getrlimit_sysctl(kp->ki_pid, which, rlimit));
1780 case PROCSTAT_CORE:
1781 return (procstat_getrlimit_core(procstat->core, which, rlimit));
1782 default:
1783 warnx("unknown access method: %d", procstat->type);
1784 return (-1);
1785 }
1786}
1787
1788static int
1789procstat_getpathname_sysctl(pid_t pid, char *pathname, size_t maxlen)
1790{
1791 int error, name[4];
1792 size_t len;
1793
1794 name[0] = CTL_KERN;
1795 name[1] = KERN_PROC;
1796 name[2] = KERN_PROC_PATHNAME;
1797 name[3] = pid;
1798 len = maxlen;
1799 error = sysctl(name, 4, pathname, &len, NULL, 0);
1800 if (error != 0 && errno != ESRCH)
1801 warn("sysctl: kern.proc.pathname: %d", pid);
1802 if (len == 0)
1803 pathname[0] = '\0';
1804 return (error);
1805}
1806
1807static int
1808procstat_getpathname_core(struct procstat_core *core, char *pathname,
1809 size_t maxlen)
1810{
1811 struct kinfo_file *files;
1812 int cnt, i, result;
1813
1814 files = kinfo_getfile_core(core, &cnt);
1815 if (files == NULL)
1816 return (-1);
1817 result = -1;
1818 for (i = 0; i < cnt; i++) {
1819 if (files[i].kf_fd != KF_FD_TYPE_TEXT)
1820 continue;
1821 strncpy(pathname, files[i].kf_path, maxlen);
1822 result = 0;
1823 break;
1824 }
1825 free(files);
1826 return (result);
1827}
1828
1829int
1830procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp,
1831 char *pathname, size_t maxlen)
1832{
1833 switch(procstat->type) {
1834 case PROCSTAT_KVM:
1835 warnx("kvm method is not supported");
1836 return (-1);
1837 case PROCSTAT_SYSCTL:
1838 return (procstat_getpathname_sysctl(kp->ki_pid, pathname,
1839 maxlen));
1840 case PROCSTAT_CORE:
1841 return (procstat_getpathname_core(procstat->core, pathname,
1842 maxlen));
1843 default:
1844 warnx("unknown access method: %d", procstat->type);
1845 return (-1);
1846 }
1847}