[pjsip] Logging bug in today's SVN 20080403

Michael CHRISTOPHER pjsip at encambio.com
Thu Apr 3 10:28:33 EDT 2008


Hello,

To reproduce a logging bug in the current SVN sources, edit the
file config_site.h to contain:

  #define PJ_CONFIG_MINIMAL_SIZE
  #include <pj/config_site_sample.h>

...implicitly defining in config_site_sample.h:

  #define PJ_LOG_MAX_LEVEL 0

...and build normally (./aconfigure && make)

The build breaks when creating the library libsrtp-<arch>.a:

  ar rv ../../lib/libsrtp-<arch>.a

...because symbols used by srtp_err.o are not defined in any
library. If PJ_LOG_MAX_LEVEL were a positive value, these symbols
would be found in log.o. Just see log.c where PJ_LOG_MAX_LEVEL is
tested to be a positive value.

Let me know if I should explain that better or give details.

One workaround is simply to always define PJ_LOG_MAX_LEVEL as
a positive integer when defining PJ_CONFIG_MINIMAL_SIZE and
including <pj/config_site_sample.h> in config_site.h. That's
not a solution, but a workaround that leads to a succesful build.

As a permanent solution I suggest the following patch (apply
with patch -p0 <textbelow.diff):

Index: pjlib/src/pj/log.c
--- pjlib/src/pj/log.c.orig	2008-04-03 14:52:58.000000000 +0200
+++ pjlib/src/pj/log.c	2008-04-03 14:52:15.000000000 +0200
@@ -22,6 +22,11 @@
 #include <pj/os.h>
 #include <pj/compat/stdarg.h>
 
+#if PJ_LOG_MAX_LEVEL < 1
+PJ_DEF(void) pj_log( const char *sender, int level, 
+		     const char *format, va_list marker) { return; /* Noop */ }
+#endif
+
 #if PJ_LOG_MAX_LEVEL >= 1
 
 #if 0

Other than pj_log, there are other symbols missing from log.o as
well when PJ_LOG_MAX_LEVEL is not a positive integer, namely:

  log_decor log_writer
  pj_log_1 pj_log_2 pj_log_3 pj_log_4 pj_log_5
  pj_log_get_decor pj_log_get_level pj_log_get_log_func
  pj_log_max_level pj_log_set_decor pj_log_set_level
  pj_log_set_log_func

If a similar solution (see patch above) is needed for these
symbols as well is unclear to me.

An kludgy alternative is to always test for a positive value in
PJ_LOG_MAX_LEVEL before using logging symbols, something like:

#if PJ_LOG_MAX_LEVEL >= 1
    va_start(args, format);
    pj_log("libsrtp", priority, format, args);
    va_end(args);
#endif

...in srtp_err.c for example.

Otherwise one may never use the logging symbols, without making
the risky assumption that they indeed exist in a library.

Regards,
Michael




More information about the pjsip mailing list