[PATCH] support: Implement <support/descriptors.h> to track file descriptors

Florian Weimer fweimer@redhat.com
Fri Nov 30 04:43:00 GMT 2018


* Carlos O'Donell:

>> +  DIR *fds = opendir ("/proc/self/fd");
>
> This makes support/descriptors.h dependent on /proc/self/fd?
>
> Can we exit UNSUPPORTED if it doesn't exist?

I think even Hurd has it.

I think it's a severe environmental problem if /proc does not exist, so
a failure is acceptable in this case.

>> +      char path[100];
>
> Why not PATH_MAX?

It's not defined on Hurd.

> We should not stat a truncated fd path since it might match another fd?
>
> 	 assert (strlen(e->d_name) < PATH_MAX);

We would get a compile-time failure with current GCC if truncation is
possible, I think:

>> +      snprintf (path, sizeof (path), "/proc/self/fd/%ld", fd);

I could try to count more precisely how many bytes are actually needed,
but that seemed like a waste of mental resources.  Should I use
xasprintf instead, to make clear that there is no truncation?

Thanks,
Florian



More information about the Libc-alpha mailing list