]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Removed TPF-specific USE_TPF_SCOREBOARD in favor of shared memory.
authorDavid McCreedy <mccreedy@apache.org>
Tue, 17 Dec 2002 19:06:10 +0000 (19:06 +0000)
committerDavid McCreedy <mccreedy@apache.org>
Tue, 17 Dec 2002 19:06:10 +0000 (19:06 +0000)
Also improved shutdown/restart of the server on TPF.

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

src/include/ap_config.h
src/include/scoreboard.h
src/main/http_main.c
src/modules/standard/mod_status.c
src/os/tpf/os.c
src/os/tpf/os.h

index defa76c40a4e299c91d2eb4019626ae813a83864..8d8c9c5ccbda35c433bff0121aaebf87793b05c8 100644 (file)
@@ -968,10 +968,11 @@ typedef int rlim_t;
 #define NO_SETSID
 #define NO_SLACK
 #define NO_TIMES
+#ifndef TPF_HAVE_SIGACTION
 #define NO_USE_SIGACTION
+#endif
 #define USE_LONGJMP
 #define USE_SHMGET_SCOREBOARD
-/*#define USE_TPF_SCOREBOARD*/
 #define USE_TPF_ACCEPT
 #define HAVE_TPF_CORE_SERIALIZED_ACCEPT
 #define USE_TPF_SELECT
index 3aee0bf803aa8b8386cdd0678ca596604dc26a47..82719a9ff8122af4a015638e4c8033c9f5e211e8 100644 (file)
@@ -185,10 +185,6 @@ typedef struct {
 } scoreboard;
 
 #define SCOREBOARD_SIZE                sizeof(scoreboard)
-#ifdef TPF
-#define SCOREBOARD_NAME                "SCOREBRD"
-#define SCOREBOARD_FRAMES              SCOREBOARD_SIZE/4095 + 1
-#endif
 
 API_EXPORT(void) ap_sync_scoreboard_image(void);
 API_EXPORT(int) ap_exists_scoreboard_image(void);
index 50bad3cdcbb6bbec6ae32baa9003af5df006ecd8..0205aa0682ab99891fe33ddebc1923c56e3ec33e 100644 (file)
@@ -382,6 +382,7 @@ static int my_child_num;
 #endif
 
 #ifdef TPF
+pid_t tpf_parent_pid;
 int tpf_child = 0;
 char tpf_server_name[INETD_SERVNAME_LENGTH+1];
 char tpf_mutex_key[TPF_MUTEX_KEY_SIZE];
@@ -2375,37 +2376,6 @@ static void reopen_scoreboard(pool *p)
 {
 }
 
-#elif defined(USE_TPF_SCOREBOARD)
-
-static void cleanup_scoreboard_heap()
-{
-    int rv;
-    rv = rsysc(ap_scoreboard_image, SCOREBOARD_FRAMES, SCOREBOARD_NAME);
-    if(rv == RSYSC_ERROR) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, server_conf,
-            "rsysc() could not release scoreboard system heap");
-    }
-}
-
-static void setup_shared_mem(pool *p)
-{
-    cinfc(CINFC_WRITE, CINFC_CMMCTK2);
-    ap_scoreboard_image = (scoreboard *) gsysc(SCOREBOARD_FRAMES, SCOREBOARD_NAME);
-
-    if (!ap_scoreboard_image) {
-        fprintf(stderr, "httpd: Could not create scoreboard system heap storage.\n");
-        exit(APEXIT_INIT);
-    }
-
-    ap_register_cleanup(p, NULL, cleanup_scoreboard_heap, ap_null_cleanup);
-    ap_scoreboard_image->global.running_generation = 0;
-}
-
-static void reopen_scoreboard(pool *p)
-{
-    cinfc(CINFC_WRITE, CINFC_CMMCTK2);
-}
-
 #else
 #define SCOREBOARD_FILE
 static scoreboard _scoreboard_image;
