core/execute: merge n_storage_fds and n_extra_fds into stashed_fds
The distinction between fdstore and extra fds is only meaningful to struct Service. As far as executor is concerned they're just some fds to pass to the service. Let's just merge it hence, for the sake of simplicity.
This commit is contained in:
@@ -5035,7 +5035,7 @@ int exec_invoke(
|
||||
int ngids = 0, ngids_after_pam = 0;
|
||||
int socket_fd = -EBADF, named_iofds[3] = EBADF_TRIPLET;
|
||||
_cleanup_close_ int bpffs_socket_fd = -EBADF, bpffs_errno_pipe = -EBADF;
|
||||
size_t n_storage_fds, n_socket_fds, n_extra_fds;
|
||||
size_t n_socket_fds, n_stashed_fds;
|
||||
_cleanup_(pidref_done_sigkill_wait) PidRef bpffs_pidref = PIDREF_NULL;
|
||||
|
||||
assert(command);
|
||||
@@ -5066,13 +5066,12 @@ int exec_invoke(
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Got no socket.");
|
||||
|
||||
socket_fd = params->fds[0];
|
||||
n_storage_fds = n_socket_fds = n_extra_fds = 0;
|
||||
n_socket_fds = n_stashed_fds = 0;
|
||||
} else {
|
||||
n_socket_fds = params->n_socket_fds;
|
||||
n_storage_fds = params->n_storage_fds;
|
||||
n_extra_fds = params->n_extra_fds;
|
||||
n_stashed_fds = params->n_stashed_fds;
|
||||
}
|
||||
n_fds = n_socket_fds + n_storage_fds + n_extra_fds;
|
||||
n_fds = n_socket_fds + n_stashed_fds;
|
||||
|
||||
r = exec_context_named_iofds(context, params, named_iofds);
|
||||
if (r < 0) {
|
||||
|
||||
@@ -1090,19 +1090,13 @@ static int exec_parameters_serialize(const ExecParameters *p, const ExecContext
|
||||
return r;
|
||||
}
|
||||
|
||||
if (p->n_storage_fds > 0) {
|
||||
r = serialize_item_format(f, "exec-parameters-n-storage-fds", "%zu", p->n_storage_fds);
|
||||
if (p->n_stashed_fds > 0) {
|
||||
r = serialize_item_format(f, "exec-parameters-n-stashed-fds", "%zu", p->n_stashed_fds);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (p->n_extra_fds > 0) {
|
||||
r = serialize_item_format(f, "exec-parameters-n-extra-fds", "%zu", p->n_extra_fds);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
|
||||
r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_stashed_fds);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1283,47 +1277,37 @@ static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
|
||||
|
||||
if (p->n_socket_fds > nr_open)
|
||||
return -EINVAL; /* too many, someone is playing games with us */
|
||||
} else if ((val = startswith(l, "exec-parameters-n-storage-fds="))) {
|
||||
} else if ((val = startswith(l, "exec-parameters-n-stashed-fds="))) {
|
||||
if (p->fds)
|
||||
return -EINVAL; /* Already received */
|
||||
|
||||
r = safe_atozu(val, &p->n_storage_fds);
|
||||
r = safe_atozu(val, &p->n_stashed_fds);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (p->n_storage_fds > nr_open)
|
||||
return -EINVAL; /* too many, someone is playing games with us */
|
||||
} else if ((val = startswith(l, "exec-parameters-n-extra-fds="))) {
|
||||
if (p->fds)
|
||||
return -EINVAL; /* Already received */
|
||||
|
||||
r = safe_atozu(val, &p->n_extra_fds);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (p->n_extra_fds > nr_open)
|
||||
if (p->n_stashed_fds > nr_open)
|
||||
return -EINVAL; /* too many, someone is playing games with us */
|
||||
} else if ((val = startswith(l, "exec-parameters-fds="))) {
|
||||
if (p->n_socket_fds + p->n_storage_fds + p->n_extra_fds == 0)
|
||||
if (p->n_socket_fds + p->n_stashed_fds == 0)
|
||||
return log_warning_errno(
|
||||
SYNTHETIC_ERRNO(EINVAL),
|
||||
"Got exec-parameters-fds= without "
|
||||
"prior exec-parameters-n-socket-fds= or exec-parameters-n-storage-fds= or exec-parameters-n-extra-fds=");
|
||||
if (p->n_socket_fds + p->n_storage_fds + p->n_extra_fds > nr_open)
|
||||
"prior exec-parameters-n-socket-fds= or exec-parameters-n-stashed-fds=");
|
||||
if (p->n_socket_fds + p->n_stashed_fds > nr_open)
|
||||
return -EINVAL; /* too many, someone is playing games with us */
|
||||
|
||||
if (p->fds)
|
||||
return -EINVAL; /* duplicated */
|
||||
|
||||
p->fds = new(int, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
|
||||
p->fds = new(int, p->n_socket_fds + p->n_stashed_fds);
|
||||
if (!p->fds)
|
||||
return log_oom_debug();
|
||||
|
||||
/* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
|
||||
FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds)
|
||||
FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_stashed_fds)
|
||||
*i = -EBADF;
|
||||
|
||||
r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds, p->fds);
|
||||
r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_stashed_fds, p->fds);
|
||||
if (r < 0)
|
||||
continue;
|
||||
|
||||
@@ -1521,9 +1505,9 @@ static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
|
||||
log_warning("Failed to parse serialized line, ignoring: %s", l);
|
||||
}
|
||||
|
||||
/* Bail out if we got exec-parameters-n-{socket/storage}-fds= but no corresponding
|
||||
/* Bail out if we got exec-parameters-n-{socket/stashed}-fds= but no corresponding
|
||||
* exec-parameters-fds= */
|
||||
if (p->n_socket_fds + p->n_storage_fds > 0 && !p->fds)
|
||||
if (p->n_socket_fds + p->n_stashed_fds > 0 && !p->fds)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -487,7 +487,7 @@ int exec_spawn(
|
||||
assert(context);
|
||||
assert(params);
|
||||
assert(!params->fds || FLAGS_SET(params->flags, EXEC_PASS_FDS));
|
||||
assert(params->fds || (params->n_socket_fds + params->n_storage_fds + params->n_extra_fds == 0 && !params->fd_names));
|
||||
assert(params->fds || (params->n_socket_fds + params->n_stashed_fds == 0 && !params->fd_names));
|
||||
assert(!params->files_env); /* We fill this field, ensure it comes NULL-initialized to us */
|
||||
assert(ret);
|
||||
|
||||
@@ -2826,7 +2826,7 @@ void exec_params_deep_clear(ExecParameters *p) {
|
||||
* to be fully cleaned up to make sanitizers and analyzers happy, as opposed as the shallow clean
|
||||
* function above. */
|
||||
|
||||
close_many_unset(p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
|
||||
close_many_unset(p->fds, p->n_socket_fds + p->n_stashed_fds);
|
||||
|
||||
p->cgroup_path = mfree(p->cgroup_path);
|
||||
|
||||
|
||||
+1
-2
@@ -399,8 +399,7 @@ typedef struct ExecParameters {
|
||||
int *fds;
|
||||
char **fd_names;
|
||||
size_t n_socket_fds;
|
||||
size_t n_storage_fds;
|
||||
size_t n_extra_fds;
|
||||
size_t n_stashed_fds;
|
||||
|
||||
char *cgroup_path;
|
||||
uint64_t cgroup_id;
|
||||
|
||||
@@ -62,8 +62,8 @@ static void exec_fuzz_one(FILE *f, FDSet *fdset) {
|
||||
params.user_lookup_fd = -EBADF;
|
||||
params.bpf_restrict_fs_map_fd = -EBADF;
|
||||
if (!params.fds)
|
||||
params.n_socket_fds = params.n_storage_fds = params.n_extra_fds = 0;
|
||||
for (size_t i = 0; params.fds && i < params.n_socket_fds + params.n_storage_fds + params.n_extra_fds; i++)
|
||||
params.n_socket_fds = params.n_stashed_fds = 0;
|
||||
for (size_t i = 0; params.fds && i < params.n_socket_fds + params.n_stashed_fds; i++)
|
||||
params.fds[i] = -EBADF;
|
||||
|
||||
exec_command_done_array(&command, /* n= */ 1);
|
||||
|
||||
+5
-9
@@ -1451,8 +1451,7 @@ static int service_collect_fds(
|
||||
int **fds,
|
||||
char ***fd_names,
|
||||
size_t *n_socket_fds,
|
||||
size_t *n_storage_fds,
|
||||
size_t *n_extra_fds) {
|
||||
size_t *n_stashed_fds) {
|
||||
|
||||
_cleanup_strv_free_ char **rfd_names = NULL;
|
||||
_cleanup_free_ int *rfds = NULL;
|
||||
@@ -1463,8 +1462,7 @@ static int service_collect_fds(
|
||||
assert(fds);
|
||||
assert(fd_names);
|
||||
assert(n_socket_fds);
|
||||
assert(n_storage_fds);
|
||||
assert(n_extra_fds);
|
||||
assert(n_stashed_fds);
|
||||
|
||||
if (s->socket_fd >= 0) {
|
||||
Socket *sock = ASSERT_PTR(SOCKET(UNIT_DEREF(s->accept_socket)));
|
||||
@@ -1548,8 +1546,7 @@ static int service_collect_fds(
|
||||
*fds = TAKE_PTR(rfds);
|
||||
*fd_names = TAKE_PTR(rfd_names);
|
||||
*n_socket_fds = rn_socket_fds;
|
||||
*n_storage_fds = s->n_fd_store;
|
||||
*n_extra_fds = s->n_extra_fds;
|
||||
*n_stashed_fds = s->n_fd_store + s->n_extra_fds;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1742,8 +1739,7 @@ static int service_spawn_internal(
|
||||
&exec_params.fds,
|
||||
&exec_params.fd_names,
|
||||
&exec_params.n_socket_fds,
|
||||
&exec_params.n_storage_fds,
|
||||
&exec_params.n_extra_fds);
|
||||
&exec_params.n_stashed_fds);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1751,7 +1747,7 @@ static int service_spawn_internal(
|
||||
|
||||
exec_params.flags |= EXEC_PASS_FDS;
|
||||
|
||||
log_unit_debug(UNIT(s), "Passing %zu fds to service", exec_params.n_socket_fds + exec_params.n_storage_fds + exec_params.n_extra_fds);
|
||||
log_unit_debug(UNIT(s), "Passing %zu fds to service", exec_params.n_socket_fds + exec_params.n_stashed_fds);
|
||||
}
|
||||
|
||||
if (!FLAGS_SET(exec_params.flags, EXEC_IS_CONTROL) && s->type == SERVICE_EXEC) {
|
||||
|
||||
Reference in New Issue
Block a user