libprocstat.c (249676) | libprocstat.c (249677) |
---|---|
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 249676 2013-04-20 08:02:43Z trociny $"); | 36__FBSDID("$FreeBSD: head/lib/libprocstat/libprocstat.c 249677 2013-04-20 08:03:56Z 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> --- 1795 unchanged lines hidden (view full) --- 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} | 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> --- 1795 unchanged lines hidden (view full) --- 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} |
1848 1849static int 1850procstat_getosrel_sysctl(pid_t pid, int *osrelp) 1851{ 1852 int error, name[4]; 1853 size_t len; 1854 1855 name[0] = CTL_KERN; 1856 name[1] = KERN_PROC; 1857 name[2] = KERN_PROC_OSREL; 1858 name[3] = pid; 1859 len = sizeof(*osrelp); 1860 error = sysctl(name, 4, osrelp, &len, NULL, 0); 1861 if (error != 0 && errno != ESRCH) 1862 warn("sysctl: kern.proc.osrel: %d", pid); 1863 return (error); 1864} 1865 1866static int 1867procstat_getosrel_core(struct procstat_core *core, int *osrelp) 1868{ 1869 size_t len; 1870 int *buf; 1871 1872 buf = procstat_core_get(core, PSC_TYPE_OSREL, NULL, &len); 1873 if (buf == NULL) 1874 return (-1); 1875 if (len < sizeof(*osrelp)) { 1876 free(buf); 1877 return (-1); 1878 } 1879 *osrelp = *buf; 1880 free(buf); 1881 return (0); 1882} 1883 1884int 1885procstat_getosrel(struct procstat *procstat, struct kinfo_proc *kp, int *osrelp) 1886{ 1887 switch(procstat->type) { 1888 case PROCSTAT_KVM: 1889 warnx("kvm method is not supported"); 1890 return (-1); 1891 case PROCSTAT_SYSCTL: 1892 return (procstat_getosrel_sysctl(kp->ki_pid, osrelp)); 1893 case PROCSTAT_CORE: 1894 return (procstat_getosrel_core(procstat->core, osrelp)); 1895 default: 1896 warnx("unknown access method: %d", procstat->type); 1897 return (-1); 1898 } 1899} |
|