Hello,

Sean Gabriel Heacock wrote:
and of course if more patches come
in from you guys.


New patches :)

1. peruser-0.3.0rc2-senv1.patch remove line N 1899:

server_env_image->control->num++;

in function child_add() because of senv_add(uid, gid, chroot) do it before 
return -
function senv_add(), line 1825

2. peruser-0.3.0rc2-senv2.patch add check for server_env_image structure.
This structure creates twice at startup.

I added function dump_server_env_image() for debug (not included in patch):
void dump_server_env_image()
{
   int x;
   _DBG("%-3s %-7s %-7s", "N", "INPUT", "OUTPUT");
   for(x = 0; x < NUM_SENV; x++)
   {
     _DBG("%-3d %-7d %-7d", x, SENV[x].input, SENV[x].output);
   }
}

and call it here:
static int make_child(server_rec *s, int slot)
{
...
     _DBG("function entered", 0);
     dump_server_env_image();

Without this patch you can see different output after
startup in console and error_log.

3. peruser-0.3.0rc2-senv3.patch perform open file descriptors cleanup
at startup new child.

4. Test:

a) add 5-10 users in system and make 5-10 virtual hosts (and processors):
<VirtualHost *:80>
         ServerName user0.example.com
         DocumentRoot /home/user0
         ServerEnvironment user0 user0
</VirtualHost>
...
<VirtualHost *:80>
         ServerName user9.example.com
         DocumentRoot /home/user9
         ServerEnvironment user9 user9
</VirtualHost>

b) make "test.cgi" script:
#!/bin/sh
echo "Content-type: text/plain"
echo
ls -la /proc/self/fd

and put it into /cgi-bin/ directory of any virtual host

c) make request to this script with and without my patches.
you will see result :)


diff -Nru httpd-2.0.61-a/server/mpm/experimental/peruser/peruser.c httpd-2.0.61-b/server/mpm/experimental/peruser/peruser.c
--- httpd-2.0.61-a/server/mpm/experimental/peruser/peruser.c	2007-10-02 18:20:16.714387209 +0300
+++ httpd-2.0.61-b/server/mpm/experimental/peruser/peruser.c	2007-10-02 18:19:50.870901208 +0300
@@ -1896,7 +1896,6 @@
         _DBG("Assigning root user/group to a child.", 0);
     }
 
-    server_env_image->control->num++;
     child_info_image->control->num++;
 
     return NULL;

diff -Nru httpd-2.0.61-b/server/mpm/experimental/peruser/peruser.c httpd-2.0.61-c/server/mpm/experimental/peruser/peruser.c
--- httpd-2.0.61-b/server/mpm/experimental/peruser/peruser.c	2007-10-02 19:36:07.000000000 +0300
+++ httpd-2.0.61-c/server/mpm/experimental/peruser/peruser.c	2007-10-02 19:39:13.661903634 +0300
@@ -311,7 +311,7 @@
 #define CHILD_INFO_TABLE (child_info_image != NULL ? child_info_image->table : NULL)
 
 static apr_size_t server_env_size;
-static server_env *server_env_image;
+static server_env *server_env_image = NULL;
 
 #define NUM_SENV (server_env_image != NULL ? server_env_image->control->num : 0)
 #define SENV (server_env_image != NULL ? server_env_image->table : NULL)
@@ -2663,44 +2663,47 @@
         CHILD_INFO_TABLE[i].id      = i;
     }
 
-    _DBG("Initializing server_environments_table", 0);
-    server_env_size = tmp_server_limit * sizeof(server_env_t) + sizeof(apr_size_t);
+    if (!server_env_image)
+    {
+	_DBG("Initializing server_environments_table", 0);
+	server_env_size = tmp_server_limit * sizeof(server_env_t) + sizeof(apr_size_t);
 
-    rv = apr_shm_create(&server_env_shm, server_env_size, NULL, global_pool);
+	rv = apr_shm_create(&server_env_shm, server_env_size, NULL, global_pool);
 
-    if (rv != APR_SUCCESS) {
-        _DBG("shared memory creation failed", 0);
+	if (rv != APR_SUCCESS) {
+    	    _DBG("shared memory creation failed", 0);
 
-        ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
-                     "Unable to create shared memory segment "
-                     "(anonymous shared memory failure)");
-    }
-    else if (rv == APR_ENOTIMPL) {
-        _DBG("anonymous shared memory not available", 0);
-        /* TODO: make up a filename and do name-based shmem */
-    }
+    	    ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
+                	 "Unable to create shared memory segment "
+                	 "(anonymous shared memory failure)");
+        }
+        else if (rv == APR_ENOTIMPL) {
+            _DBG("anonymous shared memory not available", 0);
+            /* TODO: make up a filename and do name-based shmem */
+        }
 
