Update the log file printing.

This commit is contained in:
Nicholas J. Kain 2013-05-08 08:11:15 -04:00
parent 4c52accd62
commit 3d6e3a2610

View File

@ -38,50 +38,49 @@ int gflags_quiet = 0;
int gflags_detach = 1; int gflags_detach = 1;
char *gflags_log_name = NULL; char *gflags_log_name = NULL;
#define log_syslog(level) do { \
openlog(gflags_log_name, LOG_PID, LOG_DAEMON); \
va_start(argp, format); \
vsyslog(level | LOG_DAEMON, format, argp); \
va_end(argp); \
closelog(); } while(0)
#define log_stdio() do { \
va_start(argp, format); \
vfprintf(stderr, format, argp); \
fprintf(stderr, "\n"); \
va_end(argp); } while(0)
void log_line_l(int level, const char *format, ...) void log_line_l(int level, const char *format, ...)
{ {
va_list argp; va_list argp;
if (format == NULL || gflags_quiet) if (gflags_quiet)
return; return;
if (gflags_detach) { if (gflags_detach)
openlog(gflags_log_name, LOG_PID, LOG_DAEMON); log_syslog(level);
va_start(argp, format); else
vsyslog(level | LOG_DAEMON, format, argp); log_stdio();
va_end(argp);
closelog();
} else {
va_start(argp, format);
vfprintf(stderr, format, argp);
fprintf(stderr, "\n");
va_end(argp);
}
closelog();
} }
void suicide(const char *format, ...) void suicide(const char *format, ...)
{ {
va_list argp; va_list argp;
if (format == NULL || gflags_quiet) if (gflags_quiet)
goto out; goto out;
if (gflags_detach) { if (gflags_detach)
openlog(gflags_log_name, LOG_PID, LOG_DAEMON); log_syslog(LOG_ERR);
va_start(argp, format); else {
vsyslog(LOG_ERR | LOG_DAEMON, format, argp); log_stdio();
va_end(argp);
closelog();
} else {
va_start(argp, format);
vfprintf(stderr, format, argp);
va_end(argp);
fprintf(stderr, "\n");
perror(NULL); perror(NULL);
} }
closelog();
out: out:
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#undef log_syslog
#undef log_stdio