Skip to content

Commit 2c81e60

Browse files
keszybzbluca
authored andcommitted
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) (cherry picked from commit b46a4f0) (cherry picked from commit 5855552) (cherry picked from commit cc31f2d)
1 parent e78d5c4 commit 2c81e60

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
@@ -79,7 +79,7 @@
7979
* size. See DATA_SIZE_MAX in journal-importer.h. */
8080
assert_cc(JOURNAL_SIZE_MAX <= DATA_SIZE_MAX);
8181

82-
enum {
82+
typedef enum {
8383
/* We use these as array indexes for our process metadata cache.
8484
*
8585
* The first indices of the cache stores the same metadata as the ones passed by
@@ -95,26 +95,25 @@ enum {
9595
_META_ARGV_REQUIRED,
9696
/* The fields below were added to kernel/core_pattern at later points, so they might be missing. */
9797
META_ARGV_HOSTNAME = _META_ARGV_REQUIRED, /* %h: hostname */
98-
_META_ARGV_MAX,
9998
/* If new fields are added, they should be added here, to maintain compatibility
10099
* with callers which don't know about the new fields. */
100+
_META_ARGV_MAX,
101101

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

107107
META_COMM = _META_ARGV_MAX,
108-
_META_MANDATORY_MAX,
109108

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

113-
META_EXE = _META_MANDATORY_MAX,
112+
META_EXE,
114113
META_UNIT,
115114
META_PROC_AUXV,
116115
_META_MAX
117-
};
116+
} meta_argv_t;
118117

119118
static const char * const meta_field_names[_META_MAX] = {
120119
[META_ARGV_PID] = "COREDUMP_PID=",
@@ -1200,12 +1199,24 @@ static int process_socket(int fd) {
12001199
if (r < 0)
12011200
goto finish;
12021201

1203-
/* Make sure we received at least all fields we need. */
1204-
for (int i = 0; i < _META_MANDATORY_MAX; i++)
1202+
/* Make sure we received all the expected fields. We support being called by an *older*
1203+
* systemd-coredump from the outside, so we require only the basic set of fields that
1204+
* was being sent when the support for sending to containers over a socket was added
1205+
* in a108c43e36d3ceb6e34efe37c014fc2cda856000. */
1206+
meta_argv_t i;
1207+
VA_ARGS_FOREACH(i,
1208+
META_ARGV_PID,
1209+
META_ARGV_UID,
1210+
META_ARGV_GID,
1211+
META_ARGV_SIGNAL,
1212+
META_ARGV_TIMESTAMP,
1213+
META_ARGV_RLIMIT,
1214+
META_ARGV_HOSTNAME,
1215+
META_COMM)
12051216
if (!context.meta[i]) {
12061217
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL),
1207-
"A mandatory argument (%i) has not been sent, aborting.",
1208-
i);
1218+
"Mandatory argument %s not received on socket, aborting.",
1219+
meta_field_names[i]);
12091220
goto finish;
12101221
}
12111222

0 commit comments

Comments
 (0)