diff options
author | Andreas Schneider <asn@samba.org> | 2014-08-27 16:00:43 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2014-09-01 10:23:48 +0200 |
commit | e3f7e8ce9158420379fbba3164c05bd845708c60 (patch) | |
tree | 48fd86a61c14eda21f3385b99d222fd42766a7b0 | |
parent | 9694d9924f3f7e88852936a8a27101986bb47223 (diff) | |
download | socket_wrapper-e3f7e8ce9158420379fbba3164c05bd845708c60.tar.gz socket_wrapper-e3f7e8ce9158420379fbba3164c05bd845708c60.tar.xz socket_wrapper-e3f7e8ce9158420379fbba3164c05bd845708c60.zip |
swrap: Wrap fopen to detect stale file descriptors.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r-- | src/socket_wrapper.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 9649004..574f5ba 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -337,6 +337,7 @@ struct swrap_libc_fns { socklen_t addrlen); int (*libc_dup)(int fd); int (*libc_dup2)(int oldfd, int newfd); + FILE *(*libc_fopen)(const char *name, const char *mode); #ifdef HAVE_EVENTFD int (*libc_eventfd)(int count, int flags); #endif @@ -645,6 +646,13 @@ static int libc_listen(int sockfd, int backlog) return swrap.fns.libc_listen(sockfd, backlog); } +static FILE *libc_fopen(const char *name, const char *mode) +{ + swrap_load_lib_function(SWRAP_LIBC, fopen); + + return swrap.fns.libc_fopen(name, mode); +} + static int libc_vopen(const char *pathname, int flags, va_list ap) { long int mode = 0; @@ -3066,6 +3074,29 @@ int listen(int s, int backlog) } /**************************************************************************** + * FOPEN + ***************************************************************************/ + +static FILE *swrap_fopen(const char *name, const char *mode) +{ + FILE *fp; + + fp = libc_fopen(name, mode); + if (fp != NULL) { + int fd = fileno(fp); + + swrap_remove_stale(fd); + } + + return fp; +} + +FILE *fopen(const char *name, const char *mode) +{ + return swrap_fopen(name, mode); +} + +/**************************************************************************** * OPEN ***************************************************************************/ |