Ver Fonte

Alternate log file not being used soon enough

Fix for issue #109
John C. Frickson há 9 anos atrás
pai
commit
fdc9caf696
3 ficheiros alterados com 6 adições e 7 exclusões
  1. 1 0
      Changelog
  2. 1 2
      src/check_nrpe.c
  3. 4 5
      src/nrpe.c

+ 1 - 0
Changelog

@@ -7,6 +7,7 @@ x.x.x - xxxx-xx-xx
 FIXES
 - The '--log-file=' or '-g' option is missing from the help (John Frickson)
 - check_nrpe = segfault when specifying a config file (John Frickson)
+- Alternate log file not being used soon enough (John Frickson)
 
 
 3.1.0 - 2017-04-17

+ 1 - 2
src/check_nrpe.c

@@ -116,8 +116,6 @@ int main(int argc, char **argv)
 
 	result = process_arguments(argc, argv, 0);
 
-	open_log_file();
-
 	if (result != OK || show_help == TRUE || show_license == TRUE || show_version == TRUE)
 		usage(result);			/* usage() will call exit() */
 
@@ -466,6 +464,7 @@ int process_arguments(int argc, char **argv, int from_config_file)
 				break;
 			}
 			log_file = strdup(optarg);
+			open_log_file();
 			break;
 
 		default:

+ 4 - 5
src/nrpe.c

@@ -186,8 +186,6 @@ int main(int argc, char **argv)
 		return STATE_CRITICAL;
 	}
 
-	open_log_file();
-
 	if (!nasty_metachars)
 		nasty_metachars = strdup(NASTY_METACHARS);
 
@@ -651,13 +649,13 @@ void cleanup(void)
 	free_memory();				/* free all memory we allocated */
 
 	if (sigrestart == TRUE && sigshutdown == FALSE) {
+		close_log_file();
 		result = read_config_file(config_file);	/* read the config file */
 
 		if (result == ERROR) {	/* exit if there are errors... */
 			logit(LOG_ERR, "Config file '%s' contained errors, bailing out...", config_file);
 			exit(STATE_CRITICAL);
 		}
-		open_log_file();
 		return;
 	}
 
@@ -950,10 +948,11 @@ int read_config_file(char *filename)
 		else if (!strcmp(varname, "nasty_metachars"))
 			nasty_metachars = strdup(varvalue);
 
-		else if (!strcmp(varname, "log_file"))
+		else if (!strcmp(varname, "log_file")) {
 			log_file = strdup(varvalue);
+			open_log_file();
 
-		else {
+		} else {
 			logit(LOG_WARNING, "Unknown option specified in config file '%s' - Line %d\n",
 				   filename, line);
 			continue;