From 428acee867d151da65dafb269618f29b0261327e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 18 Feb 2020 17:35:58 +1000 Subject: tools: record: record basic os-release information as well Because sometimes it's useful to know what distro a recording was made on, and the kernel version doesn't always reveal that. Fixes #428 Signed-off-by: Peter Hutterer --- tools/libinput-record.c | 26 +++++++++++++++++++++++++- tools/libinput-record.man | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 00aabe94..fd1ba926 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -1429,7 +1429,7 @@ print_system_header(struct record_context *ctx) { struct utsname u; const char *kernel = "unknown"; - FILE *dmi; + FILE *dmi, *osrelease; char buf[2048] = "unknown"; if (uname(&u) != -1) @@ -1447,6 +1447,30 @@ print_system_header(struct record_context *ctx) iprintf(ctx, "system:\n"); indent_push(ctx); + + osrelease = fopen("/etc/os-release", "r"); + if (!osrelease) + fopen("/usr/lib/os-release", "r"); + if (osrelease) { + char *distro = NULL, *version = NULL; + + while (fgets(buf, sizeof(buf), osrelease)) { + buf[strlen(buf) - 1] = '\0'; /* linebreak */ + + if (!distro && strneq(buf, "ID=", 3)) + distro = safe_strdup(&buf[3]); + else if (!version && strneq(buf, "VERSION_ID=", 11)) + version = safe_strdup(&buf[11]); + + if (distro && version) { + iprintf(ctx, "os: \"%s:%s\"\n", distro, version); + break; + } + } + free(distro); + free(version); + fclose(osrelease); + } iprintf(ctx, "kernel: \"%s\"\n", kernel); iprintf(ctx, "dmi: \"%s\"\n", buf); indent_pop(ctx); diff --git a/tools/libinput-record.man b/tools/libinput-record.man index 17cf5d3e..a537d15f 100644 --- a/tools/libinput-record.man +++ b/tools/libinput-record.man @@ -106,6 +106,7 @@ ndevices: 2 libinput: version: 1.10.0 system: + os: "fedora:26" kernel: "4.13.9-200.fc26.x86_64" dmi: "dmi:bvnLENOVO:bvrGJET72WW(2.22):bd02/21/2014:svnLENOVO:..." devices: @@ -206,6 +207,9 @@ libinput version .SS system Information about the system .TP 8 +.B os: string +Distribution ID and version, see \fIos-release(5)\fR +.TP 8 .B kernel: string Kernel version, see \fIuname(1)\fR .TP 8 -- cgit v1.2.1