static int pakfire_daemon_submit_stats(sd_event_source* s, uint64_t usec, void* p) {
struct pakfire_daemon* daemon = p;
+ struct pakfire_sysinfo sysinfo = {};
struct pakfire_cpuinfo cpuinfo = {};
struct pakfire_cpustat cpustat = {};
struct pakfire_loadavg loadavg = {};
// Fetch the distro
const struct pakfire_distro* distro = pakfire_ctx_get_distro(daemon->ctx);
+ // Fetch system information
+ r = pakfire_sysinfo(&sysinfo);
+ if (r < 0) {
+ ERROR(daemon->ctx, "Failed to fetch system info: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
// Fetch CPU info
r = pakfire_cpuinfo(&cpuinfo);
if (r) {
if (!data)
goto ERROR;
+ // System Vendor
+ if (*sysinfo.vendor) {
+ r = pakfire_json_add_string(data, "sys_vendor", sysinfo.vendor);
+ if (r)
+ goto ERROR;
+ }
+
+ // System Model
+ if (*sysinfo.name) {
+ r = pakfire_json_add_string(data, "sys_name", sysinfo.name);
+ if (r)
+ goto ERROR;
+ }
+
// CPU Model
r = pakfire_json_add_string(data, "cpu_model", cpuinfo.model);
if (r)
#include <unistd.h>
#include <pakfire/os.h>
+#include <pakfire/path.h>
#include <pakfire/parse.h>
#include <pakfire/string.h>
+// System Info
+
+#define pakfire_read_dmi(buffer, key) \
+ __pakfire_read_dmi(buffer, sizeof(buffer), key)
+
+static int __pakfire_read_dmi(char* buffer, size_t length, const char* key) {
+ char path[PATH_MAX];
+ FILE* f = NULL;
+ int r;
+
+ // Make the path
+ r = pakfire_path_append(path, "/sys/class/dmi/id", key);
+ if (r < 0)
+ return r;
+
+ // Open the file
+ f = fopen(path, "r");
+ if (!f) {
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Read the file into the buffer
+ size_t bytes_read = fread(buffer, length - 1, 1, f);
+
+ // Always terminate the array
+ buffer[bytes_read] = '\0';
+
+ // Did we encounter an error reading the file?
+ if (ferror(f)) {
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Did we read the entire file?
+ if (!feof(f)) {
+ r = -ENOBUFS;
+ goto ERROR;
+ }
+
+ // Trim any whitespace
+ pakfire_string_strip(buffer);
+
+ERROR:
+ if (f)
+ fclose(f);
+
+ return r;
+}
+
+int pakfire_sysinfo(struct pakfire_sysinfo* sysinfo) {
+ int r;
+
+ // Check input
+ if (!sysinfo)
+ return -EINVAL;
+
+ // Read the system vendor
+ r = pakfire_read_dmi(sysinfo->vendor, "sys_vendor");
+ if (r < 0)
+ return r;
+
+ // Read the product name
+ r = pakfire_read_dmi(sysinfo->name, "product_name");
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
// CPU Info
#ifdef __aarch64__
#include <stdint.h>
#include <unistd.h>
-// CPU info
+#define OS_VENDOR_MAX 32
+#define OS_NAME_MAX 64
+
+// System Info
+
+struct pakfire_sysinfo {
+ char vendor[OS_VENDOR_MAX];
+ char name[OS_NAME_MAX];
+};
+
+int pakfire_sysinfo(struct pakfire_sysinfo* sysinfo);
-#define CPU_VENDOR_MAX 16
-#define CPU_MODEL_MAX 256
+// CPU info
struct pakfire_cpuinfo {
- char vendor[CPU_VENDOR_MAX];
- char model[CPU_MODEL_MAX];
+ char vendor[OS_VENDOR_MAX];
+ char model[OS_NAME_MAX];
unsigned int count;
};