Subject: Re: [PATCH iproute2-next 2/2] netns: allow to dump and monitor nsid

From: Nicolas Dichtel <[email-masked]>
Date: Fri, 10 Apr 2015 16:03:35 +0200

Le 09/04/2015 10:36, Vadim Kochan a écrit :
> On Thu, Apr 09, 2015 at 10:30:14AM +0200, Nicolas Dichtel wrote:
[snip]
>> +	dir = opendir(NETNS_RUN_DIR);
>> +	if (!dir)
>> +		return;
>> +
>> +	while ((entry = readdir(dir)) != NULL) {
>> +		if (strcmp(entry->d_name, ".") == 0)
>> +			continue;
>> +		if (strcmp(entry->d_name, "..") == 0)
>> +			continue;
>> +		nsid = get_netnsid_from_name(entry->d_name);
>> +
>> +		if (nsid >= 0)
>> +			netns_map_add(nsid, entry->d_name);
>> +	}
>
> May be lib/namespace.c -> netns_foreach will be useful here  ?
I'm not fully convinced, because to use netns_foreach I need to have
another intermediate function.

[snip]
>> +	dir = opendir(NETNS_RUN_DIR);
>> +	if (!dir)
>> +		return -ENOENT;
>> +
>> +	while ((entry = readdir(dir)) != NULL) {
>> +		if (strcmp(entry->d_name, ".") == 0)
>> +			continue;
>> +		if (strcmp(entry->d_name, "..") == 0)
>> +			continue;
>> +		id = get_netnsid_from_name(entry->d_name);
>> +
>> +		if (nsid == id) {
>> +			strcpy(name, entry->d_name);
>> +			closedir(dir);
>> +			return 0;
>> +		}
>> +	}
>
> And may be here too ?
Same here. And this implies to also define a new structure to pass 'name' and
'nsid' to this new intermediate function. This will make the code more complex
to read.

Regards,
Nicolas