#include <time.h>
#include <errno.h>
#include <syslog.h>
+#include <assert.h>
#include "process.h"
bool_t secnet_is_daemon=False;
-uint32_t message_level=M_WARNING|M_ERROR|M_SECURITY|M_FATAL;
+uint32_t message_level=M_WARNING|M_ERR|M_SECURITY|M_FATAL;
struct log_if *system_log=NULL;
static void vMessage(uint32_t class, char *message, va_list args)
} else {
/* Messages go to stdout/stderr */
if (class & message_level) {
- if (class&M_FATAL || class&M_ERROR || class&M_WARNING) {
+ if (class&M_FATAL || class&M_ERR || class&M_WARNING) {
dest=stderr;
}
vfprintf(dest,message,args);
va_end(ap);
}
+static NORETURN(vfatal(int status, bool_t perror, char *message,
+ va_list args));
+
static void vfatal(int status, bool_t perror, char *message, va_list args)
{
int err;
err=errno;
enter_phase(PHASE_SHUTDOWN);
- if (perror) {
- Message(M_FATAL, "secnet fatal error: ");
- vMessage(M_FATAL, message, args);
+ Message(M_FATAL, "secnet fatal error: ");
+ vMessage(M_FATAL, message, args);
+ if (perror)
Message(M_FATAL, ": %s\n",strerror(err));
- }
- else {
- Message(M_FATAL, "secnet fatal error: ");
- vMessage(M_FATAL,message,args);
- }
+ else
+ Message(M_FATAL, "\n");
exit(status);
}
va_end(args);
}
-void cfgfatal(struct cloc loc, string_t facility, char *message, ...)
+void vcfgfatal_maybefile(FILE *maybe_f /* or 0 */, struct cloc loc,
+ string_t facility, char *message, va_list args)
{
- va_list args;
-
- va_start(args,message);
-
enter_phase(PHASE_SHUTDOWN);
- if (loc.file && loc.line) {
+ if (maybe_f && ferror(maybe_f)) {
+ assert(loc.file);
+ Message(M_FATAL, "error reading config file (%s, %s): %s",
+ facility, loc.file, strerror(errno));
+ } else if (maybe_f && feof(maybe_f)) {
+ assert(loc.file);
+ Message(M_FATAL, "unexpected end of config file (%s, %s)",
+ facility, loc.file);
+ } else if (loc.file && loc.line) {
Message(M_FATAL, "config error (%s, %s:%d): ",facility,loc.file,
loc.line);
} else if (!loc.file && loc.line) {
}
vMessage(M_FATAL,message,args);
- va_end(args);
exit(current_phase);
}
+void cfgfatal_maybefile(FILE *maybe_f, struct cloc loc, string_t facility,
+ char *message, ...)
+{
+ va_list args;
+
+ va_start(args,message);
+ vcfgfatal_maybefile(maybe_f,loc,facility,message,args);
+ va_end(args);
+}
+
+void cfgfatal(struct cloc loc, string_t facility, char *message, ...)
+{
+ va_list args;
+
+ va_start(args,message);
+ vcfgfatal_maybefile(0,loc,facility,message,args);
+ va_end(args);
+}
+
+void cfgfile_postreadcheck(struct cloc loc, FILE *f)
+{
+ assert(loc.file);
+ if (ferror(f)) {
+ Message(M_FATAL, "error reading config file (%s): %s",
+ loc.file, strerror(errno));
+ exit(current_phase);
+ } else if (feof(f)) {
+ Message(M_FATAL, "unexpected end of config file (%s)", loc.file);
+ exit(current_phase);
+ }
+}
+
/* Take a list of log closures and merge them */
struct loglist {
struct log_if *l;
{ "info", M_INFO },
{ "notice", M_NOTICE },
{ "warning", M_WARNING },
- { "error", M_ERROR },
+ { "error", M_ERR },
{ "security", M_SECURITY },
{ "fatal", M_FATAL },
- { "default", M_WARNING|M_ERROR|M_SECURITY|M_FATAL },
- { "verbose", M_INFO|M_NOTICE|M_WARNING|M_ERROR|M_SECURITY|M_FATAL },
+ { "default", M_WARNING|M_ERR|M_SECURITY|M_FATAL },
+ { "verbose", M_INFO|M_NOTICE|M_WARNING|M_ERR|M_SECURITY|M_FATAL },
{ "quiet", M_FATAL },
{ NULL, 0 }
};
case M_INFO: return LOG_INFO;
case M_NOTICE: return LOG_NOTICE;
case M_WARNING: return LOG_WARNING;
- case M_ERROR: return LOG_ERR;
+ case M_ERR: return LOG_ERR;
case M_SECURITY: return LOG_CRIT;
case M_FATAL: return LOG_EMERG;
default: return LOG_NOTICE;
}
static struct flagstr syslog_facility_table[]={
+#ifdef LOG_AUTH
+ { "auth", LOG_AUTH },
+#endif
+#ifdef LOG_AUTHPRIV
{ "authpriv", LOG_AUTHPRIV },
+#endif
{ "cron", LOG_CRON },
{ "daemon", LOG_DAEMON },
{ "kern", LOG_KERN },