Merge branch 'laforge/fd-debug' of https://github.com/laf0rge/nextepc

This commit is contained in:
Sukchan Lee
2019-09-19 22:26:22 +09:00
3 changed files with 66 additions and 70 deletions

View File

@@ -22,7 +22,8 @@
int __ogs_diam_domain; int __ogs_diam_domain;
static void diam_gnutls_log_func(int level, const char *str); static void diam_gnutls_log_func(int level, const char *str);
static void diam_log_func(int printlevel, const char *format, va_list ap); static void diam_log_func(int printlevel,
const char *fname, int line, const char *format, va_list ap);
int ogs_diam_init(int mode, const char *conffile, ogs_diam_config_t *fd_config) int ogs_diam_init(int mode, const char *conffile, ogs_diam_config_t *fd_config)
{ {
@@ -33,26 +34,21 @@ int ogs_diam_init(int mode, const char *conffile, ogs_diam_config_t *fd_config)
fd_g_debug_lvl = FD_LOG_ERROR; fd_g_debug_lvl = FD_LOG_ERROR;
ret = fd_log_handler_register(diam_log_func); ret = fd_log_handler_register(diam_log_func);
if (ret != 0) if (ret != 0) {
{
ogs_error("fd_log_handler_register() failed"); ogs_error("fd_log_handler_register() failed");
return ret; return ret;
} }
ret = fd_core_initialize(); ret = fd_core_initialize();
if (ret != 0) if (ret != 0) {
{
ogs_error("fd_core_initialize() failed"); ogs_error("fd_core_initialize() failed");
return ret; return ret;
} }
/* Parse the configuration file */ /* Parse the configuration file */
if (conffile) if (conffile) {
{
CHECK_FCT_DO( fd_core_parseconf(conffile), goto error ); CHECK_FCT_DO( fd_core_parseconf(conffile), goto error );
} } else {
else
{
CHECK_FCT_DO( ogs_diam_config_init(fd_config), goto error ); CHECK_FCT_DO( ogs_diam_config_init(fd_config), goto error );
} }
@@ -91,49 +87,47 @@ static void diam_gnutls_log_func(int level, const char *str)
ogs_trace("gnutls[%d]: %s", level, str); ogs_trace("gnutls[%d]: %s", level, str);
} }
static void diam_log_func(int printlevel, const char *format, va_list ap) static void diam_log_func(int printlevel,
const char *fname, int line, const char *format, va_list ap)
{ {
char buffer[OGS_HUGE_LEN]; char buffer[OGS_HUGE_LEN];
int ret = 0; int ret = 0;
ret = vsnprintf(buffer, OGS_HUGE_LEN, format, ap); ret = vsnprintf(buffer, OGS_HUGE_LEN, format, ap);
if (ret < 0 || ret > OGS_HUGE_LEN) if (ret < 0 || ret > OGS_HUGE_LEN) {
{
ogs_error("vsnprintf() failed"); ogs_error("vsnprintf() failed");
return; return;
} }
switch(printlevel) switch(printlevel) {
{ case FD_LOG_ANNOYING:
case FD_LOG_ANNOYING: ogs_trace("[%d]: %s:%u %s", printlevel, fname, line, buffer);
ogs_trace("freeDiameter[%d]: %s", printlevel, buffer); break;
break; case FD_LOG_DEBUG:
case FD_LOG_DEBUG: ogs_trace("[%d]: %s:%u %s", printlevel, fname, line, buffer);
ogs_trace("freeDiameter[%d]: %s", printlevel, buffer); break;
break; case FD_LOG_NOTICE:
case FD_LOG_NOTICE: ogs_trace("[%d]: %s:%u %s", printlevel, fname, line, buffer);
ogs_trace("freeDiameter[%d]: %s", printlevel, buffer); break;
break; case FD_LOG_ERROR:
case FD_LOG_ERROR: ogs_error("%s:%d %s", fname, line, buffer);
ogs_error("%s", buffer); if (!strcmp(buffer, " - The certificate is expired.")) {
if (!strcmp(buffer, " - The certificate is expired.")) ogs_error("You can renew CERT as follows:");
{ ogs_error("./support/freeDiameter/make_certs.sh "
ogs_error("You can renew CERT as follows:"); "./install/etc/nextepc/freeDiameter");
ogs_error("./support/freeDiameter/make_certs.sh " }
"./install/etc/nextepc/freeDiameter"); break;
} case FD_LOG_FATAL:
break; {
case FD_LOG_FATAL: char *except = "Initiating freeDiameter shutdown sequence";
{ if (strncmp(buffer, except, strlen(except)) == 0)
char *except = "Initiating freeDiameter shutdown sequence"; ogs_info("[%d]: %s:%u %s", printlevel, fname, line, buffer);
if (strncmp(buffer, except, strlen(except)) == 0) else
ogs_info("freeDiameter[%d]: %s", printlevel, buffer); ogs_fatal("%s:%d %s", fname, line, buffer);
else }
ogs_fatal("%s", buffer); break;
} default:
break; ogs_warn("%s:%d %s", fname, line, buffer);
default: break;
ogs_warn("%s", buffer);
break;
} }
} }

