You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 1999/02/12 19:30:25 UTC

cvs commit: apache-apr/pthreads/src/main Makefile.tmpl fdqueue.c http_main.c

rbb         99/02/12 10:30:24

  Modified:    pthreads/src/include fdqueue.h
               pthreads/src/main Makefile.tmpl fdqueue.c http_main.c
  Log:
  Changes to let SIGHUP work.  This also does some cleanup of the fdqueue,
  related to the shutdown of child processes.  Finally, we removed some of the
  dubgging statements that were committed in last night's patch.
  
  Work done by Manoj and I.
  
  Revision  Changes    Path
  1.2       +3 -2      apache-apr/pthreads/src/include/fdqueue.h
  
  Index: fdqueue.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/include/fdqueue.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- fdqueue.h	1999/02/03 17:50:07	1.1
  +++ fdqueue.h	1999/02/12 18:30:19	1.2
  @@ -1,5 +1,6 @@
   #ifndef FDQUEUE_H
   #define FDQUEUE_H
  +#include "httpd.h"
   #include <stdlib.h>
   #include <unistd.h>
   #include <pthread.h>
  @@ -27,8 +28,8 @@
       pthread_cond_t not_full;
   } FDQueue;
   
  -int queue_init(FDQueue *queue, size_t bounds);
  -void queue_destroy(FDQueue *queue);
  +int queue_init(FDQueue *queue, size_t bounds, pool *a);
  +void *queue_destroy(FDQueue *queue);
   int queue_push(FDQueue *queue, int fd, struct sockaddr *addr);
   int queue_pop(FDQueue *queue, struct sockaddr *addr);
   int queue_size(FDQueue *queue);
  
  
  
  1.4       +1 -0      apache-apr/pthreads/src/main/Makefile.tmpl
  
  Index: Makefile.tmpl
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/Makefile.tmpl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Makefile.tmpl	1999/02/07 06:29:29	1.3
  +++ Makefile.tmpl	1999/02/12 18:30:21	1.4
  @@ -68,6 +68,7 @@
    $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h $(INCDIR)/alloc.h \
    $(INCDIR)/buff.h $(INCDIR)/ap.h $(INCDIR)/util_uri.h \
    $(INCDIR)/http_main.h $(INCDIR)/http_log.h
  +fdqueue.o: fdqueue.c  $(INCDIR)/fdqueue.h $(INCDIR)/alloc.h 
   gen_test_char.o: gen_test_char.c $(INCDIR)/httpd.h \
    $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \
    $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h $(INCDIR)/ap_ctype.h \
  
  
  
  1.4       +4 -6      apache-apr/pthreads/src/main/fdqueue.c
  
  Index: fdqueue.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/fdqueue.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- fdqueue.c	1999/02/11 22:15:55	1.3
  +++ fdqueue.c	1999/02/12 18:30:22	1.4
  @@ -1,22 +1,20 @@
   #include "fdqueue.h"
   
  -/* XXX - We should get rid of the malloc and free used here. This should be
  - * ap_palloc, I guess (mvsk) */
  -
   /* Assumption: queue itself is allocated by the user */
   /* Assumption: increment and decrement are atomic on int */
   
  -int queue_init(FDQueue *queue, size_t bounds) {
  +int queue_init(FDQueue *queue, size_t bounds, pool *a) {
       pthread_mutex_init(&queue->one_big_mutex, NULL);
       pthread_cond_init(&queue->not_empty, NULL);
       pthread_cond_init(&queue->not_full, NULL);
       queue->head = queue->tail = 0;
  -    queue->data = malloc(bounds * sizeof(FDQueueElement));
  +    queue->data = ap_palloc(a, bounds * sizeof(FDQueueElement));
       queue->bounds = bounds;
  +    ap_register_cleanup(a, queue, (void (*)(void *))queue_destroy, ap_null_cleanup);
       return FD_QUEUE_SUCCESS;
   }
   
  -void queue_destroy(FDQueue *queue) {
  +void *queue_destroy(FDQueue *queue) {
       free(queue->data);
       /* Ignore errors here, we can't do anything about them anyway */
       pthread_cond_destroy(&queue->not_empty);
  
  
  
  1.18      +40 -43    apache-apr/pthreads/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/http_main.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- http_main.c	1999/02/11 22:15:55	1.17
  +++ http_main.c	1999/02/12 18:30:22	1.18
  @@ -497,7 +497,6 @@
           close(lr->fd);
   	lr= lr->next;
       }
  -    fprintf(stderr, "gonna exit doit");
       pthread_exit(NULL);
   }
   
  @@ -1291,7 +1290,6 @@
   
   static void graceful_sig_handler(int sig)
   {
  -    fprintf(stderr, "Got a HUP from parent");
       requests_this_child = 0;
   }
   
  @@ -1340,7 +1338,6 @@
   void ap_start_restart(int graceful)
   {
   
  -  fprintf(stderr, " SENDING A RESTART MESSAGE!!");
       if (restart_pending == 1) {
   	/* Probably not an error - don't bother reporting it */
   	return;
  @@ -1453,7 +1450,7 @@
   
       signal(SIGTERM, sig_term);
   #ifdef SIGHUP
  -    signal(SIGHUP, sig_hup);
  +    signal(SIGHUP, restart);
   #endif /* SIGHUP */
   #ifndef LINUX
   #ifdef SIGUSR1
  @@ -1724,7 +1721,8 @@
   	*nr = *lr;
   	ap_kill_cleanups_for_socket(p, nr->fd); 
   	nr->next = old_listeners;
  -        nr->index = 0; 
  +        nr->index = 0;
  +	nr->used = 1;
   	old_listeners = nr;
   	lr = lr->next;
       } while (lr && lr != ap_listeners);
  @@ -1783,15 +1781,9 @@
   	    break;
   	lr = lr->next;
       }
  +    head_listener = ap_listeners;
       close_unused_listeners();
   
  -    listenfds = ap_palloc(p, sizeof(struct pollfd));
  -    for (lr = ap_listeners, i = 0; i < num_listenfds; lr = lr->next, ++i) {
  -        lr->index = i;
  -        listenfds[i].fd = lr->fd;
  -        listenfds[i].events = POLLIN;
  -        listenfds[i].revents = 0;
  -    }
   #ifdef NO_SERIALIZED_ACCEPT
       /* warn them about the starvation problem if they're using multiple
        * sockets
  @@ -1995,7 +1987,6 @@
        * until no requests are left or we decide to close.
        */
   
  -    fprintf(stderr,"%d child_main: about to read request\n",my_child_num);
   
       while ((r = ap_read_request(current_conn)) != NULL) {
   	(void) ap_update_child_status(my_child_num, my_thread_num,
  @@ -2073,12 +2064,14 @@
   	      /*	        ap_log_error*/
   	    }  
   	 } else{
  +	   perror("ARGH\n");
  +	   exit(0);
  +
   	   /*	    ap_log_error()*/
   	 }
       }
       ap_update_child_status(my_pid, my_tid, SERVER_DEAD, (request_rec *) NULL);
       pthread_once(&firstcall, graceful_killer);
  -    fprintf(stderr, "gonna exit  accept thread");
   
       pthread_exit(NULL);
   }
  @@ -2103,7 +2096,6 @@
       }
       ap_update_child_status(my_pid, my_tid, SERVER_DEAD, (request_rec *) NULL);
       pthread_once(&firstcall, graceful_killer);
  -    fprintf(stderr, "gonna exit   worker thread");
   
       pthread_exit(NULL);
   }
  @@ -2265,7 +2257,7 @@
   
       /*done with init critical section */
   
  -    queue_init(&csd_queue, ap_threads_per_child);
  +    queue_init(&csd_queue, ap_threads_per_child, pchild);
   
       pthread_attr_init(&thread_attr);
   
  @@ -2314,35 +2306,43 @@
   
       /* Setup acceptor threads */
       
  -    lr = ap_listeners;
  -    while (lr->next != NULL) {
  -        my_info = NULL;
  -
  -	my_info = (proc_info *)malloc(sizeof(proc_info));
  -	my_info->pid = my_child_num;
  -        my_info->tid = i++;
  -	my_info->sd = lr->fd;
  -
  -	if (pthread_create(&thread, &thread_attr, accept_thread, my_info)) {
  -	  ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf,
  -		       "pthread_create: unable to create acceptor thread");
  -	  /* 
  -	   * We failed to create a thread.  Update the scoreboard,  
  -	   * or it will say SERVER_STARTING forever.
  -	   */
  -	  exit(1);
  -	} else {
  -	  /* We let each thread update it's own scoreboard entry.  This is done
  -	   * because it let's us deal with tid better.
  -	   */
  +    lr = head_listener;
  +    if (lr) {
  +        while (lr->next != NULL) {
  +	    my_info = NULL;
  +	  
  +	    my_info = (proc_info *)malloc(sizeof(proc_info));
  +	    my_info->pid = my_child_num;
  +	    my_info->tid = i++;
  +	    my_info->sd = lr->fd;
  +	    lr->used = 1;
  +
  +	    if (pthread_create(&thread, &thread_attr, accept_thread, my_info)) {
  +	        ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf,
  +			     "pthread_create: unable to create acceptor thread");
  +		/* 
  +		 * We failed to create a thread.  Update the scoreboard,  
  +		 * or it will say SERVER_STARTING forever.
  +		 */
  +		exit(1);
  +	    } else {
  +	      /* We let each thread update it's own scoreboard entry.  This is done
  +	       * because it let's us deal with tid better.
  +	       */
  +	    }
  +	    lr = lr->next;
   	}
  -	lr = lr->next;
  +    } else {
  +      /* no listening sockets????  Kill the server please.  */
  +      exit(0);
       }
  +#if 0
       /* This thread will be the one responsible for handling signals */
       sigfillset(&sig_mask);
       if ((ret = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) {
           ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, "pthread_sigmask failed");
       }
  +#endif
   
       pthread_attr_destroy(&thread_attr);
   
  @@ -2352,6 +2352,7 @@
       my_info->pid = my_child_num;
       my_info->tid = i++;
       my_info->sd = lr->fd;
  +    lr->used = 1;
       
       accept_thread(my_info);
   }
  @@ -2363,7 +2364,6 @@
       listen_rec *lr;
   
       max_threads_limit = 0;
  -    lr = ap_listeners;
       for (lr = ap_listeners, max_threads_limit = 0; lr; 
   	 lr=lr->next, max_threads_limit++);
   
  @@ -2655,15 +2655,12 @@
       }
       ap_clear_pool(pconf);
       ptemp = ap_make_sub_pool(pconf);
  -
       server_conf = ap_read_config(pconf, ptemp, ap_server_confname);
       setup_listeners(pconf);
       ap_open_logs(server_conf, pconf);
       ap_log_pid(pconf, ap_pid_fname);
       ap_set_version();
  -
       ap_init_modules(pconf, server_conf);
  -
       version_locked++;
       if (!is_graceful) {
   	reinit_scoreboard(pconf);
  @@ -2671,7 +2668,6 @@
   
       set_signals();
       /* set up get_socket */
  -    head_listener = ap_listeners;
   
       if (ap_daemons_max_free < ap_daemons_min_free + 1)	/* Don't thrash... */
   	ap_daemons_max_free = ap_daemons_min_free + 1;
  @@ -2785,6 +2781,7 @@
   	if (ap_killpg(pgrp, SIGTERM) < 0) {
   	    ap_log_error(APLOG_MARK, APLOG_WARNING, server_conf, "killpg SIGTERM");
   	}
  +        reclaim_child_processes(1);		/* Start with SIGTERM */
   	ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, server_conf,
   		    "SIGHUP received.  Attempting to restart");
       }