aboutsummaryrefslogtreecommitdiff
path: root/misc/syslog.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-07-26 22:55:08 +0000
committerUlrich Drepper <drepper@redhat.com>2008-07-26 22:55:08 +0000
commitc0216dfc6262a4f1379b990e4076127f1f47c6d1 (patch)
tree5130e982462a0c1ea5113c08b9468183895f8891 /misc/syslog.c
parent72112b0cb4b10d27e7729d12bb9f937e13975379 (diff)
downloadglibc-c0216dfc6262a4f1379b990e4076127f1f47c6d1.zip
glibc-c0216dfc6262a4f1379b990e4076127f1f47c6d1.tar.gz
glibc-c0216dfc6262a4f1379b990e4076127f1f47c6d1.tar.bz2
* misc/syslog.c (openlog_internal): Use SOCK_CLOEXEC if possible.
Diffstat (limited to 'misc/syslog.c')
-rw-r--r--misc/syslog.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/misc/syslog.c b/misc/syslog.c
index 5781b4a..baa180b 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -348,10 +348,35 @@ openlog_internal(const char *ident, int logstat, int logfac)
(void)strncpy(SyslogAddr.sun_path, _PATH_LOG,
sizeof(SyslogAddr.sun_path));
if (LogStat & LOG_NDELAY) {
- if ((LogFile = __socket(AF_UNIX, LogType, 0))
- == -1)
+#ifdef SOCK_CLOEXEC
+# ifndef __ASSUME_SOCK_CLOEXEC
+ if (__have_sock_cloexec >= 0) {
+# endif
+ LogFile = __socket(AF_UNIX,
+ LogType
+ | SOCK_CLOEXEC, 0);
+# ifndef __ASSUME_SOCK_CLOEXEC
+ if (__have_sock_cloexec == 0)
+ __have_sock_cloexec
+ = (LogFile != -1
+ || errno != EINVAL);
+#endif
+ }
+#endif
+#ifndef __ASSUME_SOCK_CLOEXEC
+# ifdef SOCK_CLOEXEC
+ if (__have_sock_cloexec < 0)
+# endif
+ LogFile = __socket(AF_UNIX, LogType, 0);
+#endif
+ if (LogFile == -1)
return;
- (void)__fcntl(LogFile, F_SETFD, 1);
+#ifndef __ASSUME_SOCK_CLOEXEC
+# ifdef SOCK_CLOEXEC
+ if (__have_sock_cloexec < 0)
+# endif
+ __fcntl(LogFile, F_SETFD, FD_CLOEXEC);
+#endif
}
}
if (LogFile != -1 && !connected)