bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] openat: reduce syscalls in first probe of /proc


From: Eric Blake
Subject: [PATCH] openat: reduce syscalls in first probe of /proc
Date: Mon, 9 May 2011 16:37:33 -0600

open/access/close is cheaper than open/stat/stat/close.

* lib/openat-proc.c (openat_proc_name): Simplify.
* modules/openat (Depends-on): Drop same-inode.
Reported by Bastien ROUCARIES.

Signed-off-by: Eric Blake <address@hidden>
---

I'm pushing this.

 ChangeLog         |    7 +++++++
 lib/openat-proc.c |   13 +++----------
 modules/openat    |    1 -
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 22442c5..64a7e8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-05-09  Eric Blake  <address@hidden>
+
+       openat: reduce syscalls in first probe of /proc
+       * lib/openat-proc.c (openat_proc_name): Simplify.
+       * modules/openat (Depends-on): Drop same-inode.
+       Reported by Bastien ROUCARIES.
+
 2011-05-09  Jim Meyering  <address@hidden>

        maint.mk: tweak new rule's name not to impinge
diff --git a/lib/openat-proc.c b/lib/openat-proc.c
index 4a470c5..d4659ff 100644
--- a/lib/openat-proc.c
+++ b/lib/openat-proc.c
@@ -31,7 +31,6 @@
 #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,
@@ -80,15 +79,9 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char 
const *file)
         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 abd3b63..c0cb834 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
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]