Debian Codegraph @

psutil/arch/osx/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 // System related functions. Original code was refactored and moved
8 // from psutil/_psutil_osx.c in 2023. This is the GIT blame before the move:
9 // https://github.com/giampaolo/psutil/blame/efd7ed3/psutil/_psutil_osx.c
10
11 #include <Python.h>
12 #include <sys/sysctl.h>
13
14 #include "../../arch/all/init.h"
15
16
17 PyObject *
18 psutil_boot_time(PyObject *self, PyObject *args) {
19 // fetch sysctl "kern.boottime"
20 int mib[2] = {CTL_KERN, KERN_BOOTTIME};
21 struct timeval result;
22 time_t boot_time = 0;
23
24 if (psutil_sysctl(mib, 2, &result, sizeof(result)) == -1)
25 return NULL;
26 boot_time = result.tv_sec;
27 return Py_BuildValue("d", (double)boot_time);
28 }