[LTP] [PATCH v3 1/3] Add tst_purge_dir() helper function

Martin Doucha mdoucha@suse.cz
Fri Jan 24 13:09:09 CET 2020


On 1/24/20 11:23 AM, Cyril Hrubis wrote:
>> -	fd = open(obj, O_DIRECTORY | O_NOFOLLOW);
>> -	if (fd != -1) {
>> -		close(fd);
>> +	errno = 0;
>> +	fd = open(path, O_DIRECTORY | O_NOFOLLOW);
>>  
>> -		/* Do NOT perform the request if the directory is "/" */
>> -		if (!strcmp(obj, "/")) {
>> -			if (errmsg != NULL) {
>> -				sprintf(err_msg, "Cannot remove /");
>> -				*errmsg = err_msg;
>> -			}
>> -			return -1;
>> +	if (fd < 0) {
>> +		if (errptr) {
>> +			sprintf(err_msg,
>> +				"Cannot open directory %s; errno=%d: %s",
>> +				path, errno, tst_strerrno(errno));
>> +			*errptr = err_msg;
>>  		}
> 
> Isn't this check useless here? Or are we trying to avoid escaping the
> directory via symlink?

You're right. I've just blindly copied the check from rmobj() which uses
it to decide whether the FS node should be removed using rmdir() or
unlink(). I'll move the open() check to tst_purge_dir() so it doesn't
get called twice for each subdirectory and drop the useless O_NOFOLLOW.

-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


More information about the ltp mailing list