import gsm0502_calc_paging_group() from openbsc
[osmocom-bb.git] / src / logging.c
index 526b39e..3c9dc03 100644 (file)
@@ -198,6 +198,7 @@ static void _logp(unsigned int subsys, int level, char *file, int line,
        llist_for_each_entry(tar, &osmo_log_target_list, entry) {
                struct log_category *category;
                int output = 0;
+               va_list bp;
 
                category = &tar->categories[subsys];
                /* subsystem is not supposed to be logged */
@@ -221,19 +222,15 @@ static void _logp(unsigned int subsys, int level, char *file, int line,
                else if (osmo_log_info->filter_fn)
                        output = osmo_log_info->filter_fn(&log_context,
                                                       tar);
+               if (!output)
+                       continue;
 
-               if (output) {
-                       /* FIXME: copying the va_list is an ugly
-                        * workaround against a bug hidden somewhere in
-                        * _output.  If we do not copy here, the first
-                        * call to _output() will corrupt the va_list
-                        * contents, and any further _output() calls
-                        * with the same va_list will segfault */
-                       va_list bp;
-                       va_copy(bp, ap);
-                       _output(tar, subsys, level, file, line, cont, format, bp);
-                       va_end(bp);
-               }
+               /* According to the manpage, vsnprintf leaves the value of ap
+                * in undefined state. Since _output uses vsnprintf and it may
+                * be called several times, we have to pass a copy of ap. */
+               va_copy(bp, ap);
+               _output(tar, subsys, level, file, line, cont, format, ap);
+               va_end(bp);
        }
 }
 
@@ -502,6 +499,7 @@ const char *log_vty_command_string(const struct log_info *info)
                goto err;
        OSMO_SNPRINTF_RET(ret, rem, offset, len);
 err:
+       str[size-1] = '\0';
        return str;
 }
 
@@ -553,6 +551,7 @@ const char *log_vty_command_description(const struct log_info *info)
                OSMO_SNPRINTF_RET(ret, rem, offset, len);
        }
 err:
+       str[size-1] = '\0';
        return str;
 }