9
0
Fork 0
mirror of https://gerrit.osmocom.org/osmocom-bb synced 2024-08-13 17:06:26 +00:00

logging: fix corrupted output

Harald reported a problem in the logging:
http://lists.osmocom.org/pipermail/openbsc/2011-May/002896.html

Reverting 81e9636454 seems to
fix the problem. However, that workaround looks ugly.

Holger gives us another clue on what was wrong:
http://lists.osmocom.org/pipermail/openbsc/2011-May/002905.html

While digging in the manpage, I found this:

"The functions vprintf(), vfprintf(), vsprintf(), vsnprintf()
are equivalent to the functions printf(), fprintf(), sprintf(),
snprintf(), respectively, except that they are called with a
va_list instead of a variable number of arguments. These functions
do not call the va_end macro. Consequently, the value of ap is
undefined after the call. The application should call va_end(ap)
itself afterwards."
This commit is contained in:
Pablo Neira Ayuso 2011-05-19 01:40:43 +02:00 committed by Pablo Neira Ayuso
parent ba01fa44fe
commit dd93bf46ed

View 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) { llist_for_each_entry(tar, &osmo_log_target_list, entry) {
struct log_category *category; struct log_category *category;
int output = 0; int output = 0;
va_list bp;
category = &tar->categories[subsys]; category = &tar->categories[subsys];
/* subsystem is not supposed to be logged */ /* subsystem is not supposed to be logged */
@ -224,7 +225,12 @@ static void _logp(unsigned int subsys, int level, char *file, int line,
if (!output) if (!output)
continue; continue;
/* 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); _output(tar, subsys, level, file, line, cont, format, ap);
va_end(bp);
} }
} }