]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 706] Only 1 instance of ntpd should be running
authorHarlan Stenn <stenn@ntp.org>
Wed, 13 Sep 2006 01:35:52 +0000 (21:35 -0400)
committerHarlan Stenn <stenn@ntp.org>
Wed, 13 Sep 2006 01:35:52 +0000 (21:35 -0400)
bk: 450760788yHntQYDXL-RBe4VoTqkbA

ntpd/ntp_io.c

index b6018f6b49b0e5d64e82a06f6fa2f039f9b51d52..55b7bf534876da746cfdd95bbd9287b45502f696 100644 (file)
@@ -845,13 +845,17 @@ create_wildcards(u_short port) {
                ((struct sockaddr_in*)&interface->bcast)->sin_addr.s_addr = htonl(INADDR_ANY);
 #endif /* MCAST */
                interface->fd = open_socket(&interface->sin,
-                                interface->flags, 0, interface);
+                                interface->flags, 1, interface);
 
                if (interface->fd != INVALID_SOCKET) {
                        wildipv4 = interface;
                        any_interface = interface;
                        add_interface(interface);
                        list_if_listening(interface, port);
+               } else {
+                       msyslog(LOG_ERR, "unable to bind to wildcard socket address %s - another process may be running - EXITING",
+                               stoa((&interface->sin)));
+                       exit(1);
                }
        }
 
@@ -876,13 +880,17 @@ create_wildcards(u_short port) {
                interface->ignore_packets = ISC_TRUE;
 
                interface->fd = open_socket(&interface->sin,
-                                interface->flags, 0, interface);
+                                interface->flags, 1, interface);
 
                if (interface->fd != INVALID_SOCKET) {
                        wildipv6 = interface;
                        any6_interface = interface;
                        add_interface(interface);
                        list_if_listening(interface, port);
+               } else {
+                       msyslog(LOG_ERR, "unable to bind to wildcard socket address %s - another process may be running - EXITING",
+                               stoa((&interface->sin)));
+                       exit(1);
                }
        }
 #endif
@@ -2206,10 +2214,14 @@ open_socket(
         * number on each interface
         */
        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
-                      (char *)&on, sizeof(on)))
+                      turn_off_reuse ? (char *)&off : (char *)&on, sizeof(on)))
        {
-               netsyslog(LOG_ERR, "setsockopt SO_REUSEADDR on fails on address %s: %m",
-                       stoa(addr));
+               netsyslog(LOG_ERR, "setsockopt SO_REUSEADDR %s on fails on address %s: %m",
+                       turn_off_reuse ? "off" : "on", stoa(addr));
+
+               closesocket(fd);
+
+               return INVALID_SOCKET;
        }
 
        /*