@@ -3260,6 +3230,9 @@ static void sig_term(int sig)
 
 static void restart(int sig)
 {
+#ifdef TPF
+    signal(sig, restart);
+#endif
 #if !defined (WIN32) && !defined(NETWARE)
     ap_start_restart(sig == SIGUSR1);
 #else
@@ -4473,13 +4446,16 @@ static void child_main(int child_num_arg)
 
 #ifdef TPF
                case EINACT:
-                   ap_log_error(APLOG_MARK, APLOG_EMERG, server_conf,
-                       "offload device inactive");
-                   clean_child_exit(APEXIT_CHILDFATAL);
+                    ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO,
+                                 server_conf, "offload device inactive");
+                    clean_child_exit(APEXIT_CHILDFATAL); 
                    break;
                default:
-                   ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, server_conf,
-                       "select/accept error (%u)", errno);
+                    if (getppid() != 1) {
+                        ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO,
+                                     server_conf, "select/accept error (%u)",
+                                     errno);
+                    }
                    clean_child_exit(APEXIT_CHILDFATAL);
 #else
                default:
@@ -4919,6 +4895,9 @@ static void perform_idle_server_maintenance(void)
         */
        kill(ap_scoreboard_image->parent[to_kill].pid, SIG_IDLE_KILL);
        idle_spawn_rate = 1;
+#ifdef TPF
+        ap_update_child_status(to_kill, SERVER_DEAD, (request_rec *)NULL);
+#endif
     }
     else if (idle_count < ap_daemons_min_free) {
        /* terminate the free list */
@@ -5146,6 +5125,11 @@ static void standalone_main(int argc, char **argv)
             * to start up and get into IDLE state then we may spawn an
             * extra child
             */
+#ifdef TPF
+            if (shutdown_pending += os_check_server(tpf_server_name)) {
+                break;
+            }
+#endif
            if (pid >= 0) {
                process_child_status(pid, status);
                /* non-fatal death... note that it's gone in the scoreboard. */
@@ -5199,17 +5183,6 @@ static void standalone_main(int argc, char **argv)
            }
 
            perform_idle_server_maintenance();
-#ifdef TPF
-            ap_check_signals();
-            if (!shutdown_pending) {
-                if (os_check_server(tpf_server_name)) {
-                    shutdown_pending++;
-                } else {
-                    sleep(1);
-                    ap_check_signals();
-                }
-            }
-#endif /*TPF */
        }
 
        if (shutdown_pending) {
@@ -5470,6 +5443,7 @@ int REALMAIN(int argc, char *argv[])
                INETD_SERVNAME_LENGTH);
         tpf_server_name[INETD_SERVNAME_LENGTH + 1] = '\0';
         sprintf(tpf_mutex_key, "%.*x", TPF_MUTEX_KEY_SIZE - 1, getpid());
+        tpf_parent_pid = getppid();
         ap_open_logs(server_conf, plog);
         ap_tpf_zinet_checks(ap_standalone, tpf_server_name, server_conf);
         ap_tpf_save_argv(argc, argv);    /* save argv parms for children */
@@ -5490,9 +5464,8 @@ int REALMAIN(int argc, char *argv[])
             copy_listeners(pconf);
             reset_tpf_listeners(&input_parms.child);
 #ifdef SCOREBOARD_FILE
-            scoreboard_fd = input_parms.child.scoreboard_fd;
             ap_scoreboard_image = &_scoreboard_image;
-#else /* must be USE_TPF_SCOREBOARD or USE_SHMGET_SCOREBOARD */
+#else /* must be USE_SHMGET_SCOREBOARD */
             ap_scoreboard_image =
                 (scoreboard *)input_parms.child.scoreboard_heap;
 #endif
