diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-12-12 11:02:59 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-04-06 16:08:23 +0200 |
commit | b2dcfd8e11977d4369560b8b4de81b947b0e963e (patch) | |
tree | ff77c6f8d1c411d5c4b46a39db29ea2e35ecbec8 /src/shared/cgroup-setup.c | |
parent | cgroup-util: add helpers for opening cgroup by id (diff) | |
download | systemd-b2dcfd8e11977d4369560b8b4de81b947b0e963e.tar.xz systemd-b2dcfd8e11977d4369560b8b4de81b947b0e963e.zip |
cgroup-setup: add fd-based version of cg_attach()
Diffstat (limited to 'src/shared/cgroup-setup.c')
-rw-r--r-- | src/shared/cgroup-setup.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index d9cca6ced4..f82af4cf43 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -384,6 +384,20 @@ int cg_attach(const char *controller, const char *path, pid_t pid) { return 0; } +int cg_fd_attach(int fd, pid_t pid) { + char c[DECIMAL_STR_MAX(pid_t) + 2]; + + assert(fd >= 0); + assert(pid >= 0); + + if (pid == 0) + pid = getpid_cached(); + + xsprintf(c, PID_FMT "\n", pid); + + return write_string_file_at(fd, "cgroup.procs", c, WRITE_STRING_FILE_DISABLE_BUFFER); +} + int cg_attach_fallback(const char *controller, const char *path, pid_t pid) { int r; |