]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: Don't fail a recursive write if value isn't dirty 30/head
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 10 Mar 2021 18:20:24 +0000 (18:20 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 10 Mar 2021 18:20:24 +0000 (18:20 +0000)
When cgroup_modify_cgroup() invokes cgroup_set_values_recursive(),
some of the settings within the cgroup may not be writable.  Avoid
failing the entire write by ignoring write failures on settings that
do not explicitly have the dirty flag set.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c
src/libcgroup-internal.h

index 40637a5305cc515f09927f4ab38883979fe5d2b2..4de07f39bd68211081f9f0382c188a11c1537d2a 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1892,7 +1892,8 @@ static int cg_set_control_value(char *path, const char *val)
  * @param controller The controller whose values are being updated
  */
 STATIC int cgroup_set_values_recursive(const char * const base,
-       const struct cgroup_controller * const controller)
+       const struct cgroup_controller * const controller,
+       bool ignore_non_dirty_failures)
 {
        char *path = NULL;
        int error = 0, ret, j;
@@ -1913,6 +1914,15 @@ STATIC int cgroup_set_values_recursive(const char * const base,
                free(path);
                path = NULL;
 
+               if (error && ignore_non_dirty_failures &&
+                   !controller->values[j]->dirty) {
+                       /* We failed to set this value, but it wasn't
+                        * marked as dirty, so ignore the failure.
+                        */
+                       error = 0;
+                       continue;
+               }
+
                if (error)
                        goto err;
 
@@ -2142,7 +2152,7 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
                        continue;
 
                error = cgroup_set_values_recursive(base,
-                               cgroup->controller[i]);
+                               cgroup->controller[i], true);
                if (error)
                        goto err;
        }
@@ -2393,7 +2403,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
                        goto err;
 
                error = cgroup_set_values_recursive(base,
-                               cgroup->controller[k]);
+                               cgroup->controller[k], false);
                if (error)
                        goto err;
 
index 0367c60a91ec829ce6d26e1a1ce0142ccd2f7991..1dfc92b5b51b6ac45d32f050b0d223347288800c 100644 (file)
@@ -389,7 +389,8 @@ int cgroup_process_v1_mnt(char *controllers[], struct mntent *ent,
 int cgroup_process_v2_mnt(struct mntent *ent, int *mnt_tbl_idx);
 
 int cgroup_set_values_recursive(const char * const base,
-       const struct cgroup_controller * const controller);
+       const struct cgroup_controller * const controller,
+       bool ignore_non_dirty_failures);
 
 int cgroup_chown_chmod_tasks(const char * const cg_path,
                             uid_t uid, gid_t gid, mode_t fperm);