ping...

On 2014/9/22 17:32, Weng Meiling wrote:
> On 2014/9/20 17:13, Weng Meiling wrote:
>> Hi guys,
>> In our environment, we found the following problem:
>>
>> we have a process and it has some threads with the same name:
>>
>> # ps  -L -eo comm,pid,lwp,args,start |grep Test
>> Testd          4489   4489 /usr/bin/Testd           09:03:39
>> Testd          4489   4582 /usr/bin/Testd           09:03:39
>> Testd          4489   4584 /usr/bin/Testd          09:03:39
>> Testd          4489   4585 /usr/bin/Testd           09:03:39
>> Testd          4489   4587 /usr/bin/Testd           09:03:39
>>
>>
>> the cgrule is:
>>
>> *:Testd          cpu,memory,cpuset          test
>>
>> if the Testd has been running, and then restart or start cgred service, just 
>> the process
>> 4489 will move into test cgroup, but the other threads just leave in the 
>> root cgroup,
>> the reason seems that cgred just move running processes according /proc, but 
>> thread isn't
>> listed under /proc, should not cgred deal with this situation?
>>
> 
> The following patch maybe can deal with this situation, another way to deal 
> with this situation is
> to use cgroup.procs file then tasks in cgroup_attach_task_pid() according to 
> some conditions,
> but this need to modify many apis, so I think the following patch is more 
> suitable, just modify one
> api. What do you think about this?
> 
> Subject: [PATCH] cgred: cgred should deal with threads when starts
> 
> Signed-off-by: Weng Meiling <wengmeiling.w...@huawei.com>
> ---
>  src/api.c | 44 ++++++++++++++++++++++++++++++++------------
>  1 file changed, 32 insertions(+), 12 deletions(-)
> 
> diff --git a/src/api.c b/src/api.c
> index 8106eff..951cafb 100644
> --- a/src/api.c
> +++ b/src/api.c
> @@ -3189,25 +3189,45 @@ int cgroup_change_all_cgroups(void)
> 
>       while ((pid_dir = readdir(dir)) != NULL) {
>               int err, pid;
> -             uid_t euid;
> -             gid_t egid;
> -             char *procname = NULL;
> +             DIR *subdir;
> +             struct dirent *subpid_dir = NULL;
> +             char subpath[FILENAME_MAX];
> 
>               err = sscanf(pid_dir->d_name, "%i", &pid);
>               if (err < 1)
>                       continue;
> 
> -             err = cgroup_get_uid_gid_from_procfs(pid, &euid, &egid);
> -             if (err)
> -                     continue;
> +             /* sscanf the task directory to deal with threads */
> +             memset(subpath, 0, FILENAME_MAX);
> +             sprintf(subpath, "/proc/%d/task", pid);
> +             subdir = opendir(subpath);
> +             if (!subdir) {
> +                     closedir(dir);
> +                     return -ECGOTHER;
> +             }
> 
> -             err = cgroup_get_procname_from_procfs(pid, &procname);
> -             if (err)
> -                     continue;
> +             while ((subpid_dir = readdir(subdir)) != NULL) {
> +                     int subpid;
> +                     gid_t egid;
> +                     uid_t euid;
> +                     char *procname = NULL;
> +                     err = sscanf(subpid_dir->d_name, "%i", &subpid);
> +                     if (err < 1)
> +                             continue;
> 
> -             err = cgroup_change_cgroup_flags(euid, egid, procname, pid, 0);
> -             if (err)
> -                     cgroup_dbg("cgroup change pid %i failed\n", pid);
> +                     err = cgroup_get_uid_gid_from_procfs(subpid, &euid, 
> &egid);
> +                     if (err)
> +                             continue;
> +
> +                     err = cgroup_get_procname_from_procfs(subpid, 
> &procname);
> +                     if (err)
> +                             continue;
> +
> +                     err = cgroup_change_cgroup_flags(euid, egid, procname, 
> subpid, 0);
> +                     if (err)
> +                             cgroup_dbg("cgroup change pid %i failed\n", 
> subpid);
> +             }
> +             closedir(subdir);
>       }
> 
>       closedir(dir);
> 



------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to