From b2dcfd8e11977d4369560b8b4de81b947b0e963e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Dec 2023 11:02:59 +0100 Subject: cgroup-setup: add fd-based version of cg_attach() --- src/shared/cgroup-setup.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/shared/cgroup-setup.c') 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; -- cgit v1.2.3