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.
This commit is contained in:
rofl0r 2017-11-04 19:26:41 +00:00 committed by Michael Adam
parent d97d486d53
commit 64b29c5f4e
2 changed files with 3 additions and 2 deletions

View File

@ -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"

View File

@ -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));