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 320 320 * process. 321 321 */ 322 322 static apr_size_t child_info_size; 323 static child_info *child_info_image ;323 static child_info *child_info_image = NULL; 324 324 static child_grace_info_t *child_grace_info_table; 325 325 struct ap_ctable *ap_child_table; 326 326 … … 936 936 msg.msg_iovlen = 5; 937 937 938 938 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)); 940 940 cmsg->cmsg_level = SOL_SOCKET; 941 941 cmsg->cmsg_type = SCM_RIGHTS; 942 942 … … 1034 1034 ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "apr_os_sock_get"); 1035 1035 } 1036 1036 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); 1038 1038 _DBG("type=%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type), my_child_num); 1039 1039 1040 #ifdef _OSD_POSIX 1040 1041 if (sock_fd >= FD_SETSIZE) 1041 1042 { 1042 1043 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, … … 1048 1049 _DBG("child_num=%d: exiting with error", my_child_num); 1049 1050 return; 1050 1051 } 1052 #endif 1051 1053 1052 1054 if (CHILD_INFO_TABLE[my_child_num].sock_fd < 0) 1053 1055 { … … 1300 1302 msg.msg_iovlen = 5; 1301 1303 1302 1304 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)); 1304 1306 cmsg->cmsg_level = SOL_SOCKET; 1305 1307 cmsg->cmsg_type = SCM_RIGHTS; 1306 1308 … … 1309 1311 msg.msg_control = cmsg; 1310 1312 msg.msg_controllen = cmsg->cmsg_len; 1311 1313 1312 1313 1314 if (processor->status == CHILD_STATUS_STANDBY) 1314 1315 { 1315 1316 _DBG("Activating child #%d", processor->id); … … 1374 1375 iov[3].iov_len = HUGE_STRING_LEN; 1375 1376 1376 1377 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)); 1378 1379 1379 1380 msg.msg_name = NULL; 1380 1381 msg.msg_namelen = 0; … … 1424 1425 apr_cpystrn(headers, buff, header_len + 1); 1425 1426 _DBG("header_len=%d headers=\"%s\"", header_len, headers); 1426 1427 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); 1441 1433 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); 1442 1451 } else { 1443 _DBG(" There is no body",0);1452 _DBG("header_len == 0, we got a socket only", 0); 1444 1453 } 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 }1453 1454 _DBG("returning 0", 0); 1454 1455 return 0; 1455 1456 } … … 2608 2609 ++ap_my_generation; 2609 2610 ap_scoreboard_image->global->running_generation = ap_my_generation; 2610 2611 2612 /* cleanup sockets */ 2613 for (i = 0; i < NUM_SENV; i++) { 2614 close(SENV[i].input); 2615 close(SENV[i].output); 2616 } 2617 2611 2618 if (is_graceful) { 2612 2619 char char_of_death = AP_PERUSER_CHAR_OF_DEATH; 2613 2620 … … 2696 2703 } 2697 2704 _DBG("Total children of %d leaving behind for graceful restart (%d living)", 2698 2705 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);2707 2706 } 2708 2707 else { 2709 2708 /* Kill 'em off */ … … 2861 2860 return rv; 2862 2861 } 2863 2862 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); 2864 2866 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); 2867 2868 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); 2869 2872 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 } 2873 2881 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 } 2882 2886 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; 2886 2892 } 2887 2893 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"); 2894 2895 child_info_image->control->num = 0; 2895 2896 2896 for (i = 0; i < tmp_server_limit; i++) 2897 { 2897 for (i = 0; i < tmp_server_limit; i++) { 2898 2898 CHILD_INFO_TABLE[i].pid = 0; 2899 2899 CHILD_INFO_TABLE[i].senv = (server_env_t*)NULL; 2900 2900 CHILD_INFO_TABLE[i].type = CHILD_TYPE_UNKNOWN; … … 2927 2927 return HTTP_INTERNAL_SERVER_ERROR; 2928 2928 } 2929 2929 2930 memset(shmem, 0, s izeof(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)); 2932 2932 server_env_image->control = (server_env_control*)shmem; 2933 shmem += sizeof(server_env_control *);2933 shmem += sizeof(server_env_control); 2934 2934 server_env_image->table = (server_env_t*)shmem; 2935 2935 } 2936 2937 if(restart_num <= 2) {2938 _DBG("Cleaning server environments table");2939 2936 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; 2949 2947 } 2950 2948 2951 2949 return OK; … … 3196 3194 "Error: Directive %s> takes one argument", cmd->cmd->name); 3197 3195 } 3198 3196 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); 3202 3198 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); 3207 3202 } 3208 3203 3209 3204 senv.nice_lvl = 0;
