SOURCES: lighttpd-branch.diff - update to r2475: * Create rrd file for em...

glen glen at pld-linux.org
Thu Apr 16 23:25:05 CEST 2009


Author: glen                         Date: Thu Apr 16 21:25:05 2009 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- update to r2475:
  * Create rrd file for empty rrdfile in mod_rrdtool (#1788)
  * Fix workaround for incorrect path info/scriptname if fastcgi prefix is "/" (fixes #729)
  * Finally removed spawn-fcgi
  * Allow xattr to overwrite mime type (fixes #1929)
  * Remove link from errormsg about fastcgi apps (fixes #1942)
  * Strip trailing dot from "Host:" header
  * Remove the optional port info from SERVER_NAME (thx Mr_Bond)
  * Fix mod_proxy RoundRobin (off by one problem if only one backend is up)
  * Rename configure.in to configure.ac, with small cleanups (fixes #1932)
  * Add proper SUID bit detection (fixes #416)
  * Check for regular file in mod_cgi, so we don't try to start directories
  * Include mmap.h from chunk.h to fix some problems with #define mmap mmap64 (fixes #1923)
  * Add support for pipe logging for server.errorlog (fixes #296)
  * Add revision number to package version for svn/git checkouts
  * Use server.tag for SERVER_SOFTWARE if configured (fixes #357)
  * Fix trailing zero char in REQUEST_URI after "strip-request-uri" in mod_fastcgi
  * mod_magnet: Add env["request.remote-ip"] (fixes #1740)
  * mod_magnet: Add env["request.path-info"]
  * Change name/version separator back to "/" (affects every place where the version is printed)

---- Files affected:
SOURCES:
   lighttpd-branch.diff (1.48 -> 1.49) 

---- Diffs:

================================================================
Index: SOURCES/lighttpd-branch.diff
diff -u SOURCES/lighttpd-branch.diff:1.48 SOURCES/lighttpd-branch.diff:1.49
--- SOURCES/lighttpd-branch.diff:1.48	Mon Mar  9 00:09:27 2009
+++ SOURCES/lighttpd-branch.diff	Thu Apr 16 23:24:59 2009
@@ -1,9 +1,504 @@
 Index: configure.in
 ===================================================================
+Index: src/spawn-fcgi.c
+===================================================================
+--- src/spawn-fcgi.c	(.../tags/lighttpd-1.4.22)	(revision 2475)
++++ src/spawn-fcgi.c	(.../branches/lighttpd-1.4.x)	(revision 2475)
+@@ -1,481 +0,0 @@
+-#include <sys/types.h>
+-#include <sys/time.h>
+-#include <sys/stat.h>
+-
+-#include <stdlib.h>
+-#include <string.h>
+-#include <errno.h>
+-#include <stdio.h>
+-#include <unistd.h>
+-#include <fcntl.h>
+-
+-#ifdef HAVE_CONFIG_H
+-#include "config.h"
+-#endif
+-
+-
+-#ifdef HAVE_PWD_H
+-#include <grp.h>
+-#include <pwd.h>
+-#endif
+-
+-#ifdef HAVE_GETOPT_H
+-#include <getopt.h>
+-#endif
+-
+-#define FCGI_LISTENSOCK_FILENO 0
+-
+-#include "sys-socket.h"
+-
+-#ifdef HAVE_SYS_WAIT_H
+-#include <sys/wait.h>
+-#endif
+-
+-/* for solaris 2.5 and netbsd 1.3.x */
+-#ifndef HAVE_SOCKLEN_T
+-typedef int socklen_t;
+-#endif
+-
+-#ifdef HAVE_SYS_UN_H
+-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, rc = 0;
+-	struct timeval tv = { 0, 100 * 1000 };
+-
+-	struct sockaddr_un fcgi_addr_un;
+-	struct sockaddr_in fcgi_addr_in;
+-	struct sockaddr *fcgi_addr;
+-
+-	socklen_t servlen;
+-
+-	if (child_count < 2) {
+-		child_count = 5;
+-	}
+-
+-	if (child_count > 256) {
+-		child_count = 256;
+-	}
+-
+-
+-	if (unixsocket) {
+-		memset(&fcgi_addr_un, 0, sizeof(fcgi_addr_un));
+-
+-		fcgi_addr_un.sun_family = AF_UNIX;
+-		strcpy(fcgi_addr_un.sun_path, unixsocket);
+-
+-#ifdef SUN_LEN
+-		servlen = SUN_LEN(&fcgi_addr_un);
+-#else
+-		/* stevens says: */
+-		servlen = strlen(fcgi_addr_un.sun_path) + sizeof(fcgi_addr_un.sun_family);
+-#endif
+-		socket_type = AF_UNIX;
+-		fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
+-	} else {
+-		memset(&fcgi_addr_in, 0, sizeof(fcgi_addr_in));
+-		fcgi_addr_in.sin_family = AF_INET;
+-		if (addr != NULL) {
+-			fcgi_addr_in.sin_addr.s_addr = inet_addr(addr);
+-		} else {
+-			fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
+-		}
+-		fcgi_addr_in.sin_port = htons(port);
+-		servlen = sizeof(fcgi_addr_in);
+-
+-		socket_type = AF_INET;
+-		fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
+-	}
+-
+-	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)) {
+-		/* server is not up, spawn in  */
+-		pid_t child;
+-		int val;
+-
+-		if (unixsocket) unlink(unixsocket);
+-
+-		close(fcgi_fd);
+-
+-		/* reopen 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;
+-		}
+-
+-		/* 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 (-1 == listen(fcgi_fd, 1024)) {
+-			fprintf(stderr, "%s.%d: fd = -1\n",
+-				__FILE__, __LINE__);
+-			return -1;
+-		}
+-
+-		while (fork_count-- > 0) {
+-
+-			if (!nofork) {
+-				child = fork();
+-			} else {
+-				child = 0;
+-			}
+-
+-			switch (child) {
+-			case 0: {
+-				char cgi_childs[64];
+-				int max_fd = 0;
+-
+-				int i = 0;
+-
+-				/* loose control terminal */
+-				setsid();
+-
+-				/* 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);
+-				}
+-
+-				max_fd = open("/dev/null", O_RDWR);
+-				close(STDERR_FILENO);
+-				dup2(max_fd, STDERR_FILENO);
+-				close(max_fd);
+-
+-				max_fd = open("/dev/null", O_RDWR);
+-				close(STDOUT_FILENO);
+-				dup2(max_fd, STDOUT_FILENO);
+-				close(max_fd);
+-
+-				/* we don't need the client socket */
+-				for (i = 3; i < max_fd; i++) {
+-					if (i != FCGI_LISTENSOCK_FILENO) close(i);
+-				}
+-
+-				/* create environment */
+-
+-				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 */
+-
+-				/* 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;
+-			}
+-		}
+-		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 rc;
+-}
+-
+-
+-void show_version () {
+-	char *b = "spawn-fcgi" "-" PACKAGE_VERSION \
+-" - spawns fastcgi processes\n"
+-;
+-	write(1, b, strlen(b));
+-}
+-
+-void show_help () {
+-	char *b = \
+-"Usage: spawn-fcgi [options] -- <fcgiapp> [fcgi app arguments]\n" \
+-"\n" \
+-"spawn-fcgi v" PACKAGE_VERSION " - spawns fastcgi processes\n" \
+-"\n" \
+-"Options:\n" \
+-" -f <fcgiapp> filename of the fcgi-application\n" \
+-" -a <addr>    bind to ip address\n" \
+-" -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" \
+-" -h           show this help\n" \
+-"(root only)\n" \
+-" -c <dir>     chroot to directory\n" \
+-" -u <user>    change to user-id\n" \
+-" -g <group>   change to group-id\n" \
+-;
+-	write(1, b, strlen(b));
+-}
+-
+-
+-int main(int argc, char **argv) {
+-	char *fcgi_app = NULL, *changeroot = NULL, *username = NULL,
+-               *groupname = NULL, *unixsocket = NULL, *pid_file = NULL,
+-                *addr = NULL;
+-	char **fcgi_app_argv = { NULL };
+-	unsigned short port = 0;
+-	int child_count = 5;
+-	int fork_count = 1;
+-	int i_am_root, o;
+-	int pid_fd = -1;
+-	int nofork = 0;
+-	struct sockaddr_un un;
+-
+-	i_am_root = (getuid() == 0);
+-
+-	while (-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:F:s:P:"))) {
+-		switch(o) {
+-		case 'f': fcgi_app = optarg; break;
+-		case 'a': addr = optarg;/* ip addr */ break;
+-		case 'p': port = strtol(optarg, NULL, 10);/* port */ break;
+-		case 'C': child_count = strtol(optarg, NULL, 10);/*  */ break;
+-		case 'F': fork_count = strtol(optarg, NULL, 10);/*  */ break;
+-		case 's': unixsocket = optarg; /* unix-domain socket */ break;
+-		case 'c': if (i_am_root) { changeroot = optarg; }/* chroot() */ break;
+-		case 'u': if (i_am_root) { username = optarg; } /* set user */ break;
+-		case 'g': if (i_am_root) { groupname = optarg; } /* set group */ break;
+-		case 'n': nofork = 1; break;
+-		case 'P': pid_file = optarg; /* PID file */ break;
+-		case 'v': show_version(); return 0;
+-		case 'h': show_help(); return 0;
+-		default:
+-			show_help();
+-			return -1;
+-		}
+-	}
+-
+-	if (optind < argc) {
+-		fcgi_app_argv = &argv[optind];
+-	}
+-
+-	if ((fcgi_app == NULL && fcgi_app_argv == NULL) || (port == 0 && unixsocket == NULL)) {
+-		show_help();
+-		return -1;
+-	}
+-
+-	if (unixsocket && port) {
+-		fprintf(stderr, "%s.%d: %s\n",
+-			__FILE__, __LINE__,
+-			"either a unix domain socket or a tcp-port, but not both\n");
+-
+-		return -1;
+-	}
+-
+-	if (unixsocket && strlen(unixsocket) > sizeof(un.sun_path) - 1) {
+-		fprintf(stderr, "%s.%d: %s\n",
+-			__FILE__, __LINE__,
+-			"path of the unix socket is too long\n");
+-
+-		return -1;
+-	}
+-
+-	/* UID handling */
+-	if (!i_am_root && (geteuid() == 0 || getegid() == 0)) {
+-		/* we are setuid-root */
+-
+-		fprintf(stderr, "%s.%d: %s\n",
+-			__FILE__, __LINE__,
+-			"Are you nuts ? Don't apply a SUID bit to this binary\n");
+-
+-		return -1;
+-	}
+-
+-	if (pid_file &&
+-	    (-1 == (pid_fd = open(pid_file, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)))) {
+-		struct stat st;
+-		if (errno != EEXIST) {
+-			fprintf(stderr, "%s.%d: opening pid-file '%s' failed: %s\n",
+-				__FILE__, __LINE__,
+-				pid_file, strerror(errno));
+-
+-			return -1;
+-		}
+-
+-		/* ok, file exists */
+-
+-		if (0 != stat(pid_file, &st)) {
+-			fprintf(stderr, "%s.%d: stating pid-file '%s' failed: %s\n",
+-				__FILE__, __LINE__,
+-				pid_file, strerror(errno));
+-
+-			return -1;
+-		}
+-
+-		/* is it a regular file ? */
+-
+-		if (!S_ISREG(st.st_mode)) {
+-			fprintf(stderr, "%s.%d: pid-file exists and isn't regular file: '%s'\n",
+-				__FILE__, __LINE__,
+-				pid_file);
+-
+-			return -1;
+-		}
+-
+-		if (-1 == (pid_fd = open(pid_file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) {
+-			fprintf(stderr, "%s.%d: opening pid-file '%s' failed: %s\n",
+-				__FILE__, __LINE__,
+-				pid_file, strerror(errno));
+-
+-			return -1;
+-		}
+-	}
+-
+-	if (i_am_root) {
+-		struct group *grp = NULL;
+-		struct passwd *pwd = NULL;
+-
+-		/* set user and group */
+-
+-		if (username) {
+-			if (NULL == (pwd = getpwnam(username))) {
+-				fprintf(stderr, "%s.%d: %s, %s\n",
+-					__FILE__, __LINE__,
+-					"can't find username", username);
+-				return -1;
+-			}
+-
+-			if (pwd->pw_uid == 0) {
+-				fprintf(stderr, "%s.%d: %s\n",
+-					__FILE__, __LINE__,
+-					"I will not set uid to 0\n");
+-				return -1;
+-			}
+-		}
+-
+-		if (groupname) {
+-			if (NULL == (grp = getgrnam(groupname))) {
+-				fprintf(stderr, "%s.%d: %s %s\n",
+-					__FILE__, __LINE__,
+-					"can't find groupname",
+-					groupname);
+-				return -1;
+-			}
+-			if (grp->gr_gid == 0) {
+-				fprintf(stderr, "%s.%d: %s\n",
+-					__FILE__, __LINE__,
+-					"I will not set gid to 0\n");
+-				return -1;
+-			}
+-
+-			/* do the change before we do the chroot() */
+-			setgid(grp->gr_gid);
+-			setgroups(0, NULL); 
+-
+-			if (username) {
+-				initgroups(username, grp->gr_gid);
+-			}
+-
+-		}
+-
+-		if (changeroot) {
+-			if (-1 == chroot(changeroot)) {
+-				fprintf(stderr, "%s.%d: %s %s\n",
+-					__FILE__, __LINE__,
+-					"chroot failed: ", strerror(errno));
+-				return -1;
+-			}
+-			if (-1 == chdir("/")) {
+-				fprintf(stderr, "%s.%d: %s %s\n",
+-					__FILE__, __LINE__,
+-					"chdir failed: ", strerror(errno));
+-				return -1;
+-			}
+-		}
+-
+-		/* drop root privs */
+-		if (username) {
+-			setuid(pwd->pw_uid);
+-		}
+-	}
+-
+-       return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, fork_count, child_count, pid_fd, nofork);
+-}
+-#else
+-int main() {
+-	return -1;
+-}
+-#endif
 Index: src/configfile-glue.c
 ===================================================================
---- src/configfile-glue.c	(.../tags/lighttpd-1.4.22)	(revision 2417)
-+++ src/configfile-glue.c	(.../branches/lighttpd-1.4.x)	(revision 2417)
+--- src/configfile-glue.c	(.../tags/lighttpd-1.4.22)	(revision 2475)
++++ src/configfile-glue.c	(.../branches/lighttpd-1.4.x)	(revision 2475)
+@@ -49,7 +49,7 @@
+ 						buffer_copy_string_buffer(ds->value, ((data_string *)(da->value->data[j]))->value);
+ 						if (!da->is_index_key) {
+ 							/* the id's were generated automaticly, as we copy now we might have to renumber them
+-							 * this is used to prepend server.modules by mod_indexfiles as it has to be loaded
++							 * this is used to prepend server.modules by mod_indexfile as it has to be loaded
+ 							 * before mod_fastcgi and friends */
+ 							buffer_copy_string_buffer(ds->key, ((data_string *)(da->value->data[j]))->key);
+ 						}
 @@ -181,7 +181,7 @@
  	return config_insert_values_internal(srv, ca, cv);
  }
@@ -15,9 +510,80 @@
  #else
 Index: src/mod_cgi.c
 ===================================================================
---- src/mod_cgi.c	(.../tags/lighttpd-1.4.22)	(revision 2417)
-+++ src/mod_cgi.c	(.../branches/lighttpd-1.4.x)	(revision 2417)
-@@ -1369,6 +1369,7 @@
+--- src/mod_cgi.c	(.../tags/lighttpd-1.4.22)	(revision 2475)
++++ src/mod_cgi.c	(.../branches/lighttpd-1.4.x)	(revision 2475)
+@@ -24,6 +24,7 @@
+ #include <fcntl.h>
+ 
+ #include "server.h"
++#include "stat_cache.h"
+ #include "keyvalue.h"
+ #include "log.h"
+ #include "connections.h"
+@@ -36,6 +37,8 @@
+ # include <sys/filio.h>
+ #endif
+ 
++#include "version.h"
++
+ enum {EOL_UNSET, EOL_N, EOL_RN};
+ 
+ typedef struct {
+@@ -776,25 +779,23 @@
+ 		/* not needed */
+ 		close(to_cgi_fds[1]);
+ 
+-		/* HACK:
+-		 * this is not nice, but it works
+-		 *
+-		 * we feed the stderr of the CGI to our errorlog, if possible
+-		 */
+-		if (srv->errorlog_mode == ERRORLOG_FILE) {
+-			close(STDERR_FILENO);
+-			dup2(srv->errorlog_fd, STDERR_FILENO);
+-		}
+-
+ 		/* create environment */
+ 		env.ptr = NULL;
+ 		env.size = 0;
+ 		env.used = 0;
+ 
+-		cgi_env_add(&env, CONST_STR_LEN("SERVER_SOFTWARE"), CONST_STR_LEN(PACKAGE_NAME"/"PACKAGE_VERSION));
++		if (buffer_is_empty(con->conf.server_tag)) {
++			cgi_env_add(&env, CONST_STR_LEN("SERVER_SOFTWARE"), CONST_STR_LEN(PACKAGE_DESC));
++		} else {
++			cgi_env_add(&env, CONST_STR_LEN("SERVER_SOFTWARE"), CONST_BUF_LEN(con->conf.server_tag));
++		}
+ 
+ 		if (!buffer_is_empty(con->server_name)) {
+-			cgi_env_add(&env, CONST_STR_LEN("SERVER_NAME"), CONST_BUF_LEN(con->server_name));
++			size_t len = con->server_name->used - 1;
++			char *colon = strchr(con->server_name->ptr, ':');
++			if (colon) len = colon - con->server_name->ptr;
++
++			cgi_env_add(&env, CONST_STR_LEN("SERVER_NAME"), con->server_name->ptr, len);
+ 		} else {
+ #ifdef HAVE_IPV6
+ 			s = inet_ntop(srv_sock->addr.plain.sa_family,
+@@ -1203,6 +1204,7 @@
+ 	size_t k, s_len;
+ 	plugin_data *p = p_d;
+ 	buffer *fn = con->physical.path;
++	stat_cache_entry *sce = NULL;
+ 
+ 	if (con->mode != DIRECT) return HANDLER_GO_ON;
+ 
+@@ -1210,6 +1212,9 @@
+ 
+ 	mod_cgi_patch_connection(srv, con, p);
+ 
++	if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) return HANDLER_GO_ON;
++	if (!S_ISREG(sce->st.st_mode)) return HANDLER_GO_ON;
++
+ 	s_len = fn->used - 1;
+ 
+ 	for (k = 0; k < p->conf.cgi->used; k++) {
+@@ -1369,6 +1374,7 @@
  }
  
  
@@ -27,8 +593,8 @@
<<Diff was trimmed, longer than 597 lines>>

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



More information about the pld-cvs-commit mailing list