Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/inetd If we can't set FD_CLOEXEC on a listening soc...



details:   https://anonhg.NetBSD.org/src/rev/02f392bbfcda
branches:  trunk
changeset: 536651:02f392bbfcda
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Thu Sep 19 21:59:03 2002 +0000

description:
If we can't set FD_CLOEXEC on a listening socket, close it rather than allowing
it to be passed down to inetd's children.
Note: Setting FD_CLOEXEC can't actually fail, but we did check for the error
anyway...

diffstat:

 usr.sbin/inetd/inetd.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (33 lines):

diff -r d4e6b225abb6 -r 02f392bbfcda usr.sbin/inetd/inetd.c
--- a/usr.sbin/inetd/inetd.c    Thu Sep 19 21:52:29 2002 +0000
+++ b/usr.sbin/inetd/inetd.c    Thu Sep 19 21:59:03 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inetd.c,v 1.83 2002/07/04 12:35:19 itojun Exp $        */
+/*     $NetBSD: inetd.c,v 1.84 2002/09/19 21:59:03 mycroft Exp $       */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
 #if 0
 static char sccsid[] = "@(#)inetd.c    8.4 (Berkeley) 4/13/94";
 #else
-__RCSID("$NetBSD: inetd.c,v 1.83 2002/07/04 12:35:19 itojun Exp $");
+__RCSID("$NetBSD: inetd.c,v 1.84 2002/09/19 21:59:03 mycroft Exp $");
 #endif
 #endif /* not lint */
 
@@ -1053,8 +1053,12 @@
                return;
        }
        /* Set all listening sockets to close-on-exec. */
-       if (fcntl(sep->se_fd, F_SETFD, FD_CLOEXEC) < 0)
-               syslog(LOG_ERR, "fcntl (F_SETFD, FD_CLOEXEC): %m");
+       if (fcntl(sep->se_fd, F_SETFD, FD_CLOEXEC) < 0) {
+               syslog(LOG_ERR, "%s/%s: fcntl(F_SETFD, FD_CLOEXEC): %m",
+                   sep->se_service, sep->se_proto);
+               close(sep->se_fd);
+               return;
+       }
 
 #define        turnon(fd, opt) \
 setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))



Home | Main Index | Thread Index | Old Index