From: Eric Blake Date: Mon, 9 May 2011 22:27:35 +0000 (-0600) Subject: openat: reduce syscalls in first probe of /proc X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb94582289e914a4dc2947a49bb16045c2b6d5c4;p=pspp openat: reduce syscalls in first probe of /proc open/access/close is cheaper than open/stat/stat/close. Use O_DIRECTORY for safety. * 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. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index be6516f881..36fb1fecf6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-05-09 Eric Blake + + 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 maint.mk: change semantics/name of tight_scope variables diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 4a470c5b9d..5711896a16 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -31,7 +31,6 @@ #include #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, @@ -75,20 +74,15 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) 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); } } diff --git a/modules/openat b/modules/openat index abd3b63b95..c0cb83405c 100644 --- a/modules/openat +++ b/modules/openat @@ -30,7 +30,6 @@ mkdir [test $HAVE_MKDIRAT = 0] open openat-die rmdir [test $REPLACE_UNLINKAT = 1] -same-inode save-cwd stdbool sys_stat