Split logging functions into separate files
This commit is contained in:
parent
447d6e59e0
commit
aacb1299d8
@ -3,7 +3,7 @@ include_HEADERS = $(top_srcdir)/yasnd.h
|
|||||||
yasnd_LDADD = ${libconfuse_LIBS}
|
yasnd_LDADD = ${libconfuse_LIBS}
|
||||||
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
|
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
|
||||||
sbin_PROGRAMS = yasnd
|
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)
|
yasnd_CPPFLAGS = -I$(top_srcdir)
|
||||||
|
|
||||||
distclean-local:
|
distclean-local:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
|
|
||||||
#include "yasnd.h"
|
#include "yasnd.h"
|
||||||
|
#include "yasnd-log.h"
|
||||||
|
|
||||||
pid_t ipc_clone_pid;
|
pid_t ipc_clone_pid;
|
||||||
pid_t ipc_sms_read_clone_pid=-1; // pid of thread, that checks for new incoming SMS
|
pid_t ipc_sms_read_clone_pid=-1; // pid of thread, that checks for new incoming SMS
|
||||||
|
30
daemon/yasnd-log.c
Normal file
30
daemon/yasnd-log.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
17
daemon/yasnd-log.h
Normal file
17
daemon/yasnd-log.h
Normal file
@ -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
|
@ -1,18 +1,17 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <syslog.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <confuse.h>
|
#include <confuse.h>
|
||||||
|
|
||||||
#include "yasnd.h"
|
#include "yasnd.h"
|
||||||
|
#include "yasnd-log.h"
|
||||||
#include "yasnd-lpt.h"
|
#include "yasnd-lpt.h"
|
||||||
|
|
||||||
cfg_t *cfg; // pointer to configuration structure
|
cfg_t *cfg; // pointer to configuration structure
|
||||||
char pidfile[]="/var/run/yasnd.pid"; // pidfile path
|
char pidfile[]="/var/run/yasnd.pid"; // pidfile path
|
||||||
host_decl* hosts=NULL; // structure with hosts' definitions
|
host_decl* hosts=NULL; // structure with hosts' definitions
|
||||||
int hosts_count=0; // count of hosts
|
int hosts_count=0; // count of hosts
|
||||||
int debug_flag=0;
|
|
||||||
bool sms_enable=false; // use SMS messages for control and reports?
|
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_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0"
|
||||||
char* phone_model=NULL; // gammu phone model, for example: "at"
|
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
|
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
|
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* allocate_memory(int bytes)
|
||||||
{
|
{
|
||||||
void* result=malloc(bytes);
|
void* result=malloc(bytes);
|
||||||
@ -301,7 +289,7 @@ void signal_handler(int signum)
|
|||||||
// block LPT control circuit
|
// block LPT control circuit
|
||||||
lpt_lock();
|
lpt_lock();
|
||||||
// close log decriptor
|
// close log decriptor
|
||||||
closelog();
|
log_close();
|
||||||
//
|
//
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -350,7 +338,7 @@ int main(int argc, char *argv[])
|
|||||||
umask(0);
|
umask(0);
|
||||||
|
|
||||||
/* Open any logs here */
|
/* Open any logs here */
|
||||||
openlog("yasnd", LOG_PID|LOG_CONS, LOG_USER);
|
log_init();
|
||||||
|
|
||||||
/* Create a new SID for the child process */
|
/* Create a new SID for the child process */
|
||||||
sid = setsid();
|
sid = setsid();
|
||||||
|
7
yasnd.h
7
yasnd.h
@ -1,10 +1,6 @@
|
|||||||
#ifndef YASND_H
|
#ifndef YASND_H
|
||||||
#define YASND_H
|
#define YASND_H
|
||||||
|
|
||||||
// Debug verbosity
|
|
||||||
#define DEBUG_BASE 1
|
|
||||||
#define DEBUG_ALL 2
|
|
||||||
|
|
||||||
// IPC message types
|
// IPC message types
|
||||||
#define SMS_SEND_TYPE 1
|
#define SMS_SEND_TYPE 1
|
||||||
#define SMS_RECEIVE_TYPE 2
|
#define SMS_RECEIVE_TYPE 2
|
||||||
@ -37,8 +33,6 @@ typedef struct {
|
|||||||
} mymsgbuf;
|
} mymsgbuf;
|
||||||
|
|
||||||
// External functions
|
// 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 void* allocate_memory(int bytes);
|
||||||
extern bool gammu_init();
|
extern bool gammu_init();
|
||||||
extern bool gammu_send_sms(const char* message);
|
extern bool gammu_send_sms(const char* message);
|
||||||
@ -50,7 +44,6 @@ extern void gammu_free();
|
|||||||
|
|
||||||
// External variables
|
// External variables
|
||||||
extern int hosts_count; // count of hosts
|
extern int hosts_count; // count of hosts
|
||||||
extern int debug_flag;
|
|
||||||
extern char* recipient_number;
|
extern char* recipient_number;
|
||||||
extern char* phone_device; // phone device for gammu, for example: "/dev/ttyACM0"
|
extern char* phone_device; // phone device for gammu, for example: "/dev/ttyACM0"
|
||||||
extern char* phone_model; // gammu phone model, for example: "at"
|
extern char* phone_model; // gammu phone model, for example: "at"
|
||||||
|
Loading…
Reference in New Issue
Block a user