summaryrefslogtreecommitdiffstats
path: root/src/shared/cgroup-setup.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-07-30 16:15:59 +0200
committerMike Yuan <me@yhndnzj.com>2024-08-02 16:36:07 +0200
commitea25672de5a22241b068050f812d61501de5f1a9 (patch)
treeb6810dcfb4aa9552aea3aae016ce05cee58ae6fa /src/shared/cgroup-setup.c
parentcgroup-setup: group v1-specific functions (diff)
downloadsystemd-ea25672de5a22241b068050f812d61501de5f1a9.tar.xz
systemd-ea25672de5a22241b068050f812d61501de5f1a9.zip
cgroup-setup: move cg_{,un}install_release_agent from cgroup-util
They're pid1-specific, so move them out of basic/.
Diffstat (limited to 'src/shared/cgroup-setup.c')
-rw-r--r--src/shared/cgroup-setup.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c
index c89c2c1d40..d7e27a1837 100644
--- a/src/shared/cgroup-setup.c
+++ b/src/shared/cgroup-setup.c
@@ -1011,3 +1011,88 @@ int cg_trim_v1_controllers(CGroupMask supported, CGroupMask mask, const char *pa
return r;
}
+
+int cg_install_release_agent(const char *controller, const char *agent) {
+ _cleanup_free_ char *fs = NULL, *contents = NULL;
+ const char *sc;
+ int r;
+
+ assert(agent);
+
+ r = cg_unified_controller(controller);
+ if (r < 0)
+ return r;
+ if (r > 0) /* doesn't apply to unified hierarchy */
+ return -EOPNOTSUPP;
+
+ r = cg_get_path(controller, NULL, "release_agent", &fs);
+ if (r < 0)
+ return r;
+
+ r = read_one_line_file(fs, &contents);
+ if (r < 0)
+ return r;
+
+ sc = strstrip(contents);
+ if (isempty(sc)) {
+ r = write_string_file(fs, agent, WRITE_STRING_FILE_DISABLE_BUFFER);
+ if (r < 0)
+ return r;
+ } else if (!path_equal(sc, agent))
+ return -EEXIST;
+
+ fs = mfree(fs);
+ r = cg_get_path(controller, NULL, "notify_on_release", &fs);
+ if (r < 0)
+ return r;
+
+ contents = mfree(contents);
+ r = read_one_line_file(fs, &contents);
+ if (r < 0)
+ return r;
+
+ sc = strstrip(contents);
+ if (streq(sc, "0")) {
+ r = write_string_file(fs, "1", WRITE_STRING_FILE_DISABLE_BUFFER);
+ if (r < 0)
+ return r;
+
+ return 1;
+ }
+
+ if (!streq(sc, "1"))
+ return -EIO;
+
+ return 0;
+}
+
+int cg_uninstall_release_agent(const char *controller) {
+ _cleanup_free_ char *fs = NULL;
+ int r;
+
+ r = cg_unified_controller(controller);
+ if (r < 0)
+ return r;
+ if (r > 0) /* Doesn't apply to unified hierarchy */
+ return -EOPNOTSUPP;
+
+ r = cg_get_path(controller, NULL, "notify_on_release", &fs);
+ if (r < 0)
+ return r;
+
+ r = write_string_file(fs, "0", WRITE_STRING_FILE_DISABLE_BUFFER);
+ if (r < 0)
+ return r;
+
+ fs = mfree(fs);
+
+ r = cg_get_path(controller, NULL, "release_agent", &fs);
+ if (r < 0)
+ return r;
+
+ r = write_string_file(fs, "", WRITE_STRING_FILE_DISABLE_BUFFER);
+ if (r < 0)
+ return r;
+
+ return 0;
+}