281364
From f53c6620c55488e2a3bd92957b21b6b95a7a3d35 Mon Sep 17 00:00:00 2001
281364
From: David Tardon <dtardon@redhat.com>
281364
Date: Thu, 12 Jan 2023 15:47:09 +0100
281364
Subject: [PATCH] coredump: put context array into a struct
281364
281364
[dtardon: This is based on commit f46c706bdd4316ae8ed6baf7a8c382b90b84f648 ,
281364
but does just the minimal change to introduce the Context struct that is
281364
needed by the following commit.]
281364
281364
Related: #2155520
281364
---
281364
 src/coredump/coredump.c | 208 +++++++++++++++++++++-------------------
281364
 1 file changed, 108 insertions(+), 100 deletions(-)
281364
281364
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
281364
index fb3a6ecfe9..ebc56d8342 100644
281364
--- a/src/coredump/coredump.c
281364
+++ b/src/coredump/coredump.c
281364
@@ -91,6 +91,10 @@ enum {
281364
         _CONTEXT_MAX
281364
 };
281364
 
281364
+typedef struct Context {
281364
+        const char *meta[_CONTEXT_MAX];
281364
+} Context;
281364
+
281364
 typedef enum CoredumpStorage {
281364
         COREDUMP_STORAGE_NONE,
281364
         COREDUMP_STORAGE_EXTERNAL,
281364
@@ -184,7 +188,7 @@ static int fix_acl(int fd, uid_t uid) {
281364
         return 0;
281364
 }
281364
 
281364
-static int fix_xattr(int fd, const char *context[_CONTEXT_MAX]) {
281364
+static int fix_xattr(int fd, const Context *context) {
281364
 
281364
         static const char * const xattrs[_CONTEXT_MAX] = {
281364
                 [CONTEXT_PID] = "user.coredump.pid",
281364
@@ -209,10 +213,10 @@ static int fix_xattr(int fd, const char *context[_CONTEXT_MAX]) {
281364
         for (i = 0; i < _CONTEXT_MAX; i++) {
281364
                 int k;
281364
 
281364
-                if (isempty(context[i]) || !xattrs[i])
281364
+                if (isempty(context->meta[i]) || !xattrs[i])
281364
                         continue;
281364
 
281364
-                k = fsetxattr(fd, xattrs[i], context[i], strlen(context[i]), XATTR_CREATE);
281364
+                k = fsetxattr(fd, xattrs[i], context->meta[i], strlen(context->meta[i]), XATTR_CREATE);
281364
                 if (k < 0 && r == 0)
281364
                         r = -errno;
281364
         }
281364
@@ -230,7 +234,7 @@ static int fix_permissions(
281364
                 int fd,
281364
                 const char *filename,
281364
                 const char *target,
281364
-                const char *context[_CONTEXT_MAX],
281364
+                const Context *context,
281364
                 uid_t uid) {
281364
 
281364
         int r;
281364
@@ -273,18 +277,18 @@ static int maybe_remove_external_coredump(const char *filename, uint64_t size) {
281364
         return 1;
281364
 }
281364
 
281364
-static int make_filename(const char *context[_CONTEXT_MAX], char **ret) {
281364
+static int make_filename(const Context *context, char **ret) {
281364
         _cleanup_free_ char *c = NULL, *u = NULL, *p = NULL, *t = NULL;
281364
         sd_id128_t boot = {};
281364
         int r;
281364
 
281364
         assert(context);
281364
 
281364
-        c = filename_escape(context[CONTEXT_COMM]);
281364
+        c = filename_escape(context->meta[CONTEXT_COMM]);
281364
         if (!c)
281364
                 return -ENOMEM;
281364
 
281364
-        u = filename_escape(context[CONTEXT_UID]);
281364
+        u = filename_escape(context->meta[CONTEXT_UID]);
281364
         if (!u)
281364
                 return -ENOMEM;
281364
 
281364
@@ -292,11 +296,11 @@ static int make_filename(const char *context[_CONTEXT_MAX], char **ret) {
281364
         if (r < 0)
281364
                 return r;
281364
 
281364
-        p = filename_escape(context[CONTEXT_PID]);
281364
+        p = filename_escape(context->meta[CONTEXT_PID]);
281364
         if (!p)
281364
                 return -ENOMEM;
281364
 
281364
-        t = filename_escape(context[CONTEXT_TIMESTAMP]);
281364
+        t = filename_escape(context->meta[CONTEXT_TIMESTAMP]);
281364
         if (!t)
281364
                 return -ENOMEM;
281364
 
281364
@@ -313,7 +317,7 @@ static int make_filename(const char *context[_CONTEXT_MAX], char **ret) {
281364
 }
281364
 
281364
 static int save_external_coredump(
281364
-                const char *context[_CONTEXT_MAX],
281364
+                const Context *context,
281364
                 int input_fd,
281364
                 char **ret_filename,
281364
                 int *ret_node_fd,
281364
@@ -334,19 +338,19 @@ static int save_external_coredump(
281364
         assert(ret_data_fd);
281364
         assert(ret_size);
281364
 
281364
-        r = parse_uid(context[CONTEXT_UID], &uid);
281364
+        r = parse_uid(context->meta[CONTEXT_UID], &uid);
281364
         if (r < 0)
281364
                 return log_error_errno(r, "Failed to parse UID: %m");
281364
 
281364
-        r = safe_atou64(context[CONTEXT_RLIMIT], &rlimit);
281364
+        r = safe_atou64(context->meta[CONTEXT_RLIMIT], &rlimit);
281364
         if (r < 0)
281364
-                return log_error_errno(r, "Failed to parse resource limit: %s", context[CONTEXT_RLIMIT]);
281364
+                return log_error_errno(r, "Failed to parse resource limit: %s", context->meta[CONTEXT_RLIMIT]);
281364
         if (rlimit < page_size()) {
281364
                 /* Is coredumping disabled? Then don't bother saving/processing the coredump.
281364
                  * Anything below PAGE_SIZE cannot give a readable coredump (the kernel uses
281364
                  * ELF_EXEC_PAGESIZE which is not easily accessible, but is usually the same as PAGE_SIZE. */
281364
                 log_info("Resource limits disable core dumping for process %s (%s).",
281364
-                         context[CONTEXT_PID], context[CONTEXT_COMM]);
281364
+                         context->meta[CONTEXT_PID], context->meta[CONTEXT_COMM]);
281364
                 return -EBADSLT;
281364
         }
281364
 
281364
@@ -371,7 +375,7 @@ static int save_external_coredump(
281364
 
281364
         r = copy_bytes(input_fd, fd, max_size, 0);
281364
         if (r < 0) {
281364
-                log_error_errno(r, "Cannot store coredump of %s (%s): %m", context[CONTEXT_PID], context[CONTEXT_COMM]);
281364
+                log_error_errno(r, "Cannot store coredump of %s (%s): %m", context->meta[CONTEXT_PID], context->meta[CONTEXT_COMM]);
281364
                 goto fail;
281364
         }
281364
         *ret_truncated = r == 1;
281364
@@ -659,12 +663,12 @@ static int get_process_container_parent_cmdline(pid_t pid, char** cmdline) {
281364
         return 1;
281364
 }
281364
 
281364
-static int change_uid_gid(const char *context[]) {
281364
+static int change_uid_gid(const Context *context) {
281364
         uid_t uid;
281364
         gid_t gid;
281364
         int r;
281364
 
281364
-        r = parse_uid(context[CONTEXT_UID], &uid);
281364
+        r = parse_uid(context->meta[CONTEXT_UID], &uid);
281364
         if (r < 0)
281364
                 return r;
281364
 
281364
@@ -677,7 +681,7 @@ static int change_uid_gid(const char *context[]) {
281364
                         uid = gid = 0;
281364
                 }
281364
         } else {
281364
-                r = parse_gid(context[CONTEXT_GID], &gid;;
281364
+                r = parse_gid(context->meta[CONTEXT_GID], &gid;;
281364
                 if (r < 0)
281364
                         return r;
281364
         }
281364
@@ -685,23 +689,23 @@ static int change_uid_gid(const char *context[]) {
281364
         return drop_privileges(uid, gid, 0);
281364
 }
281364
 
281364
-static bool is_journald_crash(const char *context[_CONTEXT_MAX]) {
281364
+static bool is_journald_crash(const Context *context) {
281364
         assert(context);
281364
 
281364
-        return streq_ptr(context[CONTEXT_UNIT], SPECIAL_JOURNALD_SERVICE);
281364
+        return streq_ptr(context->meta[CONTEXT_UNIT], SPECIAL_JOURNALD_SERVICE);
281364
 }
281364
 
281364
-static bool is_pid1_crash(const char *context[_CONTEXT_MAX]) {
281364
+static bool is_pid1_crash(const Context *context) {
281364
         assert(context);
281364
 
281364
-        return streq_ptr(context[CONTEXT_UNIT], SPECIAL_INIT_SCOPE) ||
281364
-                streq_ptr(context[CONTEXT_PID], "1");
281364
+        return streq_ptr(context->meta[CONTEXT_UNIT], SPECIAL_INIT_SCOPE) ||
281364
+                streq_ptr(context->meta[CONTEXT_PID], "1");
281364
 }
281364
 
281364
 #define SUBMIT_COREDUMP_FIELDS 4
281364
 
281364
 static int submit_coredump(
281364
-                const char *context[_CONTEXT_MAX],
281364
+                Context *context,
281364
                 struct iovec *iovec,
281364
                 size_t n_iovec_allocated,
281364
                 size_t n_iovec,
281364
@@ -760,11 +764,11 @@ static int submit_coredump(
281364
         if (coredump_size <= arg_process_size_max) {
281364
                 _cleanup_free_ char *stacktrace = NULL;
281364
 
281364
-                r = coredump_make_stack_trace(coredump_fd, context[CONTEXT_EXE], &stacktrace);
281364
+                r = coredump_make_stack_trace(coredump_fd, context->meta[CONTEXT_EXE], &stacktrace);
281364
                 if (r >= 0)
281364
-                        core_message = strjoin("MESSAGE=Process ", context[CONTEXT_PID],
281364
-                                               " (", context[CONTEXT_COMM], ") of user ",
281364
-                                               context[CONTEXT_UID], " dumped core.",
281364
+                        core_message = strjoin("MESSAGE=Process ", context->meta[CONTEXT_PID],
281364
+                                               " (", context->meta[CONTEXT_COMM], ") of user ",
281364
+                                               context->meta[CONTEXT_UID], " dumped core.",
281364
                                                journald_crash ? "\nCoredump diverted to " : "",
281364
                                                journald_crash ? filename : "",
281364
                                                "\n\n", stacktrace);
281364
@@ -779,9 +783,9 @@ static int submit_coredump(
281364
         if (!core_message)
281364
 #endif
281364
 log:
281364
-        core_message = strjoin("MESSAGE=Process ", context[CONTEXT_PID],
281364
-                               " (", context[CONTEXT_COMM], ") of user ",
281364
-                               context[CONTEXT_UID], " dumped core.",
281364
+        core_message = strjoin("MESSAGE=Process ", context->meta[CONTEXT_PID],
281364
+                               " (", context->meta[CONTEXT_COMM], ") of user ",
281364
+                               context->meta[CONTEXT_UID], " dumped core.",
281364
                                journald_crash && filename ? "\nCoredump diverted to " : NULL,
281364
                                journald_crash && filename ? filename : NULL);
281364
         if (!core_message)
281364
@@ -826,7 +830,7 @@ log:
281364
         return 0;
281364
 }
281364
 
281364
-static void map_context_fields(const struct iovec *iovec, const char* context[]) {
281364
+static void map_context_fields(const struct iovec *iovec, Context *context) {
281364
 
281364
         static const char * const context_field_names[] = {
281364
                 [CONTEXT_PID] = "COREDUMP_PID=",
281364
@@ -857,7 +861,7 @@ static void map_context_fields(const struct iovec *iovec, const char* context[])
281364
 
281364
                 /* Note that these strings are NUL terminated, because we made sure that a trailing NUL byte is in the
281364
                  * buffer, though not included in the iov_len count. (see below) */
281364
-                context[i] = p;
281364
+                context->meta[i] = p;
281364
                 break;
281364
         }
281364
 }
281364
@@ -866,7 +870,7 @@ static int process_socket(int fd) {
281364
         _cleanup_close_ int coredump_fd = -1;
281364
         struct iovec *iovec = NULL;
281364
         size_t n_iovec = 0, n_allocated = 0, i, k;
281364
-        const char *context[_CONTEXT_MAX] = {};
281364
+        Context context = {};
281364
         int r;
281364
 
281364
         assert(fd >= 0);
281364
@@ -950,7 +954,7 @@ static int process_socket(int fd) {
281364
                 iovec[n_iovec].iov_len = (size_t) n;
281364
 
281364
                 cmsg_close_all(&mh);
281364
-                map_context_fields(iovec + n_iovec, context);
281364
+                map_context_fields(iovec + n_iovec, &context);
281364
                 n_iovec++;
281364
         }
281364
 
281364
@@ -960,24 +964,24 @@ static int process_socket(int fd) {
281364
         }
281364
 
281364
         /* Make sure we got all data we really need */
281364
-        assert(context[CONTEXT_PID]);
281364
-        assert(context[CONTEXT_UID]);
281364
-        assert(context[CONTEXT_GID]);
281364
-        assert(context[CONTEXT_SIGNAL]);
281364
-        assert(context[CONTEXT_TIMESTAMP]);
281364
-        assert(context[CONTEXT_RLIMIT]);
281364
-        assert(context[CONTEXT_HOSTNAME]);
281364
-        assert(context[CONTEXT_COMM]);
281364
+        assert(context.meta[CONTEXT_PID]);
281364
+        assert(context.meta[CONTEXT_UID]);
281364
+        assert(context.meta[CONTEXT_GID]);
281364
+        assert(context.meta[CONTEXT_SIGNAL]);
281364
+        assert(context.meta[CONTEXT_TIMESTAMP]);
281364
+        assert(context.meta[CONTEXT_RLIMIT]);
281364
+        assert(context.meta[CONTEXT_HOSTNAME]);
281364
+        assert(context.meta[CONTEXT_COMM]);
281364
         assert(coredump_fd >= 0);
281364
 
281364
         /* Small quirk: the journal fields contain the timestamp padded with six zeroes, so that the kernel-supplied 1s
281364
          * granularity timestamps becomes 1µs granularity, i.e. the granularity systemd usually operates in. Since we
281364
          * are reconstructing the original kernel context, we chop this off again, here. */
281364
-        k = strlen(context[CONTEXT_TIMESTAMP]);
281364
+        k = strlen(context.meta[CONTEXT_TIMESTAMP]);
281364
         if (k > 6)
281364
-                context[CONTEXT_TIMESTAMP] = strndupa(context[CONTEXT_TIMESTAMP], k - 6);
281364
+                context.meta[CONTEXT_TIMESTAMP] = strndupa(context.meta[CONTEXT_TIMESTAMP], k - 6);
281364
 
281364
-        r = submit_coredump(context, iovec, n_allocated, n_iovec, coredump_fd);
281364
+        r = submit_coredump(&context, iovec, n_allocated, n_iovec, coredump_fd);
281364
 
281364
 finish:
281364
         for (i = 0; i < n_iovec; i++)
281364
@@ -1062,7 +1066,7 @@ static char* set_iovec_field_free(struct iovec *iovec, size_t *n_iovec, const ch
281364
 }
281364
 
281364
 static int gather_pid_metadata(
281364
-                char* context[_CONTEXT_MAX],
281364
+                Context *context,
281364
                 char **comm_fallback,
281364
                 struct iovec *iovec, size_t *n_iovec) {
281364
 
281364
@@ -1077,65 +1081,69 @@ static int gather_pid_metadata(
281364
         const char *p;
281364
         int r, signo;
281364
 
281364
-        r = parse_pid(context[CONTEXT_PID], &pid;;
281364
+        r = parse_pid(context->meta[CONTEXT_PID], &pid;;
281364
         if (r < 0)
281364
-                return log_error_errno(r, "Failed to parse PID \"%s\": %m", context[CONTEXT_PID]);
281364
+                return log_error_errno(r, "Failed to parse PID \"%s\": %m", context->meta[CONTEXT_PID]);
281364
 
281364
-        r = get_process_comm(pid, &context[CONTEXT_COMM]);
281364
+        r = get_process_comm(pid, &t);
281364
         if (r < 0) {
281364
                 log_warning_errno(r, "Failed to get COMM, falling back to the command line: %m");
281364
-                context[CONTEXT_COMM] = strv_join(comm_fallback, " ");
281364
-                if (!context[CONTEXT_COMM])
281364
+                context->meta[CONTEXT_COMM] = strv_join(comm_fallback, " ");
281364
+                if (!context->meta[CONTEXT_COMM])
281364
                         return log_oom();
281364
-        }
281364
+        } else
281364
+                context->meta[CONTEXT_COMM] = t;
281364
 
281364
-        r = get_process_exe(pid, &context[CONTEXT_EXE]);
281364
+        r = get_process_exe(pid, &t);
281364
         if (r < 0)
281364
                 log_warning_errno(r, "Failed to get EXE, ignoring: %m");
281364
+        else
281364
+                context->meta[CONTEXT_EXE] = t;
281364
 
281364
-        if (cg_pid_get_unit(pid, &context[CONTEXT_UNIT]) >= 0) {
281364
-                if (!is_journald_crash((const char**) context)) {
281364
+        if (cg_pid_get_unit(pid, &t) >= 0) {
281364
+                if (!is_journald_crash(context)) {
281364
                         /* OK, now we know it's not the journal, hence we can make use of it now. */
281364
                         log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
281364
                         log_open();
281364
                 }
281364
 
281364
                 /* If this is PID 1 disable coredump collection, we'll unlikely be able to process it later on. */
281364
-                if (is_pid1_crash((const char**) context)) {
281364
+                if (is_pid1_crash(context)) {
281364
                         log_notice("Due to PID 1 having crashed coredump collection will now be turned off.");
281364
                         disable_coredumps();
281364
                 }
281364
 
281364
-                set_iovec_string_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]);
281364
-        }
281364
+                set_iovec_string_field(iovec, n_iovec, "COREDUMP_UNIT=", context->meta[CONTEXT_UNIT]);
281364
+        } else
281364
+                context->meta[CONTEXT_UNIT] = t;
281364
 
281364
         if (cg_pid_get_user_unit(pid, &t) >= 0)
281364
                 set_iovec_field_free(iovec, n_iovec, "COREDUMP_USER_UNIT=", t);
281364
 
281364
         /* The next few are mandatory */
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_PID=", context[CONTEXT_PID]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_PID=", context->meta[CONTEXT_PID]))
281364
                 return log_oom();
281364
 
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_UID=", context[CONTEXT_UID]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_UID=", context->meta[CONTEXT_UID]))
281364
                 return log_oom();
281364
 
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_GID=", context[CONTEXT_GID]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_GID=", context->meta[CONTEXT_GID]))
281364
                 return log_oom();
281364
 
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL=", context[CONTEXT_SIGNAL]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL=", context->meta[CONTEXT_SIGNAL]))
281364
                 return log_oom();
281364
 
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_RLIMIT=", context[CONTEXT_RLIMIT]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_RLIMIT=", context->meta[CONTEXT_RLIMIT]))
281364
                 return log_oom();
281364
 
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_HOSTNAME=", context[CONTEXT_HOSTNAME]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_HOSTNAME=", context->meta[CONTEXT_HOSTNAME]))
281364
                 return log_oom();
281364
 
281364
-        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_COMM=", context[CONTEXT_COMM]))
281364
+        if (!set_iovec_string_field(iovec, n_iovec, "COREDUMP_COMM=", context->meta[CONTEXT_COMM]))
281364
                 return log_oom();
281364
 
281364
-        if (context[CONTEXT_EXE] &&
281364
-            !set_iovec_string_field(iovec, n_iovec, "COREDUMP_EXE=", context[CONTEXT_EXE]))
281364
+        if (context->meta[CONTEXT_EXE] &&
281364
+            !set_iovec_string_field(iovec, n_iovec, "COREDUMP_EXE=", context->meta[CONTEXT_EXE]))
281364
                 return log_oom();
281364
 
281364
         if (sd_pid_get_session(pid, &t) >= 0)
281364
@@ -1198,11 +1206,11 @@ static int gather_pid_metadata(
281364
         if (get_process_environ(pid, &t) >= 0)
281364
                 set_iovec_field_free(iovec, n_iovec, "COREDUMP_ENVIRON=", t);
281364
 
281364
-        t = strjoin("COREDUMP_TIMESTAMP=", context[CONTEXT_TIMESTAMP], "000000");
281364
+        t = strjoin("COREDUMP_TIMESTAMP=", context->meta[CONTEXT_TIMESTAMP], "000000");
281364
         if (t)
281364
                 iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(t);
281364
 
281364
-        if (safe_atoi(context[CONTEXT_SIGNAL], &signo) >= 0 && SIGNAL_VALID(signo))
281364
+        if (safe_atoi(context->meta[CONTEXT_SIGNAL], &signo) >= 0 && SIGNAL_VALID(signo))
281364
                 set_iovec_string_field(iovec, n_iovec, "COREDUMP_SIGNAL_NAME=SIG", signal_to_string(signo));
281364
 
281364
         return 0; /* we successfully acquired all metadata */
281364
@@ -1210,7 +1218,7 @@ static int gather_pid_metadata(
281364
 
281364
 static int process_kernel(int argc, char* argv[]) {
281364
 
281364
-        char* context[_CONTEXT_MAX] = {};
281364
+        Context context = {};
281364
         struct iovec iovec[29 + SUBMIT_COREDUMP_FIELDS];
281364
         size_t i, n_iovec, n_to_free = 0;
281364
         int r;
281364
@@ -1222,15 +1230,15 @@ static int process_kernel(int argc, char* argv[]) {
281364
                 return -EINVAL;
281364
         }
281364
 
281364
-        context[CONTEXT_PID]       = argv[1 + CONTEXT_PID];
281364
-        context[CONTEXT_UID]       = argv[1 + CONTEXT_UID];
281364
-        context[CONTEXT_GID]       = argv[1 + CONTEXT_GID];
281364
-        context[CONTEXT_SIGNAL]    = argv[1 + CONTEXT_SIGNAL];
281364
-        context[CONTEXT_TIMESTAMP] = argv[1 + CONTEXT_TIMESTAMP];
281364
-        context[CONTEXT_RLIMIT]    = argv[1 + CONTEXT_RLIMIT];
281364
-        context[CONTEXT_HOSTNAME]  = argv[1 + CONTEXT_HOSTNAME];
281364
+        context.meta[CONTEXT_PID]       = argv[1 + CONTEXT_PID];
281364
+        context.meta[CONTEXT_UID]       = argv[1 + CONTEXT_UID];
281364
+        context.meta[CONTEXT_GID]       = argv[1 + CONTEXT_GID];
281364
+        context.meta[CONTEXT_SIGNAL]    = argv[1 + CONTEXT_SIGNAL];
281364
+        context.meta[CONTEXT_TIMESTAMP] = argv[1 + CONTEXT_TIMESTAMP];
281364
+        context.meta[CONTEXT_RLIMIT]    = argv[1 + CONTEXT_RLIMIT];
281364
+        context.meta[CONTEXT_HOSTNAME]  = argv[1 + CONTEXT_HOSTNAME];
281364
 
281364
-        r = gather_pid_metadata(context, argv + 1 + CONTEXT_COMM, iovec, &n_to_free);
281364
+        r = gather_pid_metadata(&context, argv + 1 + CONTEXT_COMM, iovec, &n_to_free);
281364
         if (r < 0)
281364
                 goto finish;
281364
 
281364
@@ -1243,8 +1251,8 @@ static int process_kernel(int argc, char* argv[]) {
281364
 
281364
         assert(n_iovec <= ELEMENTSOF(iovec));
281364
 
281364
-        if (is_journald_crash((const char**) context) || is_pid1_crash((const char**) context))
281364
-                r = submit_coredump((const char**) context,
281364
+        if (is_journald_crash(&context) || is_pid1_crash(&context))
281364
+                r = submit_coredump(&context,
281364
                                     iovec, ELEMENTSOF(iovec), n_iovec,
281364
                                     STDIN_FILENO);
281364
         else
281364
@@ -1255,15 +1263,15 @@ static int process_kernel(int argc, char* argv[]) {
281364
                 free(iovec[i].iov_base);
281364
 
281364
         /* Those fields are allocated by gather_pid_metadata */
281364
-        free(context[CONTEXT_COMM]);
281364
-        free(context[CONTEXT_EXE]);
281364
-        free(context[CONTEXT_UNIT]);
281364
+        free((char *) context.meta[CONTEXT_COMM]);
281364
+        free((char *) context.meta[CONTEXT_EXE]);
281364
+        free((char *) context.meta[CONTEXT_UNIT]);
281364
 
281364
         return r;
281364
 }
281364
 
281364
 static int process_backtrace(int argc, char *argv[]) {
281364
-        char *context[_CONTEXT_MAX] = {};
281364
+        Context context = {};
281364
         _cleanup_free_ char *message = NULL;
281364
         _cleanup_free_ struct iovec *iovec = NULL;
281364
         size_t n_iovec, n_allocated, n_to_free = 0, i;
281364
@@ -1279,13 +1287,13 @@ static int process_backtrace(int argc, char *argv[]) {
281364
                 return -EINVAL;
281364
         }
281364
 
281364
-        context[CONTEXT_PID]       = argv[2 + CONTEXT_PID];
281364
-        context[CONTEXT_UID]       = argv[2 + CONTEXT_UID];
281364
-        context[CONTEXT_GID]       = argv[2 + CONTEXT_GID];
281364
-        context[CONTEXT_SIGNAL]    = argv[2 + CONTEXT_SIGNAL];
281364
-        context[CONTEXT_TIMESTAMP] = argv[2 + CONTEXT_TIMESTAMP];
281364
-        context[CONTEXT_RLIMIT]    = argv[2 + CONTEXT_RLIMIT];
281364
-        context[CONTEXT_HOSTNAME]  = argv[2 + CONTEXT_HOSTNAME];
281364
+        context.meta[CONTEXT_PID]       = argv[2 + CONTEXT_PID];
281364
+        context.meta[CONTEXT_UID]       = argv[2 + CONTEXT_UID];
281364
+        context.meta[CONTEXT_GID]       = argv[2 + CONTEXT_GID];
281364
+        context.meta[CONTEXT_SIGNAL]    = argv[2 + CONTEXT_SIGNAL];
281364
+        context.meta[CONTEXT_TIMESTAMP] = argv[2 + CONTEXT_TIMESTAMP];
281364
+        context.meta[CONTEXT_RLIMIT]    = argv[2 + CONTEXT_RLIMIT];
281364
+        context.meta[CONTEXT_HOSTNAME]  = argv[2 + CONTEXT_HOSTNAME];
281364
 
281364
         n_allocated = 34 + COREDUMP_STORAGE_EXTERNAL;
281364
         /* 26 metadata, 2 static, +unknown input, 4 storage, rounded up */
281364
@@ -1293,7 +1301,7 @@ static int process_backtrace(int argc, char *argv[]) {
281364
         if (!iovec)
281364
                 return log_oom();
281364
 
281364
-        r = gather_pid_metadata(context, argv + 2 + CONTEXT_COMM, iovec, &n_to_free);
281364
+        r = gather_pid_metadata(&context, argv + 2 + CONTEXT_COMM, iovec, &n_to_free);
281364
         if (r < 0)
281364
                 goto finish;
281364
         if (r > 0) {
281364
@@ -1320,10 +1328,10 @@ static int process_backtrace(int argc, char *argv[]) {
281364
         if (journal_importer_eof(&importer)) {
281364
                 log_warning("Did not receive a full journal entry on stdin, ignoring message sent by reporter");
281364
 
281364
-                message = strjoin("MESSAGE=Process ", context[CONTEXT_PID],
281364
-                                  " (", context[CONTEXT_COMM], ")"
281364
-                                  " of user ", context[CONTEXT_UID],
281364
-                                  " failed with ", context[CONTEXT_SIGNAL]);
281364
+                message = strjoin("MESSAGE=Process ", context.meta[CONTEXT_PID],
281364
+                                  " (", context.meta[CONTEXT_COMM], ")"
281364
+                                  " of user ", context.meta[CONTEXT_UID],
281364
+                                  " failed with ", context.meta[CONTEXT_SIGNAL]);
281364
                 if (!message) {
281364
                         r = log_oom();
281364
                         goto finish;
281364
@@ -1349,9 +1357,9 @@ static int process_backtrace(int argc, char *argv[]) {
281364
                 free(iovec[i].iov_base);
281364
 
281364
         /* Those fields are allocated by gather_pid_metadata */
281364
-        free(context[CONTEXT_COMM]);
281364
-        free(context[CONTEXT_EXE]);
281364
-        free(context[CONTEXT_UNIT]);
281364
+        free((char *) context.meta[CONTEXT_COMM]);
281364
+        free((char *) context.meta[CONTEXT_EXE]);
281364
+        free((char *) context.meta[CONTEXT_UNIT]);
281364
 
281364
         return r;
281364
 }