summaryrefslogtreecommitdiffhomepage
path: root/src/main.c
AgeCommit message (Collapse)Author
2020-09-30change loglevel of "Not running as root" message to INFOrofl0r
there's no reason to display this as warning.
2020-09-16main: print error when config_init() failsrofl0r
2020-09-16speed up big config parsing by 2x using gperfrofl0r
2020-09-16move config reload message to reload_config()rofl0r
move it to before disabling logging, so a message with the correct timestamp is printed if logging was already enabled. also add a message when loading finished, so one can see from the timestamp how long it took. note that this only works on a real config reload triggered by SIGHUP/SIGUSR1, because on startup we don't know yet where to log to.
2020-09-15main: include loop headerrofl0r
2020-09-15free() loop records toorofl0r
2020-09-15replace leftover users of hashmap with htabrofl0r
also fixes a bug where the ErrorFile directive would create a new hashmap on every added item, effectively allowing only the use of the last specified errornumber, and producing memory leaks on each config reload.
2020-09-15fix free()ing of config itemsrofl0r
- we need to free the config after it has been succesfully loaded, not unconditionally before reloading. - we also need to free them before exiting from the main program to have clean valgrind output.
2020-09-15shutdown: free children from right placerofl0r
2020-09-14main: orderly shutdown on SIGINT toorofl0r
the appropriate code in the signal handler was already set up, but for some reason the signal itself not being handled.
2020-09-07change loglevel of start/stop/reload messages to NOTICErofl0r
this allows to see them when the verbose INFO loglevel is not desired. closes #78
2020-09-06allow SIGUSR1 to be used as an alternative to SIGHUProfl0r
this allows a tinyproxy session in terminal foreground mode to reload its configuration without dropping active connections.
2020-09-06main.c: remove set_signal_handler code duplicationrofl0r
2020-09-06do not catch SIGHUP in foreground-moderofl0r
it's quite unexpected for an application running foreground in a terminal to keep running when the terminal is closed. also in such a case (if file logging is disabled) there's no way to see what's happening to the proxy.
2020-03-16anonymous: fix segfault loading config itemrofl0r
unlike other functions called from the config parser code, anonymous_insert() accesses the global config variable rather than passing it as an argument. however the global variable is only set after successful loading of the entire config. we fix this by adding a conf argument to each anonymous_* function, passing the global pointer in calls done from outside the config parser. fixes #292
2020-01-15conf: use 2 swappable conf slots, so old config can stay validrofl0r
... in case reloading of it after SIGHUP fails, the old config can continue working. (apart from the logging-related issue mentioned in 27d96df99900c5a62ab0fdf2a37565e78f256d6a )
2020-01-15conf: fix loading of default valuesrofl0r
previously, default values were stored once into a static struct, then on each reload item by item copied manually into a "new" config struct. this has proven to be errorprone, as additions in one of the 2 locations were not propagated to the second one, apart from being simply a lot of gratuitous code. we now simply load the default values directly into the config struct to be used on each reload. closes #283
2020-01-15remove duplicate code calling reload_config_file()rofl0r
as a side effect of not updating the config pointer when loading the config file fails, the "FIXME" level comment to take appropriate action in that case has been removed. the only issue remaining when receiving a SIGHUP and encountering a malformed config file would now be the case that output to syslog/logfile won't be resumed, if initially so configured.
2020-01-15access config via a pointer, not a hardcoded struct addressrofl0r
this is required so we can elegantly swap out an old config for a new one in the future and remove lots of boilerplate from config initialization code. unfortunately this is a quite intrusive change as the config struct was accessed in numerous places, but frankly it should have been done via a pointer right from the start. right now, we simply point to a static struct in main.c, so there shouldn't be any noticeable changes in behaviour.
2020-01-15remove config file name item from conf structrofl0r
since this is set via command line, we can deal with it easily from where it is actually needed.
2020-01-15remove godaemon member from config structurerofl0r
since this option can't be set via config file, it makes sense to factor it out and use it only where strictly needed, e.g. in startup code.
2020-01-15move commandline parsing to main()rofl0r
2020-01-15move initialize_config_defaults to conf.crofl0r
2019-12-21simplify codebase by using one thread/conn, instead of preforked procsrofl0r
the existing codebase used an elaborate and complex approach for its parallelism: 5 different config file options, namely - MaxClients - MinSpareServers - MaxSpareServers - StartServers - MaxRequestsPerChild were used to steer how (and how many) parallel processes tinyproxy would spin up at start, how many processes at each point needed to be idle, etc. it seems all preforked processes would listen on the server port and compete with each other about who would get assigned the new incoming connections. since some data needs to be shared across those processes, a half- baked "shared memory" implementation was provided for this purpose. that implementation used to use files in the filesystem, and since it had a big FIXME comment, the author was well aware of how hackish that approach was. this entire complexity is now removed. the main thread enters a loop which polls on the listening fds, then spins up a new thread per connection, until the maximum number of connections (MaxClients) is hit. this is the only of the 5 config options left after this cleanup. since threads share the same address space, the code necessary for shared memory access has been removed. this means that the other 4 mentioned config option will now produce a parse error, when encountered. currently each thread uses a hardcoded default of 256KB per thread for the thread stack size, which is quite lavish and should be sufficient for even the worst C libraries, but people may want to tweak this value to the bare minimum, thus we may provide a new config option for this purpose in the future. i suspect that on heavily optimized C libraries such a musl, a stack size of 8-16 KB per thread could be sufficient. since the existing list implementation in vector.c did not provide a way to remove a single item from an existing list, i added my own list implementation from my libulz library which offers this functionality, rather than trying to add an ad-hoc, and perhaps buggy implementation to the vector_t list code. the sblist code is contained in an 80 line C file and as simple as it can get, while offering good performance and is proven bugfree due to years of use in other projects.
2018-09-01main: remove the "-l" switch to display the license and authorsMichael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2018-02-09Fix CVE-2017-11747: Create PID file before dropping privileges.Michael Adam
Resolves #106 Signed-off-by: Michael Adam <obnox@samba.org>
2017-11-16log to stdout if no logfile specifiedrofl0r
some users want to run tinyproxy on an as-needed basis in a terminal, without setting it up permanently to run as a daemon/service. in such use case, it is very annoying that tinyproxy didn't have an option to log to stdout, so the user has to keep a second terminal open to `tail -f` the log. additionally, this precluded usage with runit service supervisor, which runs all services in foreground and creates logfiles from the service's stdout/stderr. since logging to stdout doesn't make sense when daemonized, now if no logfile is specified and daemon mode activated, a warning is printed to stderr once, and nothing is logged. the original idea was to fail with an error message, though some users might actually want to run tinyproxy as daemon and no logging at all.
2017-11-16do not create a pidfile, if none is specified in configrofl0r
some people want to run tinyproxy with minimal configuration from the command line (and as non-root), but tinyproxy insists on writing a pid file, which only makes sense for usage as a service, hereby forcing the user to either run it as root so it can write to the default location, or start editing the default config file to work around it. and if no pidfile is specified in the config, it frankly doesn't make sense to force creation of one anyway.
2016-01-03update URLrofl0r
2013-11-09[BB#63] conf: Allow multiple Listen statements in the config.Michael Adam
This introduces a list (vector) of addresses instead of having just one address string. Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09child: add addr argument to child_listening_sock().Michael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-01[BB#115] Drop supplementary groupsGaudenz Steinlin
Supplementary groups are inherited from the calling process. Drop all supplementary groups if the "Group" configuration directive is set to change to a different user. Otherwise the process may have more rights than expected. Reviewed-by: Michael Adam <obnox@samba.org>
2011-02-28Update URLs of TinyproxyMukund Sivaraman
2010-06-02[BB#74] Create log and pid files after we drop privsMukund Sivaraman
2010-06-02Remove excessive codeMukund Sivaraman
2010-06-01[BB#89] Don't recompile regular expressionsJohn van der Kamp
This is a modification of a patch originally written by John van der Kamp <john@kirika.demon.nl> at <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579427#12> The modification was done by the committer.
2010-04-21Revert "main: drop privileges right after reading the config"Mukund Sivaraman
This reverts commit 7a9abc2a04dd8ed1f113aa9c803af24adfb22773. It should fix the issue in bug #87.
2010-03-28Just fix the support URLsMukund Sivaraman
2010-03-28Revert "Update Tinyproxy website URLs"Mukund Sivaraman
This reverts commit b108162dfb408b4818a6ea8b2a148ddaf1506bbe.
2010-03-27Update Tinyproxy website URLsMukund Sivaraman
2010-03-02change the default pid file location to ↵Michael Adam
"@LOCALSTATEDIR@/run/tinyproxy/tinyproxy.pid" I.e., add a tinyproxy subdirectory. This is meant to ease running tinyproxy as non-root user. The subdirectory can be used to give the tinyproxy user write permission. Michael
2010-03-02change the default log file location to ↵Michael Adam
"@LOCALSTATEDIR@/log/tinyproxy/tinyproxy.log" i.e. add a tinyproxy subdirectory. This is meant to ease running tinyproxy as non-root user the subdirectory can be used to give the tinyproxy user write permission. Michael
2010-03-02main: some tabs->spacesMichael Adam
2010-03-02main: move a log message.Michael Adam
2010-03-02main: drop privileges right after reading the configMichael Adam
This is the second part of fixing bug #74. I lets tinyproxy create its log and pid files as the user as which it is running, so that later on at SIGHUP, the log file can successfully be reopened. Michael
2010-03-02main: separate loading of config and setup_logging at startupMichael Adam
This is the first part of a fix for bug #74 (making reloading of config work if running as non-privileged user) Michael
2010-02-17Display upstream proxy support in usage messageMukund Sivaraman
2010-02-17Update help text a littleMukund Sivaraman
2010-01-19Change to for loopMukund Sivaraman
2010-01-18Show authors and documenters when license is requestedMukund Sivaraman