Commit Graph

139 Commits

Author SHA1 Message Date
Omar Polo 8a50fc0330 initialize the logger early
Initialize the logger as soon as possible and log by default to
stderr.  With this, some (common?) errors are printed early instead of
ending up in syslog.

	# NB: this is in configless mode
	% ./gmid -p 80
	[2021-07-07 11:05:57] bind: Address already in use
	% ./gmid -p 81
	[2021-07-07 11:13:53] bind: Permission denied
	%
2021-07-07 09:18:24 +00:00
Omar Polo 090b8a89fa gracefully shut down fastcgi backends
we need to delete the events associated with the backends, otherwise
the server process won't ever quit.

Here, we add a pending counter to every backend and shut down
immediately if they aren't handling any client; otherwise we try to
close them as soon as possible (i.e. when they close the connection to
the last connected client.)
2021-07-06 10:54:27 +00:00
Omar Polo ef945cf415 reset fcgi array in free_config
otherwise path, port and/or prog could become an invalid pointer.
2021-07-06 10:46:50 +00:00
Omar Polo f98e9045ae add -D to define macros from the cmd line 2021-06-29 12:39:34 +00:00
Omar Polo 0be2a537e6 sync the usage; while there also change order and capitalize 2021-06-29 11:04:29 +00:00
Omar Polo fdb43a4c0e define GMID_STRING and reuse-it
GMID_VERSION follows the CGI/FastCGI style, i.e. project_name/version.

Define GMID_STRING with a more "human" variant "project_name version",
and reuse that in the --help and --version codepath.
2021-06-29 10:56:07 +00:00
Omar Polo 0233b0f6b9 add version in usage 2021-06-29 10:51:42 +00:00
Omar Polo 9327bc045a use getprogname() in usage() 2021-06-29 10:50:39 +00:00
Omar Polo 5777923bb0 use getopt_long, add --help as synonym of -h and -V/--version 2021-06-29 10:49:59 +00:00
Omar Polo e952c5052a allow sending fd to log on to the logger process
the logger process now can receive a file descriptor to write logs
to.  At the moment the logic is simple, if it receives a file it logs
there, otherwise it logs to syslog.  This will allow to log on custom
log files.
2021-06-15 08:06:10 +00:00
Omar Polo ab1e0169b9 free fastcgi param list 2021-06-12 10:20:36 +00:00
Omar Polo 3b33eab3ad TAILQ_REMOVE env and aliases during config_free
it's not technically required, since a couple of lines below we free
whole host struct, and we don't have code that may use
h->{env,aliases} afterwards, but it's nice not to have invalid
pointers around.  it may bite in the future.
2021-06-12 10:19:17 +00:00
Omar Polo 8ad1c57024 fastcgi: a first implementation
Not production-ready yet, but it's a start.

This adds a third ``backend'' for gmid: until now there it served
local files or CGI scripts, now FastCGI applications too.

FastCGI is meant to be an improvement over CGI: instead of exec'ing a
script for every request, it allows to open a single connection to an
``application'' and send the requests/receive the responses over that
socket using a simple binary protocol.

At the moment gmid supports three different methods of opening a
fastcgi connection:

 - local unix sockets, with: fastcgi "/path/to/sock"
 - network sockets, with: fastcgi tcp "host" [port]
   port defaults to 9000 and can be either a string or a number
 - subprocess, with: fastcgi spawn "/path/to/program"
   the fastcgi protocol is done over the executed program stdin

of these, the last is only for testing and may be removed in the
future.

