Author: glen                         Date: Mon Jul 14 15:49:39 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- update to r2199:
  - merge spawn-fcgi changes from trunk (from @2191)
  - let spawn-fcgi propagate exit code from spawned fcgi application

---- Files affected:
SOURCES:
   lighttpd-branch.diff (1.36 -> 1.37) 

---- Diffs:

================================================================
Index: SOURCES/lighttpd-branch.diff
diff -u SOURCES/lighttpd-branch.diff:1.36 SOURCES/lighttpd-branch.diff:1.37
--- SOURCES/lighttpd-branch.diff:1.36   Tue Jun 17 18:10:03 2008
+++ SOURCES/lighttpd-branch.diff        Mon Jul 14 17:49:34 2008
@@ -1,7 +1,7 @@
 Index: lighttpd.spec.in
 ===================================================================
---- lighttpd.spec.in   (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ lighttpd.spec.in   (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- lighttpd.spec.in   (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ lighttpd.spec.in   (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -1,83 +0,0 @@
 -Summary: A fast webserver with minimal memory-footprint (lighttpd)
 -Name: lighttpd
@@ -90,8 +90,8 @@
 ===================================================================
 Index: src/mod_ssi_exprparser.h
 ===================================================================
---- src/mod_ssi_exprparser.h   (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_ssi_exprparser.h   (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_ssi_exprparser.h   (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_ssi_exprparser.h   (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -1,12 +0,0 @@
 -#define TK_AND                             1
 -#define TK_OR                              2
@@ -107,8 +107,8 @@
 -#define TK_VALUE                          12
 Index: src/configfile-glue.c
 ===================================================================
---- src/configfile-glue.c      (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/configfile-glue.c      (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/configfile-glue.c      (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/configfile-glue.c      (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -529,7 +529,7 @@
  int config_append_cond_match_buffer(connection *con, data_config *dc, buffer 
*buf, int n)
  {
@@ -120,8 +120,8 @@
  
 Index: src/mod_cgi.c
 ===================================================================
---- src/mod_cgi.c      (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_cgi.c      (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_cgi.c      (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_cgi.c      (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -987,6 +987,8 @@
                        *c = '/';
                }
@@ -173,8 +173,8 @@
                                chunkqueue_remove_finished_chunks(cq);
 Index: src/mod_rewrite.c
 ===================================================================
---- src/mod_rewrite.c  (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_rewrite.c  (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_rewrite.c  (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_rewrite.c  (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -385,8 +385,7 @@
  
                        start = 0; end = pattern_len;
@@ -199,8 +199,8 @@
                                                        
buffer_append_string(con->request.uri, list[num]);
 Index: src/lempar.c
 ===================================================================
---- src/lempar.c       (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/lempar.c       (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/lempar.c       (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/lempar.c       (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -210,7 +210,7 @@
  */
  const char *ParseTokenName(int tokenType){
@@ -248,8 +248,8 @@
  %%
 Index: src/connections.c
 ===================================================================
---- src/connections.c  (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/connections.c  (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/connections.c  (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/connections.c  (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -199,6 +199,7 @@
  
        /* don't resize the buffer if we were in SSL_ERROR_WANT_* */
@@ -423,8 +423,8 @@
                        switch(con->mode) {
 Index: src/configfile.c
 ===================================================================
---- src/configfile.c   (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/configfile.c   (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/configfile.c   (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/configfile.c   (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -7,6 +7,7 @@
  #include <string.h>
  #include <stdio.h>
@@ -517,8 +517,8 @@
  
 Index: src/lemon.c
 ===================================================================
---- src/lemon.c        (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/lemon.c        (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/lemon.c        (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/lemon.c        (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -12,6 +12,19 @@
  #include <ctype.h>
  #include <stdlib.h>
@@ -601,8 +601,8 @@
    size_t filesize;
 Index: src/mod_scgi.c
 ===================================================================
---- src/mod_scgi.c     (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_scgi.c     (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_scgi.c     (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_scgi.c     (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -202,6 +202,15 @@
         *
         */
@@ -875,8 +875,8 @@
  
 Index: src/lighttpd-angel.c
 ===================================================================
---- src/lighttpd-angel.c       (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/lighttpd-angel.c       (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/lighttpd-angel.c       (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/lighttpd-angel.c       (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -28,9 +28,12 @@
  static volatile sig_atomic_t graceful_restart = 0;
  static volatile pid_t pid = -1;
@@ -901,8 +901,8 @@
         */
 Index: src/mod_rrdtool.c
 ===================================================================
---- src/mod_rrdtool.c  (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_rrdtool.c  (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_rrdtool.c  (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_rrdtool.c  (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -148,6 +148,8 @@
                args[i++] = dash;
                args[i++] = NULL;
@@ -923,8 +923,8 @@
                SEGFAULT();
 Index: src/response.c
 ===================================================================
---- src/response.c     (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/response.c     (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/response.c     (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/response.c     (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -101,7 +101,7 @@
        if (!have_server) {
                if (buffer_is_empty(con->conf.server_tag)) {
@@ -945,8 +945,8 @@
                        log_error_write(srv, __FILE__, __LINE__,  "s",  "run 
condition");
 Index: src/plugin.c
 ===================================================================
---- src/plugin.c       (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/plugin.c       (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/plugin.c       (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/plugin.c       (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -197,7 +197,7 @@
  
  #else
@@ -958,8 +958,8 @@
  #endif
 Index: src/SConscript
 ===================================================================
---- src/SConscript     (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/SConscript     (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/SConscript     (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/SConscript     (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -43,6 +43,7 @@
        'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] },
        'mod_fastcgi' : { 'src' : [ 'mod_fastcgi.c' ] },
@@ -970,8 +970,8 @@
        'mod_indexfile' : { 'src' : [ 'mod_indexfile.c' ] },
 Index: src/mod_extforward.c
 ===================================================================
---- src/mod_extforward.c       (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_extforward.c       (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_extforward.c       (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_extforward.c       (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -281,8 +281,9 @@
  static const char *last_not_in_array(array *a, plugin_data *p)
  {
@@ -985,8 +985,8 @@
  
 Index: src/Makefile.am
 ===================================================================
---- src/Makefile.am    (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/Makefile.am    (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/Makefile.am    (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/Makefile.am    (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -16,20 +16,17 @@
  configparser.c configparser.h:
  mod_ssi_exprparser.c mod_ssi_exprparser.h:
@@ -1014,8 +1014,8 @@
        keyvalue.c chunk.c  \
 Index: src/network_openssl.c
 ===================================================================
---- src/network_openssl.c      (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/network_openssl.c      (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/network_openssl.c      (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/network_openssl.c      (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -85,6 +85,7 @@
                         *
                         */
@@ -1034,8 +1034,8 @@
  
 Index: src/mod_redirect.c
 ===================================================================
---- src/mod_redirect.c (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_redirect.c (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_redirect.c (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_redirect.c (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -215,8 +215,7 @@
  
                        start = 0; end = pattern_len;
@@ -1060,8 +1060,8 @@
                                                        
buffer_append_string(p->location, list[num]);
 Index: src/mod_webdav.c
 ===================================================================
---- src/mod_webdav.c   (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_webdav.c   (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_webdav.c   (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_webdav.c   (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -570,6 +570,8 @@
                                /* */
                        }
@@ -1102,8 +1102,8 @@
        return has_lock;
 Index: src/md5.c
 ===================================================================
---- src/md5.c  (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/md5.c  (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/md5.c  (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/md5.c  (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -52,9 +52,9 @@
  #define S43 15
  #define S44 21
@@ -1152,8 +1152,8 @@
    unsigned int i, j;
 Index: src/mod_compress.c
 ===================================================================
---- src/mod_compress.c (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/mod_compress.c (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/mod_compress.c (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/mod_compress.c (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -102,7 +102,7 @@
        return HANDLER_GO_ON;
  }
@@ -1201,8 +1201,8 @@
                                                s->compress_cache_dir, 
strerror(errno));
 Index: src/md5.h
 ===================================================================
---- src/md5.h  (.../tags/lighttpd-1.4.19)      (revision 2190)
-+++ src/md5.h  (.../branches/lighttpd-1.4.x)   (revision 2190)
+--- src/md5.h  (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/md5.h  (.../branches/lighttpd-1.4.x)   (revision 2199)
 @@ -42,6 +42,6 @@
  } MD5_CTX;
  
@@ -1211,10 +1211,405 @@
 +void MD5_Update (MD5_CTX *, const void *, unsigned int);
  void MD5_Final (unsigned char [16], MD5_CTX *);
  
+Index: src/spawn-fcgi.c
+===================================================================
+--- src/spawn-fcgi.c   (.../tags/lighttpd-1.4.19)      (revision 2199)
++++ src/spawn-fcgi.c   (.../branches/lighttpd-1.4.x)   (revision 2199)
+@@ -37,9 +37,9 @@
+ #endif
+ 
+ #ifdef HAVE_SYS_UN_H
+-int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned 
short port, const char *unixsocket, int child_count, int pid_fd, int nofork) {
++int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned 
short port, const char *unixsocket, int fork_count, int child_count, int 
pid_fd, int nofork) {
+       int fcgi_fd;
+-      int socket_type, status;
++      int socket_type, status, rc = 0;
+       struct timeval tv = { 0, 100 * 1000 };
+ 
+       struct sockaddr_un fcgi_addr_un;
+@@ -48,9 +48,6 @@
+ 
+       socklen_t servlen;
+ 
+-      pid_t child;
+-      int val;
+-
+       if (child_count < 2) {
+               child_count = 5;
+       }
+@@ -74,25 +71,6 @@
+ #endif
+               socket_type = AF_UNIX;
+               fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
+-
+-              /* check if some backend is listening on the socket
+-               * as if we delete the socket-file and rebind there will be no 
"socket already in use" error
+-               */
+-              if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
+-                      fprintf(stderr, "%s.%d\n",
+-                              __FILE__, __LINE__);
+-                      return -1;
+-              }
+-
+-              if (-1 != connect(fcgi_fd, fcgi_addr, servlen)) {
+-                      fprintf(stderr, "%s.%d: socket is already used, can't 
spawn\n",
+-                              __FILE__, __LINE__);
+-                      return -1;
+-              }
+-
+-              /* cleanup previous socket if it exists */
+-              unlink(unixsocket);
+-              close(fcgi_fd);
+       } else {
+               fcgi_addr_in.sin_family = AF_INET;
+                 if (addr != NULL) {
+@@ -107,133 +85,176 @@
+               fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
+       }
+ 
+-      /* open socket */
+       if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
+               fprintf(stderr, "%s.%d\n",
+                       __FILE__, __LINE__);
+               return -1;
+       }
+ 
+-      val = 1;
+-      if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 
0) {
+-              fprintf(stderr, "%s.%d\n",
+-                      __FILE__, __LINE__);
+-              return -1;
+-      }
++      if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) {
++              /* server is not up, spawn in  */
++              pid_t child;
++              int val;
+ 
+-      /* create socket */
+-      if (-1 == bind(fcgi_fd, fcgi_addr, servlen)) {
+-              fprintf(stderr, "%s.%d: bind failed: %s\n",
+-                      __FILE__, __LINE__,
+-                      strerror(errno));
+-              return -1;
+-      }
++              if (unixsocket) unlink(unixsocket);
+ 
+-      if (-1 == listen(fcgi_fd, 1024)) {
+-              fprintf(stderr, "%s.%d: fd = -1\n",
+-                      __FILE__, __LINE__);
+-              return -1;
+-      }
++              close(fcgi_fd);
+ 
+-      if (!nofork) {
+-              child = fork();
+-      } else {
+-              child = 0;
+-      }
++              /* reopen socket */
++              if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
++                      fprintf(stderr, "%s.%d\n",
++                              __FILE__, __LINE__);
++                      return -1;
++              }
+ 
+-      switch (child) {
+-      case 0: {
+-              char cgi_childs[64];
++              val = 1;
++              if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, 
sizeof(val)) < 0) {
++                      fprintf(stderr, "%s.%d\n",
++                              __FILE__, __LINE__);
++                      return -1;
++              }
+ 
+-              int i = 0;
+-
+-              /* is safe as we limit to 256 childs */
+-              sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", child_count);
+-
+-              if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
+-                      close(FCGI_LISTENSOCK_FILENO);
+-                      dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
+-                      close(fcgi_fd);
++              /* create socket */
++              if (-1 == bind(fcgi_fd, fcgi_addr, servlen)) {
++                      fprintf(stderr, "%s.%d: bind failed: %s\n",
++                              __FILE__, __LINE__,
++                              strerror(errno));
++                      return -1;
+               }
+ 
+-              /* we don't need the client socket */
+-              for (i = 3; i < 256; i++) {
+-                      close(i);
++              if (-1 == listen(fcgi_fd, 1024)) {
++                      fprintf(stderr, "%s.%d: fd = -1\n",
++                              __FILE__, __LINE__);
++                      return -1;
+               }
+ 
+-              /* create environment */
++              while (fork_count-- > 0) {
+ 
+-              putenv(cgi_childs);
++                      if (!nofork) {
++                              child = fork();
++                      } else {
++                              child = 0;
++                      }
+ 
+-              /* fork and replace shell */
+-              if (appArgv) {
+-                      execv(appArgv[0], appArgv);
++                      switch (child) {
++                      case 0: {
++                              char cgi_childs[64];
++                              int max_fd = 0;
+ 
+-              } else {
+-                      char *b = malloc(strlen("exec ") + strlen(appPath) + 1);
+-                      strcpy(b, "exec ");
+-                      strcat(b, appPath);
++                              int i = 0;
+ 
+-                      /* exec the cgi */
+-                      execl("/bin/sh", "sh", "-c", b, (char *)NULL);
+-              }
++                              /* loose control terminal */
++                              setsid();
+ 
+-              exit(errno);
++                              /* is safe as we limit to 256 childs */
++                              sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", 
child_count);
+ 
+-              break;
+-      }
+-      case -1:
+-              /* error */
+-              break;
+-      default:
+-              /* father */
++                              if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
++                                      close(FCGI_LISTENSOCK_FILENO);
++                                      dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
++                                      close(fcgi_fd);
++                              }
+ 
+-              /* wait */
+-              select(0, NULL, NULL, NULL, &tv);
++                              max_fd = open("/dev/null", O_RDWR);
++                              close(STDERR_FILENO);
++                              dup2(max_fd, STDERR_FILENO);
++                              close(max_fd);
+ 
+-              switch (waitpid(child, &status, WNOHANG)) {
+-              case 0:
+-                      fprintf(stderr, "%s.%d: child spawned successfully: 
PID: %d\n",
+-                              __FILE__, __LINE__,
+-                              child);
++                              max_fd = open("/dev/null", O_RDWR);
++                              close(STDOUT_FILENO);
++                              dup2(max_fd, STDOUT_FILENO);
++                              close(max_fd);
+ 
+-                      /* write pid file */
+-                      if (pid_fd != -1) {
+-                              /* assume a 32bit pid_t */
+-                              char pidbuf[12];
++                              /* we don't need the client socket */
++                              for (i = 3; i < max_fd; i++) {
++                                      if (i != FCGI_LISTENSOCK_FILENO) 
close(i);
++                              }
+ 
+-                              snprintf(pidbuf, sizeof(pidbuf) - 1, "%d", 
child);
++                              /* create environment */
+ 
+-                              write(pid_fd, pidbuf, strlen(pidbuf));
+-                              close(pid_fd);
+-                              pid_fd = -1;
++                              putenv(cgi_childs);
++
++                              /* fork and replace shell */
++                              if (appArgv) {
++                                      execv(appArgv[0], appArgv);
++
++                              } else {
++                                      char *b = malloc(strlen("exec ") + 
strlen(appPath) + 1);
++                                      strcpy(b, "exec ");
++                                      strcat(b, appPath);
++
++                                      /* exec the cgi */
++                                      execl("/bin/sh", "sh", "-c", b, (char 
*)NULL);
++                              }
++
++                              exit(errno);
++
++                              break;
+                       }
++                      case -1:
++                              /* error */
++                              break;
++                      default:
++                              /* father */
+ 
+-                      break;
+-              case -1:
+-                      break;
+-              default:
+-                      if (WIFEXITED(status)) {
+-                              fprintf(stderr, "%s.%d: child exited with: %d, 
%s\n",
+-                                      __FILE__, __LINE__,
+-                                      WEXITSTATUS(status), 
strerror(WEXITSTATUS(status)));
+-                      } else if (WIFSIGNALED(status)) {
+-                              fprintf(stderr, "%s.%d: child signaled: %d\n",
+-                                      __FILE__, __LINE__,
+-                                      WTERMSIG(status));
+-                      } else {
+-                              fprintf(stderr, "%s.%d: child died somehow: 
%d\n",
+-                                      __FILE__, __LINE__,
+-                                      status);
++                              /* wait */
++                              select(0, NULL, NULL, NULL, &tv);
++
++                              switch (waitpid(child, &status, WNOHANG)) {
++                              case 0:
++                                      fprintf(stdout, "%s.%d: child spawned 
successfully: PID: %d\n",
++                                              __FILE__, __LINE__,
++                                              child);
++
++                                      /* write pid file */
++                                      if (pid_fd != -1) {
++                                              /* assume a 32bit pid_t */
++                                              char pidbuf[12];
++
++                                              snprintf(pidbuf, sizeof(pidbuf) 
- 1, "%d", child);
++
++                                              write(pid_fd, pidbuf, 
strlen(pidbuf));
++                                              /* avoid eol for the last one */
++                                              if (fork_count != 0) {
++                                                      write(pid_fd, "\n", 1);
++                                              }
++                                      }
++
++                                      break;
++                              case -1:
++                                      break;
++                              default:
++                                      if (WIFEXITED(status)) {
++                                              fprintf(stderr, "%s.%d: child 
exited with: %d\n",
++                                                      __FILE__, __LINE__, 
WEXITSTATUS(status));
++                                              rc = WEXITSTATUS(status);
++                                      } else if (WIFSIGNALED(status)) {
++                                              fprintf(stderr, "%s.%d: child 
signaled: %d\n",
++                                                      __FILE__, __LINE__,
++                                                      WTERMSIG(status));
++                                              rc = 1;
++                                      } else {
++                                              fprintf(stderr, "%s.%d: child 
died somehow: %d\n",
++                                                      __FILE__, __LINE__,
++                                                      status);
++                                              rc = status;
++                                      }
++                              }
++
++                              break;
+                       }
+               }
+-
+-              break;
++              close(pid_fd);
++              pid_fd = -1;
++      } else {
++              fprintf(stderr, "%s.%d: socket is already used, can't spawn\n",
++                      __FILE__, __LINE__);
++              return -1;
+       }
+ 
+       close(fcgi_fd);
+ 
+-      return 0;
++      return rc;
+ }
+ 
+ 
+@@ -256,6 +277,7 @@
+ " -p <port>    bind to tcp-port\n" \
+ " -s <path>    bind to unix-domain socket\n" \
+ " -C <childs>  (PHP only) numbers of childs to spawn (default 5)\n" \
++" -F <childs>  numbers of childs to fork (default 1)\n" \
+ " -P <path>    name of PID-file for spawed process\n" \
+ " -n           no fork (for daemontools)\n" \
+ " -v           show version\n" \
+@@ -276,20 +298,21 @@
+       char **fcgi_app_argv = { NULL };
+       unsigned short port = 0;
+       int child_count = 5;
++      int fork_count = 1;
+       int i_am_root, o;
<<Diff was trimmed, longer than 597 lines>>

---- CVS-web:
    
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/lighttpd-branch.diff?r1=1.36&r2=1.37&f=u

_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to