Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

System Information (0.8.5), step 1: the collector (src/sysreport: machine, CPU, memory, GPUs, displays from the EDID, storage, PCI and USB with pci.ids/usb.ids names, network by kind and driver, audio, Bluetooth, power, thermal, Raspberry Pi, kernel features) and lordos-sysreport report [--json|--markdown]; no field can hold a serial, UUID, MAC, address, host or user name, checked over five fake machines full of them

Federico Pereirafd29a0c58083
diff --git a/docs/BENCHMARK.md b/docs/BENCHMARK.md
index 85926fc..8f4d1d6 100644
--- a/docs/BENCHMARK.md
+++ b/docs/BENCHMARK.md
@@ -1,6 +1,6 @@
# System Information, LordBench and hardware reports (proposal)
-**Status: design proposal, nothing here is built yet.** It plans three releases and a later stage:
+**Status: design proposal; the 0.8.5 collector and `lordos-sysreport` are built (below), the rest is not.** It plans three releases and a later stage:
| Release | What |
|---|---|
@@ -237,6 +237,15 @@ before installing.
## Work plan for 0.8.5
+**Built (2026-10-26):** `server/src/sysreport/` (the collector, `ids.c` for `pci.ids`/`usb.ids`, the JSON
+and Markdown output), `lordos-sysreport report [--json | --markdown]` in `/usr/bin` (package `lordos`,
+which recommends `pci.ids` and `usb.ids`), and `tests/sysreport_test.c`: five fake machines (AMD desktop,
+Intel laptop, Nvidia desktop, Raspberry Pi 5, VM) full of serials, UUIDs, MAC addresses, a host name, a
+user name, monitor serials and a MAC inside an interface name, none of which may reach a report
+(`build/sysreport-test fixture <dir> <kind>` writes one for `--root`). Checked on VM 116 against the real
+machine. Not yet: the GPU's EGL, composition and scanout layers (they come from the running
+`lord-server`, with `lord.sysinfo`), `hw-memory-modules`, the app.
+
1. `server/src/sysreport/`: collector, GPU layers, `pci.ids`/EDID readers, fake-sysfs fixtures
(AMD desktop, Intel laptop, Nvidia desktop, Raspberry Pi 5, VM), the anonymization test,
`hw-memory-modules`, `lordos-sysreport report`.
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 7bada25..9913bf0 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -590,8 +590,10 @@ Details in `MAIL.md`. Tested on VM 123 against local Dovecot, Postfix and Radica
this machine, each marked *configured* or *effective* (a probe app tries what must fail). JSON
and Markdown reports with preview, built from an allow-list of fields. The logic lives in
`server/src/sysreport/`, shared by the app, the `lordos-sysreport` command and tests.
- - [ ] collector, GPU layers, `pci.ids`/EDID readers, fake-sysfs fixtures, anonymization test,
- the read-only `hw-memory-modules` admin action, `lordos-sysreport`;
+ - [x] collector, `pci.ids`/`usb.ids`/EDID readers, fake-sysfs fixtures, anonymization test,
+ `lordos-sysreport report` (2026-10-26);
+ - [ ] the GPU's live layers (EGL, composition, scanout) through `lord.sysinfo`, the read-only
+ `hw-memory-modules` admin action;
- [ ] Overview, Hardware and Compatibility tabs (en, es, pt, right to left);
- [ ] Checks, configured and effective, with the probe app and a signed `checks.json`;
- [ ] reports; first real reports from the Pi 5 with a monitor and the RX 580 PC.
diff --git a/docs/VM-SETUP.md b/docs/VM-SETUP.md
index 9f3e24d..daddbb5 100644
--- a/docs/VM-SETUP.md
+++ b/docs/VM-SETUP.md
@@ -1652,3 +1652,12 @@ was not tested here). Nothing was installed with apt.
scripts and backups deleted, `lordos` restarted to the login screen. The traffic history
(`~/.local/state/lordos/net-history.bin`) keeps the test minutes (app ids and byte counts only).
No Proxmox setting was touched.
+
+## Step 47 — 0.8.5: System Information's collector (VM 116 `lordos-gpu`, October 26)
+
+See `BENCHMARK.md` ("0.8.5 — System Information"). Built in `~/LordOS-085fs` (`make -C server
+build/lordos-sysreport build/sysreport-test`) and run from there as `lord`; nothing was installed
+over `/usr/local/lib/lordos`.
+
+- **Installed:** `usb.ids` (Debian, architecture `all`: the USB vendor and product names, read by
+ `lordos-sysreport`; `pci.ids` was already installed). The package recommends both.
diff --git a/server/mk/sysreport.mk b/server/mk/sysreport.mk
new file mode 100644
index 0000000..15d60cd
--- /dev/null
+++ b/server/mk/sysreport.mk
@@ -0,0 +1,15 @@
+# System Information (0.8.5, src/sysreport, docs/BENCHMARK.md): the collector, shared by the
+# `lordos-sysreport` command and (later) lord.sysinfo. Read-only, no root, libc only.
+SYSREPORT_SRC := src/sysreport/sysreport.c src/sysreport/sysreport_out.c src/sysreport/ids.c src/hw/edid.c src/hw/jbuf.c src/sec/json.c
+SYSREPORT_HDR := $(wildcard src/sysreport/*.h) src/hw/edid.h src/hw/jbuf.h src/sec/json.h
+all: build/lordos-sysreport
+build/lordos-sysreport: src/sysreport/cli.c $(SYSREPORT_SRC) $(SYSREPORT_HDR) build/gen/lord_version.h
+ @mkdir -p build
+ $(CC) $(CPPFLAGS) -Ibuild/gen $(CFLAGS) $(WARN) -std=c11 -o $@ src/sysreport/cli.c $(SYSREPORT_SRC)
+# five fake machines full of serials, UUIDs, MACs and names that must not reach a report;
+# `build/sysreport-test fixture <dir> amd|intel|nvidia|rpi5|vm` writes one for `--root`
+test: build/sysreport-test
+build/sysreport-test: tests/sysreport_test.c $(SYSREPORT_SRC) $(SYSREPORT_HDR)
+ @mkdir -p build
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/sysreport_test.c $(SYSREPORT_SRC)
+ ./$@ || { rm -f $@; exit 1; }
diff --git a/server/src/sysreport/cli.c b/server/src/sysreport/cli.c
new file mode 100644
index 0000000..d632540
--- /dev/null
+++ b/server/src/sysreport/cli.c
@@ -0,0 +1,44 @@
+/* cli.c — `lordos-sysreport`, System Information's command (see docs/BENCHMARK.md). An ordinary
+ * user command: lord-server never runs it. It prints the same report as the app, so one can be made
+ * on a machine without a session (a headless Pi, a VM over SSH, CI).
+ *
+ * lordos-sysreport report [--json | --markdown]
+ *
+ * --root <dir> reads a fake tree instead of this machine (tests and fixtures only). */
+#include "sysreport.h"
+#include "lord_version.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int usage(void) {
+ fprintf(stderr, "usage: lordos-sysreport report [--json | --markdown]\n"
+ " Prints this computer's hardware and what the system made of it (no serial numbers,\n"
+ " addresses, host or user names). Markdown by default.\n");
+ return 2;
+}
+
+int main(int argc, char **argv) {
+ const char *root = "", *mode = "markdown";
+ int report = 0;
+ for (int i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "report")) report = 1;
+ else if (!strcmp(argv[i], "--json")) mode = "json";
+ else if (!strcmp(argv[i], "--markdown")) mode = "markdown";
+ else if (!strcmp(argv[i], "--root") && i + 1 < argc) root = argv[++i];
+ else return usage();
+ }
+ if (!report) return usage();
+
+ SysReport *r = malloc(sizeof *r);
+ if (!r) return 1;
+ sysreport_collect(r, root, NULL, NULL);
+ snprintf(r->sw.lordos, sizeof r->sw.lordos, "%s%s%s", LORD_VERSION, LORD_CHANNEL[0] ? "-" : "", LORD_CHANNEL);
+ char *out = !strcmp(mode, "json") ? sysreport_json(r) : sysreport_markdown(r);
+ free(r);
+ if (!out) { fprintf(stderr, "lordos-sysreport: out of memory\n"); return 1; }
+ fputs(out, stdout);
+ free(out);
+ return ferror(stdout) ? 1 : 0;
+}
diff --git a/server/src/sysreport/ids.c b/server/src/sysreport/ids.c
new file mode 100644
index 0000000..5037cd5
--- /dev/null
+++ b/server/src/sysreport/ids.c
@@ -0,0 +1,114 @@
+/* ids.c — pci.ids / usb.ids lookups (see ids.h). The format: a vendor line "vvvv Name" at the start
+ * of a line, its devices on the lines below as "\tdddd Name" (subsystems "\t\t…" are skipped), and,
+ * in pci.ids, classes as "C cc Name" with subclasses "\tss Name". Comments start with '#'. */
+#include "ids.h"
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#define IDS_MAX (8u << 20)
+
+int ids_open(IdsDb *db, const char *path) {
+ db->text = NULL;
+ db->len = 0;
+ int fd = open(path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0) return -1;
+ struct stat st;
+ if (fstat(fd, &st) || !S_ISREG(st.st_mode) || st.st_size <= 0 || (unsigned long long)st.st_size > IDS_MAX) { close(fd); return -1; }
+ char *p = malloc((size_t)st.st_size + 1);
+ size_t got = 0;
+ while (p && got < (size_t)st.st_size) {
+ ssize_t n = read(fd, p + got, (size_t)st.st_size - got);
+ if (n <= 0) break;
+ got += (size_t)n;
+ }
+ close(fd);
+ if (!p || !got) { free(p); return -1; }
+ p[got] = 0;
+ db->text = p;
+ db->len = got;
+ return 0;
+}
+
+void ids_close(IdsDb *db) { free(db->text); db->text = NULL; db->len = 0; }
+
+/* The name after "<hex> " up to the end of the line, printable ASCII only. */
+static void copy_name(const char *s, const char *end, char *out, size_t size) {
+ if (!out || !size) return;
+ while (s < end && *s == ' ') s++;
+ size_t o = 0;
+ for (; s < end && *s != '\n' && o + 1 < size; s++) out[o++] = (*s >= 0x20 && *s < 0x7f) ? *s : '?';
+ while (o && out[o - 1] == ' ') o--;
+ out[o] = 0;
+}
+
+/* The line [s, e) starts (after `tabs` tabs) with the hex id followed by a space. */
+static int id_line(const char *s, const char *e, int tabs, const char *id, size_t idlen, const char **name) {
+ for (int i = 0; i < tabs; i++) { if (s >= e || *s != '\t') return 0; s++; }
+ if (s < e && *s == '\t') return 0;
+ if ((size_t)(e - s) <= idlen) return 0;
+ for (size_t i = 0; i < idlen; i++) if (tolower((unsigned char)s[i]) != tolower((unsigned char)id[i])) return 0;
+ if (s[idlen] != ' ') return 0;
+ *name = s + idlen;
+ return 1;
+}
+
+static size_t hexlen(const char *s) {
+ size_t n = 0;
+ while (s && isxdigit((unsigned char)s[n])) n++;
+ return s && !s[n] ? n : 0;
+}
+
+void ids_lookup(const IdsDb *db, const char *vendor, const char *device, char *vname, size_t vsize, char *dname, size_t dsize) {
+ if (vname && vsize) vname[0] = 0;
+ if (dname && dsize) dname[0] = 0;
+ size_t vl = hexlen(vendor), dl = hexlen(device);
+ if (!db->text || vl != 4) return;
+ const char *p = db->text, *end = db->text + db->len;
+ int in_vendor = 0;
+ while (p < end) {
+ const char *e = memchr(p, '\n', (size_t)(end - p));
+ if (!e) e = end;
+ const char *name;
+ if (*p != '#' && *p != '\t' && p < e) {
+ if (in_vendor) return; /* past the vendor's devices */
+ if (*p == 'C' && p[1] == ' ') return; /* the class section follows the vendors */
+ if (id_line(p, e, 0, vendor, 4, &name)) {
+ copy_name(name, e, vname, vsize);
+ if (dl != 4) return;
+ in_vendor = 1;
+ }
+ } else if (in_vendor && id_line(p, e, 1, device, 4, &name)) {
+ copy_name(name, e, dname, dsize);
+ return;
+ }
+ p = e + 1;
+ }
+}
+
+void ids_pci_class(const IdsDb *db, const char *cls, char *cname, size_t csize, char *sname, size_t ssize) {
+ if (cname && csize) cname[0] = 0;
+ if (sname && ssize) sname[0] = 0;
+ if (!db->text || hexlen(cls) < 4) return;
+ const char *p = db->text, *end = db->text + db->len;
+ int in_class = 0;
+ while (p < end) {
+ const char *e = memchr(p, '\n', (size_t)(end - p));
+ if (!e) e = end;
+ const char *name;
+ if (p + 2 < e && p[0] == 'C' && p[1] == ' ') {
+ if (in_class) return;
+ if (id_line(p + 2, e, 0, cls, 2, &name)) { copy_name(name, e, cname, csize); in_class = 1; }
+ } else if (in_class && *p != '#' && *p != '\t' && p < e) {
+ return;
+ } else if (in_class && id_line(p, e, 1, cls + 2, 2, &name)) {
+ copy_name(name, e, sname, ssize);
+ return;
+ }
+ p = e + 1;
+ }
+}
diff --git a/server/src/sysreport/ids.h b/server/src/sysreport/ids.h
new file mode 100644
index 0000000..f37aa0d
--- /dev/null
+++ b/server/src/sysreport/ids.h
@@ -0,0 +1,22 @@
+/* ids.h — vendor, device and class names from the hwdata lists (`pci.ids` and `usb.ids`, the Debian
+ * packages of the same names, /usr/share/misc). The file is read once into memory (at most 8 MB) and
+ * searched in place; names are copied out as printable ASCII. A missing file only means no names. */
+#ifndef LORD_SYSREPORT_IDS_H
+#define LORD_SYSREPORT_IDS_H
+
+#include <stddef.h>
+
+typedef struct { char *text; size_t len; } IdsDb;
+
+int ids_open(IdsDb *db, const char *path); /* 0, or -1 (db stays empty and lookups find nothing) */
+void ids_close(IdsDb *db);
+
+/* vendor and device are lowercase or uppercase hex ("10de", "2684"); device may be NULL for the
+ * vendor only. Each out gets the name, or "" when it isn't listed. */
+void ids_lookup(const IdsDb *db, const char *vendor, const char *device, char *vname, size_t vsize, char *dname, size_t dsize);
+
+/* PCI class: "030000" → class "Display controller", subclass "VGA compatible controller"
+ * (pci.ids "C" lines). Either out may be NULL. */
+void ids_pci_class(const IdsDb *db, const char *cls, char *cname, size_t csize, char *sname, size_t ssize);
+
+#endif
diff --git a/server/src/sysreport/sysreport.c b/server/src/sysreport/sysreport.c
new file mode 100644
index 0000000..6194094
--- /dev/null
+++ b/server/src/sysreport/sysreport.c
@@ -0,0 +1,811 @@
+/* sysreport.c — System Information's collector (see sysreport.h). Every read is a small file opened
+ * with O_NOFOLLOW where it's a leaf, cut to its first line and to printable ASCII; directories are
+ * listed in name order so two runs on one machine give the same report. */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include "sysreport.h"
+#include "ids.h"
+#include "../hw/edid.h"
+
+#include <ctype.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/utsname.h>
+#include <time.h>
+#include <unistd.h>
+
+/* ---- reading ---- */
+
+/* A whole small file (at most max bytes, NUL-terminated); NULL when missing. *len gets its size. */
+static char *read_file(const char *path, size_t max, size_t *len) {
+ int fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
+ if (fd < 0) return NULL;
+ char *p = malloc(max + 1);
+ size_t got = 0;
+ while (p && got < max) {
+ ssize_t n = read(fd, p + got, max - got);
+ if (n <= 0) break;
+ got += (size_t)n;
+ }
+ close(fd);
+ if (!p) return NULL;
+ p[got] = 0;
+ if (len) *len = got;
+ return p;
+}
+
+/* The first line of a sysfs/proc attribute, trimmed, printable ASCII only. "" when missing. */
+static void read_attr(const char *path, char *out, size_t size) {
+ out[0] = 0;
+ int fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
+ if (fd < 0) return;
+ char buf[512];
+ ssize_t n = read(fd, buf, sizeof buf - 1);
+ close(fd);
+ if (n <= 0) return;
+ buf[n] = 0;
+ ssize_t i = 0;
+ while (i < n && (buf[i] == ' ' || buf[i] == '\t')) i++;
+ size_t o = 0;
+ for (; i < n && buf[i] && buf[i] != '\n' && o + 1 < size; i++)
+ out[o++] = (buf[i] >= 0x20 && buf[i] < 0x7f) ? buf[i] : '?';
+ while (o && (out[o - 1] == ' ' || out[o - 1] == '\t')) o--;
+ out[o] = 0;
+}
+
+static void attr(const char *root, const char *dir, const char *name, char *out, size_t size) {
+ char p[1024];
+ snprintf(p, sizeof p, "%s%s/%s", root, dir, name);
+ read_attr(p, out, size);
+}
+
+static long long attr_num(const char *root, const char *dir, const char *name, long long def) {
+ char v[64];
+ attr(root, dir, name, v, sizeof v);
+ if (!v[0]) return def;
+ char *end;
+ long long x = strtoll(v, &end, 0);
+ return end == v ? def : x;
+}
+
+static int exists(const char *root, const char *path) {
+ char p[1024];
+ snprintf(p, sizeof p, "%s%s", root, path);
+ struct stat st;
+ return lstat(p, &st) == 0;
+}
+
+/* A hex ID attribute ("0x10de" or "10de") as `digits` lowercase hex digits; "" if not hex. */
+static void hex_attr(const char *root, const char *dir, const char *name, int digits, char *out) {
+ char v[32];
+ attr(root, dir, name, v, sizeof v);
+ const char *s = v;
+ if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) s += 2;
+ size_t n = strlen(s);
+ out[0] = 0;
+ if (!n || n > (size_t)digits) return;
+ for (size_t i = 0; i < n; i++) if (!isxdigit((unsigned char)s[i])) return;
+ size_t pad = (size_t)digits - n;
+ for (size_t i = 0; i < pad; i++) out[i] = '0';
+ for (size_t i = 0; i < n; i++) out[pad + i] = (char)tolower((unsigned char)s[i]);
+ out[digits] = 0;
+}
+
+/* The last component of a link (a device's "driver", "subsystem"), [A-Za-z0-9_-] only. */
+static void link_base(const char *root, const char *dir, const char *name, char *out, size_t size) {
+ char p[1024], l[512];
+ snprintf(p, sizeof p, "%s%s/%s", root, dir, name);
+ ssize_t n = readlink(p, l, sizeof l - 1);
+ out[0] = 0;
+ if (n <= 0) return;
+ l[n] = 0;
+ const char *b = strrchr(l, '/');
+ b = b ? b + 1 : l;
+ size_t o = 0;
+ for (; *b && o + 1 < size; b++) if (isalnum((unsigned char)*b) || *b == '_' || *b == '-') out[o++] = *b;
+ out[o] = 0;
+}
+
+/* The names in <root><dir> (no dot entries), sorted; free with free_list. */
+static int list_dir(const char *root, const char *dir, char ***names) {
+ char p[1024];
+ snprintf(p, sizeof p, "%s%s", root, dir);
+ *names = NULL;
+ DIR *d = opendir(p);
+ if (!d) return 0;
+ int n = 0, cap = 0;
+ struct dirent *e;
+ while ((e = readdir(d)) && n < 4096) {
+ if (e->d_name[0] == '.') continue;
+ if (n == cap) {
+ cap = cap ? cap * 2 : 32;
+ char **nn = realloc(*names, (size_t)cap * sizeof *nn);
+ if (!nn) break;
+ *names = nn;
+ }
+ if (!((*names)[n] = strdup(e->d_name))) break;
+ n++;
+ }
+ closedir(d);
+ /* natural order: "card2" before "card10" */
+ for (int i = 1; i < n; i++)
+ for (int j = i; j > 0; j--) {
+ const char *a = (*names)[j - 1], *b = (*names)[j];
+ size_t la = strcspn(a, "0123456789"), lb = strcspn(b, "0123456789");
+ int c = (la == lb && !strncmp(a, b, la) && isdigit((unsigned char)a[la]) && isdigit((unsigned char)b[lb]))
+ ? (atoll(a + la) > atoll(b + lb) ? 1 : atoll(a + la) < atoll(b + lb) ? -1 : strcmp(a, b))
+ : strcmp(a, b);
+ if (c <= 0) break;
+ char *t = (*names)[j - 1]; (*names)[j - 1] = (*names)[j]; (*names)[j] = t;
+ }
+ return n;
+}
+
+static void free_list(char **names, int n) {
+ for (int i = 0; i < n; i++) free(names[i]);
+ free(names);
+}
+
+/* "key<spaces>: value" in /proc/cpuinfo-style text (the first one); "" when missing. */
+static void field(const char *txt, const char *key, char *out, size_t size) {
+ out[0] = 0;
+ size_t kl = strlen(key);
+ for (const char *p = txt; p && *p; p = strchr(p, '\n') ? strchr(p, '\n') + 1 : NULL) {
+ if (strncmp(p, key, kl) || (p[kl] != ' ' && p[kl] != '\t' && p[kl] != ':')) continue;
+ const char *v = strchr(p, ':');
+ const char *nl = strchr(p, '\n');
+ if (!v || (nl && v > nl)) continue;
+ v++;
+ while (*v == ' ' || *v == '\t') v++;
+ size_t o = 0;
+ for (; *v && *v != '\n' && o + 1 < size; v++) out[o++] = (*v >= 0x20 && *v < 0x7f) ? *v : '?';
+ while (o && out[o - 1] == ' ') o--;
+ out[o] = 0;
+ return;
+ }
+}
+
+/* os-release: KEY=value or KEY="value". */
+static void osr_field(const char *txt, const char *key, char *out, size_t size) {
+ out[0] = 0;
+ size_t kl = strlen(key);
+ for (const char *p = txt; p && *p; p = strchr(p, '\n') ? strchr(p, '\n') + 1 : NULL) {
+ if (strncmp(p, key, kl) || p[kl] != '=') continue;
+ const char *v = p + kl + 1;
+ char q = (*v == '"' || *v == '\'') ? *v++ : 0;
+ size_t o = 0;
+ for (; *v && *v != '\n' && *v != q && o + 1 < size; v++) out[o++] = (*v >= 0x20 && *v < 0x7f) ? *v : '?';
+ out[o] = 0;
+ return;
+ }
+}
+
+/* ---- machine ---- */
+
+static const char *chassis_name(int t) {
+ switch (t) {
+ case 3: case 4: case 5: case 6: case 7: case 15: case 16: case 24: return "desktop";
+ case 8: case 9: case 10: case 14: case 31: case 32: return "laptop";
+ case 11: return "handheld";
+ case 13: return "all-in-one";
+ case 17: case 23: case 25: case 28: case 29: return "server";
+ case 30: return "tablet";
+ case 35: case 36: return "mini-pc";
+ case 1: return "other";
+ default: return "";
+ }
+}
+
+/* DMI vendor strings firmware leaves unset. */
+static void drop_placeholder(char *s) {
+ static const char *junk[] = { "To be filled by O.E.M.", "To Be Filled By O.E.M.", "Default string", "System Product Name",
+ "System manufacturer", "Not Applicable", "Not Specified", "None", "0123456789", "Type1ProductConfigId" };
+ for (size_t i = 0; i < sizeof junk / sizeof junk[0]; i++) if (!strcmp(s, junk[i])) { s[0] = 0; return; }
+}
+
+static void collect_machine(SysReport *r, const char *root, const char *cpuinfo) {
+ SrMachine *m = &r->machine;
+ const char *dmi = "/sys/class/dmi/id";
+ attr(root, dmi, "sys_vendor", m->vendor, sizeof m->vendor);
+ attr(root, dmi, "product_name", m->product, sizeof m->product);
+ attr(root, dmi, "product_version", m->version, sizeof m->version);
+ attr(root, dmi, "board_vendor", m->board_vendor, sizeof m->board_vendor);
+ attr(root, dmi, "board_name", m->board_name, sizeof m->board_name);
+ attr(root, dmi, "bios_vendor", m->bios_vendor, sizeof m->bios_vendor);
+ attr(root, dmi, "bios_version", m->bios_version, sizeof m->bios_version);
+ attr(root, dmi, "bios_date", m->bios_date, sizeof m->bios_date);
+ drop_placeholder(m->vendor); drop_placeholder(m->product); drop_placeholder(m->version);
+ drop_placeholder(m->board_vendor); drop_placeholder(m->board_name);
+ snprintf(m->chassis, sizeof m->chassis, "%s", chassis_name((int)attr_num(root, dmi, "chassis_type", 2)));
+
+ char p[1024];
+ snprintf(p, sizeof p, "%s/proc/device-tree/model", root);
+ read_attr(p, m->model, sizeof m->model);
+
+ if (exists(root, "/sys/firmware/efi")) snprintf(m->firmware, sizeof m->firmware, "uefi");
+ else if (m->bios_vendor[0]) snprintf(m->firmware, sizeof m->firmware, "bios");
+ else if (m->model[0]) snprintf(m->firmware, sizeof m->firmware, "dt");
+ m->secure_boot = -1;
+ snprintf(p, sizeof p, "%s/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c", root);
+ size_t len = 0;
+ char *sb = read_file(p, 16, &len);
+ if (sb && len >= 5) m->secure_boot = sb[4] == 1; /* 4 bytes of attributes, then the value */
+ free(sb);
+
+ /* virtualization: the CPU's "hypervisor" flag, then who the DMI says made the machine */
+ char flags[4096];
+ field(cpuinfo, "flags", flags, sizeof flags);
+ int hv = strstr(flags, " hypervisor") != NULL;
+ char compat[256] = "";
+ snprintf(p, sizeof p, "%s/proc/device-tree/compatible", root);
+ read_attr(p, compat, sizeof compat);
+ if (!strncmp(compat, "linux,dummy-virt", 16)) hv = 1;
+ if (hv) {
+ const char *v = "vm";
+ if (strstr(m->vendor, "QEMU") || strstr(compat, "dummy-virt")) v = "kvm";
+ else if (strstr(m->vendor, "VMware")) v = "vmware";
+ else if (strstr(m->vendor, "innotek") || strstr(m->product, "VirtualBox")) v = "virtualbox";
+ else if (strstr(m->vendor, "Microsoft")) v = "hyper-v";
+ else if (strstr(m->vendor, "Xen")) v = "xen";
+ else if (strstr(m->vendor, "Parallels")) v = "parallels";
+ snprintf(m->virt, sizeof m->virt, "%s", v);
+ if (!m->chassis[0] || !strcmp(m->chassis, "other")) snprintf(m->chassis, sizeof m->chassis, "vm");
+ }
+}
+
+/* ---- CPU and memory ---- */
+
+static void arm_core(unsigned part, char *out, size_t size) {
+ static const struct { unsigned part; const char *name; } parts[] = {
+ { 0xd03, "Cortex-A53" }, { 0xd04, "Cortex-A35" }, { 0xd05, "Cortex-A55" }, { 0xd07, "Cortex-A57" },
+ { 0xd08, "Cortex-A72" }, { 0xd09, "Cortex-A73" }, { 0xd0a, "Cortex-A75" }, { 0xd0b, "Cortex-A76" },
+ { 0xd0c, "Neoverse-N1" }, { 0xd0d, "Cortex-A77" }, { 0xd41, "Cortex-A78" }, { 0xd44, "Cortex-X1" },
+ { 0xd46, "Cortex-A510" }, { 0xd47, "Cortex-A710" }, { 0xd80, "Cortex-A520" }, { 0xd81, "Cortex-A720" },
+ };
+ for (size_t i = 0; i < sizeof parts / sizeof parts[0]; i++)
+ if (parts[i].part == part) { snprintf(out, size, "%s", parts[i].name); return; }
+}
+
+/* "48K", "1024 K", "32M" → KiB */
+static int cache_kb(const char *s) {
+ char *end;
+ long v = strtol(s, &end, 10);
+ while (*end == ' ') end++;
+ if (*end == 'M') v *= 1024;
+ return v > 0 && v < (1L << 30) ? (int)v : 0;
+}
+
+static void collect_cpu(SysReport *r, const char *root, const char *cpuinfo) {
+ SrCpu *c = &r->cpu;
+ field(cpuinfo, "model name", c->model, sizeof c->model);
+ field(cpuinfo, "vendor_id", c->vendor, sizeof c->vendor);
+ field(cpuinfo, "microcode", c->microcode, sizeof c->microcode);
+ if (!c->vendor[0]) {
+ char impl[16], part[16];
+ field(cpuinfo, "CPU implementer", impl, sizeof impl);
+ field(cpuinfo, "CPU part", part, sizeof part);
+ if (impl[0]) {
+ unsigned long i = strtoul(impl, NULL, 0);
+ snprintf(c->vendor, sizeof c->vendor, "%s", i == 0x41 ? "ARM" : i == 0x51 ? "Qualcomm" : i == 0x61 ? "Apple" : "other");
+ }
+ if (!c->model[0] && part[0]) arm_core((unsigned)strtoul(part, NULL, 0), c->model, sizeof c->model);
+ }
+ char p[1024];
+ snprintf(p, sizeof p, "%s/proc/sys/kernel/arch", root);
+ read_attr(p, c->arch, sizeof c->arch);
+ if (!c->arch[0] && !root[0]) { struct utsname u; if (!uname(&u)) snprintf(c->arch, sizeof c->arch, "%.15s", u.machine); }
+
+ /* instruction sets that matter for LordOS's own code and for apps */
+ static const char *x86[] = { "sse4_2", "avx", "avx2", "fma", "avx512f", "aes", "sha_ni", "vaes" };
+ static const char *arm[] = { "asimd", "sve", "sve2", "aes", "sha2", "crc32", "atomics" };
+ char flags[4096];
+ field(cpuinfo, "flags", flags, sizeof flags);
+ int is_arm = !flags[0];
+ if (is_arm) field(cpuinfo, "Features", flags, sizeof flags);
+ const char **want = is_arm ? arm : x86;
+ size_t nwant = is_arm ? sizeof arm / sizeof arm[0] : sizeof x86 / sizeof x86[0];
+ for (size_t i = 0; i < nwant; i++) {
+ size_t wl = strlen(want[i]);
+ for (const char *f = flags; (f = strstr(f, want[i])); f += wl)
+ if ((f == flags || f[-1] == ' ') && (f[wl] == ' ' || !f[wl])) {
+ size_t o = strlen(c->flags);
+ snprintf(c->flags + o, sizeof c->flags - o, "%s%s", o ? " " : "", want[i]);
+ break;
+ }
+ }
+
+ /* topology: unique (package, core) pairs among the CPUs listed in sysfs */
+ char **cpus;
+ int n = list_dir(root, "/sys/devices/system/cpu", &cpus);
+ long pk[1024], co[1024];
+ int npairs = 0, maxpk = -1;
+ for (int i = 0; i < n; i++) {
+ if (strncmp(cpus[i], "cpu", 3) || !isdigit((unsigned char)cpus[i][3])) continue;
+ char d[128];
+ snprintf(d, sizeof d, "/sys/devices/system/cpu/%s", cpus[i]);
+ if (attr_num(root, d, "online", 1) == 0) continue;
+ c->threads++;
+ snprintf(d, sizeof d, "/sys/devices/system/cpu/%s/topology", cpus[i]);
+ long pkg = (long)attr_num(root, d, "physical_package_id", 0), core = (long)attr_num(root, d, "core_id", c->threads);
+ if (pkg > maxpk) maxpk = (int)pkg;
+ int seen = 0;
+ for (int j = 0; j < npairs && !seen; j++) seen = pk[j] == pkg && co[j] == core;
+ if (!seen && npairs < 1024) { pk[npairs] = pkg; co[npairs] = core; npairs++; }
+ }
+ free_list(cpus, n);
+ c->cores = npairs;
+ c->sockets = maxpk + 1;
+ if (!c->threads) { /* no sysfs: count /proc/cpuinfo's processors */
+ for (const char *q = cpuinfo; (q = strstr(q, "processor")); q += 9) if (q == cpuinfo || q[-1] == '\n') c->threads++;
+ c->cores = c->threads;
+ c->sockets = c->threads ? 1 : 0;
+ }
+
+ const char *f = "/sys/devices/system/cpu/cpu0/cpufreq";
+ c->min_mhz = (int)(attr_num(root, f, "cpuinfo_min_freq", 0) / 1000);
+ c->max_mhz = (int)(attr_num(root, f, "cpuinfo_max_freq", 0) / 1000);
+ attr(root, f, "scaling_governor", c->governor, sizeof c->governor);
+
+ char **idx;
+ n = list_dir(root, "/sys/devices/system/cpu/cpu0/cache", &idx);
+ for (int i = 0; i < n; i++) {
+ if (strncmp(idx[i], "index", 5)) continue;
+ char d[128], type[24], size[24];
+ snprintf(d, sizeof d, "/sys/devices/system/cpu/cpu0/cache/%s", idx[i]);
+ long lvl = (long)attr_num(root, d, "level", 0);
+ attr(root, d, "type", type, sizeof type);
+ attr(root, d, "size", size, sizeof size);
+ int kb = cache_kb(size);
+ if (lvl == 1 && !strcmp(type, "Data")) c->l1d_kb = kb;
+ else if (lvl == 1 && !strcmp(type, "Instruction")) c->l1i_kb = kb;
+ else if (lvl == 2) c->l2_kb = kb;
+ else if (lvl == 3) c->l3_kb = kb;
+ }
+ free_list(idx, n);
+}
+
+static void collect_memory(SysReport *r, const char *root) {
+ char p[1024], v[64];
+ snprintf(p, sizeof p, "%s/proc/meminfo", root);
+ char *txt = read_file(p, 16384, NULL);
+ if (txt) {
+ field(txt, "MemTotal", v, sizeof v); r->mem.total_kb = strtoull(v, NULL, 10);
+ field(txt, "SwapTotal", v, sizeof v); r->mem.swap_kb = strtoull(v, NULL, 10);
+ free(txt);
+ }
+ char **b;
+ int n = list_dir(root, "/sys/block", &b);
+ for (int i = 0; i < n && r->mem.zram_n < SR_MAX_ZRAM; i++) {
+ if (strncmp(b[i], "zram", 4)) continue;
+ char d[96], algo[128];
+ snprintf(d, sizeof d, "/sys/block/%s", b[i]);
+ long long size = attr_num(root, d, "disksize", 0);
+ if (size <= 0) continue;
+ int k = r->mem.zram_n++;
+ r->mem.zram_kb[k] = (uint64_t)size / 1024;
+ attr(root, d, "comp_algorithm", algo, sizeof algo); /* "lzo [lz4] zstd": the one in brackets */
+ const char *a = strchr(algo, '['), *e = a ? strchr(a, ']') : NULL;
+ if (a && e) snprintf(r->mem.zram_algo[k], sizeof r->mem.zram_algo[k], "%.*s", (int)(e - a - 1), a + 1);
+ }
+ free_list(b, n);
+}
+
+/* ---- graphics and displays ---- */
+
+static void collect_gpus(SysReport *r, const char *root, const IdsDb *pci) {
+ char **e;
+ int n = list_dir(root, "/sys/class/drm", &e);
+ for (int i = 0; i < n && r->ngpu < SR_MAX_GPU; i++) {
+ if (strncmp(e[i], "card", 4) || strchr(e[i], '-')) continue;
+ SrGpu *g = &r->gpu[r->ngpu++];
+ char d[160];
+ snprintf(g->card, sizeof g->card, "%.11s", e[i]);
+ snprintf(d, sizeof d, "/sys/class/drm/%s/device", e[i]);
+ link_base(root, d, "driver", g->driver, sizeof g->driver);
+ hex_attr(root, d, "vendor", 4, g->vendor_id);
+ hex_attr(root, d, "device", 4, g->device_id);
+ snprintf(g->bus, sizeof g->bus, "%s", g->vendor_id[0] ? "pci" : "platform");
+ if (g->vendor_id[0]) ids_lookup(pci, g->vendor_id, g->device_id, g->vendor, sizeof g->vendor, g->device, sizeof g->device);
+ g->boot_vga = attr_num(root, d, "boot_vga", 0) == 1;
+ char **dn;
+ char dd[192];
+ snprintf(dd, sizeof dd, "%s/drm", d);
+ int m = list_dir(root, dd, &dn);
+ for (int j = 0; j < m; j++) if (!strncmp(dn[j], "renderD", 7)) g->render_node = 1;
+ free_list(dn, m);
+ size_t cl = strlen(e[i]);
+ for (int j = 0; j < n; j++) {
+ if (strncmp(e[j], e[i], cl) || e[j][cl] != '-' || strstr(e[j], "Writeback")) continue;
+ char cd[160], st[24];
+ snprintf(cd, sizeof cd, "/sys/class/drm/%s", e[j]);
+ attr(root, cd, "status", st, sizeof st);
+ g->connectors++;
+ if (!strcmp(st, "connected")) g->connected++;
+ }
+ }
+ free_list(e, n);
+}
+
+static void collect_displays(SysReport *r, const char *root) {
+ char **e;
+ int n = list_dir(root, "/sys/class/drm", &e);
+ for (int i = 0; i < n && r->ndisplay < SR_MAX_DISPLAY; i++) {
+ const char *dash = strchr(e[i], '-');
+ if (strncmp(e[i], "card", 4) || !dash || strstr(e[i], "Writeback")) continue;
+ char d[160], st[24], en[24];
+ snprintf(d, sizeof d, "/sys/class/drm/%s", e[i]);
+ attr(root, d, "status", st, sizeof st);
+ if (strcmp(st, "connected")) continue;
+ SrDisplay *x = &r->display[r->ndisplay++];
+ x->connected = 1;
+ attr(root, d, "enabled", en, sizeof en);
+ x->enabled = !strcmp(en, "enabled");
+ snprintf(x->card, sizeof x->card, "%.*s", (int)(dash - e[i]) < 11 ? (int)(dash - e[i]) : 11, e[i]);
+ snprintf(x->connector, sizeof x->connector, "%.31s", dash + 1);
+ attr(root, d, "modes", x->mode, sizeof x->mode);
+ char p[1024];
+ snprintf(p, sizeof p, "%s%s/edid", root, d);
+ size_t len = 0;
+ uint8_t *raw = (uint8_t *)read_file(p, 512, &len);
+ Edid ed;
+ if (raw && len >= 128 && !edid_parse(raw, len, &ed)) {
+ /* the identity without the serial: name, maker, product, year, size, native mode */
+ snprintf(x->name, sizeof x->name, "%s", ed.name);
+ snprintf(x->pnp, sizeof x->pnp, "%s", ed.vendor);
+ snprintf(x->product, sizeof x->product, "%04x", ed.product);
+ x->year = ed.year;
+ x->width_cm = ed.width_cm;
+ x->height_cm = ed.height_cm;
+ x->diag_tenths = edid_diagonal_tenths(&ed);
+ x->pref_w = ed.pref_w;
+ x->pref_h = ed.pref_h;
+ }
+ free(raw);
+ }
+ free_list(e, n);
+}
+
+/* ---- storage ---- */
+
+static void collect_disks(SysReport *r, const char *root) {
+ char **b;
+ int n = list_dir(root, "/sys/block", &b);
+ static const char *skip[] = { "loop", "ram", "zram", "dm-", "md", "nbd", "mtdblock", "fd" };
+ for (int i = 0; i < n && r->ndisk < SR_MAX_DISK; i++) {
+ int sk = strstr(b[i], "boot") || strstr(b[i], "rpmb");
+ for (size_t k = 0; k < sizeof skip / sizeof skip[0] && !sk; k++) sk = !strncmp(b[i], skip[k], strlen(skip[k]));
+ if (sk) continue;
+ char d[96];
+ snprintf(d, sizeof d, "/sys/block/%s", b[i]);
+ long long sectors = attr_num(root, d, "size", 0);
+ if (sectors <= 0) continue; /* an empty card reader */
+ SrDisk *k = &r->disk[r->ndisk++];
+ snprintf(k->name, sizeof k->name, "%.15s", b[i]);
+ k->bytes = (uint64_t)sectors * 512;
+ char q[128];
+ snprintf(q, sizeof q, "%s/queue", d);
+ k->rotational = attr_num(root, q, "rotational", 0) == 1;
+ k->removable = attr_num(root, d, "removable", 0) == 1;
+ snprintf(q, sizeof q, "%s/device", d);
+ attr(root, q, "model", k->model, sizeof k->model);
+ attr(root, q, "vendor", k->vendor, sizeof k->vendor);
+ if (!strncmp(b[i], "nvme", 4)) {
+ snprintf(k->transport, sizeof k->transport, "nvme");
+ char spd[32], wid[8];
+ snprintf(q, sizeof q, "%s/device/device", d);
+ attr(root, q, "current_link_speed", spd, sizeof spd);
+ attr(root, q, "current_link_width", wid, sizeof wid);
+ if (spd[0] && wid[0]) snprintf(k->link, sizeof k->link, "%.20s x%.4s", spd, wid);
+ } else if (!strncmp(b[i], "mmcblk", 6)) {
+ snprintf(k->transport, sizeof k->transport, "mmc");
+ } else if (!strncmp(b[i], "vd", 2)) {
+ snprintf(k->transport, sizeof k->transport, "virtio");
+ } else {
+ char p[1024], l[1024];
+ snprintf(p, sizeof p, "%s%s", root, d);
+ ssize_t m = readlink(p, l, sizeof l - 1);
+ l[m > 0 ? m : 0] = 0;
+ snprintf(k->transport, sizeof k->transport, "%s", strstr(l, "/usb") ? "usb" : strstr(l, "/ata") ? "sata" : "scsi");
+ }
+ }
+ free_list(b, n);
+}
+
+/* ---- buses ---- */
+
+static void collect_pci(SysReport *r, const char *root, const IdsDb *ids) {
+ char **e;
+ int n = list_dir(root, "/sys/bus/pci/devices", &e);
+ for (int i = 0; i < n && r->npci < SR_MAX_PCI; i++) {
+ char d[128];
+ snprintf(d, sizeof d, "/sys/bus/pci/devices/%s", e[i]);
+ SrPci *x = &r->pci[r->npci];
+ hex_attr(root, d, "vendor", 4, x->vendor_id);
+ hex_attr(root, d, "device", 4, x->device_id);
+ hex_attr(root, d, "class", 6, x->slot_class);
+ if (!x->vendor_id[0]) { memset(x, 0, sizeof *x); continue; }
+ link_base(root, d, "driver", x->driver, sizeof x->driver);
+ ids_lookup(ids, x->vendor_id, x->device_id, x->vendor, sizeof x->vendor, x->device, sizeof x->device);
+ char cname[48], sname[48];
+ ids_pci_class(ids, x->slot_class, cname, sizeof cname, sname, sizeof sname);
+ snprintf(x->class_name, sizeof x->class_name, "%s", sname[0] ? sname : cname);
+ r->npci++;
+ }
+ free_list(e, n);
+}
+
+static void collect_usb(SysReport *r, const char *root, const IdsDb *ids) {
+ char **e;
+ int n = list_dir(root, "/sys/bus/usb/devices", &e);
+ for (int i = 0; i < n && r->nusb < SR_MAX_USB; i++) {
+ if (strchr(e[i], ':') || !strncmp(e[i], "usb", 3)) continue; /* interfaces and root hubs */
+ char d[128];
+ snprintf(d, sizeof d, "/sys/bus/usb/devices/%s", e[i]);
+ SrUsb *u = &r->usb[r->nusb];
+ hex_attr(root, d, "idVendor", 4, u->vendor_id);
+ hex_attr(root, d, "idProduct", 4, u->product_id);
+ if (!u->vendor_id[0]) { memset(u, 0, sizeof *u); continue; }
+ hex_attr(root, d, "bDeviceClass", 2, u->cls);
+ char s[16];
+ attr(root, d, "speed", s, sizeof s);
+ u->speed_mbps = atoi(s);
+ char ifd[160];
+ snprintf(ifd, sizeof ifd, "%s/%s:1.0", d, e[i]);
+ link_base(root, ifd, "driver", u->driver, sizeof u->driver);
+ ids_lookup(ids, u->vendor_id, u->product_id, u->vendor, sizeof u->vendor, u->product, sizeof u->product);
+ r->nusb++;
+ }
+ free_list(e, n);
+}
+
+/* ---- network, audio, Bluetooth, power, thermal ---- */
+
+static void collect_net(SysReport *r, const char *root) {
+ char **e;
+ int n = list_dir(root, "/sys/class/net", &e);
+ for (int i = 0; i < n && r->nnet < SR_MAX_NET; i++) {
+ if (!strcmp(e[i], "lo")) continue;
+ char d[96], w[128], st[16];
+ snprintf(d, sizeof d, "/sys/class/net/%s", e[i]);
+ SrNet *x = &r->net[r->nnet++];
+ int has_dev = exists(root, (snprintf(w, sizeof w, "%s/device", d), w));
+ snprintf(w, sizeof w, "%s/wireless", d);
+ int wifi = exists(root, w) || exists(root, (snprintf(w, sizeof w, "%s/phy80211", d), w));
+ long long type = attr_num(root, d, "type", 1);
+ snprintf(x->kind, sizeof x->kind, "%s", wifi ? "wifi" : !has_dev ? "virtual" : type == 1 ? "ethernet" : "other");
+ snprintf(w, sizeof w, "%s/device", d);
+ link_base(root, w, "driver", x->driver, sizeof x->driver);
+ attr(root, d, "operstate", st, sizeof st);
+ x->up = !strcmp(st, "up");
+ x->speed_mbps = x->up ? (int)attr_num(root, d, "speed", -1) : -1;
+ if (x->speed_mbps <= 0) x->speed_mbps = -1;
+ }
+ free_list(e, n);
+}
+
+static void collect_audio(SysReport *r, const char *root) {
+ char p[1024];
+ snprintf(p, sizeof p, "%s/proc/asound/cards", root);
+ char *txt = read_file(p, 16384, NULL);
+ /* " 0 [PCH ]: HDA-Intel - HDA Intel PCH": the text after " - " */
+ for (char *l = txt; l && *l && r->naudio < SR_MAX_AUDIO; ) {
+ char *nl = strchr(l, '\n');
+ if (nl) *nl = 0;
+ char *b = strchr(l, '['), *dash = strstr(l, "]: ");
+ if (b && dash && (dash = strstr(dash, " - "))) {
+ char *dst = r->audio[r->naudio++];
+ size_t o = 0;
+ for (const char *s = dash + 3; *s && o + 1 < SR_NAME; s++) dst[o++] = (*s >= 0x20 && *s < 0x7f) ? *s : '?';
+ dst[o] = 0;
+ }
+ l = nl ? nl + 1 : NULL;
+ }
+ free(txt);
+}
+
+static void collect_bt(SysReport *r, const char *root) {
+ char **e;
+ int n = list_dir(root, "/sys/class/bluetooth", &e);
+ for (int i = 0; i < n && r->nbt < 4; i++) {
+ if (strncmp(e[i], "hci", 3) || strchr(e[i], ':')) continue;
+ char d[96];
+ snprintf(d, sizeof d, "/sys/class/bluetooth/%s/device", e[i]);
+ link_base(root, d, "driver", r->bt_driver[r->nbt], sizeof r->bt_driver[0]);
+ r->nbt++;
+ }
+ free_list(e, n);
+}
+
+static void collect_power(SysReport *r, const char *root) {
+ char **e;
+ int n = list_dir(root, "/sys/class/power_supply", &e);
+ for (int i = 0; i < n && r->npower < SR_MAX_POWER; i++) {
+ char d[128], type[24], scope[24];
+ snprintf(d, sizeof d, "/sys/class/power_supply/%s", e[i]);
+ attr(root, d, "scope", scope, sizeof scope);
+ if (!strcmp(scope, "Device")) continue; /* a mouse's or headset's battery */
+ attr(root, d, "type", type, sizeof type);
+ SrPower *x = &r->power[r->npower++];
+ snprintf(x->kind, sizeof x->kind, "%s", !strcmp(type, "Battery") ? "battery" : !strcmp(type, "Mains") ? "ac"
+ : !strncmp(type, "USB", 3) ? "usb" : !strcmp(type, "UPS") ? "ups" : "other");
+ attr(root, d, "manufacturer", x->vendor, sizeof x->vendor);
+ attr(root, d, "model_name", x->model, sizeof x->model);
+ attr(root, d, "technology", x->technology, sizeof x->technology);
+ attr(root, d, "status", x->status, sizeof x->status);
+ x->capacity = (int)attr_num(root, d, "capacity", -1);
+ x->online = (int)attr_num(root, d, "online", -1);
+ long long full = attr_num(root, d, "energy_full", -1), design = attr_num(root, d, "energy_full_design", -1);
+ if (full < 0 || design <= 0) { full = attr_num(root, d, "charge_full", -1); design = attr_num(root, d, "charge_full_design", -1); }
+ x->health = full >= 0 && design > 0 ? (int)(full * 100 / design) : -1;
+ }
+ free_list(e, n);
+}
+
+static void collect_thermal(SysReport *r, const char *root) {
+ char **e;
+ int n = list_dir(root, "/sys/class/thermal", &e);
+ for (int i = 0; i < n && r->nthermal < SR_MAX_THERMAL; i++) {
+ if (strncmp(e[i], "thermal_zone", 12)) continue;
+ char d[96];
+ snprintf(d, sizeof d, "/sys/class/thermal/%s", e[i]);
+ SrThermal *t = &r->thermal[r->nthermal++];
+ attr(root, d, "type", t->type, sizeof t->type);
+ t->milli_c = (int)attr_num(root, d, "temp", INT32_MIN);
+ }
+ free_list(e, n);
+ n = list_dir(root, "/sys/class/hwmon", &e);
+ for (int i = 0; i < n && r->nthermal < SR_MAX_THERMAL; i++) {
+ char d[96];
+ snprintf(d, sizeof d, "/sys/class/hwmon/%s", e[i]);
+ SrThermal *t = &r->thermal[r->nthermal];
+ attr(root, d, "name", t->type, sizeof t->type);
+ if (!t->type[0]) continue;
+ t->milli_c = (int)attr_num(root, d, "temp1_input", INT32_MIN);
+ char **f;
+ int m = list_dir(root, d, &f);
+ for (int j = 0; j < m; j++) if (!strncmp(f[j], "fan", 3) && strstr(f[j], "_input")) t->fans++;
+ free_list(f, m);
+ r->nthermal++;
+ }
+ free_list(e, n);
+}
+
+/* ---- Raspberry Pi ---- */
+
+static void collect_pi(SysReport *r, const char *root, const char *cpuinfo) {
+ char p[1024], compat[512] = "";
+ snprintf(p, sizeof p, "%s/proc/device-tree/compatible", root);
+ size_t len = 0;
+ char *c = read_file(p, sizeof compat - 1, &len);
+ if (c) {
+ for (size_t i = 0; i < len; i++) if (!c[i]) c[i] = ' '; /* NUL-separated list */
+ snprintf(compat, sizeof compat, "%s", c);
+ free(c);
+ }
+ r->pi.is_pi = strstr(compat, "raspberrypi") != NULL;
+ r->pi.throttled = -1;
+ if (!r->pi.is_pi) return;
+ snprintf(r->pi.model, sizeof r->pi.model, "%s", r->machine.model);
+ field(cpuinfo, "Revision", r->pi.revision, sizeof r->pi.revision);
+ /* the firmware node's get_throttled: soc:firmware on the Pi 4, soc@…:firmware on the Pi 5 */
+ char **e;
+ int n = list_dir(root, "/sys/devices/platform", &e);
+ for (int i = 0; i < n && r->pi.throttled < 0; i++) {
+ char d[256], **f;
+ snprintf(d, sizeof d, "/sys/devices/platform/%s", e[i]);
+ int m = list_dir(root, d, &f);
+ for (int j = 0; j < m && r->pi.throttled < 0; j++) {
+ size_t fl = strlen(f[j]);
+ if (fl < 8 || strcmp(f[j] + fl - 8, "firmware")) continue;
+ char fd[512];
+ snprintf(fd, sizeof fd, "%s/%s", d, f[j]);
+ r->pi.throttled = (int)attr_num(root, fd, "get_throttled", -1);
+ }
+ free_list(f, m);
+ }
+ free_list(e, n);
+}
+
+/* ---- software ---- */
+
+static void collect_software(SysReport *r, const char *root) {
+ SrSoftware *s = &r->sw;
+ char p[1024];
+ snprintf(p, sizeof p, "%s/etc/os-release", root);
+ char *txt = read_file(p, 8192, NULL);
+ if (!txt) { snprintf(p, sizeof p, "%s/usr/lib/os-release", root); txt = read_file(p, 8192, NULL); }
+ if (txt) {
+ osr_field(txt, "PRETTY_NAME", s->os, sizeof s->os);
+ osr_field(txt, "ID", s->os_id, sizeof s->os_id);
+ osr_field(txt, "VERSION_ID", s->os_version, sizeof s->os_version);
+ free(txt);
+ }
+ snprintf(p, sizeof p, "%s/proc/sys/kernel/osrelease", root);
+ read_attr(p, s->kernel, sizeof s->kernel);
+ snprintf(p, sizeof p, "%s/sys/kernel/security/lsm", root);
+ read_attr(p, s->lsm, sizeof s->lsm);
+ s->bpf_lsm = strstr(s->lsm, "bpf") != NULL;
+ s->cgroup2 = exists(root, "/sys/fs/cgroup/cgroup.controllers");
+ s->landlock_abi = -1;
+#ifdef SYS_landlock_create_ruleset
+ if (!root[0]) {
+ long abi = syscall(SYS_landlock_create_ruleset, NULL, 0, 1u); /* LANDLOCK_CREATE_RULESET_VERSION */
+ s->landlock_abi = abi > 0 ? (int)abi : 0;
+ }
+#endif
+
+ /* the kernel options LordOS's isolation, firewall and memory handling depend on */
+ static const char *opts[] = {
+ "CONFIG_SECURITY_LANDLOCK", "CONFIG_SECCOMP_FILTER", "CONFIG_USER_NS", "CONFIG_BPF_SYSCALL", "CONFIG_BPF_JIT",
+ "CONFIG_CGROUP_BPF", "CONFIG_BPF_LSM", "CONFIG_INET_DIAG_DESTROY", "CONFIG_INET_UDP_DIAG", "CONFIG_MEMCG",
+ "CONFIG_PSI", "CONFIG_ZRAM", "CONFIG_DRM", "CONFIG_UHID",
+ };
+ snprintf(p, sizeof p, "%s/boot/config-%s", root, s->kernel);
+ txt = s->kernel[0] && !strchr(s->kernel, '/') ? read_file(p, 1u << 20, NULL) : NULL;
+ for (size_t i = 0; i < sizeof opts / sizeof opts[0] && s->nkconf < SR_MAX_KCONF; i++) {
+ SrKconf *k = &s->kconf[s->nkconf++];
+ snprintf(k->name, sizeof k->name, "%s", opts[i]);
+ if (!txt) continue;
+ char key[64];
+ snprintf(key, sizeof key, "\n%s=", opts[i]);
+ const char *v = strstr(txt, key); /* absent or "# … is not set": n */
+ if (v) { v += strlen(key); snprintf(k->value, sizeof k->value, "%c", *v == 'y' || *v == 'm' ? *v : '?'); }
+ else snprintf(k->value, sizeof k->value, "n");
+ }
+ free(txt);
+
+ s->sessiond = exists(root, "/run/lordos/cgroup.sock");
+ s->netperm = exists(root, "/run/lordos/netperm.sock");
+ s->fand = exists(root, "/run/lordos/fand.sock");
+ s->netd = exists(root, "/run/lordos/netd.sock");
+}
+
+/* ---- all of it ---- */
+
+void sysreport_collect(SysReport *r, const char *root, const char *pci_ids, const char *usb_ids) {
+ if (!root) root = "";
+ memset(r, 0, sizeof *r);
+ r->schema = 1;
+ time_t now = time(NULL);
+ struct tm tm;
+ if (localtime_r(&now, &tm)) strftime(r->date, sizeof r->date, "%Y-%m-%d", &tm);
+
+ char p[1024];
+ snprintf(p, sizeof p, "%s/proc/cpuinfo", root);
+ char *cpuinfo = read_file(p, 1u << 20, NULL);
+ const char *ci = cpuinfo ? cpuinfo : "";
+
+ IdsDb pci, usb;
+ char ip[1024];
+ snprintf(ip, sizeof ip, "%s/usr/share/misc/pci.ids", root);
+ ids_open(&pci, pci_ids ? pci_ids : ip);
+ snprintf(ip, sizeof ip, "%s/usr/share/misc/usb.ids", root);
+ ids_open(&usb, usb_ids ? usb_ids : ip);
+
+ collect_machine(r, root, ci);
+ collect_cpu(r, root, ci);
+ collect_memory(r, root);
+ collect_gpus(r, root, &pci);
+ collect_displays(r, root);
+ collect_disks(r, root);
+ collect_pci(r, root, &pci);
+ collect_usb(r, root, &usb);
+ collect_net(r, root);
+ collect_audio(r, root);
+ collect_bt(r, root);
+ collect_power(r, root);
+ collect_thermal(r, root);
+ collect_pi(r, root, ci);
+ collect_software(r, root);
+
+ ids_close(&pci);
+ ids_close(&usb);
+ free(cpuinfo);
+}
diff --git a/server/src/sysreport/sysreport.h b/server/src/sysreport/sysreport.h
new file mode 100644
index 0000000..31fe0e9
--- /dev/null
+++ b/server/src/sysreport/sysreport.h
@@ -0,0 +1,181 @@
+/* sysreport.h — System Information's collector (0.8.5, see docs/BENCHMARK.md): what hardware this
+ * machine has and what the kernel made of it, read without root from world-readable files (sysfs,
+ * /proc, the device tree, os-release, the kernel config). Used by `lordos-sysreport` and, later, by
+ * `lord.sysinfo`; nothing is written, executed or sent anywhere.
+ *
+ * Privacy by construction: the report is built from a fixed list of fields, and the structures below
+ * have no place for serial numbers, UUIDs, MAC or IP addresses, host or user names, Wi-Fi network
+ * names or home-folder paths (network interfaces are reported by kind and driver, not by name, as a
+ * name can carry the MAC). tests/sysreport_test.c fills a fake system with such values and checks that
+ * none reaches the JSON or the Markdown.
+ *
+ * `root` prefixes every path ("" for this machine; tests point it at a fake tree). Facts that only
+ * the running system can give (the Landlock ABI, which LordOS services are up) are left unknown
+ * under a fake root. */
+#ifndef LORD_SYSREPORT_H
+#define LORD_SYSREPORT_H
+
+#include <stdint.h>
+
+#define SR_NAME 96
+#define SR_MAX_GPU 8
+#define SR_MAX_DISPLAY 12
+#define SR_MAX_DISK 32
+#define SR_MAX_PCI 96
+#define SR_MAX_USB 64
+#define SR_MAX_NET 16
+#define SR_MAX_AUDIO 8
+#define SR_MAX_POWER 8
+#define SR_MAX_THERMAL 16
+#define SR_MAX_KCONF 16
+#define SR_MAX_ZRAM 4
+
+typedef struct {
+ char vendor[SR_NAME], product[SR_NAME], version[SR_NAME];
+ char board_vendor[SR_NAME], board_name[SR_NAME];
+ char chassis[24]; /* "desktop", "laptop", "server", "vm"…, "" unknown */
+ char bios_vendor[SR_NAME], bios_version[SR_NAME], bios_date[24];
+ char model[SR_NAME]; /* device tree model (ARM boards) */
+ char firmware[8]; /* "uefi", "bios", "dt" (device tree), "" */
+ int secure_boot; /* 1 on, 0 off, -1 unknown */
+ char virt[24]; /* hypervisor ("kvm", "vmware"…), "" bare metal or unknown */
+} SrMachine;
+
+typedef struct {
+ char model[SR_NAME], vendor[32], arch[16];
+ int sockets, cores, threads;
+ int min_mhz, max_mhz;
+ char governor[24];
+ int l1d_kb, l1i_kb, l2_kb, l3_kb; /* per core (L1, L2 on most) or shared (L3); 0 unknown */
+ char flags[160]; /* the instruction sets that matter, space-separated */
+ char microcode[24];
+} SrCpu;
+
+typedef struct {
+ uint64_t total_kb, swap_kb;
+ int zram_n;
+ uint64_t zram_kb[SR_MAX_ZRAM];
+ char zram_algo[SR_MAX_ZRAM][16];
+} SrMemory;
+
+typedef struct {
+ char card[12]; /* "card0" */
+ char bus[12]; /* "pci", "platform" */
+ char vendor_id[5], device_id[5];
+ char vendor[SR_NAME], device[SR_NAME];
+ char driver[32];
+ int boot_vga; /* the firmware's console GPU */
+ int render_node; /* a renderD* node belongs to it */
+ int connectors, connected; /* KMS connectors */
+} SrGpu;
+
+typedef struct {
+ char connector[32]; /* "HDMI-A-1", "eDP-1" (the card is dropped) */
+ char card[12];
+ int connected, enabled;
+ char name[16], pnp[4]; /* EDID monitor name and manufacturer code */
+ char product[5];
+ int year, width_cm, height_cm, diag_tenths;
+ int pref_w, pref_h; /* native mode */
+ char mode[24]; /* first mode the kernel lists */
+} SrDisplay;
+
+typedef struct {
+ char name[16]; /* "nvme0n1", "sda" */
+ char model[SR_NAME], vendor[SR_NAME];
+ uint64_t bytes;
+ int rotational, removable;
+ char transport[12]; /* "nvme", "sata", "usb", "mmc", "virtio", "scsi", "" */
+ char link[32]; /* NVMe PCIe link ("8.0 GT/s PCIe x4") */
+} SrDisk;
+
+typedef struct {
+ char slot_class[7]; /* class code "030000" */
+ char vendor_id[5], device_id[5];
+ char vendor[SR_NAME], device[SR_NAME], class_name[48];
+ char driver[32];
+} SrPci;
+
+typedef struct {
+ char vendor_id[5], product_id[5];
+ char vendor[SR_NAME], product[SR_NAME];
+ char cls[3]; /* device class, "00" when per interface */
+ int speed_mbps;
+ char driver[32]; /* the first interface's */
+} SrUsb;
+
+typedef struct {
+ char kind[12]; /* "ethernet", "wifi", "virtual", "other" */
+ char driver[32];
+ int speed_mbps; /* -1 unknown or down */
+ int up;
+} SrNet;
+
+typedef struct {
+ char kind[12]; /* "battery", "ac", "usb", "ups" */
+ char vendor[SR_NAME], model[SR_NAME], technology[16];
+ int capacity; /* %, -1 unknown */
+ int health; /* full charge as % of the design capacity, -1 unknown */
+ char status[16];
+ int online; /* AC: 1 plugged */
+} SrPower;
+
+typedef struct {
+ char type[32]; /* thermal zone type or hwmon chip name */
+ int milli_c; /* INT32_MIN unknown */
+ int fans; /* hwmon: fan inputs */
+} SrThermal;
+
+typedef struct {
+ char name[40]; /* CONFIG_… */
+ char value[8]; /* "y", "m", "n" (not set), "" unknown */
+} SrKconf;
+
+typedef struct {
+ char os[SR_NAME], os_id[24], os_version[24];
+ char kernel[64];
+ char lordos[48]; /* LordOS version, filled by the caller */
+ char lsm[96]; /* /sys/kernel/security/lsm */
+ int landlock_abi; /* -1 unknown, 0 unavailable */
+ int bpf_lsm; /* "bpf" in the LSM list */
+ int cgroup2; /* unified hierarchy mounted */
+ int nkconf;
+ SrKconf kconf[SR_MAX_KCONF];
+ int sessiond, netperm, fand, netd; /* their sockets in /run/lordos (-1 unknown) */
+} SrSoftware;
+
+typedef struct {
+ char model[SR_NAME], revision[16]; /* /proc/cpuinfo "Revision" (the board code) */
+ int throttled; /* get_throttled bits, -1 unknown */
+ int is_pi;
+} SrPi;
+
+typedef struct {
+ int schema;
+ char date[16]; /* YYYY-MM-DD, filled by sysreport_collect */
+ SrMachine machine;
+ SrCpu cpu;
+ SrMemory mem;
+ int ngpu; SrGpu gpu[SR_MAX_GPU];
+ int ndisplay; SrDisplay display[SR_MAX_DISPLAY];
+ int ndisk; SrDisk disk[SR_MAX_DISK];
+ int npci; SrPci pci[SR_MAX_PCI];
+ int nusb; SrUsb usb[SR_MAX_USB];
+ int nnet; SrNet net[SR_MAX_NET];
+ int naudio; char audio[SR_MAX_AUDIO][SR_NAME];
+ int nbt; char bt_driver[4][32];
+ int npower; SrPower power[SR_MAX_POWER];
+ int nthermal; SrThermal thermal[SR_MAX_THERMAL];
+ SrPi pi;
+ SrSoftware sw;
+} SysReport;
+
+/* Fills r from the tree at root ("" = this machine). pci_ids/usb_ids are the name lists (NULL: the
+ * Debian paths under root). Always succeeds: what can't be read stays empty or unknown. */
+void sysreport_collect(SysReport *r, const char *root, const char *pci_ids, const char *usb_ids);
+
+/* The report as JSON (schema 1) or as a Markdown summary; malloc'd, NULL on out-of-memory. */
+char *sysreport_json(const SysReport *r);
+char *sysreport_markdown(const SysReport *r);
+
+#endif
diff --git a/server/src/sysreport/sysreport_out.c b/server/src/sysreport/sysreport_out.c
new file mode 100644
index 0000000..b52894d
--- /dev/null
+++ b/server/src/sysreport/sysreport_out.c
@@ -0,0 +1,367 @@
+/* sysreport_out.c — the report as JSON (schema 1) and as a Markdown summary (see sysreport.h). Both
+ * print only the structure's fields, so neither can carry more than the collector kept. */
+#include "sysreport.h"
+#include "../hw/jbuf.h"
+
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+
+/* ---- JSON ---- */
+
+static void jkey(HBuf *b, int *first, const char *key) {
+ hb_printf(b, "%s\"%s\":", *first ? "" : ",", key);
+ *first = 0;
+}
+static void js(HBuf *b, int *first, const char *key, const char *v) { jkey(b, first, key); hb_str(b, v); }
+static void ji(HBuf *b, int *first, const char *key, long long v) { jkey(b, first, key); hb_printf(b, "%lld", v); }
+static void jb(HBuf *b, int *first, const char *key, int v) { jkey(b, first, key); hb_printf(b, "%s", v ? "true" : "false"); }
+/* -1 (or INT32_MIN) means unknown: null */
+static void jn(HBuf *b, int *first, const char *key, long long v, long long unknown) {
+ jkey(b, first, key);
+ if (v == unknown) hb_printf(b, "null"); else hb_printf(b, "%lld", v);
+}
+
+char *sysreport_json(const SysReport *r) {
+ HBuf b = { 0 };
+ int f = 1, g;
+ hb_printf(&b, "{");
+ ji(&b, &f, "schema", r->schema);
+ js(&b, &f, "date", r->date);
+
+ const SrMachine *m = &r->machine;
+ jkey(&b, &f, "machine"); hb_printf(&b, "{"); g = 1;
+ js(&b, &g, "vendor", m->vendor); js(&b, &g, "product", m->product); js(&b, &g, "version", m->version);
+ js(&b, &g, "boardVendor", m->board_vendor); js(&b, &g, "boardName", m->board_name);
+ js(&b, &g, "chassis", m->chassis); js(&b, &g, "model", m->model);
+ js(&b, &g, "biosVendor", m->bios_vendor); js(&b, &g, "biosVersion", m->bios_version); js(&b, &g, "biosDate", m->bios_date);
+ js(&b, &g, "firmware", m->firmware);
+ jkey(&b, &g, "secureBoot"); hb_printf(&b, "%s", m->secure_boot < 0 ? "null" : m->secure_boot ? "true" : "false");
+ js(&b, &g, "virtualization", m->virt);
+ hb_printf(&b, "}");
+
+ const SrCpu *c = &r->cpu;
+ jkey(&b, &f, "cpu"); hb_printf(&b, "{"); g = 1;
+ js(&b, &g, "model", c->model); js(&b, &g, "vendor", c->vendor); js(&b, &g, "arch", c->arch);
+ ji(&b, &g, "sockets", c->sockets); ji(&b, &g, "cores", c->cores); ji(&b, &g, "threads", c->threads);
+ ji(&b, &g, "minMHz", c->min_mhz); ji(&b, &g, "maxMHz", c->max_mhz); js(&b, &g, "governor", c->governor);
+ ji(&b, &g, "l1dKB", c->l1d_kb); ji(&b, &g, "l1iKB", c->l1i_kb); ji(&b, &g, "l2KB", c->l2_kb); ji(&b, &g, "l3KB", c->l3_kb);
+ js(&b, &g, "flags", c->flags); js(&b, &g, "microcode", c->microcode);
+ hb_printf(&b, "}");
+
+ jkey(&b, &f, "memory"); hb_printf(&b, "{"); g = 1;
+ ji(&b, &g, "totalKB", (long long)r->mem.total_kb); ji(&b, &g, "swapKB", (long long)r->mem.swap_kb);
+ jkey(&b, &g, "zram"); hb_printf(&b, "[");
+ for (int i = 0; i < r->mem.zram_n; i++) {
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ ji(&b, &h, "sizeKB", (long long)r->mem.zram_kb[i]); js(&b, &h, "algorithm", r->mem.zram_algo[i]);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]}");
+
+ jkey(&b, &f, "gpus"); hb_printf(&b, "[");
+ for (int i = 0; i < r->ngpu; i++) {
+ const SrGpu *x = &r->gpu[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "card", x->card); js(&b, &h, "bus", x->bus); js(&b, &h, "vendorId", x->vendor_id); js(&b, &h, "deviceId", x->device_id);
+ js(&b, &h, "vendor", x->vendor); js(&b, &h, "device", x->device); js(&b, &h, "driver", x->driver);
+ jb(&b, &h, "bootVga", x->boot_vga); jb(&b, &h, "renderNode", x->render_node);
+ ji(&b, &h, "connectors", x->connectors); ji(&b, &h, "connected", x->connected);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "displays"); hb_printf(&b, "[");
+ for (int i = 0; i < r->ndisplay; i++) {
+ const SrDisplay *x = &r->display[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "card", x->card); js(&b, &h, "connector", x->connector); jb(&b, &h, "enabled", x->enabled);
+ js(&b, &h, "name", x->name); js(&b, &h, "manufacturer", x->pnp); js(&b, &h, "product", x->product);
+ ji(&b, &h, "year", x->year); ji(&b, &h, "widthCm", x->width_cm); ji(&b, &h, "heightCm", x->height_cm);
+ ji(&b, &h, "diagonalTenths", x->diag_tenths); ji(&b, &h, "nativeWidth", x->pref_w); ji(&b, &h, "nativeHeight", x->pref_h);
+ js(&b, &h, "mode", x->mode);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "storage"); hb_printf(&b, "[");
+ for (int i = 0; i < r->ndisk; i++) {
+ const SrDisk *x = &r->disk[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "name", x->name); js(&b, &h, "model", x->model); js(&b, &h, "vendor", x->vendor);
+ ji(&b, &h, "bytes", (long long)x->bytes); jb(&b, &h, "rotational", x->rotational); jb(&b, &h, "removable", x->removable);
+ js(&b, &h, "transport", x->transport); js(&b, &h, "link", x->link);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "pci"); hb_printf(&b, "[");
+ for (int i = 0; i < r->npci; i++) {
+ const SrPci *x = &r->pci[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "class", x->slot_class); js(&b, &h, "className", x->class_name);
+ js(&b, &h, "vendorId", x->vendor_id); js(&b, &h, "deviceId", x->device_id);
+ js(&b, &h, "vendor", x->vendor); js(&b, &h, "device", x->device); js(&b, &h, "driver", x->driver);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "usb"); hb_printf(&b, "[");
+ for (int i = 0; i < r->nusb; i++) {
+ const SrUsb *x = &r->usb[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "vendorId", x->vendor_id); js(&b, &h, "productId", x->product_id);
+ js(&b, &h, "vendor", x->vendor); js(&b, &h, "product", x->product); js(&b, &h, "class", x->cls);
+ ji(&b, &h, "speedMbps", x->speed_mbps); js(&b, &h, "driver", x->driver);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "network"); hb_printf(&b, "[");
+ for (int i = 0; i < r->nnet; i++) {
+ const SrNet *x = &r->net[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "kind", x->kind); js(&b, &h, "driver", x->driver); jb(&b, &h, "up", x->up);
+ jn(&b, &h, "speedMbps", x->speed_mbps, -1);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "audio"); hb_printf(&b, "[");
+ for (int i = 0; i < r->naudio; i++) { if (i) hb_printf(&b, ","); hb_str(&b, r->audio[i]); }
+ hb_printf(&b, "]");
+ jkey(&b, &f, "bluetooth"); hb_printf(&b, "[");
+ for (int i = 0; i < r->nbt; i++) { int h = 1; hb_printf(&b, "%s{", i ? "," : ""); js(&b, &h, "driver", r->bt_driver[i]); hb_printf(&b, "}"); }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "power"); hb_printf(&b, "[");
+ for (int i = 0; i < r->npower; i++) {
+ const SrPower *x = &r->power[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "kind", x->kind); js(&b, &h, "vendor", x->vendor); js(&b, &h, "model", x->model);
+ js(&b, &h, "technology", x->technology); js(&b, &h, "status", x->status);
+ jn(&b, &h, "capacity", x->capacity, -1); jn(&b, &h, "health", x->health, -1); jn(&b, &h, "online", x->online, -1);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ jkey(&b, &f, "thermal"); hb_printf(&b, "[");
+ for (int i = 0; i < r->nthermal; i++) {
+ const SrThermal *x = &r->thermal[i];
+ int h = 1;
+ hb_printf(&b, "%s{", i ? "," : "");
+ js(&b, &h, "sensor", x->type); jn(&b, &h, "milliC", x->milli_c, INT32_MIN); ji(&b, &h, "fans", x->fans);
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "]");
+
+ if (r->pi.is_pi) {
+ jkey(&b, &f, "raspberryPi"); hb_printf(&b, "{"); g = 1;
+ js(&b, &g, "model", r->pi.model); js(&b, &g, "revision", r->pi.revision);
+ jn(&b, &g, "throttled", r->pi.throttled, -1);
+ hb_printf(&b, "}");
+ }
+
+ const SrSoftware *s = &r->sw;
+ jkey(&b, &f, "software"); hb_printf(&b, "{"); g = 1;
+ js(&b, &g, "os", s->os); js(&b, &g, "osId", s->os_id); js(&b, &g, "osVersion", s->os_version);
+ js(&b, &g, "kernel", s->kernel); js(&b, &g, "lordos", s->lordos); js(&b, &g, "lsm", s->lsm);
+ jn(&b, &g, "landlockAbi", s->landlock_abi, -1); jb(&b, &g, "bpfLsm", s->bpf_lsm); jb(&b, &g, "cgroup2", s->cgroup2);
+ jkey(&b, &g, "kernelConfig"); hb_printf(&b, "{");
+ for (int i = 0; i < s->nkconf; i++) {
+ if (i) hb_printf(&b, ",");
+ hb_str(&b, s->kconf[i].name);
+ hb_printf(&b, ":");
+ if (s->kconf[i].value[0]) hb_str(&b, s->kconf[i].value); else hb_printf(&b, "null");
+ }
+ hb_printf(&b, "}");
+ jkey(&b, &g, "services"); hb_printf(&b, "{"); int h = 1;
+ jb(&b, &h, "lord-sessiond", s->sessiond); jb(&b, &h, "lord-netd", s->netd);
+ jb(&b, &h, "lord-netperm", s->netperm); jb(&b, &h, "lord-fand", s->fand);
+ hb_printf(&b, "}}");
+
+ hb_printf(&b, "}\n");
+ return hb_take(&b);
+}
+
+/* ---- Markdown ---- */
+
+/* A table cell: '|' and '`' would break the table; "—" for empty. */
+static void cell(HBuf *b, const char *s) {
+ if (!s || !s[0]) { hb_printf(b, " — |"); return; }
+ hb_printf(b, " ");
+ for (; *s; s++) hb_printf(b, "%c", *s == '|' || *s == '`' ? '/' : *s);
+ hb_printf(b, " |");
+}
+
+static void size_text(unsigned long long bytes, char *out, size_t n) {
+ if (bytes >= 1000ULL * 1000 * 1000 * 1000) snprintf(out, n, "%.1f TB", bytes / 1e12);
+ else if (bytes >= 1000ULL * 1000 * 1000) snprintf(out, n, "%.0f GB", bytes / 1e9);
+ else snprintf(out, n, "%.0f MB", bytes / 1e6);
+}
+
+static void two(char *out, size_t n, const char *a, const char *b) {
+ snprintf(out, n, "%s%s%s", a, a[0] && b[0] ? " " : "", b);
+}
+
+char *sysreport_markdown(const SysReport *r) {
+ HBuf b = { 0 };
+ char t[256], u[64];
+ const SrMachine *m = &r->machine;
+ hb_printf(&b, "# System report\n\n");
+ hb_printf(&b, "Made on %s by `lordos-sysreport` (schema %d). It lists the hardware and what the system made of it; it holds no serial numbers, addresses, host or user names.\n\n", r->date, r->schema);
+
+ hb_printf(&b, "## Overview\n\n| | |\n|---|---|\n");
+ two(t, sizeof t, m->vendor, m->product);
+ if (!t[0]) snprintf(t, sizeof t, "%s", m->model);
+ hb_printf(&b, "| Computer |"); cell(&b, t); hb_printf(&b, "\n");
+ hb_printf(&b, "| Kind |"); cell(&b, m->virt[0] ? m->virt : m->chassis); hb_printf(&b, "\n");
+ two(t, sizeof t, m->board_vendor, m->board_name);
+ hb_printf(&b, "| Board |"); cell(&b, t); hb_printf(&b, "\n");
+ snprintf(t, sizeof t, "%s%s%s%s%s", m->firmware, m->bios_version[0] ? ", " : "", m->bios_version, m->bios_date[0] ? ", " : "", m->bios_date);
+ hb_printf(&b, "| Firmware |"); cell(&b, t); hb_printf(&b, "\n");
+ hb_printf(&b, "| Secure Boot |"); cell(&b, m->secure_boot < 0 ? "" : m->secure_boot ? "on" : "off"); hb_printf(&b, "\n");
+ hb_printf(&b, "| System |"); cell(&b, r->sw.os); hb_printf(&b, "\n");
+ hb_printf(&b, "| Kernel |"); cell(&b, r->sw.kernel); hb_printf(&b, "\n");
+ hb_printf(&b, "| LordOS |"); cell(&b, r->sw.lordos); hb_printf(&b, "\n\n");
+
+ const SrCpu *c = &r->cpu;
+ hb_printf(&b, "## Processor\n\n| | |\n|---|---|\n");
+ hb_printf(&b, "| Model |"); cell(&b, c->model); hb_printf(&b, "\n");
+ snprintf(t, sizeof t, "%s, %d socket%s, %d cores, %d threads", c->arch, c->sockets, c->sockets == 1 ? "" : "s", c->cores, c->threads);
+ hb_printf(&b, "| Layout |"); cell(&b, t); hb_printf(&b, "\n");
+ if (c->max_mhz) {
+ snprintf(t, sizeof t, "%d–%d MHz%s%s", c->min_mhz, c->max_mhz, c->governor[0] ? ", governor " : "", c->governor);
+ hb_printf(&b, "| Frequency |"); cell(&b, t); hb_printf(&b, "\n");
+ }
+ snprintf(t, sizeof t, "L1d %d KB, L1i %d KB, L2 %d KB, L3 %d KB", c->l1d_kb, c->l1i_kb, c->l2_kb, c->l3_kb);
+ hb_printf(&b, "| Cache |"); cell(&b, t); hb_printf(&b, "\n");
+ hb_printf(&b, "| Instructions |"); cell(&b, c->flags); hb_printf(&b, "\n\n");
+
+ hb_printf(&b, "## Memory\n\n");
+ size_text(r->mem.total_kb * 1024ULL, t, sizeof t);
+ size_text(r->mem.swap_kb * 1024ULL, u, sizeof u);
+ hb_printf(&b, "%s, swap %s", t, r->mem.swap_kb ? u : "none");
+ for (int i = 0; i < r->mem.zram_n; i++) {
+ size_text(r->mem.zram_kb[i] * 1024ULL, u, sizeof u);
+ hb_printf(&b, ", zram %s (%s)", u, r->mem.zram_algo[i][0] ? r->mem.zram_algo[i] : "?");
+ }
+ hb_printf(&b, ".\n\n");
+
+ hb_printf(&b, "## Graphics\n\n| Card | Device | Driver | Render node | Connected outputs |\n|---|---|---|---|---|\n");
+ for (int i = 0; i < r->ngpu; i++) {
+ const SrGpu *g = &r->gpu[i];
+ hb_printf(&b, "|"); cell(&b, g->card);
+ two(t, sizeof t, g->vendor, g->device);
+ if (!t[0] && g->vendor_id[0]) snprintf(t, sizeof t, "%s:%s", g->vendor_id, g->device_id);
+ cell(&b, t); cell(&b, g->driver); cell(&b, g->render_node ? "yes" : "no");
+ snprintf(t, sizeof t, "%d of %d", g->connected, g->connectors); cell(&b, t);
+ hb_printf(&b, "\n");
+ }
+ if (!r->ngpu) hb_printf(&b, "| — | none found | | | |\n");
+ hb_printf(&b, "\n");
+
+ if (r->ndisplay) {
+ hb_printf(&b, "## Displays\n\n| Output | Monitor | Size | Native mode |\n|---|---|---|---|\n");
+ for (int i = 0; i < r->ndisplay; i++) {
+ const SrDisplay *x = &r->display[i];
+ hb_printf(&b, "|"); cell(&b, x->connector);
+ if (x->year) snprintf(t, sizeof t, "%s, %d", x->name[0] ? x->name : x->pnp, x->year);
+ else snprintf(t, sizeof t, "%s", x->name[0] ? x->name : x->pnp);
+ cell(&b, t);
+ if (x->diag_tenths) snprintf(t, sizeof t, "%d.%d\" (%d × %d cm)", x->diag_tenths / 10, x->diag_tenths % 10, x->width_cm, x->height_cm);
+ else t[0] = 0;
+ cell(&b, t);
+ if (x->pref_w) snprintf(t, sizeof t, "%d × %d", x->pref_w, x->pref_h); else snprintf(t, sizeof t, "%s", x->mode);
+ cell(&b, t);
+ hb_printf(&b, "\n");
+ }
+ hb_printf(&b, "\n");
+ }
+
+ hb_printf(&b, "## Storage\n\n| Disk | Model | Size | Kind |\n|---|---|---|---|\n");
+ for (int i = 0; i < r->ndisk; i++) {
+ const SrDisk *x = &r->disk[i];
+ hb_printf(&b, "|"); cell(&b, x->name); cell(&b, x->model);
+ size_text(x->bytes, t, sizeof t); cell(&b, t);
+ snprintf(t, sizeof t, "%s%s%s%s%s", x->transport, x->rotational ? ", spinning" : "", x->removable ? ", removable" : "", x->link[0] ? ", " : "", x->link);
+ cell(&b, t);
+ hb_printf(&b, "\n");
+ }
+ hb_printf(&b, "\n");
+
+ hb_printf(&b, "## Network, audio and Bluetooth\n\n");
+ for (int i = 0; i < r->nnet; i++) {
+ const SrNet *x = &r->net[i];
+ hb_printf(&b, "- %s%s%s%s", x->kind, x->driver[0] ? " (" : "", x->driver, x->driver[0] ? ")" : "");
+ if (x->up && x->speed_mbps > 0) hb_printf(&b, ", up at %d Mbit/s", x->speed_mbps);
+ else hb_printf(&b, ", %s", x->up ? "up" : "down");
+ hb_printf(&b, "\n");
+ }
+ for (int i = 0; i < r->naudio; i++) hb_printf(&b, "- audio: %s\n", r->audio[i]);
+ for (int i = 0; i < r->nbt; i++) hb_printf(&b, "- Bluetooth%s%s\n", r->bt_driver[i][0] ? ": " : "", r->bt_driver[i]);
+ hb_printf(&b, "\n");
+
+ if (r->npower) {
+ hb_printf(&b, "## Power\n\n");
+ for (int i = 0; i < r->npower; i++) {
+ const SrPower *x = &r->power[i];
+ if (!strcmp(x->kind, "battery")) {
+ hb_printf(&b, "- battery");
+ two(t, sizeof t, x->vendor, x->model);
+ if (t[0]) hb_printf(&b, " %s", t);
+ if (x->capacity >= 0) hb_printf(&b, ", %d %%", x->capacity);
+ if (x->health >= 0) hb_printf(&b, ", holds %d %% of its design charge", x->health);
+ if (x->status[0]) hb_printf(&b, ", %s", x->status);
+ hb_printf(&b, "\n");
+ } else {
+ hb_printf(&b, "- %s%s\n", x->kind, x->online == 1 ? ", plugged in" : x->online == 0 ? ", unplugged" : "");
+ }
+ }
+ hb_printf(&b, "\n");
+ }
+
+ if (r->pi.is_pi) {
+ hb_printf(&b, "## Raspberry Pi\n\n%s, revision %s", r->pi.model, r->pi.revision[0] ? r->pi.revision : "unknown");
+ if (r->pi.throttled >= 0)
+ hb_printf(&b, "; %s (0x%x)", r->pi.throttled == 0 ? "never throttled or under-voltage since boot"
+ : (r->pi.throttled & 0x50005) ? "under-voltage or throttling seen" : "flags set", (unsigned)r->pi.throttled);
+ hb_printf(&b, ".\n\n");
+ }
+
+ const SrSoftware *s = &r->sw;
+ hb_printf(&b, "## Kernel features LordOS uses\n\n| | |\n|---|---|\n");
+ hb_printf(&b, "| Security modules |"); cell(&b, s->lsm); hb_printf(&b, "\n");
+ if (s->landlock_abi >= 0) { snprintf(t, sizeof t, "%d", s->landlock_abi); hb_printf(&b, "| Landlock ABI |"); cell(&b, s->landlock_abi ? t : "unavailable"); hb_printf(&b, "\n"); }
+ hb_printf(&b, "| cgroup v2 |"); cell(&b, s->cgroup2 ? "yes" : "no"); hb_printf(&b, "\n");
+ for (int i = 0; i < s->nkconf; i++) {
+ hb_printf(&b, "|"); cell(&b, s->kconf[i].name);
+ cell(&b, !strcmp(s->kconf[i].value, "y") ? "built in" : !strcmp(s->kconf[i].value, "m") ? "module"
+ : !strcmp(s->kconf[i].value, "n") ? "not set" : s->kconf[i].value[0] ? s->kconf[i].value : "unknown");
+ hb_printf(&b, "\n");
+ }
+ hb_printf(&b, "\n## Devices\n\n| Kind | Device | Driver |\n|---|---|---|\n");
+ for (int i = 0; i < r->npci; i++) {
+ const SrPci *x = &r->pci[i];
+ hb_printf(&b, "|"); cell(&b, x->class_name[0] ? x->class_name : x->slot_class);
+ two(t, sizeof t, x->vendor, x->device);
+ if (!t[0]) snprintf(t, sizeof t, "%s:%s", x->vendor_id, x->device_id);
+ cell(&b, t); cell(&b, x->driver); hb_printf(&b, "\n");
+ }
+ for (int i = 0; i < r->nusb; i++) {
+ const SrUsb *x = &r->usb[i];
+ hb_printf(&b, "| USB |");
+ two(t, sizeof t, x->vendor, x->product);
+ if (!t[0]) snprintf(t, sizeof t, "%s:%s", x->vendor_id, x->product_id);
+ cell(&b, t); cell(&b, x->driver); hb_printf(&b, "\n");
+ }
+ return hb_take(&b);
+}
diff --git a/server/tests/sysreport_test.c b/server/tests/sysreport_test.c
new file mode 100644
index 0000000..87f1912
--- /dev/null
+++ b/server/tests/sysreport_test.c
@@ -0,0 +1,515 @@
+/* sysreport_test.c — System Information's collector (src/sysreport) over fake trees: an AMD desktop,
+ * an Intel laptop, an Nvidia desktop, a Raspberry Pi 5 and a VM. Each tree is full of things a report
+ * must never carry (serial numbers, UUIDs, MAC addresses, a host name, a user name, a monitor's serial,
+ * a MAC inside an interface name); the test checks what each report finds, that its JSON is valid,
+ * and that none of those values reaches the JSON or the Markdown.
+ *
+ * build/sysreport-test the tests (make test)
+ * build/sysreport-test fixture <dir> <kind> writes a fake tree (amd, intel, nvidia, rpi5, vm), for
+ * `lordos-sysreport report --root <dir>` */
+#include "sysreport/sysreport.h"
+#include "sysreport/ids.h"
+#include "sec/json.h"
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static int n_ok, n_bad;
+#define CHECK(cond, ...) do { if (cond) n_ok++; else { n_bad++; printf("✗ " __VA_ARGS__); printf("\n"); } } while (0)
+
+static void mkdirs(const char *path) {
+ char p[1024];
+ snprintf(p, sizeof p, "%s", path);
+ for (char *s = p + 1; *s; s++) if (*s == '/') { *s = 0; mkdir(p, 0755); *s = '/'; }
+ mkdir(p, 0755);
+}
+
+/* <root>/<rel> with data (parent folders created); len < 0: strlen. */
+static void putn(const char *root, const char *rel, const void *data, int len) {
+ char p[1024], d[1024];
+ snprintf(p, sizeof p, "%s/%s", root, rel);
+ snprintf(d, sizeof d, "%s", p);
+ char *sl = strrchr(d, '/');
+ if (sl) { *sl = 0; mkdirs(d); }
+ FILE *f = fopen(p, "wb");
+ if (!f) { printf("cannot write %s: %s\n", p, strerror(errno)); exit(2); }
+ fwrite(data, 1, len < 0 ? strlen(data) : (size_t)len, f);
+ fclose(f);
+}
+static void put(const char *root, const char *rel, const char *text) { putn(root, rel, text, -1); }
+
+static void lnk(const char *root, const char *rel, const char *target) {
+ char p[1024], d[1024];
+ snprintf(p, sizeof p, "%s/%s", root, rel);
+ snprintf(d, sizeof d, "%s", p);
+ char *sl = strrchr(d, '/');
+ if (sl) { *sl = 0; mkdirs(d); }
+ unlink(p);
+ if (symlink(target, p)) printf("symlink %s: %s\n", p, strerror(errno));
+}
+
+static void driver(const char *root, const char *dir, const char *name) {
+ char rel[512], target[256];
+ snprintf(rel, sizeof rel, "%s/driver", dir);
+ snprintf(target, sizeof target, "../../../bus/drivers/%s", name);
+ lnk(root, rel, target);
+}
+
+/* A 128-byte EDID 1.4 with a name, a serial descriptor and a native mode. */
+static void edid(uint8_t *e, const char *pnp, uint16_t product, const char *name, const char *serial, int w, int h, int wcm, int hcm, int year) {
+ memset(e, 0, 128);
+ static const uint8_t hdr[8] = { 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0 };
+ memcpy(e, hdr, 8);
+ uint16_t m = (uint16_t)(((pnp[0] - 'A' + 1) << 10) | ((pnp[1] - 'A' + 1) << 5) | (pnp[2] - 'A' + 1));
+ e[8] = (uint8_t)(m >> 8); e[9] = (uint8_t)m;
+ e[10] = (uint8_t)product; e[11] = (uint8_t)(product >> 8);
+ e[12] = 0xef; e[13] = 0xbe; e[14] = 0xad; e[15] = 0xde; /* serial 0xdeadbeef */
+ e[16] = 10; e[17] = (uint8_t)(year - 1990);
+ e[18] = 1; e[19] = 4; e[20] = 0x80; e[21] = (uint8_t)wcm; e[22] = (uint8_t)hcm;
+ uint8_t *t = e + 54; /* detailed timing */
+ t[0] = 0x56; t[1] = 0x5e;
+ t[2] = (uint8_t)w; t[4] = (uint8_t)((w >> 8) << 4);
+ t[5] = (uint8_t)h; t[7] = (uint8_t)((h >> 8) << 4);
+ const char *txt[2] = { name, serial };
+ uint8_t tag[2] = { 0xfc, 0xff };
+ for (int k = 0; k < 2; k++) {
+ uint8_t *d = e + 72 + 18 * k;
+ d[3] = tag[k];
+ size_t n = strlen(txt[k]);
+ for (int i = 0; i < 13; i++) d[5 + i] = (size_t)i < n ? (uint8_t)txt[k][i] : (size_t)i == n ? 0x0a : 0x20;
+ }
+ e[108 + 3] = 0x10; /* dummy descriptor */
+ unsigned sum = 0;
+ for (int i = 0; i < 127; i++) sum += e[i];
+ e[127] = (uint8_t)(256 - sum % 256);
+}
+
+static const char *PCI_IDS =
+ "# pci.ids (a few lines)\n"
+ "1002 Advanced Micro Devices, Inc. [AMD/ATI]\n"
+ "\t67df Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]\n"
+ "\t\t1002 0b31 Radeon RX 580\n"
+ "\tab38 Navi 10 HDMI Audio\n"
+ "10de NVIDIA Corporation\n"
+ "\t2684 AD102 [GeForce RTX 4090]\n"
+ "144d Samsung Electronics Co Ltd\n"
+ "\ta808 NVMe SSD Controller SM981/PM981/PM983\n"
+ "1af4 Red Hat, Inc.\n"
+ "\t1050 Virtio 1.0 GPU\n"
+ "8086 Intel Corporation\n"
+ "\t9a49 TigerLake-LP GT2 [Iris Xe Graphics]\n"
+ "\t2725 Wi-Fi 6E(802.11ax) AX210/AX1675* 2x2 [Typhoon Peak]\n"
+ "C 02 Network controller\n"
+ "\t80 Network controller\n"
+ "C 03 Display controller\n"
+ "\t00 VGA compatible controller\n"
+ "\t80 Display controller\n"
+ "C 01 Mass storage controller\n"
+ "\t08 Non-Volatile memory controller\n";
+
+static const char *USB_IDS =
+ "046d Logitech, Inc.\n"
+ "\tc52b Unifying Receiver\n"
+ "0bda Realtek Semiconductor Corp.\n"
+ "\t8153 RTL8153 Gigabit Ethernet Adapter\n"
+ "C 00 (Defined at Interface level)\n";
+
+/* the things no report may carry */
+static const char *SECRETS[] = { "SECRET", "secret", "deadbeef", "DEADBEEF", "de:ad:be:ef", "4c4c4544", "enxdeadbeef", "SECRETMON", "secretuser", "/home/" };
+
+static void common_secrets(const char *r) {
+ put(r, "proc/sys/kernel/hostname", "secret-host\n");
+ put(r, "sys/class/dmi/id/product_serial", "SECRET-SERIAL-123\n");
+ put(r, "sys/class/dmi/id/product_uuid", "4c4c4544-0042-3510-8051-b7c04f4d4d32\n");
+ put(r, "sys/class/dmi/id/board_serial", "SECRET-BOARD\n");
+ put(r, "sys/class/dmi/id/chassis_serial", "SECRET-CHASSIS\n");
+ put(r, "etc/hostname", "secret-host\n");
+ put(r, "etc/passwd", "secretuser:x:1000:1000:Secret User,,,:/home/secretuser:/bin/bash\n");
+}
+
+static void kernel(const char *r, const char *rel) {
+ char p[256];
+ put(r, "proc/sys/kernel/osrelease", rel);
+ snprintf(p, sizeof p, "boot/config-%s", rel);
+ put(r, p, "#\n# Linux kernel config\n#\nCONFIG_SECURITY_LANDLOCK=y\nCONFIG_BPF_SYSCALL=y\n# CONFIG_BPF_LSM is not set\nCONFIG_ZRAM=m\nCONFIG_USER_NS=y\n");
+ put(r, "sys/kernel/security/lsm", "lockdown,capability,landlock,yama,apparmor,bpf");
+ put(r, "sys/fs/cgroup/cgroup.controllers", "cpu memory io pids");
+ put(r, "etc/os-release", "PRETTY_NAME=\"Debian GNU/Linux 13 (trixie)\"\nID=debian\nVERSION_ID=\"13\"\n");
+ put(r, "usr/share/misc/pci.ids", PCI_IDS);
+ put(r, "usr/share/misc/usb.ids", USB_IDS);
+}
+
+static void cpus(const char *r, int threads, int per_core) {
+ for (int i = 0; i < threads; i++) {
+ char p[256], v[16];
+ snprintf(p, sizeof p, "sys/devices/system/cpu/cpu%d/topology/core_id", i);
+ snprintf(v, sizeof v, "%d\n", i / per_core);
+ put(r, p, v);
+ snprintf(p, sizeof p, "sys/devices/system/cpu/cpu%d/topology/physical_package_id", i);
+ put(r, p, "0\n");
+ }
+ put(r, "sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq", "800000\n");
+ put(r, "sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "4200000\n");
+ put(r, "sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", "schedutil\n");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index0/level", "1"); put(r, "sys/devices/system/cpu/cpu0/cache/index0/type", "Data");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index0/size", "32K");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index1/level", "1"); put(r, "sys/devices/system/cpu/cpu0/cache/index1/type", "Instruction");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index1/size", "32K");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index2/level", "2"); put(r, "sys/devices/system/cpu/cpu0/cache/index2/type", "Unified");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index2/size", "512K");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index3/level", "3"); put(r, "sys/devices/system/cpu/cpu0/cache/index3/type", "Unified");
+ put(r, "sys/devices/system/cpu/cpu0/cache/index3/size", "32768K");
+}
+
+/* a PCI device under /sys/bus/pci/devices */
+static void pcidev(const char *r, const char *slot, const char *ven, const char *dev, const char *cls, const char *drv) {
+ char d[256], f[300];
+ snprintf(d, sizeof d, "sys/bus/pci/devices/%s", slot);
+ snprintf(f, sizeof f, "%s/vendor", d); put(r, f, ven);
+ snprintf(f, sizeof f, "%s/device", d); put(r, f, dev);
+ snprintf(f, sizeof f, "%s/class", d); put(r, f, cls);
+ if (drv) driver(r, d, drv);
+}
+
+/* a DRM card: device ids (or none for a platform GPU), driver, a render node and connectors */
+static void card(const char *r, int n, const char *ven, const char *dev, const char *drv, int render, int boot) {
+ char d[256], f[300];
+ snprintf(d, sizeof d, "sys/class/drm/card%d/device", n);
+ if (ven) { snprintf(f, sizeof f, "%s/vendor", d); put(r, f, ven); snprintf(f, sizeof f, "%s/device", d); put(r, f, dev); }
+ if (boot) { snprintf(f, sizeof f, "%s/boot_vga", d); put(r, f, "1\n"); }
+ driver(r, d, drv);
+ if (render) { snprintf(f, sizeof f, "%s/drm/renderD%d/dev", d, 128 + n); put(r, f, "226:128\n"); }
+ snprintf(f, sizeof f, "%s/serial", d); put(r, f, "SECRET-GPU\n");
+}
+
+static void conn(const char *r, int n, const char *name, int connected, const uint8_t *ed, const char *modes) {
+ char d[256], f[300];
+ snprintf(d, sizeof d, "sys/class/drm/card%d-%s", n, name);
+ snprintf(f, sizeof f, "%s/status", d); put(r, f, connected ? "connected\n" : "disconnected\n");
+ snprintf(f, sizeof f, "%s/enabled", d); put(r, f, connected ? "enabled\n" : "disabled\n");
+ if (ed) { snprintf(f, sizeof f, "%s/edid", d); putn(r, f, ed, 128); }
+ if (modes) { snprintf(f, sizeof f, "%s/modes", d); put(r, f, modes); }
+}
+
+static void netif(const char *r, const char *name, const char *drv, int wifi, const char *speed) {
+ char d[256], f[300];
+ snprintf(d, sizeof d, "sys/class/net/%s", name);
+ snprintf(f, sizeof f, "%s/address", d); put(r, f, "de:ad:be:ef:00:01\n");
+ snprintf(f, sizeof f, "%s/type", d); put(r, f, "1\n");
+ snprintf(f, sizeof f, "%s/operstate", d); put(r, f, speed ? "up\n" : "down\n");
+ if (speed) { snprintf(f, sizeof f, "%s/speed", d); put(r, f, speed); }
+ if (drv) { snprintf(f, sizeof f, "%s/device", d); driver(r, f, drv); }
+ if (wifi) { snprintf(f, sizeof f, "%s/wireless/x", d); put(r, f, ""); }
+}
+
+static void disk(const char *r, const char *name, const char *model, const char *sectors, int rot, const char *link) {
+ char d[256], f[300];
+ snprintf(d, sizeof d, "sys/block/%s", name);
+ if (link) { /* sdX is a link into the device tree: its path says the bus */
+ char real[256];
+ snprintf(real, sizeof real, "sys/devices/%s/block/%s", link, name);
+ snprintf(f, sizeof f, "%s/size", real); put(r, f, sectors);
+ snprintf(f, sizeof f, "../devices/%s/block/%s", link, name);
+ lnk(r, d, f);
+ } else {
+ snprintf(f, sizeof f, "%s/size", d); put(r, f, sectors);
+ }
+ snprintf(f, sizeof f, "%s/queue/rotational", d); put(r, f, rot ? "1\n" : "0\n");
+ snprintf(f, sizeof f, "%s/removable", d); put(r, f, "0\n");
+ snprintf(f, sizeof f, "%s/device/model", d); put(r, f, model);
+ snprintf(f, sizeof f, "%s/device/serial", d); put(r, f, "SECRET-DISK\n");
+ snprintf(f, sizeof f, "%s/device/wwid", d); put(r, f, "eui.SECRET0000\n");
+}
+
+static void fixture(const char *r, const char *kind) {
+ uint8_t ed[128];
+ common_secrets(r);
+ kernel(r, "6.12.43+deb13-amd64");
+ put(r, "proc/meminfo", "MemTotal: 32768000 kB\nMemFree: 1 kB\nSwapTotal: 2097148 kB\n");
+ put(r, "proc/asound/cards", " 0 [Generic ]: HDA-Intel - HD-Audio Generic\n HD-Audio Generic at 0xfcd00000 irq 89\n");
+ put(r, "run/lordos/netperm.sock", "");
+ if (!strcmp(kind, "amd")) {
+ put(r, "sys/class/dmi/id/sys_vendor", "Micro-Star International Co., Ltd.\n");
+ put(r, "sys/class/dmi/id/product_name", "MS-7C02\n");
+ put(r, "sys/class/dmi/id/product_version", "To be filled by O.E.M.\n");
+ put(r, "sys/class/dmi/id/board_vendor", "Micro-Star International Co., Ltd.\n");
+ put(r, "sys/class/dmi/id/board_name", "B450 TOMAHAWK MAX (MS-7C02)\n");
+ put(r, "sys/class/dmi/id/chassis_type", "3\n");
+ put(r, "sys/class/dmi/id/bios_vendor", "American Megatrends Inc.\n");
+ put(r, "sys/class/dmi/id/bios_version", "3.J0\n");
+ put(r, "sys/class/dmi/id/bios_date", "11/23/2023\n");
+ uint8_t sb[5] = { 6, 0, 0, 0, 1 };
+ putn(r, "sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c", sb, 5);
+ put(r, "proc/cpuinfo", "processor\t: 0\nvendor_id\t: AuthenticAMD\nmodel name\t: AMD Ryzen 7 5800X 8-Core Processor\n"
+ "microcode\t: 0xa201205\nflags\t\t: fpu sse4_2 avx avx2 fma aes sha_ni\n");
+ cpus(r, 16, 2);
+ card(r, 0, "0x1002", "0x67df", "amdgpu", 1, 1);
+ edid(ed, "DEL", 0xa0c4, "DELL U2720Q", "SECRETMON01", 3840, 2160, 60, 34, 2021);
+ conn(r, 0, "DP-1", 1, ed, "3840x2160\n2560x1440\n");
+ conn(r, 0, "HDMI-A-1", 0, NULL, NULL);
+ pcidev(r, "0000:0a:00.0", "0x1002", "0x67df", "0x030000", "amdgpu");
+ pcidev(r, "0000:0a:00.1", "0x1002", "0xab38", "0x040300", "snd_hda_intel");
+ pcidev(r, "0000:01:00.0", "0x144d", "0xa808", "0x010802", "nvme");
+ disk(r, "nvme0n1", "Samsung SSD 970 EVO Plus 1TB\n", "1953525168\n", 0, NULL);
+ put(r, "sys/block/nvme0n1/device/device/current_link_speed", "8.0 GT/s PCIe\n");
+ put(r, "sys/block/nvme0n1/device/device/current_link_width", "4\n");
+ disk(r, "sda", "WDC WD40EFRX-68N\n", "7814037168\n", 1, "pci0000:00/0000:00:01.3/ata1/host0/target0:0:0/0:0:0:0");
+ disk(r, "loop0", "", "1000\n", 0, NULL);
+ netif(r, "enp5s0", "r8169", 0, "1000\n");
+ netif(r, "docker0", NULL, 0, NULL);
+ put(r, "sys/bus/usb/devices/usb1/idVendor", "1d6b\n");
+ put(r, "sys/bus/usb/devices/1-2/idVendor", "046d\n"); put(r, "sys/bus/usb/devices/1-2/idProduct", "c52b\n");
+ put(r, "sys/bus/usb/devices/1-2/speed", "12\n"); put(r, "sys/bus/usb/devices/1-2/bDeviceClass", "00\n");
+ put(r, "sys/bus/usb/devices/1-2/serial", "SECRET-USB\n"); put(r, "sys/bus/usb/devices/1-2/product", "secretuser's receiver\n");
+ driver(r, "sys/bus/usb/devices/1-2/1-2:1.0", "usbhid");
+ put(r, "sys/class/hwmon/hwmon0/name", "k10temp"); put(r, "sys/class/hwmon/hwmon0/temp1_input", "41250");
+ put(r, "sys/class/hwmon/hwmon1/name", "nct6797"); put(r, "sys/class/hwmon/hwmon1/fan1_input", "900");
+ put(r, "sys/class/hwmon/hwmon1/fan2_input", "0");
+ } else if (!strcmp(kind, "intel")) {
+ put(r, "sys/class/dmi/id/sys_vendor", "LENOVO\n");
+ put(r, "sys/class/dmi/id/product_name", "20XW0026US\n");
+ put(r, "sys/class/dmi/id/product_version", "ThinkPad X1 Carbon Gen 9\n");
+ put(r, "sys/class/dmi/id/chassis_type", "10\n");
+ put(r, "sys/class/dmi/id/bios_vendor", "LENOVO\n");
+ put(r, "sys/firmware/efi/x", "");
+ put(r, "proc/cpuinfo", "processor\t: 0\nvendor_id\t: GenuineIntel\nmodel name\t: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz\n"
+ "flags\t\t: fpu sse4_2 avx avx2 avx512f fma aes vaes\n");
+ cpus(r, 8, 2);
+ card(r, 0, "0x8086", "0x9a49", "i915", 1, 1);
+ edid(ed, "AUO", 0x2336, "", "SECRETMON02", 1920, 1200, 30, 19, 2020);
+ conn(r, 0, "eDP-1", 1, ed, "1920x1200\n");
+ pcidev(r, "0000:00:02.0", "0x8086", "0x9a49", "0x030000", "i915");
+ pcidev(r, "0000:00:14.3", "0x8086", "0x2725", "0x028000", "iwlwifi");
+ netif(r, "wlp0s20f3", "iwlwifi", 1, "866\n");
+ netif(r, "enxdeadbeef0001", "r8152", 0, "1000\n"); /* the name carries the MAC */
+ put(r, "sys/class/power_supply/BAT0/type", "Battery\n");
+ put(r, "sys/class/power_supply/BAT0/manufacturer", "SMP\n");
+ put(r, "sys/class/power_supply/BAT0/model_name", "5B10W13975\n");
+ put(r, "sys/class/power_supply/BAT0/technology", "Li-poly\n");
+ put(r, "sys/class/power_supply/BAT0/capacity", "76\n");
+ put(r, "sys/class/power_supply/BAT0/status", "Discharging\n");
+ put(r, "sys/class/power_supply/BAT0/energy_full", "45000000\n");
+ put(r, "sys/class/power_supply/BAT0/energy_full_design", "57000000\n");
+ put(r, "sys/class/power_supply/BAT0/serial_number", "SECRET-BAT\n");
+ put(r, "sys/class/power_supply/AC/type", "Mains\n");
+ put(r, "sys/class/power_supply/AC/online", "0\n");
+ put(r, "sys/class/power_supply/hidpp_battery_0/type", "Battery\n");
+ put(r, "sys/class/power_supply/hidpp_battery_0/scope", "Device\n");
+ put(r, "sys/class/bluetooth/hci0/address", "de:ad:be:ef:00:02\n");
+ driver(r, "sys/class/bluetooth/hci0/device", "btusb");
+ put(r, "sys/class/bluetooth/hci0:256/x", "");
+ put(r, "sys/class/thermal/thermal_zone0/type", "x86_pkg_temp"); put(r, "sys/class/thermal/thermal_zone0/temp", "52000");
+ } else if (!strcmp(kind, "nvidia")) {
+ put(r, "sys/class/dmi/id/sys_vendor", "ASUS\n");
+ put(r, "sys/class/dmi/id/chassis_type", "7\n");
+ put(r, "proc/cpuinfo", "processor\t: 0\nvendor_id\t: GenuineIntel\nmodel name\t: Intel(R) Core(TM) i9-10900\nflags\t\t: avx2\n");
+ cpus(r, 20, 2);
+ card(r, 0, "0x10de", "0x2684", "nouveau", 1, 1);
+ conn(r, 0, "DP-1", 0, NULL, NULL);
+ pcidev(r, "0000:01:00.0", "0x10de", "0x2684", "0x030000", "nouveau");
+ } else if (!strcmp(kind, "rpi5")) {
+ putn(r, "proc/device-tree/model", "Raspberry Pi 5 Model B Rev 1.0", 31);
+ putn(r, "proc/device-tree/compatible", "raspberrypi,5-model-b\0brcm,bcm2712\0", 36);
+ put(r, "proc/cpuinfo", "processor\t: 0\nBogoMIPS\t: 108.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics\n"
+ "CPU implementer\t: 0x41\nCPU part\t: 0xd0b\n\nprocessor\t: 1\n\n"
+ "Revision\t: d04170\nSerial\t\t: 10000000deadbeef\nModel\t\t: Raspberry Pi 5 Model B Rev 1.0\n");
+ cpus(r, 4, 1);
+ put(r, "proc/sys/kernel/arch", "aarch64\n");
+ card(r, 0, NULL, NULL, "v3d", 1, 0);
+ card(r, 1, NULL, NULL, "vc4-drm", 0, 0);
+ edid(ed, "SAM", 0x7155, "LS27A600U", "SECRETMON03", 2560, 1440, 60, 34, 2022);
+ conn(r, 1, "HDMI-A-1", 1, ed, "2560x1440\n");
+ conn(r, 1, "HDMI-A-2", 0, NULL, NULL);
+ conn(r, 1, "Writeback-1", 0, NULL, NULL);
+ disk(r, "mmcblk0", "", "62333952\n", 0, NULL);
+ disk(r, "mmcblk0boot0", "", "8192\n", 0, NULL);
+ put(r, "sys/devices/platform/soc@107c000000/soc@107c000000:firmware/get_throttled", "0x50000\n");
+ put(r, "sys/block/zram0/disksize", "2147483648\n");
+ put(r, "sys/block/zram0/comp_algorithm", "lzo lzo-rle lz4 [zstd]\n");
+ put(r, "sys/class/hwmon/hwmon2/name", "pwmfan"); put(r, "sys/class/hwmon/hwmon2/fan1_input", "2900");
+ } else if (!strcmp(kind, "vm")) {
+ put(r, "sys/class/dmi/id/sys_vendor", "QEMU\n");
+ put(r, "sys/class/dmi/id/product_name", "Standard PC (Q35 + ICH9, 2009)\n");
+ put(r, "sys/class/dmi/id/chassis_type", "1\n");
+ put(r, "sys/class/dmi/id/bios_vendor", "SeaBIOS\n");
+ put(r, "proc/cpuinfo", "processor\t: 0\nvendor_id\t: GenuineIntel\nmodel name\t: Intel Xeon Processor (Skylake, IBRS)\n"
+ "flags\t\t: fpu sse4_2 avx avx2 hypervisor\n");
+ cpus(r, 4, 1);
+ card(r, 0, "0x1af4", "0x1050", "virtio-pci", 0, 1);
+ conn(r, 0, "Virtual-1", 1, NULL, "1280x800\n1024x768\n");
+ disk(r, "vda", "", "67108864\n", 1, NULL);
+ netif(r, "ens18", "virtio_net", 0, "-1\n");
+ }
+}
+
+static int contains(const char *hay, const char *needle) { return hay && strstr(hay, needle) != NULL; }
+
+/* Collects the tree, checks the JSON parses and holds no secret; returns the report and its texts. */
+static SysReport *run(const char *root, char **json, char **md) {
+ SysReport *r = calloc(1, sizeof *r);
+ sysreport_collect(r, root, NULL, NULL);
+ snprintf(r->sw.lordos, sizeof r->sw.lordos, "0.8.5-beta");
+ *json = sysreport_json(r);
+ *md = sysreport_markdown(r);
+ JDoc doc;
+ char err[128] = "";
+ CHECK(*json && !json_parse(*json, strlen(*json), &doc, err, sizeof err), "%s: JSON invalid: %s", root, err);
+ if (*json && !err[0]) json_free(&doc);
+ for (size_t i = 0; i < sizeof SECRETS / sizeof SECRETS[0]; i++) {
+ CHECK(!contains(*json, SECRETS[i]), "%s: the JSON carries \"%s\"", root, SECRETS[i]);
+ CHECK(!contains(*md, SECRETS[i]), "%s: the Markdown carries \"%s\"", root, SECRETS[i]);
+ }
+ return r;
+}
+
+static void test_ids(void) {
+ char path[] = "/tmp/sysreport-ids-XXXXXX";
+ int fd = mkstemp(path);
+ if (fd < 0 || write(fd, PCI_IDS, strlen(PCI_IDS)) != (ssize_t)strlen(PCI_IDS)) { printf("mkstemp\n"); exit(2); }
+ close(fd);
+ IdsDb db;
+ CHECK(!ids_open(&db, path), "ids_open");
+ char v[96], d[96];
+ ids_lookup(&db, "1002", "67df", v, sizeof v, d, sizeof d);
+ CHECK(!strcmp(v, "Advanced Micro Devices, Inc. [AMD/ATI]") && !strcmp(d, "Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]"), "ids amd: %s / %s", v, d);
+ ids_lookup(&db, "10DE", "2684", v, sizeof v, d, sizeof d);
+ CHECK(!strcmp(v, "NVIDIA Corporation") && !strcmp(d, "AD102 [GeForce RTX 4090]"), "ids uppercase: %s / %s", v, d);
+ ids_lookup(&db, "1002", "2684", v, sizeof v, d, sizeof d); /* another vendor's device */
+ CHECK(!strcmp(v, "Advanced Micro Devices, Inc. [AMD/ATI]") && !d[0], "ids no device across vendors: %s", d);
+ ids_lookup(&db, "1002", "0b31", v, sizeof v, d, sizeof d); /* a subsystem line, not a device */
+ CHECK(!d[0], "ids subsystem is not a device: %s", d);
+ ids_lookup(&db, "dead", "beef", v, sizeof v, d, sizeof d);
+ CHECK(!v[0] && !d[0], "ids unknown");
+ ids_lookup(&db, "10d", "2684", v, sizeof v, d, sizeof d);
+ CHECK(!v[0], "ids short vendor id");
+ char cn[48], sn[48];
+ ids_pci_class(&db, "030000", cn, sizeof cn, sn, sizeof sn);
+ CHECK(!strcmp(cn, "Display controller") && !strcmp(sn, "VGA compatible controller"), "class: %s / %s", cn, sn);
+ ids_pci_class(&db, "028000", cn, sizeof cn, sn, sizeof sn);
+ CHECK(!strcmp(cn, "Network controller") && !strcmp(sn, "Network controller"), "class 0280: %s / %s", cn, sn);
+ ids_pci_class(&db, "0c0330", cn, sizeof cn, sn, sizeof sn);
+ CHECK(!cn[0] && !sn[0], "class unknown");
+ ids_close(&db);
+ unlink(path);
+ CHECK(ids_open(&db, "/nonexistent/pci.ids") == -1, "ids missing file");
+ ids_lookup(&db, "1002", "67df", v, sizeof v, d, sizeof d);
+ CHECK(!v[0] && !d[0], "ids lookups on an empty db");
+}
+
+static void rmtree(const char *dir) {
+ char cmd[1200];
+ snprintf(cmd, sizeof cmd, "rm -rf '%s'", dir);
+ if (system(cmd)) printf("cannot remove %s\n", dir);
+}
+
+static void test_kind(const char *kind) {
+ char root[] = "/tmp/sysreport-test-XXXXXX";
+ if (!mkdtemp(root)) { printf("mkdtemp\n"); exit(2); }
+ fixture(root, kind);
+ char *json, *md;
+ SysReport *r = run(root, &json, &md);
+ CHECK(r->schema == 1 && strlen(r->date) == 10, "%s: schema/date", kind);
+ CHECK(!strcmp(r->sw.os, "Debian GNU/Linux 13 (trixie)") && !strcmp(r->sw.os_version, "13"), "%s: os %s", kind, r->sw.os);
+ CHECK(r->sw.landlock_abi == -1, "%s: landlock unknown under a fake root", kind);
+ CHECK(r->sw.bpf_lsm && r->sw.cgroup2 && r->sw.netperm && !r->sw.fand, "%s: lsm/cgroup/services", kind);
+ int ll = 0, bl = 0, zr = 0;
+ for (int i = 0; i < r->sw.nkconf; i++) {
+ if (!strcmp(r->sw.kconf[i].name, "CONFIG_SECURITY_LANDLOCK")) ll = !strcmp(r->sw.kconf[i].value, "y");
+ if (!strcmp(r->sw.kconf[i].name, "CONFIG_BPF_LSM")) bl = !strcmp(r->sw.kconf[i].value, "n");
+ if (!strcmp(r->sw.kconf[i].name, "CONFIG_ZRAM")) zr = !strcmp(r->sw.kconf[i].value, "m");
+ }
+ CHECK(ll && bl && zr, "%s: kernel config", kind);
+ CHECK(r->naudio == 1 && !strcmp(r->audio[0], "HD-Audio Generic"), "%s: audio %s", kind, r->audio[0]);
+ CHECK(contains(md, "# System report") && contains(md, "| LordOS | 0.8.5-beta |"), "%s: markdown head", kind);
+
+ if (!strcmp(kind, "amd")) {
+ CHECK(!strcmp(r->machine.vendor, "Micro-Star International Co., Ltd.") && !r->machine.version[0], "amd: dmi (placeholder dropped)");
+ CHECK(!strcmp(r->machine.chassis, "desktop") && !strcmp(r->machine.firmware, "uefi") && r->machine.secure_boot == 1, "amd: chassis/firmware/sb");
+ CHECK(!r->machine.virt[0], "amd: bare metal");
+ CHECK(r->cpu.threads == 16 && r->cpu.cores == 8 && r->cpu.sockets == 1, "amd: topology %d/%d/%d", r->cpu.sockets, r->cpu.cores, r->cpu.threads);
+ CHECK(r->cpu.max_mhz == 4200 && r->cpu.min_mhz == 800 && !strcmp(r->cpu.governor, "schedutil"), "amd: freq");
+ CHECK(r->cpu.l1d_kb == 32 && r->cpu.l2_kb == 512 && r->cpu.l3_kb == 32768, "amd: caches");
+ CHECK(!strcmp(r->cpu.flags, "sse4_2 avx avx2 fma aes sha_ni"), "amd: flags \"%s\"", r->cpu.flags);
+ CHECK(r->mem.total_kb == 32768000 && r->mem.swap_kb == 2097148 && !r->mem.zram_n, "amd: memory");
+ CHECK(r->ngpu == 1 && !strcmp(r->gpu[0].driver, "amdgpu") && r->gpu[0].render_node && r->gpu[0].boot_vga
+ && r->gpu[0].connectors == 2 && r->gpu[0].connected == 1 && !strcmp(r->gpu[0].bus, "pci"), "amd: gpu");
+ CHECK(contains(r->gpu[0].device, "Radeon RX 470/480/570"), "amd: gpu name %s", r->gpu[0].device);
+ CHECK(r->ndisplay == 1 && !strcmp(r->display[0].name, "DELL U2720Q") && !strcmp(r->display[0].pnp, "DEL")
+ && r->display[0].pref_w == 3840 && r->display[0].year == 2021 && r->display[0].diag_tenths > 270
+ && !strcmp(r->display[0].connector, "DP-1") && !strcmp(r->display[0].mode, "3840x2160"), "amd: display");
+ CHECK(r->ndisk == 2 && !strcmp(r->disk[0].name, "nvme0n1") && !strcmp(r->disk[0].transport, "nvme")
+ && !strcmp(r->disk[0].link, "8.0 GT/s PCIe x4") && !strcmp(r->disk[1].transport, "sata") && r->disk[1].rotational, "amd: disks");
+ CHECK(r->npci == 3 && !strcmp(r->pci[0].class_name, "Non-Volatile memory controller") && !strcmp(r->pci[0].driver, "nvme"), "amd: pci");
+ CHECK(r->nusb == 1 && !strcmp(r->usb[0].product, "Unifying Receiver") && !strcmp(r->usb[0].driver, "usbhid") && r->usb[0].speed_mbps == 12, "amd: usb");
+ CHECK(r->nnet == 2 && !strcmp(r->net[0].kind, "virtual") && !strcmp(r->net[1].kind, "ethernet") && r->net[1].speed_mbps == 1000, "amd: net");
+ int fans = 0;
+ for (int i = 0; i < r->nthermal; i++) fans += r->thermal[i].fans;
+ CHECK(r->nthermal == 2 && r->thermal[0].milli_c == 41250 && fans == 2, "amd: thermal");
+ CHECK(!r->pi.is_pi && !contains(json, "raspberryPi"), "amd: no Pi");
+ } else if (!strcmp(kind, "intel")) {
+ CHECK(!strcmp(r->machine.chassis, "laptop") && !strcmp(r->machine.version, "ThinkPad X1 Carbon Gen 9") && r->machine.secure_boot == -1, "intel: machine");
+ CHECK(!strcmp(r->cpu.flags, "sse4_2 avx avx2 fma avx512f aes vaes"), "intel: flags %s", r->cpu.flags);
+ CHECK(r->ndisplay == 1 && !r->display[0].name[0] && !strcmp(r->display[0].pnp, "AUO") && contains(md, "| eDP-1 | AUO, 2020 |"), "intel: panel");
+ CHECK(r->nnet == 2 && !strcmp(r->net[0].kind, "ethernet") && !strcmp(r->net[0].driver, "r8152")
+ && !strcmp(r->net[1].kind, "wifi") && !strcmp(r->net[1].driver, "iwlwifi"), "intel: net %s %s", r->net[0].kind, r->net[1].kind);
+ CHECK(r->npower == 2 && !strcmp(r->power[0].kind, "ac") && r->power[0].online == 0
+ && !strcmp(r->power[1].kind, "battery") && r->power[1].capacity == 76 && r->power[1].health == 78, "intel: power");
+ CHECK(contains(md, "holds 78 % of its design charge"), "intel: markdown battery");
+ CHECK(r->nbt == 1 && !strcmp(r->bt_driver[0], "btusb"), "intel: bluetooth");
+ CHECK(contains(r->pci[1].class_name, "Network controller") && contains(r->pci[1].device, "AX210"), "intel: wifi pci");
+ } else if (!strcmp(kind, "nvidia")) {
+ CHECK(r->ngpu == 1 && !strcmp(r->gpu[0].vendor, "NVIDIA Corporation") && !strcmp(r->gpu[0].driver, "nouveau") && !r->gpu[0].connected, "nvidia: gpu");
+ CHECK(r->cpu.cores == 10 && r->cpu.threads == 20 && !strcmp(r->machine.chassis, "desktop"), "nvidia: cpu/chassis");
+ CHECK(!r->ndisplay && !contains(md, "## Displays"), "nvidia: no displays");
+ } else if (!strcmp(kind, "rpi5")) {
+ CHECK(r->pi.is_pi && !strcmp(r->pi.revision, "d04170") && r->pi.throttled == 0x50000, "rpi5: pi %s %x", r->pi.revision, r->pi.throttled);
+ CHECK(!strcmp(r->machine.firmware, "dt") && !strcmp(r->machine.model, "Raspberry Pi 5 Model B Rev 1.0"), "rpi5: machine");
+ CHECK(!strcmp(r->cpu.vendor, "ARM") && !strcmp(r->cpu.model, "Cortex-A76") && !strcmp(r->cpu.arch, "aarch64"), "rpi5: cpu %s %s", r->cpu.vendor, r->cpu.model);
+ CHECK(!strcmp(r->cpu.flags, "asimd aes sha2 crc32 atomics"), "rpi5: features %s", r->cpu.flags);
+ CHECK(r->ngpu == 2 && !strcmp(r->gpu[0].bus, "platform") && !strcmp(r->gpu[0].driver, "v3d") && r->gpu[0].render_node
+ && !strcmp(r->gpu[1].driver, "vc4-drm") && r->gpu[1].connectors == 2 && r->gpu[1].connected == 1, "rpi5: gpus");
+ CHECK(r->ndisplay == 1 && !strcmp(r->display[0].card, "card1") && !strcmp(r->display[0].name, "LS27A600U"), "rpi5: display");
+ CHECK(r->ndisk == 1 && !strcmp(r->disk[0].transport, "mmc"), "rpi5: sd card (boot partitions skipped)");
+ CHECK(r->mem.zram_n == 1 && r->mem.zram_kb[0] == 2097152 && !strcmp(r->mem.zram_algo[0], "zstd"), "rpi5: zram");
+ CHECK(contains(json, "\"raspberryPi\":{") && contains(md, "under-voltage or throttling seen (0x50000)"), "rpi5: report");
+ } else if (!strcmp(kind, "vm")) {
+ CHECK(!strcmp(r->machine.virt, "kvm") && !strcmp(r->machine.chassis, "vm") && !strcmp(r->machine.firmware, "bios"), "vm: virt %s %s", r->machine.virt, r->machine.chassis);
+ CHECK(r->ngpu == 1 && !strcmp(r->gpu[0].device, "Virtio 1.0 GPU") && !r->gpu[0].render_node, "vm: gpu");
+ CHECK(r->ndisplay == 1 && !r->display[0].pref_w && contains(md, "| Virtual-1 | — | — | 1280x800 |"), "vm: display without EDID");
+ CHECK(r->ndisk == 1 && !strcmp(r->disk[0].transport, "virtio") && r->nnet == 1 && r->net[0].speed_mbps == -1, "vm: disk/net");
+ CHECK(contains(json, "\"speedMbps\":null"), "vm: unknown speed is null");
+ }
+ free(json);
+ free(md);
+ free(r);
+ rmtree(root);
+}
+
+static void test_empty(void) {
+ char root[] = "/tmp/sysreport-empty-XXXXXX";
+ if (!mkdtemp(root)) { printf("mkdtemp\n"); exit(2); }
+ char *json, *md;
+ SysReport *r = run(root, &json, &md);
+ CHECK(!r->ngpu && !r->ndisk && !r->cpu.threads && contains(md, "none found"), "empty tree");
+ free(json); free(md); free(r);
+ rmtree(root);
+}
+
+int main(int argc, char **argv) {
+ if (argc == 4 && !strcmp(argv[1], "fixture")) {
+ mkdirs(argv[2]);
+ fixture(argv[2], argv[3]);
+ return 0;
+ }
+ test_ids();
+ const char *kinds[] = { "amd", "intel", "nvidia", "rpi5", "vm" };
+ for (size_t i = 0; i < sizeof kinds / sizeof kinds[0]; i++) test_kind(kinds[i]);
+ test_empty();
+ printf("sysreport-test: %d ok, %d failed\n", n_ok, n_bad);
+ return n_bad ? 1 : 0;
+}
diff --git a/tools/iso/mkdeb.sh b/tools/iso/mkdeb.sh
index 502ec2e..d5c170f 100755
--- a/tools/iso/mkdeb.sh
+++ b/tools/iso/mkdeb.sh
@@ -8,6 +8,7 @@
# /usr/lib/lordos/bin/lord-netd system networking (root; launched and watched by lord-sessiond)
# /usr/lib/lordos/bin/lord-fand fan control by temperature (root, own service, enabled)
# /usr/lib/lordos/bin/lord-server each session's server (looks for ../themes and ../assets)
+# /usr/bin/lordos-sysreport System Information's report as a command (user; docs/BENCHMARK.md)
# /usr/lib/lordos/themes/<theme>/ theme.json, theme.bundle.js and their resources (greeter: the
# login screen)
# /usr/lib/lordos/assets/ fonts, texts (locales), icons, shell integration
@@ -42,6 +43,7 @@ VERSION=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' package.json | head -1)
[ -x server/build/lord-netperm ] || { echo "missing server/build/lord-netperm (make -C server; clang for BPF)" >&2; exit 1; }
[ -x server/build/lord-netd ] || { echo "missing server/build/lord-netd (make -C server)" >&2; exit 1; }
[ -x server/build/lord-fand ] || { echo "missing server/build/lord-fand (make -C server)" >&2; exit 1; }
+[ -x server/build/lordos-sysreport ] || { echo "missing server/build/lordos-sysreport (make -C server)" >&2; exit 1; }
[ -x server/build/lord-sessiond ] || { echo "missing server/build/lord-sessiond (make -C server, with libssl-dev, libsrtp2-dev and libusrsctp-dev)" >&2; exit 1; }
[ -f themes/greeter/theme.bundle.js ] || { echo "missing the login screen (npm run build)" >&2; exit 1; }
for t in themes/*/theme.bundle.js; do [ -f "$t" ] || { echo "built themes missing (npm run build)" >&2; exit 1; }; done
@@ -57,6 +59,10 @@ install -m 755 server/build/lord-netperm "$L/bin/lord-netperm"
install -m 755 server/build/lord-fand "$L/bin/lord-fand"
# the LordOS Imager's first-run file applier (Raspberry Pi image, rpi/firstboot; docs/IMAGER.md)
install -m 755 server/build/lordos-firstrun "$L/bin/lordos-firstrun"
+# System Information's report for a terminal, SSH or CI; lord-server never runs it
+install -d "$PKG/usr/bin"
+install -m 755 server/build/lordos-sysreport "$PKG/usr/bin/lordos-sysreport"
+strip --strip-unneeded "$PKG/usr/bin/lordos-sysreport" 2>/dev/null || true
# isolated PDF and archive helper (optional: make skips it without libpoppler-glib-dev/libarchive-dev);
# lord-server only launches the lord-doc in its own folder
[ -x server/build/lord-doc ] && install -m 755 server/build/lord-doc "$L/bin/lord-doc"
@@ -245,7 +251,7 @@ Architecture: ${DEB_ARCH:-$(dpkg --print-architecture)}
Maintainer: LordOS <[email protected]>
Installed-Size: $SIZE
Depends: libc6 (>= 2.38), libwayland-server0 (>= 1.22), libwayland-client0 (>= 1.22), libxkbcommon0 (>= 1.5), libcrypt1, libssl3t64 | libssl3, ca-certificates, passwd, procps, xkb-data$GPUDEPS$DOCDEPS$MEDIADEPS$RTCDEPS
-Recommends: pipewire-pulse, wireplumber, wpasupplicant, openvpn, fonts-noto-core, locales, tzdata, sudo, cups, cups-client, avahi-daemon, mesa-va-drivers, bluez, libspa-0.2-bluetooth, power-profiles-daemon, systemd-timesyncd, shared-mime-info, gsettings-desktop-schemas, xwayland
+Recommends: pipewire-pulse, wireplumber, wpasupplicant, openvpn, fonts-noto-core, locales, tzdata, sudo, cups, cups-client, avahi-daemon, mesa-va-drivers, bluez, libspa-0.2-bluetooth, power-profiles-daemon, systemd-timesyncd, shared-mime-info, gsettings-desktop-schemas, xwayland, pci.ids, usb.ids
Section: x11
Priority: optional
Protected: yes