index 558a8df26864570613f612b289f50c0fec7879b8..d74810873b69be0071850348e478d1d6afe375e8 100644 (file)
@@ -534,6 +534,16 @@ static int status_handler(request_rec *r)
                if (!short_report) {
                    if (no_table_report) {
                        if (score_record.status == SERVER_DEAD)
+#ifdef TPF
+                            if (kill(ps_record.pid, 0) == 0) {
+                                /* on TPF show PIDs of the living dead */
+                                ap_rprintf(r,
+                                "<b>Server %d-%d</b> (%d): %d|%lu|%lu [",
+                                i, (int) ps_record.generation,
+                                (int)ps_record.pid, (int) conn_lres,
+                                my_lres, lres);
+                            } else
+#endif /* TPF */
                            ap_rprintf(r,
                                "<b>Server %d-%d</b> (-): %d|%lu|%lu [",
                                i, (int) ps_record.generation, (int) conn_lres,
@@ -608,6 +618,16 @@ static int status_handler(request_rec *r)
                    }
                    else {              /* !no_table_report */
                        if (score_record.status == SERVER_DEAD)
+#ifdef TPF
+                            if (kill(ps_record.pid, 0) == 0) {
+                                /* on TPF show PIDs of the living dead */
+                                ap_rprintf(r,
+                                    "<tr><td><b>%d-%d</b><td>%d<td>%d/%lu/%lu",
+                                    i, (int) ps_record.generation,
+                                    (int) ps_record.pid,
+                                    (int) conn_lres, my_lres, lres);
+                            } else
+#endif /* TPF */
                            ap_rprintf(r,
                                "<tr><td><b>%d-%d</b><td>-<td>%d/%lu/%lu",
                                i, (int) ps_record.generation,
index fb65ae89ca47dbd957bcd9b1c2e65711b978081d..b5db0d68a52c6c114a0ad9a77a9776ddba5c911f 100644 (file)
@@ -78,12 +78,15 @@ unsigned short zinet_model;
 char *argv_ptr = NULL;
 
 static FILE *sock_fp;
+static int   sock_sd;
 
-int tpf_select(int maxfds, fd_set *reads, fd_set *writes, fd_set *excepts, struct timeval *tv)
+int tpf_select(int maxfds, fd_set *reads, fd_set *writes, fd_set *excepts,
+               struct timeval *tv)
 {
-/* We're going to force our way through select.  We're only interested reads and TPF allows
-   2billion+ socket descriptors for we don't want an fd_set that big.  Just assume that maxfds-1
-   contains the socket descriptor we're interested in.  If it's 0, leave it alone. */
+/* We're going to force our way through select.  We're only interested reads
+   and TPF allows 2billion+ socket descriptors for we don't want an fd_set
+   that big.  Just assume that maxfds-1 contains the socket descriptor we're
+   interested in.  If it's 0, leave it alone. */
 
     int sockets[1];
     int no_reads = 0;
@@ -104,25 +107,31 @@ int tpf_select(int maxfds, fd_set *reads, fd_set *writes, fd_set *excepts, struc
     ap_check_signals();
     if ((no_reads + no_writes + no_excepts == 0) &&
         (tv) && (tv->tv_sec + tv->tv_usec != 0)) {
-#ifdef TPF_HAVE_SAWNC
         /* TPF's select immediately returns if the sum of
            no_reads, no_writes, and no_excepts is zero.
-           This means that the select calls in http_main.c
-           for shutdown don't actually wait while killing children.
            The following code makes TPF's select work a little closer
            to everyone else's select:
         */
+#ifdef TPF_HAVE_SAWNC
         struct ev0bk evnblock;
-
+#endif
         timeout = tv->tv_sec;
         if (tv->tv_usec) {
             timeout++; /* round up to seconds (like TPF's select does) */
         }
-        evnblock.evnpstinf.evnbkc1 = 1; /* nbr of posts needed */
-        evntc(&evnblock, EVENT_CNT, 'N', timeout, EVNTC_1052);
-        tpf_sawnc(&evnblock, EVENT_CNT);
+        if (timeout > 0) { /* paranoid check for valid timeout */
+#ifdef TPF_HAVE_SAWNC
+            evnblock.evnpstinf.evnbkc1 = 1; /* nbr of posts needed */
+            evntc(&evnblock, EVENT_CNT, 'N', timeout, EVNTC_1052);
+            tpf_sawnc(&evnblock, EVENT_CNT);
+#else
+            sleep(timeout);
 #endif
+        }
     } else {
+        if (timeout < 0) { /* paranoid check for valid timeout */
+            timeout = 0;
+        }
         rv = select(sockets, no_reads, no_writes, no_excepts, timeout);
     }
     ap_check_signals();
@@ -138,13 +147,13 @@ int tpf_accept(int sockfd, struct sockaddr *peer, int *paddrlen)
 
     ap_check_signals();
     socks[0] = sockfd;
-    rv = select(socks, 1, 0, 0, 1000);
+    rv = select(socks, 1, 0, 0, TPF_ACCEPT_SECS_TO_BLOCK * 1000);
     errno = sock_errno();
     if(rv>0) {
-        ap_check_signals();
         rv = accept(sockfd, peer, paddrlen);
         errno = sock_errno();
     }    
+    ap_check_signals();
     return rv;
 }
    
@@ -372,10 +381,8 @@ pid_t os_fork(server_rec *s, int slot)
         ap_log_error(APLOG_MARK, APLOG_CRIT, s,
         "unable to replace stdout with sock device driver");
     input_parms.generation = ap_my_generation;
-#if defined(USE_TPF_SCOREBOARD) || defined(USE_SHMGET_SCOREBOARD)
+#ifdef USE_SHMGET_SCOREBOARD
     input_parms.scoreboard_heap = ap_scoreboard_image;
-#else
-    input_parms.scoreboard_fd = scoreboard_fd;
 #endif
 
     lr = ap_listeners;
@@ -448,6 +455,8 @@ void ap_tpf_zinet_checks(int standalone,
 int os_check_server(char *server) {
     int *current_acn;
 
+    ap_check_signals();
+
     /* check that the program activation number hasn't changed */
         current_acn = (int *)cinfc_fast(CINFC_CMMACNUM);
         if (ecbp2()->ce2acn != *current_acn) {
@@ -476,8 +485,8 @@ void os_note_additional_cleanups(pool *p, int sd) {
     sprintf(sockfilename, "/dev/tpf.socket.file/%.8X", sd);
     sock_fp = fopen(sockfilename, "r+");
     /* arrange to close on exec or restart */
-    ap_note_cleanups_for_file(p, sock_fp);
-    fcntl(sd,F_SETFD,FD_CLOEXEC);
+    ap_note_cleanups_for_file_ex(p, sock_fp, 1);
+    sock_sd = sd;
 }
 
 void ap_tpf_save_argv(int argc, char **argv) {
@@ -498,6 +507,7 @@ void ap_tpf_save_argv(int argc, char **argv) {
 }
 
 void os_tpf_child(APACHE_TPF_INPUT *input_parms) {
+    extern pid_t tpf_parent_pid;
     extern char tpf_mutex_key[TPF_MUTEX_KEY_SIZE];
 
     tpf_child = 1;
@@ -505,7 +515,8 @@ void os_tpf_child(APACHE_TPF_INPUT *input_parms) {
     ap_restart_time = input_parms->restart_time;
     tpf_fds = input_parms->tpf_fds;
     tpf_shm_static_ptr = input_parms->shm_static_ptr;
-    sprintf(tpf_mutex_key, "%.*x", TPF_MUTEX_KEY_SIZE - 1, getppid());
+    tpf_parent_pid = getppid();
+    sprintf(tpf_mutex_key, "%.*x", TPF_MUTEX_KEY_SIZE - 1, tpf_parent_pid);
 }
 
 #ifndef __PIPE_
@@ -540,7 +551,7 @@ static void *ap_tpf_get_shared_mem(size_t size)
     void *result;
 
     if ((shmid = shmget(shmkey, size, IPC_CREAT | SHM_R | SHM_W)) == -1) {
-        perror("shmget failed in ap_tpf_get_shared_mem funciton");
+        perror("shmget failed in ap_tpf_get_shared_mem function");
         exit(1);
     }
 #define BADSHMAT ((void *)(-1))
@@ -777,6 +788,11 @@ int killpg(pid_t pgrp, int sig)
             kill(pid, sig);
         }
     }
+    /* allow time for the signals to get to the children */
+    sleep(1);
+    /* get idle children's attention by closing the socket */
+    closesocket(sock_sd);
+    sleep(1);
 
     return(0);
 }
@@ -788,9 +804,14 @@ int killpg(pid_t pgrp, int sig)
 */
 void show_os_specific_compile_settings(void)
 {
+int i;
 
 #ifdef USE_TPF_SCOREBOARD
-    printf(" -D USE_TPF_SCOREBOARD\n");
+   #error "USE_TPF_SCOREBOARD (system heap scoreboard)"
+   #error "is no longer supported."
+   #error "Replace with USE_SHMGET_SCOREBOARD to use"
+   #error "shared memory or remove entirely to use"
+   #error "scoreboard on file for pre-PUT10 systems"
 #endif
 
 #ifdef TPF_FORK_EXTENDED
@@ -821,4 +842,21 @@ void show_os_specific_compile_settings(void)
     printf(" -D HAVE_SYSLOG\n");
 #endif
 
+    printf(" -D TPF_ACCEPT_SECS_TO_BLOCK=%i\n", TPF_ACCEPT_SECS_TO_BLOCK);
+    /* round SCOREBOARD_MAINTENANCE_INTERVAL up to seconds */
+    i = (SCOREBOARD_MAINTENANCE_INTERVAL + 999999) / 1000000;
+    if (i == 1) {
+        printf(" -D SCOREBOARD_MAINTENANCE_INTERVAL=1 SECOND\n");
+    } else {
+        printf(" -D SCOREBOARD_MAINTENANCE_INTERVAL=%i SECONDS\n", i); 
+    }
+
+#ifdef TPF_HAVE_SIGACTION
+    printf(" -D TPF_HAVE_SIGACTION\n");
+#endif
+
+#ifdef NO_USE_SIGACTION
+    printf(" -D NO_USE_SIGACTION\n");
+#endif
+
 }
index 32f7c7f495a991467725b9ba1fc7dd2cbadd91cb..fb0390e35dfcc43b59a05734c694e8753f1678dc 100644 (file)
 #include <sysapi.h>  
 #include "ap_config.h"
 
+#define WUNTRACED 0 /* TPF's waitpid() doesn't support WUNTRACED */
+
+/* TPF_ACCEPT_SECS_TO_BLOCK is the number of seconds to block while
+   waiting to accept a new request in the ap_accept/tpf_accept function */
+#ifndef TPF_ACCEPT_SECS_TO_BLOCK
+#define TPF_ACCEPT_SECS_TO_BLOCK 1
+#endif
+
 #ifdef HAVE_ISNAN
 #undef HAVE_ISNAN
 #endif
@@ -151,7 +159,6 @@ typedef struct tpf_fd_list {
 #include <i$netd.h>
 typedef struct apache_input {
     void                *scoreboard_heap;   /* scoreboard system heap address */
-    int                 scoreboard_fd;      /* scoreboard file descriptor */
     int                 slot;               /* child number */
     int                 generation;         /* server generation number */
     int                 listeners[10];
@@ -189,7 +196,6 @@ void show_os_specific_compile_settings(void);
 char *getpass(const char *prompt);
 int killpg(pid_t pgrp, int sig);
 extern char *ap_server_argv0;
-extern int scoreboard_fd;
 #include <signal.h>
 #ifndef SIGPIPE
 #define SIGPIPE 14