xref: /netbsd-src/external/bsd/ntp/dist/sntp/log.c (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1*eabc0478Schristos /*	$NetBSD: log.c,v 1.12 2024/08/18 20:47:20 christos Exp $	*/
23123f114Skardel 
33123f114Skardel #include <config.h>
4abb0f93cSkardel 
5abb0f93cSkardel #include "log.h"
6abb0f93cSkardel 
7*eabc0478Schristos extern const char *progname;		/* for msyslog use too */
8af12ab5eSchristos 
9af12ab5eSchristos static int counter = 0;
10abb0f93cSkardel 
113123f114Skardel static void cleanup_log(void);
12abb0f93cSkardel 
133123f114Skardel void
142950cc38Schristos sntp_init_logging(
152950cc38Schristos 	const char *prog
162950cc38Schristos 	)
173123f114Skardel {
18af12ab5eSchristos 
193123f114Skardel 	msyslog_term = TRUE;
202950cc38Schristos 	init_logging(prog, 0, FALSE);
212950cc38Schristos 	msyslog_term_pid = FALSE;
222950cc38Schristos 	msyslog_include_timestamp = FALSE;
23abb0f93cSkardel }
24abb0f93cSkardel 
253123f114Skardel void
263123f114Skardel open_logfile(
27abb0f93cSkardel 	const char *logfile
28abb0f93cSkardel 	)
29abb0f93cSkardel {
302950cc38Schristos 	change_logfile(logfile, FALSE);
31af12ab5eSchristos 	counter = 1; //counter++;
32abb0f93cSkardel 	atexit(cleanup_log);
33abb0f93cSkardel }
34abb0f93cSkardel 
35af12ab5eSchristos //not sure about this. Are the atexit() functions called by FIFO or LIFO order? The end result is PROBABLY the same
363123f114Skardel static void
373123f114Skardel cleanup_log(void)
383123f114Skardel {
39af12ab5eSchristos 	//counter--;
40af12ab5eSchristos 	//if(counter <= 0){
41af12ab5eSchristos 	if(counter == 1){
423123f114Skardel 		syslogit = TRUE;
433123f114Skardel 		fflush(syslog_file);
443123f114Skardel 		fclose(syslog_file);
453123f114Skardel 		syslog_file = NULL;
46af12ab5eSchristos 		counter = 0;
47af12ab5eSchristos 	}
48abb0f93cSkardel }
49