]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl-uki: several follow-ups for inspect_osrel()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Jan 2023 02:05:46 +0000 (11:05 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 25 Jan 2023 10:51:38 +0000 (10:51 +0000)
Follow-ups for #26124 and #26158.

- use os_release_pretty_name(),
- constify the buffer passed to inspect_osrel(),
- propagate errors in inspect_osrele(), and ignore them in the caller
  side,
- and several coding style fixlets.

src/boot/bootctl-uki.c

index 97339680210d214e3be28b8b111b703b4d18e884..e304cad06ae1304cf7c7159bb0cb4b08dface950 100644 (file)
@@ -4,6 +4,7 @@
 #include "bootctl-uki.h"
 #include "env-file.h"
 #include "fd-util.h"
+#include "os-util.h"
 #include "parse-util.h"
 #include "pe-header.h"
 
@@ -159,50 +160,53 @@ static int read_pe_section(
         return 0;
 }
 
-static void inspect_osrel(char *osrel, size_t osrel_size) {
+static int inspect_osrel(const void *osrel, size_t osrel_size) {
         _cleanup_fclose_ FILE *s = NULL;
         _cleanup_free_ char *pname = NULL, *name = NULL;
         int r;
 
-        assert(osrel);
-        s = fmemopen(osrel, osrel_size, "r");
+        assert(osrel || osrel_size == 0);
+
+        if (!osrel)
+                return 0;
+
+        s = fmemopen((void*) osrel, osrel_size, "r");
         if (!s)
-                return (void) log_warning_errno(errno, "Failed to open embedded os-release file, ignoring: %m");
+                return log_warning_errno(errno, "Failed to open embedded os-release file, ignoring: %m");
 
         r = parse_env_file(s, NULL,
                            "PRETTY_NAME", &pname,
                            "NAME",        &name);
         if (r < 0)
-                return (void) log_warning_errno(r, "Failed to parse embedded os-release file, ignoring: %m");
+                return log_warning_errno(r, "Failed to parse embedded os-release file, ignoring: %m");
 
-        if (pname || name)
-                printf("         OS: %s\n", pname ?: name);
+        printf("         OS: %s\n", os_release_pretty_name(pname, name));
+        return 0;
 }
 
 static void inspect_uki(FILE *uki, struct PeSectionHeader *sections, size_t scount) {
-        _cleanup_free_ char *cmdline = NULL;
-        _cleanup_free_ char *uname = NULL;
-        _cleanup_free_ char *osrel = NULL;
-        size_t osrel_size, idx;
+        _cleanup_free_ char *cmdline = NULL, *uname = NULL;
+        _cleanup_free_ void *osrel = NULL;
+        size_t osrel_size = 0, idx;
 
         assert(uki);
         assert(sections || scount == 0);
 
         if (find_pe_section(sections, scount, name_cmdline, sizeof(name_cmdline), &idx))
-                read_pe_section(uki, sections + idx, (void**)&cmdline, NULL);
+                read_pe_section(uki, sections + idx, (void**) &cmdline, NULL);
 
         if (find_pe_section(sections, scount, name_uname, sizeof(name_uname), &idx))
-                read_pe_section(uki, sections + idx, (void**)&uname, NULL);
+                read_pe_section(uki, sections + idx, (void**) &uname, NULL);
 
         if (find_pe_section(sections, scount, name_osrel, sizeof(name_osrel), &idx))
-                read_pe_section(uki, sections + idx, (void**)&osrel, &osrel_size);
+                read_pe_section(uki, sections + idx, &osrel, &osrel_size);
 
         if (cmdline)
                 printf("    Cmdline: %s\n", cmdline);
         if (uname)
                 printf("    Version: %s\n", uname);
-        if (osrel)
-                inspect_osrel(osrel, osrel_size);
+
+        (void) inspect_osrel(osrel, osrel_size);
 }
 
 int verb_kernel_inspect(int argc, char *argv[], void *userdata) {