View File

@@ -135,6 +135,8 @@ extern const char fd_libproto_version[];
* *
* PARAMETERS: * PARAMETERS:
* loglevel : Integer, how important the message is. Valid values are macros FD_LOG_* * loglevel : Integer, how important the message is. Valid values are macros FD_LOG_*
* filename : source file name
* line : source line number
* format : Same format string as in the printf function * format : Same format string as in the printf function
* ... : Same list as printf * ... : Same list as printf
* *
@@ -146,9 +148,9 @@ extern const char fd_libproto_version[];
* RETURN VALUE: * RETURN VALUE:
* None. * None.
*/ */
void fd_log ( int, const char *, ... ) _ATTRIBUTE_PRINTFLIKE_(2,3); void fd_log ( int, const char *, int, const char *, ... ) _ATTRIBUTE_PRINTFLIKE_(4,5);
#ifndef SWIG #ifndef SWIG
void fd_log_va( int, const char *, va_list); void fd_log_va( int, const char *, int, const char *, va_list);
#endif /* SWIG */ #endif /* SWIG */
/* these are internal objects of the debug facility, /* these are internal objects of the debug facility,
@@ -208,7 +210,7 @@ char * fd_log_time ( struct timespec * ts, char * buf, size_t len, int incl_date
* RETURN VALUE: * RETURN VALUE:
* int : Success or failure * int : Success or failure
*/ */
int fd_log_handler_register ( void (*logger)(int loglevel, const char * format, va_list args) ); int fd_log_handler_register ( void (*logger)(int loglevel, const char *fname, int line, const char * format, va_list args) );
/* /*
* FUNCTION: fd_log_handler_unregister * FUNCTION: fd_log_handler_unregister
@@ -309,7 +311,7 @@ static char * file_bname_init(char * full) { file_bname = basename(full); return
The general debug macro The general debug macro
*************************/ *************************/
#define LOG(printlevel,format,args... ) \ #define LOG(printlevel,format,args... ) \
fd_log((printlevel), STD_TRACE_FMT_STRING format STD_TRACE_FMT_ARGS, ## args) fd_log((printlevel), __FILE__, __LINE__, STD_TRACE_FMT_STRING format STD_TRACE_FMT_ARGS, ## args)
/* /*
* Use the following macros in the code to get traces with location & pid in debug mode: * Use the following macros in the code to get traces with location & pid in debug mode:
@@ -355,7 +357,7 @@ static char * file_bname_init(char * full) { file_bname = basename(full); return
for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2)); __i++) { \ for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2)); __i++) { \
sprintf(__strbuf + (2 * __i), "%02hhx", __buf[__i]); \ sprintf(__strbuf + (2 * __i), "%02hhx", __buf[__i]); \
} \ } \
fd_log(printlevel, STD_TRACE_FMT_STRING "%s%s%s" STD_TRACE_FMT_ARGS, \ fd_log(printlevel, __FILE__, __LINE__, STD_TRACE_FMT_STRING "%s%s%s" STD_TRACE_FMT_ARGS, \
(prefix), __strbuf, (suffix)); \ (prefix), __strbuf, (suffix)); \
} }
@@ -490,15 +492,15 @@ static __inline__ int old_TRACE_BOOL( enum old_levels level, const char * file,
#define TRACE_BOOL(level) old_TRACE_BOOL((level), __STRIPPED_FILE__, __PRETTY_FUNCTION__) #define TRACE_BOOL(level) old_TRACE_BOOL((level), __STRIPPED_FILE__, __PRETTY_FUNCTION__)
#ifndef SWIG #ifndef SWIG
static __inline__ void fd_log_deprecated( int level, const char *format, ... ) MARK_DEPRECATED static __inline__ void fd_log_deprecated( int level, const char *fname, int line, const char *format, ... ) MARK_DEPRECATED
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
fd_log_va(level, format, ap); fd_log_va(level, fname, line, format, ap);
va_end(ap); va_end(ap);
} }
#else /* SWIG */ #else /* SWIG */
void fd_log_deprecated( int level, const char *format, ... ); void fd_log_deprecated( int level, const char *fname, int line, const char *format, ... );
#endif /* SWIG */ #endif /* SWIG */
static __inline__ void replace_me() MARK_DEPRECATED { } static __inline__ void replace_me() MARK_DEPRECATED { }
@@ -507,9 +509,9 @@ static __inline__ void replace_me() MARK_DEPRECATED { }
/* Use the LOG_* instead, or use the new *_dump functions when dumping an object */ /* Use the LOG_* instead, or use the new *_dump functions when dumping an object */
#define fd_log_debug(format,args...) fd_log_deprecated(FD_LOG_DEBUG, format, ## args) #define fd_log_debug(format,args...) fd_log_deprecated(FD_LOG_DEBUG, __FILE__, __LINE__, format, ## args)
#define fd_log_notice(format,args...) fd_log_deprecated(FD_LOG_NOTICE, format, ## args) #define fd_log_notice(format,args...) fd_log_deprecated(FD_LOG_NOTICE, __FILE__, __LINE__, format, ## args)
#define fd_log_error(format,args...) fd_log_deprecated(FD_LOG_ERROR, format, ## args) #define fd_log_error(format,args...) fd_log_deprecated(FD_LOG_ERROR, __FILE__, __LINE__, format, ## args)
/* old macro for traces. To be replaced by appropriate LOG_* macros. */ /* old macro for traces. To be replaced by appropriate LOG_* macros. */
# define TRACE_DEBUG(oldlevel, format,args... ) { \ # define TRACE_DEBUG(oldlevel, format,args... ) { \
@@ -601,9 +603,9 @@ static __inline__ void replace_me() MARK_DEPRECATED { }
#undef LOG_BUFFER #undef LOG_BUFFER
#define LOG_D(format,args... ) /* noop */ #define LOG_D(format,args... ) /* noop */
#define LOG_N(format,args...) fd_log(FD_LOG_NOTICE, format, ## args) #define LOG_N(format,args...) fd_log(FD_LOG_NOTICE, __FILE__, __LINE__, format, ## args)
#define LOG_E(format,args...) fd_log(FD_LOG_ERROR, format, ## args) #define LOG_E(format,args...) fd_log(FD_LOG_ERROR, __FILE__, __LINE__, format, ## args)
#define LOG_F(format,args...) fd_log(FD_LOG_FATAL, format, ## args) #define LOG_F(format,args...) fd_log(FD_LOG_FATAL, __FILE__, __LINE__, format, ## args)
#define LOG_BUFFER(printlevel, level, prefix, buf, bufsz, suffix ) { \ #define LOG_BUFFER(printlevel, level, prefix, buf, bufsz, suffix ) { \
if (printlevel > FD_LOG_DEBUG) { \ if (printlevel > FD_LOG_DEBUG) { \
int __i; \ int __i; \
@@ -613,7 +615,7 @@ static __inline__ void replace_me() MARK_DEPRECATED { }
for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2); __i++) { \ for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2); __i++) { \
sprintf(__strbuf + (2 * __i), "%02.2hhx", __buf[__i]); \ sprintf(__strbuf + (2 * __i), "%02.2hhx", __buf[__i]); \
} \ } \
fd_log(printlevel, prefix"%s"suffix, __strbuf); \ fd_log(printlevel, __FILE__, __LINE__, prefix"%s"suffix, __strbuf); \
} }
#endif /* STRIP_DEBUG_CODE */ #endif /* STRIP_DEBUG_CODE */

