Use SOCK_CLOEXEC if available

Ray pointed out that we can avoid the race here.
This commit is contained in:
Matthias Clasen 2016-07-25 09:45:37 -04:00
parent a5f209bc65
commit a2d5d1f119

View File

@ -132,7 +132,6 @@
# include <windows.h> # include <windows.h>
#endif #endif
/** /**
* SECTION:messages * SECTION:messages
* @title: Message Logging * @title: Message Logging
@ -1621,17 +1620,25 @@ g_log_writer_supports_color (gint output_fd)
static int journal_fd = -1; static int journal_fd = -1;
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#else
#define HAVE_SOCK_CLOEXEC 1
#endif
static void static void
open_journal (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; return;
#ifndef HAVE_SOCK_CLOEXEC
if (fcntl (journal_fd, F_SETFD, FD_CLOEXEC) < 0) if (fcntl (journal_fd, F_SETFD, FD_CLOEXEC) < 0)
{ {
close (journal_fd); close (journal_fd);
journal_fd = -1; journal_fd = -1;
} }
#endif
} }
/** /**