Skip to content

Commit

Permalink
tree-wide: drop acquire_data_fd_full() helper
Browse files Browse the repository at this point in the history
Let's drop support systems lacking memfds, i.e. pre kernel 3.17 systems.
This allows us to drastically simplify the "data fd" concept, so far
that we can remove it entirely.

This replaces acquire_data_fd() with a specialized call to
memfd_new_and_seal(), not that memfds can be the only implementation of
the concept.
  • Loading branch information
poettering committed Dec 17, 2024
1 parent 8d08f18 commit a87a962
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 289 deletions.
3 changes: 3 additions & 0 deletions src/basic/memfd-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ int memfd_new_and_seal(const char *name, const void *data, size_t sz) {

assert(data || sz == 0);

if (sz == SIZE_MAX)
sz = strlen(data);

fd = memfd_new(name);
if (fd < 0)
return fd;
Expand Down
3 changes: 3 additions & 0 deletions src/basic/memfd-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ int memfd_create_wrapper(const char *name, unsigned mode);
int memfd_new(const char *name);
int memfd_new_and_map(const char *name, size_t sz, void **p);
int memfd_new_and_seal(const char *name, const void *data, size_t sz);
static inline int memfd_new_and_seal_string(const char *name, const char *s) {
return memfd_new_and_seal(name, s, SIZE_MAX);
}

int memfd_add_seals(int fd, unsigned int seals);
int memfd_get_seals(int fd, unsigned int *ret_seals);
Expand Down
4 changes: 2 additions & 2 deletions src/core/dbus-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "bus-util.h"
#include "chase.h"
#include "confidential-virt.h"
#include "data-fd-util.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-job.h"
Expand All @@ -33,6 +32,7 @@
#include "locale-util.h"
#include "log.h"
#include "manager-dump.h"
#include "memfd-util.h"
#include "os-util.h"
#include "parse-util.h"
#include "path-util.h"
Expand Down Expand Up @@ -1447,7 +1447,7 @@ static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *er
static int reply_dump_by_fd(sd_bus_message *message, char *dump) {
_cleanup_close_ int fd = -EBADF;

fd = acquire_data_fd(dump);
fd = memfd_new_and_seal_string("dump", dump);
if (fd < 0)
return fd;

Expand Down
4 changes: 2 additions & 2 deletions src/core/exec-invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "chattr-util.h"
#include "chown-recursive.h"
#include "copy.h"
#include "data-fd-util.h"
#include "env-util.h"
#include "escape.h"
#include "exec-credential.h"
Expand All @@ -44,6 +43,7 @@
#include "io-util.h"
#include "iovec-util.h"
#include "journal-send.h"
#include "memfd-util.h"
#include "missing_ioprio.h"
#include "missing_prctl.h"
#include "missing_sched.h"
Expand Down Expand Up @@ -406,7 +406,7 @@ static int setup_input(
case EXEC_INPUT_DATA: {
int fd;

fd = acquire_data_fd_full(context->stdin_data, context->stdin_data_size, /* flags = */ 0);
fd = memfd_new_and_seal("exec-input", context->stdin_data, context->stdin_data_size);
if (fd < 0)
return fd;

Expand Down
3 changes: 1 addition & 2 deletions src/home/homed-home.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "build-path.h"
#include "bus-common-errors.h"
#include "bus-locator.h"
#include "data-fd-util.h"
#include "env-util.h"
#include "errno-list.h"
#include "errno-util.h"
Expand Down Expand Up @@ -1266,7 +1265,7 @@ static int home_start_work(
if (r < 0)
return r;

stdin_fd = acquire_data_fd(formatted);
stdin_fd = memfd_new_and_seal_string("request", formatted);
if (stdin_fd < 0)
return stdin_fd;

Expand Down
4 changes: 2 additions & 2 deletions src/home/homework-cifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include <linux/fs.h>
#endif

#include "data-fd-util.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
#include "fs-util.h"
#include "homework-cifs.h"
#include "homework-mount.h"
#include "memfd-util.h"
#include "mkdir.h"
#include "mount-util.h"
#include "process-util.h"
Expand Down Expand Up @@ -76,7 +76,7 @@ int home_setup_cifs(
pid_t mount_pid;
int exit_status;

passwd_fd = acquire_data_fd(*pw);
passwd_fd = memfd_new_and_seal_string("cifspw", *pw);
if (passwd_fd < 0)
return log_error_errno(passwd_fd, "Failed to create data FD for password: %m");

Expand Down
4 changes: 2 additions & 2 deletions src/network/networkd-serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include "af-list.h"
#include "daemon-util.h"
#include "data-fd-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "iovec-util.h"
#include "json-util.h"
#include "memfd-util.h"
#include "networkd-address.h"
#include "networkd-json.h"
#include "networkd-link.h"
Expand Down Expand Up @@ -69,7 +69,7 @@ int manager_serialize(Manager *manager) {
return r;

_cleanup_close_ int fd = -EBADF;
fd = acquire_data_fd(dump);
fd = memfd_new_and_seal_string("serialization", dump);
if (fd < 0)
return fd;

Expand Down
4 changes: 2 additions & 2 deletions src/oom/oomd-manager-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "bus-common-errors.h"
#include "bus-polkit.h"
#include "data-fd-util.h"
#include "fd-util.h"
#include "memfd-util.h"
#include "oomd-manager-bus.h"
#include "oomd-manager.h"
#include "user-util.h"
Expand All @@ -22,7 +22,7 @@ static int bus_method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus
if (r < 0)
return r;

fd = acquire_data_fd(dump);
fd = memfd_new_and_seal_string("oomd-dump", dump);
if (fd < 0)
return fd;

Expand Down
4 changes: 2 additions & 2 deletions src/shared/bus-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include "capsule-util.h"
#include "chase.h"
#include "daemon-util.h"
#include "data-fd-util.h"
#include "env-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "memfd-util.h"
#include "memstream-util.h"
#include "path-util.h"
#include "socket-util.h"
Expand Down Expand Up @@ -803,7 +803,7 @@ static int method_dump_memory_state_by_fd(sd_bus_message *message, void *userdat
if (r < 0)
return r;

fd = acquire_data_fd_full(dump, dump_size, /* flags = */ 0);
fd = memfd_new_and_seal("malloc-info", dump, dump_size);
if (fd < 0)
return fd;

Expand Down
Loading

0 comments on commit a87a962

Please sign in to comment.