Added system logging for important errors
* Messages with "fatal" or "error" log level are now also passed to syslogd service with help of vsyslog() function. * On systems that use syslog service, these messages will be available in default system log files like /var/log/syslog or /var/log/messages.
This commit is contained in:
parent
dfd885c011
commit
d74e60b6a7
2 changed files with 25 additions and 2 deletions
|
@ -29,8 +29,8 @@ dnl Overwrite default archiver flags.
|
|||
AC_SUBST(AR_FLAGS, [cr])
|
||||
|
||||
dnl Check for header files that do not exist on all platforms
|
||||
AC_CHECK_HEADERS([libutil.h pthread.h pty.h strings.h sys/prctl.h sys/uio.h \
|
||||
util.h utmp.h utmpx.h])
|
||||
AC_CHECK_HEADERS([libutil.h pthread.h pty.h strings.h syslog.h sys/prctl.h \
|
||||
sys/uio.h util.h utmp.h utmpx.h])
|
||||
|
||||
dnl Most systems require linking against libutil.so in order to get login_tty()
|
||||
AC_CHECK_FUNCS(login_tty, [],
|
||||
|
@ -41,6 +41,9 @@ AC_CHECK_FUNCS(login_tty, [],
|
|||
dnl Use strlcat() instead of strncat() to avoid spurious warnings
|
||||
AC_CHECK_FUNCS([strlcat])
|
||||
|
||||
dnl Use vsyslog() for logging important error messages
|
||||
AC_CHECK_FUNCS([vsyslog])
|
||||
|
||||
dnl Prefer thread-safe functions, if available
|
||||
AC_CHECK_FUNCS([getgrgid_r getgrnam_r gethostbyname_r getpwnam_r getpwuid_r \
|
||||
openpty strcasestr getresuid getresgid setresuid setresgid ])
|
||||
|
|
|
@ -52,6 +52,19 @@
|
|||
|
||||
#include "logging/logging.h"
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
# include <syslog.h>
|
||||
# ifndef HAVE_VSYSLOG
|
||||
static void vsyslog(int priority, const char *fmt, va_list ap) {
|
||||
char *s = vStringPrintf(NULL, fmt, ap);
|
||||
if (s) {
|
||||
syslog(priority, "%s", s);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static int verbosity = MSG_DEFAULT;
|
||||
|
||||
static void debugMsg(int level, const char *fmt, va_list ap) {
|
||||
|
@ -86,6 +99,9 @@ void error(const char *fmt, ...) {
|
|||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
debugMsg(MSG_ERROR, fmt, ap);
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
vsyslog(LOG_ERR, fmt, ap);
|
||||
#endif
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -100,6 +116,10 @@ void fatal(const char *fmt, ...) {
|
|||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
debugMsg(MSG_QUIET, fmt, ap);
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
vsyslog(LOG_CRIT, fmt, ap);
|
||||
syslog(LOG_CRIT, "Aborting...");
|
||||
#endif
|
||||
va_end(ap);
|
||||
_exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue