Compare commits

...

14 Commits

Author SHA1 Message Date
Stefan Bühler 4a9104f602 backport to debhelper/compat 7 2013-07-21 14:24:50 +02:00
Stefan Bühler 4d99a7bf81 debian 0.2.2-1 2013-07-21 13:43:36 +02:00
Stefan Bühler 58fb5450bf fcgi-cgi 0.2.2
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABCAAGBQJR68ZjAAoJEODn0BcelbrXz6oP/3o1/1I5MkzS4UTE236bkEar
 +UPdLMAvzhmlsKePIScpfquV+7FSGiojfMdTNec4iuAuzjSi2fydiegbbNuYkOTj
 Bf9Sw518RUcbnfqF+MCyOYIa95M6CBB7NZ18RZgYPg04hpFUBrroMORvdRh6jLfT
 RfILpfN87QbKmYhQi4XY6IK61/8ukAHw/nu0SPULuE19VKLzbKgdibq+fHZpGCwc
 yi3164fT/mOKjYrENZ/dhnVgruQtcVo2RD4Q48ZNXANgR2SNtq7OXstG8dbmjEfO
 4RwwJWAdpbqWmB7Nl0U3Ro4jYfgbN9TjdgZ/WGg9qc6vb8oXQ8dqNkMQYHlClav/
 WryzL2EUEci4r3AKyYytJGJwko3/MWr2PLYjT+YKYPcAcgW3gjKjKDJo3c29+OF9
 Xz/s56KNSULOXP6e0vadLoTA1NA3B494piMLQFaynkKJE/Sc1BlVlLzF/U2bMB2p
 BktbeB+9XKN28PDJV9gA7A0/2XfN1Rd5BWjKDwWla9xGpjdoqWC7LMKvoxkhgUC5
 iOUYnu0jMoLAo8tRddBJOI4U6A6Ox7ym8r7u83Lgm/LTmOwZXd/j7mT0L+LB4+hP
 9hnijVUob+Gu5rwGQ1F907lJCfHDt78L82UwFl8dh/P7+J5mqkyMSye0/cpr+/60
 S6aP7ivKDt8eJhG5gaOH
 =nyMa
 -----END PGP SIGNATURE-----

Merge tag 'fcgi-cgi-0.2.2' into debian

fcgi-cgi 0.2.2
2013-07-21 13:38:27 +02:00
Stefan Bühler 42b7646e96 Release as 0.2.2 2013-07-21 13:30:26 +02:00
Stefan Bühler c699a147a1 copy PATH environment variable 2013-07-20 15:16:15 +02:00
Stefan Bühler b40d34f0c8 wait for proper connection close 2013-07-20 14:52:57 +02:00
Stefan Bühler 15394ede2f fix description in command line help/version 2013-07-20 10:49:34 +02:00
Stefan Bühler ef2ff3f599 [cmake] fix macros, glib2 including and libev cflags 2013-07-20 10:47:34 +02:00
Stefan Bühler 64c505e3c7 [cmake] improve libev handling 2013-07-20 10:31:59 +02:00
Stefan Bühler 9541b9d885 make README a proper formatted README.rst 2013-05-29 13:46:45 +02:00
Stefan Bühler 8d84e0d1bc backport to compat 8, hardening flags 2013-05-25 13:41:12 +02:00
Stefan Bühler a86596cec4 debian 0.2.1-1 2013-05-23 18:02:45 +02:00
Stefan Bühler c00f2bba96 Merge fcgi-cgi 0.2.1 into debian 2013-05-23 18:01:49 +02:00
Stefan Bühler 394d2a0500 fcgi-cgi 0.2.0-1 2013-05-18 18:33:04 +02:00
15 changed files with 396 additions and 53 deletions

View File

