]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: parse rlimit field at same place as other fields
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Oct 2024 14:37:09 +0000 (15:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Oct 2024 22:08:11 +0000 (23:08 +0100)
src/coredump/coredump.c

index bc2a722bbb5762f2464dd24fea1e9e0d4d2e3d0f..f8422b1dbd81c4e9f8622e1e0a7f3c059b18d9d5 100644 (file)
@@ -144,6 +144,7 @@ typedef struct Context {
         uid_t uid;
         gid_t gid;
         int signo;
+        uint64_t rlimit;
         bool is_pid1;
         bool is_journald;
         int mount_tree_fd;
@@ -455,7 +456,7 @@ static int save_external_coredump(
         _cleanup_(unlink_and_freep) char *tmp = NULL;
         _cleanup_free_ char *fn = NULL;
         _cleanup_close_ int fd = -EBADF;
-        uint64_t rlimit, process_limit, max_size;
+        uint64_t process_limit, max_size;
         bool truncated, storage_on_tmpfs;
         struct stat st;
         int r;
@@ -468,11 +469,7 @@ static int save_external_coredump(
         assert(ret_compressed_size);
         assert(ret_truncated);
 
-        r = safe_atou64(context->meta[META_ARGV_RLIMIT], &rlimit);
-        if (r < 0)
-                return log_error_errno(r, "Failed to parse resource limit '%s': %m",
-                                       context->meta[META_ARGV_RLIMIT]);
-        if (rlimit < page_size())
+        if (context->rlimit < page_size())
                 /* Is coredumping disabled? Then don't bother saving/processing the
                  * coredump. Anything below PAGE_SIZE cannot give a readable coredump
                  * (the kernel uses ELF_EXEC_PAGESIZE which is not easily accessible, but
@@ -487,7 +484,7 @@ static int save_external_coredump(
                                        "Limits for coredump processing and storage are both 0, not dumping core.");
 
         /* Never store more than the process configured, or than we actually shall keep or process */
-        max_size = MIN(rlimit, process_limit);
+        max_size = MIN(context->rlimit, process_limit);
 
         r = make_filename(context, &fn);
         if (r < 0)
@@ -1077,6 +1074,10 @@ static int context_parse_iovw(Context *context, struct iovec_wrapper *iovw) {
         if (r < 0)
                 log_warning_errno(r, "Failed to parse signal number \"%s\", ignoring: %m", context->meta[META_ARGV_SIGNAL]);
 
+        r = safe_atou64(context->meta[META_ARGV_RLIMIT], &context->rlimit);
+        if (r < 0)
+                log_warning_errno(r, "Failed to parse resource limit \"%s\", ignoring: %m", context->meta[META_ARGV_RLIMIT]);
+
         unit = context->meta[META_UNIT];
         context->is_pid1 = streq(context->meta[META_ARGV_PID], "1") || streq_ptr(unit, SPECIAL_INIT_SCOPE);
         context->is_journald = streq_ptr(unit, SPECIAL_JOURNALD_SERVICE);