2 * msyslog - either send a message to the terminal or print it on
5 * Converted to use varargs, much better ... jks
12 #ifdef HAVE_SYS_TYPES_H
13 # include <sys/types.h>
21 #include "ntp_types.h"
22 #include "ntp_string.h"
23 #include "ntp_stdlib.h"
24 #include "ntp_syslog.h"
27 # include "..\ports\winnt\libntp\log.h"
28 # include "..\ports\winnt\libntp\messages.h"
33 FILE *syslog_file = NULL;
35 u_long ntp_syslogmask = ~ (u_long) 0;
39 LPTSTR lpszStrings[1];
40 static WORD event_type[] = {
41 EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
42 EVENTLOG_WARNING_TYPE,
43 EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
45 #endif /* SYS_WINNT */
46 extern char *progname;
48 #if defined(__STDC__) || defined(HAVE_STDARG_H)
49 void msyslog(int level, const char *fmt, ...)
50 #else /* defined(__STDC__) || defined(HAVE_STDARG_H) */
52 void msyslog(va_alist)
54 #endif /* defined(__STDC__) || defined(HAVE_STDARG_H) */
56 #if defined(__STDC__) || defined(HAVE_STDARG_H)
62 char buf[1025], nfmt[256];
67 register char *n, *prog;
68 register const char *f;
69 #ifdef CHAR_SYS_ERRLIST
71 extern char *sys_errlist[];
76 #if defined(__STDC__) || defined(HAVE_STDARG_H)
81 level = va_arg(ap, int);
82 fmt = va_arg(ap, char *);
88 while ((c = *f++) != '\0' && c != '\n' && n < &nfmt[252]) {
93 if ((c = *f++) != 'm') {
99 #if !defined(VMS) && !defined(SYS_WINNT) && !defined (SYS_VXWORKS)
100 if ((unsigned)olderrno > sys_nerr)
101 sprintf((char *)(err = xerr), "error %d", olderrno);
103 err = (char*)sys_errlist[olderrno];
104 #elif defined(VMS) || defined (SYS_VXWORKS)
105 err = strerror(olderrno);
106 #else /* SYS_WINNT */
109 FORMAT_MESSAGE_FROM_SYSTEM,
112 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
117 #endif /* VMS && SYS_WINNT */
118 if ((n + strlen(err)) < &nfmt[254]) {
129 vsprintf(buf, nfmt, ap);
130 #if !defined(VMS) && !defined (SYS_VXWORKS)
133 syslog(level, "%s", buf);
136 lpszStrings[0] = buf;
138 switch (event_type[level])
140 case EVENTLOG_ERROR_TYPE:
141 reportAnEEvent(NTP_ERROR,1,lpszStrings);
143 case EVENTLOG_INFORMATION_TYPE:
144 reportAnIEvent(NTP_INFO,1,lpszStrings);
146 case EVENTLOG_WARNING_TYPE:
147 reportAnWEvent(NTP_WARNING,1,lpszStrings);
152 #endif /* SYS_WINNT */
154 #endif /* VMS && SYS_VXWORKS*/
156 FILE *out_file = syslog_file ? syslog_file
157 : level <= LOG_ERR ? stderr : stdout;
158 /* syslog() provides the timestamp, so if we're not using
159 syslog, we must provide it. */
160 prog = strrchr(progname, '/');
165 (void) fprintf(out_file, "%s ", humanlogtime ());
166 (void) fprintf(out_file, "%s[%d]: %s", prog, (int)getpid(), buf);