1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
10 #include "headers/shared.h"
12 static int dbg_flag = 0;
13 static int chroot_flag = 0;
14 static int daemon_flag = 0;
16 static void _log(const char *msg, va_list args) __attribute__((format(printf, 1, 0))) __attribute__((nonnull));
22 /* For internal logs */
25 #define LOGFILE "/logs/ossec.log"
27 #define LOGFILE "ossec.log"
32 static void _log(const char *msg, va_list args)
36 va_list args2; /* For the stderr print */
44 /* If under chroot, log directly to /logs/ossec.log */
45 if (chroot_flag == 1) {
46 fp = fopen(LOGFILE, "a");
50 snprintf(_logfile, 256, "%s%s", DEFAULTDIR, LOGFILE);
52 snprintf(_logfile, 256, "%s", LOGFILE);
54 fp = fopen(_logfile, "a");
57 /* Maybe log to syslog if the log file is not available */
59 (void)fprintf(fp, "%d/%02d/%02d %02d:%02d:%02d ",
60 p->tm_year + 1900, p->tm_mon + 1,
61 p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
62 (void)vfprintf(fp, msg, args);
64 (void)fprintf(fp, "\r\n");
66 (void)fprintf(fp, "\n");
72 /* Only if not in daemon mode */
73 if (daemon_flag == 0) {
75 (void)fprintf(stderr, "%d/%02d/%02d %02d:%02d:%02d ",
76 p->tm_year + 1900, p->tm_mon + 1 , p->tm_mday,
77 p->tm_hour, p->tm_min, p->tm_sec);
78 (void)vfprintf(stderr, msg, args2);
80 (void)fprintf(stderr, "\r\n");
82 (void)fprintf(stderr, "\n");
86 /* args2 must be ended here */
90 void debug1(const char *msg, ...)
102 void debug2(const char *msg, ...)
113 void merror(const char *msg, ... )
122 void verbose(const char *msg, ... )
131 /* Only logs to a file */
132 void log2file(const char *msg, ... )
138 /* We set daemon flag to 1, so nothing is printed to the terminal */
139 dbg_tmp = daemon_flag;
143 daemon_flag = dbg_tmp;
148 void ErrorExit(const char *msg, ...)
176 void print_out(const char *msg, ...)
181 /* Print to stderr */
182 (void)vfprintf(stderr, msg, args);
185 (void)fprintf(stderr, "\r\n");
187 (void)fprintf(stderr, "\n");
200 return (chroot_flag);