aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2009-03-20 20:33:14 +0000
committerDavid Shaw <[email protected]>2009-03-20 20:33:14 +0000
commitda66b1d69e793cb5bc714caedef60f8de8dbfd7c (patch)
tree221984ec785e5d09cc003f634e558238646ea8c1
parent* gpgv.c (strusage): Fix name of program in "Syntax" line. (diff)
downloadgnupg-da66b1d69e793cb5bc714caedef60f8de8dbfd7c.tar.gz
gnupg-da66b1d69e793cb5bc714caedef60f8de8dbfd7c.zip
* iobuf.c (fd_cache_synchronize): New. fsync() a file in cache.
(iobuf_ioctl): Called here, for ioctl 4. (fd_cache_invalidate): Pass return code from close() back to iobuf_ioctl().
-rw-r--r--util/ChangeLog7
-rw-r--r--util/iobuf.c61
2 files changed, 60 insertions, 8 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index 21132d24d..af9d30ccd 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-20 David Shaw <[email protected]>
+
+ * iobuf.c (fd_cache_synchronize): New. fsync() a file in cache.
+ (iobuf_ioctl): Called here, for ioctl 4.
+ (fd_cache_invalidate): Pass return code from close() back to
+ iobuf_ioctl().
+
2009-03-13 David Shaw <[email protected]>
* http.c (do_parse_uri): Properly handle IPv6 literal addresses as
diff --git a/util/iobuf.c b/util/iobuf.c
index d2565baed..e14a7cce0 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -1,6 +1,6 @@
/* iobuf.c - file handling
- * Copyright (C) 1998, 1999, 2000, 2001, 2003,
- * 2004, 2008 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2008,
+ * 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -162,10 +162,11 @@ fd_cache_strcmp (const char *a, const char *b)
* Invalidate (i.e. close) a cached iobuf or all iobufs if NULL is
* used for FNAME.
*/
-static void
+static int
fd_cache_invalidate (const char *fname)
{
CLOSE_CACHE cc;
+ int err=0;
if (!fname) {
if( DBG_IOBUF )
@@ -181,7 +182,7 @@ fd_cache_invalidate (const char *fname)
cc->fp = INVALID_FP;
}
}
- return;
+ return err;
}
if( DBG_IOBUF )
@@ -192,16 +193,43 @@ fd_cache_invalidate (const char *fname)
if( DBG_IOBUF )
log_debug (" did (%s)\n", cc->fname);
#ifdef HAVE_DOSISH_SYSTEM
- CloseHandle (cc->fp);
+ if(CloseHandle (cc->fp)==0)
+ err=-1;
#else
- close(cc->fp);
+ err=close(cc->fp);
#endif
cc->fp = INVALID_FP;
}
}
+
+ return err;
}
+static int
+fd_cache_synchronize(const char *fname)
+{
+ int err=0;
+
+#ifndef HAVE_DOSISH_SYSTEM
+ CLOSE_CACHE cc;
+
+ if( DBG_IOBUF )
+ log_debug ("fd_cache_synchronize (%s)\n", fname);
+ for (cc=close_cache; cc; cc = cc->next )
+ {
+ if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) )
+ {
+ if( DBG_IOBUF )
+ log_debug (" did (%s)\n", cc->fname);
+
+ err=fsync(cc->fp);
+ }
+ }
+#endif
+
+ return err;
+}
static FILEP_OR_FD
direct_open (const char *fname, const char *mode)
@@ -1298,10 +1326,10 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
ptrval? (char*)ptrval:"[all]");
if ( !a && !intval ) {
#ifndef FILE_FILTER_USES_STDIO
- fd_cache_invalidate (ptrval);
+ return fd_cache_invalidate (ptrval);
#endif
return 0;
- }
+ }
}
else if ( cmd == 3 ) { /* disallow/allow caching */
if( DBG_IOBUF )
@@ -1322,6 +1350,23 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
}
#endif
}
+ else if(cmd==4)
+ {
+ /* Do a fsync on the open fd and return any errors to the
+ caller of iobuf_ioctl */
+ if( DBG_IOBUF )
+ log_debug("iobuf-*.*: ioctl `%s' fsync\n",
+ ptrval? (char*)ptrval:"<null>");
+
+ if(!a && !intval && ptrval)
+ {
+#ifndef FILE_FILTER_USES_STDIO
+ return fd_cache_synchronize (ptrval);
+#else
+ return 0;
+#endif
+ }
+ }
return -1;
}