mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
Use SOCK_CLOEXEC if available
Ray pointed out that we can avoid the race here.
This commit is contained in:
parent
a5f209bc65
commit
a2d5d1f119
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user