diff --git a/daemon/Makefile.am b/daemon/Makefile.am index f9e7b1b..66bb5f8 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -3,7 +3,7 @@ include_HEADERS = $(top_srcdir)/yasnd.h yasnd_LDADD = ${libconfuse_LIBS} yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la sbin_PROGRAMS = yasnd -yasnd_SOURCES = yasnd.c yasnd-ipc.c yasnd-lpt.c +yasnd_SOURCES = yasnd.c yasnd-ipc.c yasnd-log.c yasnd-lpt.c yasnd_CPPFLAGS = -I$(top_srcdir) distclean-local: diff --git a/daemon/yasnd-ipc.c b/daemon/yasnd-ipc.c index 9a971c0..4cca76f 100644 --- a/daemon/yasnd-ipc.c +++ b/daemon/yasnd-ipc.c @@ -2,6 +2,7 @@ #include #include "yasnd.h" +#include "yasnd-log.h" pid_t ipc_clone_pid; pid_t ipc_sms_read_clone_pid=-1; // pid of thread, that checks for new incoming SMS diff --git a/daemon/yasnd-log.c b/daemon/yasnd-log.c new file mode 100644 index 0000000..57398d1 --- /dev/null +++ b/daemon/yasnd-log.c @@ -0,0 +1,30 @@ +#include + +int debug_flag=0; // debug verbosity flag + +void log_init() +{ + return openlog("yasnd", LOG_PID|LOG_CONS, LOG_USER); +} + +void log_close() +{ + return closelog(); +} + +/* + Function, that called to output various debug messages to syslog +*/ +void log_debug(const char *message,int verbosity) +{ + if (debug_flag>=verbosity) + syslog(LOG_INFO,"%s",message); +} + +/* + Function, that called to output information message to syslog +*/ +void log_event(const char *message) +{ + syslog(LOG_INFO,"%s",message); +} diff --git a/daemon/yasnd-log.h b/daemon/yasnd-log.h new file mode 100644 index 0000000..282a415 --- /dev/null +++ b/daemon/yasnd-log.h @@ -0,0 +1,17 @@ +#ifndef YASND_LOG_H +#define YASND_LOG_H + +// Debug verbosity +#define DEBUG_BASE 1 +#define DEBUG_ALL 2 + +// External variables +extern int debug_flag; + +// External functions +extern void log_init(); +extern void log_close(); +extern void log_debug(const char *message,int verbosity); +extern void log_event(const char *message); + +#endif diff --git a/daemon/yasnd.c b/daemon/yasnd.c index fa023ec..aa491ce 100644 --- a/daemon/yasnd.c +++ b/daemon/yasnd.c @@ -1,18 +1,17 @@ #include #include #include -#include #include #include #include "yasnd.h" +#include "yasnd-log.h" #include "yasnd-lpt.h" cfg_t *cfg; // pointer to configuration structure char pidfile[]="/var/run/yasnd.pid"; // pidfile path host_decl* hosts=NULL; // structure with hosts' definitions int hosts_count=0; // count of hosts -int debug_flag=0; bool sms_enable=false; // use SMS messages for control and reports? char* phone_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0" char* phone_model=NULL; // gammu phone model, for example: "at" @@ -24,17 +23,6 @@ int failures_second=0; // count of failures while hosts checking, that triggers int failures_third=0; // count of failures while hosts checking, that clean failure statistics pid_t mainloop_clone_pid; // pid of clone process, that containt main loop -void log_debug(const char *message,int verbosity) -{ - if (debug_flag>=verbosity) - syslog(LOG_INFO,"%s",message); -} - -void log_event(const char *message) -{ - syslog(LOG_INFO,"%s",message); -} - void* allocate_memory(int bytes) { void* result=malloc(bytes); @@ -301,7 +289,7 @@ void signal_handler(int signum) // block LPT control circuit lpt_lock(); // close log decriptor - closelog(); + log_close(); // exit(EXIT_SUCCESS); } @@ -350,7 +338,7 @@ int main(int argc, char *argv[]) umask(0); /* Open any logs here */ - openlog("yasnd", LOG_PID|LOG_CONS, LOG_USER); + log_init(); /* Create a new SID for the child process */ sid = setsid(); diff --git a/yasnd.h b/yasnd.h index 45a2e09..eb9980d 100644 --- a/yasnd.h +++ b/yasnd.h @@ -1,10 +1,6 @@ #ifndef YASND_H #define YASND_H -// Debug verbosity -#define DEBUG_BASE 1 -#define DEBUG_ALL 2 - // IPC message types #define SMS_SEND_TYPE 1 #define SMS_RECEIVE_TYPE 2 @@ -37,8 +33,6 @@ typedef struct { } mymsgbuf; // External functions -extern void log_event(const char *message); -extern void log_debug(const char *message,int verbosity); extern void* allocate_memory(int bytes); extern bool gammu_init(); extern bool gammu_send_sms(const char* message); @@ -50,7 +44,6 @@ extern void gammu_free(); // External variables extern int hosts_count; // count of hosts -extern int debug_flag; extern char* recipient_number; extern char* phone_device; // phone device for gammu, for example: "/dev/ttyACM0" extern char* phone_model; // gammu phone model, for example: "at"