@ -2,54 +2,28 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
cmake_policy(VERSION 2.6.0)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckLibraryExists)
INCLUDE(FindPkgConfig)
INCLUDE(AddTargetProperties)
MACRO(ADD_TARGET_PROPERTIES _target _name _properties)
SET(_properties ${ARGV})
LIST(REMOVE_AT _properties 0)
LIST(REMOVE_AT _properties 0)
GET_TARGET_PROPERTY(_old_properties ${_target} ${_name})
#MESSAGE("adding property to ${_target} ${_name}: ${_properties}")
IF(NOT _old_properties)
# in case it's NOTFOUND
SET(_old_properties)
ELSE(NOT _old_properties)
SET(_old_properties "${_old_properties} ")
ENDIF(NOT _old_properties)
SET_TARGET_PROPERTIES(${_target} PROPERTIES ${_name} "${_old_properties}${_properties}")
ENDMACRO(ADD_TARGET_PROPERTIES)
PROJECT(fcgi-cgi C)
SET(PACKAGE_VERSION 0.2.1)
SET(PACKAGE_VERSION 0.2.2)
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
# libev
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
CHECK_LIBRARY_EXISTS(ev ev_time "" HAVE_LIBEV)
IF(HAVE_LIBEV)
SET(EV_LIBRARIES ev)
SET(EV_STATIC_LIBRARIES ev;m)
CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_RT)
IF(NEED_RT)
SET(EV_STATIC_LIBRARIES ${EV_STATIC_LIBRARIES} rt)
ENDIF(NEED_RT)
ELSE(HAVE_LIBEV)
MESSAGE(FATAL_ERROR "Couldn't find lib ev")
ENDIF(HAVE_LIBEV)
ELSE(HAVE_EV_H)
MESSAGE(FATAL_ERROR "Couldn't find <ev.h>")
ENDIF(HAVE_EV_H)
FIND_PACKAGE(LibEV REQUIRED)
# GLIB 2
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
SET(GLIB_INCLUDES ${GLIB2_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}/glib-2.0/ ${GLIB2_INCLUDE_DIRS}/glib-2.0/include/)
INCLUDE_DIRECTORIES(${GLIB_INCLUDES})
INCLUDE_DIRECTORIES(${GLIB2_INCLUDES_DIRS})
SET(MAIN_SOURCE fastcgi.c fcgi-cgi.c)
@ -61,15 +35,15 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(fcgi-cgi ${MAIN_SOURCE})
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "-std=gnu99 -Wall -g -Wshadow -W -pedantic -fPIC -D_GNU_SOURCE")
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "-std=gnu99 -Wall -g -Wshadow -W -pedantic -fPIC")
# libev
TARGET_LINK_LIBRARIES(fcgi-cgi "${EV_LIBRARIES}")
TARGET_LINK_LIBRARIES(fcgi-cgi ${LIBEV_LDFLAGS})
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS ${LIBEV_CFLAGS})
# GLIB 2
TARGET_LINK_LIBRARIES(fcgi-cgi "${GLIB2_LIBRARIES}")
ADD_TARGET_PROPERTIES(fcgi-cgi LINK_FLAGS "${GLIB2_LDFLAGS}")
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "${GLIB2_CFLAGS_OTHER}")
TARGET_LINK_LIBRARIES(fcgi-cgi ${GLIB2_LDFLAGS})
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS ${GLIB2_CFLAGS})
INSTALL(TARGETS fcgi-cgi DESTINATION bin)

2
README
View File

@ -1,2 +0,0 @@
fcgi-cgi is a FastCGI application to run cgi applications.

54
README.rst Normal file
View File

