xref: /netbsd-src/external/bsd/ntp/dist/sntp/log.c (revision ba65fde2d7fefa7d39838fa5fa855e62bd606b5e)
1 /*	$NetBSD: log.c,v 1.5 2012/02/01 20:48:01 kardel Exp $	*/
2 
3 #include <config.h>
4 
5 #include "log.h"
6 
7 const char *progname = "sntp";	/* for msyslog use too */
8 
9 static void cleanup_log(void);
10 
11 void
12 init_logging(void)
13 {
14 	openlog(progname, LOG_PID | LOG_CONS, OPENLOG_FAC);
15 	msyslog_term = TRUE;
16 }
17 
18 void
19 open_logfile(
20 	const char *logfile
21 	)
22 {
23 	syslog_file = fopen(logfile, "a");
24 	if (syslog_file == NULL) {
25 		msyslog(LOG_ERR, "sntp: Cannot open logfile %s",
26 			logfile);
27 		return;
28 	}
29 	syslogit = FALSE;
30 	atexit(cleanup_log);
31 }
32 
33 
34 static void
35 cleanup_log(void)
36 {
37 	syslogit = TRUE;
38 	fflush(syslog_file);
39 	fclose(syslog_file);
40 	syslog_file = NULL;
41 }
42