]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Read more system information and sent it to the build service
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jan 2025 15:38:29 +0000 (15:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jan 2025 15:38:29 +0000 (15:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c
src/pakfire/os.c
src/pakfire/os.h

index d57affef1e344c45fae4af9c4936354c5fadbe8b..fe8a61a53cfedaad9fb453dd183fcb0670ef4503 100644 (file)
@@ -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)
index e80fe184516ecfd7ad6330b3d44d0161b09ef628..85856dcb207f537b01a6f44617b5da869a15bd05 100644 (file)
 #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__
index 522fb901759d7fd086eed1798b98c545cb9fe2d2..1836ebdf9721a9500fa9e7116130cf944596cd0d 100644 (file)
 #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;
 };