2018-06-04 03:11:21 -07:00
|
|
|
/*
|
2020-06-24 05:59:10 -07:00
|
|
|
* Copyright (c) 2018 Alastair Roy Poole <netstar@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2018-06-04 03:11:21 -07:00
|
|
|
*/
|
2020-07-11 05:09:38 -07:00
|
|
|
|
2018-06-04 03:11:21 -07:00
|
|
|
#define _DEFAULT_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <math.h>
|
2019-08-29 15:55:43 -07:00
|
|
|
#include <sys/stat.h>
|
2018-06-04 03:11:21 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
2020-06-16 09:29:51 -07:00
|
|
|
#if !defined(__linux__)
|
2020-04-14 10:24:27 -07:00
|
|
|
# include <sys/sysctl.h>
|
|
|
|
#endif
|
2018-06-04 03:11:21 -07:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
#define __MacOS__
|
|
|
|
# include <mach/mach.h>
|
|
|
|
# include <mach/vm_statistics.h>
|
|
|
|
# include <mach/mach_types.h>
|
|
|
|
# include <mach/mach_init.h>
|
|
|
|
# include <mach/mach_host.h>
|
|
|
|
# include <net/if_mib.h>
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 13:32:33 -07:00
|
|
|
#if defined(__OpenBSD__)
|
2019-05-25 07:34:33 -07:00
|
|
|
# include <sys/sched.h>
|
2018-06-04 03:11:21 -07:00
|
|
|
# include <sys/swap.h>
|
|
|
|
# include <sys/mount.h>
|
|
|
|
# include <sys/sensors.h>
|
|
|
|
# include <net/if_types.h>
|
|
|
|
# include <ifaddrs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
|
|
|
# include <net/if_mib.h>
|
|
|
|
# include <vm/vm_param.h>
|
2019-09-07 14:37:58 -07:00
|
|
|
# include <dev/acpica/acpiio.h>
|
2018-06-04 03:11:21 -07:00
|
|
|
#endif
|
|
|
|
|
2020-07-09 12:23:14 -07:00
|
|
|
#include "macros.h"
|
2020-07-10 03:50:49 -07:00
|
|
|
#include "machine.h"
|
|
|
|
#include "machine/machine.bogox"
|
|
|
|
#include "machine/cpu.bogox"
|
|
|
|
#include "machine/memory.bogox"
|
|
|
|
#include "machine/sensors.bogox"
|
|
|
|
#include "machine/network.bogox"
|
2018-06-04 03:11:21 -07:00
|
|
|
|
2018-06-10 06:09:44 -07:00
|
|
|
void
|
2020-06-17 15:08:44 -07:00
|
|
|
system_info_all_free(Sys_Info *info)
|
2018-06-04 03:11:21 -07:00
|
|
|
{
|
2020-06-16 12:12:55 -07:00
|
|
|
sensor_t *snsr;
|
|
|
|
int i;
|
2018-06-04 03:11:21 -07:00
|
|
|
|
2020-06-17 14:34:25 -07:00
|
|
|
for (i = 0; i < info->cpu_count; i++)
|
2020-07-11 05:09:38 -07:00
|
|
|
free(info->cores[i]);
|
2020-06-17 14:34:25 -07:00
|
|
|
free(info->cores);
|
2018-06-04 03:11:21 -07:00
|
|
|
|
2020-07-11 05:09:38 -07:00
|
|
|
for (i = 0; i < info->sensor_count; i++) {
|
2020-06-17 14:34:25 -07:00
|
|
|
snsr = info->sensors[i];
|
2020-06-18 07:36:39 -07:00
|
|
|
if (snsr->name)
|
|
|
|
free(snsr->name);
|
2020-10-05 04:18:26 -07:00
|
|
|
if (snsr->child_name)
|
|
|
|
free(snsr->child_name);
|
2020-06-16 12:12:55 -07:00
|
|
|
free(snsr);
|
|
|
|
}
|
2020-06-17 14:34:25 -07:00
|
|
|
if (info->sensors)
|
|
|
|
free(info->sensors);
|
2018-06-10 06:09:44 -07:00
|
|
|
|
2020-07-11 05:09:38 -07:00
|
|
|
for (i = 0; i < info->power.battery_count; i++) {
|
2020-06-18 04:17:11 -07:00
|
|
|
if (info->power.batteries[i]->name)
|
|
|
|
free(info->power.batteries[i]->name);
|
2020-06-18 04:54:45 -07:00
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
if (info->power.batteries[i]->mibs)
|
|
|
|
free(info->power.batteries[i]->mibs);
|
|
|
|
#endif
|
2020-06-17 14:34:25 -07:00
|
|
|
free(info->power.batteries[i]);
|
2020-06-16 12:12:55 -07:00
|
|
|
}
|
2020-06-17 14:34:25 -07:00
|
|
|
if (info->power.batteries)
|
|
|
|
free(info->power.batteries);
|
2018-06-10 06:09:44 -07:00
|
|
|
|
2020-06-17 14:34:25 -07:00
|
|
|
free(info);
|
2018-06-10 06:09:44 -07:00
|
|
|
}
|
|
|
|
|
2020-10-27 07:43:04 -07:00
|
|
|
Sys_Info *
|
|
|
|
system_info_basic_get(void)
|
|
|
|
{
|
|
|
|
Sys_Info *info = calloc(1, sizeof(Sys_Info));
|
|
|
|
if (!info) return NULL;
|
|
|
|
|
|
|
|
info->cores = system_cpu_usage_get(&info->cpu_count);
|
|
|
|
|
|
|
|
system_memory_usage_get(&info->memory);
|
2020-11-09 07:32:02 -08:00
|
|
|
system_power_state_get(&info->power);
|
2020-10-27 07:43:04 -07:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2020-05-14 06:43:44 -07:00
|
|
|
Sys_Info *
|
2020-06-17 15:08:44 -07:00
|
|
|
system_info_all_get(void)
|
2018-06-10 06:09:44 -07:00
|
|
|
{
|
2020-06-17 14:34:25 -07:00
|
|
|
Sys_Info *info;
|
2018-06-10 06:09:44 -07:00
|
|
|
|
2020-06-17 14:34:25 -07:00
|
|
|
info = calloc(1, sizeof(Sys_Info));
|
|
|
|
if (!info) return NULL;
|
2018-06-10 06:09:44 -07:00
|
|
|
|
2020-06-18 07:36:39 -07:00
|
|
|
info->cores = system_cpu_usage_get(&info->cpu_count);
|
2018-06-10 06:09:44 -07:00
|
|
|
|
2020-06-18 07:36:39 -07:00
|
|
|
system_memory_usage_get(&info->memory);
|
2018-06-10 09:06:34 -07:00
|
|
|
|
2020-06-18 07:36:39 -07:00
|
|
|
system_power_state_get(&info->power);
|
2018-06-10 06:09:44 -07:00
|
|
|
|
2020-10-03 03:35:36 -07:00
|
|
|
info->sensors = system_sensors_thermal_get(&info->sensor_count);
|
2020-04-14 10:24:27 -07:00
|
|
|
|
2020-06-17 14:34:25 -07:00
|
|
|
return info;
|
2018-06-10 06:09:44 -07:00
|
|
|
}
|
|
|
|
|