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