(openlog_internal): Use SOCK_CLOEXEC if possible.
authordrepper <drepper>
Sat, 26 Jul 2008 22:55:01 +0000 (22:55 +0000)
committerdrepper <drepper>
Sat, 26 Jul 2008 22:55:01 +0000 (22:55 +0000)
misc/syslog.c

index 5781b4a..baa180b 100644 (file)
@@ -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)