[lvm-devel] [PATCH 4/7][retry remove] Add new "dm_device_has_holders" fn to libdm

Peter Rajnoha prajnoha at redhat.com
Wed Sep 21 11:23:13 UTC 2011


On 09/20/2011 03:10 PM +0100, Zdenek Kabelac wrote:
> Dne 20.9.2011 14:57, Peter Rajnoha napsal(a):
>> +	if (!(d = opendir(dir))) {
>> +		log_sys_error("opendir", dir);
>> +		return 0;
>> +	}
>> +
>> +	while ((dirent = readdir(d)))
>> +		if (strcmp(dirent->d_name, ".") && strcmp(dirent->d_name, ".."))
>> +			break;
> 
> Hmm since  readdir() may return -1 - this looks like error check is missing here

Well, this is a version of readdir that returns either NULL or a pointer to a dirent
structure - man 2 readdir vs. man 3 readdir (difference in POSIX compliance).

The POSIX version returns an error only if the DIR* stream descriptor is wrong, but
this one should be fine since we already check the error in opendir just before this
call. I think it's OK to do it this way.

Peter




More information about the lvm-devel mailing list