Debian Codegraph @

psutil/arch/bsd/sys.c

raw
1 /*
2 * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include <Python.h>
8 #include <sys/sysctl.h>
9 #include <stdio.h>
10 #include <sys/param.h> // OS version
11 #if defined(PSUTIL_FREEBSD) || defined(PSUTIL_NETBSD)
12 #include <utmpx.h>
13 #elif defined(PSUTIL_OPENBSD)
14 #include <utmp.h>
15 #endif
16
17 #include "../../arch/all/init.h"
18
19
20 // Return a Python float indicating the system boot time expressed in
21 // seconds since the epoch.
22 PyObject *
23 psutil_boot_time(PyObject *self, PyObject *args) {
24 // fetch sysctl "kern.boottime"
25 static int request[2] = { CTL_KERN, KERN_BOOTTIME };
26 struct timeval boottime;
27
28 if (psutil_sysctl(request, 2, &boottime, sizeof(boottime)) != 0)
29 return NULL;
30 return Py_BuildValue("d", (double)boottime.tv_sec);
31 }