]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Add the slack fd code, and the reordering of log/socket opening.
authordgaudet <dgaudet@unknown>
Fri, 27 Jun 1997 01:47:47 +0000 (01:47 +0000)
committerdgaudet <dgaudet@unknown>
Fri, 27 Jun 1997 01:47:47 +0000 (01:47 +0000)
Reviewed by:
Submitted by:
Obtained from:

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3@78374 13f79535-47bb-0310-9956-ffa450edef68

APACHE_1_2_X/src/CHANGES
APACHE_1_2_X/src/PORTING
APACHE_1_2_X/src/include/ap_config.h
APACHE_1_2_X/src/include/conf.h
APACHE_1_2_X/src/include/http_config.h
APACHE_1_2_X/src/include/httpd.h
APACHE_1_2_X/src/main/alloc.c
APACHE_1_2_X/src/main/http_config.c
APACHE_1_2_X/src/main/http_main.c
APACHE_1_2_X/src/main/util.c

index 196941227d45f50a12e32f6f98d3a0d8f105c155..ea91e82b4e11c9f4fe33e3993290c4074b225f46 100644 (file)
@@ -1,5 +1,22 @@
 Changes with Apache 1.2.1
-  
+
+  *) Attempt to work around problems with third party libraries that do not
+     handle high numbered descriptors (examples include bind, and
+     solaris libc).  On all systems apache attempts to keep all permanent
+     descriptors above 15 (called the low slack line).  Solaris users
+     can also benefit from adding -DHIGH_SLACK_LINE=256 to EXTRA_CFLAGS
+     which keeps all non-FILE * descriptors above 255.  On all systems
+     this should make supporting large numbers of vhosts with many open
+     log files more feasible.  If this causes trouble please report it,
+     you can disable this workaround by adding -DNO_SLACK to EXTRA_CFLAGS.
+     [Dean Gaudet] various PRs
+
+  *) Related to the last entry, network sockets are now opened before
+     log files are opened.  The only known case where this can cause
+     problems is under Solaris with many virtualhosts and many Listen
+     directives.  But using -DHIGH_SLACK_LINE=256 described above will
+     work around this problem.  [Dean Gaudet]
+
   *) pregsub had an off-by-1 in its error checking code. [Alexei Kosut]
 
 Changes with Apache 1.2
index 97fccdb8521df4d9f4f60032b7574c6ff7fe47fa..7509f681ffd05dbc07df436c0bf2a5b59e4c485d 100644 (file)
@@ -227,6 +227,9 @@ build for your OS.
       NO_LINGCLOSE:
        Do not use Apache's soft, "lingering" close feature to
        terminate connections.
+      NO_SLACK:
+       Do not use the "slack" fd feature which requires a working fcntl
+       F_DUPFD.
 --
 
   MISC #DEFINES:
index fd7869c069c0a4f59e3c943c693190b4a081c603..923cd7d4fba6c691547b7088f9b58cab2da5a69d 100644 (file)
@@ -73,6 +73,7 @@
 extern void GETPRIVMODE();
 extern void GETUSERMODE();
 extern char *inet_ntoa();
+#define NO_SLACK
 
 #elif defined(SUNOS4)
 #define HAVE_GMTOFF
index fd7869c069c0a4f59e3c943c693190b4a081c603..923cd7d4fba6c691547b7088f9b58cab2da5a69d 100644 (file)
@@ -73,6 +73,7 @@
 extern void GETPRIVMODE();
 extern void GETUSERMODE();
 extern char *inet_ntoa();
+#define NO_SLACK
 
 #elif defined(SUNOS4)
 #define HAVE_GMTOFF
index 148ab6958f77269e497c937a8d9b42df07fc8df8..8c2635b90dd1c47b894292739a0ccd061cdb6581 100644 (file)
@@ -261,6 +261,7 @@ module *find_linked_module (const char *name);
 /* For http_main.c... */
 
 server_rec *read_config (pool *conf_pool, pool *temp_pool, char *config_name);
+void init_modules(pool *p, server_rec *s);
 void setup_prelinked_modules();
 void show_directives();
 void show_modules();
index 3f15afdb350924cd8884874d958434dd216c4ba3..00e7347f2a4ca84da3e09adf28704261dc861ce3 100644 (file)
 #define DECLINED -1            /* Module declines to handle */
 #define OK 0                   /* Module has handled this stage. */
 
+
 /* ----------------------- HTTP Status Codes  ------------------------- */
 
 #define RESPONSE_CODES 38
@@ -711,3 +712,31 @@ char *get_local_host(pool *);
 unsigned long get_virthost_addr (const char *hostname, unsigned short *port);
 
 extern time_t restart_time;
+
+/*
+ * Apache tries to keep all of its long term filehandles (such as log files,
+ * and sockets) above this number.  This is to workaround problems in many
+ * third party libraries that are compiled with a small FD_SETSIZE.  There
+ * should be no reason to lower this, because it's only advisory.  If a file
+ * can't be allocated above this number then it will remain in the "slack"
+ * area.
+ *
+ * Only the low slack line is used by default.  If HIGH_SLACK_LINE is defined
+ * then an attempt is also made to keep all non-FILE * files above the high
+ * slack line.  This is to work around a Solaris C library limitation, where it
+ * uses an unsigned char to store the file descriptor.
+ */
+#ifndef LOW_SLACK_LINE
+#define LOW_SLACK_LINE 15
+#endif
+/* #define HIGH_SLACK_LINE     255 */
+
+/*
+ * The ap_slack() function takes a fd, and tries to move it above the indicated
+ * line.  It returns an fd which may or may not have moved above the line, and
+ * never fails.  If the high line was requested and it fails it will also try
+ * the low line.
+ */
+int ap_slack (int fd, int line);
+#define AP_SLACK_LOW   1
+#define AP_SLACK_HIGH  2
index 2557c079caf5d87ef228547480e9fa1765b2b754..d81b14ac01cd669e4b3179daedd1df129f851f3e 100644 (file)
@@ -58,8 +58,7 @@
  * rst --- 4/95 --- 6/95
  */
 
