Compare commits
No commits in common. "a05861c83f9c0f82cf1339a86bdac06b5a57ac2a" and "6e57502a2964b45d68ba1b9f38c7a4e3f782fe99" have entirely different histories.
a05861c83f
...
6e57502a29
56
main.c
56
main.c
@ -13,16 +13,11 @@
|
||||
|
||||
#define HOSTNAME "localhost"
|
||||
#define EVENT_SIZE (sizeof(struct inotify_event))
|
||||
|
||||
//debug levels
|
||||
#define NONE 0
|
||||
#define WARNING 1
|
||||
#define INFO 2
|
||||
#define DEBUG 3
|
||||
|
||||
char debug[5][10] = { "[NONE]", "[INFO]", "[WARNING]", "[DEBUG]" };
|
||||
char fn[30] = "";
|
||||
|
||||
struct connexion
|
||||
{
|
||||
int pid;
|
||||
@ -51,7 +46,7 @@ struct notify_config
|
||||
};
|
||||
|
||||
struct config cfg = {"","","",""};
|
||||
int loglevel = DEBUG;
|
||||
int loglevel = INFO;
|
||||
|
||||
// return date in localized format
|
||||
char * frtime(const time_t timet)
|
||||
@ -70,29 +65,24 @@ int printlog(char str[], int level, int errnum)
|
||||
time_t now = 0;
|
||||
char tmp[128];
|
||||
int retval = EXIT_SUCCESS;
|
||||
static char fn_tmp[30];
|
||||
|
||||
if ( level <= loglevel )
|
||||
{
|
||||
time( &now );
|
||||
if (errnum != 0)
|
||||
{
|
||||
sprintf( tmp, "%s %s: %s %s\n", debug[level], frtime(now), str, strerror(errnum));
|
||||
sprintf( tmp, "%s: %s %s\n", frtime(now), str, strerror(errnum));
|
||||
}else
|
||||
{
|
||||
sprintf( tmp, "%s %s: %s\n", debug[level], frtime(now), str);
|
||||
sprintf( tmp, "%s: %s\n", frtime(now), str);
|
||||
}
|
||||
if ( (fh = fopen(cfg.logfile, "a")) == NULL)
|
||||
{
|
||||
perror(cfg.logfile);
|
||||
retval = EXIT_FAILURE;
|
||||
}else
|
||||
}
|
||||
if ( retval == EXIT_SUCCESS )
|
||||
{
|
||||
if( strcmp(fn_tmp, fn) != 0 )
|
||||
{
|
||||
fprintf(fh, "\n---------- function %s ----------\n", fn);
|
||||
strcpy(fn_tmp, fn);
|
||||
}
|
||||
fprintf(fh, "%s", tmp);
|
||||
fclose(fh);
|
||||
}
|
||||
@ -106,7 +96,6 @@ int explode( char * str, char * separator, size_t m, size_t n, char exploded[m][
|
||||
char * pch;
|
||||
int x=0 ;
|
||||
|
||||
strcpy( fn, "explode");
|
||||
pch = strtok( str, separator );
|
||||
while( pch != NULL )
|
||||
{
|
||||
@ -219,7 +208,6 @@ int readconfig( struct config * cfg )
|
||||
}
|
||||
if (cfg->commande[0] == 0)
|
||||
{
|
||||
strcpy(cfg->commande,"no command found");
|
||||
printf("command not found in config file: no command will be executed\n");
|
||||
retval += 4;
|
||||
}
|
||||
@ -233,13 +221,15 @@ int isinarray( int pid, int array[], int n )
|
||||
int x;
|
||||
char strlog[128];
|
||||
|
||||
strcpy( fn, "isinarray");
|
||||
for(x=1;x<=n;x++)
|
||||
{
|
||||
if( pid == array[x])
|
||||
{
|
||||
sprintf(strlog, "pid %i is in array", pid);
|
||||
printlog(strlog, DEBUG, 0 );
|
||||
if (loglevel >= DEBUG )
|
||||
{
|
||||
sprintf(strlog, "pid %i is in array", pid);
|
||||
printlog(strlog, DEBUG, 0 );
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@ -249,7 +239,6 @@ int isinarray( int pid, int array[], int n )
|
||||
// initialize config file watching
|
||||
int init_config_watch( char config_file[], struct notify_config * ncc )
|
||||
{
|
||||
strcpy( fn, "init_config_watch" );
|
||||
ncc->fd = inotify_init();
|
||||
if ( ncc->fd < 0 )
|
||||
{
|
||||
@ -276,7 +265,6 @@ int notify_config_change(struct notify_config * ncc, char config_file[])
|
||||
struct timeval tv = {1,0};
|
||||
int retval;
|
||||
|
||||
strcpy( fn, "notify_config_change");
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(ncc->fd, &rfds);
|
||||
retval = select(ncc->fd+1, &rfds, NULL, NULL, &tv);
|
||||
@ -322,7 +310,6 @@ void getutmp( struct connexion * conn, time_t * time )
|
||||
char str[6];
|
||||
char strlog[128];
|
||||
|
||||
strcpy( fn, "getutpm");
|
||||
conn->host_ip[0]='\0';
|
||||
conn->host_ipv6[0]='\0';
|
||||
setutent();
|
||||
@ -412,7 +399,6 @@ int getpids(int pid, int exploded[])
|
||||
char separator[] = " ";
|
||||
int x = 0;
|
||||
|
||||
strcpy( fn, "getpids");
|
||||
sprintf( path, "/proc/%d/task/%d/children", pid, pid);
|
||||
sprintf(strlog, "process path: %s", path);
|
||||
printlog(strlog, DEBUG,0);
|
||||
@ -453,7 +439,6 @@ int getprocinfo( struct connexion * conn )
|
||||
//char tab[128];
|
||||
time_t timet=0;
|
||||
|
||||
strcpy( fn, "getprocinfo");
|
||||
//get connexion time
|
||||
getutmp( conn, &timet );
|
||||
if ( timet == 0)
|
||||
@ -539,7 +524,6 @@ int main()
|
||||
struct notify_config ncc;
|
||||
//char * ptr;
|
||||
|
||||
strcpy( fn, "main");
|
||||
// Loading configuration
|
||||
readconfig( &cfg );
|
||||
|
||||
@ -560,8 +544,13 @@ int main()
|
||||
id=fork();
|
||||
if(id == 0)
|
||||
{
|
||||
r = system( str );
|
||||
printlog("str", WARNING, 0);
|
||||
if (cfg.commande[0] != 0)
|
||||
{
|
||||
r = system( str );
|
||||
}else
|
||||
{
|
||||
printlog("no command defined: no command launched", WARNING, 0);
|
||||
}
|
||||
exit(r);
|
||||
}else if( id<0 )
|
||||
{
|
||||
@ -572,7 +561,6 @@ int main()
|
||||
while (1)
|
||||
{
|
||||
memset(&conn, 0, sizeof(conn));
|
||||
ip[0] = '\0';
|
||||
// get the sshd process ID (PID)
|
||||
if ( (fh = fopen("/run/sshd.pid", "r" )) == NULL)
|
||||
{
|
||||
@ -632,8 +620,14 @@ int main()
|
||||
printlog(strlog, WARNING, 0);
|
||||
}else if (id == 0)
|
||||
{
|
||||
printlog(str, INFO, 0);
|
||||
r = system( str );
|
||||
if (cfg.commande[0] != 0)
|
||||
{
|
||||
printlog(str, INFO, 0);
|
||||
r = system( str );
|
||||
}else
|
||||
{
|
||||
printlog("no command defined: no command launched", WARNING, 0);
|
||||
}
|
||||
exit(r);
|
||||
}
|
||||
}else
|
||||
|
Reference in New Issue
Block a user