httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject Re: HUPs under Solaris
Date Mon, 07 Jul 1997 09:21:37 GMT
> > On Sun, 6 Jul 1997, Marc Slemko wrote:
> > 
> > > Running a test server, port 6666, as me, Solaris 2.5.1.
> > > 
> > > A HUP always gives:
> > > 
> > > bind: Invalid argument
> > > httpd: could not bind to port 6666
> > > 
> > > and it dies.  Should this work, or am I crazy? 
> > > 
> > > Haven't had a chance to look at it yet...

Grr.  You can do "socket, dup, bind" once, but not twice (yep everything
is closed in between).  Nothing else seems to have this problem.  I tested
this with a tiny test program. 

If I move the bind() before the ap_slack() it works OK.  But if I pummel
it with SIGHUPs it still barfs.  But that's not new to 1.2.1, at least it
isn't for me.  I get bind errors under 1.2.0 as well, when pummeling it
with SIGHUPs that is. 

I can't reproduce this last behaviour easily in a small test program, so I
suspect it's related to children not exiting fast enough for Solaris'
tastes.  It's probably fixed in 2.6 when sockets move back out of userland
into the kernel.  I'll see if I can't talk to someone at sun about this. 

At any rate, there are two workarounds: NO_SLACK, or using SIGUSR1 instead
of SIGHUP.  And there's the patch below that at least makes it as lame as
1.2.0 w.r.t. sighup pummeling.

Dean

--- apache_1.2.1-dist/src/http_main.c	Sun Jun 29 11:08:37 1997
+++ apache_1.2.1/src/http_main.c	Mon Jul  7 02:09:33 1997
@@ -1971,6 +1971,32 @@
     return 0;
 }
 
+
+static void sock_bind (int s, const struct sockaddr_in *server)
+{
+#ifdef MPE
+/* MPE requires CAP=PM and GETPRIVMODE to bind to ports less than 1024 */
+    if (ntohs(server->sin_port) < 1024) GETPRIVMODE();
+#endif
+    if(bind(s, (struct sockaddr *)server,sizeof(struct sockaddr_in)) == -1)
+    {
+        perror("bind");
+#ifdef MPE
+        if (ntohs(server->sin_port) < 1024) GETUSERMODE();
+#endif
+	if (server->sin_addr.s_addr != htonl(INADDR_ANY))
+	    fprintf(stderr,"httpd: could not bind to address %s port %d\n",
+		    inet_ntoa(server->sin_addr), ntohs(server->sin_port));
+	else
+	    fprintf(stderr,"httpd: could not bind to port %d\n",
+		    ntohs(server->sin_port));
+        exit(1);
+    }
+#ifdef MPE
+    if (ntohs(server->sin_port) < 1024) GETUSERMODE();
+#endif
+}
+
 static int make_sock(pool *pconf, const struct sockaddr_in *server)
 {
     int s;
@@ -1982,6 +2008,10 @@
         exit(1);
     }
 
+#ifdef SOLARIS2
+    sock_bind (s, server);
+#endif
+	
     s = ap_slack(s, AP_SLACK_HIGH);
 
     note_cleanups_for_fd(pconf, s); /* arrange to close on exec or restart */
@@ -2031,27 +2061,10 @@
 	}
     }
 
-#ifdef MPE
-/* MPE requires CAP=PM and GETPRIVMODE to bind to ports less than 1024 */
-    if (ntohs(server->sin_port) < 1024) GETPRIVMODE();
-#endif
-    if(bind(s, (struct sockaddr *)server,sizeof(struct sockaddr_in)) == -1)
-    {
-        perror("bind");
-#ifdef MPE
-        if (ntohs(server->sin_port) < 1024) GETUSERMODE();
-#endif
-	if (server->sin_addr.s_addr != htonl(INADDR_ANY))
-	    fprintf(stderr,"httpd: could not bind to address %s port %d\n",
-		    inet_ntoa(server->sin_addr), ntohs(server->sin_port));
-	else
-	    fprintf(stderr,"httpd: could not bind to port %d\n",
-		    ntohs(server->sin_port));
-        exit(1);
-    }
-#ifdef MPE
-    if (ntohs(server->sin_port) < 1024) GETUSERMODE();
+#ifndef SOLARIS2
+    sock_bind (s, server);
 #endif
+
     listen(s, 512);
     return s;
 }


Mime
View raw message