summaryrefslogtreecommitdiffstats
path: root/lib/socket_wrapper
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-10-02 07:18:48 +0200
committerAndreas Schneider <asn@cryptomilk.org>2014-10-02 09:35:10 +0200
commit9731516e7f87cc16412eb830840d0393e8a4f823 (patch)
treee5e64b126f2b2629ac55ce9f2bcd0028968fe167 /lib/socket_wrapper
parentf8584abfef0974a19547927258369b04e03d6336 (diff)
downloadsamba-9731516e7f87cc16412eb830840d0393e8a4f823.tar.gz
samba-9731516e7f87cc16412eb830840d0393e8a4f823.tar.xz
samba-9731516e7f87cc16412eb830840d0393e8a4f823.zip
swrap: Wrap fopen to detect stale file descriptors.
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib/socket_wrapper')
-rw-r--r--lib/socket_wrapper/socket_wrapper.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index 96490041c7..574f5ba71a 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/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
***************************************************************************/