lighttpd 1.4.x https://www.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2708 lines
95 KiB

[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from "fastcgi.*" to "gw.*" "fastcgi.backend.*" -> "gw.backend.*" "fastcgi.active-requests" -> "gw.active-requests" ("fastcgi.requests" remains "fastcgi.requests") ("proxy.requests" is new) ("scgi.requests" is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -> int debug fastcgi_env member removed from plugin_config renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW" reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs->spaces and reformatting
4 years ago
#include "first.h"
#include "gw_backend.h"
#include <sys/types.h>
#include <sys/stat.h>
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
#include "sys-socket.h"
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include "base.h"
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
#include "array.h"
#include "buffer.h"
#include "crc32.h"
#include "fdevent.h"
#include "log.h"
#include "sock_addr.h"
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
#include "status_counter.h"
static int * gw_status_get_counter(server *srv, gw_host *host, gw_proc *proc, const char *tag, size_t len) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
buffer *b = srv->tmp_buf;
buffer_copy_string_len(b, CONST_STR_LEN("gw.backend."));
buffer_append_string_buffer(b, host->id);
if (proc) {
buffer_append_string_len(b, CONST_STR_LEN("."));
buffer_append_int(b, proc->id);
}
buffer_append_string_len(b, tag, len);
return status_counter_get_counter(srv, CONST_BUF_LEN(b));
}
static void gw_proc_tag_inc(server *srv, gw_host *host, gw_proc *proc, const char *tag, size_t len) {
++(*gw_status_get_counter(srv, host, proc, tag, len));
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
static void gw_proc_load_inc(server *srv, gw_host *host, gw_proc *proc) {
*gw_status_get_counter(srv,host,proc,CONST_STR_LEN(".load")) = ++proc->load;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
status_counter_inc(srv, CONST_STR_LEN("gw.active-requests"));
}
static void gw_proc_load_dec(server *srv, gw_host *host, gw_proc *proc) {
*gw_status_get_counter(srv,host,proc,CONST_STR_LEN(".load")) = --proc->load;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
status_counter_dec(srv, CONST_STR_LEN("gw.active-requests"));
}
static void gw_host_assign(server *srv, gw_host *host) {
*gw_status_get_counter(srv,host,NULL,CONST_STR_LEN(".load")) = ++host->load;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
static void gw_host_reset(server *srv, gw_host *host) {
*gw_status_get_counter(srv,host,NULL,CONST_STR_LEN(".load")) = --host->load;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
static int gw_status_init(server *srv, gw_host *host, gw_proc *proc) {
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".disabled")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".died")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".overloaded")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".connected")) = 0;
*gw_status_get_counter(srv, host, proc, CONST_STR_LEN(".load")) = 0;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
*gw_status_get_counter(srv, host, NULL, CONST_STR_LEN(".load")) = 0;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
return 0;
}
static void gw_proc_set_state(gw_host *host, gw_proc *proc, int state) {
if ((int)proc->state == state) return;
if (proc->state == PROC_STATE_RUNNING) {
--host->active_procs;
} else if (state == PROC_STATE_RUNNING) {
++host->active_procs;
}
proc->state = state;
}
static gw_proc *gw_proc_init(void) {
gw_proc *f = calloc(1, sizeof(*f));
force_assert(f);
f->unixsocket = buffer_init();
f->connection_name = buffer_init();
f->prev = NULL;
f->next = NULL;
f->state = PROC_STATE_DIED;
return f;
}
static void gw_proc_free(gw_proc *f) {
if (!f) return;
gw_proc_free(f->next);
buffer_free(f->unixsocket);
buffer_free(f->connection_name);
free(f->saddr);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
free(f);
}
static gw_host *gw_host_init(void) {
gw_host *f = calloc(1, sizeof(*f));
force_assert(f);
return f;
}
static void gw_host_free(gw_host *h) {
if (!h) return;
if (h->refcount) {
--h->refcount;
return;
}
gw_proc_free(h->first);
gw_proc_free(h->unused_procs);
for (uint32_t i = 0; i < h->args.used; ++i) free(h->args.ptr[i]);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
free(h->args.ptr);
free(h);
}
static gw_exts *gw_extensions_init(void) {
gw_exts *f = calloc(1, sizeof(*f));
force_assert(f);
return f;
}
static void gw_extensions_free(gw_exts *f) {
if (!f) return;
for (uint32_t i = 0; i < f->used; ++i) {
gw_extension *fe = f->exts+i;
for (uint32_t j = 0; j < fe->used; ++j) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
gw_host_free(fe->hosts[j]);
}
free(fe->hosts);
}
free(f->exts);
free(f);
}
static int gw_extension_insert(gw_exts *ext, const buffer *key, gw_host *fh) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
gw_extension *fe = NULL;
for (uint32_t i = 0; i < ext->used; ++i) {
if (buffer_is_equal(key, &ext->exts[i].key)) {
fe = ext->exts+i;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
break;
}
}
if (NULL == fe) {
if (ext->used == ext->size) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
ext->size += 8;
ext->exts = realloc(ext->exts, ext->size * sizeof(gw_extension));
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
force_assert(ext->exts);
memset(ext->exts + ext->used, 0, 8 * sizeof(gw_extension));
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
fe = ext->exts + ext->used++;
fe->last_used_ndx = -1;
buffer *b;
*(const buffer **)&b = &fe->key;
memcpy(b, key, sizeof(buffer)); /*(copy; not later free'd)*/
}
if (fe->size == fe->used) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
fe->size += 4;
fe->hosts = realloc(fe->hosts, fe->size * sizeof(*(fe->hosts)));
force_assert(fe->hosts);
}
fe->hosts[fe->used++] = fh;
return 0;
}
static void gw_proc_connect_success(server *srv, gw_host *host, gw_proc *proc, int debug) {
gw_proc_tag_inc(srv, host, proc, CONST_STR_LEN(".connected"));
proc->last_used = srv->cur_ts;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (debug) {
log_error_write(srv, __FILE__, __LINE__, "ssdsbsd",
"got proc:",
"pid:", proc->pid,
"socket:", proc->connection_name,
"load:", proc->load);
}
}
static void gw_proc_connect_error(server *srv, gw_host *host, gw_proc *proc, pid_t pid, int errnum, int debug) {
log_error_write(srv, __FILE__, __LINE__, "sssb",
"establishing connection failed:", strerror(errnum),
"socket:", proc->connection_name);
if (!proc->is_local) {
proc->disabled_until = srv->cur_ts + host->disable_time;
gw_proc_set_state(host, proc, PROC_STATE_OVERLOADED);
}
else if (proc->pid == pid && proc->state == PROC_STATE_RUNNING) {
/* several requests from lighttpd might reference the same proc
*
* Only one of them should mark the proc
* and all other ones should just take a new one.
*
* If a new proc was started with the old struct, this might
* otherwise lead to marking a perfectly good proc as dead
*/
log_error_write(srv, __FILE__, __LINE__, "sdssd",
"backend error; we'll disable for", host->disable_time,
"secs and send the request to another backend instead:",
"load:", host->load);
if (EAGAIN == errnum) {
/* - EAGAIN: cool down the backend; it is overloaded */
#ifdef __linux__
log_error_write(srv, __FILE__, __LINE__, "s",
"If this happened on Linux: You have run out of local ports. "
"Check the manual, section Performance how to handle this.");
#endif
if (debug) {
log_error_write(srv, __FILE__, __LINE__, "sbsd",
"This means that you have more incoming requests than your "
"FastCGI backend can handle in parallel. It might help to "
"spawn more FastCGI backends or PHP children; if not, "
"decrease server.max-connections. The load for this FastCGI "
"backend", proc->connection_name, "is", proc->load);
}
proc->disabled_until = srv->cur_ts + host->disable_time;
gw_proc_set_state(host, proc, PROC_STATE_OVERLOADED);
}
else {
/* we got a hard error from the backend like
* - ECONNREFUSED for tcp-ip sockets
* - ENOENT for unix-domain-sockets
*/
#if 0
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
gw_proc_set_state(host, proc, PROC_STATE_DIED_WAIT_FOR_PID);
#else /* treat as overloaded (future: unless we send kill() signal)*/
proc->disabled_until = srv->cur_ts + host->disable_time;
gw_proc_set_state(host, proc, PROC_STATE_OVERLOADED);
#endif
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
}
if (EAGAIN == errnum) {
gw_proc_tag_inc(srv, host, proc, CONST_STR_LEN(".overloaded"));
}
else {
gw_proc_tag_inc(srv, host, proc, CONST_STR_LEN(".died"));
}
}
static void gw_proc_release(server *srv, gw_host *host, gw_proc *proc, int debug) {
gw_proc_load_dec(srv, host, proc);
if (debug) {
log_error_write(srv, __FILE__, __LINE__, "ssdsbsd",
"released proc:",
"pid:", proc->pid,
"socket:", proc->connection_name,
"load:", proc->load);
}
}
static void gw_proc_check_enable(server *srv, gw_host *host, gw_proc *proc) {
if (srv->cur_ts <= proc->disabled_until) return;
if (proc->state != PROC_STATE_OVERLOADED) return;
gw_proc_set_state(host, proc, PROC_STATE_RUNNING);
log_error_write(srv, __FILE__, __LINE__, "sbbdb",
"gw-server re-enabled:", proc->connection_name,
host->host, host->port, host->unixsocket);
}
static void gw_proc_waitpid_log(server *srv, gw_host *host, gw_proc *proc, int status) {
UNUSED(host);
if (WIFEXITED(status)) {
if (proc->state != PROC_STATE_KILLED) {
log_error_write(srv, __FILE__, __LINE__, "sdb",
"child exited:",
WEXITSTATUS(status), proc->connection_name);
}
} else if (WIFSIGNALED(status)) {
if (WTERMSIG(status) != SIGTERM && WTERMSIG(status) != SIGINT
&& WTERMSIG(status) != host->kill_signal) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"child signalled:", WTERMSIG(status));
}
} else {
log_error_write(srv, __FILE__, __LINE__, "sd",
"child died somehow:", status);
}
}
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
static int gw_proc_waitpid(server *srv, gw_host *host, gw_proc *proc) {
int rc, status;
if (!proc->is_local) return 0;
if (proc->pid <= 0) return 0;
do {
rc = waitpid(proc->pid, &status, WNOHANG);
} while (-1 == rc && errno == EINTR);
if (0 == rc) return 0; /* child still running */
/* child terminated */
if (-1 == rc) {
/* EINVAL or ECHILD no child processes */
/* should not happen; someone else has cleaned up for us */
log_error_write(srv, __FILE__, __LINE__, "sddss",
"pid ", proc->pid, proc->state,
"not found:", strerror(errno));
}
else {
gw_proc_waitpid_log(srv, host, proc, status);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
proc->pid = 0;
if (proc->state != PROC_STATE_KILLED)
proc->disabled_until = srv->cur_ts;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
gw_proc_set_state(host, proc, PROC_STATE_DIED);
return 1;
}
static int gw_proc_sockaddr_init(server *srv, gw_host *host, gw_proc *proc) {
sock_addr addr;
socklen_t addrlen;
if (!buffer_string_is_empty(proc->unixsocket)) {
if (1 != sock_addr_from_str_hints(srv, &addr, &addrlen,
proc->unixsocket->ptr, AF_UNIX, 0)) {
errno = EINVAL;
return -1;
}
buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("unix:"));
buffer_append_string_buffer(proc->connection_name, proc->unixsocket);
}
else {
/*(note: name resolution here is *blocking* if IP string not supplied)*/
if (1 != sock_addr_from_str_hints(srv, &addr, &addrlen,
host->host->ptr, 0, proc->port)) {
errno = EINVAL;
return -1;
}
else {
/* overwrite host->host buffer with IP addr string so that
* any further use of gw_host does not block on DNS lookup */
buffer *h;
*(const buffer **)&h = host->host;
sock_addr_inet_ntop_copy_buffer(h, &addr);
host->family = sock_addr_get_family(&addr);
}
buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("tcp:"));
buffer_append_string_buffer(proc->connection_name, host->host);
buffer_append_string_len(proc->connection_name, CONST_STR_LEN(":"));
buffer_append_int(proc->connection_name, proc->port);
}
if (NULL != proc->saddr && proc->saddrlen < addrlen) {
free(proc->saddr);
proc->saddr = NULL;
}
if (NULL == proc->saddr) {
proc->saddr = (struct sockaddr *)malloc(addrlen);
force_assert(proc->saddr);
}
proc->saddrlen = addrlen;
memcpy(proc->saddr, &addr, addrlen);
return 0;
}
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) {
char *dst;
if (!key || !val) return -1;
dst = malloc(key_len + val_len + 3);
force_assert(dst);
memcpy(dst, key, key_len);
dst[key_len] = '=';
memcpy(dst + key_len + 1, val, val_len + 1); /* add the \0 from the value */
for (uint32_t i = 0; i < env->used; ++i) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (0 == strncmp(dst, env->ptr[i], key_len + 1)) {
free(env->ptr[i]);
env->ptr[i] = dst;
return 0;
}
}
if (env->size <= env->used + 1) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
env->size += 16;
env->ptr = realloc(env->ptr, env->size * sizeof(*env->ptr));
force_assert(env->ptr);
}
env->ptr[env->used++] = dst;
return 0;
}
static int gw_spawn_connection(server *srv, gw_host *host, gw_proc *proc, int debug) {
int gw_fd;
int status;
struct timeval tv = { 0, 10 * 1000 };
if (debug) {
log_error_write(srv, __FILE__, __LINE__, "sdb",
"new proc, socket:", proc->port, proc->unixsocket);
}
gw_fd = fdevent_socket_cloexec(proc->saddr->sa_family, SOCK_STREAM, 0);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (-1 == gw_fd) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"failed:", strerror(errno));
return -1;
}
do {
status = connect(gw_fd, proc->saddr, proc->saddrlen);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
} while (-1 == status && errno == EINTR);
if (-1 == status && errno != ENOENT
&& !buffer_string_is_empty(proc->unixsocket)) {
log_error_write(srv, __FILE__, __LINE__, "sbss",
"unlink", proc->unixsocket,
"after connect failed:", strerror(errno));
unlink(proc->unixsocket->ptr);
}
close(gw_fd);
if (-1 == status) {
/* server is not up, spawn it */
char_array env;
uint32_t i;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
int dfd = -1;
/* reopen socket */
gw_fd = fdevent_socket_cloexec(proc->saddr->sa_family, SOCK_STREAM, 0);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (-1 == gw_fd) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"socket failed:", strerror(errno));
return -1;
}
if (fdevent_set_so_reuseaddr(gw_fd, 1) < 0) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
log_error_write(srv, __FILE__, __LINE__, "ss",
"socketsockopt failed:", strerror(errno));
close(gw_fd);
return -1;
}
/* create socket */
if (-1 == bind(gw_fd, proc->saddr, proc->saddrlen)) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
log_error_write(srv, __FILE__, __LINE__, "sbs",
"bind failed for:",
proc->connection_name,
strerror(errno));
close(gw_fd);
return -1;
}
if (-1 == listen(gw_fd, host->listen_backlog)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"listen failed:", strerror(errno));
close(gw_fd);
return -1;
}
{
/* create environment */
env.ptr = NULL;
env.size = 0;
env.used = 0;
/* build clean environment */
if (host->bin_env_copy && host->bin_env_copy->used) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
for (i = 0; i < host->bin_env_copy->used; ++i) {
data_string *ds=(data_string *)host->bin_env_copy->data[i];
char *ge;
if (NULL != (ge = getenv(ds->value.ptr))) {
env_add(&env,CONST_BUF_LEN(&ds->value),ge,strlen(ge));
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
}
} else {
char ** const e = fdevent_environ();
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
for (i = 0; e[i]; ++i) {
char *eq;
if (NULL != (eq = strchr(e[i], '='))) {
env_add(&env, e[i], eq - e[i], eq+1, strlen(eq+1));
}
}
}
/* create environment */
if (host->bin_env) {
for (i = 0; i < host->bin_env->used; ++i) {
data_string *ds = (data_string *)host->bin_env->data[i];
env_add(&env, CONST_BUF_LEN(&ds->key),
CONST_BUF_LEN(&ds->value));
}
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
}
for (i = 0; i < env.used; ++i) {
/* search for PHP_FCGI_CHILDREN */
if (0 == strncmp(env.ptr[i], "PHP_FCGI_CHILDREN=",
sizeof("PHP_FCGI_CHILDREN=")-1)) {
break;
}
}
/* not found, add a default */
if (i == env.used) {
env_add(&env, CONST_STR_LEN("PHP_FCGI_CHILDREN"),
CONST_STR_LEN("1"));
}
env.ptr[env.used] = NULL;
}
dfd = fdevent_open_dirname(host->args.ptr[0], 1); /* permit symlinks */
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (-1 == dfd) {
log_error_write(srv, __FILE__, __LINE__, "sss",
"open dirname failed:", strerror(errno),
host->args.ptr[0]);
}
/*(FCGI_LISTENSOCK_FILENO == STDIN_FILENO == 0)*/
proc->pid = (dfd >= 0)
? fdevent_fork_execve(host->args.ptr[0], host->args.ptr,
env.ptr, gw_fd, -1, -1, dfd)
: -1;
for (i = 0; i < env.used; ++i) free(env.ptr[i]);
free(env.ptr);
if (-1 != dfd) close(dfd);
close(gw_fd);
if (-1 == proc->pid) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"gw-backend failed to start:", host->bin_path);
proc->pid = 0;
proc->disabled_until = srv->cur_ts;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
return -1;
}
/* register process */
proc->last_used = srv->cur_ts;
proc->is_local = 1;
/* wait */
select(0, NULL, NULL, NULL, &tv);
if (0 != gw_proc_waitpid(srv, host, proc)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"gw-backend failed to start:", host->bin_path);
log_error_write(srv, __FILE__, __LINE__, "s",
"If you're trying to run your app as a FastCGI backend, make "
"sure you're using the FastCGI-enabled version. If this is PHP "
"on Gentoo, add 'fastcgi' to the USE flags. If this is PHP, try "
"removing the bytecode caches for now and try again.");
return -1;
}
} else {
proc->is_local = 0;
proc->pid = 0;
if (debug) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"(debug) socket is already used; won't spawn:",
proc->connection_name);
}
}
gw_proc_set_state(host, proc, PROC_STATE_RUNNING);
return 0;
}
static void gw_proc_spawn(server *srv, gw_host *host, int debug) {
gw_proc *proc;
for (proc = host->unused_procs; proc; proc = proc->next) {
/* (proc->pid <= 0 indicates PROC_STATE_DIED, not PROC_STATE_KILLED) */
if (proc->pid > 0) continue;
/* (do not attempt to spawn another proc if a proc just exited) */
if (proc->disabled_until >= srv->cur_ts) return;
break;
}
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (proc) {
if (proc == host->unused_procs)
host->unused_procs = proc->next;
else
proc->prev->next = proc->next;
if (proc->next) {
proc->next->prev = proc->prev;
proc->next = NULL;
}
proc->prev = NULL;
} else {
proc = gw_proc_init();
proc->id = host->max_id++;
}
++host->num_procs;
if (buffer_string_is_empty(host->unixsocket)) {
proc->port = host->port + proc->id;
} else {
buffer_copy_buffer(proc->unixsocket, host->unixsocket);
buffer_append_string_len(proc->unixsocket, CONST_STR_LEN("-"));
buffer_append_int(proc->unixsocket, proc->id);
}
if (0 != gw_proc_sockaddr_init(srv, host, proc)) {
/*(should not happen if host->host validated at startup,
* and translated from name to IP address at startup)*/
log_error_write(srv, __FILE__, __LINE__, "s",
"ERROR: spawning backend failed.");
--host->num_procs;
if (proc->id == host->max_id-1) --host->max_id;
gw_proc_free(proc);
} else if (gw_spawn_connection(srv, host, proc, debug)) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
log_error_write(srv, __FILE__, __LINE__, "s",
"ERROR: spawning backend failed.");
proc->next = host->unused_procs;
if (host->unused_procs)
host->unused_procs->prev = proc;
host->unused_procs = proc;
} else {
proc->next = host->first;
if (host->first)
host->first->prev = proc;
host->first = proc;
}
}
static void gw_proc_kill(server *srv, gw_host *host, gw_proc *proc) {
UNUSED(srv);
if (proc->next) proc->next->prev = proc->prev;
if (proc->prev) proc->prev->next = proc->next;
if (proc->prev == NULL) host->first = proc->next;
proc->prev = NULL;
proc->next = host->unused_procs;
proc->disabled_until = 0;
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
if (host->unused_procs)
host->unused_procs->prev = proc;
host->unused_procs = proc;
kill(proc->pid, host->kill_signal);
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
gw_proc_set_state(host, proc, PROC_STATE_KILLED);
--host->num_procs;
}
static gw_host * unixsocket_is_dup(gw_plugin_data *p, const buffer *unixsocket) {
if (NULL == p->cvlist) return NULL;
/* (init i to 0 if global context; to 1 to skip empty global context) */
for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) {
config_plugin_value_t *cpv = p->cvlist + p->cvlist[i].v.u2[0];
gw_plugin_config *conf = NULL;
for (; -1 != cpv->k_id; ++cpv) {
switch (cpv->k_id) {
case 0: /* xxxxx.server */
if (cpv->vtype == T_CONFIG_LOCAL) conf = cpv->v.v;
break;
default:
break;
}
}
if (NULL == conf || NULL == conf->exts) continue;
gw_exts *exts = conf->exts;
for (uint32_t j = 0; j < exts->used; ++j) {
gw_extension *ex = exts->exts+j;
for (uint32_t n = 0; n < ex->used; ++n) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
gw_host *host = ex->hosts[n];
if (!buffer_string_is_empty(host->unixsocket)
&& buffer_is_equal(host->unixsocket, unixsocket)
&& !buffer_string_is_empty(host->bin_path))
return host;
}
}
}
return NULL;
}
static int parse_binpath(char_array *env, const buffer *b) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
char *start = b->ptr;
char c;
/* search for spaces */
for (size_t i = 0; i < buffer_string_length(b); ++i) {
switch(b->ptr[i]) {
case ' ':
case '\t':
/* a WS, stop here and copy the argument */
if (env->size == env->used) {
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
env->size += 16;
env->ptr = realloc(env->ptr, env->size * sizeof(*env->ptr));
}
c = b->ptr[i];
b->ptr[i] = '\0';
env->ptr[env->used++] = strdup(start);
b->ptr[i] = c;
start = b->ptr + i + 1;
break;
default:
break;
}
}
if (env->size == env->used) { /*need one extra for terminating NULL*/
[core] shared code for socket backends common codebase for socket backends, based off mod_fastcgi with some features added for mod_proxy (mostly intended to reduce code duplication and enhance code isolation) mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance for similar behavior as proxy.balance, but the balancing is per-host and not per-proc. proxy.balance is also per-host and not per-proc. mod_proxy and mod_scgi can now use proxy.map-extensions and scgi.map-extensions, similar to fastcgi.map-extensions. mod_fastcgi behavior change (affects only mod_status): - statistics tags have been renamed from &#34;fastcgi.*&#34; to &#34;gw.*&#34; &#34;fastcgi.backend.*&#34; -&gt; &#34;gw.backend.*&#34; &#34;fastcgi.active-requests&#34; -&gt; &#34;gw.active-requests&#34; (&#34;fastcgi.requests&#34; remains &#34;fastcgi.requests&#34;) (&#34;proxy.requests&#34; is new) (&#34;scgi.requests&#34; is new) mod_scgi behavior change (likely minor): - removed scgi_proclist_sort_down() and scgi_proclist_sort_up(). procs now chosen based on load as measured by num socket connnections Note: modules using gw_backend.[ch] are currently still independent modules. If it had been written as a single module with fastcgi, scgi, proxy implementations, then there would have been a chance of breaking some existing user configurations where module ordering made a difference for which module handled a given request, though for most people, this would have made no difference. Details about mod_fastcgi code transformations: unsigned int debug -&gt; int debug fastcgi_env member removed from plugin_config renamed &#34;fcgi&#34; and &#34;fastcgi&#34; to &#34;gw&#34;, and &#34;FCGI&#34; to &#34;GW&#34; reorganize routines for high-level and lower-level interfaces some lower-level internal interfaces changed to use host,proc,debug args rather than knowing about higher-level (app) hctx and plugin_data tabs-&gt;spaces and reformatting
4 years ago
env->size += 16;