coredumpctl: use NULL outputs for COREDUMP existence checks
print_list() and print_info() used RETRIEVE() to strndup() the entire COREDUMP field into a heap-allocated string, only to check whether it exists. With sd_journal_set_data_threshold(j, 0) in print_info(), this copies the full coredump binary (potentially hundreds of MB) to heap just to print "Storage: journal". Now that sd_journal_get_data() accepts NULL output pointers, use a direct NULL/NULL existence check instead. Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
a5c811591f
commit
836de2900b
@@ -552,14 +552,14 @@ static int print_list(FILE* file, sd_journal *j, Table *t) {
|
||||
_cleanup_free_ char
|
||||
*mid = NULL, *pid = NULL, *uid = NULL, *gid = NULL,
|
||||
*sgnl = NULL, *exe = NULL, *comm = NULL,
|
||||
*filename = NULL, *truncated = NULL, *coredump = NULL;
|
||||
*filename = NULL, *truncated = NULL;
|
||||
const void *d;
|
||||
size_t l;
|
||||
usec_t ts;
|
||||
int r, signal_as_int = 0;
|
||||
const char *present = NULL, *color = NULL;
|
||||
uint64_t size = UINT64_MAX;
|
||||
bool normal_coredump;
|
||||
bool normal_coredump, has_inline_coredump;
|
||||
uid_t uid_as_int = UID_INVALID;
|
||||
gid_t gid_as_int = GID_INVALID;
|
||||
pid_t pid_as_int = 0;
|
||||
@@ -578,9 +578,11 @@ static int print_list(FILE* file, sd_journal *j, Table *t) {
|
||||
RETRIEVE(d, l, "COREDUMP_COMM", comm);
|
||||
RETRIEVE(d, l, "COREDUMP_FILENAME", filename);
|
||||
RETRIEVE(d, l, "COREDUMP_TRUNCATED", truncated);
|
||||
RETRIEVE(d, l, "COREDUMP", coredump);
|
||||
}
|
||||
|
||||
/* Check for an inline coredump without copying the (potentially large) payload to heap. */
|
||||
has_inline_coredump = sd_journal_get_data(j, "COREDUMP", NULL, NULL) >= 0;
|
||||
|
||||
if (!pid || !uid || !gid || !sgnl || !comm) {
|
||||
log_warning("Found a coredump entry without mandatory fields (PID=%s, UID=%s, GID=%s, SIGNAL=%s, COMM=%s), ignoring.",
|
||||
strna(pid), strna(uid), strna(gid), strna(sgnl), strna(comm));
|
||||
@@ -604,7 +606,7 @@ static int print_list(FILE* file, sd_journal *j, Table *t) {
|
||||
return r;
|
||||
|
||||
analyze_coredump_file(filename, &present, &color, &size);
|
||||
} else if (coredump)
|
||||
} else if (has_inline_coredump)
|
||||
present = "journal";
|
||||
else if (normal_coredump) {
|
||||
present = "none";
|
||||
@@ -640,12 +642,12 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
*boot_id = NULL, *machine_id = NULL, *hostname = NULL,
|
||||
*slice = NULL, *cgroup = NULL, *owner_uid = NULL,
|
||||
*message = NULL, *timestamp = NULL, *filename = NULL,
|
||||
*truncated = NULL, *coredump = NULL,
|
||||
*truncated = NULL,
|
||||
*pkgmeta_name = NULL, *pkgmeta_version = NULL, *pkgmeta_json = NULL,
|
||||
*tid = NULL, *thread_name = NULL;
|
||||
const void *d;
|
||||
size_t l;
|
||||
bool normal_coredump;
|
||||
bool normal_coredump, has_inline_coredump;
|
||||
int r;
|
||||
|
||||
assert(file);
|
||||
@@ -672,7 +674,6 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
RETRIEVE(d, l, "COREDUMP_TIMESTAMP", timestamp);
|
||||
RETRIEVE(d, l, "COREDUMP_FILENAME", filename);
|
||||
RETRIEVE(d, l, "COREDUMP_TRUNCATED", truncated);
|
||||
RETRIEVE(d, l, "COREDUMP", coredump);
|
||||
RETRIEVE(d, l, "COREDUMP_PACKAGE_NAME", pkgmeta_name);
|
||||
RETRIEVE(d, l, "COREDUMP_PACKAGE_VERSION", pkgmeta_version);
|
||||
RETRIEVE(d, l, "COREDUMP_PACKAGE_JSON", pkgmeta_json);
|
||||
@@ -683,6 +684,9 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
RETRIEVE(d, l, "MESSAGE", message);
|
||||
}
|
||||
|
||||
/* Check for an inline coredump without copying the (potentially large) payload to heap. */
|
||||
has_inline_coredump = sd_journal_get_data(j, "COREDUMP", NULL, NULL) >= 0;
|
||||
|
||||
if (need_space)
|
||||
fputs("\n", file);
|
||||
|
||||
@@ -820,7 +824,7 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
if (size != UINT64_MAX)
|
||||
fprintf(file, " Size on Disk: %s\n", FORMAT_BYTES(size));
|
||||
|
||||
} else if (coredump)
|
||||
} else if (has_inline_coredump)
|
||||
fprintf(file, " Storage: journal\n");
|
||||
else
|
||||
fprintf(file, " Storage: none\n");
|
||||
|
||||
Reference in New Issue
Block a user