~ubuntu-branches/ubuntu/hardy/lighttpd/hardy

« back to all changes in this revision

Viewing changes to src/server.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2007-09-12 14:02:31 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070912140231-g5w19l8wbtywlcgd
Tags: 1.4.18-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Update maintainer field in debian/control.
  - Build against libgamin-dev rather than libfam-dev (fixes a warning
    during startup)
  - Make sure that upgrades succeed, even if we can't restart lighttpd.
  - Clean environment in init.d script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
static volatile sig_atomic_t graceful_shutdown = 0;
69
69
static volatile sig_atomic_t handle_sig_alarm = 1;
70
70
static volatile sig_atomic_t handle_sig_hup = 0;
 
71
static volatile sig_atomic_t forwarded_sig_hup = 0;
71
72
 
72
73
#if defined(HAVE_SIGACTION) && defined(SA_SIGINFO)
73
74
static volatile siginfo_t last_sigterm_info;
94
95
                handle_sig_alarm = 1; 
95
96
                break;
96
97
        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
                }
99
111
                break;
100
112
        case SIGCHLD:
101
113
                break;
775
787
                        setuid(pwd->pw_uid);
776
788
                }
777
789
#endif
778
 
#ifdef HAVE_SYS_PRCTL_H
 
790
#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE)
 
791
                /**
 
792
                 * on IRIX 6.5.30 they have prctl() but no DUMPABLE
 
793
                 */
779
794
                if (srv->srvconf.enable_cores) {
780
795
                        prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
781
796
                }
985
1000
        num_childs = srv->srvconf.max_worker;
986
1001
        if (num_childs > 0) {
987
1002
                int child = 0;
988
 
                while (!child && !srv_shutdown) {
 
1003
                while (!child && !srv_shutdown && !graceful_shutdown) {
989
1004
                        if (num_childs > 0) {
990
1005
                                switch (fork()) {
991
1006
                                case -1:
1000
1015
                        } else {
1001
1016
                                int status;
1002
1017
 
1003
 
                                /* ignore EINTR */
1004
 
                                if (-1 != wait(&status)) num_childs++;
1005
 
                        }
1006
 
                }
1007
 
                if (srv_shutdown) {
1008
 
                        kill(0, SIGTERM);
1009
 
                }
1010
 
                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
                }
1011
1073
        }
1012
1074
#endif
1013
1075
 
1098
1160
#ifdef HAVE_SIGACTION
1099
1161
                                log_error_write(srv, __FILE__, __LINE__, "sdsd", 
1100
1162
                                        "logfiles cycled UID =",
1101
 
                                        last_sigterm_info.si_uid,
 
1163
                                        last_sighup_info.si_uid,
1102
1164
                                        "PID =",
1103
 
                                        last_sigterm_info.si_pid);
 
1165
                                        last_sighup_info.si_pid);
1104
1166
#else
1105
1167
                                log_error_write(srv, __FILE__, __LINE__, "s", 
1106
1168
                                        "logfiles cycled");