Skip to content

Commit b46a4f0

Browse files
committed
coredump: get rid of _META_MANDATORY_MAX
No functional change. This change is done in preparation for future changes. Currently, the list of fields which are received on the command line is a strict subset of the fields which are always expected to be received on a socket. But when we add new kernel args in the future, we'll have two non-overlapping sets and this approach will not work. Get rid of the variable and enumerate the required fields. This set will never change, so this is actually more maintainable. The message with the hint where to add new fields is switched with _META_ARGV_MAX. The new order is more correct. (cherry-picked from 49f1f2d) (cherry-picked from aea6a631bca93e8b04a11aaced694f25f4da155e) (cherry picked from cf16b6b6b2e0a656531bfd73ad66be3817b155cd)
1 parent 866a9a5 commit b46a4f0

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/coredump/coredump.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
* size. See DATA_SIZE_MAX in journal-importer.h. */
8383
assert_cc(JOURNAL_SIZE_MAX <= DATA_SIZE_MAX);
8484

85-
enum {
85+
typedef enum {
8686
/* We use these as array indexes for our process metadata cache.
8787
*
8888
* The first indices of the cache stores the same metadata as the ones passed by
@@ -98,26 +98,25 @@ enum {
9898
_META_ARGV_REQUIRED,
9999
/* The fields below were added to kernel/core_pattern at later points, so they might be missing. */
100100
META_ARGV_HOSTNAME = _META_ARGV_REQUIRED, /* %h: hostname */
101-
_META_ARGV_MAX,
102101
/* If new fields are added, they should be added here, to maintain compatibility
103102
* with callers which don't know about the new fields. */
103+
_META_ARGV_MAX,
104104

105105
/* The following indexes are cached for a couple of special fields we use (and
106106
* thereby need to be retrieved quickly) for naming coredump files, and attaching
107107
* xattrs. Unlike the previous ones they are retrieved from the runtime
108108
* environment. */
109109

110110
META_COMM = _META_ARGV_MAX,
111-
_META_MANDATORY_MAX,
112111

113112
/* The rest are similar to the previous ones except that we won't fail if one of
114113
* them is missing in a message sent over the socket. */
115114

116-
META_EXE = _META_MANDATORY_MAX,
115+
META_EXE,
117116
META_UNIT,
118117
META_PROC_AUXV,
119118
_META_MAX
120-
};
119+
} meta_argv_t;
121120

122121
static const char * const meta_field_names[_META_MAX] = {
123122
[META_ARGV_PID] = "COREDUMP_PID=",
@@ -1084,12 +1083,24 @@ static int process_socket(int fd) {
10841083
if (r < 0)
10851084
goto finish;
10861085

1087-
/* Make sure we received at least all fields we need. */
1088-
for (int i = 0; i < _META_MANDATORY_MAX; i++)
1086+
/* Make sure we received all the expected fields. We support being called by an *older*
1087+
* systemd-coredump from the outside, so we require only the basic set of fields that
1088+
* was being sent when the support for sending to containers over a socket was added
1089+
* in a108c43e36d3ceb6e34efe37c014fc2cda856000. */
1090+
meta_argv_t i;
1091+
VA_ARGS_FOREACH(i,
1092+
META_ARGV_PID,
1093+
META_ARGV_UID,
1094+
META_ARGV_GID,
1095+
META_ARGV_SIGNAL,
1096+
META_ARGV_TIMESTAMP,
1097+
META_ARGV_RLIMIT,
1098+
META_ARGV_HOSTNAME,
1099+
META_COMM)
10891100
if (!context.meta[i]) {
10901101
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL),
1091-
"A mandatory argument (%i) has not been sent, aborting.",
1092-
i);
1102+
"Mandatory argument %s not received on socket, aborting.",
1103+
meta_field_names[i]);
10931104
goto finish;
10941105
}
10951106

0 commit comments

Comments
 (0)