]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgrouptest: let check_task() receive a pid as argument
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 9 Jan 2009 16:27:48 +0000 (16:27 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 9 Jan 2009 16:27:48 +0000 (16:27 +0000)
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>

The patch would get a reject because of modifications in an earlier
patch. Hence updating the patch by fixing the reject.

This patch makes the function check_task() capable of checking if a pid
other than the calling process is attached to a particlular group. Earlier
it was checking for the calling process only.
For optimization purpose 0 is used to indicate that the task to be attached
is the current task and hence call cgroup_gettid() only once.

Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com>
Acked-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@311 4f4bb910-9a46-0410-90c8-c897d4f1cd53

tests/libcgrouptest.h
tests/test_functions.c

index 36edc2680f90c0e3d81831877df4813459d00756..00765bde0f51c3c0321202900cfc530d34408f35 100644 (file)
@@ -138,7 +138,7 @@ struct cgroup *new_cgroup(char *group, char *controller_name,
         char *control_file, int value_type, struct cntl_val_t cval,
                                         struct uid_gid_t ids, int i);
 int check_fsmounted(int multimnt);
-int check_task(char *tasksfile);
+int check_task(char *tasksfile, pid_t pid);
 /* function to print messages in better format */
 void message(int num, int pass, const char *api,
                                                 int ret, char *extra);
index 4b8bcbb0bb14d52ddcbf083fb5f2704dede06521..fcdd308ac88bf47686fa93a9d32b6d39df0feb87 100644 (file)
@@ -96,12 +96,12 @@ void test_cgroup_attach_task(int retcode, struct cgroup *cgrp,
                build_path(tasksfile, mountpoint,
                                         group1, "tasks");
 
-               if (check_task(tasksfile)) {
+               if (check_task(tasksfile, 0)) {
                        if (fs_mounted == 2) {
                                /* multiple mounts */
                                build_path(tasksfile2, mountpoint2,
                                                         group2, "tasks");
-                               if (check_task(tasksfile2)) {
+                               if (check_task(tasksfile2, 0)) {
                                        message(i, PASS, "attach_task()",
                                                 retval, info[TASKINGRP]);
                                } else {
@@ -613,7 +613,7 @@ error:
  * Checks if the current task belongs to the given tasks file
  * @param tasksfile the task file to be tested for the task
  */
-int check_task(char *tasksfile)
+int check_task(char *tasksfile, pid_t pid)
 {
        FILE *file;
        pid_t curr_tid, tid;
@@ -626,7 +626,11 @@ int check_task(char *tasksfile)
                exit(1);
        }
 
-       curr_tid = cgrouptest_gettid();
+       if (pid)
+               curr_tid = pid;
+       else
+               curr_tid = cgrouptest_gettid();
+
        while (!feof(file)) {
                fscanf(file, "%u", &tid);
                if (tid == curr_tid) {