View | Details | Raw Unified | Return to bug 57685
Collapse All | Expand All

(-)a/modules/generators/mod_cgid.c (-3 / +23 lines)
Lines 866-871 static int cgid_start(apr_pool_t *p, server_rec *main_server, Link Here
866
                      apr_proc_t *procnew)
866
                      apr_proc_t *procnew)
867
{
867
{
868
868
869
    sleep(3);
870
869
    daemon_should_exit = 0; /* clear setting from previous generation */
871
    daemon_should_exit = 0; /* clear setting from previous generation */
870
    if ((daemon_pid = fork()) < 0) {
872
    if ((daemon_pid = fork()) < 0) {
871
        ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, APLOGNO(01253)
873
        ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, APLOGNO(01253)
Lines 1203-1220 static int connect_to_daemon(int *sdptr, request_rec *r, Link Here
1203
{
1205
{
1204
    int sd;
1206
    int sd;
1205
    int connect_tries;
1207
    int connect_tries;
1208
    int connect_errno;
1206
    apr_interval_time_t sliding_timer;
1209
    apr_interval_time_t sliding_timer;
1207
1210
1208
    connect_tries = 0;
1211
    connect_tries = 0;
1209
    sliding_timer = 100000; /* 100 milliseconds */
1212
    sliding_timer = 100000; /* 100 milliseconds */
1210
    while (1) {
1213
    while (1) {
1214
        connect_errno = 0;
1211
        ++connect_tries;
1215
        ++connect_tries;
1212
        if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
1216
        if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
1213
            return log_scripterror(r, conf, HTTP_INTERNAL_SERVER_ERROR, errno,
1217
            return log_scripterror(r, conf, HTTP_INTERNAL_SERVER_ERROR, errno,
1214
                                   APLOGNO(01255) "unable to create socket to cgi daemon");
1218
                                   APLOGNO(01255) "unable to create socket to cgi daemon");
1215
        }
1219
        }
1216
        if (connect(sd, (struct sockaddr *)server_addr, server_addr_len) < 0) {
1220
        if (connect(sd, (struct sockaddr *)server_addr, server_addr_len) < 0) {
1217
            if (errno == ECONNREFUSED && connect_tries < DEFAULT_CONNECT_ATTEMPTS) {
1221
            /* Save errno for later */
1222
            connect_errno = errno;
1223
            /* ECONNREFUSED means the listen queue is full; ENOENT means that
1224
             * the cgid server either hasn't started up yet, or we're pointing
1225
             * at the wrong socket file */
1226
            if ((errno == ECONNREFUSED || errno == ENOENT)
1227
                && connect_tries < DEFAULT_CONNECT_ATTEMPTS) {
1218
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, errno, r, APLOGNO(01256)
1228
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, errno, r, APLOGNO(01256)
1219
                              "connect #%d to cgi daemon failed, sleeping before retry",
1229
                              "connect #%d to cgi daemon failed, sleeping before retry",
1220
                              connect_tries);
1230
                              connect_tries);
Lines 1235-1245 static int connect_to_daemon(int *sdptr, request_rec *r, Link Here
1235
                                      close_unix_socket, apr_pool_cleanup_null);
1245
                                      close_unix_socket, apr_pool_cleanup_null);
1236
            break; /* we got connected! */
1246
            break; /* we got connected! */
1237
        }
1247
        }
1248
1238
        /* gotta try again, but make sure the cgid daemon is still around */
1249
        /* gotta try again, but make sure the cgid daemon is still around */
1239
        if (kill(daemon_pid, 0) != 0) {
1250
        if (connect_errno != ENOENT && kill(daemon_pid, 0) != 0) {
1240
            return log_scripterror(r, conf, HTTP_SERVICE_UNAVAILABLE, errno, APLOGNO(01258)
1251
            return log_scripterror(r, conf, HTTP_SERVICE_UNAVAILABLE, connect_errno, APLOGNO(01258)
1241
                                   "cgid daemon is gone; is Apache terminating?");
1252
                                   "cgid daemon is gone; is Apache terminating?");
1242
        }
1253
        }
1254
1255
        /* If we didn't find the socket but we started the server long ago,
1256
         * chances are there's something wrong with the cgid daemon
1257
         * XXX: Hardcoded number alert */
1258
        if (connect_errno == ENOENT &&
1259
                apr_time_sec(apr_time_now() - ap_scoreboard_image->global->restart_time) > 60) {
1260
            return log_scripterror(r, conf, HTTP_SERVICE_UNAVAILABLE, connect_errno, APLOGNO()
1261
                                   "the unix socket file is gone or was never created");
1262
        }
1243
    }
1263
    }
1244
    *sdptr = sd;
1264
    *sdptr = sd;
1245
    return OK;
1265
    return OK;

Return to bug 57685