+2011-05-09 Eric Blake <eblake@redhat.com>
+
+ openat: reduce syscalls in first probe of /proc
+ * lib/openat-proc.c (openat_proc_name): Require that /proc/self/fd
+ be a directory. Simplify the probe for .. bugs.
+ * modules/openat (Depends-on): Drop same-inode.
+ Reported by Bastien ROUCARIES.
+
2011-05-09 Jim Meyering <meyering@redhat.com>
maint.mk: change semantics/name of tight_scope variables
#include <unistd.h>
#include "intprops.h"
-#include "same-inode.h"
/* The results of open() in this file are not used with fchdir,
and we do not leak fds to any single-threaded code that could use stdio,
problem is exhibited on code that built on Solaris 8 and
running on Solaris 10. */
- int proc_self_fd = open ("/proc/self/fd", O_SEARCH);
+ int proc_self_fd = open ("/proc/self/fd",
+ O_SEARCH | O_DIRECTORY | O_NOCTTY | O_NONBLOCK);
if (proc_self_fd < 0)
proc_status = -1;
else
{
- struct stat proc_self_fd_dotdot_st;
- struct stat proc_self_st;
- char dotdot_buf[PROC_SELF_FD_NAME_SIZE_BOUND (sizeof ".." - 1)];
- sprintf (dotdot_buf, PROC_SELF_FD_FORMAT, proc_self_fd, "..");
- proc_status =
- ((stat (dotdot_buf, &proc_self_fd_dotdot_st) == 0
- && stat ("/proc/self", &proc_self_st) == 0
- && SAME_INODE (proc_self_fd_dotdot_st, proc_self_st))
- ? 1 : -1);
+ char dotdot_buf[PROC_SELF_FD_NAME_SIZE_BOUND (sizeof "../fd" - 1)];
+ sprintf (dotdot_buf, PROC_SELF_FD_FORMAT, proc_self_fd, "../fd");
+ proc_status = access (dotdot_buf, F_OK) ? -1 : 1;
close (proc_self_fd);
}
}