[libvirt] [PATCH 07/23] util: add compat wrapper for g_fsync

Daniel P. Berrangé berrange at redhat.com
Thu Jan 2 14:53:41 UTC 2020


g_fsync isn't available until 2.63 so we need a compat
wrapper temporarily.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/glibcompat.c    | 13 +++++++++++++
 src/util/glibcompat.h    |  5 +++++
 3 files changed, 19 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a7b1ef23bc..d3184dbf5c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1504,6 +1504,7 @@ virSecurityManagerVerify;
 
 
 # util/glibcompat.h
+vir_g_fsync;
 vir_g_strdup_printf;
 vir_g_strdup_vprintf;
 
diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c
index 3f830840cf..4ebefb4478 100644
--- a/src/util/glibcompat.c
+++ b/src/util/glibcompat.c
@@ -19,11 +19,13 @@
 #include <config.h>
 
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "glibcompat.h"
 
 #undef g_strdup_printf
 #undef g_strdup_vprintf
+#undef g_fsync
 
 /* Due to a bug in glib, g_strdup_printf() nor g_strdup_vprintf()
  * abort on OOM.  It's fixed in glib's upstream. Provide our own
@@ -51,3 +53,14 @@ vir_g_strdup_vprintf(const char *msg, va_list args)
     abort();
   return ret;
 }
+
+
+gint
+vir_g_fsync(gint fd)
+{
+#ifdef G_OS_WIN32
+  return _commit(fd);
+#else
+  return fsync(fd);
+#endif
+}
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h
index 2bbbe57612..d6b83f4b93 100644
--- a/src/util/glibcompat.h
+++ b/src/util/glibcompat.h
@@ -25,8 +25,13 @@ char *vir_g_strdup_printf(const char *msg, ...)
     G_GNUC_PRINTF(1, 2);
 char *vir_g_strdup_vprintf(const char *msg, va_list args)
     G_GNUC_PRINTF(1, 0);
+gint vir_g_fsync(gint fd);
 
 #if !GLIB_CHECK_VERSION(2, 64, 0)
 # define g_strdup_printf vir_g_strdup_printf
 # define g_strdup_vprintf vir_g_strdup_vprintf
 #endif
+
+#if !GLIB_CHECK_VERSION(2, 63, 0)
+# define g_fsync vir_g_fsync
+#endif
-- 
2.24.1




More information about the libvir-list mailing list