Commit Graph

55 Commits

Author SHA1 Message Date
Glenn Strauss d76756ca10 [core] perf: pass (fdnode *) to epoll and kqueue 2019-03-07 00:32:17 -05:00
Glenn Strauss 41384a3657 [core] isolate fdevent processing 2019-03-07 00:32:17 -05:00
Glenn Strauss 800e9b7349 [core] remove fde_ndx member outside fdevents
(isolated to fdevent framework internals)
2019-03-07 00:32:17 -05:00
Glenn Strauss 0a46f7ec23 [core] some fdevent code streamlining
isolate fde_ndx to fdevent framework internals
2019-03-07 00:32:17 -05:00
Glenn Strauss fc914ae442 [core] map FDEVENT_* to OS system event frameworks
(avoid need to translate event flags between OS and lighttpd FDEVENT_*)
2019-02-17 18:35:05 -05:00
Glenn Strauss f5f221eda8 [core] dispatch events from within event framework
event framework now calls interface to dispatch events rather than
itself implementing multiple interfaces for fdevent_process() to
be able to dispatch events generically.
2019-02-13 21:34:59 -05:00
Glenn Strauss 653b0dac7c [core] fdevent_process()
process fdevents in fdevent.c
2019-02-04 03:01:33 -05:00
Glenn Strauss 78024584bb [core] check if SOCK_NONBLOCK is ignored (fixes #2883)
x-ref:
  "fdevent_init should check if SOCK_NONBLOCK works"
  https://redmine.lighttpd.net/issues/2883
2018-08-05 03:44:15 -04:00
Glenn Strauss 04d76e7afd [core] some header cleanup
provide standard types in first.h instead of base.h
provide lighttpd types in base_decls.h instead of settings.h
reduce headers exposed by headers for core data structures
  do not expose <pcre.h> or <stdlib.h> in headers
move stat_cache_entry to stat_cache.h
reduce use of "server.h" and "base.h" in headers
2018-04-08 22:22:23 -04:00
Glenn Strauss d400f8aac5 [core] fdevent_accept_listenfd() nonblock cloexec
fdevent_accept_listenfd() now always returns fd O_NONBLOCK O_CLOEXEC
for consistency, rather than setting elsewhere in connection_accepted()

Handle older Linux 2.6 kernels which might have accept4() in glibc,
but return ENOSYS, as accept4() was not added until Linux kernel 2.6.28.
2018-03-25 00:59:48 -04:00
Glenn Strauss b9df146b3c [core] non-blocking write() to piped loggers
If pipe fills and would block, then discard remaining write.
Do not block lighttpd if the logger blocks, such as if disk fills up.
2018-01-02 21:01:41 -05:00
Glenn Strauss 84b5064dc4 [core] discard from socket using recv MSG_TRUNC
discard from socket using recv MSG_TRUNC on Linux TCP SOCK_STREAM socket

Currently, lighttpd supports only TCP SOCK_STREAM.  If UDP SOCK_DGRAM
were to be supported in the future, then socket type will need to be
stored so that MSG_TRUNC is used appropriately for the desired effect.

To find out socket type on arbitrary socket fd:
  getsockopt(..., SOL_SOCKET, SO_TYPE, ...)
but better to store it with each listening socket.
2017-12-11 21:35:31 -05:00
Glenn Strauss d5d0258362 [core] support POLLRDHUP, where available (#2743)
x-ref:
  "mod_cgi, lighty not killing CGI if connection in the other end is closed"
  https://redmine.lighttpd.net/boards/2/topics/5962
  "1.4.40/41 mod_proxy, mod_scgi may trigger POLLHUP on *BSD,Darwin"
  https://redmine.lighttpd.net/issues/2743
2017-11-19 12:01:09 -05:00
Glenn Strauss 8f3bbd7f13 [core] isolate backend fdevent handler defs 2017-11-03 23:02:08 -04:00
Glenn Strauss 168f67a1b1 [core] perf: more efficient fdevent_sched_run()
perf: more efficient fdevent_sched_run() over fds pending close
2017-10-21 12:34:17 -04:00
Glenn Strauss 93e91954a7 [core] fdevent setsockopt() helper functions
fdevent_set_tcp_nodelay()
fdevent_set_so_reuseaddr()
2017-09-23 10:30:08 -04:00
Glenn Strauss 9030cfaecf [core] SIGCHLD handle_waitpid hook for modules
centralize most waitpid() handling in core server, with hooks for
modules to be informed of pid and status when a process exits.

This enables faster discovery (and restart) of exited processes,
and also allows for lighttpd to manage backend processes in the
parent (master) process when server.max-worker > 0.
2017-09-10 16:24:34 -04:00
Glenn Strauss d4a37a3bbb [core] remove fdevent fcntl_set hook
(could have been removed in 2010 with commit 38f2d1dd
 which removed fdevent_linux_rtsig.c)
2017-07-29 00:36:48 -04:00
Glenn Strauss adeec956c3 [core] restart piped loggers if they exit (fixes #1393)
x-ref:
  "access log pipe writer should restart child process if it exits"
  https://redmine.lighttpd.net/issues/1393
2017-07-23 19:02:31 -04:00
Glenn Strauss ad7d6a6b15 [core] fdevent_cycle_logger()
fdevent_cycle_logger() re-opens log files before closing existing fd
2017-07-23 19:02:31 -04:00
Glenn Strauss 91d14acfc3 [core] fdevent_connect_status() shared code 2017-07-15 22:42:15 -04:00
Glenn Strauss 9e75b81982 [core] reduce exposure of unistd.h, other includes
reduce exposure of unistd.h, and some other include cleanup
2017-07-15 22:42:15 -04:00
Glenn Strauss 685cab057e [core] rename fd_close_on_exec()
rename fd_close_on_exec() to fdevent_setfd_cloexec()
2017-07-15 22:42:15 -04:00
Glenn Strauss a9970fec23 [core] consolidate fork()/execve() code (#1393)
(refactoring work to address issue #1393)

x-ref:
  "access log pipe writer should restart child process if it exits"
  https://redmine.lighttpd.net/issues/1393
2017-07-15 22:42:15 -04:00
Glenn Strauss 6f88c28c44 [core] fix compiler warnings on Mac OS X
(thx wardw)
2017-06-13 08:56:13 -04:00
Glenn Strauss 69aeaf2fad [mod_proxy] fix typo identified by coverity
fix mod_proxy.c typo identified by coverity
silence some warnings checking return values of fcntl() in fdevent.c
2017-05-15 23:59:22 -04:00
Glenn Strauss 8641d1b03f [core] no SOCK_CLOEXEC on Linux kernel < 2.6.27
Linux kernels < 2.6.27 (old!) might return EINVAL if SOCK_CLOEXEC used

x-ref:
  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529929
  http://www.linksysinfo.org/index.php?threads/lighttpd-no-longer-starts-toastman-1-28-0510-7.73132/
2017-04-15 17:46:25 -04:00
Glenn Strauss 4796313efc [core] collect ioctl FIONREAD code
include <sys/ioctl.h> in files which use ioctl()
  instead of exposing header in local header "sys-socket.h"
2017-03-28 02:17:33 -04:00
Glenn Strauss ba953cdf45 [core] include "fdevent.h" where needed
(instead of providing #include "fdevent.h" in base.h)
2017-03-28 02:17:33 -04:00
Glenn Strauss a53f662a30 [core] remove some unused header includes
remove exposure of stdio.h in buffer.h for print_backtrace(), now static
2017-03-28 02:17:33 -04:00
Glenn Strauss 3399b0dd16 [core] default server.max-fds=4096 if unspecified (#2789)
x-ref:
  "lighttpd cores on AIX when nofiles is unlimited"
  https://redmine.lighttpd.net/issues/2789
2017-02-28 11:34:04 -05:00
Glenn Strauss 95a756dcb3 [core] issue trace if max-fds too large (fixes #2789)
x-ref:
  "lighttpd cores on AIX when nofiles is unlimited"
  https://redmine.lighttpd.net/issues/2789
2017-02-13 14:24:53 -05:00
Glenn Strauss 93afda9c8e performance: use Linux extended syscalls and flags
reduce syscalls on Linux using extended syscalls and flags,
e.g. accept4(), pipe2(), O_CLOEXEC, SOCK_CLOEXEC, SOCK_NONBLOCK

github: closes #2
2016-09-24 02:23:49 -04:00
Glenn Strauss ede5ea2d83 fix mis-cast in unused code
For correctness, fix cast to (fdnode *) in #ifdef __WIN32 code.
(lighttpd compiles under cygwin, but not under native _WIN32)

(thx ToApolytoXaos)
2016-08-25 02:01:33 -04:00
Glenn Strauss 40f16d52db [core] fix crash if ready events on abandoned fd (fixes #2748)
x-ref:
  "1.4.40/1.4.41 uploads to CGI may cause crash (SIGABRT)"
  https://redmine.lighttpd.net/issues/2748
2016-08-24 15:30:11 -04:00
Glenn Strauss 6ec66c4dce [core] better DragonFlyBSD support (fixes #2746)
(thx xenu)

x-ref:
  "[PATCH] better DragonFlyBSD support; fix crash"
  https://redmine.lighttpd.net/issues/2746
2016-08-20 14:19:10 -04:00
Glenn Strauss 4bc06bfc0b [core] check if client half-closed TCP if POLLHUP (#2743)
Check if client half-closed TCP connection if POLLHUP is received.
This more robustly handles if client called shutdown(fd, SHUT_WR).

This patch reverts commit:ab05eb7c which should now be handled properly.
(Time will tell.)

x-ref:
  "1.4.40/41 mod_proxy, mod_scgi may trigger POLLHUP on *BSD,Darwin"
  https://redmine.lighttpd.net/issues/2743
2016-08-06 04:28:45 -04:00
Glenn Strauss 1cb30900f3 [core] remove assert in fdevent_unregister()
assumptions changed: fdn->events can be 0 with server streaming
request and/or response.
2016-07-07 12:47:13 -04:00
Glenn Strauss 18a7b2be37 [core] option to stream response body to client (fixes #949, #760, #1283, #1387)
Set server.stream-response-body = 1 or server.stream-response-body = 2
to have lighttpd stream response body to client as it arrives from the
backend (CGI, FastCGI, SCGI, proxy).

default: buffer entire response body before sending response to client.
(This preserves existing behavior for now, but may in the future be
 changed to stream response to client, which is the behavior more
 commonly expected.)

x-ref:
  "fastcgi, cgi, flush, php5 problem."
  https://redmine.lighttpd.net/issues/949
  "Random crashing on FreeBSD 6.1"
  https://redmine.lighttpd.net/issues/760
  "Memory usage increases when proxy+ssl+large file"
  https://redmine.lighttpd.net/issues/1283
  "lighttpd+fastcgi memory problem"
  https://redmine.lighttpd.net/issues/1387
2016-06-19 23:34:16 -04:00
Glenn Strauss 4b0c822ed0 always poll for client POLLHUP/POLLERR events (fixes #399)
to detect client disconnect.  Do so even when waiting on backend,
and not polling for POLLRD or POLLWR on client connection.

This reduces unnecessary load on backends when backends are slow
to respond and client has given up waiting.

x-ref:
  "https://redmine.lighttpd.net/issues/399"
  FastCGI performance on high load
2016-04-18 06:19:03 -04:00
Glenn Strauss 8abd06a7ff consistent inclusion of config.h at top of files (fixes #2073)
From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3113 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-03-19 15:14:35 +00:00
Stefan Bühler 566cf8decb add force_assert for more allocation results
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3072 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-01-30 13:59:07 +00:00
Stefan Bühler 9f2be4882d force assertion: setting FD_CLOEXEC must work (if available)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2952 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:29 +00:00
Stefan Bühler 07dd0bd0a5 add force_assert() to enforce assertions as simple assert()s are disabled by -DNDEBUG (fixes #2546)
From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2948 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:20 +00:00
Stefan Bühler 6f208cfde1 fix/silence bugs reported by ccc-analyzer (clang)
These should all be non critical:
 * memory leaks on startup in error cases (which lead to
   immediate shutdowns anyway)
 * http_auth/ldap: passing uninitialized "ret" to ldap_err2string
 * sizeof(T) not matching the target pointer in malloc/calloc calls;
   those cases were either:
   * T being the wrong pointer type - shouldn't matter as long as all
     pointers have same size
   * T being larger than the type needed
 * mod_accesslog: direct use after free in cleanup (server shutdown);
   could crash before "clean" shutdown
 * some false positives (mod_compress, mod_expire)
 * assert(srv->config_context->used > 0); - this is always the case,
   as there is always a global config block

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2920 152afb58-edef-0310-8abb-c4023f1b3aa9
2013-11-13 11:43:26 +00:00
Cyril Brulebois 0c6a564543 Fix non-ANSI function declarations.
The proper way to declare a function taking no parameters isn't:
  foo bar();

But this instead:
  foo bar(void);

Signed-off-by: Cyril Brulebois <kibi@debian.org>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2843 152afb58-edef-0310-8abb-c4023f1b3aa9
2012-08-31 14:11:41 +00:00
Stefan Bühler f0816d8db2 fdevent: add solaris eventports (fixes #2171)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2796 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-06-13 17:34:57 +00:00
Stefan Bühler 7e5b0fe9ab Rename fdevent_event_add to _set to reflect what the function does. Fix some handlers.
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2765 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-17 09:54:42 +00:00
Stefan Bühler f8eb52ebda add libev fdevent handler: server.event-handler = "libev"
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2754 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-07 10:46:34 +00:00
Stefan Bühler 38f2d1ddd7 cleanup fdevent code, removed linux-rtsig handler, replaced some fprintf calls
* use log functions
 * convert flags
 * fix handler callback prototype

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2752 152afb58-edef-0310-8abb-c4023f1b3aa9
2010-08-06 21:57:15 +00:00