-    if (rv || !(shmem = apr_shm_baseaddr_get(server_env_shm))) {
-        _DBG("apr_shm_baseaddr_get() failed", 0);
-        return HTTP_INTERNAL_SERVER_ERROR;
-    }
+        if (rv || !(shmem = apr_shm_baseaddr_get(server_env_shm))) {
+            _DBG("apr_shm_baseaddr_get() failed", 0);
+            return HTTP_INTERNAL_SERVER_ERROR;
+        }
 
-    memset(shmem, 0, sizeof(server_env_size));
-    server_env_image = (server_env*)calloc(1, sizeof(server_env_size));
-    server_env_image->control = (server_env_control*)shmem;
-    shmem += sizeof(server_env_control*);
-    server_env_image->table = (server_env_t*)shmem;
+        memset(shmem, 0, sizeof(server_env_size));
+        server_env_image = (server_env*)calloc(1, sizeof(server_env_size));
+        server_env_image->control = (server_env_control*)shmem;
+        shmem += sizeof(server_env_control*);
+        server_env_image->table = (server_env_t*)shmem;
 
-    server_env_image->control->num = 0;
+        server_env_image->control->num = 0;
 
-    for (i = 0; i < tmp_server_limit; i++)
-    {
-        SENV[i].processor_id = -1;
-        SENV[i].uid          = -1;
-        SENV[i].gid          = -1;
-        SENV[i].chroot       = NULL;
-        SENV[i].input        = -1;
-        SENV[i].output       = -1;
+        for (i = 0; i < tmp_server_limit; i++)
+        {
+            SENV[i].processor_id = -1;
+            SENV[i].uid          = -1;
+            SENV[i].gid          = -1;
+            SENV[i].chroot       = NULL;
+            SENV[i].input        = -1;
+            SENV[i].output       = -1;
+        }
     }
 
     return OK;
diff -Nru httpd-2.0.61-c/server/mpm/experimental/peruser/peruser.c httpd-2.0.61-d/server/mpm/experimental/peruser/peruser.c
--- httpd-2.0.61-c/server/mpm/experimental/peruser/peruser.c	2007-10-02 18:43:38.724638956 +0300
+++ httpd-2.0.61-d/server/mpm/experimental/peruser/peruser.c	2007-10-02 19:03:05.064437666 +0300
@@ -369,6 +369,7 @@
 
 int grace_children = 0;
 int grace_children_alive = 0;
+int server_env_cleanup = 1;
 
 #ifdef GPROF
 /* 
@@ -2792,6 +2793,33 @@
             _DBG("%s %d", child_type_string(CHILD_INFO_TABLE[my_child_num].type), my_child_num);
             _DBG("request for %s / (server %s) seems to be for us", r->hostname, r->server->server_hostname);
 
+            if (server_env_cleanup)
+            {
+                int i;
+                int input = sconf->senv->input;
+                int output = sconf->senv->output;
+
+                _DBG("performing handle cleanup");
+                for (i = 0; i < NUM_SENV; i++)
+                {
+                    if (SENV[i].input > 0 && SENV[i].input != input) {
+                        int retval = close(SENV[i].input);
+                        if (retval < 0) {
+                            ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
+                                         "close(%d) failed", SENV[i].input);
+                        }
+                    }
+                    if (SENV[i].output > 0 && SENV[i].output != output) {
+                        int retval = close(SENV[i].output);
+                        if (retval < 0) {
+                            ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
+                                         "close(%d) failed", SENV[i].output);
+                        }
+                    }
+                }
+                server_env_cleanup = 0;
+            }
+
             return OK;
         }
         default:
_______________________________________________
Peruser mailing list
[email protected]
http://www.telana.com/mailman/listinfo/peruser

Reply via email to