From: Michael Tremer Date: Sat, 25 Jan 2025 15:38:29 +0000 (+0000) Subject: daemon: Read more system information and sent it to the build service X-Git-Tag: 0.9.30~380 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecdf6b2d1782a86480ead106031177dd79f8c703;p=pakfire.git daemon: Read more system information and sent it to the build service Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index d57affef..fe8a61a5 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -130,6 +130,7 @@ static int pakfire_daemon_terminate(sd_event_source* source, 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 = {}; @@ -162,6 +163,13 @@ static int pakfire_daemon_submit_stats(sd_event_source* s, uint64_t usec, void* // 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) { @@ -203,6 +211,20 @@ static int pakfire_daemon_submit_stats(sd_event_source* s, uint64_t usec, void* 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) diff --git a/src/pakfire/os.c b/src/pakfire/os.c index e80fe184..85856dcb 100644 --- a/src/pakfire/os.c +++ b/src/pakfire/os.c @@ -25,9 +25,80 @@ #include #include +#include #include #include +// 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__ diff --git a/src/pakfire/os.h b/src/pakfire/os.h index 522fb901..1836ebdf 100644 --- a/src/pakfire/os.h +++ b/src/pakfire/os.h @@ -24,14 +24,23 @@ #include #include -// 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; };