This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: src/winsup/cygwin ChangeLog fhandler_proc.cc f ...


On 10/09/2014 07:24 AM, corinna@cygwin.com wrote:

> Log message:
> 	* fhandler_proc.cc (fhandler_proc::readdir): Set dirent d_type.
> 	* fhandler_process.cc (fhandler_process::readdir): Ditto.
> 	* fhandler_procnet.cc (fhandler_procnet::readdir): Ditto.
> 	* fhandler_procsys.cc (fhandler_procsys::readdir): Ditto.
> 	* fhandler_procsysvipc.cc (fhandler_procsysvipc::readdir): Ditto.
> 	*  fhandler_virtual.h (virt_ftype_to_dtype): Define new inline function
> 	to generate dirent d_type from virtual_ftype_t.

Most of these look okay; but I have a problem with fhandler_procsys.cc:

> @@ -357,10 +358,17 @@
>  	res = ENMFILE;
>        else
>  	{
> +	  struct stat st;
> +	  char *file = tp.c_get ();
> +
>  	  sys_wcstombs (de->d_name, NAME_MAX + 1, f.dbi.ObjectName.Buffer,
>  			f.dbi.ObjectName.Length / sizeof (WCHAR));
>  	  de->d_ino = hash_path_name (get_ino (), de->d_name);
> -	  de->d_type = 0;
> +	  stpcpy (stpcpy (stpcpy (file, get_name ()), "/"), de->d_name);
> +	  if (!lstat64 (file, &st))
> +	    de->d_type = IFTODT (st.st_mode);
> +	  else
> +	    de->d_type = DT_UNKNOWN;

The whole point of d_type is for optimization, to tell a process when it
can avoid the overhead of an lstat() because the system was able to
obtain the information in a cheaper manner.  But if you have to resort
to an lstat() to get the information, then you are wasting cycles on the
case of a user that doesn't care about d_type.  I'd rather we always
return DT_UNKNOWN if the only way we'd get a better type is by calling
lstat().

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]