BootId **ret) {
_cleanup_free_ BootId *next_boot = NULL;
- char match[STRLEN("_BOOT_ID=") + SD_ID128_STRING_MAX] = "_BOOT_ID=";
sd_id128_t boot_id;
int r;
return r;
/* Now seek to the last occurrence of this boot ID. */
- sd_id128_to_string(next_boot->id, match + STRLEN("_BOOT_ID="));
- r = sd_journal_add_match(j, match, sizeof(match) - 1);
+ r = add_match_boot_id(j, next_boot->id);
if (r < 0)
return r;
* If no reference is given, the journal head/tail will do,
* they're "virtual" boots after all. */
if (boot_id && !sd_id128_is_null(*boot_id)) {
- char match[STRLEN("_BOOT_ID=") + SD_ID128_STRING_MAX] = "_BOOT_ID=";
-
sd_journal_flush_matches(j);
- sd_id128_to_string(*boot_id, match + STRLEN("_BOOT_ID="));
- r = sd_journal_add_match(j, match, sizeof(match) - 1);
+ r = add_match_boot_id(j, *boot_id);
if (r < 0)
return r;
}
static int add_boot(sd_journal *j) {
- char match[STRLEN("_BOOT_ID=") + SD_ID128_STRING_MAX] = "_BOOT_ID=";
sd_id128_t boot_id;
int r;
return r == 0 ? -ENODATA : r;
}
- sd_id128_to_string(boot_id, match + STRLEN("_BOOT_ID="));
-
- r = sd_journal_add_match(j, match, sizeof(match) - 1);
+ r = add_match_boot_id(j, boot_id);
if (r < 0)
return log_error_errno(r, "Failed to add match: %m");
return 0;
}
+int add_match_boot_id(sd_journal *j, sd_id128_t id) {
+ char match[STRLEN("_BOOT_ID=") + SD_ID128_STRING_MAX];
+
+ assert(j);
+ assert(!sd_id128_is_null(id));
+
+ sd_id128_to_string(id, stpcpy(match, "_BOOT_ID="));
+ return sd_journal_add_match(j, match, strlen(match));
+}
+
int add_match_this_boot(sd_journal *j, const char *machine) {
- char match[9+32+1] = "_BOOT_ID=";
sd_id128_t boot_id;
int r;
return log_error_errno(r, "Failed to get boot id: %m");
}
- sd_id128_to_string(boot_id, match + 9);
- r = sd_journal_add_match(j, match, strlen(match));
+ r = add_match_boot_id(j, boot_id);
if (r < 0)
return log_error_errno(r, "Failed to add match: %m");