Compare commits

..

No commits in common. "debian" and "master" have entirely different histories.

15 changed files with 53 additions and 396 deletions

View File

@ -2,28 +2,54 @@ 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.2)
SET(PACKAGE_VERSION 0.2.1)
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
FIND_PACKAGE(LibEV REQUIRED)
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)
# GLIB 2
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
INCLUDE_DIRECTORIES(${GLIB2_INCLUDES_DIRS})
SET(GLIB_INCLUDES ${GLIB2_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}/glib-2.0/ ${GLIB2_INCLUDE_DIRS}/glib-2.0/include/)
INCLUDE_DIRECTORIES(${GLIB_INCLUDES})
SET(MAIN_SOURCE fastcgi.c fcgi-cgi.c)
@ -35,15 +61,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")
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS "-std=gnu99 -Wall -g -Wshadow -W -pedantic -fPIC -D_GNU_SOURCE")
# libev
TARGET_LINK_LIBRARIES(fcgi-cgi ${LIBEV_LDFLAGS})
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS ${LIBEV_CFLAGS})
TARGET_LINK_LIBRARIES(fcgi-cgi "${EV_LIBRARIES}")
# GLIB 2
TARGET_LINK_LIBRARIES(fcgi-cgi ${GLIB2_LDFLAGS})
ADD_TARGET_PROPERTIES(fcgi-cgi COMPILE_FLAGS ${GLIB2_CFLAGS})
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}")
INSTALL(TARGETS fcgi-cgi DESTINATION bin)

2
README Normal file
View File

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

View File

@ -1,54 +0,0 @@
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

@ -1,13 +0,0 @@
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)

View File

@ -1,71 +0,0 @@
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.2], [lighttpd@stbuehler.de])
AC_INIT([fcgi-cgi], [0.2.1], [lighttpd@stbuehler.de])
AC_CONFIG_SRCDIR([fcgi-cgi.c])
AC_CONFIG_HEADERS([config.h])

101
debian/changelog vendored
View File

@ -1,101 +0,0 @@
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
View File

@ -1 +0,0 @@
7

29
debian/control vendored
View File

@ -1,29 +0,0 @@
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
View File

@ -1,43 +0,0 @@
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'.

View File

@ -1,2 +0,0 @@
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
View File

@ -1,10 +0,0 @@
#!/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)"

View File

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

View File

@ -604,31 +604,7 @@ error:
static void fastcgi_connection_fd_cb(struct ev_loop *loop, ev_io *w, int revents) {
fastcgi_connection *fcon = (fastcgi_connection*) w->data;
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;
}
UNUSED(loop);
if (revents & EV_READ) {
read_queue(fcon);
@ -661,6 +637,11 @@ 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);
@ -674,7 +655,9 @@ static void fastcgi_connection_free(fastcgi_connection *fcon) {
void fastcgi_connection_close(fastcgi_connection *fcon) {
fcon->closing = TRUE;
if (fcon->fd != -1) {
shutdown(fcon->fd, SHUT_WR);
ev_io_stop(fcon->fsrv->loop, &fcon->fd_watcher);
close(fcon->fd);
fcon->fd = -1;
}
fastcgi_queue_clear(&fcon->write_queue);
@ -683,9 +666,7 @@ void fastcgi_connection_close(fastcgi_connection *fcon) {
g_byte_array_set_size(fcon->parambuf, 0);
fastcgi_connection_environ_clear(fcon);
if (fcon->fd == -1) {
ev_prepare_start(fcon->fsrv->loop, &fcon->fsrv->closing_watcher);
}
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) {
@ -742,7 +723,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 && -1 == fcon->fd) {
if (fcon->closing) {
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 " - FastCGI application to run normal cgi applications")
#define PACKAGE_DESC (PACKAGE_NAME " v" PACKAGE_VERSION " - forks and watches multiple instances of a program in the same environment")
struct fcgi_cgi_server;
typedef struct fcgi_cgi_server fcgi_cgi_server;
@ -311,32 +311,6 @@ 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;
@ -379,7 +353,6 @@ 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);