1
0

added function name in log

This commit is contained in:
Daniel Tartavel 2020-06-08 15:29:41 +02:00
parent 97adaf7c09
commit 5d828b133a

18
main.c
View File

@ -20,7 +20,8 @@
#define INFO 2 #define INFO 2
#define DEBUG 3 #define DEBUG 3
char debug[5][10] = { "[NONE]", "[INFO]", "[WARNING]", "DEBUG" }; char debug[5][10] = { "[NONE]", "[INFO]", "[WARNING]", "[DEBUG]" };
char fn[30] = "";
struct connexion struct connexion
{ {
@ -58,6 +59,7 @@ char * frtime(const time_t timet)
struct tm *date_tm; struct tm *date_tm;
static char result[40]; static char result[40];
strcpy( fn, "frtime");
date_tm = localtime(&timet); date_tm = localtime(&timet);
strftime(result, 40, "%c", date_tm); strftime(result, 40, "%c", date_tm);
return result; return result;
@ -69,6 +71,7 @@ int printlog(char str[], int level, int errnum)
time_t now = 0; time_t now = 0;
char tmp[128]; char tmp[128];
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;
static char fn_tmp[30];
if ( level <= loglevel ) if ( level <= loglevel )
{ {
@ -86,6 +89,11 @@ int printlog(char str[], int level, int errnum)
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
}else }else
{ {
if( strcmp(fn, fn_tmp) != 0 )
{
fprintf(fh, "%s", fn);
strcpy(fn_tmp, fn);
}
fprintf(fh, "%s", tmp); fprintf(fh, "%s", tmp);
fclose(fh); fclose(fh);
} }
@ -99,6 +107,7 @@ int explode( char * str, char * separator, size_t m, size_t n, char exploded[m][
char * pch; char * pch;
int x=0 ; int x=0 ;
strcpy( fn, "explode");
pch = strtok( str, separator ); pch = strtok( str, separator );
while( pch != NULL ) while( pch != NULL )
{ {
@ -224,6 +233,7 @@ int isinarray( int pid, int array[], int n )
int x; int x;
char strlog[128]; char strlog[128];
strcpy( fn, "isinarray");
for(x=1;x<=n;x++) for(x=1;x<=n;x++)
{ {
if( pid == array[x]) if( pid == array[x])
@ -239,6 +249,7 @@ int isinarray( int pid, int array[], int n )
// initialize config file watching // initialize config file watching
int init_config_watch( char config_file[], struct notify_config * ncc ) int init_config_watch( char config_file[], struct notify_config * ncc )
{ {
strcpy( fn, "init_config_watch" );
ncc->fd = inotify_init(); ncc->fd = inotify_init();
if ( ncc->fd < 0 ) if ( ncc->fd < 0 )
{ {
@ -265,6 +276,7 @@ int notify_config_change(struct notify_config * ncc, char config_file[])
struct timeval tv = {1,0}; struct timeval tv = {1,0};
int retval; int retval;
strcpy( fn, "notify_config_change");
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(ncc->fd, &rfds); FD_SET(ncc->fd, &rfds);
retval = select(ncc->fd+1, &rfds, NULL, NULL, &tv); retval = select(ncc->fd+1, &rfds, NULL, NULL, &tv);
@ -310,6 +322,7 @@ void getutmp( struct connexion * conn, time_t * time )
char str[6]; char str[6];
char strlog[128]; char strlog[128];
strcpy( fn, "getutpm");
conn->host_ip[0]='\0'; conn->host_ip[0]='\0';
conn->host_ipv6[0]='\0'; conn->host_ipv6[0]='\0';
setutent(); setutent();
@ -399,6 +412,7 @@ int getpids(int pid, int exploded[])
char separator[] = " "; char separator[] = " ";
int x = 0; int x = 0;
strcpy( fn, "getpids");
sprintf( path, "/proc/%d/task/%d/children", pid, pid); sprintf( path, "/proc/%d/task/%d/children", pid, pid);
sprintf(strlog, "process path: %s", path); sprintf(strlog, "process path: %s", path);
printlog(strlog, DEBUG,0); printlog(strlog, DEBUG,0);
@ -439,6 +453,7 @@ int getprocinfo( struct connexion * conn )
//char tab[128]; //char tab[128];
time_t timet=0; time_t timet=0;
strcpy( fn, "getprocinfo");
//get connexion time //get connexion time
getutmp( conn, &timet ); getutmp( conn, &timet );
if ( timet == 0) if ( timet == 0)
@ -524,6 +539,7 @@ int main()
struct notify_config ncc; struct notify_config ncc;
//char * ptr; //char * ptr;
strcpy( fn, "main");
// Loading configuration // Loading configuration
readconfig( &cfg ); readconfig( &cfg );