P.S.: the fastcgi rule is per-location of course :)
2021-05-09 18:23:36 +00:00
Omar Polo 7b2d743260 move pidfile & cgi to global vars 2021-05-01 12:17:42 +00:00
Omar Polo fdea6aa0bc allow ``root'' rule to be specified per-location block 2021-04-30 17:16:34 +00:00
Omar Polo cc8c2901ad added ``alias'' option to define hostname aliases for a server 2021-04-29 18:23:35 +00:00
Omar Polo 8e8b2e252c pidfile support with `-P pidfile' 2021-04-28 12:45:22 +00:00
Omar Polo 48b69cb2dc fix some logging
- we can't use log_* or fatal() before logger_init
- err -> errx if errno isn't involved
2021-04-28 12:43:17 +00:00
Omar Polo 9cc630aa63 added ``env'' option to define environment vars for CGI scripts 2021-04-28 12:43:17 +00:00
Omar Polo 419a423520 keep verbosity level after config reload 2021-04-28 12:42:36 +00:00
Omar Polo 1b333122a9 typo 2021-04-26 20:58:06 +00:00
Omar Polo 5d1474a561 typo in comment 2021-04-20 09:53:33 +00:00
Omar Polo 3841a36930 restore signal handlers before exec'ing CGI scripts 2021-04-20 09:53:03 +00:00
Omar Polo b8e64ccd44 list instead of fixed-size array for vhosts and locations
saves some bytes of memory and removes the limit on the maximum number
of vhosts and location blocks.
2021-03-31 16:32:18 +00:00
Omar Polo 7e1df73d7d fix mkdirs: create directories recursively 2021-03-31 13:56:58 +00:00
Omar Polo 8e09ee1d50 typo 2021-03-20 10:48:11 +00:00
Omar Polo b9c9123b8e fix signal handling so it works on linux too
it seems that linux calls the signal handlers even when we're waiting
on sigwait for that signal.  Work around that.
2021-03-20 10:43:23 +00:00
Omar Polo d632468df5 fix correct shutdown after SIG{INT,TERM} 2021-03-20 09:23:53 +00:00
Omar Polo 1d3eb470b0 quit every process cleanly when receiving SIGINT or SIGTERM 2021-03-20 08:51:17 +00:00
Omar Polo bc99d868bc refactoring: imsg everywhere
use imsg to handle ALL kinds of IPC in gmid.  This simplifies and shorten the
code, and  makes everything more uniform too.
2021-03-19 19:21:29 +00:00
Omar Polo dbe262a45d split usage string into two lines 2021-03-03 17:51:42 +00:00
Omar Polo 2c3e53dac6 give each server process its own socket for the executor
this fixes a bug introduced with the prefork mechanics: every server
process shared the same socket, and this would cause a race condition
when multiple server processes asked for a script cgi being executed.

This gives each server process its own socket to talk to the executor,
so the race cannot happen.
2021-03-03 17:22:01 +00:00
Omar Polo 376a540764
move log_init & vars to gmid.c, retain logger_main in log.c
this is to let the regression suite compile
2021-02-23 13:44:20 +01:00
Omar Polo d278a0c3c5
moving logging to its own process 2021-02-23 13:40:59 +01:00
Omar Polo 52418c8d82 fix various compilation errors
Include gmid.h as first header in every file, as it then includes
config.h (that defines _GNU_SOURCE for instance).

Fix also a warning about unsigned vs signed const char pointers in
openssl.
2021-02-12 12:47:20 +00:00
Omar Polo aa37287565 add newline after usage 2021-02-10 17:58:43 +00:00
Omar Polo df58efff26 fix seccomp for the new event loop
add/remove syscalls from the BPF filter and move sandbox() after
libevent initialisation
2021-02-08 12:46:46 +00:00
Omar Polo 3abf91b0b4 improve logs management 2021-02-07 15:30:28 +00:00
Omar Polo a709ddf5eb added prefork option 2021-02-07 12:05:32 +00:00
Omar Polo e3ddf39095 add the ``entrypoint'' option 2021-02-06 18:28:43 +00:00
Omar Polo 6abda252e9 added ``block return'' and ``strip'' options 2021-02-06 17:22:37 +00:00
Omar Polo 102d2e9cce missing argument for LOGI 2021-02-04 18:09:42 +00:00
Omar Polo 9543e3fbaf avoid race-condition
what if we receive a SIGHUP right after unblock_signal (or during the
whole block_signals...unblock_signals) but *before* the wait_sighup?
Yeah.
2021-02-04 18:09:30 +00:00
Omar Polo ca21e10043 reload configuration on SIGHUP 2021-02-04 13:23:15 +00:00
Omar Polo e824d03efa drop unnecessary check around close 2021-02-03 16:53:34 +00:00
Omar Polo 4e2e2ab1d3 refactor executor_main
now it's symmetrical to listener_main().
2021-02-03 16:37:53 +00:00
Omar Polo d672b8fba1 refactoring startup logic 2021-02-03 16:28:00 +00:00
Omar Polo 9edb828251 drop privileges after the fork 2021-02-03 14:13:32 +00:00
Omar Polo 3c680bddab configless: fixing the case of the implicit "."
I got bitten by the scope visibility rules.  After the end of the
block, the path variable is no longer valid, and in fact later
load_vhosts fails to open that (because the buffer gets invalidated)
2021-02-02 09:30:24 +00:00
Omar Polo bcf5d929e6 ensure absolute paths in config-less mode 2021-02-01 11:07:57 +00:00