httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r383774 - /httpd/httpd/branches/fcgi-proxy-dev/support/fcgistarter.c
Date Tue, 07 Mar 2006 04:37:03 GMT
Author: rooneg
Date: Mon Mar  6 20:37:02 2006
New Revision: 383774

URL: http://svn.apache.org/viewcvs?rev=383774&view=rev
Log:
Add support for starting multiple fastcgi processes listening on a
given socket.  This somewhat makes up for our lack of a good way to
manage connections to a given proxy backend.

* support/fcgistarter.c
  (main): Accept a new -N option that controls how many child procs
   we fork off.

Modified:
    httpd/httpd/branches/fcgi-proxy-dev/support/fcgistarter.c

Modified: httpd/httpd/branches/fcgi-proxy-dev/support/fcgistarter.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/branches/fcgi-proxy-dev/support/fcgistarter.c?rev=383774&r1=383773&r2=383774&view=diff
==============================================================================
--- httpd/httpd/branches/fcgi-proxy-dev/support/fcgistarter.c (original)
+++ httpd/httpd/branches/fcgi-proxy-dev/support/fcgistarter.c Mon Mar  6 20:37:02 2006
@@ -29,12 +29,14 @@
 #include <unistd.h> /* For execl */
 #endif
 
+static const char *usage_message =
+    "usage: fcgistarter -c <command> -p <port> [-i <interface> -N <num>]\n"
+    "\n"
+    "If an interface is not specified, any available will be used.\n";
+
 static void usage()
 {
-    fprintf(stderr,
-            "usage: fcgistarter -c <command> -p <port> [-i <interface>]\n"
-            "\n"
-            "If an interface is not specified, any available will be used.\n");
+    fprintf(stderr, "%s", usage_message);
 
     exit(EXIT_FAILURE);
 }
@@ -64,9 +66,9 @@
 
 
     /* Command line arguments */
+    int num_to_start = 1, port = 0;
     const char *interface = NULL;
     const char *command = NULL;
-    int port = 0;
 
     apr_initialize();
 
@@ -83,7 +85,7 @@
         const char *arg;
         char opt;
 
-        rv = apr_getopt(gopt, "c:p:i:", &opt, &arg);
+        rv = apr_getopt(gopt, "c:p:i:N:", &opt, &arg);
         if (APR_STATUS_IS_EOF(rv)) {
             break;
         } else if (rv) {
@@ -105,6 +107,13 @@
                 interface = arg;
                 break;
 
+            case 'N':
+                num_to_start = atoi(arg);
+                if (! num_to_start) {
+                    usage();
+                }
+                break;
+
             default:
                 break;
             }
@@ -135,63 +144,68 @@
         exit_error(rv, "apr_socket_listen");
     }
 
-    rv = apr_proc_fork(&proc, pool);
-    if (rv == APR_INCHILD) {
-        apr_os_file_t oft = 0;
-        apr_os_sock_t oskt;
-
-        rv = apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
-        if (rv) {
-            exit_error(rv, "apr_proc_detach");
-        }
+    while (--num_to_start >= 0) {
+        rv = apr_proc_fork(&proc, pool);
+        if (rv == APR_INCHILD) {
+            apr_os_file_t oft = 0;
+            apr_os_sock_t oskt;
+
+            rv = apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
+            if (rv) {
+                exit_error(rv, "apr_proc_detach");
+            }
 
 #if defined(WIN32) || defined(OS2) || defined(NETWARE)
 #error "Please implement me."
 #else
-        /* Ok, so we need a file that has file descriptor 0 (which
-         * FastCGI wants), but points to our socket.  This isn't really
-         * possible in APR, so we cheat a bit.  I have no idea how to
-         * do this on a non-unix platform, so for now this is platform
-         * specific.  Ick.
-         *
-         * Note that this has to happen post-detach, otherwise fd 0
-         * gets closed during apr_proc_detach and it's all for nothing.
-         *
-         * Unfortunately, doing this post detach means we have no way
-         * to let anyone know if there's a problem at this point :( */
-
-        rv = apr_os_file_put(&infd, &oft, APR_READ | APR_WRITE, pool);
-        if (rv) {
-            exit(EXIT_FAILURE);
-        }
 
-        rv = apr_os_sock_get(&oskt, skt);
-        if (rv) {
-            exit(EXIT_FAILURE);
-        }
+            /* Ok, so we need a file that has file descriptor 0 (which
+             * FastCGI wants), but points to our socket.  This isn't really
+             * possible in APR, so we cheat a bit.  I have no idea how to
+             * do this on a non-unix platform, so for now this is platform
+             * specific.  Ick.
+             *
+             * Note that this has to happen post-detach, otherwise fd 0
+             * gets closed during apr_proc_detach and it's all for nothing.
+             *
+             * Unfortunately, doing this post detach means we have no way
+             * to let anyone know if there's a problem at this point :( */
+
+            rv = apr_os_file_put(&infd, &oft, APR_READ | APR_WRITE, pool);
+            if (rv) {
+                exit(EXIT_FAILURE);
+            }
 
-        rv = apr_os_file_put(&skwrapper, &oskt, APR_READ | APR_WRITE,
-                             pool);
-        if (rv) {
-            exit(EXIT_FAILURE);
-        }
+            rv = apr_os_sock_get(&oskt, skt);
+            if (rv) {
+                exit(EXIT_FAILURE);
+            }
 
-        rv = apr_file_dup2(infd, skwrapper, pool);
-        if (rv) {
-            exit(EXIT_FAILURE);
-        }
+            rv = apr_os_file_put(&skwrapper, &oskt, APR_READ | APR_WRITE,
+                                 pool);
+            if (rv) {
+                exit(EXIT_FAILURE);
+            }
 
-        /* XXX Can't use apr_proc_create because there's no way to get
-         *     infd into the procattr without going through another dup2,
-         *     which means by the time it gets to the fastcgi process it
-         *     is no longer fd 0, so it doesn't work.  Sigh. */
+            rv = apr_file_dup2(infd, skwrapper, pool);
+            if (rv) {
+                exit(EXIT_FAILURE);
+            }
+
+            /* XXX Can't use apr_proc_create because there's no way to get
+             *     infd into the procattr without going through another dup2,
+             *     which means by the time it gets to the fastcgi process it
+             *     is no longer fd 0, so it doesn't work.  Sigh. */
 
-        execl(command, NULL);
+            execl(command, NULL);
 #endif
-    } else if (rv == APR_INPARENT) {
-        apr_socket_close(skt);
-    } else {
-       exit_error(rv, "apr_proc_fork");
+        } else if (rv == APR_INPARENT) {
+            if (num_to_start == 0) {
+                apr_socket_close(skt);
+            }
+        } else {
+            exit_error(rv, "apr_proc_fork");
+        }
     }
 
     return EXIT_SUCCESS;



Mime
View raw message