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

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

Return to bug 57685