[PATCH] IPC: add a context to the client interface
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbipcc.h | 19 +++++++++++++++++++
lib/ipc_int.h | 1 +
lib/ipcc.c | 17 +++++++++++++++++
3 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/include/qb/qbipcc.h b/include/qb/qbipcc.h
index 6227e0f..a55848f 100644
--- a/include/qb/qbipcc.h
+++ b/include/qb/qbipcc.h
@@ -162,6 +162,25 @@ ssize_t qb_ipcc_sendv_recv(qb_ipcc_connection_t *c,
ssize_t qb_ipcc_event_recv(qb_ipcc_connection_t* c, void *msg_ptr,
size_t msg_len, int32_t ms_timeout);
+/**
+ * Associate a "user" pointer with this connection.
+ *
+ * @param context the point to associate with this connection.
+ * @param c connection instance
+ * @see qb_ipcc_context_get()
+ */
+void qb_ipcc_context_set(qb_ipcc_connection_t *c, void *context);
+
+/**
+ * Get the context (set previously)
+ *
+ * @param c connection instance
+ * @return the context
+ * @see qb_ipcc_context_set()
+ */
+void *qb_ipcc_context_get(qb_ipcc_connection_t *c);
+
+
/* *INDENT-OFF* */
#ifdef __cplusplus
}
diff --git a/lib/ipc_int.h b/lib/ipc_int.h
index 7f37038..67093fc 100644
--- a/lib/ipc_int.h
+++ b/lib/ipc_int.h
@@ -113,6 +113,7 @@ struct qb_ipcc_connection {
struct qb_ipc_request_header *receive_buf;
uint32_t fc_enable_max;
int32_t is_connected;
+ void * context;
};
int32_t qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 5f2d439..6bcc5d5 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -318,3 +318,20 @@ qb_ipcc_disconnect(struct qb_ipcc_connection *c)
free(c->receive_buf);
free(c);
}
+
+void
+qb_ipcc_context_set(struct qb_ipcc_connection *c, void *context)
+{
+ if (c == NULL) {
+ return;
+ }
+ c->context = context;
+}
+
+void *qb_ipcc_context_get(struct qb_ipcc_connection *c)
+{
+ if (c == NULL) {
+ return NULL;
+ }
+ return c->context;
+}
--
1.7.7.5
12 years, 3 months
[PATCH] LOG: make sure the format is checked.
by Angus Salkeld
In case of log clashes (same file/lineno but in different directories.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log_dcs.c | 8 +++++---
tests/check_log.c | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
index 8f01889..215252e 100644
--- a/lib/log_dcs.c
+++ b/lib/log_dcs.c
@@ -126,8 +126,9 @@ qb_log_dcs_get(int32_t * newly_created,
*/
rc = qb_array_index(lookup_arr, lineno, (void **)&csl_head);
assert(rc == 0);
- if (csl_head->cs
- && strcmp(safe_filename, csl_head->cs->filename) == 0) {
+ if (csl_head->cs &&
+ format == csl_head->cs->format &&
+ strcmp(safe_filename, csl_head->cs->filename) == 0) {
return csl_head->cs;
}
/*
@@ -143,7 +144,8 @@ qb_log_dcs_get(int32_t * newly_created,
} else {
for (csl = csl_head; csl; csl = csl->next) {
assert(csl->cs->lineno == lineno);
- if (strcmp(safe_filename, csl->cs->filename) == 0) {
+ if (format == csl->cs->format &&
+ strcmp(safe_filename, csl->cs->filename) == 0) {
cs = csl->cs;
break;
}
diff --git a/tests/check_log.c b/tests/check_log.c
index 9665c2b..58b2d4c 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -252,6 +252,10 @@ START_TEST(test_log_basic)
log_and_this_too();
ck_assert_int_eq(num_msgs, 2);
+ qb_log_filter_ctl(t, QB_LOG_FILTER_CLEAR_ALL,
+ QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
+ qb_log_filter_ctl(t, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, __FILE__, LOG_DEBUG);
/*
* make sure we can pass in a null filename or function name.
*/
@@ -259,6 +263,21 @@ START_TEST(test_log_basic)
__LINE__, 0, "null filename");
qb_log_from_external_source(NULL, __FILE__, "%s", LOG_INFO,
__LINE__, 0, "null function");
+
+ /* check same file/lineno logs with different formats work
+ */
+ num_msgs = 0;
+ qb_log_from_external_source(__func__, __FILE__, "%s bla", LOG_INFO,
+ 56, 0, "filename/lineno");
+ ck_assert_int_eq(num_msgs, 1);
+ ck_assert_str_eq(test_buf, "filename/lineno bla");
+
+ num_msgs = 0;
+ qb_log_from_external_source(__func__, __FILE__, "%s", LOG_INFO,
+ 56, 0, "same filename/lineno");
+ ck_assert_int_eq(num_msgs, 1);
+ ck_assert_str_eq(test_buf, "same filename/lineno");
+
}
END_TEST
--
1.7.7.5
12 years, 3 months
[PATCH] make the pc file auto detect -lrt
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/libqb.pc.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/libqb.pc.in b/lib/libqb.pc.in
index 8426856..caaabd0 100644
--- a/lib/libqb.pc.in
+++ b/lib/libqb.pc.in
@@ -7,5 +7,5 @@ Name: libqb
Version: @PACKAGE_VERSION@
Description: libqb
Requires:
-Libs: -L${libdir} -lqb -lrt -ldl
+Libs: -L${libdir} -lqb @LIB_RT@ -ldl
Cflags: -I${includedir}
--
1.7.7.5
12 years, 3 months
[PATCH 1/4] TEST: change the script to .sh and generated c file to auto_
by Angus Salkeld
Just to make cleanup easier
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/.gitignore | 2 +-
tests/Makefile.am | 24 ++++++++++++------------
tests/make-log-test | 34 ----------------------------------
tests/make-log-test.sh | 34 ++++++++++++++++++++++++++++++++++
4 files changed, 47 insertions(+), 47 deletions(-)
delete mode 100755 tests/make-log-test
create mode 100755 tests/make-log-test.sh
diff --git a/tests/.gitignore b/tests/.gitignore
index a3be604..e637dff 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -6,5 +6,5 @@ bms
loop
rbreader
rbwriter
-write_logs.c
libqb
+auto_*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d8f64e2..8d358cb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -47,22 +47,22 @@ loop_SOURCES = loop.c $(top_builddir)/include/qb/qbloop.h
loop_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
loop_LDADD = $(LIB_RT) $(top_builddir)/lib/libqb.la
-if HAVE_DICT_WORDS
-if HAVE_SLOW_TESTS
-EXTRA_DIST += make-log-test
-CLEANFILES += write_logs.c
-MAINTAINERCLEANFILES += write_logs.c
-nodist_bench_log_SOURCES = write_logs.c
+distclean-compile:
+ rm -rf auto_*.c
-bench_log: write_logs.c
-$(builddir)/write_logs.c: make-log-test
- $(srcdir)/make-log-test > $(builddir)/write_logs-tmp.c
- $(AM_V_GEN)mv $(builddir)/write_logs-tmp.c $(builddir)/write_logs.c
+if HAVE_DICT_WORDS
+if HAVE_SLOW_TESTS
+EXTRA_DIST += make-log-test.sh
+CLEANFILES += auto_write_logs.c
+MAINTAINERCLEANFILES += auto_write_logs.c
-distclean-compile:
- rm -rf write_logs.c
+nodist_bench_log_SOURCES = auto_write_logs.c
+bench_log: auto_write_logs.c
+$(builddir)/auto_write_logs.c: make-log-test.sh
+ $(srcdir)/make-log-test.sh > $(builddir)/write_logs-tmp.c
+ $(AM_V_GEN)mv $(builddir)/write_logs-tmp.c $(builddir)/auto_write_logs.c
endif
endif
diff --git a/tests/make-log-test b/tests/make-log-test
deleted file mode 100755
index 0dba275..0000000
--- a/tests/make-log-test
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env bash
-
-line=
-count=0
-total=50000
-echo "#include <stdio.h>"
-echo "#include <qb/qblog.h>"
-echo "extern void log_dict_words(void);"
-echo "void log_dict_words(void) {"
-
-while read w
-do
- if [ $count -eq 0 ]
- then
- line=" qb_log(LOG_DEBUG, \"%d : %s %s %s\", $total"
- fi
- line="$line, \"$w\""
- let count="$count+1"
- if [ $count -eq 3 ]
- then
- line="$line );"
- count=0
- let total="$total-1"
- echo $line
- if [ $total -eq 0 ]
- then
- echo "}"
- exit 0
- fi
- fi
-done < /usr/share/dict/words
-
-echo "}"
-
diff --git a/tests/make-log-test.sh b/tests/make-log-test.sh
new file mode 100755
index 0000000..0dba275
--- /dev/null
+++ b/tests/make-log-test.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+line=
+count=0
+total=50000
+echo "#include <stdio.h>"
+echo "#include <qb/qblog.h>"
+echo "extern void log_dict_words(void);"
+echo "void log_dict_words(void) {"
+
+while read w
+do
+ if [ $count -eq 0 ]
+ then
+ line=" qb_log(LOG_DEBUG, \"%d : %s %s %s\", $total"
+ fi
+ line="$line, \"$w\""
+ let count="$count+1"
+ if [ $count -eq 3 ]
+ then
+ line="$line );"
+ count=0
+ let total="$total-1"
+ echo $line
+ if [ $total -eq 0 ]
+ then
+ echo "}"
+ exit 0
+ fi
+ fi
+done < /usr/share/dict/words
+
+echo "}"
+
--
1.7.7.5
12 years, 3 months
[PATCH 1/3] Fix check_ipc.c formatting.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/check_ipc.c | 49 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index b31b4a3..4bac8a6 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -73,14 +73,16 @@ static qb_ipcs_service_t* s1;
static int32_t turn_on_fc = QB_FALSE;
static int32_t fc_enabled = 89;
-static int32_t exit_handler(int32_t rsignal, void *data)
+static int32_t
+exit_handler(int32_t rsignal, void *data)
{
qb_log(LOG_DEBUG, "caught signal %d", rsignal);
qb_ipcs_destroy(s1);
return -1;
}
-static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c,
+static int32_t
+s1_msg_process_fn(qb_ipcs_connection_t *c,
void *data, size_t size)
{
struct qb_ipc_request_header *req_pt = (struct qb_ipc_request_header *)data;
@@ -117,37 +119,43 @@ static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c,
return 0;
}
-static int32_t my_job_add(enum qb_loop_priority p,
+static int32_t
+my_job_add(enum qb_loop_priority p,
void *data,
qb_loop_job_dispatch_fn fn)
{
return qb_loop_job_add(my_loop, p, data, fn);
}
-static int32_t my_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t events,
+static int32_t
+my_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t events,
void *data, qb_ipcs_dispatch_fn_t fn)
{
return qb_loop_poll_add(my_loop, p, fd, events, data, fn);
}
-static int32_t my_dispatch_mod(enum qb_loop_priority p, int32_t fd, int32_t events,
+static int32_t
+my_dispatch_mod(enum qb_loop_priority p, int32_t fd, int32_t events,
void *data, qb_ipcs_dispatch_fn_t fn)
{
return qb_loop_poll_mod(my_loop, p, fd, events, data, fn);
}
-static int32_t my_dispatch_del(int32_t fd)
+static int32_t
+my_dispatch_del(int32_t fd)
{
return qb_loop_poll_del(my_loop, fd);
}
-static void s1_connection_destroyed(qb_ipcs_connection_t *c)
+static void
+s1_connection_destroyed(qb_ipcs_connection_t *c)
{
qb_enter();
qb_loop_stop(my_loop);
}
-static void run_ipc_server(void)
+static void
+run_ipc_server(void)
{
int32_t res;
qb_loop_signal_handle handle;
@@ -185,7 +193,8 @@ static void run_ipc_server(void)
qb_loop_run(my_loop);
}
-static int32_t run_function_in_new_process(void (*run_ipc_server_fn)(void))
+static int32_t
+run_function_in_new_process(void (*run_ipc_server_fn)(void))
{
pid_t pid = fork ();
@@ -201,7 +210,8 @@ static int32_t run_function_in_new_process(void (*run_ipc_server_fn)(void))
return pid;
}
-static int32_t stop_process(pid_t pid)
+static int32_t
+stop_process(pid_t pid)
{
/* wait a bit for the server to shutdown by it's self */
usleep(100000);
@@ -216,7 +226,8 @@ struct my_req {
};
static struct my_req request;
-static int32_t send_and_check(uint32_t size, int32_t ms_timeout)
+static int32_t
+send_and_check(uint32_t size, int32_t ms_timeout, int32_t expect_perfection)
{
struct qb_ipc_response_header res_header;
int32_t res;
@@ -265,7 +276,8 @@ repeat_send:
}
static int32_t recv_timeout = -1;
-static void test_ipc_txrx(void)
+static void
+test_ipc_txrx(void)
{
int32_t j;
int32_t c = 0;
@@ -387,7 +399,8 @@ struct my_res {
};
static struct my_res response;
-static void test_ipc_dispatch(void)
+static void
+test_ipc_dispatch(void)
{
int32_t res;
int32_t j;
@@ -461,9 +474,10 @@ START_TEST(test_ipc_disp_us)
}
END_TEST
+static void
+test_ipc_server_fail(void)
#ifdef IPC_HANDLES_FAILED_SERVER
-static void test_ipc_server_fail(void)
{
struct qb_ipc_request_header req_header;
struct qb_ipc_response_header res_header;
@@ -539,7 +553,8 @@ START_TEST(test_ipc_server_fail_shm)
END_TEST
#endif /* IPC_HANDLES_FAILED_SERVER */
-static Suite *ipc_suite(void)
+static Suite *
+ipc_suite(void)
{
TCase *tc;
uid_t uid;
@@ -587,7 +602,6 @@ static Suite *ipc_suite(void)
tcase_set_timeout(tc, 6);
suite_add_tcase(s, tc);
-
uid = geteuid();
if (uid == 0) {
tc = tcase_create("ipc_txrx_posix_mq");
@@ -613,7 +627,8 @@ static Suite *ipc_suite(void)
return s;
}
-int32_t main(void)
+int32_t
+main(void)
{
int32_t number_failed;
--
1.7.7.5
12 years, 3 months
[PATCH 1/2] LOG: add %N (log name) as a format option
by Angus Salkeld
This will log the name passed into qb_log_init()
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
examples/simplelog.c | 2 +-
include/qb/qblog.h | 1 +
lib/log.c | 27 +++++++++++++++++++++------
lib/log_blackbox.c | 5 +++--
lib/log_file.c | 6 +++---
lib/log_int.h | 1 +
6 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/examples/simplelog.c b/examples/simplelog.c
index ef57503..0752807 100644
--- a/examples/simplelog.c
+++ b/examples/simplelog.c
@@ -190,7 +190,7 @@ int32_t main(int32_t argc, char *argv[])
log_fd = qb_log_file_open(logfile);
qb_log_filter_ctl(log_fd, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, __FILE__, priority);
- qb_log_format_set(log_fd, "%t %n() [%p] %b");
+ qb_log_format_set(log_fd, "[%N] %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);
}
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index 1f5f00c..7961209 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -477,6 +477,7 @@ void qb_log_tags_stringify_fn_set(qb_log_tags_stringify_fn fn);
* %t TIMESTAMP
* %b BUFFER
* %g TAGS
+ * %N name (passed into qb_log_init)
*
* any number between % and character specify field length to pad or chop
*/
diff --git a/lib/log.c b/lib/log.c
index 1002953..9dfb99e 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -670,7 +670,7 @@ qb_log_init(const char *name, int32_t facility, uint8_t priority)
conf[i].pos = i;
conf[i].debug = QB_FALSE;
conf[i].state = QB_LOG_STATE_UNUSED;
- conf[i].name[0] = '\0';
+ strncpy(conf[i].name, name, PATH_MAX);
conf[i].facility = facility;
qb_list_init(&conf[i].filter_head);
qb_log_format_set(i, NULL);
@@ -684,8 +684,6 @@ qb_log_init(const char *name, int32_t facility, uint8_t priority)
conf[QB_LOG_STDERR].state = QB_LOG_STATE_DISABLED;
conf[QB_LOG_BLACKBOX].state = QB_LOG_STATE_DISABLED;
- strncpy(conf[QB_LOG_SYSLOG].name, name, PATH_MAX);
- snprintf(conf[QB_LOG_BLACKBOX].name, PATH_MAX, "%s-blackbox", name);
logger_inited = QB_TRUE;
(void)qb_log_syslog_open(&conf[QB_LOG_SYSLOG]);
@@ -757,7 +755,7 @@ qb_log_target_free(struct qb_log_target *t)
(void)qb_log_filter_ctl(t->pos, QB_LOG_FILTER_CLEAR_ALL,
QB_LOG_FILTER_FILE, NULL, 0);
t->debug = QB_FALSE;
- t->name[0] = '\0';
+ t->filename[0] = '\0';
qb_log_format_set(t->pos, NULL);
_log_target_state_set(t, QB_LOG_STATE_UNUSED);
}
@@ -808,7 +806,7 @@ qb_log_custom_open(qb_log_logger_fn log_fn,
}
t->instance = user_data;
- snprintf(t->name, PATH_MAX, "custom-%d", t->pos);
+ snprintf(t->filename, PATH_MAX, "custom-%d", t->pos);
t->logger = log_fn;
t->vlogger = NULL;
@@ -934,7 +932,24 @@ qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
void
qb_log_format_set(int32_t t, const char *format)
{
+ char* ptr = NULL;
+ size_t len = 0;
+
+ if (format) {
+ ptr = strstr(format, "%N");
+ len = strlen(format);
+ }
free(conf[t].format);
- conf[t].format = strdup(format ? format : "[%p] %b");
+
+ if (ptr) {
+ len += strlen(conf[t].name);
+ conf[t].format = calloc(len + 1, sizeof(char));
+ strncpy(conf[t].format, format, ptr - format);
+ strcat(conf[t].format, conf[t].name);
+ ptr += 2;
+ strcat(conf[t].format, ptr);
+ } else {
+ conf[t].format = strdup(format ? format : "[%p] %b");
+ }
assert(conf[t].format != NULL);
}
diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c
index c9d091b..1c07c2e 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -32,7 +32,7 @@ _blackbox_reload(int32_t target)
return;
}
qb_rb_close(t->instance);
- t->instance = qb_rb_open(t->name, t->size,
+ t->instance = qb_rb_open(t->filename, t->size,
QB_RB_FLAG_CREATE | QB_RB_FLAG_OVERWRITE, 0);
}
@@ -100,8 +100,9 @@ qb_log_blackbox_open(struct qb_log_target *t)
if (t->size < 1024) {
return -EINVAL;
}
+ snprintf(t->filename, PATH_MAX, "%s-blackbox", t->name);
- t->instance = qb_rb_open(t->name, t->size,
+ t->instance = qb_rb_open(t->filename, t->size,
QB_RB_FLAG_CREATE | QB_RB_FLAG_OVERWRITE, 0);
if (t->instance == NULL) {
return -errno;
diff --git a/lib/log_file.c b/lib/log_file.c
index b8c2038..c374927 100644
--- a/lib/log_file.c
+++ b/lib/log_file.c
@@ -57,7 +57,7 @@ _file_reload(int32_t target)
if (t->instance) {
fclose(t->instance);
}
- t->instance = fopen(t->name, "a+");
+ t->instance = fopen(t->filename, "a+");
}
int32_t
@@ -66,7 +66,7 @@ qb_log_stderr_open(struct qb_log_target *t)
t->logger = _file_logger;
t->reload = NULL;
t->close = NULL;
- strncpy(t->name, "stderr", PATH_MAX);
+ strncpy(t->filename, "stderr", PATH_MAX);
t->instance = stderr;
return 0;
}
@@ -90,7 +90,7 @@ qb_log_file_open(const char *filename)
return rc;
}
t->instance = fp;
- strncpy(t->name, filename, PATH_MAX);
+ strncpy(t->filename, filename, PATH_MAX);
t->logger = _file_logger;
t->reload = _file_reload;
diff --git a/lib/log_int.h b/lib/log_int.h
index 1e311db..a1755a9 100644
--- a/lib/log_int.h
+++ b/lib/log_int.h
@@ -31,6 +31,7 @@ struct qb_log_target {
uint32_t pos;
enum qb_log_target_state state;
char name[PATH_MAX];
+ char filename[PATH_MAX];
struct qb_list_head filter_head;
int32_t facility;
int32_t priority_bump;
--
1.7.7.5
12 years, 3 months
[PATCH] UTIL: fix qb_timespec_add_ms()
by Angus Salkeld
It was overwriting the timespec value instead of
add to it.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/util.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 51c94bb..6b835cc 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -126,8 +126,8 @@ void
qb_timespec_add_ms(struct timespec *ts, int32_t ms)
{
#ifndef S_SPLINT_S
- ts->tv_sec = ms / 1000;
- ts->tv_nsec = (ms % 1000) * QB_TIME_NS_IN_MSEC;
+ ts->tv_sec += ms / 1000;
+ ts->tv_nsec += (ms % 1000) * QB_TIME_NS_IN_MSEC;
if (ts->tv_nsec >= 1000000000L) {
ts->tv_sec++;
ts->tv_nsec = ts->tv_nsec - 1000000000L;
--
1.7.7.5
12 years, 3 months
[PATCH] LOG: make it possible to pass in a NULL filename/function into qb_log_from_external_source()
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log_dcs.c | 23 ++++++++++++++---------
tests/check_log.c | 8 ++++++++
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
index c5022a5..8f01889 100644
--- a/lib/log_dcs.c
+++ b/lib/log_dcs.c
@@ -112,25 +112,30 @@ qb_log_dcs_get(int32_t * newly_created,
struct callsite_list *csl_head;
struct callsite_list *csl_last;
struct callsite_list *csl;
+ const char *safe_filename = filename;
+ const char *safe_function = function;
+ if (filename == NULL) {
+ safe_filename = "";
+ }
+ if (function == NULL) {
+ safe_function = "";
+ }
/*
* try the fastest access first (no locking needed)
*/
rc = qb_array_index(lookup_arr, lineno, (void **)&csl_head);
- if (rc == 0 && csl_head->cs
- && strcmp(filename, csl_head->cs->filename) == 0) {
+ assert(rc == 0);
+ if (csl_head->cs
+ && strcmp(safe_filename, csl_head->cs->filename) == 0) {
return csl_head->cs;
}
/*
* so we will either have to create it or go through a list, so lock it.
*/
(void)qb_thread_lock(arr_next_lock);
- if (rc < 0) {
- rc = qb_array_index(lookup_arr, lineno, (void **)&csl_head);
- assert(rc == 0);
- }
if (csl_head->cs == NULL) {
- csl_head->cs = _log_dcs_new_cs(function, filename, format,
+ csl_head->cs = _log_dcs_new_cs(safe_function, safe_filename, format,
priority, lineno, tags);
cs = csl_head->cs;
csl_head->next = NULL;
@@ -138,7 +143,7 @@ qb_log_dcs_get(int32_t * newly_created,
} else {
for (csl = csl_head; csl; csl = csl->next) {
assert(csl->cs->lineno == lineno);
- if (strcmp(filename, csl->cs->filename) == 0) {
+ if (strcmp(safe_filename, csl->cs->filename) == 0) {
cs = csl->cs;
break;
}
@@ -150,7 +155,7 @@ qb_log_dcs_get(int32_t * newly_created,
if (csl == NULL) {
goto cleanup;
}
- csl->cs = _log_dcs_new_cs(function, filename, format,
+ csl->cs = _log_dcs_new_cs(safe_function, safe_filename, format,
priority, lineno, tags);
csl->next = NULL;
csl_last->next = csl;
diff --git a/tests/check_log.c b/tests/check_log.c
index 142384a..f49325d 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -246,6 +246,14 @@ START_TEST(test_log_basic)
log_also();
log_and_this_too();
ck_assert_int_eq(num_msgs, 2);
+
+ /*
+ * make sure we can pass in a null filename or function name.
+ */
+ qb_log_from_external_source(__func__, NULL, "%s", LOG_INFO,
+ __LINE__, 0, "null filename");
+ qb_log_from_external_source(NULL, __FILE__, "%s", LOG_INFO,
+ __LINE__, 0, "null function");
}
END_TEST
--
1.7.7.4
12 years, 4 months
ANNOUNCE release of 0.8.1
by Angus Salkeld
I am please to announce the release of version 0.8.1.
The details of the release can be found here:
https://github.com/asalkeld/libqb/wiki#wiki-Releases
The main features of the release are:
- The trie is now a patricia trie
- Many fixes to the map notification system
- Fix errors found by api-sanity-autotest
- ipc fixes for corosync
- Better support for compiling on mac (Thanks Andrew)
- Fix "make check" on sparc (Thanks Fabio)
Regards
Angus Salkeld
12 years, 4 months
[PATCH 1/2] Fix two simple coverity warnings
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
examples/tcpclient.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/examples/tcpclient.c b/examples/tcpclient.c
index 15c60f0..1222450 100644
--- a/examples/tcpclient.c
+++ b/examples/tcpclient.c
@@ -39,7 +39,7 @@ main(int argc, char *argv[])
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
- memcpy(&server_addr.sin_addr, host->h_addr, sizeof(host->h_addr));
+ memcpy(&server_addr.sin_addr, host->h_addr_list[0], sizeof(server_addr.sin_addr));
bzero(&(server_addr.sin_zero),8);
if (connect(sock, (struct sockaddr *)&server_addr,
@@ -65,9 +65,12 @@ main(int argc, char *argv[])
if (res > 0) {
res = recv(sock, recv_data, 1024, 0);
- recv_data[res] = '\0';
-
- printf("\nResponse: %s ", recv_data);
+ if (res > 0) {
+ recv_data[res] = '\0';
+ printf("\nResponse: %s ", recv_data);
+ } else {
+ perror("recv");
+ }
}
}
return EXIT_SUCCESS;
--
1.7.7.4
12 years, 4 months