diff options
Diffstat (limited to '')
-rw-r--r-- | src/basic/fileio.c | 3 | ||||
-rw-r--r-- | src/basic/fileio.h | 10 | ||||
-rw-r--r-- | src/shared/bootspec.c | 38 | ||||
-rw-r--r-- | src/shared/bootspec.h | 9 |
4 files changed, 28 insertions, 32 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 52a29e2f7b..2d29c384cc 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -322,8 +322,7 @@ int write_string_file_full( mode_t mode = write_string_file_flags_to_mode(flags); if (FLAGS_SET(flags, WRITE_STRING_FILE_LABEL|WRITE_STRING_FILE_CREATE)) { - const char *lookup = label_fn ? label_fn : fn; - r = label_ops_pre(dir_fd, lookup, mode); + r = label_ops_pre(dir_fd, label_fn ?: fn, mode); if (r < 0) goto fail; diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 08017f8270..71ec6ba921 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -49,15 +49,15 @@ FILE* fmemopen_unlocked(void *buf, size_t size, const char *mode); int write_string_stream_full(FILE *f, const char *line, WriteStringFileFlags flags, const struct timespec *ts); static inline int write_string_stream(FILE *f, const char *line, WriteStringFileFlags flags) { - return write_string_stream_full(f, line, flags, /* ts= */ NULL); + return write_string_stream_full(f, line, flags, NULL); } int write_string_file_full(int dir_fd, const char *fn, const char *line, WriteStringFileFlags flags, const struct timespec *ts, const char *label_fn); -static inline int write_string_file(const char *fn, const char *line, WriteStringFileFlags flags) { - return write_string_file_full(AT_FDCWD, fn, line, flags, /* ts= */ NULL, /*label_fn=*/ NULL); -} static inline int write_string_file_at(int dir_fd, const char *fn, const char *line, WriteStringFileFlags flags) { - return write_string_file_full(dir_fd, fn, line, flags, /* ts= */ NULL, /*label_fn=*/ NULL); + return write_string_file_full(dir_fd, fn, line, flags, NULL, NULL); +} +static inline int write_string_file(const char *fn, const char *line, WriteStringFileFlags flags) { + return write_string_file_at(AT_FDCWD, fn, line, flags); } int write_string_filef(const char *fn, WriteStringFileFlags flags, const char *format, ...) _printf_(3, 4); diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 9c4877055a..12d2a9d147 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -58,7 +58,16 @@ static const char* const boot_entry_source_json_table[_BOOT_ENTRY_SOURCE_MAX] = DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source_json, BootEntrySource); -static void boot_entry_addons_done(BootEntryAddons *addons); +static void boot_entry_addons_done(BootEntryAddons *addons) { + assert(addons); + + FOREACH_ARRAY(addon, addons->items, addons->n_items) { + free(addon->cmdline); + free(addon->location); + } + addons->items = mfree(addons->items); + addons->n_items = 0; +} static void boot_entry_free(BootEntry *entry) { assert(entry); @@ -302,7 +311,7 @@ static int boot_entry_load_type1( const BootEntrySource source, const char *dir, const char *fname, - BootEntry *entry) { + BootEntry *ret) { _cleanup_(boot_entry_free) BootEntry tmp = BOOT_ENTRY_INIT(BOOT_ENTRY_CONF, source); char *c; @@ -312,7 +321,7 @@ static int boot_entry_load_type1( assert(root); assert(dir); assert(fname); - assert(entry); + assert(ret); /* Loads a Type #1 boot menu entry from the specified FILE* object */ @@ -402,7 +411,7 @@ static int boot_entry_load_type1( return log_syntax(NULL, LOG_ERR, tmp.path, line, r, "Error while parsing: %m"); } - *entry = TAKE_STRUCT(tmp); + *ret = TAKE_STRUCT(tmp); return 0; } @@ -421,7 +430,7 @@ int boot_config_load_type1( assert(dir); assert(fname); - if (!GREEDY_REALLOC0(config->entries, config->n_entries + 1)) + if (!GREEDY_REALLOC(config->entries, config->n_entries + 1)) return log_oom(); BootEntry *entry = config->entries + config->n_entries; @@ -429,10 +438,10 @@ int boot_config_load_type1( r = boot_entry_load_type1(f, root, source, dir, fname, entry); if (r < 0) return r; + config->n_entries++; entry->global_addons = &config->global_addons[source]; - config->n_entries++; return 0; } @@ -449,7 +458,7 @@ void boot_config_free(BootConfig *config) { boot_entry_free(i); free(config->entries); - FOREACH_ARRAY(i, config->global_addons, _BOOT_ENTRY_SOURCE_MAX) + FOREACH_ELEMENT(i, config->global_addons) boot_entry_addons_done(i); set_free(config->inodes_seen); @@ -1076,17 +1085,6 @@ static int insert_boot_entry_addon( return 0; } -static void boot_entry_addons_done(BootEntryAddons *addons) { - assert(addons); - - FOREACH_ARRAY(addon, addons->items, addons->n_items) { - free(addon->cmdline); - free(addon->location); - } - addons->items = mfree(addons->items); - addons->n_items = 0; -} - static int boot_entries_find_unified_addons( BootConfig *config, int d_fd, @@ -1242,12 +1240,12 @@ static int boot_entries_find_unified( if (r < 0) continue; - if (!GREEDY_REALLOC0(config->entries, config->n_entries + 1)) + if (!GREEDY_REALLOC(config->entries, config->n_entries + 1)) return log_oom(); BootEntry *entry = config->entries + config->n_entries; - if (boot_entry_load_unified(root, source, j, p, osrelease, profile, cmdline, config->entries + config->n_entries) < 0) + if (boot_entry_load_unified(root, source, j, p, osrelease, profile, cmdline, entry) < 0) continue; /* look for .efi.extra.d */ diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index 6dda8549a1..95675214b2 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -98,11 +98,11 @@ typedef struct BootConfig { .selected_entry = -1, \ } -const char* boot_entry_type_to_string(BootEntryType); -const char* boot_entry_type_json_to_string(BootEntryType); +const char* boot_entry_type_to_string(BootEntryType) _const_; +const char* boot_entry_type_json_to_string(BootEntryType) _const_; -const char* boot_entry_source_to_string(BootEntrySource); -const char* boot_entry_source_json_to_string(BootEntrySource); +const char* boot_entry_source_to_string(BootEntrySource) _const_; +const char* boot_entry_source_json_to_string(BootEntrySource) _const_; BootEntry* boot_config_find_entry(BootConfig *config, const char *id); @@ -137,7 +137,6 @@ int boot_config_select_special_entries(BootConfig *config, bool skip_efivars); static inline const char* boot_entry_title(const BootEntry *entry) { assert(entry); - return ASSERT_PTR(entry->show_title ?: entry->title ?: entry->id); } |