Skip to content

Commit 5855552

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)
1 parent ad6db74 commit 5855552

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

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

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

108108
META_COMM = _META_ARGV_MAX,
109-
_META_MANDATORY_MAX,
110109

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

114-
META_EXE = _META_MANDATORY_MAX,
113+
META_EXE,
115114
META_UNIT,
116115
META_PROC_AUXV,
117116
_META_MAX
118-
};
117+
} meta_argv_t;
119118

120119
static const char * const meta_field_names[_META_MAX] = {
121120
[META_ARGV_PID] = "COREDUMP_PID=",
@@ -1138,12 +1137,24 @@ static int process_socket(int fd) {
11381137
if (r < 0)
11391138
goto finish;
11401139

1141-
/* Make sure we received at least all fields we need. */
1142-
for (int i = 0; i < _META_MANDATORY_MAX; i++)
1140+
/* Make sure we received all the expected fields. We support being called by an *older*
1141+
* systemd-coredump from the outside, so we require only the basic set of fields that
1142+
* was being sent when the support for sending to containers over a socket was added
1143+
* in a108c43e36d3ceb6e34efe37c014fc2cda856000. */
1144+
meta_argv_t i;
1145+
VA_ARGS_FOREACH(i,
1146+
META_ARGV_PID,
1147+
META_ARGV_UID,
1148+
META_ARGV_GID,
1149+
META_ARGV_SIGNAL,
1150+
META_ARGV_TIMESTAMP,
1151+
META_ARGV_RLIMIT,
1152+
META_ARGV_HOSTNAME,
1153+
META_COMM)
11431154
if (!context.meta[i]) {
11441155
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL),
1145-
"A mandatory argument (%i) has not been sent, aborting.",
1146-
i);
1156+
"Mandatory argument %s not received on socket, aborting.",
1157+
meta_field_names[i]);
11471158
goto finish;
11481159
}
11491160

0 commit comments

Comments
 (0)