Use CLOCK_MONOTONIC for all our timing needs, when possible Otherwise we can malfunction if the clock warps. This depends on an unreleased adns feature, so the warning is currently not actually printed. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Closures: Provide closure_type_name This will be used in error reporting. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
log: Set log level for early logging Unless ->level is set, logging is just a no-op. We must set this twice, because the system log is used to report command line parsing errors, but the command line might increase the log level. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
logging: Move "starting" message earlier We are going to add some log messages to PHASE_RUN hooks. We want the overall startup message to come first. Doing this right after PHASE_DAEMONIZE makes sense as PHASE_DAEMONIZE now sets up logging, too. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
site: Change site->control(bool_t) to site->startup() This is only ever called with run=True. We are going to want to rely on this property. If we ever do more runtime reconfig that will be done differently. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
startup: Break out start_sites We were going to want to change when this happens. But actually it seems that is not right. Keep the commit anyway, as I think it improves clarity a bit. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
log: Provide system_log from the very start It is just too inconvenient not to have this while reading the config. Set up a default system_log which logs to stderr. When setup_log is called, system_log will be overwritten and this struct is no longer used. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Administrivia: Fix erroneous GPL3+ licence notices "version d or later" (!) Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
When turning on debug, turn on verbose too. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Copyright updates - update to GPLv3, etc. Update to GPLv3. secnet as actually installed is GPLv3+ anyway because it depends on python-ipaddr (Apache 2.0, which is GPLv2-incompatible), adns (now GPLv3+), and libgmp (now LGPLv3+). Also: * Add missing copyright notices and credits. * Get rid of old FSF street address; use URL instead. * Remove obsolete LICENCE.txt (which was for snprintf reimplementation). * Remove obsolete references to Cendio (for old ipaddr.py, now gone). Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
NEW etc.: Replace most calls to safe_realloc_ary Replace with REALLOC_ARY whenever the array object size is not 1 In subnet_list_set_len and ipset_set_len we abolish the unnecessary temporary variable `nd'. In subnet_list_set_len we also simplify the assert integer overflow condition (the division is not needed because REALLOC_ARY and hence safe_malloc_ary will check for potential multiplication overflow). Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
NEW etc.: Use NEW in all obvious places Entirely automatic conversion, using the following Perl rune: perl -i~ -pe 's#^(\s+)(\w+)=safe_malloc\(sizeof\(\*\2\),"[^"]+"\);$#$1NEW($2);#' *.c conffile.fl conffile.y Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
util: Use BSD queue.h for phase hook lists We are about to touch this code and would like something clearer to work with. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
secnet: provide will_droppriv polypath is going to want to know whether to do privsep. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
poll: Support deregistration from the main event loop The logic here is slightly subtle because of reentrancy hazards. See the comment in deregister_for_poll. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
poll: Abolish max_nfds We do not need to be advised of a static maximum, since we dynamically size the array now. Abolish the variable (which is unused) and change all the callers. No functional change. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
poll: Avoid duplicate array index counting Calculate remain from idx at the top of the loop. This avoids having to keep both remain and idx in step. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
poll: Make handling of fds array actually dynamic Previously we relied on the max_fds argument to register_for_poll being big enough and allocated an array at startup. But we are going to want to be more dynamic, so actually do the dynamic array resizing. We now start with a zero-sized array and increase it as needed. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
main loop: Use <bsd/sys/queue.h> for poll interest list This makes the code clearer, shorter and more typesafe. It is also going to make it easier to introduce deregistration. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
fds: Introduce pipe_cloexec() Replace all calls to pipe() with this new function, which checks errors for us, and also sets both fds to close-on-exec. There are some minor functional changes: * Error messages from pipe() failing are now less detailed about the context. This is not important. * The signal self-pipe is now cloexec too. This is at worst harmless. * When execing userv-ipif we rely on cloexec to close the spare copies of the pipe ends. * The stderr self-pipe spare writing end is redudantly made cloexec even though it is about to be closed shortly afterwards. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>