PeruserAttachments: httpd-2.2.3-peruser-0.3.0-dc3-r57.patch

File httpd-2.2.3-peruser-0.3.0-dc3-r57.patch, 9.8 KB (added by mephisto23, 3 years ago)
  • server/mpm/experimental/peruser/peruser.c

    old new  
    320320 * process. 
    321321 */ 
    322322static apr_size_t child_info_size; 
    323 static child_info *child_info_image; 
     323static child_info *child_info_image = NULL; 
    324324static child_grace_info_t *child_grace_info_table; 
    325325struct ap_ctable *ap_child_table; 
    326326 
     
    936936    msg.msg_iovlen  = 5; 
    937937 
    938938    cmsg = apr_palloc(pool, sizeof(*cmsg) + sizeof(sock_fd)); 
    939     cmsg->cmsg_len   = sizeof(*cmsg) + sizeof(sock_fd); 
     939    cmsg->cmsg_len   = CMSG_LEN(sizeof(sock_fd)); 
    940940    cmsg->cmsg_level = SOL_SOCKET; 
    941941    cmsg->cmsg_type  = SCM_RIGHTS; 
    942942 
     
    10341034        ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "apr_os_sock_get"); 
    10351035    } 
    10361036 
    1037     _DBG("child_num=%d sock=%ld sock_fd=%d\n", my_child_num, sock, sock_fd); 
     1037    _DBG("child_num=%d sock=%ld sock_fd=%d", my_child_num, sock, sock_fd); 
    10381038    _DBG("type=%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type), my_child_num); 
    10391039 
     1040#ifdef _OSD_POSIX 
    10401041    if (sock_fd >= FD_SETSIZE) 
    10411042    { 
    10421043        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, 
     
    10481049        _DBG("child_num=%d: exiting with error", my_child_num); 
    10491050        return; 
    10501051    } 
     1052#endif 
    10511053 
    10521054    if (CHILD_INFO_TABLE[my_child_num].sock_fd < 0) 
    10531055    { 
     
    13001302    msg.msg_iovlen  = 5; 
    13011303 
    13021304    cmsg = apr_palloc(r->pool, sizeof(*cmsg) + sizeof(sock_fd)); 
    1303     cmsg->cmsg_len   = sizeof(*cmsg) + sizeof(sock_fd); 
     1305    cmsg->cmsg_len   = CMSG_LEN(sizeof(sock_fd)); 
    13041306    cmsg->cmsg_level = SOL_SOCKET; 
    13051307    cmsg->cmsg_type  = SCM_RIGHTS; 
    13061308 
     
    13091311    msg.msg_control    = cmsg; 
    13101312    msg.msg_controllen = cmsg->cmsg_len; 
    13111313 
    1312  
    13131314    if (processor->status == CHILD_STATUS_STANDBY) 
    13141315    { 
    13151316        _DBG("Activating child #%d", processor->id); 
     
    13741375    iov[3].iov_len  = HUGE_STRING_LEN; 
    13751376 
    13761377    cmsg = apr_palloc(ptrans, sizeof(*cmsg) + sizeof(trans_sock_fd)); 
    1377     cmsg->cmsg_len = sizeof(*cmsg) + sizeof(trans_sock_fd); 
     1378    cmsg->cmsg_len = CMSG_LEN(sizeof(trans_sock_fd)); 
    13781379 
    13791380    msg.msg_name       = NULL; 
    13801381    msg.msg_namelen    = 0; 
     
    14241425    apr_cpystrn(headers, buff, header_len + 1); 
    14251426    _DBG("header_len=%d headers=\"%s\"", header_len, headers); 
    14261427 
    1427 if (header_len) {     
    1428     _DBG("header_len > 0, we got a request", 0); 
    1429     /* -- store received data into an brigade and add 
    1430           it to the current transaction's pool -- */ 
    1431     bucket = apr_bucket_eos_create(alloc); 
    1432     APR_BRIGADE_INSERT_HEAD(bb, bucket); 
    1433     bucket = apr_bucket_socket_create(*trans_sock, alloc); 
    1434     APR_BRIGADE_INSERT_HEAD(bb, bucket); 
    1435  
    1436     if (body_len) { 
    1437         body = (char*)&buff[header_len + 1]; 
    1438         _DBG("body_len=%d body=\"%s\"", body_len, body); 
    1439  
    1440         bucket = apr_bucket_heap_create(body, body_len, NULL, alloc); 
     1428    if (header_len) {     
     1429        _DBG("header_len > 0, we got a request", 0); 
     1430        /* -- store received data into an brigade and add 
     1431           it to the current transaction's pool -- */ 
     1432        bucket = apr_bucket_eos_create(alloc); 
    14411433        APR_BRIGADE_INSERT_HEAD(bb, bucket); 
     1434        bucket = apr_bucket_socket_create(*trans_sock, alloc); 
     1435        APR_BRIGADE_INSERT_HEAD(bb, bucket); 
     1436         
     1437        if (body_len) { 
     1438            body = (char*)&buff[header_len + 1]; 
     1439            _DBG("body_len=%d body=\"%s\"", body_len, body); 
     1440             
     1441            bucket = apr_bucket_heap_create(body, body_len, NULL, alloc); 
     1442            APR_BRIGADE_INSERT_HEAD(bb, bucket); 
     1443        } else { 
     1444            _DBG("There is no body",0); 
     1445        } 
     1446         
     1447        bucket = apr_bucket_heap_create(headers, header_len, NULL, alloc); 
     1448         
     1449        APR_BRIGADE_INSERT_HEAD(bb, bucket); 
     1450        apr_pool_userdata_set(bb, "PERUSER_SOCKETS", NULL, ptrans); 
    14421451    } else { 
    1443         _DBG("There is no body",0); 
     1452        _DBG("header_len == 0, we got a socket only", 0); 
    14441453    } 
    1445  
    1446     bucket = apr_bucket_heap_create(headers, header_len, NULL, alloc); 
    1447  
    1448     APR_BRIGADE_INSERT_HEAD(bb, bucket); 
    1449     apr_pool_userdata_set(bb, "PERUSER_SOCKETS", NULL, ptrans); 
    1450 } else { 
    1451     _DBG("header_len == 0, we got a socket only", 0); 
    1452 } 
    14531454    _DBG("returning 0", 0); 
    14541455    return 0; 
    14551456} 
     
    26082609    ++ap_my_generation; 
    26092610    ap_scoreboard_image->global->running_generation = ap_my_generation; 
    26102611     
     2612    /* cleanup sockets */ 
     2613    for (i = 0; i < NUM_SENV; i++) { 
     2614        close(SENV[i].input); 
     2615        close(SENV[i].output); 
     2616    } 
     2617 
    26112618    if (is_graceful) { 
    26122619        char char_of_death = AP_PERUSER_CHAR_OF_DEATH; 
    26132620 
     
    26962703        } 
    26972704        _DBG("Total children of %d leaving behind for graceful restart (%d living)",  
    26982705                       grace_children, grace_children_alive); 
    2699  
    2700        /* destroy server_env_image */ 
    2701         for (i = 0; i < NUM_SENV; i++) 
    2702         { 
    2703             close(SENV[i].input); 
    2704             close(SENV[i].output); 
    2705         } 
    2706        cleanup_server_environments(NULL); 
    27072706    } 
    27082707    else { 
    27092708        /* Kill 'em off */ 
     
    28612860        return rv; 
    28622861    } 
    28632862 
     2863    if (!child_info_image) { 
     2864        _DBG("Initializing child_info_table", 0); 
     2865        child_info_size = tmp_server_limit * sizeof(child_info_t) + sizeof(apr_size_t); 
    28642866 
    2865     _DBG("Initializing child_info_table", 0); 
    2866     child_info_size = tmp_server_limit * sizeof(child_info_t) + sizeof(apr_size_t); 
     2867        rv = apr_shm_create(&child_info_shm, child_info_size, NULL, global_pool); 
    28672868 
    2868     rv = apr_shm_create(&child_info_shm, child_info_size, NULL, global_pool); 
     2869        /*  if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) { */ 
     2870        if (rv != APR_SUCCESS) { 
     2871            _DBG("shared memory creation failed", 0); 
    28692872 
    2870 /*  if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) { */ 
    2871     if (rv != APR_SUCCESS) { 
    2872         _DBG("shared memory creation failed", 0); 
     2873            ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, 
     2874                         "Unable to create shared memory segment " 
     2875                         "(anonymous shared memory failure)"); 
     2876        } 
     2877        else if (rv == APR_ENOTIMPL) { 
     2878            _DBG("anonymous shared memory not available", 0); 
     2879            /* TODO: make up a filename and do name-based shmem */ 
     2880        } 
    28732881 
    2874         ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, 
    2875                      "Unable to create shared memory segment " 
    2876                      "(anonymous shared memory failure)"); 
    2877     } 
    2878     else if (rv == APR_ENOTIMPL) { 
    2879         _DBG("anonymous shared memory not available", 0); 
    2880         /* TODO: make up a filename and do name-based shmem */ 
    2881     } 
     2882        if (rv || !(shmem = apr_shm_baseaddr_get(child_info_shm))) { 
     2883            _DBG("apr_shm_baseaddr_get() failed", 0); 
     2884            return HTTP_INTERNAL_SERVER_ERROR; 
     2885        } 
    28822886 
    2883     if (rv || !(shmem = apr_shm_baseaddr_get(child_info_shm))) { 
    2884         _DBG("apr_shm_baseaddr_get() failed", 0); 
    2885         return HTTP_INTERNAL_SERVER_ERROR; 
     2887        memset(shmem, 0, child_info_size); 
     2888        child_info_image = (child_info*)apr_palloc(global_pool, sizeof(child_info)); 
     2889        child_info_image->control = (child_info_control*)shmem; 
     2890        shmem += sizeof(child_info_control); 
     2891        child_info_image->table = (child_info_t*)shmem; 
    28862892    } 
    28872893 
    2888     memset(shmem, 0, sizeof(child_info_size)); 
    2889     child_info_image = (child_info*)calloc(1, sizeof(child_info_size)); 
    2890     child_info_image->control = (child_info_control*)shmem; 
    2891     shmem += sizeof(child_info_control*); 
    2892     child_info_image->table = (child_info_t*)shmem; 
    2893  
     2894    _DBG("Clearing child_info_table"); 
    28942895    child_info_image->control->num = 0; 
    28952896 
    2896     for (i = 0; i < tmp_server_limit; i++) 
    2897     { 
     2897    for (i = 0; i < tmp_server_limit; i++) { 
    28982898        CHILD_INFO_TABLE[i].pid     = 0; 
    28992899        CHILD_INFO_TABLE[i].senv    = (server_env_t*)NULL; 
    29002900        CHILD_INFO_TABLE[i].type    = CHILD_TYPE_UNKNOWN; 
     
    29272927            return HTTP_INTERNAL_SERVER_ERROR; 
    29282928        } 
    29292929 
    2930         memset(shmem, 0, sizeof(server_env_size)); 
    2931         server_env_image = (server_env*)calloc(1, sizeof(server_env_size)); 
     2930        memset(shmem, 0, server_env_size); 
     2931        server_env_image = (server_env*)apr_palloc(global_pool, sizeof(server_env)); 
    29322932        server_env_image->control = (server_env_control*)shmem; 
    2933         shmem += sizeof(server_env_control*); 
     2933        shmem += sizeof(server_env_control); 
    29342934        server_env_image->table = (server_env_t*)shmem; 
    29352935    } 
    2936  
    2937     if(restart_num <= 2) { 
    2938         _DBG("Cleaning server environments table"); 
    29392936     
    2940         server_env_image->control->num = 0; 
    2941         for (i = 0; i < tmp_server_limit; i++) { 
    2942             SENV[i].processor_id = -1; 
    2943             SENV[i].uid          = -1; 
    2944             SENV[i].gid          = -1; 
    2945             SENV[i].chroot       = NULL; 
    2946             SENV[i].input        = -1; 
    2947             SENV[i].output       = -1; 
    2948         } 
     2937    _DBG("Clearing server environment table"); 
     2938    server_env_image->control->num = 0;     
     2939 
     2940    for (i = 0; i < tmp_server_limit; i++) { 
     2941        SENV[i].processor_id = -1; 
     2942        SENV[i].uid          = -1; 
     2943        SENV[i].gid          = -1; 
     2944        SENV[i].chroot       = NULL; 
     2945        SENV[i].input        = -1; 
     2946        SENV[i].output       = -1; 
    29492947    } 
    29502948 
    29512949    return OK; 
     
    31963194                            "Error: Directive %s> takes one argument", cmd->cmd->name); 
    31973195    } 
    31983196 
    3199     /*  Check for existing processors on first launch and between gracefuls */ 
    3200     if (restart_num == 1 || is_graceful) { 
    3201         server_env_t *old_senv = find_senv_by_name(senv.name); 
     3197    server_env_t *old_senv = find_senv_by_name(senv.name); 
    32023198 
    3203         if (old_senv) { 
    3204             return apr_psprintf(cmd->temp_pool, 
    3205                                 "Error: Processor %s already defined", senv.name); 
    3206         } 
     3199    if (old_senv) { 
     3200        return apr_psprintf(cmd->temp_pool, 
     3201                            "Error: Processor %s already defined", senv.name); 
    32073202    } 
    32083203 
    32093204    senv.nice_lvl               = 0;