lighttpd1.4/src/base.h

206 lines
4.6 KiB
C
Raw Normal View History

#ifndef _BASE_H_
#define _BASE_H_
#include "first.h"
#include <sys/types.h>
#include <sys/time.h>
#if defined(__APPLE__) && defined(__MACH__)
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
#include <time.h>
#endif
#endif
#include "base_decls.h"
#include "buffer.h"
#include "array.h"
#include "chunk.h"
#include "http_kv.h"
#include "request.h"
2017-10-29 05:23:19 +00:00
#include "sock_addr.h"
struct fdevents; /* declaration */
struct connection {
request_st request;
h2con *h2;
int fd; /* the FD for this connection */
int ndx; /* reverse mapping to server->connection[ndx] */
fdnode *fdn; /* fdevent (fdnode *) object */
/* fd states */
signed char is_readable;
signed char is_writable;
char is_ssl_sock;
char traffic_limit_reached;
uint16_t revents_err;
uint16_t proto_default_port;
chunkqueue *write_queue; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
chunkqueue *read_queue; /* a small queue for low-level read ( HTTP request ) [ mem ] */
off_t bytes_written; /* used by mod_accesslog, mod_rrd */
off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */
off_t bytes_read; /* used by mod_accesslog, mod_rrd */
int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes);
int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes);
handler_t (* reqbody_read)(struct request_st *r);
server *srv;
void *plugin_slots;
void **plugin_ctx; /* plugin connection specific config */
void *config_data_base;
sock_addr dst_addr;
buffer *dst_addr_buf;
struct server_socket *srv_socket; /* reference to the server-socket */
/* timestamps */
time_t read_idle_ts;
time_t close_timeout_ts;
time_t write_request_ts;
time_t connection_start;
uint32_t request_count; /* number of requests handled in this connection */
int keep_alive_idle; /* remember max_keep_alive_idle from config */
};
typedef struct {
connection **ptr;
uint32_t size;
uint32_t used;
} connections;
typedef struct {
2019-11-16 01:26:54 +00:00
void *ptr;
uint32_t used;
uint32_t size;
} buffer_plugin;
typedef struct {
2019-11-16 01:26:54 +00:00
/*(used sparsely, if at all, after config at startup)*/
uint32_t max_request_field_size;
unsigned char log_state_handling;
unsigned char log_request_header_on_error;
2019-11-16 01:26:54 +00:00
unsigned char http_header_strict;
unsigned char http_host_strict;
unsigned char http_host_normalize;
unsigned char http_method_get_body;
unsigned char high_precision_timestamps;
unsigned char h2proto;
unsigned short http_url_normalize;
unsigned char absolute_dir_redirect;
unsigned short max_worker;
unsigned short max_fds;
unsigned short max_conns;
unsigned short port;
unsigned int upload_temp_file_size;
array *upload_tempdirs;
2019-11-16 01:26:54 +00:00
unsigned char dont_daemonize;
unsigned char preflight_check;
unsigned char enable_cores;
unsigned char compat_module_load;
unsigned char config_deprecated;
unsigned char config_unsupported;
2019-11-16 01:26:54 +00:00
unsigned char systemd_socket_activation;
unsigned char errorlog_use_syslog;
const buffer *syslog_facility;
const buffer *bindhost;
const buffer *changeroot;
const buffer *username;
const buffer *groupname;
const buffer *network_backend;
const array *feature_flags;
2019-11-16 01:26:54 +00:00
const char *event_handler;
buffer *pid_file;
buffer *modules_dir;
array *modules;
array *config_touched;
array empty_array;
} server_config;
typedef struct server_socket {
sock_addr addr;
int fd;
unsigned short is_ssl;
unsigned short sidx;
fdnode *fdn;
server *srv;
buffer *srv_token;
} server_socket;
typedef struct {
server_socket **ptr;
uint32_t size;
uint32_t used;
} server_socket_array;
struct server {
void *plugin_slots;
array *config_context;
struct fdevents *ev;
int (* network_backend_write)(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh);
handler_t (* request_env)(request_st *r);
/* buffers */
buffer *tmp_buf;
connections conns;
connections joblist_A;
connections joblist_B;
connections fdwaitqueue;
/* counters */
int con_opened;
int con_read;
int con_written;
int con_closed;
int max_fds; /* max possible fds */
int max_fds_lowat;/* low watermark */
int max_fds_hiwat;/* high watermark */
int cur_fds; /* currently used fds */
int sockets_disabled;
uint32_t max_conns;
log_error_st *errh;
2019-11-16 01:26:54 +00:00
time_t loadts;
double loadavg[3];
/* members used at start-up or rarely used */
server_config srvconf;
2019-11-16 01:26:54 +00:00
void *config_data_base;
server_socket_array srv_sockets;
server_socket_array srv_sockets_inherited;
buffer_plugin plugins;
time_t startup_ts;
time_t graceful_expire_ts;
uid_t uid;
gid_t gid;
pid_t pid;
int stdin_fd;
[core] graceful and immediate restart option graceful and (nearly) immediate lighttpd restart option For *some* configurations, it *may* be safe to background the current lighttpd server (or workers) to continue processing active requests and, in parallel, to start up a new lighttpd server with a new configuration. For other configurations, doing so might not be safe! Therefore, this option must be explicitly configured to enable: server.feature-flags += ("server.graceful-restart-bg" => "enable") server.systemd-socket-activation = "enable" Along with enabling server.feature-flags "server.graceful-restart-bg", enabling server.systemd-socket-activation allows transfer of open listening sockets to the new lighttpd server instance, and occurs without closing the listening sockets and without destroying the kernel listen backlog queue on the socket. Safe configurations may include lighttpd.conf which connect to standalone backend daemons, e.g. proxying to other servers, including PHP-FPM backends. Unsafe configurations include lighttpd.conf which use "bin-path" option in *.server configs, instructing lighttpd to execute the backends. Using the graceful-and-immediate-restart option is likely *unsafe* if the backend daemon expects only one instance of itself to run at a time. Current implementation of graceful and immediate restart option keeps the backgrounded lighttpd in the same process group, so that subsequent SIGINT or SIGTERM will shut down both the new and the backgrounded servers. (An alternative option (commented out in the code) is to background and detach from the new lighttpd process.) Regardless, existing subprocesses, such as CGI, remain in original process group. As a result, the new lighttpd server may receive SIGCHLD for unknown processes inherited from the old server, which the new lighttpd server will reap and discard. The original lighttpd server, now a child, will be unable to detect exit or reap and report status on those pre-existing subprocesses. Graceful restart is triggered in lighttpd by sending lighttpd SIGUSR1. If lighttpd is configured with workers, then SIGINT (not SIGUSR1) is sent to the process group, including other processes started by lighttpd, e.g. CGI. To work well with graceful restart, CGI scripts and other processes should trap SIGINT (and SIGUSR1 for good measure). Long-running scripts may want to checkpoint and close, e.g. a CGI script implementing a long-running websocket connection.
2020-09-25 14:59:28 +00:00
char **argv;
};
#endif