@ -0,0 +1,54 @@
Description
-----------
:Homepage:
http://redmine.lighttpd.net/projects/fcgi-cgi/wiki
fcgi-cgi is a FastCGI application to run normal cgi applications. It doesn't
make CGI applications faster, but it allows you to run them on a different
host and with different user permissions (without the need for suexec).
lighttpd2 won't have a mod_cgi, so you need this FastCGI wrapper to be able
to execute standard cgi applications like mailman and cgit.
fcgi-cgi is released under the `MIT license <http://git.lighttpd.net/fcgi-cgi.cgi/tree/COPYING>`_
Usage
-----
Examples for spawning a fcg-cgi instance with daemontools or runit::
#!/bin/sh
# run script
exec spawn-fcgi -n -s /tmp/fastcgi-cgi.sock -u www-default -U www-data -- /usr/bin/fcgi-cgi
Build dependencies
------------------
* glib >= 2.16.0 (http://www.gtk.org/)
* libev (http://software.schmorp.de/pkg/libev.html)
* cmake or autotools (for snapshots/releases the autotool generated files are included)
Build
-----
* snapshot/release with autotools::
./configure
make
* build from git: ``git clone git://git.lighttpd.net/fcgi-cgi.git``
* with autotools::
./autogen.sh
./configure
make
* with cmake (should work with snapshots/releases too)::
cmake .
make

View File

@ -0,0 +1,13 @@
MACRO(ADD_TARGET_PROPERTIES _target _name)
SET(_properties)
FOREACH(_prop ${ARGN})
SET(_properties "${_properties} ${_prop}")
ENDFOREACH(_prop)
GET_TARGET_PROPERTY(_old_properties ${_target} ${_name})
MESSAGE(STATUS "adding property to ${_target} ${_name}:" ${_properties})
IF(NOT _old_properties)
# in case it's NOTFOUND
SET(_old_properties)
ENDIF(NOT _old_properties)
SET_TARGET_PROPERTIES(${_target} PROPERTIES ${_name} "${_old_properties} ${_properties}")
ENDMACRO(ADD_TARGET_PROPERTIES)

71
cmake/FindLibEV.cmake Normal file
View File

@ -0,0 +1,71 @@
SET(LIBEV_PATH "" CACHE PATH "Base path for include/ev.h and lib/libev*")
SET(LIBEV_INCLUDE_PATH "" CACHE PATH "Include path for ev.h")
SET(LIBEV_LIBDIR "" CACHE PATH "Path containing libev")
IF(LIBEV_PATH)
SET(LIBEV_INCLUDE_PATH "${LIBEV_PATH}/include" CACHE PATH "Include path for ev.h" FORCE)
SET(LIBEV_LIBDIR "${LIBEV_PATH}/lib" CACHE PATH "Path containing libev" FORCE)
ENDIF(LIBEV_PATH)
IF(LIBEV_INCLUDE_PATH)
INCLUDE_DIRECTORIES(${LIBEV_INCLUDE_PATH})
ENDIF(LIBEV_INCLUDE_PATH)
# Use cached result
IF(NOT LIBEV_FOUND)
UNSET(HAVE_EV_H)
UNSET(HAVE_LIBEV)
UNSET(HAVE_EV_H CACHE)
UNSET(HAVE_LIBEV CACHE)
UNSET(LIBEV_CFLAGS)
UNSET(LIBEV_LDFLAGS)
IF(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
SET(CMAKE_REQUIRED_INCLUDES ${LIBEV_INCLUDE_PATH})
# MESSAGE(STATUS "Looking for ev.h in ${CMAKE_REQUIRED_INCLUDES}")
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
# MESSAGE(STATUS "Looking for lib ev in ${LIBEV_LIBDIR}")
CHECK_LIBRARY_EXISTS(ev ev_time "${LIBEV_LIBDIR}" HAVE_LIBEV)
IF(HAVE_LIBEV)
SET(LIBEV_LIBRARIES ev CACHE INTERNAL "")
SET(LIBEV_CFLAGS "" CACHE INTERNAL "")
SET(LIBEV_LDFLAGS "-L${LIBEV_LIBDIR} -lev" CACHE INTERNAL "")
SET(LIBEV_FOUND TRUE CACHE INTERNAL "Found libev" FORCE)
ELSE(HAVE_LIBEV)
MESSAGE(STATUS "Couldn't find lib ev in ${LIBEV_LIBDIR}")
ENDIF(HAVE_LIBEV)
ELSE(HAVE_EV_H)
MESSAGE(STATUS "Couldn't find <ev.h> in ${LIBEV_INCLUDE_PATH}")
ENDIF(HAVE_EV_H)
ELSE(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
pkg_check_modules(LIBEV libev)
IF(NOT LIBEV_FOUND)
# MESSAGE(STATUS "Looking for ev.h in ${CMAKE_REQUIRED_INCLUDES}")
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
IF(HAVE_EV_H)
# MESSAGE(STATUS "Looking for lib ev")
CHECK_LIBRARY_EXISTS(ev ev_time "" HAVE_LIBEV)
IF(HAVE_LIBEV)
SET(LIBEV_CFLAGS "" CACHE INTERNAL "")
SET(LIBEV_LDFLAGS "-lev" CACHE INTERNAL "")
SET(LIBEV_FOUND TRUE CACHE INTERNAL "Found libev" FORCE)
ELSE(HAVE_LIBEV)
MESSAGE(STATUS "Couldn't find lib ev")
ENDIF(HAVE_LIBEV)
ELSE(HAVE_EV_H)
MESSAGE(STATUS "Couldn't find <ev.h>")
ENDIF(HAVE_EV_H)
ENDIF(NOT LIBEV_FOUND)
ENDIF(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
ENDIF(NOT LIBEV_FOUND)
IF(NOT LIBEV_FOUND)
IF(LibEV_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find libev")
ENDIF(LibEV_FIND_REQUIRED)
ENDIF(NOT LIBEV_FOUND)
MARK_AS_ADVANCED(LIBEV_PATH LIBEV_INCLUDE_PATH LIBEV_LIBDIR)

View File

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT([fcgi-cgi], [0.2.1], [lighttpd@stbuehler.de])
AC_INIT([fcgi-cgi], [0.2.2], [lighttpd@stbuehler.de])
AC_CONFIG_SRCDIR([fcgi-cgi.c])
AC_CONFIG_HEADERS([config.h])

101
debian/changelog vendored Normal file
View File

@ -0,0 +1,101 @@
fcgi-cgi (0.2.2-2) unstable; urgency=low
* backport to debhelper/compat 7
-- Stefan Bühler <stbuehler@web.de> Sun, 21 Jul 2013 14:24:37 +0200
fcgi-cgi (0.2.2-1) unstable; urgency=low
* make README a proper formatted README.rst
* [cmake] improve libev handling
* [cmake] fix macros, glib2 including and libev cflags
* fix description in command line help/version
* wait for proper connection close
* copy PATH environment variable
-- Stefan Bühler <stbuehler@web.de> Sun, 21 Jul 2013 13:42:48 +0200
fcgi-cgi (0.2.1-2) unstable; urgency=low
* backport to compat 8, hardening flags
-- Stefan Bühler <stbuehler@web.de> Sat, 25 May 2013 13:40:47 +0200
fcgi-cgi (0.2.1-1) unstable; urgency=low
* New upstream release
+ clear environment after request end
+ close stdin after writing request body
-- Stefan Bühler <stbuehler@web.de> Thu, 23 May 2013 18:02:06 +0200
fcgi-cgi (0.2.0-1) unstable; urgency=low
* Handle requests after the first one (fixing keep-alive)
-- Stefan Bühler <stbuehler@web.de> Sat, 18 May 2013 18:18:18 +0200
fcgi-cgi (0.1.8-1) unstable; urgency=low
* New upstream release
+ [cmake] fix link object/lib order
+ remove stropts.h include
-- Stefan Bühler <source@stbuehler.de> Thu, 28 Oct 2010 21:45:00 +0000
fcgi-cgi (0.1.7-1) unstable; urgency=low
* Backport to debhelper 5
* New upstream release
+ Fix libev check for libev4
+ [cmake] remove check for c++
-- Stefan Bühler <source@stbuehler.de> Thu, 28 Oct 2010 19:14:39 +0000
fcgi-cgi (0.1.5-1) unstable; urgency=low
* New upstream release
+ Reenable accepting connections after hitting the limit (fixes #2195)
+ Add commandline options (-c)
+ Add man page
-- Stefan Bühler <source@stbuehler.de> Fri, 07 May 2010 20:53:57 +0000
fcgi-cgi (0.1.4-1) unstable; urgency=low
* New upstream release
+ Re-enable child in/err pipes after fcgi con close
-- Stefan Bühler <source@stbuehler.de> Wed, 06 Jan 2010 16:27:47 +0000
fcgi-cgi (0.1.3-1) unstable; urgency=low
* Use GByteArray instead of GString, read padding bytes in normal reads()
and skip them
-- Stefan Bühler <source@stbuehler.de> Wed, 11 Nov 2009 20:38:32 +0000
fcgi-cgi (0.1.2-1) unstable; urgency=low
* Fast chdir() fix - broke everything...
-- Stefan Bühler <source@stbuehler.de> Wed, 11 Nov 2009 15:23:28 +0000
fcgi-cgi (0.1.1-1) unstable; urgency=low
* Some upstream fixes (issues with POST requests)
* chdir() before exec()
-- Stefan Bühler <source@stbuehler.de> Wed, 11 Nov 2009 15:08:42 +0000
fcgi-cgi (0.1.0-1) unstable; urgency=low
* Initial release
-- Stefan Bühler <source@stbuehler.de> Sun, 13 Sep 2009 17:56:48 +0000
fcgi-cgi (0.1.0-0) unstable; urgency=low
* Initial release
-- Stefan Bühler <source@stbuehler.de> Sun, 13 Sep 2009 17:56:31 +0000

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
7

29
debian/control vendored Normal file
View File

@ -0,0 +1,29 @@
Source: fcgi-cgi
Section: web
Priority: extra
Maintainer: Stefan Bühler <stbuehler@web.de>
Build-Depends: debhelper (>= 7), cmake, libglib2.0-dev, libev-dev, cdbs
Standards-Version: 3.9.4
Homepage: http://redmine.lighttpd.net/projects/fcgi-cgi
Package: fcgi-cgi
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: FastCGI application to run cgi applications
FastCGI application to run cgi applications; this allows one to run
cgi applications with different user permissions than the webserver
without using suExec wrappers.
And the webserver doesn't need to fork, and it may be easier to get
the webserver running in a chroot.
Package: fcgi-cgi-dbg
Architecture: any
Section: debug
Priority: extra
Depends: fcgi-cgi (=${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
Description: FastCGI application to run cgi applications
FastCGI application to run cgi applications; this allows one to run
cgi applications with different user permissions than the webserver
without using suExec wrappers.
And the webserver doesn't need to fork, and it may be easier to get
the webserver running in a chroot.

43
debian/copyright vendored Normal file
View File

@ -0,0 +1,43 @@
This package was debianized by Stefan Bühler <source@stbuehler.de> on
Sun, 13 Sep 2009 17:21:19 +0000.
It was downloaded from http://redmine.lighttpd.net/projects/fcgi-cgi
Upstream Author:
Stefan Bühler <stbuehler@web.de>
Copyright:
<Copyright (C) 2009 Stefan Bühler>
License:
The MIT License
Copyright (c) 2009 Stefan Bühler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The Debian packaging is:
Copyright (C) 2009 Stefan Bühler <source@stbuehler.de>
and is licensed under the GPL version 3,
see `/usr/share/common-licenses/GPL-3'.

2
debian/fcgi-cgi.install vendored Normal file
View File

@ -0,0 +1,2 @@
debian/tmp/usr/bin/fcgi-cgi /usr/bin/
debian/tmp/usr/share/man/man1/fcgi-cgi.1 /usr/share/man/man1/

10
debian/rules vendored Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/cmake.mk
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)
DEB_CMAKE_EXTRA_FLAGS=-DCMAKE_BUILD_TYPE="RelWithDebInfo"
DEB_CMAKE_EXTRA_FLAGS+=-DCMAKE_SHARED_LINKER_FLAGS="$(LDFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS)"

1
debian/source/format vendored Normal file
View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -604,7 +604,31 @@ error:
static void fastcgi_connection_fd_cb(struct ev_loop *loop, ev_io *w, int revents) {
fastcgi_connection *fcon = (fastcgi_connection*) w->data;
UNUSED(loop);
if (fcon->closing) {
char buf[1024];
ssize_t r;
r = read(fcon->fd, buf, sizeof(buf));
if (r > 0) return;
if (-1 == r) switch (errno) {
case EINTR:
case EAGAIN:
#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
#endif
return; /* try again later */
default:
break;
}
ev_io_stop(loop, w);
close(fcon->fd);
fcon->fd = -1;
ev_prepare_start(fcon->fsrv->loop, &fcon->fsrv->closing_watcher);
return;
}
if (revents & EV_READ) {
read_queue(fcon);
@ -637,11 +661,6 @@ static fastcgi_connection *fastcgi_connecion_create(fastcgi_server *fsrv, gint f
static void fastcgi_connection_free(fastcgi_connection *fcon) {
fcon->fsrv->callbacks->cb_reset_connection(fcon);
if (fcon->fd != -1) {
ev_io_stop(fcon->fsrv->loop, &fcon->fd_watcher);
close(fcon->fd);
fcon->fd = -1;
}
fastcgi_queue_clear(&fcon->write_queue);
fastcgi_connection_environ_clear(fcon);
@ -655,9 +674,7 @@ static void fastcgi_connection_free(fastcgi_connection *fcon) {
void fastcgi_connection_close(fastcgi_connection *fcon) {
fcon->closing = TRUE;
if (fcon->fd != -1) {
ev_io_stop(fcon->fsrv->loop, &fcon->fd_watcher);
close(fcon->fd);
fcon->fd = -1;
shutdown(fcon->fd, SHUT_WR);
}
fastcgi_queue_clear(&fcon->write_queue);
@ -666,7 +683,9 @@ void fastcgi_connection_close(fastcgi_connection *fcon) {
g_byte_array_set_size(fcon->parambuf, 0);
fastcgi_connection_environ_clear(fcon);
ev_prepare_start(fcon->fsrv->loop, &fcon->fsrv->closing_watcher);
if (fcon->fd == -1) {
ev_prepare_start(fcon->fsrv->loop, &fcon->fsrv->closing_watcher);
}
}
static void fastcgi_server_fd_cb(struct ev_loop *loop, ev_io *w, int revents) {
@ -723,7 +742,7 @@ static void fastcgi_cleanup_connections(fastcgi_server *fsrv) {
for (i = 0; i < fsrv->connections->len; ) {
fastcgi_connection *fcon = g_ptr_array_index(fsrv->connections, i);
if (fcon->closing) {
if (fcon->closing && -1 == fcon->fd) {
fastcgi_connection *t_fcon;
guint l = fsrv->connections->len-1;
t_fcon = g_ptr_array_index(fsrv->connections, i) = g_ptr_array_index(fsrv->connections, l);

View File

@ -22,7 +22,7 @@
#define __STR(x) #x
#define ERROR(...) g_printerr("fcgi-cgi.c:" G_STRINGIFY(__LINE__) ": " __VA_ARGS__)
#define PACKAGE_DESC (PACKAGE_NAME " v" PACKAGE_VERSION " - forks and watches multiple instances of a program in the same environment")
#define PACKAGE_DESC (PACKAGE_NAME " v" PACKAGE_VERSION " - FastCGI application to run normal cgi applications")
struct fcgi_cgi_server;
typedef struct fcgi_cgi_server fcgi_cgi_server;
@ -311,6 +311,32 @@ static void fcgi_cgi_child_error(fcgi_cgi_child *cld) {
}
}
static void copy_env_var(GPtrArray *env, const char *name) {
guint i, namelen = strlen(name);
const char *value;
for (i = 0; i < env->len; ) {
const char *entry = g_ptr_array_index(env, i);
if (0 == strncmp(entry, name, namelen) && entry[namelen] == '=') {
g_ptr_array_remove_index_fast(env, i);
g_free((char*) entry);
} else {
++i;
}
}
value = getenv(name);
if (NULL != value) {
guint valuelen = strlen(value);
char *entry = g_malloc(namelen + valuelen + 2);
memcpy(entry, name, namelen);
entry[namelen] = '=';
memcpy(entry + namelen + 1, value, valuelen);
entry[namelen+valuelen+1] = 0;
g_ptr_array_add(env, entry);
}
}
static void fcgi_cgi_child_start(fcgi_cgi_child *cld, const gchar *path) {
int pipes_to[2] = {-1, -1}, pipes_from[2] = {-1, -1}, pipes_err[2] = {-1, -1};
pid_t pid;
@ -353,6 +379,7 @@ static void fcgi_cgi_child_start(fcgi_cgi_child *cld, const gchar *path) {
}
}
copy_env_var(enva, "PATH");
g_ptr_array_add(enva, NULL);
newenv = (char**) g_ptr_array_free(enva, FALSE);
execve(path, args, newenv);