X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fshared%2Fdebug_op.c;h=f428a2ef3c8b687cc2c4def9da83e212f7d20316;hp=6be1f8cc2a79cbbc079d8136d27c376f7baa2e47;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/shared/debug_op.c b/src/shared/debug_op.c old mode 100755 new mode 100644 index 6be1f8c..f428a2e --- a/src/shared/debug_op.c +++ b/src/shared/debug_op.c @@ -1,6 +1,3 @@ -/* @(#) $Id: ./src/shared/debug_op.c, 2011/09/08 dcid Exp $ - */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * @@ -10,13 +7,13 @@ * Foundation */ - #include "headers/shared.h" +static int dbg_flag = 0; +static int chroot_flag = 0; +static int daemon_flag = 0; -int dbg_flag = 0; -int chroot_flag = 0; -int daemon_flag = 0; +static void _log(const char *msg, va_list args) __attribute__((format(printf, 1, 0))) __attribute__((nonnull)); #ifdef WIN32 void WinSetError(); @@ -24,90 +21,75 @@ void WinSetError(); /* For internal logs */ #ifndef LOGFILE - #ifndef WIN32 - #define LOGFILE "/logs/ossec.log" - #else - #define LOGFILE "ossec.log" - #endif +#ifndef WIN32 +#define LOGFILE "/logs/ossec.log" +#else +#define LOGFILE "ossec.log" +#endif #endif -/* _log function */ -void _log(const char * msg,va_list args) +static void _log(const char *msg, va_list args) { time_t tm; struct tm *p; - - /* For the stderr print */ - va_list args2; - + va_list args2; /* For the stderr print */ FILE *fp; tm = time(NULL); p = localtime(&tm); - - /* Duplicating args */ + /* Duplicate args */ va_copy(args2, args); - /* If under chroot, log directly to /logs/ossec.log */ - if(chroot_flag == 1) - { + if (chroot_flag == 1) { fp = fopen(LOGFILE, "a"); - } - else - { + } else { char _logfile[256]; - #ifndef WIN32 +#ifndef WIN32 snprintf(_logfile, 256, "%s%s", DEFAULTDIR, LOGFILE); - #else +#else snprintf(_logfile, 256, "%s", LOGFILE); - #endif +#endif fp = fopen(_logfile, "a"); } - /* Maybe log to syslog if the log file is not available. */ - if(fp) - { - (void)fprintf(fp,"%d/%02d/%02d %02d:%02d:%02d ", - p->tm_year+1900,p->tm_mon+1, - p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec); + /* Maybe log to syslog if the log file is not available */ + if (fp) { + (void)fprintf(fp, "%d/%02d/%02d %02d:%02d:%02d ", + p->tm_year + 1900, p->tm_mon + 1, + p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); (void)vfprintf(fp, msg, args); - #ifdef WIN32 +#ifdef WIN32 (void)fprintf(fp, "\r\n"); - #else +#else (void)fprintf(fp, "\n"); - #endif +#endif fflush(fp); fclose(fp); } - /* Only if not in daemon mode */ - if(daemon_flag == 0) - { - /* Print to stderr */ - (void)fprintf(stderr,"%d/%02d/%02d %02d:%02d:%02d ", - p->tm_year+1900,p->tm_mon+1 ,p->tm_mday, - p->tm_hour,p->tm_min,p->tm_sec); + if (daemon_flag == 0) { + /* Print to stderr */ + (void)fprintf(stderr, "%d/%02d/%02d %02d:%02d:%02d ", + p->tm_year + 1900, p->tm_mon + 1 , p->tm_mday, + p->tm_hour, p->tm_min, p->tm_sec); (void)vfprintf(stderr, msg, args2); - #ifdef WIN32 +#ifdef WIN32 (void)fprintf(stderr, "\r\n"); - #else +#else (void)fprintf(stderr, "\n"); - #endif +#endif } - /* args2 must be ended here */ va_end(args2); } - -void debug1(const char * msg,...) +void debug1(const char *msg, ...) { - if(dbg_flag >= 1) - { + if (dbg_flag >= 1) { va_list args; va_start(args, msg); @@ -117,35 +99,37 @@ void debug1(const char * msg,...) } } -void debug2(const char * msg,...) +void debug2(const char *msg, ...) { - if(dbg_flag >= 2) - { + if (dbg_flag >= 2) { va_list args; + va_start(args, msg); _log(msg, args); va_end(args); } } -void merror(const char * msg,... ) +void merror(const char *msg, ... ) { va_list args; + va_start(args, msg); _log(msg, args); va_end(args); } -void verbose(const char * msg,... ) +void verbose(const char *msg, ... ) { va_list args; + va_start(args, msg); _log(msg, args); va_end(args); } /* Only logs to a file */ -void log2file(const char * msg,... ) +void log2file(const char *msg, ... ) { int dbg_tmp; va_list args; @@ -165,12 +149,12 @@ void ErrorExit(const char *msg, ...) { va_list args; - #ifdef WIN32 - /* If not MA */ - #ifndef MA - WinSetError(); - #endif - #endif +#ifdef WIN32 + /* If not MA */ +#ifndef MA + WinSetError(); +#endif +#endif va_start(args, msg); _log(msg, args); @@ -179,13 +163,11 @@ void ErrorExit(const char *msg, ...) exit(1); } - void nowChroot() { chroot_flag = 1; } - void nowDaemon() { daemon_flag = 1; @@ -199,16 +181,15 @@ void print_out(const char *msg, ...) /* Print to stderr */ (void)vfprintf(stderr, msg, args); - #ifdef WIN32 +#ifdef WIN32 (void)fprintf(stderr, "\r\n"); - #else +#else (void)fprintf(stderr, "\n"); - #endif +#endif va_end(args); } - void nowDebug() { dbg_flag++; @@ -216,7 +197,5 @@ void nowDebug() int isChroot() { - return(chroot_flag); + return (chroot_flag); } - -/* EOF */