Skip to content

Commit

Permalink
LOG: fix threaded logging.
Browse files Browse the repository at this point in the history
This has been broken for a year - yikes!
Thanks to Voznesensky Vladimir for spotting it.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
asalkeld committed Jun 14, 2012
1 parent 22569f5 commit b9f8ec3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
12 changes: 9 additions & 3 deletions examples/simplelog.c
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/log.c
Expand Up @@ -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)) {
Expand Down
47 changes: 46 additions & 1 deletion tests/check_log.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b9f8ec3

Please sign in to comment.