From 9f870a11218d0bc6364d6b333fd878106746adf9 Mon Sep 17 00:00:00 2001 From: Robert Norris Date: Sun, 5 Mar 2017 18:43:33 +0000 Subject: OS syslog compatibility fallback. Mainly for Windows systems which doesn't have syslog(). Implement simple fallback to print to stderr, rather than a more complicated use of Windows Event Log. Also basic fallbacks for openlog() and closelog() which don't really do anything. TESTED: Functions build on Windows cross build 'scons build-all check' passes on Linux Signed-off-by: Fred Wright --- os_compat.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'os_compat.h') diff --git a/os_compat.h b/os_compat.h index 00e56559..9321809f 100644 --- a/os_compat.h +++ b/os_compat.h @@ -57,6 +57,38 @@ int clock_gettime(clockid_t, struct timespec *); int os_daemon(int nochdir, int noclose); + +#ifdef HAVE_SYSLOG_H +#include +#else +/* + * Substitutes for syslog functions + * (only subset of defines used by gpsd components listed) + * + */ +/* Copy of syslog.h defines when otherwise not available */ +/* priorities (these are ordered) */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ +/* Option flags for openlog */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_PERROR 0x20 /* log to stderr as well */ +/* facility codes */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_DAEMON (3<<3) /* system daemons */ + +void syslog(int priority, const char *format, ...); +void openlog(const char *__ident, int __option, int __facility); +void closelog(void); +#endif /* !HAVE_SYSLOG_H */ + + /* Provide BSD strlcat()/strlcpy() on platforms that don't have it */ #ifndef HAVE_STRLCAT -- cgit v1.2.1