Skip to content

Passing FDs through systemd-run, e.g. via LISTEN_FDS #16332

@snarkmaster

Description

@snarkmaster

This works today:

exec 3> /my/file
export LISTEN_FDS=3
export LISTEN_PID=$$
exec systemd-nspawn ... -- my_program --fd 3

This is great for exposing files or sockets in the resulting container.

If I have a container running systemd inside, I can similarly try to start a program inside it via systemd-run. However, in this case, LISTEN_FDS-style file descriptor forwarding is not supported, so in this example my program will fail with EBADF.

exec 3> /my/file
export LISTEN_FDS=3
export LISTEN_PID=$$
exec systemd-run --pipe --wait ... -- my_program --fd 3

As far as I can tell, implementing this should be possible. The least bad idea I found in 30 minutes of reading the code was to add a new handler to dbus-service.c that calls service_add_fd_store.

Would this be a sensible API? Are there other good ways to run a transient unit with arbitrary FDs inside my container?

If the API is OK, what about the implementation, is it enough to sequentially add my FDs to the FD store of the transient unit?

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFE 🎁Request for Enhancement, i.e. a feature requestpid1

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions