xref: /netbsd-src/external/bsd/ntp/dist/sntp/log.c (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1 /*	$NetBSD: log.c,v 1.12 2024/08/18 20:47:20 christos Exp $	*/
2 
3 #include <config.h>
4 
5 #include "log.h"
6 
7 extern const char *progname;		/* for msyslog use too */
8 
9 static int counter = 0;
10 
11 static void cleanup_log(void);
12 
13 void
14 sntp_init_logging(
15 	const char *prog
16 	)
17 {
18 
19 	msyslog_term = TRUE;
20 	init_logging(prog, 0, FALSE);
21 	msyslog_term_pid = FALSE;
22 	msyslog_include_timestamp = FALSE;
23 }
24 
25 void
26 open_logfile(
27 	const char *logfile
28 	)
29 {
30 	change_logfile(logfile, FALSE);
31 	counter = 1; //counter++;
32 	atexit(cleanup_log);
33 }
34 
35 //not sure about this. Are the atexit() functions called by FIFO or LIFO order? The end result is PROBABLY the same
36 static void
37 cleanup_log(void)
38 {
39 	//counter--;
40 	//if(counter <= 0){
41 	if(counter == 1){
42 		syslogit = TRUE;
43 		fflush(syslog_file);
44 		fclose(syslog_file);
45 		syslog_file = NULL;
46 		counter = 0;
47 	}
48 }
49