12#define _GNU_SOURCE_WAS_NOT_DEFINED
16#ifdef _GNU_SOURCE_WAS_NOT_DEFINED
40 n_log(
LOG_ERR,
"Could not allocate the internal hash table because it's already done" );
50 n_log(
LOG_ERR,
"Could not allocate the internal hash with size %d", max );
55 n_log(
LOG_DEBUG,
"LOGGING: nodup system activated with a hash table of %d cells", max );
93static char *
get_nodup_key(
const char *file,
const char *func,
int line )
97 nstrprintf( nstr,
"%s%s%d", file, func, line );
118 nstrprintf( nstr,
"%s%s%s%d", file, func, prefix, line );
159 if( strcmp( log, node -> data .
string ) == 0 )
201 if( strcmp( log, node -> data .
string ) == 0 )
220void _n_nodup_log(
int LEVEL,
const char *file,
const char *func,
int line,
const char *format, ... )
229 char *syslogbuffer = NULL ;
231 va_start (args, format);
232 if(
vasprintf( &syslogbuffer, format, args ) == -1 )
235 n_log(
LOG_ERR ,
"=>%s:%s:%d unable to parse '%s', %s" , file , func , line , format , strerror( error ) );
250 _n_log( LEVEL, file, func, line,
"%s", syslogbuffer );
259 if( node && node -> data .
string )
261 Free( node -> data .
string );
262 node -> data .
string = syslogbuffer ;
264 _n_log( LEVEL, file, func, line,
"%s", syslogbuffer );
269 _n_log( LEVEL, file, func, line,
"%s", syslogbuffer );
273 Free( syslogbuffer );
288void _n_nodup_log_indexed(
int LEVEL,
const char *prefix,
const char *file,
const char *func,
int line,
const char *format, ... )
293 char *syslogbuffer = NULL ;
295 va_start (args, format);
296 if(
vasprintf( &syslogbuffer, format, args ) == -1 )
299 n_log(
LOG_ERR ,
"=>%s:%s:%d unable to parse '%s:%s', %s" , file , func , line , prefix , format , strerror( error ) );
314 _n_log( LEVEL, file, func, line,
"%s", syslogbuffer );
323 if( node && node -> data .
string )
325 Free( node -> data .
string );
326 node -> data .
string = syslogbuffer ;
328 _n_log( LEVEL, file, func, line,
"%s", syslogbuffer );
333 _n_log( LEVEL, file, func, line,
"%s", syslogbuffer );
338 Free( syslogbuffer );
357 char *tmpfile = NULL ;
361 out = fopen( tmpfile,
"wb" );
366 for(
unsigned long int it = 0 ; it <
_n_nodup_table -> size ; it ++ )
370 hash_node = (
HASH_NODE *)list_node -> ptr ;
371 fprintf( out,
"%s\n", hash_node -> data .
string );
378 strprintf( cmd,
"mv -f %s %s ; chmod 644 %s", tmpfile, file, file );
380 int ret = system( cmd );
384 n_log(
LOG_ERR ,
"could not run '%s' , %s" , cmd , strerror( error ) );
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
int destroy_ht(HASH_TABLE **table)
empty a table and destroy it
HASH_TABLE * new_ht(size_t size)
Create a hash table with the given size.
int empty_ht(HASH_TABLE *table)
empty a table
int ht_put_string(HASH_TABLE *table, const char *key, char *string)
put a string value (copy/dup) with given key in the targeted hash table
HASH_NODE * ht_get_node(HASH_TABLE *table, const char *key)
get node at 'key' from 'table'
structure of a hash table node
structure of a hash table
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Logging function.
int dump_nodup_log(char *file)
Dump the duplicate error log hash table in a file.
int close_nodup_log()
Empty nodup logtable and close the no duplicate logging session.
void _n_nodup_log(int LEVEL, const char *file, const char *func, int line, const char *format,...)
Logging function.
int empty_nodup_table()
Empty the nodup internal table.
void _n_nodup_log_indexed(int LEVEL, const char *prefix, const char *file, const char *func, int line, const char *format,...)
Logging function.
int init_nodup_log(int max)
initialize the no duplicate logging system
#define nstrprintf(__nstr_var,...)
Macro to quickly allocate and sprintf to N_STR *.
#define strprintf(__n_var,...)
Macro to quickly allocate and sprintf to a char *.
A box including a string and his lenght.
Common headers and low-level hugly functions & define.
Hash functions and table.
List structures and definitions.
int vasprintf(char **strp, const char *fmt, va_list ap)
snprintf from a va_list, helper for asprintf
int check_n_log_dup_indexed(const char *log, const char *file, const char *func, int line, const char *prefix)
check if a log was already done or not at the given line, func, file
static char * get_nodup_key(const char *file, const char *func, int line)
internal, get a key for a log entry
static char * get_nodup_indexed_key(const char *file, const char *func, const char *prefix, int line)
internal, get a key for an indexed log entry
int check_n_log_dup(const char *log, const char *file, const char *func, int line)
check if a log was already done or not at the given line, func, file
static HASH_TABLE * _n_nodup_table
internal: no dup hash_table log save
Generic No Dup Log system.
N_STR and string function declaration.