From 926dfe5925883cc5ac5198dae700d727d8f8714e Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 27 May 2020 18:53:32 +0100 Subject: [PATCH] gstdio: Handle EINTR in g_fsync() Signed-off-by: Philip Withnall --- glib/gstdio.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/glib/gstdio.c b/glib/gstdio.c index 4e235e0ad..f14ea172b 100644 --- a/glib/gstdio.c +++ b/glib/gstdio.c @@ -1660,10 +1660,13 @@ g_freopen (const gchar *filename, * g_fsync: * @fd: a file descriptor * - * A wrapper for the POSIX fsync() function (_commit() on Windows). - * The fsync() function is used to synchronize a file's in-core + * A wrapper for the POSIX `fsync()` function. On Windows, `_commit()` will be + * used. + * The `fsync()` function is used to synchronize a file's in-core * state with that of the disk. * + * This wrapper will handle retrying on `EINTR`. + * * See the C library manual for more details about fsync(). * * Returns: 0 on success, or -1 if an error occurred. @@ -1676,8 +1679,14 @@ g_fsync (gint fd) { #ifdef G_OS_WIN32 return _commit (fd); +#elif defined(HAVE_FSYNC) + int retval; + do + retval = fsync (fd); + while (G_UNLIKELY (retval < 0 && errno == EINTR)); + return retval; #else - return fsync (fd); + return 0; #endif }