Allow overriding logfile and pidfile path from command line.
This commit is contained in:
parent
cb6f868739
commit
34b4c8ef8c
@ -40,9 +40,15 @@ OPTIONS
|
|||||||
*-h*::
|
*-h*::
|
||||||
Display a short help screen of command line arguments and exit.
|
Display a short help screen of command line arguments and exit.
|
||||||
|
|
||||||
*-l*::
|
*-L*::
|
||||||
Display the licensing agreement.
|
Display the licensing agreement.
|
||||||
|
|
||||||
|
*-l <logfile>*::
|
||||||
|
Set log file path. Overrides configuration file *LogFile* directive.
|
||||||
|
|
||||||
|
*-p <pidfile>*::
|
||||||
|
Set pidfile path. Overrides configuration file *PidFile* directive.
|
||||||
|
|
||||||
*-v*::
|
*-v*::
|
||||||
Display version information and exit.
|
Display version information and exit.
|
||||||
|
|
||||||
|
30
src/conf.c
30
src/conf.c
@ -542,7 +542,7 @@ static void initialize_with_defaults (struct config_s *conf,
|
|||||||
* Load the configuration.
|
* Load the configuration.
|
||||||
*/
|
*/
|
||||||
int reload_config_file (const char *config_fname, struct config_s *conf,
|
int reload_config_file (const char *config_fname, struct config_s *conf,
|
||||||
struct config_s *defaults)
|
struct config_s *defaults, struct config_s *overrides)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -582,6 +582,34 @@ int reload_config_file (const char *config_fname, struct config_s *conf,
|
|||||||
conf->idletimeout = MAX_IDLE_TIME;
|
conf->idletimeout = MAX_IDLE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy overridable values. */
|
||||||
|
if (overrides->logf_name != NULL) {
|
||||||
|
if (conf->logf_name != NULL) {
|
||||||
|
safefree (conf->logf_name);
|
||||||
|
}
|
||||||
|
conf->logf_name = safestrdup (overrides->logf_name);
|
||||||
|
if (!conf->logf_name) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: Could not allocate memory.\n",
|
||||||
|
PACKAGE);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
conf->syslog = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overrides->pidpath != NULL) {
|
||||||
|
if (conf->pidpath != NULL) {
|
||||||
|
safefree (conf->pidpath);
|
||||||
|
}
|
||||||
|
conf->pidpath = safestrdup (overrides->pidpath);
|
||||||
|
if (!conf->pidpath) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: Could not allocate memory.\n",
|
||||||
|
PACKAGE);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ struct config_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern int reload_config_file (const char *config_fname, struct config_s *conf,
|
extern int reload_config_file (const char *config_fname, struct config_s *conf,
|
||||||
struct config_s *defaults);
|
struct config_s *defaults, struct config_s *overrides);
|
||||||
|
|
||||||
int config_compile_regex (void);
|
int config_compile_regex (void);
|
||||||
|
|
||||||
|
45
src/main.c
45
src/main.c
@ -50,6 +50,7 @@
|
|||||||
*/
|
*/
|
||||||
struct config_s config;
|
struct config_s config;
|
||||||
struct config_s config_defaults;
|
struct config_s config_defaults;
|
||||||
|
struct config_s config_overrides;
|
||||||
unsigned int received_sighup = FALSE; /* boolean */
|
unsigned int received_sighup = FALSE; /* boolean */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -149,8 +150,10 @@ display_usage (void)
|
|||||||
"Options are:\n"
|
"Options are:\n"
|
||||||
" -d Do not daemonize (run in foreground).\n"
|
" -d Do not daemonize (run in foreground).\n"
|
||||||
" -c FILE Use an alternate configuration file.\n"
|
" -c FILE Use an alternate configuration file.\n"
|
||||||
|
" -l FILE Set log file path (overrides config file)\n"
|
||||||
|
" -p FILE Set pid file path (overrides config file)\n"
|
||||||
" -h Display this usage information.\n"
|
" -h Display this usage information.\n"
|
||||||
" -l Display the license.\n"
|
" -L Display the license.\n"
|
||||||
" -v Display version information.\n");
|
" -v Display version information.\n");
|
||||||
|
|
||||||
/* Display the modes compiled into tinyproxy */
|
/* Display the modes compiled into tinyproxy */
|
||||||
@ -220,17 +223,17 @@ get_id (char *str)
|
|||||||
* This function parses command line arguments.
|
* This function parses command line arguments.
|
||||||
**/
|
**/
|
||||||
static void
|
static void
|
||||||
process_cmdline (int argc, char **argv, struct config_s *conf)
|
process_cmdline (int argc, char **argv, struct config_s *conf, struct config_s *overrides)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while ((opt = getopt (argc, argv, "c:vldh")) != EOF) {
|
while ((opt = getopt (argc, argv, "c:l:p:vLdh")) != EOF) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
display_version ();
|
display_version ();
|
||||||
exit (EX_OK);
|
exit (EX_OK);
|
||||||
|
|
||||||
case 'l':
|
case 'L':
|
||||||
display_license ();
|
display_license ();
|
||||||
exit (EX_OK);
|
exit (EX_OK);
|
||||||
|
|
||||||
@ -251,6 +254,32 @@ process_cmdline (int argc, char **argv, struct config_s *conf)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
if (overrides->logf_name != NULL) {
|
||||||
|
safefree (overrides->logf_name);
|
||||||
|
}
|
||||||
|
overrides->logf_name = safestrdup (optarg);
|
||||||
|
if (!overrides->logf_name) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: Could not allocate memory.\n",
|
||||||
|
argv[0]);
|
||||||
|
exit (EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
if (overrides->pidpath != NULL) {
|
||||||
|
safefree (overrides->pidpath);
|
||||||
|
}
|
||||||
|
overrides->pidpath = safestrdup (optarg);
|
||||||
|
if (!overrides->pidpath) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"%s: Could not allocate memory.\n",
|
||||||
|
argv[0]);
|
||||||
|
exit (EX_SOFTWARE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
display_usage ();
|
display_usage ();
|
||||||
exit (EX_OK);
|
exit (EX_OK);
|
||||||
@ -370,7 +399,7 @@ int reload_config (void)
|
|||||||
shutdown_logging ();
|
shutdown_logging ();
|
||||||
|
|
||||||
ret = reload_config_file (config_defaults.config_file, &config,
|
ret = reload_config_file (config_defaults.config_file, &config,
|
||||||
&config_defaults);
|
&config_defaults, &config_overrides);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -396,11 +425,13 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
initialize_config_defaults (&config_defaults);
|
initialize_config_defaults (&config_defaults);
|
||||||
process_cmdline (argc, argv, &config_defaults);
|
memset (&config_overrides, 0, sizeof(config_overrides));
|
||||||
|
process_cmdline (argc, argv, &config_defaults, &config_overrides);
|
||||||
|
|
||||||
if (reload_config_file (config_defaults.config_file,
|
if (reload_config_file (config_defaults.config_file,
|
||||||
&config,
|
&config,
|
||||||
&config_defaults)) {
|
&config_defaults,
|
||||||
|
&config_overrides)) {
|
||||||
exit (EX_SOFTWARE);
|
exit (EX_SOFTWARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user