[glib] Use SOCK_CLOEXEC if available
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Use SOCK_CLOEXEC if available
- Date: Mon, 25 Jul 2016 13:47:40 +0000 (UTC)
commit a2d5d1f119ade1cba22c3c3802baa9afb3cb0ec0
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jul 25 09:45:37 2016 -0400
Use SOCK_CLOEXEC if available
Ray pointed out that we can avoid the race here.
glib/gmessages.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/glib/gmessages.c b/glib/gmessages.c
index a16db58..70b93a2 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -132,7 +132,6 @@
# include <windows.h>
#endif
-
/**
* SECTION:messages
* @title: Message Logging
@@ -1621,17 +1620,25 @@ g_log_writer_supports_color (gint output_fd)
static int journal_fd = -1;
+#ifndef SOCK_CLOEXEC
+#define SOCK_CLOEXEC 0
+#else
+#define HAVE_SOCK_CLOEXEC 1
+#endif
+
static void
open_journal (void)
{
- if ((journal_fd = socket (AF_UNIX, SOCK_DGRAM, 0)) < 0)
+ if ((journal_fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0)
return;
+#ifndef HAVE_SOCK_CLOEXEC
if (fcntl (journal_fd, F_SETFD, FD_CLOEXEC) < 0)
{
close (journal_fd);
journal_fd = -1;
}
+#endif
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]