mirror of
https://salsa.debian.org/ha-team/libqb
synced 2026-08-07 09:43:12 +00:00
LOG: fix threaded logging.
This has been broken for a year - yikes! Thanks to Voznesensky Vladimir for spotting it. Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
parent
22569f51ba
commit
b9f8ec34df
@ -235,10 +235,16 @@ main(int32_t argc, char *argv[])
|
||||
func_one();
|
||||
func_two();
|
||||
|
||||
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
||||
if (!do_threaded) {
|
||||
/* Disabling syslog here will prevent the logs from
|
||||
* getting flushed in qb_log_fini() if threaded
|
||||
* logging is on.
|
||||
*/
|
||||
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
||||
|
||||
qb_log(LOG_WARNING, "no syslog");
|
||||
qb_log(LOG_ERR, "no syslog");
|
||||
qb_log(LOG_WARNING, "no syslog");
|
||||
qb_log(LOG_ERR, "no syslog");
|
||||
}
|
||||
|
||||
#if 0
|
||||
// test blackbox
|
||||
|
||||
@ -225,7 +225,7 @@ qb_log_thread_log_write(struct qb_log_callsite *cs,
|
||||
if (t->state != QB_LOG_STATE_ENABLED) {
|
||||
continue;
|
||||
}
|
||||
if (t->threaded) {
|
||||
if (!t->threaded) {
|
||||
continue;
|
||||
}
|
||||
if (qb_bit_is_set(cs->targets, t->pos)) {
|
||||
|
||||
@ -568,7 +568,48 @@ START_TEST(test_log_long_msg)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite *log_suite(void)
|
||||
START_TEST(test_threaded_logging)
|
||||
{
|
||||
int32_t t;
|
||||
int32_t rc;
|
||||
|
||||
qb_log_init("test", LOG_USER, LOG_EMERG);
|
||||
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
||||
|
||||
t = qb_log_custom_open(_test_logger, NULL, NULL, NULL);
|
||||
rc = qb_log_filter_ctl(t, QB_LOG_FILTER_ADD,
|
||||
QB_LOG_FILTER_FILE, "*", LOG_INFO);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
qb_log_format_set(t, "%b");
|
||||
rc = qb_log_ctl(t, QB_LOG_CONF_ENABLED, QB_TRUE);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
rc = qb_log_ctl(t, QB_LOG_CONF_THREADED, QB_TRUE);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
qb_log_thread_start();
|
||||
|
||||
memset(test_buf, 0, sizeof(test_buf));
|
||||
test_priority = 0;
|
||||
num_msgs = 0;
|
||||
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
qb_log(LOG_INFO, "Yoda how old are you? - %d", __LINE__);
|
||||
|
||||
qb_log_fini();
|
||||
|
||||
ck_assert_int_eq(num_msgs, 10);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite *
|
||||
log_suite(void)
|
||||
{
|
||||
TCase *tc;
|
||||
Suite *s = suite_create("logging");
|
||||
@ -606,6 +647,10 @@ static Suite *log_suite(void)
|
||||
tcase_add_test(tc, test_log_filter_fn);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("threaded_logging");
|
||||
tcase_add_test(tc, test_threaded_logging);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user