-#include "conf.h"
-#include "alloc.h"
+#include "httpd.h"
 
 #include <stdarg.h>
 
@@ -801,7 +800,10 @@ int popenf(pool *a, const char *name, int flg, int mode)
   block_alarms();
   fd = open(name, flg, mode);
   save_errno = errno;
-  if (fd >= 0) note_cleanups_for_fd (a, fd);
+  if (fd >= 0) {
+    fd = ap_slack (fd, AP_SLACK_HIGH);
+    note_cleanups_for_fd (a, fd);
+  }
   unblock_alarms();
   errno = save_errno;
   return fd;
@@ -846,6 +848,7 @@ FILE *pfopen(pool *a, const char *name, const char *mode)
     desc = open(name, baseFlag | O_APPEND | O_CREAT,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
     if (desc >= 0) {
+      desc = ap_slack(desc, AP_SLACK_LOW);
       fd = fdopen(desc, mode);
     }
   } else {
index 51c0ec6580bf89e3ef238724718c2650895271f9..9b37b2bdb869c73e99b1dc08eb63e35101a00fa6 100644 (file)
@@ -1077,7 +1077,6 @@ server_rec *init_server_config(pool *p)
 server_rec *read_config(pool *p, pool *ptemp, char *confname)
 {
     server_rec *s = init_server_config(p);
-    module *m;
     
     init_config_globals(p);
     
@@ -1089,13 +1088,20 @@ server_rec *read_config(pool *p, pool *ptemp, char *confname)
     
     fixup_virtual_hosts (p, s);
     
+    return s;
+}
+    
+
+void init_modules(pool *p, server_rec *s)
+{
+    module *m;
+
     for (m = top_module; m; m = m->next)
         if (m->init)
            (*m->init) (s, p);
-    
-    return s;
 }
 
+
 /********************************************************************
  * Configuration directives are restricted in terms of where they may
  * appear in the main configuration files and/or .htaccess files according
index 20ef2bba263e9a759b9f41b79f3006de8eb9f96a..348ca039c3b858bc96c40318d8356dcba66e4ba5 100644 (file)
@@ -1981,6 +1981,8 @@ static int make_sock(pool *pconf, const struct sockaddr_in *server)
         exit(1);
     }
 
+    s = ap_slack(s, AP_SLACK_HIGH);
+
     note_cleanups_for_fd(pconf, s); /* arrange to close on exec or restart */
     
 #ifndef MPE
@@ -2135,20 +2137,6 @@ void standalone_main(int argc, char **argv)
        ptrans = make_sub_pool (pconf);
 
        server_conf = read_config (pconf, ptrans, server_confname); 
-       open_logs (server_conf, pconf);
-       set_group_privs ();
-       accept_mutex_init (pconf);
-       if (!is_graceful) {
-           reinit_scoreboard(pconf);
-       }
-#ifdef SCOREBOARD_FILE
-       else {
-           scoreboard_fname = server_root_relative (pconf, scoreboard_fname);
-           note_cleanups_for_fd (pconf, scoreboard_fd);
-       }
-#endif
-
-       default_server_hostnames (server_conf);
 
        if (listeners == NULL) {
            if (!is_graceful) {
@@ -2183,6 +2171,22 @@ void standalone_main(int argc, char **argv)
            sd = -1;
        }
 
+       init_modules (pconf, server_conf);
+       open_logs (server_conf, pconf);
+       set_group_privs ();
+       accept_mutex_init (pconf);
+       if (!is_graceful) {
+           reinit_scoreboard(pconf);
+       }
+#ifdef SCOREBOARD_FILE
+       else {
+           scoreboard_fname = server_root_relative (pconf, scoreboard_fname);
+           note_cleanups_for_fd (pconf, scoreboard_fd);
+       }
+#endif
+
+       default_server_hostnames (server_conf);
+
        set_signals ();
        log_pid (pconf, pid_fname);
 
@@ -2391,6 +2395,7 @@ main(int argc, char *argv[])
 
     suexec_enabled = init_suexec();
     server_conf = read_config (pconf, ptrans, server_confname);
+    init_modules (pconf, server_conf);
     
     if(standalone) {
         clear_pool (pconf);    /* standalone_main rereads... */
index e21adca0d7278925ca8b6d144aed646df534bd38..36d7ad165c42e0c691261fd40bf51e7bcb87c28c 100644 (file)
@@ -1326,3 +1326,30 @@ strerror (int err) {
     return (p);
 }
 #endif
+
+
+int ap_slack (int fd, int line)
+{
+#if !defined(F_DUPFD) || defined(NO_SLACK)
+    return fd;
+#else
+    int new_fd;
+
+#ifdef HIGH_SLACK_LINE
+    if (line == AP_SLACK_HIGH) {
+       new_fd = fcntl (fd, F_DUPFD, HIGH_SLACK_LINE);
+       if (new_fd != -1) {
+           close (fd);
+           return new_fd;
+       }
+    }
+#endif
+    /* otherwise just assume line == AP_SLACK_LOW */
+    new_fd = fcntl (fd, F_DUPFD, LOW_SLACK_LINE);
+    if (new_fd == -1) {
+      return fd;
+    }
+    close (fd);
+    return new_fd;
+#endif
+}