1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

bootctl-uki: several follow-ups for inspect_osrel()

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.
This commit is contained in:
Yu Watanabe 2023-01-25 11:05:46 +09:00 committed by Luca Boccassi
parent 903dd65b5e
commit 1b7586df97

View File

@ -4,6 +4,7 @@
#include "bootctl-uki.h" #include "bootctl-uki.h"
#include "env-file.h" #include "env-file.h"
#include "fd-util.h" #include "fd-util.h"
#include "os-util.h"
#include "parse-util.h" #include "parse-util.h"
#include "pe-header.h" #include "pe-header.h"
@ -159,50 +160,53 @@ static int read_pe_section(
return 0; 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_fclose_ FILE *s = NULL;
_cleanup_free_ char *pname = NULL, *name = NULL; _cleanup_free_ char *pname = NULL, *name = NULL;
int r; int r;
assert(osrel); assert(osrel || osrel_size == 0);
s = fmemopen(osrel, osrel_size, "r");
if (!osrel)
return 0;
s = fmemopen((void*) osrel, osrel_size, "r");
if (!s) 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, r = parse_env_file(s, NULL,
"PRETTY_NAME", &pname, "PRETTY_NAME", &pname,
"NAME", &name); "NAME", &name);
if (r < 0) 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", os_release_pretty_name(pname, name));
printf(" OS: %s\n", pname ?: name); return 0;
} }
static void inspect_uki(FILE *uki, struct PeSectionHeader *sections, size_t scount) { static void inspect_uki(FILE *uki, struct PeSectionHeader *sections, size_t scount) {
_cleanup_free_ char *cmdline = NULL; _cleanup_free_ char *cmdline = NULL, *uname = NULL;
_cleanup_free_ char *uname = NULL; _cleanup_free_ void *osrel = NULL;
_cleanup_free_ char *osrel = NULL; size_t osrel_size = 0, idx;
size_t osrel_size, idx;
assert(uki); assert(uki);
assert(sections || scount == 0); assert(sections || scount == 0);
if (find_pe_section(sections, scount, name_cmdline, sizeof(name_cmdline), &idx)) 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)) 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)) 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) if (cmdline)
printf(" Cmdline: %s\n", cmdline); printf(" Cmdline: %s\n", cmdline);
if (uname) if (uname)
printf(" Version: %s\n", 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) { int verb_kernel_inspect(int argc, char *argv[], void *userdata) {