[PATCH 1/7] LOG: fix logging to file
by Angus Salkeld
qb_log_file_open() left the target in an UNUSED state.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/log.c b/lib/log.c
index db2b595..6975dd6 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -562,6 +562,7 @@ struct qb_log_target *qb_log_target_alloc(void)
int32_t i;
for (i = 0; i < 32; i++) {
if (conf[i].state == QB_LOG_STATE_UNUSED) {
+ conf[i].state = QB_LOG_STATE_DISABLED;
return &conf[i];
}
}
--
1.7.4
13 years
[PATCH] Compile on FreeBSD
by Angus Salkeld
Also re-run autoscan.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
configure.ac | 21 +++++++++------------
lib/log.c | 14 +++++---------
lib/log_dcs.c | 2 +-
tests/check_log.c | 4 ++--
tests/make-log-test | 2 +-
5 files changed, 18 insertions(+), 25 deletions(-)
diff --git a/configure.ac b/configure.ac
index 361035b..4a1efcf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,20 +6,15 @@ AC_PREREQ([2.61])
AC_INIT([libqb],
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
[quarterback-devel(a)fedorahosted.org])
-
-AM_INIT_AUTOMAKE([-Wno-portability])
-
AC_CONFIG_SRCDIR([lib/ringbuffer.c])
AC_CONFIG_HEADERS([include/config.h include/qb/qbconfig.h])
-
+AM_INIT_AUTOMAKE([-Wno-portability])
LT_PREREQ([2.2.6])
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
-
AC_CANONICAL_HOST
AC_PROG_LIBTOOL
-
AC_LANG([C])
dnl Fix default variables - "prefix" variable if not specified
@@ -54,12 +49,12 @@ if ! ${MAKE-make} --version /cannot/make/this >/dev/null 2>&1; then
AC_MSG_ERROR([you don't seem to have GNU make; it is required])
fi
-AC_PROG_CC
-AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_AWK
-AC_PROG_LN_S
+AC_PROG_CC
+AC_PROG_CPP
AC_PROG_INSTALL
+AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_CHECK_PROGS([PKGCONFIG], [pkg-config])
AC_CHECK_PROGS([DOXYGEN], [doxygen])
@@ -132,16 +127,18 @@ AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
+AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_CHOWN
+AC_FUNC_ERROR_AT_LINE
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_FUNC_REALLOC
-AC_FUNC_STRERROR_R
-AC_CHECK_FUNCS([alarm clock_gettime ftruncate gettimeofday memset munmap \
- socket strchr strerror strstr epoll_create epoll_create1 \
+AC_CHECK_FUNCS([alarm clock_gettime ftruncate gettimeofday localtime_r memset munmap \
+ socket strchr strdup strerror strrchr strstr \
+ epoll_create epoll_create1 \
pthread_spin_lock timerfd_create])
## local defines
diff --git a/lib/log.c b/lib/log.c
index 4a1f881..db2b595 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -23,6 +23,8 @@
#include <link.h>
#include <stdarg.h>
+#include <dlfcn.h>
+
#include <qb/qbdefs.h>
#include <qb/qblist.h>
#include <qb/qblog.h>
@@ -421,12 +423,9 @@ int32_t qb_log_filter_ctl(int32_t t, enum qb_log_filter_conf c,
if (!logger_inited) {
return -EINVAL;
}
- if (t < 0 || t >= 32) {
+ if (t < 0 || t >= 32 || conf[t].state == QB_LOG_STATE_UNUSED) {
return -EBADF;
}
- if (conf[t].state == QB_LOG_STATE_UNUSED) {
- return -EBADFD;
- }
if (text == NULL ||
priority > LOG_TRACE ||
type > QB_LOG_FILTER_FORMAT ||
@@ -452,7 +451,7 @@ _log_so_walk_callback(struct dl_phdr_info *info, size_t size, void *data)
void *handle;
void *start;
void *stop;
- char *error;
+ const char *error;
handle = dlopen(info->dlpi_name, RTLD_LAZY);
error = dlerror();
@@ -627,12 +626,9 @@ int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
if (!logger_inited) {
return -EINVAL;
}
- if (t < 0 || t >= 32) {
+ if (t < 0 || t >= 32 || conf[t].state == QB_LOG_STATE_UNUSED) {
return -EBADF;
}
- if (conf[t].state == QB_LOG_STATE_UNUSED) {
- return -EBADFD;
- }
switch (c) {
case QB_LOG_CONF_ENABLED:
if (arg) {
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
index 6dfef1e..14a8e11 100644
--- a/lib/log_dcs.c
+++ b/lib/log_dcs.c
@@ -104,7 +104,7 @@ qb_log_dcs_get(int32_t *newly_created,
uint32_t tags)
{
int32_t rc;
- struct qb_log_callsite *cs;
+ struct qb_log_callsite *cs = NULL;
struct callsite_list *csl_head;
struct callsite_list *csl_next;
struct callsite_list *csl;
diff --git a/tests/check_log.c b/tests/check_log.c
index 7fa65a3..0ada405 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -48,10 +48,10 @@ START_TEST(test_log_stupid_inputs)
/* non-opened log file */
rc = qb_log_filter_ctl(21, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "bla", LOG_TRACE);
- ck_assert_int_eq(rc, -EBADFD);
+ ck_assert_int_eq(rc, -EBADF);
rc = qb_log_ctl(21, QB_LOG_CONF_PRIORITY_BUMP, -1);
- ck_assert_int_eq(rc, -EBADFD);
+ ck_assert_int_eq(rc, -EBADF);
/* target < 0 or >= 32 */
rc = qb_log_filter_ctl(41, QB_LOG_FILTER_ADD,
diff --git a/tests/make-log-test b/tests/make-log-test
index ab27f00..8cf1a54 100755
--- a/tests/make-log-test
+++ b/tests/make-log-test
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
line=
count=0
--
1.7.4
13 years
[PATCH 01/14] LOG: add the ability to adjust the priority sent to syslog()
by Angus Salkeld
If you have:
qb_log_filter_ctl(QB_LOG_SYSLOG, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "hack.c", LOG_DEBUG);
these logs will not make there way to /var/log/messags
without reconfiguring syslog.
So to help on the fly debugging do the following:
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP,
LOG_INFO - LOG_DEBUG);
Now all messages that have the QB_LOG_SYSLOG target set
will have their priority bumped before going to syslog().
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblog.h | 7 +++++++
lib/log.c | 3 +++
lib/log_int.h | 1 +
lib/log_syslog.c | 8 +++++++-
4 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index a5317b1..a5a1b69 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -82,6 +82,12 @@ extern "C" {
* qb_log_ctl(mytarget, QB_LOG_CONF_THREADED, QB_TRUE);
* @endcode
*
+ * To workaround your syslog daemon filtering all messages > LOG_INFO
+ * @code
+ * qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP,
+ * LOG_INFO - LOG_DEBUG);
+ * @endcode
+ *
* @par Filtering messages.
* To have more power over what log messages go to which target you can apply
* filters to the targets. What happens is the desired callsites have the
@@ -312,6 +318,7 @@ enum qb_log_conf {
QB_LOG_CONF_DEBUG,
QB_LOG_CONF_SIZE,
QB_LOG_CONF_THREADED,
+ QB_LOG_CONF_PRIORITY_BUMP,
};
enum qb_log_filter_type {
diff --git a/lib/log.c b/lib/log.c
index a281df2..5b66bfd 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -598,6 +598,9 @@ int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
need_reload = QB_TRUE;
}
break;
+ case QB_LOG_CONF_PRIORITY_BUMP:
+ conf[t].priority_bump = arg;
+ break;
case QB_LOG_CONF_SIZE:
conf[t].size = arg;
if (t == QB_LOG_BLACKBOX) {
diff --git a/lib/log_int.h b/lib/log_int.h
index 755b755..34f82e0 100644
--- a/lib/log_int.h
+++ b/lib/log_int.h
@@ -47,6 +47,7 @@ struct qb_log_target {
char name[PATH_MAX];
struct qb_list_head filter_head;
int32_t facility;
+ int32_t priority_bump;
int32_t debug;
size_t size;
char *format;
diff --git a/lib/log_syslog.c b/lib/log_syslog.c
index 5544e39..8a1ec8b 100644
--- a/lib/log_syslog.c
+++ b/lib/log_syslog.c
@@ -27,10 +27,16 @@ static void _syslog_logger(struct qb_log_target *t,
time_t timestamp, const char *msg)
{
char output_buffer[COMBINE_BUFFER_SIZE];
+ int32_t final_priority = cs->priority + t->priority_bump;
qb_log_target_format(t, cs, timestamp, msg, output_buffer);
- syslog(cs->priority, "%s", output_buffer);
+ if (final_priority > LOG_DEBUG) {
+ return;
+ } else if (final_priority < LOG_EMERG) {
+ final_priority = LOG_EMERG;
+ }
+ syslog(final_priority, "%s", output_buffer);
}
static void _syslog_close(struct qb_log_target *t)
--
1.7.4
13 years
[PATCH 1/4] LOG: only set state in log.c
by Angus Salkeld
This requires an enable after qb_log_file_open()
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log_file.c | 1 -
tests/simple-log.c | 1 +
2 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/log_file.c b/lib/log_file.c
index 12c4327..9ba8a6d 100644
--- a/lib/log_file.c
+++ b/lib/log_file.c
@@ -85,7 +85,6 @@ int32_t qb_log_file_open(const char *filename)
t->logger = _file_logger;
t->reload = _file_reload;
t->close = _file_close;
- t->state = QB_LOG_STATE_ENABLED;
return t->pos;
}
diff --git a/tests/simple-log.c b/tests/simple-log.c
index e507e0f..898a9c1 100644
--- a/tests/simple-log.c
+++ b/tests/simple-log.c
@@ -163,6 +163,7 @@ int32_t main(int32_t argc, char *argv[])
QB_LOG_FILTER_FILE, __FILE__, priority);
qb_log_format_set(log_fd, "%t %n() [%p] %b");
qb_log_ctl(log_fd, QB_LOG_CONF_THREADED, do_threaded);
+ qb_log_ctl(log_fd, QB_LOG_CONF_ENABLED, QB_TRUE);
}
if (do_threaded) {
qb_log_thread_start();
--
1.7.4
13 years
log-bench.c
by Steven Dake
I pulled latest git and noticed the copyright I submitted on this file
had the wrong license and probably needs adjustment to match the libqb
licenses.
Regards
-steve
13 years
[PATCH 1/8] Add required include to qbloop.h
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbloop.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/include/qb/qbloop.h b/include/qb/qbloop.h
index 605a394..3b74616 100644
--- a/include/qb/qbloop.h
+++ b/include/qb/qbloop.h
@@ -28,6 +28,7 @@ extern "C" {
/* *INDENT-ON* */
#include <signal.h>
+#include <stdint.h>
/**
* @file qbloop.h
--
1.7.4
13 years