From: Kamalesh Babulal Date: Tue, 18 Jan 2022 15:22:13 +0000 (-0700) Subject: api.c: cache cgrules with CGFLAG_USECACHE flag X-Git-Tag: v3.0~249 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80a0bd4b8873df38060309e775d609dcc219531f;p=thirdparty%2Flibcgroup.git api.c: cache cgrules with CGFLAG_USECACHE flag pam_cgroup.so plugin uses /etc/cgrules.conf to assign processes to the requested cgroup. This works well with active cgrulesengd but in the instances where cgrulesengd is disabled, the rules are not read and cached by default. Fix this is by reloading and caching the rules when called with CGFLAG_USECACHE flag. Fixes: https://github.com/libcgroup/libcgroup/issues/84 Reported-by: Kent Overstreet Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka TJH: Minor commit comment changes --- diff --git a/src/api.c b/src/api.c index 88ae1adb..1cadc73f 100644 --- a/src/api.c +++ b/src/api.c @@ -3876,6 +3876,20 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid, goto finished; } + /* + * User had asked to find the matching rule (if one exist) in the + * cached rules but the list might be empty due to the inactive + * cgrulesengd. Lets emulate its behaviour of caching the rules + * by reloading the rules from the configuration file. + */ + if ((flags & CGFLAG_USECACHE) && (rl.head == NULL)) { + cgroup_warn("Warning: no cached rules found, trying to reload " + " from %s.\n", CGRULES_CONF_FILE); + ret = cgroup_reload_cached_rules(); + if (ret != 0) + goto finished; + } + /* * If the user did not ask for cached rules, we must parse the * configuration to find a matching rule (if one exists). Else, we'll