View File

@@ -41,7 +41,7 @@ pthread_mutex_t fd_log_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_key_t fd_log_thname; pthread_key_t fd_log_thname;
int fd_g_debug_lvl = FD_LOG_NOTICE; int fd_g_debug_lvl = FD_LOG_NOTICE;
static void fd_internal_logger( int, const char *, va_list ); static void fd_internal_logger( int, const char *, int, const char *, va_list );
static int use_colors = 0; /* 0: not init, 1: yes, 2: no */ static int use_colors = 0; /* 0: not init, 1: yes, 2: no */
/* These may be used to pass specific debug requests via the command-line parameters */ /* These may be used to pass specific debug requests via the command-line parameters */
@@ -53,10 +53,10 @@ int fd_breaks = 0;
int fd_breakhere(void) { return ++fd_breaks; } int fd_breakhere(void) { return ++fd_breaks; }
/* Allow passing of the log and debug information from base stack to extensions */ /* Allow passing of the log and debug information from base stack to extensions */
void (*fd_logger)( int loglevel, const char * format, va_list args ) = fd_internal_logger; void (*fd_logger)( int loglevel, const char *fname, int line, const char * format, va_list args ) = fd_internal_logger;
/* Register an external call back for tracing and debug */ /* Register an external call back for tracing and debug */
int fd_log_handler_register( void (*logger)(int loglevel, const char * format, va_list args) ) int fd_log_handler_register( void (*logger)(int loglevel, const char *fname, int line, const char * format, va_list args) )
{ {
CHECK_PARAMS( logger ); CHECK_PARAMS( logger );
@@ -85,7 +85,7 @@ static void fd_cleanup_mutex_silent( void * mutex )
} }
static void fd_internal_logger( int printlevel, const char *format, va_list ap ) static void fd_internal_logger( int printlevel, const char *fname, int line, const char *format, va_list ap )
{ {
char buf[25]; char buf[25];
@@ -94,13 +94,13 @@ static void fd_internal_logger( int printlevel, const char *format, va_list ap )
return; return;
/* add timestamp */ /* add timestamp */
printf("%s ", fd_log_time(NULL, buf, sizeof(buf), printf("%s %s:%d ", fd_log_time(NULL, buf, sizeof(buf),
#if (defined(DEBUG) && defined(DEBUG_WITH_META)) #if (defined(DEBUG) && defined(DEBUG_WITH_META))
1, 1 1, 1
#else /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */ #else /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */
0, 0 0, 0
#endif /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */ #endif /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */
)); ), fname, line);
/* Use colors on stdout ? */ /* Use colors on stdout ? */
if (!use_colors) { if (!use_colors) {
if (isatty(STDOUT_FILENO)) if (isatty(STDOUT_FILENO))
@@ -126,7 +126,7 @@ static void fd_internal_logger( int printlevel, const char *format, va_list ap )
} }
/* Log a debug message */ /* Log a debug message */
void fd_log ( int loglevel, const char * format, ... ) void fd_log ( int loglevel, const char *fname, int line, const char * format, ... )
{ {
va_list ap; va_list ap;
@@ -135,7 +135,7 @@ void fd_log ( int loglevel, const char * format, ... )
pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock); pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
va_start(ap, format); va_start(ap, format);
fd_logger(loglevel, format, ap); fd_logger(loglevel, fname, line, format, ap);
va_end(ap); va_end(ap);
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
@@ -144,12 +144,12 @@ void fd_log ( int loglevel, const char * format, ... )
} }
/* Log a debug message */ /* Log a debug message */
void fd_log_va ( int loglevel, const char * format, va_list args ) void fd_log_va ( int loglevel, const char *fname, int line, const char * format, va_list args )
{ {
(void)pthread_mutex_lock(&fd_log_lock); (void)pthread_mutex_lock(&fd_log_lock);
pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock); pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
fd_logger(loglevel, format, args); fd_logger(loglevel, fname, line, format, args);
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
(void)pthread_mutex_unlock(&fd_log_lock); (void)pthread_mutex_unlock(&fd_log_lock);