[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH] fchdir: move fd shadowing into fd-hook
From: |
Eric Blake |
Subject: |
[RFC PATCH] fchdir: move fd shadowing into fd-hook |
Date: |
Wed, 27 Apr 2011 18:32:40 -0600 |
In order to eventually add socket nonblocking status into
fd shadowing, it is useful to move the existing fchdir name
shadowing into a common file.
* modules/fd-hook (Depends-on): Add dosname, dup2,
filenamecat-lgpl, getcwd-lgpl, malloc-posix, realloc-posix,
stdbool, strdup-posix.
* modules/fchdir (Depends-on): Add fd-hook, drop unused modules.
* modules/dup2 (Depends-on): Add fd-hook.
* modules/dup3 (Depends-on): Likewise.
* modules/open (Depends-on): Likewise.
* modules/fcntl (Depends-on): Likewise.
* lib/fchdir.c (rpl_fstat, rpl_closedir, rpl_closedir, rpl_dup)
(fchdir): Rewrite to use public interfaces.
(ensure_dirs_slot, get_name, _gl_unregister_fd, _gl_register_fd)
(_gl_register_dup, _gl_directory_name): Move and rename...
* lib/fd-hook.c (ensure_shadows_slot, get_absolute_name)
(register_shadow_fd_name, get_shadow_fd_name)
(register_shadow_dup_fd, unregister_shadow_fd): ...here.
* lib/fd-hook.h: Add new prototypes.
* lib/unistd.in.h: Drop unused prototypes.
* lib/dup2.c (dup2): Update callers.
* lib/open.c (open): Likewise.
* lib/close.c (rpl_close): Likewise.
* lib/dup3.c (dup3): Likewise.
* lib/fcntl.c (dupfd, rpl_fcntl): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
Note that fchdir is currently LGPLv3+ (although that might be
worth relaxing to v2+), while fd-hook is LGPLv2+, so this
code motion represents a change in license. Jim and Bruno
need to give consent to that action.
I'm posting this now for review comments; it may still need
tweaks once I start coding up socket nonblocking status
tracking for mingw.
ChangeLog | 24 +++++++
lib/close.c | 2 +-
lib/dup2.c | 6 +-
lib/dup3.c | 3 +-
lib/fchdir.c | 173 +++--------------------------------------------------
lib/fcntl.c | 8 ++-
lib/fd-hook.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
lib/fd-hook.h | 32 +++++++++-
lib/open.c | 6 +-
lib/unistd.in.h | 8 ---
modules/dup2 | 1 +
modules/dup3 | 1 +
modules/fchdir | 8 ---
modules/fcntl | 1 +
modules/fd-hook | 8 +++
modules/open | 1 +
16 files changed, 267 insertions(+), 194 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cd32fd1..2d2afe8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
2011-04-27 Eric Blake <address@hidden>
+ fchdir: move fd shadowing into fd-hook
+ * modules/fd-hook (Depends-on): Add dosname, dup2,
+ filenamecat-lgpl, getcwd-lgpl, malloc-posix, realloc-posix,
+ stdbool, strdup-posix.
+ * modules/fchdir (Depends-on): Add fd-hook, drop unused modules.
+ * modules/dup2 (Depends-on): Add fd-hook.
+ * modules/dup3 (Depends-on): Likewise.
+ * modules/open (Depends-on): Likewise.
+ * modules/fcntl (Depends-on): Likewise.
+ * lib/fchdir.c (rpl_fstat, rpl_closedir, rpl_closedir, rpl_dup)
+ (fchdir): Rewrite to use public interfaces.
+ (ensure_dirs_slot, get_name, _gl_unregister_fd, _gl_register_fd)
+ (_gl_register_dup, _gl_directory_name): Move and rename...
+ * lib/fd-hook.c (ensure_shadows_slot, get_absolute_name)
+ (register_shadow_fd_name, get_shadow_fd_name)
+ (register_shadow_dup_fd, unregister_shadow_fd): ...here.
+ * lib/fd-hook.h: Add new prototypes.
+ * lib/unistd.in.h: Drop unused prototypes.
+ * lib/dup2.c (dup2): Update callers.
+ * lib/open.c (open): Likewise.
+ * lib/close.c (rpl_close): Likewise.
+ * lib/dup3.c (dup3): Likewise.
+ * lib/fcntl.c (dupfd, rpl_fcntl): Likewise.
+
tests: drop unused link dependency
* modules/areadlinkat-tests (Makefile.am): Drop stale LDADD.
* modules/dirent-safer-tests (Makefile.am): Likewise.
diff --git a/lib/close.c b/lib/close.c
index 2c41c75..473481a 100644
--- a/lib/close.c
+++ b/lib/close.c
@@ -35,7 +35,7 @@ rpl_close (int fd)
#if REPLACE_FCHDIR
if (retval >= 0)
- _gl_unregister_fd (fd);
+ unregister_shadow_fd (fd);
#endif
return retval;
diff --git a/lib/dup2.c b/lib/dup2.c
index e00dc7b..895cb06 100644
--- a/lib/dup2.c
+++ b/lib/dup2.c
@@ -25,6 +25,8 @@
#include <errno.h>
#include <fcntl.h>
+#include "fd-hook.h"
+
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Get declarations of the Win32 API functions. */
# define WIN32_LEAN_AND_MEAN
@@ -82,7 +84,7 @@ rpl_dup2 (int fd, int desired_fd)
errno = EBADF;
# if REPLACE_FCHDIR
if (fd != desired_fd && result != -1)
- result = _gl_register_dup (fd, result);
+ result = register_shadow_dup_fd (fd, result);
# endif
return result;
}
@@ -120,7 +122,7 @@ dup2 (int fd, int desired_fd)
result = fcntl (fd, F_DUPFD, desired_fd);
# if REPLACE_FCHDIR
if (0 <= result)
- result = _gl_register_dup (fd, result);
+ result = register_shadow_dup_fd (fd, result);
# endif
# else
result = dupfd (fd, desired_fd);
diff --git a/lib/dup3.c b/lib/dup3.c
index 2f87da6..1d35f41 100644
--- a/lib/dup3.c
+++ b/lib/dup3.c
@@ -25,6 +25,7 @@
#include <limits.h>
#include "binary-io.h"
+#include "fd-hook.h"
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Native Woe32 API. */
@@ -58,7 +59,7 @@ dup3 (int oldfd, int newfd, int flags)
have_dup3_really = 1;
# if REPLACE_FCHDIR
if (0 <= result)
- result = _gl_register_dup (oldfd, newfd);
+ result = register_shadow_dup_fd (oldfd, newfd);
# endif
return result;
}
diff --git a/lib/fchdir.c b/lib/fchdir.c
index 6dd704f..f78be56 100644
--- a/lib/fchdir.c
+++ b/lib/fchdir.c
@@ -19,18 +19,13 @@
/* Specification. */
#include <unistd.h>
-#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
-#include <stdbool.h>
#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include "dosname.h"
-#include "filenamecat.h"
+#include "fd-hook.h"
#ifndef REPLACE_OPEN_DIRECTORY
# define REPLACE_OPEN_DIRECTORY 0
@@ -44,159 +39,6 @@
descriptor, since mingw refuses to rename any in-use file system
object. */
-/* Array of file descriptors opened. If REPLACE_OPEN_DIRECTORY or if it points
- to a directory, it stores info about this directory. */
-typedef struct
-{
- char *name; /* Absolute name of the directory, or NULL. */
- /* FIXME - add a DIR* member to make dirfd possible on mingw? */
-} dir_info_t;
-static dir_info_t *dirs;
-static size_t dirs_allocated;
-
-/* Try to ensure dirs has enough room for a slot at index fd; free any
- contents already in that slot. Return false and set errno to
- ENOMEM on allocation failure. */
-static bool
-ensure_dirs_slot (size_t fd)
-{
- if (fd < dirs_allocated)
- free (dirs[fd].name);
- else
- {
- size_t new_allocated;
- dir_info_t *new_dirs;
-
- new_allocated = 2 * dirs_allocated + 1;
- if (new_allocated <= fd)
- new_allocated = fd + 1;
- new_dirs =
- (dirs != NULL
- ? (dir_info_t *) realloc (dirs, new_allocated * sizeof *dirs)
- : (dir_info_t *) malloc (new_allocated * sizeof *dirs));
- if (new_dirs == NULL)
- return false;
- memset (new_dirs + dirs_allocated, 0,
- (new_allocated - dirs_allocated) * sizeof *dirs);
- dirs = new_dirs;
- dirs_allocated = new_allocated;
- }
- return true;
-}
-
-/* Return an absolute name of DIR in malloc'd storage. */
-static char *
-get_name (char const *dir)
-{
- char *cwd;
- char *result;
- int saved_errno;
-
- if (IS_ABSOLUTE_FILE_NAME (dir))
- return strdup (dir);
-
- /* We often encounter "."; treat it as a special case. */
- cwd = getcwd (NULL, 0);
- if (!cwd || (dir[0] == '.' && dir[1] == '\0'))
- return cwd;
-
- result = mfile_name_concat (cwd, dir, NULL);
- saved_errno = errno;
- free (cwd);
- errno = saved_errno;
- return result;
-}
-
-/* Hook into the gnulib replacements for open() and close() to keep track
- of the open file descriptors. */
-
-/* Close FD, cleaning up any fd to name mapping if fd was visiting a
- directory. */
-void
-_gl_unregister_fd (int fd)
-{
- if (fd >= 0 && fd < dirs_allocated)
- {
- free (dirs[fd].name);
- dirs[fd].name = NULL;
- }
-}
-
-/* Mark FD as visiting FILENAME. FD must be non-negative, and refer
- to an open file descriptor. If REPLACE_OPEN_DIRECTORY is non-zero,
- this should only be called if FD is visiting a directory. Close FD
- and return -1 if there is insufficient memory to track the
- directory name; otherwise return FD. */
-int
-_gl_register_fd (int fd, const char *filename)
-{
- struct stat statbuf;
-
- assert (0 <= fd);
- if (REPLACE_OPEN_DIRECTORY
- || (fstat (fd, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)))
- {
- if (!ensure_dirs_slot (fd)
- || (dirs[fd].name = get_name (filename)) == NULL)
- {
- int saved_errno = errno;
- close (fd);
- errno = saved_errno;
- return -1;
- }
- }
- return fd;
-}
-
-/* Mark NEWFD as a duplicate of OLDFD; useful from dup, dup2, dup3,
- and fcntl. Both arguments must be valid and distinct file
- descriptors. Close NEWFD and return -1 if OLDFD is tracking a
- directory, but there is insufficient memory to track the same
- directory in NEWFD; otherwise return NEWFD. */
-int
-_gl_register_dup (int oldfd, int newfd)
-{
- assert (0 <= oldfd && 0 <= newfd && oldfd != newfd);
- if (oldfd < dirs_allocated && dirs[oldfd].name)
- {
- /* Duplicated a directory; must ensure newfd is allocated. */
- if (!ensure_dirs_slot (newfd)
- || (dirs[newfd].name = strdup (dirs[oldfd].name)) == NULL)
- {
- int saved_errno = errno;
- close (newfd);
- errno = saved_errno;
- newfd = -1;
- }
- }
- else if (newfd < dirs_allocated)
- {
- /* Duplicated a non-directory; ensure newfd is cleared. */
- free (dirs[newfd].name);
- dirs[newfd].name = NULL;
- }
- return newfd;
-}
-
-/* If FD is currently visiting a directory, then return the name of
- that directory. Otherwise, return NULL and set errno. */
-const char *
-_gl_directory_name (int fd)
-{
- if (0 <= fd && fd < dirs_allocated && dirs[fd].name != NULL)
- return dirs[fd].name;
- /* At this point, fd is either invalid, or open but not a directory.
- If dup2 fails, errno is correctly EBADF. */
- if (0 <= fd)
- {
- if (dup2 (fd, fd) == fd)
- errno = ENOTDIR;
- }
- else
- errno = EBADF;
- return NULL;
-}
-
#if REPLACE_OPEN_DIRECTORY
/* Return stat information about FD in STATBUF. Needed when
rpl_open() used a dummy file to work around an open() that can't
@@ -205,8 +47,9 @@ _gl_directory_name (int fd)
int
rpl_fstat (int fd, struct stat *statbuf)
{
- if (0 <= fd && fd < dirs_allocated && dirs[fd].name != NULL)
- return stat (dirs[fd].name, statbuf);
+ const char *dir = get_shadow_fd_name (fd);
+ if (dir)
+ return stat (dir, statbuf);
return fstat (fd, statbuf);
}
#endif
@@ -222,7 +65,7 @@ rpl_closedir (DIR *dp)
int retval = closedir (dp);
if (retval >= 0)
- _gl_unregister_fd (fd);
+ unregister_shadow_fd (fd);
return retval;
}
@@ -236,7 +79,7 @@ rpl_opendir (const char *filename)
if (dp != NULL)
{
int fd = dirfd (dp);
- if (0 <= fd && _gl_register_fd (fd, filename) != fd)
+ if (0 <= fd && register_shadow_fd_name (fd, filename) != fd)
{
int saved_errno = errno;
closedir (dp);
@@ -256,7 +99,7 @@ rpl_dup (int oldfd)
int newfd = dup (oldfd);
if (0 <= newfd)
- newfd = _gl_register_dup (oldfd, newfd);
+ newfd = register_shadow_dup_fd (oldfd, newfd);
return newfd;
}
@@ -266,6 +109,6 @@ rpl_dup (int oldfd)
int
fchdir (int fd)
{
- const char *name = _gl_directory_name (fd);
+ const char *name = get_shadow_fd_name (fd);
return name ? chdir (name) : -1;
}
diff --git a/lib/fcntl.c b/lib/fcntl.c
index d6a328c..49053c4 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -27,6 +27,8 @@
#include <stdarg.h>
#include <unistd.h>
+#include "fd-hook.h"
+
#if !HAVE_FCNTL
# define rpl_fcntl fcntl
#endif
@@ -137,7 +139,7 @@ dupfd (int oldfd, int newfd, int flags)
# if REPLACE_FCHDIR
if (0 <= result)
- result = _gl_register_dup (oldfd, result);
+ result = register_shadow_dup_fd (oldfd, result);
# endif
return result;
}
@@ -204,7 +206,7 @@ rpl_fcntl (int fd, int action, /* arg */...)
}
# if REPLACE_FCHDIR
if (0 <= result)
- result = _gl_register_dup (fd, result);
+ result = register_shadow_dup_fd (fd, result);
# endif
}
break;
@@ -235,7 +237,7 @@ rpl_fcntl (int fd, int action, /* arg */...)
have_dupfd_cloexec = 1;
# if REPLACE_FCHDIR
if (0 <= result)
- result = _gl_register_dup (fd, result);
+ result = register_shadow_dup_fd (fd, result);
# endif
}
else
diff --git a/lib/fd-hook.c b/lib/fd-hook.c
index 40fbeeb..9094cae 100644
--- a/lib/fd-hook.c
+++ b/lib/fd-hook.c
@@ -20,10 +20,185 @@
/* Specification. */
#include "fd-hook.h"
+#include <errno.h>
+#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
-/* Currently, this entire code is only needed for the handling of sockets
- on native Windows platforms. */
+#include "dosname.h"
+#include "filenamecat.h"
+
+#ifndef REPLACE_OPEN_DIRECTORY
+# define REPLACE_OPEN_DIRECTORY 0
+#endif
+
+/* Code for maintaining additional information associated with
+ particular file descriptors. Used by the 'fchdir' module for
+ maintaining directory names, and eventually by 'nonblocking' for
+ maintaining socket nonblocking status; both uses are only needed on
+ mingw. */
+
+#if REPLACE_FCHDIR
+
+/* Array of registered shadow file descriptors. */
+typedef struct
+{
+ char *name; /* Absolute name of a directory, or NULL, for fchdir. */
+ /* FIXME - add a DIR* member, for dirfd? */
+ /* FIXME - add socket blocking status, for nonblocking? */
+} shadow_fd;
+static shadow_fd *shadow_fds;
+static size_t shadows_allocated;
+
+/* Try to ensure shadow_fds has enough room for a slot at index FD;
+ free any contents already in that slot. Return false and set errno
+ to ENOMEM on allocation failure. */
+static bool
+ensure_shadow_slot (size_t fd)
+{
+ if (fd < shadows_allocated)
+ {
+ free (shadow_fds[fd].name);
+ shadow_fds[fd].name = NULL;
+ }
+ else
+ {
+ size_t new_allocated;
+ shadow_fd *new_shadows;
+
+ new_allocated = 2 * shadows_allocated + 1;
+ if (new_allocated <= fd)
+ new_allocated = fd + 1;
+ new_shadows =
+ (shadow_fds != NULL
+ ? (shadow_fd *) realloc (shadow_fds,
+ new_allocated * sizeof *shadow_fds)
+ : (shadow_fd *) malloc (new_allocated * sizeof *shadow_fds));
+ if (new_shadows == NULL)
+ return false;
+ memset (new_shadows + shadows_allocated, 0,
+ (new_allocated - shadows_allocated) * sizeof *shadow_fds);
+ shadow_fds = new_shadows;
+ shadows_allocated = new_allocated;
+ }
+ return true;
+}
+
+/* Return an absolute name of FILE in malloc'd storage. */
+static char *
+get_absolute_name (char const *file)
+{
+ char *cwd;
+ char *result;
+ int saved_errno;
+
+ if (IS_ABSOLUTE_FILE_NAME (file))
+ return strdup (file);
+
+ /* We often encounter "."; treat it as a special case. */
+ cwd = getcwd (NULL, 0);
+ if (!cwd || (file[0] == '.' && file[1] == '\0'))
+ return cwd;
+
+ result = mfile_name_concat (cwd, file, NULL);
+ saved_errno = errno;
+ free (cwd);
+ errno = saved_errno;
+ return result;
+}
+
+/* Create a shadow around FD visiting the directory DIR. Close FD and
+ return -1 if there is insufficient memory to track the directory
+ name; otherwise return FD. */
+int
+register_shadow_fd_name (int fd, const char *dir)
+{
+ struct stat statbuf;
+
+ if (fd < 0)
+ abort ();
+ if (REPLACE_OPEN_DIRECTORY
+ || (fstat (fd, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)))
+ {
+ if (!ensure_shadow_slot (fd)
+ || (shadow_fds[fd].name = get_absolute_name (dir)) == NULL)
+ {
+ int saved_errno = errno;
+ close (fd);
+ errno = saved_errno;
+ return -1;
+ }
+ }
+ return fd;
+}
+
+/* If FD was registered as a shadow directory, then return its name.
+ Otherwise, return NULL and set errno to ENOTDIR or EBADF. */
+const char *
+get_shadow_fd_name (int fd)
+{
+ if (0 <= fd && fd < shadows_allocated && shadow_fds[fd].name != NULL)
+ return shadow_fds[fd].name;
+ /* At this point, fd is either invalid, or open but not a directory.
+ If dup2 fails, errno is correctly EBADF. */
+ if (0 <= fd)
+ {
+ if (dup2 (fd, fd) == fd)
+ errno = ENOTDIR;
+ }
+ else
+ errno = EBADF;
+ return NULL;
+}
+
+/* Mark NEWFD as a duplicate of OLDFD; useful from dup, dup2, dup3,
+ and fcntl. Both arguments must be valid and distinct file
+ descriptors. Close NEWFD and return -1 if there is insufficient
+ memory to track the same information on NEWFD as exists in the
+ shadow for OLDFD; otherwise return NEWFD. */
+int
+register_shadow_dup_fd (int oldfd, int newfd)
+{
+ if (oldfd < 0 || newfd < 0 || oldfd == newfd)
+ abort ();
+ if (oldfd < shadows_allocated && shadow_fds[oldfd].name)
+ {
+ /* Duplicated a directory; must ensure newfd is allocated. */
+ if (!ensure_shadow_slot (newfd)
+ || (shadow_fds[newfd].name = strdup (shadow_fds[oldfd].name)) ==
NULL)
+ {
+ int saved_errno = errno;
+ close (newfd);
+ errno = saved_errno;
+ newfd = -1;
+ }
+ }
+ else if (newfd < shadows_allocated)
+ {
+ /* Duplicated a non-directory; ensure newfd is cleared. */
+ free (shadow_fds[newfd].name);
+ shadow_fds[newfd].name = NULL;
+ }
+ return newfd;
+}
+
+/* Remove any extra data associated with FD, which is now closed. */
+void
+unregister_shadow_fd (int fd)
+{
+ if (fd >= 0 && fd < shadow_fds)
+ {
+ free (shadow_fds[fd].name);
+ shadow_fds[fd].name = NULL;
+ }
+}
+
+#endif
+
+/* Currently, the remainder of this code is only needed for the
+ handling of sockets on native Windows platforms. */
#if WINDOWS_SOCKETS
/* The first and last link in the doubly linked list.
diff --git a/lib/fd-hook.h b/lib/fd-hook.h
index aab4d91..181748b 100644
--- a/lib/fd-hook.h
+++ b/lib/fd-hook.h
@@ -22,9 +22,37 @@
extern "C" {
#endif
+/* Code for maintaining additional information associated with
+ particular file descriptors. Used by the 'fchdir' module for
+ maintaining directory names, and eventually by 'nonblocking' for
+ maintaining socket nonblocking status; both uses are only needed on
+ mingw. */
-/* Currently, this entire code is only needed for the handling of sockets
- on native Windows platforms. */
+#if REPLACE_FCHDIR
+
+/* Create a shadow around FD visiting the directory DIR. Close FD and
+ return -1 if there is insufficient memory to track the directory
+ name; otherwise return FD. */
+int register_shadow_fd_name (int fd, const char *dir);
+
+/* If FD was registered as a shadow directory, then return its name.
+ Otherwise, return NULL and set errno to ENOTDIR or EBADF. */
+const char *get_shadow_fd_name (int fd);
+
+/* Mark NEWFD as a duplicate of OLDFD; useful from dup, dup2, dup3,
+ and fcntl. Both arguments must be valid and distinct file
+ descriptors. Close NEWFD and return -1 if there is insufficient
+ memory to track the same information on NEWFD as exists in the
+ shadow for OLDFD; otherwise return NEWFD. */
+int register_shadow_dup_fd (int oldfd, int newfd);
+
+/* Remove any extra data associated with FD, which is now closed. */
+void unregister_shadow_fd (int fd);
+
+#endif
+
+/* Currently, the remainder of this code is only needed for the
+ handling of sockets on native Windows platforms. */
#if WINDOWS_SOCKETS
diff --git a/lib/open.c b/lib/open.c
index e60b619..9c2fbab 100644
--- a/lib/open.c
+++ b/lib/open.c
@@ -24,6 +24,8 @@
#undef __need_system_fcntl_h
#include <sys/types.h>
+#include "fd-hook.h"
+
static inline int
orig_open (const char *filename, int flags, mode_t mode)
{
@@ -129,7 +131,7 @@ open (const char *filename, int flags, ...)
/* Maximum recursion depth of 1. */
fd = open ("/dev/null", flags, mode);
if (0 <= fd)
- fd = _gl_register_fd (fd, filename);
+ fd = register_shadow_fd_name (fd, filename);
}
else
errno = EACCES;
@@ -169,7 +171,7 @@ open (const char *filename, int flags, ...)
#if REPLACE_FCHDIR
if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
- fd = _gl_register_fd (fd, filename);
+ fd = register_shadow_fd_name (fd, filename);
#endif
return fd;
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index d216e38..9e09aed 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -430,14 +430,6 @@ _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
<http://www.opengroup.org/susv3xsh/fchdir.html>. */
# if ! @HAVE_FCHDIR@
_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
-
-/* Gnulib internal hooks needed to maintain the fchdir metadata. */
-_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
- _GL_ARG_NONNULL ((2));
-_GL_EXTERN_C void _gl_unregister_fd (int fd);
-_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
-_GL_EXTERN_C const char *_gl_directory_name (int fd);
-
# else
# if address@hidden@
_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
diff --git a/modules/dup2 b/modules/dup2
index 17cafd1..52189f9 100644
--- a/modules/dup2
+++ b/modules/dup2
@@ -8,6 +8,7 @@ m4/dup2.m4
Depends-on:
unistd
dup2-obsolete
+fd-hook
configure.ac:
gl_FUNC_DUP2
diff --git a/modules/dup3 b/modules/dup3
index 4454a3a..06c1d1d 100644
--- a/modules/dup3
+++ b/modules/dup3
@@ -8,6 +8,7 @@ m4/dup3.m4
Depends-on:
unistd
fcntl
+fd-hook
binary-io
getdtablesize
extensions
diff --git a/modules/fchdir b/modules/fchdir
index 0a3ab99..f232deb 100644
--- a/modules/fchdir
+++ b/modules/fchdir
@@ -9,19 +9,11 @@ Depends-on:
close
dirent
dirfd
-dosname
dup2
-fcntl
fcntl-h
-filenamecat-lgpl
-getcwd-lgpl
include_next
-malloc-posix
open
-realloc-posix
stat
-stdbool
-strdup-posix
sys_stat
unistd
diff --git a/modules/fcntl b/modules/fcntl
index 67630f9..4e40d8e 100644
--- a/modules/fcntl
+++ b/modules/fcntl
@@ -8,6 +8,7 @@ lib/fcntl.c
Depends-on:
dup2
fcntl-h
+fd-hook
getdtablesize
extensions
diff --git a/modules/fd-hook b/modules/fd-hook
index 7127083..0eef7b7 100644
--- a/modules/fd-hook
+++ b/modules/fd-hook
@@ -6,6 +6,14 @@ lib/fd-hook.h
lib/fd-hook.c
Depends-on:
+dosname
+dup2
+filenamecat-lgpl
+getcwd-lgpl
+malloc-posix
+realloc-posix
+stdbool
+strdup-posix
unistd
configure.ac:
diff --git a/modules/open b/modules/open
index 2982908..d02d88e 100644
--- a/modules/open
+++ b/modules/open
@@ -8,6 +8,7 @@ m4/mode_t.m4
Depends-on:
fcntl-h
+fd-hook
stat
configure.ac:
--
1.7.4.4
- [RFC PATCH] fchdir: move fd shadowing into fd-hook,
Eric Blake <=