[CRIU] [PATCH 1/8] cgroup: drop useless name variable in collect_cgroups

Dmitry Safonov dsafonov at virtuozzo.com
Thu Jul 21 07:45:06 PDT 2016


On 07/21/2016 05:44 PM, Pavel Emelyanov wrote:
> On 07/15/2016 10:28 PM, Dmitry Safonov wrote:
>> It looks like, it's completely not needed here.
>>
>> criu/cgroup.c:582:4: warning: Value stored to 'name' is never read
>>                         name = cc->name + 5;
>>                         ^      ~~~~~~~~~~~~
>>
>> Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
>> ---
>>  criu/cgroup.c | 11 ++++-------
>>  1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/criu/cgroup.c b/criu/cgroup.c
>> index 72d80c40b3e7..eb1f6bbd7005 100644
>> --- a/criu/cgroup.c
>> +++ b/criu/cgroup.c
>> @@ -547,7 +547,7 @@ static int collect_cgroups(struct list_head *ctls)
>>
>>  	list_for_each_entry(cc, ctls, l) {
>>  		char path[PATH_MAX], mopts[1024];
>> -		char *name, prefix[] = ".criu.cgmounts.XXXXXX";
>> +		char prefix[] = ".criu.cgmounts.XXXXXX";
>>  		struct cg_controller *cg;
>>
>>  		current_controller = NULL;
>> @@ -578,13 +578,10 @@ static int collect_cgroups(struct list_head *ctls)
>>  		if (!opts.manage_cgroups)
>>  			continue;
>>
>> -		if (strstartswith(cc->name, "name=")) {
>> -			name = cc->name + 5;
>> +		if (strstartswith(cc->name, "name="))
>>  			snprintf(mopts, sizeof(mopts), "none,%s", cc->name);
>> -		} else {
>> -			name = cc->name;
>> -			snprintf(mopts, sizeof(mopts), "%s", name);
>> -		}
>> +		else
>> +			snprintf(mopts, sizeof(mopts), "%s", cc->name);
>>
>
> Am I misreading this?

Hmm, if foo is cc->name,

> Was:
>
> if (foo ~= "^name=")
> 	name = foo + 5;
> 	sprintf(... name);

here was sprintf(..., foo)

> else
> 	name = foo;
> 	sprintf(... name);
>
> now
>
> if (foo != "^name=")
> 	sprintf(... foo);
> else
> 	sprintf(... foo);
>
> while should likely be
>
> if (foo != "^name=")
> 	sprintf(... foo + 5);
> else
> 	sprintf(... foo);
>
>>  		if (mkdtemp(prefix) == NULL) {
>>  			pr_perror("can't make dir for cg mounts");
>>
>


-- 
              Dmitry


More information about the CRIU mailing list