From 3662afc79319c1920e53c049a26badec3b522b37 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sat, 4 Nov 2017 19:26:41 +0000 Subject: [PATCH 1/2] do not create a pidfile, if none is specified in config 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. --- etc/tinyproxy.conf.in | 1 + src/main.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/etc/tinyproxy.conf.in b/etc/tinyproxy.conf.in index e24ad4a..09c883a 100644 --- a/etc/tinyproxy.conf.in +++ b/etc/tinyproxy.conf.in @@ -121,6 +121,7 @@ LogLevel Info # # PidFile: Write the PID of the main tinyproxy thread to this file so it # can be used for signalling purposes. +# If not specified, no pidfile will be written. # #PidFile "@localstatedir@/run/tinyproxy/tinyproxy.pid" diff --git a/src/main.c b/src/main.c index ae2a3a8..50cacca 100644 --- a/src/main.c +++ b/src/main.c @@ -356,7 +356,7 @@ static void initialize_config_defaults (struct config_s *conf) conf->stathost = safestrdup (TINYPROXY_STATHOST); conf->idletimeout = MAX_IDLE_TIME; conf->logf_name = safestrdup (LOCALSTATEDIR "/log/tinyproxy/tinyproxy.log"); - conf->pidpath = safestrdup (LOCALSTATEDIR "/run/tinyproxy/tinyproxy.pid"); + conf->pidpath = NULL; } /** @@ -496,7 +496,7 @@ main (int argc, char **argv) child_close_sock (); /* Remove the PID file */ - if (unlink (config.pidpath) < 0) { + if (config.pidpath != NULL && unlink (config.pidpath) < 0) { log_message (LOG_WARNING, "Could not remove PID file \"%s\": %s.", config.pidpath, strerror (errno)); From 2edfc38b8e6043866212832b7f07619b9cb9e8e7 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sat, 4 Nov 2017 19:40:42 +0000 Subject: [PATCH 2/2] log to stdout if not running as daemon 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. --- src/log.c | 7 +++++-- src/main.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/log.c b/src/log.c index f5a0b44..2a3c6d8 100644 --- a/src/log.c +++ b/src/log.c @@ -70,7 +70,10 @@ static unsigned int logging_initialized = FALSE; /* boolean */ */ int open_log_file (const char *log_file_name) { - log_file_fd = create_file_safely (log_file_name, FALSE); + if (config.godaemon == FALSE) + log_file_fd = fileno(stdout); + else + log_file_fd = create_file_safely (log_file_name, FALSE); return log_file_fd; } @@ -79,7 +82,7 @@ int open_log_file (const char *log_file_name) */ void close_log_file (void) { - if (log_file_fd < 0) { + if (log_file_fd < 0 || log_file_fd == fileno(stdout)) { return; } diff --git a/src/main.c b/src/main.c index 50cacca..f606627 100644 --- a/src/main.c +++ b/src/main.c @@ -147,7 +147,7 @@ display_usage (void) printf ("Usage: %s [options]\n", PACKAGE); printf ("\n" "Options are:\n" - " -d Do not daemonize (run in foreground).\n" + " -d Do not daemonize (run in foreground, log to stdout).\n" " -c FILE Use an alternate configuration file.\n" " -h Display this usage information.\n" " -l Display the license.\n"