diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /src/coredump | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/coredump')
-rw-r--r-- | src/coredump/coredump-vacuum.c | 19 | ||||
-rw-r--r-- | src/coredump/coredump.c | 21 | ||||
-rw-r--r-- | src/coredump/coredumpctl.c | 55 | ||||
-rw-r--r-- | src/coredump/meson.build | 15 |
4 files changed, 54 insertions, 56 deletions
diff --git a/src/coredump/coredump-vacuum.c b/src/coredump/coredump-vacuum.c index 7e0c98c..8e2febd 100644 --- a/src/coredump/coredump-vacuum.c +++ b/src/coredump/coredump-vacuum.c @@ -179,18 +179,12 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { c = hashmap_get(h, UID_TO_PTR(uid)); if (c) { - if (t < c->oldest_mtime) { - char *n; - - n = strdup(de->d_name); - if (!n) - return log_oom(); - - free_and_replace(c->oldest_file, n); + r = free_and_strdup_warn(&c->oldest_file, de->d_name); + if (r < 0) + return r; c->oldest_mtime = t; } - } else { _cleanup_(vacuum_candidate_freep) VacuumCandidate *n = NULL; @@ -198,10 +192,9 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { if (!n) return log_oom(); - n->oldest_file = strdup(de->d_name); - if (!n->oldest_file) - return log_oom(); - + r = free_and_strdup_warn(&n->oldest_file, de->d_name); + if (r < 0) + return r; n->oldest_mtime = t; r = hashmap_put(h, UID_TO_PTR(uid), n); diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 32c1766..a8ee8e0 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -51,7 +51,7 @@ #include "strv.h" #include "sync-util.h" #include "tmpfile-util.h" -#include "uid-alloc-range.h" +#include "uid-classification.h" #include "user-util.h" /* The maximum size up to which we process coredumps. We use 1G on 32-bit systems, and 32G on 64-bit systems */ @@ -178,8 +178,8 @@ static int parse_config(void) { int r; - r = config_parse_config_file( - "coredump.conf", + r = config_parse_standard_file_with_dropins( + "systemd/coredump.conf", "Coredump\0", config_item_table_lookup, items, @@ -630,8 +630,7 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s if (n < 0) return log_error_errno((int) n, "Failed to read core data: %m"); if ((size_t) n < size) - return log_error_errno(SYNTHETIC_ERRNO(EIO), - "Core data too short."); + return log_error_errno(SYNTHETIC_ERRNO(EIO), "Core data too short."); *ret = TAKE_PTR(field); *ret_size = size + 9; @@ -1479,7 +1478,7 @@ static int forward_coredump_to_container(Context *context) { char buf[DECIMAL_STR_MAX(pid_t)]; const char *t = context->meta[i]; - switch(i) { + switch (i) { case META_ARGV_PID: xsprintf(buf, PID_FMT, ucred.pid); @@ -1550,7 +1549,7 @@ static int forward_coredump_to_container(Context *context) { if (r < 0) return log_debug_errno(r, "Failed to wait for child to terminate: %m"); if (r != EXIT_SUCCESS) - return log_debug_errno(SYNTHETIC_ERRNO(EPROTO), "Failed to process coredump in container: %m"); + return log_debug_errno(SYNTHETIC_ERRNO(EPROTO), "Failed to process coredump in container."); return 0; } @@ -1558,7 +1557,7 @@ static int forward_coredump_to_container(Context *context) { static int process_kernel(int argc, char* argv[]) { _cleanup_(iovw_free_freep) struct iovec_wrapper *iovw = NULL; Context context = {}; - int r; + int r, signo; /* When we're invoked by the kernel, stdout/stderr are closed which is dangerous because the fds * could get reallocated. To avoid hard to debug issues, let's instead bind stdout/stderr to @@ -1587,6 +1586,12 @@ static int process_kernel(int argc, char* argv[]) { /* OK, now we know it's not the journal, hence we can make use of it now. */ log_set_target_and_open(LOG_TARGET_JOURNAL_OR_KMSG); + /* Log minimal metadata now, so it is not lost if the system is about to shut down. */ + log_info("Process %s (%s) of user %s terminated abnormally with signal %s/%s, processing...", + context.meta[META_ARGV_PID], context.meta[META_COMM], + context.meta[META_ARGV_UID], context.meta[META_ARGV_SIGNAL], + strna(safe_atoi(context.meta[META_ARGV_SIGNAL], &signo) >= 0 ? signal_to_string(signo) : NULL)); + r = in_same_namespace(getpid_cached(), context.pid, NAMESPACE_PID); if (r < 0) log_debug_errno(r, "Failed to check pidns of crashing process, ignoring: %m"); diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 84d4531..3a3cd7d 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -67,34 +67,38 @@ static bool arg_all = false; static ImagePolicy *arg_image_policy = NULL; STATIC_DESTRUCTOR_REGISTER(arg_debugger_args, strv_freep); +STATIC_DESTRUCTOR_REGISTER(arg_root, freep); +STATIC_DESTRUCTOR_REGISTER(arg_image, freep); STATIC_DESTRUCTOR_REGISTER(arg_file, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); static int add_match(sd_journal *j, const char *match) { _cleanup_free_ char *p = NULL; - const char* prefix, *pattern; - pid_t pid; + const char *field; int r; if (strchr(match, '=')) - prefix = ""; - else if (strchr(match, '/')) { + field = NULL; + else if (is_path(match)) { r = path_make_absolute_cwd(match, &p); if (r < 0) return log_error_errno(r, "path_make_absolute_cwd(\"%s\"): %m", match); match = p; - prefix = "COREDUMP_EXE="; - } else if (parse_pid(match, &pid) >= 0) - prefix = "COREDUMP_PID="; + field = "COREDUMP_EXE"; + } else if (parse_pid(match, NULL) >= 0) + field = "COREDUMP_PID"; else - prefix = "COREDUMP_COMM="; + field = "COREDUMP_COMM"; - pattern = strjoina(prefix, match); - log_debug("Adding match: %s", pattern); - r = sd_journal_add_match(j, pattern, 0); + log_debug("Adding match: %s%s%s", strempty(field), field ? "=" : "", match); + if (field) + r = journal_add_match_pair(j, field, match); + else + r = sd_journal_add_match(j, match, SIZE_MAX); if (r < 0) - return log_error_errno(r, "Failed to add match \"%s\": %m", match); + return log_error_errno(r, "Failed to add match \"%s%s%s\": %m", + strempty(field), field ? "=" : "", match); return 0; } @@ -102,11 +106,11 @@ static int add_match(sd_journal *j, const char *match) { static int add_matches(sd_journal *j, char **matches) { int r; - r = sd_journal_add_match(j, "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR, 0); + r = sd_journal_add_match(j, "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR, SIZE_MAX); if (r < 0) return log_error_errno(r, "Failed to add match \"%s\": %m", "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR); - r = sd_journal_add_match(j, "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR, 0); + r = sd_journal_add_match(j, "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR, SIZE_MAX); if (r < 0) return log_error_errno(r, "Failed to add match \"%s\": %m", "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR); @@ -126,19 +130,19 @@ static int acquire_journal(sd_journal **ret, char **matches) { assert(ret); if (arg_directory) { - r = sd_journal_open_directory(&j, arg_directory, 0); + r = sd_journal_open_directory(&j, arg_directory, SD_JOURNAL_ASSUME_IMMUTABLE); if (r < 0) return log_error_errno(r, "Failed to open journals in directory: %s: %m", arg_directory); } else if (arg_root) { - r = sd_journal_open_directory(&j, arg_root, SD_JOURNAL_OS_ROOT); + r = sd_journal_open_directory(&j, arg_root, SD_JOURNAL_OS_ROOT | SD_JOURNAL_ASSUME_IMMUTABLE); if (r < 0) return log_error_errno(r, "Failed to open journals in root directory: %s: %m", arg_root); } else if (arg_file) { - r = sd_journal_open_files(&j, (const char**)arg_file, 0); + r = sd_journal_open_files(&j, (const char**)arg_file, SD_JOURNAL_ASSUME_IMMUTABLE); if (r < 0) return log_error_errno(r, "Failed to open journal files: %m"); } else { - r = sd_journal_open(&j, arg_all ? 0 : SD_JOURNAL_LOCAL_ONLY); + r = sd_journal_open(&j, arg_all ? 0 : SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE); if (r < 0) return log_error_errno(r, "Failed to open journal: %m"); } @@ -875,7 +879,7 @@ static int dump_list(int argc, char **argv, void *userdata) { verb_is_info = argc >= 1 && streq(argv[0], "info"); - r = acquire_journal(&j, argv + 1); + r = acquire_journal(&j, strv_skip(argv, 1)); if (r < 0) return r; @@ -1126,7 +1130,7 @@ static int dump_core(int argc, char **argv, void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --field/-F only makes sense with list"); - r = acquire_journal(&j, argv + 1); + r = acquire_journal(&j, strv_skip(argv, 1)); if (r < 0) return r; @@ -1199,7 +1203,7 @@ static int run_debug(int argc, char **argv, void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --field/-F only makes sense with list"); - r = acquire_journal(&j, argv + 1); + r = acquire_journal(&j, strv_skip(argv, 1)); if (r < 0) return r; @@ -1240,7 +1244,7 @@ static int run_debug(int argc, char **argv, void *userdata) { if (r < 0) return r; - r = strv_extend_strv(&debugger_call, STRV_MAKE(exe, "-c", path), false); + r = strv_extend_many(&debugger_call, exe, "-c", path); if (r < 0) return log_oom(); @@ -1249,14 +1253,14 @@ static int run_debug(int argc, char **argv, void *userdata) { const char *sysroot_cmd; sysroot_cmd = strjoina("set sysroot ", arg_root); - r = strv_extend_strv(&debugger_call, STRV_MAKE("-iex", sysroot_cmd), false); + r = strv_extend_many(&debugger_call, "-iex", sysroot_cmd); if (r < 0) return log_oom(); } else if (streq(arg_debugger, "lldb")) { const char *sysroot_cmd; sysroot_cmd = strjoina("platform select --sysroot ", arg_root, " host"); - r = strv_extend_strv(&debugger_call, STRV_MAKE("-O", sysroot_cmd), false); + r = strv_extend_many(&debugger_call, "-O", sysroot_cmd); if (r < 0) return log_oom(); } @@ -1392,7 +1396,8 @@ static int run(int argc, char *argv[]) { DISSECT_IMAGE_GENERIC_ROOT | DISSECT_IMAGE_REQUIRE_ROOT | DISSECT_IMAGE_RELAX_VAR_CHECK | - DISSECT_IMAGE_VALIDATE_OS, + DISSECT_IMAGE_VALIDATE_OS | + DISSECT_IMAGE_ALLOW_USERSPACE_VERITY, &mounted_dir, /* ret_dir_fd= */ NULL, &loop_device); diff --git a/src/coredump/meson.build b/src/coredump/meson.build index a699746..bb81149 100644 --- a/src/coredump/meson.build +++ b/src/coredump/meson.build @@ -5,15 +5,10 @@ systemd_coredump_sources = files( 'coredump-vacuum.c', ) -common_link_with = [ - libshared, - libbasic_compress, -] - common_dependencies = [ - liblz4, - libxz, - libzstd, + liblz4_cflags, + libxz_cflags, + libzstd_cflags, threads, ] @@ -22,7 +17,7 @@ executables += [ 'name' : 'systemd-coredump', 'conditions' : ['ENABLE_COREDUMP'], 'sources' : systemd_coredump_sources, - 'link_with' : common_link_with, + 'link_with' : [libshared], 'dependencies' : common_dependencies + [libacl], }, executable_template + { @@ -30,7 +25,7 @@ executables += [ 'public' : true, 'conditions' : ['ENABLE_COREDUMP'], 'sources' : files('coredumpctl.c'), - 'link_with' : common_link_with, + 'link_with' : [libshared], 'dependencies' : common_dependencies, }, test_template + { |