[glib/th/gspawn-no-safe-close: 3/4] gstdio: use safe_close_with_error() from g_close()
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/th/gspawn-no-safe-close: 3/4] gstdio: use safe_close_with_error() from g_close()
- Date: Tue, 18 Oct 2022 07:01:06 +0000 (UTC)
commit 2b1b421816a031c6d30f32a268502df34109b9db
Author: Thomas Haller <thaller redhat com>
Date: Tue Oct 18 08:52:21 2022 +0200
gstdio: use safe_close_with_error() from g_close()
glib/gstdio.c | 47 +++++++----------------------------------------
1 file changed, 7 insertions(+), 40 deletions(-)
---
diff --git a/glib/gstdio.c b/glib/gstdio.c
index 15a1105ec9..f4b83180d3 100644
--- a/glib/gstdio.c
+++ b/glib/gstdio.c
@@ -48,6 +48,7 @@
#include "gstdio.h"
#include "gstdioprivate.h"
+#include "gutilsprivate.h"
#if !defined (G_OS_UNIX) && !defined (G_OS_WIN32)
#error Please port this to your operating system
@@ -1767,51 +1768,17 @@ g_close (gint fd,
{
int res;
- res = close (fd);
+ res = _g_safe_close_with_error (fd);
- if (res == -1)
+ if (res < 0)
{
- int errsv = errno;
-
- if (errsv == EINTR)
- {
- /* Just ignore EINTR for now; a retry loop is the wrong thing to do
- * on Linux at least. Anyone who wants to add a conditional check
- * for e.g. HP-UX is welcome to do so later...
- *
- * https://lwn.net/Articles/576478/
- * http://lkml.indiana.edu/hypermail/linux/kernel/0509.1/0877.html
- * https://bugzilla.gnome.org/show_bug.cgi?id=682819
- * http://utcc.utoronto.ca/~cks/space/blog/unix/CloseEINTR
- *
https://sites.google.com/site/michaelsafyan/software-engineering/checkforeintrwheninvokingclosethinkagain
- */
- return TRUE;
- }
-
g_set_error_literal (error, G_FILE_ERROR,
- g_file_error_from_errno (errsv),
- g_strerror (errsv));
-
- if (errsv == EBADF)
- {
- if (fd >= 0)
- {
- /* Closing an non-negative, invalid file descriptor is a bug. The bug is
- * not necessarily in the caller of g_close(), but somebody else
- * might have wrongly closed fd. In any case, there is a serious bug
- * somewhere. */
- g_critical ("g_close(fd:%d) failed with EBADF. The tracking of file descriptors got messed
up", fd);
- }
- else
- {
- g_critical ("g_close(fd:%d) failed with EBADF. This is not a valid file descriptor", fd);
- }
- }
-
- errno = errsv;
-
+ g_file_error_from_errno (-res),
+ g_strerror (-res));
+ errno = -res;
return FALSE;
}
+ /* errno is undefined. */
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]