Changeset 1982

Show
Ignore:
Timestamp:
09/05/2007 10:39:56 AM (14 months ago)
Author:
jan
Message:

* fixed forwarding a SIGINT and SIGHUP when using max-workers (#902)

Location:
branches/lighttpd-1.4.x
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/lighttpd-1.4.x/NEWS

    r1980 r1982  
    66- 1.4.18 - 
    77  * fixed compile error on IRIX 6.5.x on prctl() (#1333) 
     8  * fixed forwarding a SIGINT and SIGHUP when using max-workers (#902) 
    89 
    910 
  • branches/lighttpd-1.4.x/src/server.c

    r1980 r1982  
    6969static volatile sig_atomic_t handle_sig_alarm = 1; 
    7070static volatile sig_atomic_t handle_sig_hup = 0; 
     71static volatile sig_atomic_t forwarded_sig_hup = 0; 
    7172 
    7273#if defined(HAVE_SIGACTION) && defined(SA_SIGINFO) 
     
    9596                break; 
    9697        case SIGHUP: 
    97                 handle_sig_hup = 1; 
    98                 memcpy(&last_sighup_info, si, sizeof(*si)); 
     98                /**  
     99                 * we send the SIGHUP to all procs in the process-group 
     100                 * this includes ourself 
     101                 *  
     102                 * make sure we only send it once and don't create a  
     103                 * infinite loop 
     104                 */ 
     105                if (!forwarded_sig_hup) { 
     106                        handle_sig_hup = 1; 
     107                        memcpy(&last_sighup_info, si, sizeof(*si)); 
     108                } else { 
     109                        forwarded_sig_hup = 0; 
     110                } 
    99111                break; 
    100112        case SIGCHLD: 
     
    9891001        if (num_childs > 0) { 
    9901002                int child = 0; 
    991                 while (!child && !srv_shutdown) { 
     1003                while (!child && !srv_shutdown && !graceful_shutdown) { 
    9921004                        if (num_childs > 0) { 
    9931005                                switch (fork()) { 
     
    10041016                                int status; 
    10051017 
    1006                                 /* ignore EINTR */ 
    1007                                 if (-1 != wait(&status)) num_childs++; 
    1008                         } 
    1009                 } 
    1010                 if (srv_shutdown) { 
    1011                         kill(0, SIGTERM); 
    1012                 } 
    1013                 if (!child) return 0; 
     1018                                if (-1 != wait(&status)) { 
     1019                                        /**  
     1020                                         * one of our workers went away  
     1021                                         */ 
     1022                                        num_childs++; 
     1023                                } else { 
     1024                                        switch (errno) { 
     1025                                        case EINTR: 
     1026                                                /** 
     1027                                                 * if we receive a SIGHUP we have to close our logs ourself as we don't  
     1028                                                 * have the mainloop who can help us here 
     1029                                                 */ 
     1030                                                if (handle_sig_hup) { 
     1031                                                        handle_sig_hup = 0; 
     1032 
     1033                                                        log_error_cycle(srv); 
     1034 
     1035                                                        /** 
     1036                                                         * forward to all procs in the process-group 
     1037                                                         *  
     1038                                                         * we also send it ourself 
     1039                                                         */ 
     1040                                                        if (!forwarded_sig_hup) { 
     1041                                                                forwarded_sig_hup = 1; 
     1042                                                                kill(0, SIGHUP); 
     1043                                                        } 
     1044                                                } 
     1045                                                break; 
     1046                                        default: 
     1047                                                break; 
     1048                                        } 
     1049                                } 
     1050                        } 
     1051                } 
     1052 
     1053                /** 
     1054                 * for the parent this is the exit-point  
     1055                 */ 
     1056                if (!child) { 
     1057                        /**  
     1058                         * kill all children too  
     1059                         */ 
     1060                        if (graceful_shutdown) { 
     1061                                kill(0, SIGINT); 
     1062                        } else if (srv_shutdown) { 
     1063                                kill(0, SIGTERM); 
     1064                        } 
     1065 
     1066                        log_error_close(srv); 
     1067                        network_close(srv); 
     1068                        connections_free(srv); 
     1069                        plugins_free(srv); 
     1070                        server_free(srv); 
     1071                        return 0; 
     1072                } 
    10141073        } 
    10151074#endif 
     
    11021161                                log_error_write(srv, __FILE__, __LINE__, "sdsd",  
    11031162                                        "logfiles cycled UID =", 
    1104                                         last_sigterm_info.si_uid, 
     1163                                        last_sighup_info.si_uid, 
    11051164                                        "PID =", 
    1106                                         last_sigterm_info.si_pid); 
     1165                                        last_sighup_info.si_pid); 
    11071166#else 
    11081167                                log_error_write(srv, __FILE__, __LINE__, "s",