summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>2009-06-26 14:51:33 +0900
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-29 16:51:11 +0530
commit3f066c5cec75b9a75a533e6403b25a988ed66986 (patch)
tree0a5ee430e5d3bd042388978266bfb15cbe98ec4f /src
parent581ce3c1ebbfdf0026de7bee75bd928be2a39982 (diff)
downloadlibcg-3f066c5cec75b9a75a533e6403b25a988ed66986.tar.gz
libcg-3f066c5cec75b9a75a533e6403b25a988ed66986.tar.xz
libcg-3f066c5cec75b9a75a533e6403b25a988ed66986.zip
Apply a new rule to 'cgclassify' command.
Hi, Changelog of v6: ================ * Change the cgroup_get_procname_from_procfs() calling for the returning value's change. Changelog of v5: ================ * Add the description of a new option "--sticky". Changelog of v4: ================ * Add a new option "--sticky" so that cgrulesengd daemon does not change the children's cgroups which is classified by 'cgclassify' command. Changelog of v3: ================ * New patch. Description: ============ This patch applies a new rule to 'cgclassify' command. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/tools/cgclassify.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c
index ceaca34..74d5bec 100644
--- a/src/tools/cgclassify.c
+++ b/src/tools/cgclassify.c
@@ -57,36 +57,51 @@ int change_group_path(pid_t pid, struct cgroup_group_spec *cgroup_list[])
/*
* Change process group as specified in cgrules.conf.
*/
-int change_group_uid_gid(pid_t pid)
+int change_group_based_on_rule(pid_t pid)
{
uid_t euid;
gid_t egid;
- int ret;
+ char *procname = NULL;
+ int ret = -1;
/* Put pid into right cgroup as per rules in /etc/cgrules.conf */
if (cgroup_get_uid_gid_from_procfs(pid, &euid, &egid)) {
fprintf(stderr, "Error in determining euid/egid of"
" pid %d\n", pid);
- return -1;
+ goto out;
+ }
+ ret = cgroup_get_procname_from_procfs(pid, &procname);
+ if (ret) {
+ fprintf(stderr, "Error in determining process name of"
+ " pid %d\n", pid);
+ goto out;
}
- /* Change the cgroup by determining the rules based on uid */
- ret = cgroup_change_cgroup_uid_gid(euid, egid, pid);
+ /* Change the cgroup by determining the rules */
+ ret = cgroup_change_cgroup_flags(euid, egid, procname, pid, 0);
if (ret) {
fprintf(stderr, "Error: change of cgroup failed for"
- " pid %d: %s\n",
- pid, cgroup_strerror(ret));
- return -1;
+ " pid %d: %s\n", pid, cgroup_strerror(ret));
+ goto out;
}
-
- return 0;
+ ret = 0;
+out:
+ if (procname)
+ free(procname);
+ return ret;
}
+static struct option longopts[] = {
+ {"sticky", no_argument, NULL, 's'},
+ {0, 0, 0, 0}
+};
+
int main(int argc, char *argv[])
{
int ret = 0, i, exit_code = 0;
pid_t pid;
int cg_specified = 0;
+ int flag_child = 0;
struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
int c;
@@ -94,13 +109,13 @@ int main(int argc, char *argv[])
if (argc < 2) {
fprintf(stderr, "usage is %s "
"[-g <list of controllers>:<relative path to cgroup>] "
- "<list of pids> \n",
+ "[--sticky] <list of pids> \n",
argv[0]);
exit(2);
}
memset(cgroup_list, 0, sizeof(cgroup_list));
- while ((c = getopt(argc, argv, "+g:")) > 0) {
+ while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
switch (c) {
case 'g':
if (parse_cgroup_spec(cgroup_list, optarg)) {
@@ -110,6 +125,9 @@ int main(int argc, char *argv[])
}
cg_specified = 1;
break;
+ case 's':
+ flag_child |= CGROUP_DAEMON_UNCHANGE_CHILDREN;
+ break;
default:
fprintf(stderr, "Invalid command line option\n");
exit(2);
@@ -128,10 +146,15 @@ int main(int argc, char *argv[])
for (i = optind; i < argc; i++) {
pid = (uid_t) atoi(argv[i]);
+ if (flag_child)
+ ret = cgroup_register_unchanged_process(pid, flag_child);
+ if (ret)
+ exit_code = 1;
+
if (cg_specified)
ret = change_group_path(pid, cgroup_list);
else
- ret = change_group_uid_gid(pid);
+ ret = change_group_based_on_rule(pid);
/* if any group change fails */
if (ret)