make error in libqb/trunk
by Seth Lauzon
PASS: array.test
PASS: rb.test
PASS: log.test
PASS: loop.test
FAIL: ipc.test
FAIL: resources.test
===================================================
2 of 6 tests failed
See tests/test-suite.log
Please report to quarterback-devel(a)fedorahosted.org
===================================================
make[6]: *** [test-suite.log] Error 1
make[6]: Leaving directory `/usr/local/src/pve/libqb/trunk/libqb-0.5.0/tests'
make[5]: *** [check-TESTS] Error 2
make[5]: Leaving directory `/usr/local/src/pve/libqb/trunk/libqb-0.5.0/tests'
make[4]: *** [check-am] Error 2
make[4]: Leaving directory `/usr/local/src/pve/libqb/trunk/libqb-0.5.0/tests'
make[3]: *** [check-recursive] Error 1
make[3]: Leaving directory `/usr/local/src/pve/libqb/trunk/libqb-0.5.0'
make[2]: *** [check] Error 2
make[2]: Leaving directory `/usr/local/src/pve/libqb/trunk/libqb-0.5.0'
dh_auto_test: make -j1 check returned exit code 2
make[1]: *** [build] Error 29
make[1]: Leaving directory `/usr/local/src/pve/libqb/trunk/libqb-0.5.0'
dpkg-buildpackage: error: debian/rules build gave error exit status 2
make: *** [libqb_0.5.0-1_amd64.deb] Error 2
=============================================
libqb 0.5.0.2-42e7: tests/test-suite.log
==============================================
2 of 6 tests failed.
.. contents:: :depth: 2
FAIL: ipc.test (exit: 1)
========================
Running suite(s): ipc
[info] server name: test_ipc_txrx_shm_block
[info] IPC credentials authenticated
[info] server name: test_ipc_txrx_shm_tmo
[info] IPC credentials authenticated
[info] server name: test_ipc_txrx_us_block
[info] IPC credentials authenticated
[info] server name: test_ipc_txrx_us_tmo
[info] IPC credentials authenticated
[info] server name: test_ipc_fc_shm
[info] IPC credentials authenticated
[info] server name: test_ipc_fc_us
[info] IPC credentials authenticated
[info] server name: test_ipc_txrx_pmq
[info] IPC credentials authenticated
[info] server name: test_ipc_txrx_smq
[info] IPC credentials authenticated
[info] qb_ipcc_send: Invalid argument (22)
[info] server name: test_ipc_disp_shm
[info] IPC credentials authenticated
[info] server name: test_ipc_disp_us
[info] IPC credentials authenticated
[info] qb_ipcs_event_send: Socket operation on non-socket (88)
90%: Checks: 10, Failures: 0, Errors: 1
check_ipc.c:273:P:ipc_txrx_shm_block:test_ipc_txrx_shm_block:0: Passed
check_ipc.c:273:P:ipc_txrx_shm_tmo:test_ipc_txrx_shm_tmo:0: Passed
check_ipc.c:273:P:ipc_txrx_us_block:test_ipc_txrx_us_block:0: Passed
check_ipc.c:273:P:ipc_txrx_us_tmo:test_ipc_txrx_us_tmo:0: Passed
check_ipc.c:273:P:ipc_fc_shm:test_ipc_fc_shm:0: Passed
check_ipc.c:273:P:ipc_fc_us:test_ipc_fc_us:0: Passed
check_ipc.c:273:P:ipc_txrx_posix_mq:test_ipc_txrx_pmq:0: Passed
check_ipc.c:273:P:ipc_txrx_sysv_mq:test_ipc_txrx_smq:0: Passed
check_ipc.c:391:P:ipc_dispatch_shm:test_ipc_disp_shm:0: Passed
check_ipc.c:403:E:ipc_dispatch_us:test_ipc_disp_us:0: (after this point) Test timeout expired
FAIL: resources.test (exit: 1)
==============================
/dev/shm/qb-test_ipc_disp_us-control-13639-8
/dev/shm/qb-test_ipc_disp_us-control-19058-8
/dev/shm/qb-test_ipc_disp_us-control-3040-8
/dev/shm/qb-test_ipc_disp_us-control-8355-8
Error: shared memory segments not closed/unlinked
Any help is greatly appreciated.
Thanks,
Seth
12 years, 9 months
[PATCH] LOG: use strerror_r instead of strerror in qb_perror()
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblog.h | 17 +++++++++++++++--
tests/check_log.c | 5 ++++-
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index 815f1bd..c841697 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -213,6 +213,7 @@ extern "C" {
#define LOG_TRACE (LOG_DEBUG + 1)
#define QB_LOG_MAX_LEN 512
+#define QB_LOG_STRERROR_MAX_LEN 128
typedef const char *(*qb_log_tags_stringify_fn)(uint32_t tags);
@@ -322,11 +323,23 @@ void qb_log_from_external_source(const char *function,
* @param args usual printf style args
*/
#ifndef S_SPLINT_S
+#ifdef _GNU_SOURCE
+/* The GNU version of strerror_r returns a (char*) that *must* be used */
#define qb_perror(priority, fmt, args...) do { \
- const char *err = strerror(errno); \
- qb_logt(priority, 0, fmt ": %s (%d)", ##args, err, errno); \
+ char _perr_buf_[QB_LOG_STRERROR_MAX_LEN]; \
+ const char *_perr_str_ = strerror_r(errno, _perr_buf_, sizeof(_perr_buf_)); \
+ qb_logt(priority, 0, fmt ": %s (%d)", ##args, _perr_str_, errno); \
} while(0)
#else
+/* The XSI-compliant strerror_r() return 0 or -1 (in case the buffer is full) */
+#define qb_perror(priority, fmt, args...) do { \
+ char _perr_buf_[QB_LOG_STRERROR_MAX_LEN]; \
+ if (strerror_r(errno, _perr_buf_, sizeof(_perr_buf_)) == 0) { \
+ qb_logt(priority, 0, fmt ": %s (%d)", ##args, _perr_buf_, errno); \
+ } else { qb_logt(priority, 0, fmt ": (%d)", ##args, errno); } \
+ } while(0)
+#endif
+#else
#define qb_perror
#endif
diff --git a/tests/check_log.c b/tests/check_log.c
index ca7103f..8326111 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -106,6 +106,9 @@ static void log_it_please(void)
qb_enter();
qb_log(LOG_TRACE, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_DEBUG, "A:%d B:%d C:%d", 1, 2, 3);
+ errno = EEXIST;
+ qb_perror(LOG_WARNING, "bogus error");
+ errno = 0;
qb_log(LOG_INFO, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_NOTICE, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_WARNING, "A:%d B:%d C:%d", 1, 2, 3);
@@ -156,7 +159,7 @@ START_TEST(test_log_basic)
num_msgs = 0;
qb_log(LOG_ERR, "try if you: log_it_please()");
log_it_please();
- ck_assert_int_eq(num_msgs, 2);
+ ck_assert_int_eq(num_msgs, 3);
qb_log_filter_ctl(t, QB_LOG_FILTER_REMOVE,
QB_LOG_FILTER_FUNCTION, "log_it_please", LOG_WARNING);
--
1.7.5.2
12 years, 9 months
[PATCH] TEST: bump up the logging timeout
by Angus Salkeld
This was failing on sparcv9, but seems to just be a slow machine.
With a bigger timeout it passes.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/check_log.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/check_log.c b/tests/check_log.c
index fdc04d2..ca7103f 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -377,7 +377,7 @@ static Suite *log_suite(void)
tc = tcase_create("threads");
tcase_add_test(tc, test_log_threads);
- tcase_set_timeout(tc, 30);
+ tcase_set_timeout(tc, 360);
suite_add_tcase(s, tc);
tc = tcase_create("long_msg");
--
1.7.5.2
12 years, 9 months
[PATCH 1/3] Revert "LOG: use uint8_t for pointer manipulation"
by Angus Salkeld
This reverts commit a47ae0b6598f16189d55386ef9a3ad1cad204893.
---
lib/log_blackbox.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c
index d24eb8a..0a88e12 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -141,7 +141,7 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
{
qb_ringbuffer_t *instance;
ssize_t bytes_read;
- uint8_t chunk[512];
+ char chunk[512];
int fd;
char time_buf[64];
@@ -157,10 +157,10 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
}
do {
- uint8_t *ptr;
+ char *ptr;
uint32_t *lineno;
uint32_t *fn_size;
- uint8_t *function;
+ char *function;
time_t *timestamp;
/* uint32_t *log_size; */
--
1.7.5.2
12 years, 9 months
[PATCH 1/2] LOG: use uint8_t for pointer manipulation
by Angus Salkeld
char changes size on different arches.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log_blackbox.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c
index 1e21f74..60f9e52 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -135,7 +135,7 @@ void qb_log_blackbox_print_from_file(const char *bb_filename)
{
qb_ringbuffer_t *instance;
ssize_t bytes_read;
- char chunk[512];
+ uint8_t chunk[512];
int fd;
char time_buf[64];
@@ -151,10 +151,10 @@ void qb_log_blackbox_print_from_file(const char *bb_filename)
}
do {
- char *ptr;
+ uint8_t *ptr;
uint32_t *lineno;
uint32_t *fn_size;
- char *function;
+ uint8_t *function;
time_t *timestamp;
/*uint32_t *log_size;*/
--
1.7.5.2
12 years, 9 months
[PATCH] Fix references to README
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
Makefile.am | 2 +-
libqb.spec.in | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 37c80c6..624baf5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,7 +39,7 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure depcomp \
ACLOCAL_AMFLAGS = -I m4
-dist_doc_DATA = COPYING INSTALL README TODO
+dist_doc_DATA = COPYING INSTALL README.markdown TODO
SUBDIRS = include lib docs tests
diff --git a/libqb.spec.in b/libqb.spec.in
index d23221c..f734656 100644
--- a/libqb.spec.in
+++ b/libqb.spec.in
@@ -59,7 +59,7 @@ developing applications that use %{name}.
%files devel
%defattr(-,root,root,-)
-%doc COPYING README
+%doc COPYING README.markdown
%{_includedir}/qb/
%{_libdir}/libqb.so
%{_libdir}/pkgconfig/libqb.pc
--
1.7.5.2
12 years, 9 months
[PATCH 1/2] Change Lindent options to break the procedure type.
by Angus Salkeld
so change:
int foo(void)
to
int
foo(void)
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
Lindent | 7 +-
lib/array.c | 23 ++--
lib/atomic_gcc.c | 41 ++++---
lib/atomic_lock.c | 63 ++++++----
lib/hdb.c | 62 ++++++----
lib/ipc_posix_mq.c | 74 ++++++-----
lib/ipc_shm.c | 85 +++++++------
lib/ipc_sysv_mq.c | 76 +++++++-----
lib/ipc_us.c | 171 ++++++++++++++-----------
lib/ipcc.c | 38 +++---
lib/ipcs.c | 147 +++++++++++++---------
lib/log.c | 151 ++++++++++++----------
lib/log_blackbox.c | 24 ++--
lib/log_dcs.c | 48 +++----
lib/log_file.c | 21 ++-
lib/log_format.c | 23 ++--
lib/log_syslog.c | 15 ++-
lib/log_thread.c | 35 +++--
lib/loop.c | 30 +++--
lib/loop_job.c | 22 ++--
lib/loop_poll.c | 327 ++++++++++++++++++++++++++---------------------
lib/loop_timerlist.c | 83 +++++++------
lib/ringbuffer.c | 76 +++++++-----
lib/ringbuffer_helper.c | 40 ++++---
lib/util.c | 83 +++++++-----
25 files changed, 1012 insertions(+), 753 deletions(-)
diff --git a/Lindent b/Lindent
index 68bf25e..0c39b28 100755
--- a/Lindent
+++ b/Lindent
@@ -4,7 +4,12 @@
# we use the same formatting. No point re-inventing that
# wheel.
#
-PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
+# Differences to kernel style:
+# --dont-break-procedure-type -> --break-procedure-type
+#
+PARAM="-npro -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
+-cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -psl -sai
+-saf -saw -ncs -nsc -sob -nfca -cp1 -ss -ts8"
RES=`indent --version`
V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
diff --git a/lib/array.c b/lib/array.c
index 937e7f1..51cc9f7 100644
--- a/lib/array.c
+++ b/lib/array.c
@@ -35,12 +35,13 @@ struct qb_array {
size_t num_bins;
};
-qb_array_t* qb_array_create(size_t max_elements, size_t element_size)
+qb_array_t *
+qb_array_create(size_t max_elements, size_t element_size)
{
int32_t i;
struct qb_array *a = NULL;
- if (max_elements > (MAX_BIN_ELEMENTS*MAX_BINS)) {
+ if (max_elements > (MAX_BIN_ELEMENTS * MAX_BINS)) {
errno = -EINVAL;
return NULL;
}
@@ -66,7 +67,8 @@ qb_array_t* qb_array_create(size_t max_elements, size_t element_size)
return a;
}
-int32_t qb_array_index(struct qb_array* a, int32_t idx, void** element_out)
+int32_t
+qb_array_index(struct qb_array * a, int32_t idx, void **element_out)
{
int32_t b;
int32_t elem;
@@ -88,7 +90,8 @@ int32_t qb_array_index(struct qb_array* a, int32_t idx, void** element_out)
return 0;
}
-size_t qb_array_num_bins_get(struct qb_array* a)
+size_t
+qb_array_num_bins_get(struct qb_array * a)
{
if (a == NULL) {
return -EINVAL;
@@ -96,7 +99,8 @@ size_t qb_array_num_bins_get(struct qb_array* a)
return a->num_bins;
}
-size_t qb_array_elems_per_bin_get(struct qb_array* a)
+size_t
+qb_array_elems_per_bin_get(struct qb_array * a)
{
if (a == NULL) {
return -EINVAL;
@@ -104,12 +108,13 @@ size_t qb_array_elems_per_bin_get(struct qb_array* a)
return MAX_BIN_ELEMENTS;
}
-int32_t qb_array_grow(struct qb_array* a, size_t max_elements)
+int32_t
+qb_array_grow(struct qb_array * a, size_t max_elements)
{
int32_t i;
int32_t old_bins;
- if (a == NULL || max_elements > (MAX_BIN_ELEMENTS*MAX_BINS)) {
+ if (a == NULL || max_elements > (MAX_BIN_ELEMENTS * MAX_BINS)) {
return -EINVAL;
}
if (max_elements <= a->max_elements) {
@@ -129,7 +134,8 @@ int32_t qb_array_grow(struct qb_array* a, size_t max_elements)
return 0;
}
-void qb_array_free(struct qb_array* a)
+void
+qb_array_free(struct qb_array *a)
{
int32_t i;
for (i = 0; i < a->num_bins; i++) {
@@ -137,4 +143,3 @@ void qb_array_free(struct qb_array* a)
}
free(a);
}
-
diff --git a/lib/atomic_gcc.c b/lib/atomic_gcc.c
index 45d0e90..80499cb 100644
--- a/lib/atomic_gcc.c
+++ b/lib/atomic_gcc.c
@@ -25,55 +25,64 @@
#include "config.h"
#include <qb/qbatomic.h>
-void qb_atomic_init(void)
+void
+qb_atomic_init(void)
{
}
-int32_t qb_atomic_int_exchange_and_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
- int32_t val)
+int32_t
+qb_atomic_int_exchange_and_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t val)
{
return __sync_fetch_and_add(atomic, val);
}
-void qb_atomic_int_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)
+void
+qb_atomic_int_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)
{
__sync_fetch_and_add(atomic, val);
}
-int32_t qb_atomic_int_compare_and_exchange(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
- int32_t oldval, int32_t newval)
+int32_t
+qb_atomic_int_compare_and_exchange(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t oldval, int32_t newval)
{
return __sync_bool_compare_and_swap(atomic, oldval, newval);
}
-int32_t qb_atomic_pointer_compare_and_exchange(volatile void* QB_GNUC_MAY_ALIAS * atomic,
- void* oldval, void* newval)
+int32_t
+qb_atomic_pointer_compare_and_exchange(volatile void *QB_GNUC_MAY_ALIAS *
+ atomic, void *oldval, void *newval)
{
return __sync_bool_compare_and_swap(atomic, oldval, newval);
}
-int32_t (qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)
+int32_t
+(qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)
{
__sync_synchronize();
return *atomic;
}
-void (qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
- int32_t newval)
+void
+(qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t newval)
{
*atomic = newval;
__sync_synchronize();
}
-void* (qb_atomic_pointer_get) (volatile void* QB_GNUC_MAY_ALIAS * atomic)
+void *
+(qb_atomic_pointer_get) (volatile void *QB_GNUC_MAY_ALIAS * atomic)
{
__sync_synchronize();
- return (void*)*atomic;
+ return (void *)*atomic;
}
-void (qb_atomic_pointer_set) (volatile void* QB_GNUC_MAY_ALIAS * atomic,
- void* newval)
+void
+(qb_atomic_pointer_set) (volatile void *QB_GNUC_MAY_ALIAS * atomic,
+ void *newval)
{
*atomic = newval;
__sync_synchronize();
-}
+}
\ No newline at end of file
diff --git a/lib/atomic_lock.c b/lib/atomic_lock.c
index 595cc3d..ba52092 100644
--- a/lib/atomic_lock.c
+++ b/lib/atomic_lock.c
@@ -45,7 +45,8 @@
/* We have to use the slow, but safe locking method */
static qb_thread_lock_t *qb_atomic_mutex = NULL;
-void qb_atomic_init(void)
+void
+qb_atomic_init(void)
{
if (qb_atomic_mutex == NULL) {
qb_atomic_mutex = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
@@ -54,7 +55,8 @@ void qb_atomic_init(void)
}
int32_t
-qb_atomic_int_exchange_and_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)
+qb_atomic_int_exchange_and_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t val)
{
int32_t result;
@@ -66,15 +68,17 @@ qb_atomic_int_exchange_and_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int3
return result;
}
-void qb_atomic_int_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)
+void
+qb_atomic_int_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)
{
qb_thread_lock(qb_atomic_mutex);
*atomic += val;
qb_thread_unlock(qb_atomic_mutex);
}
-int32_t qb_atomic_int_compare_and_exchange(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
- int32_t oldval, int32_t newval)
+int32_t
+qb_atomic_int_compare_and_exchange(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t oldval, int32_t newval)
{
int32_t result;
@@ -90,8 +94,9 @@ int32_t qb_atomic_int_compare_and_exchange(volatile int32_t QB_GNUC_MAY_ALIAS *
return result;
}
-int32_t qb_atomic_pointer_compare_and_exchange(volatile void* QB_GNUC_MAY_ALIAS *
- atomic, void* oldval, void* newval)
+int32_t
+qb_atomic_pointer_compare_and_exchange(volatile void *QB_GNUC_MAY_ALIAS *
+ atomic, void *oldval, void *newval)
{
int32_t result;
@@ -119,16 +124,19 @@ int32_t(qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic) {
return result;
}
-void (qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t newval)
+void
+(qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t newval)
{
qb_thread_lock(qb_atomic_mutex);
*atomic = newval;
qb_thread_unlock(qb_atomic_mutex);
}
-void* (qb_atomic_pointer_get) (volatile void* QB_GNUC_MAY_ALIAS * atomic)
+void *
+(qb_atomic_pointer_get) (volatile void *QB_GNUC_MAY_ALIAS * atomic)
{
- void* result;
+ void *result;
qb_thread_lock(qb_atomic_mutex);
result = *atomic;
@@ -137,34 +145,40 @@ void* (qb_atomic_pointer_get) (volatile void* QB_GNUC_MAY_ALIAS * atomic)
return result;
}
-void (qb_atomic_pointer_set) (volatile void* QB_GNUC_MAY_ALIAS * atomic,
- void* newval)
+void
+(qb_atomic_pointer_set) (volatile void *QB_GNUC_MAY_ALIAS * atomic,
+ void *newval)
{
qb_thread_lock(qb_atomic_mutex);
*atomic = newval;
qb_thread_unlock(qb_atomic_mutex);
}
-int32_t (qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)
+int32_t
+(qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)
{
QB_ATOMIC_MEMORY_BARRIER;
return *atomic;
}
-void (qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t newval)
+void
+(qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+ int32_t newval)
{
*atomic = newval;
QB_ATOMIC_MEMORY_BARRIER;
}
-void* (qb_atomic_pointer_get) (volatile void* QB_GNUC_MAY_ALIAS * atomic)
+void *
+(qb_atomic_pointer_get) (volatile void *QB_GNUC_MAY_ALIAS * atomic)
{
QB_ATOMIC_MEMORY_BARRIER;
return *atomic;
}
-void (qb_atomic_pointer_set) (volatile void* QB_GNUC_MAY_ALIAS * atomic,
- void* newval)
+void
+(qb_atomic_pointer_set) (volatile void *QB_GNUC_MAY_ALIAS * atomic,
+ void *newval)
{
*atomic = newval;
QB_ATOMIC_MEMORY_BARRIER;
@@ -173,24 +187,27 @@ void (qb_atomic_pointer_set) (volatile void* QB_GNUC_MAY_ALIAS * atomic,
#endif /* QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
#ifndef QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED
-int32_t (qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)
+int32_t
+(qb_atomic_int_get) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)
{
return qb_atomic_int_get(atomic);
}
-void (qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
+void
+(qb_atomic_int_set) (volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
int32_t newval)
{
qb_atomic_int_set(atomic, newval);
}
-void* (qb_atomic_pointer_get) (volatile void* QB_GNUC_MAY_ALIAS * atomic)
-{
+void *
+(qb_atomic_pointer_get) (volatile void *QB_GNUC_MAY_ALIAS * atomic) {
return qb_atomic_pointer_get(atomic);
}
-void (qb_atomic_pointer_set) (volatile void* QB_GNUC_MAY_ALIAS * atomic,
- void* newval)
+void
+(qb_atomic_pointer_set) (volatile void *QB_GNUC_MAY_ALIAS * atomic,
+ void *newval)
{
qb_atomic_pointer_set(atomic, newval);
}
diff --git a/lib/hdb.c b/lib/hdb.c
index 837eefc..34cd72e 100644
--- a/lib/hdb.c
+++ b/lib/hdb.c
@@ -29,7 +29,8 @@ enum QB_HDB_HANDLE_STATE {
QB_HDB_HANDLE_STATE_ACTIVE
};
-static void qb_hdb_create_first_run(struct qb_hdb *hdb)
+static void
+qb_hdb_create_first_run(struct qb_hdb *hdb)
{
if (hdb->first_run == 1) {
hdb->first_run = 0;
@@ -38,21 +39,24 @@ static void qb_hdb_create_first_run(struct qb_hdb *hdb)
}
}
-void qb_hdb_create(struct qb_hdb *hdb)
+void
+qb_hdb_create(struct qb_hdb *hdb)
{
memset(hdb, 0, sizeof(struct qb_hdb));
hdb->first_run = 1;
qb_hdb_create_first_run(hdb);
}
-void qb_hdb_destroy(struct qb_hdb *hdb)
+void
+qb_hdb_destroy(struct qb_hdb *hdb)
{
qb_array_free(hdb->handles);
memset(hdb, 0, sizeof(struct qb_hdb));
}
-int32_t qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size,
- qb_handle_t * handle_id_out)
+int32_t
+qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size,
+ qb_handle_t * handle_id_out)
{
int32_t handle;
int32_t res = 0;
@@ -80,11 +84,12 @@ int32_t qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size,
if (res != 0) {
return res;
}
- res = qb_array_index(hdb->handles, handle_count, (void**)&entry);
+ res = qb_array_index(hdb->handles, handle_count,
+ (void **)&entry);
if (res != 0) {
return res;
}
- qb_atomic_int_inc((int32_t*)&hdb->handle_count);
+ qb_atomic_int_inc((int32_t *)&hdb->handle_count);
}
instance = malloc(instance_size);
@@ -117,8 +122,8 @@ int32_t qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size,
return res;
}
-int32_t qb_hdb_handle_get(struct qb_hdb * hdb, qb_handle_t handle_in,
- void **instance)
+int32_t
+qb_hdb_handle_get(struct qb_hdb * hdb, qb_handle_t handle_in, void **instance)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
@@ -133,7 +138,7 @@ int32_t qb_hdb_handle_get(struct qb_hdb * hdb, qb_handle_t handle_in,
return (-EBADF);
}
- if (qb_array_index(hdb->handles, handle, (void**)&entry) != 0 ||
+ if (qb_array_index(hdb->handles, handle, (void **)&entry) != 0 ||
entry->state != QB_HDB_HANDLE_STATE_ACTIVE) {
return (-EBADF);
}
@@ -148,13 +153,15 @@ int32_t qb_hdb_handle_get(struct qb_hdb * hdb, qb_handle_t handle_in,
return (0);
}
-int32_t qb_hdb_handle_get_always(struct qb_hdb * hdb, qb_handle_t handle_in,
- void **instance)
+int32_t
+qb_hdb_handle_get_always(struct qb_hdb * hdb, qb_handle_t handle_in,
+ void **instance)
{
return qb_hdb_handle_get(hdb, handle_in, instance);
}
-int32_t qb_hdb_handle_put(struct qb_hdb * hdb, qb_handle_t handle_in)
+int32_t
+qb_hdb_handle_put(struct qb_hdb * hdb, qb_handle_t handle_in)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
@@ -168,7 +175,7 @@ int32_t qb_hdb_handle_put(struct qb_hdb * hdb, qb_handle_t handle_in)
return (-EBADF);
}
- if (qb_array_index(hdb->handles, handle, (void**)&entry) != 0 ||
+ if (qb_array_index(hdb->handles, handle, (void **)&entry) != 0 ||
(check != 0xffffffff && check != entry->check)) {
return (-EBADF);
}
@@ -183,7 +190,8 @@ int32_t qb_hdb_handle_put(struct qb_hdb * hdb, qb_handle_t handle_in)
return (0);
}
-int32_t qb_hdb_handle_destroy(struct qb_hdb * hdb, qb_handle_t handle_in)
+int32_t
+qb_hdb_handle_destroy(struct qb_hdb * hdb, qb_handle_t handle_in)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
@@ -198,7 +206,7 @@ int32_t qb_hdb_handle_destroy(struct qb_hdb * hdb, qb_handle_t handle_in)
return (-EBADF);
}
- if (qb_array_index(hdb->handles, handle, (void**)&entry) != 0 ||
+ if (qb_array_index(hdb->handles, handle, (void **)&entry) != 0 ||
(check != 0xffffffff && check != entry->check)) {
return (-EBADF);
}
@@ -208,7 +216,8 @@ int32_t qb_hdb_handle_destroy(struct qb_hdb * hdb, qb_handle_t handle_in)
return (res);
}
-int32_t qb_hdb_handle_refcount_get(struct qb_hdb * hdb, qb_handle_t handle_in)
+int32_t
+qb_hdb_handle_refcount_get(struct qb_hdb * hdb, qb_handle_t handle_in)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
@@ -223,7 +232,7 @@ int32_t qb_hdb_handle_refcount_get(struct qb_hdb * hdb, qb_handle_t handle_in)
return (-EBADF);
}
- if (qb_array_index(hdb->handles, handle, (void**)&entry) != 0 ||
+ if (qb_array_index(hdb->handles, handle, (void **)&entry) != 0 ||
(check != 0xffffffff && check != entry->check)) {
return (-EBADF);
}
@@ -233,13 +242,14 @@ int32_t qb_hdb_handle_refcount_get(struct qb_hdb * hdb, qb_handle_t handle_in)
return (refcount);
}
-void qb_hdb_iterator_reset(struct qb_hdb *hdb)
+void
+qb_hdb_iterator_reset(struct qb_hdb *hdb)
{
hdb->iterator = 0;
}
-int32_t qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance,
- qb_handle_t * handle)
+int32_t
+qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance, qb_handle_t * handle)
{
int32_t res = -1;
uint64_t checker;
@@ -248,7 +258,9 @@ int32_t qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance,
handle_count = qb_atomic_int_get(&hdb->handle_count);
while (hdb->iterator < handle_count) {
- res = qb_array_index(hdb->handles, hdb->iterator, (void**)&entry);
+ res = qb_array_index(hdb->handles,
+ hdb->iterator,
+ (void **)&entry);
if (res != 0) {
break;
}
@@ -264,12 +276,14 @@ int32_t qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance,
return (res);
}
-uint32_t qb_hdb_base_convert(qb_handle_t handle)
+uint32_t
+qb_hdb_base_convert(qb_handle_t handle)
{
return (handle & 0xffffffff);
}
-uint64_t qb_hdb_nocheck_convert(uint32_t handle)
+uint64_t
+qb_hdb_nocheck_convert(uint32_t handle)
{
uint64_t retvalue = 0xffffffffULL << 32 | handle;
diff --git a/lib/ipc_posix_mq.c b/lib/ipc_posix_mq.c
index b61a662..068fad3 100644
--- a/lib/ipc_posix_mq.c
+++ b/lib/ipc_posix_mq.c
@@ -41,7 +41,8 @@ static size_t q_space_used = 0;
* utility functions
* --------------------------------------------------------
*/
-static int32_t posix_mq_increase_limits(size_t max_msg_size, int32_t q_len)
+static int32_t
+posix_mq_increase_limits(size_t max_msg_size, int32_t q_len)
{
int32_t res = 0;
#ifdef QB_RLIMIT_CHANGE_NEEDED
@@ -74,8 +75,8 @@ static int32_t posix_mq_increase_limits(size_t max_msg_size, int32_t q_len)
return res;
}
-static int32_t posix_mq_open(struct qb_ipc_one_way *one_way,
- const char *name, size_t q_len)
+static int32_t
+posix_mq_open(struct qb_ipc_one_way *one_way, const char *name, size_t q_len)
{
int32_t res = posix_mq_increase_limits(one_way->max_msg_size, q_len);
if (res != 0) {
@@ -92,9 +93,9 @@ static int32_t posix_mq_open(struct qb_ipc_one_way *one_way,
return 0;
}
-static int32_t posix_mq_create(struct qb_ipcs_connection *c,
- struct qb_ipc_one_way *one_way,
- const char *name, size_t q_len)
+static int32_t
+posix_mq_create(struct qb_ipcs_connection *c,
+ struct qb_ipc_one_way *one_way, const char *name, size_t q_len)
{
struct mq_attr attr;
mqd_t q = 0;
@@ -142,8 +143,9 @@ try_smaller:
return res;
}
-static ssize_t qb_ipc_pmq_send(struct qb_ipc_one_way *one_way,
- const void *msg_ptr, size_t msg_len)
+static ssize_t
+qb_ipc_pmq_send(struct qb_ipc_one_way *one_way,
+ const void *msg_ptr, size_t msg_len)
{
int32_t res = mq_send(one_way->u.pmq.q, msg_ptr, msg_len, 1);
if (res != 0) {
@@ -152,9 +154,9 @@ static ssize_t qb_ipc_pmq_send(struct qb_ipc_one_way *one_way,
return msg_len;
}
-static ssize_t qb_ipc_pmq_sendv(struct qb_ipc_one_way *one_way,
- const struct iovec* iov,
- size_t iov_len)
+static ssize_t
+qb_ipc_pmq_sendv(struct qb_ipc_one_way *one_way,
+ const struct iovec *iov, size_t iov_len)
{
int32_t total_size = 0;
int32_t i;
@@ -184,10 +186,9 @@ static ssize_t qb_ipc_pmq_sendv(struct qb_ipc_one_way *one_way,
return total_size;
}
-static ssize_t qb_ipc_pmq_recv(struct qb_ipc_one_way *one_way,
- void *msg_ptr,
- size_t msg_len,
- int32_t ms_timeout)
+static ssize_t
+qb_ipc_pmq_recv(struct qb_ipc_one_way *one_way,
+ void *msg_ptr, size_t msg_len, int32_t ms_timeout)
{
uint32_t msg_prio;
struct timespec ts_timeout;
@@ -198,18 +199,16 @@ static ssize_t qb_ipc_pmq_recv(struct qb_ipc_one_way *one_way,
qb_timespec_add_ms(&ts_timeout, ms_timeout);
}
- mq_receive_again:
+mq_receive_again:
if (ms_timeout >= 0) {
res = mq_timedreceive(one_way->u.pmq.q,
(char *)msg_ptr,
one_way->max_msg_size,
- &msg_prio,
- &ts_timeout);
+ &msg_prio, &ts_timeout);
} else {
res = mq_receive(one_way->u.pmq.q,
(char *)msg_ptr,
- one_way->max_msg_size,
- &msg_prio);
+ one_way->max_msg_size, &msg_prio);
}
if (res == -1) {
switch (errno) {
@@ -238,7 +237,8 @@ static ssize_t qb_ipc_pmq_recv(struct qb_ipc_one_way *one_way,
* --------------------------------------------------------
*/
-static void qb_ipcc_pmq_disconnect(struct qb_ipcc_connection *c)
+static void
+qb_ipcc_pmq_disconnect(struct qb_ipcc_connection *c)
{
struct qb_ipc_request_header hdr;
@@ -260,8 +260,9 @@ static void qb_ipcc_pmq_disconnect(struct qb_ipcc_connection *c)
mq_unlink(c->response.u.pmq.name);
}
-int32_t qb_ipcc_pmq_connect(struct qb_ipcc_connection *c,
- struct qb_ipc_connection_response *response)
+int32_t
+qb_ipcc_pmq_connect(struct qb_ipcc_connection *c,
+ struct qb_ipc_connection_response *response)
{
int32_t res = 0;
@@ -280,8 +281,7 @@ int32_t qb_ipcc_pmq_connect(struct qb_ipcc_connection *c,
return -EINVAL;
}
- res = posix_mq_open(&c->request, response->request,
- QB_REQUEST_Q_LEN);
+ res = posix_mq_open(&c->request, response->request, QB_REQUEST_Q_LEN);
if (res != 0) {
perror("mq_open:REQUEST");
return res;
@@ -314,7 +314,8 @@ cleanup_request:
* --------------------------------------------------------
*/
-static void qb_ipcs_pmq_disconnect(struct qb_ipcs_connection *c)
+static void
+qb_ipcs_pmq_disconnect(struct qb_ipcs_connection *c)
{
struct qb_ipc_response_header msg;
@@ -333,9 +334,10 @@ static void qb_ipcs_pmq_disconnect(struct qb_ipcs_connection *c)
mq_unlink(c->response.u.pmq.name);
}
-static int32_t qb_ipcs_pmq_connect(struct qb_ipcs_service *s,
- struct qb_ipcs_connection *c,
- struct qb_ipc_connection_response *r)
+static int32_t
+qb_ipcs_pmq_connect(struct qb_ipcs_service *s,
+ struct qb_ipcs_connection *c,
+ struct qb_ipc_connection_response *r)
{
int32_t res = 0;
@@ -359,9 +361,11 @@ static int32_t qb_ipcs_pmq_connect(struct qb_ipcs_service *s,
}
if (!s->needs_sock_for_poll) {
- res = s->poll_fns.dispatch_add(s->poll_priority, (int32_t)c->request.u.pmq.q,
- POLLIN | POLLPRI | POLLNVAL,
- c, qb_ipcs_dispatch_service_request);
+ res =
+ s->poll_fns.dispatch_add(s->poll_priority,
+ (int32_t) c->request.u.pmq.q,
+ POLLIN | POLLPRI | POLLNVAL, c,
+ qb_ipcs_dispatch_service_request);
}
r->hdr.error = 0;
@@ -380,7 +384,8 @@ cleanup:
return res;
}
-static ssize_t qb_ipc_pmq_q_len_get(struct qb_ipc_one_way *one_way)
+static ssize_t
+qb_ipc_pmq_q_len_get(struct qb_ipc_one_way *one_way)
{
struct mq_attr info;
int32_t res = mq_getattr(one_way->u.pmq.q, &info);
@@ -390,7 +395,8 @@ static ssize_t qb_ipc_pmq_q_len_get(struct qb_ipc_one_way *one_way)
return -errno;
}
-void qb_ipcs_pmq_init(struct qb_ipcs_service * s)
+void
+qb_ipcs_pmq_init(struct qb_ipcs_service *s)
{
s->funcs.connect = qb_ipcs_pmq_connect;
s->funcs.disconnect = qb_ipcs_pmq_disconnect;
diff --git a/lib/ipc_shm.c b/lib/ipc_shm.c
index d9112e2..1f38f26 100644
--- a/lib/ipc_shm.c
+++ b/lib/ipc_shm.c
@@ -35,22 +35,24 @@
* client functions
* --------------------------------------------------------
*/
-static void qb_ipcc_shm_disconnect(struct qb_ipcc_connection *c)
+static void
+qb_ipcc_shm_disconnect(struct qb_ipcc_connection *c)
{
qb_rb_close(c->request.u.shm.rb);
qb_rb_close(c->response.u.shm.rb);
qb_rb_close(c->event.u.shm.rb);
}
-static ssize_t qb_ipc_shm_send(struct qb_ipc_one_way *one_way,
- const void *msg_ptr, size_t msg_len)
+static ssize_t
+qb_ipc_shm_send(struct qb_ipc_one_way *one_way,
+ const void *msg_ptr, size_t msg_len)
{
return qb_rb_chunk_write(one_way->u.shm.rb, msg_ptr, msg_len);
}
-static ssize_t qb_ipc_shm_sendv(struct qb_ipc_one_way *one_way,
- const struct iovec* iov,
- size_t iov_len)
+static ssize_t
+qb_ipc_shm_sendv(struct qb_ipc_one_way *one_way,
+ const struct iovec *iov, size_t iov_len)
{
char *dest;
int32_t res = 0;
@@ -82,39 +84,37 @@ static ssize_t qb_ipc_shm_sendv(struct qb_ipc_one_way *one_way,
return total_size;
}
-static ssize_t qb_ipc_shm_recv(struct qb_ipc_one_way *one_way,
- void *msg_ptr,
- size_t msg_len,
- int32_t ms_timeout)
+static ssize_t
+qb_ipc_shm_recv(struct qb_ipc_one_way *one_way,
+ void *msg_ptr, size_t msg_len, int32_t ms_timeout)
{
if (one_way->u.shm.rb == NULL) {
return -ENOTCONN;
}
return qb_rb_chunk_read(one_way->u.shm.rb,
- (void *)msg_ptr,
- msg_len,
- ms_timeout);
+ (void *)msg_ptr, msg_len, ms_timeout);
}
-static ssize_t qb_ipc_shm_peek(struct qb_ipc_one_way *one_way, void **data_out, int32_t ms_timeout)
+static ssize_t
+qb_ipc_shm_peek(struct qb_ipc_one_way *one_way, void **data_out,
+ int32_t ms_timeout)
{
if (one_way->u.shm.rb == NULL) {
return -ENOTCONN;
}
- return qb_rb_chunk_peek(one_way->u.shm.rb,
- data_out,
- ms_timeout);
+ return qb_rb_chunk_peek(one_way->u.shm.rb, data_out, ms_timeout);
}
-static void qb_ipc_shm_reclaim(struct qb_ipc_one_way *one_way)
+static void
+qb_ipc_shm_reclaim(struct qb_ipc_one_way *one_way)
{
if (one_way->u.shm.rb != NULL) {
qb_rb_chunk_reclaim(one_way->u.shm.rb);
}
}
-static void qb_ipc_shm_fc_set(struct qb_ipc_one_way *one_way,
- int32_t fc_enable)
+static void
+qb_ipc_shm_fc_set(struct qb_ipc_one_way *one_way, int32_t fc_enable)
{
int32_t *fc;
fc = qb_rb_shared_user_data_get(one_way->u.shm.rb);
@@ -122,7 +122,8 @@ static void qb_ipc_shm_fc_set(struct qb_ipc_one_way *one_way,
qb_atomic_int_set(fc, fc_enable);
}
-static int32_t qb_ipc_shm_fc_get(struct qb_ipc_one_way *one_way)
+static int32_t
+qb_ipc_shm_fc_get(struct qb_ipc_one_way *one_way)
{
int32_t *fc;
int32_t rc = qb_rb_refcount_get(one_way->u.shm.rb);
@@ -134,7 +135,8 @@ static int32_t qb_ipc_shm_fc_get(struct qb_ipc_one_way *one_way)
return qb_atomic_int_get(fc);
}
-static ssize_t qb_ipc_shm_q_len_get(struct qb_ipc_one_way *one_way)
+static ssize_t
+qb_ipc_shm_q_len_get(struct qb_ipc_one_way *one_way)
{
if (one_way->u.shm.rb == NULL) {
return -ENOTCONN;
@@ -142,8 +144,9 @@ static ssize_t qb_ipc_shm_q_len_get(struct qb_ipc_one_way *one_way)
return qb_rb_chunks_used(one_way->u.shm.rb);
}
-int32_t qb_ipcc_shm_connect(struct qb_ipcc_connection *c,
- struct qb_ipc_connection_response *response)
+int32_t
+qb_ipcc_shm_connect(struct qb_ipcc_connection * c,
+ struct qb_ipc_connection_response * response)
{
int32_t res = 0;
@@ -159,9 +162,9 @@ int32_t qb_ipcc_shm_connect(struct qb_ipcc_connection *c,
return -errno;
}
- c->request.u.shm.rb = qb_rb_open(response->request, c->request.max_msg_size,
- QB_RB_FLAG_SHARED_PROCESS,
- sizeof(int32_t));
+ c->request.u.shm.rb =
+ qb_rb_open(response->request, c->request.max_msg_size,
+ QB_RB_FLAG_SHARED_PROCESS, sizeof(int32_t));
if (c->request.u.shm.rb == NULL) {
res = -errno;
goto return_error;
@@ -186,13 +189,13 @@ int32_t qb_ipcc_shm_connect(struct qb_ipcc_connection *c,
}
return 0;
- cleanup_request_response:
+cleanup_request_response:
qb_rb_close(c->response.u.shm.rb);
- cleanup_request:
+cleanup_request:
qb_rb_close(c->request.u.shm.rb);
- return_error:
+return_error:
errno = -res;
qb_util_perror(LOG_ERR, "connection failed");
@@ -204,7 +207,8 @@ int32_t qb_ipcc_shm_connect(struct qb_ipcc_connection *c,
* --------------------------------------------------------
*/
-static void qb_ipcs_shm_disconnect(struct qb_ipcs_connection *c)
+static void
+qb_ipcs_shm_disconnect(struct qb_ipcs_connection *c)
{
struct qb_ipc_response_header msg;
@@ -226,17 +230,21 @@ static void qb_ipcs_shm_disconnect(struct qb_ipcs_connection *c)
}
}
-static int32_t qb_ipcs_shm_connect(struct qb_ipcs_service *s,
- struct qb_ipcs_connection *c,
- struct qb_ipc_connection_response *r)
+static int32_t
+qb_ipcs_shm_connect(struct qb_ipcs_service *s,
+ struct qb_ipcs_connection *c,
+ struct qb_ipc_connection_response *r)
{
int32_t res;
qb_util_log(LOG_DEBUG, "connecting to client [%d]", c->pid);
- snprintf(r->request, NAME_MAX, "%s-request-%d-%d", s->name, c->pid, c->setup.u.us.sock);
- snprintf(r->response, NAME_MAX, "%s-response-%d-%d", s->name, c->pid, c->setup.u.us.sock);
- snprintf(r->event, NAME_MAX, "%s-event-%d-%d", s->name, c->pid, c->setup.u.us.sock);
+ snprintf(r->request, NAME_MAX, "%s-request-%d-%d", s->name, c->pid,
+ c->setup.u.us.sock);
+ snprintf(r->response, NAME_MAX, "%s-response-%d-%d", s->name, c->pid,
+ c->setup.u.us.sock);
+ snprintf(r->event, NAME_MAX, "%s-event-%d-%d", s->name, c->pid,
+ c->setup.u.us.sock);
c->request.u.shm.rb = qb_rb_open(r->request,
c->request.max_msg_size,
@@ -290,7 +298,8 @@ cleanup:
return res;
}
-void qb_ipcs_shm_init(struct qb_ipcs_service *s)
+void
+qb_ipcs_shm_init(struct qb_ipcs_service *s)
{
s->funcs.connect = qb_ipcs_shm_connect;
s->funcs.disconnect = qb_ipcs_shm_disconnect;
diff --git a/lib/ipc_sysv_mq.c b/lib/ipc_sysv_mq.c
index f2f4d16..503f649 100644
--- a/lib/ipc_sysv_mq.c
+++ b/lib/ipc_sysv_mq.c
@@ -42,8 +42,9 @@ struct my_msgbuf {
* utility functions
* --------------------------------------------------------
*/
-static int32_t sysv_mq_unnamed_create(struct qb_ipcs_connection *c,
- struct qb_ipc_one_way *queue)
+static int32_t
+sysv_mq_unnamed_create(struct qb_ipcs_connection *c,
+ struct qb_ipc_one_way *queue)
{
struct msqid_ds info;
int32_t res = 0;
@@ -51,8 +52,8 @@ static int32_t sysv_mq_unnamed_create(struct qb_ipcs_connection *c,
retry_creating_the_q:
queue->u.smq.key = random();
queue->u.smq.q =
- msgget(queue->u.smq.key,
- IPC_CREAT | IPC_EXCL | IPC_NOWAIT | S_IWUSR | S_IRUSR);
+ msgget(queue->u.smq.key,
+ IPC_CREAT | IPC_EXCL | IPC_NOWAIT | S_IWUSR | S_IRUSR);
if (queue->u.smq.q == -1 && errno == EEXIST) {
goto retry_creating_the_q;
} else if (queue->u.smq.q == -1) {
@@ -90,9 +91,9 @@ retry_creating_the_q:
return 0;
}
-
-static int32_t sysv_split_and_send(int32_t q, const void *msg_ptr,
- size_t msg_len, int32_t last_chunk)
+static int32_t
+sysv_split_and_send(int32_t q, const void *msg_ptr,
+ size_t msg_len, int32_t last_chunk)
{
int32_t res;
int32_t sent = 0;
@@ -139,14 +140,16 @@ return_status:
* client functions
* --------------------------------------------------------
*/
-static ssize_t qb_ipc_smq_send(struct qb_ipc_one_way *one_way,
- const void *msg_ptr, size_t msg_len)
+static ssize_t
+qb_ipc_smq_send(struct qb_ipc_one_way *one_way,
+ const void *msg_ptr, size_t msg_len)
{
return sysv_split_and_send(one_way->u.smq.q, msg_ptr, msg_len, QB_TRUE);
}
-static ssize_t qb_ipc_smq_sendv(struct qb_ipc_one_way *one_way,
- const struct iovec *iov, size_t iov_len)
+static ssize_t
+qb_ipc_smq_sendv(struct qb_ipc_one_way *one_way,
+ const struct iovec *iov, size_t iov_len)
{
int32_t res;
int32_t sent = 0;
@@ -155,21 +158,25 @@ static ssize_t qb_ipc_smq_sendv(struct qb_ipc_one_way *one_way,
for (i = 0; i < iov_len; i++) {
if (iov[i].iov_len <= MY_DATA_SIZE) {
- if (i == iov_len-1) {
+ if (i == iov_len - 1) {
buf.id = 1;
} else {
buf.id = i + iov[i].iov_len;
}
memcpy(buf.data, iov[i].iov_base, iov[i].iov_len);
- res = msgsnd(one_way->u.smq.q, &buf, iov[i].iov_len, IPC_NOWAIT);
+ res = msgsnd(one_way->u.smq.q,
+ &buf, iov[i].iov_len,
+ IPC_NOWAIT);
if (res == 0) {
res = iov[i].iov_len;
} else {
res = -errno;
}
} else {
- res = sysv_split_and_send(one_way->u.smq.q, iov[i].iov_base,
- iov[i].iov_len, (i == iov_len-1));
+ res = sysv_split_and_send(one_way->u.smq.q,
+ iov[i].iov_base,
+ iov[i].iov_len,
+ (i == iov_len - 1));
}
if (res > 0) {
sent += res;
@@ -180,10 +187,9 @@ static ssize_t qb_ipc_smq_sendv(struct qb_ipc_one_way *one_way,
return sent;
}
-static ssize_t qb_ipc_smq_recv(struct qb_ipc_one_way *one_way,
- void *msg_ptr,
- size_t msg_len,
- int32_t ms_timeout)
+static ssize_t
+qb_ipc_smq_recv(struct qb_ipc_one_way *one_way,
+ void *msg_ptr, size_t msg_len, int32_t ms_timeout)
{
ssize_t res;
ssize_t received = 0;
@@ -193,7 +199,8 @@ static ssize_t qb_ipc_smq_recv(struct qb_ipc_one_way *one_way,
do {
try_again:
- res = msgrcv(one_way->u.smq.q, &buf, MY_DATA_SIZE, 0, IPC_NOWAIT);
+ res = msgrcv(one_way->u.smq.q, &buf,
+ MY_DATA_SIZE, 0, IPC_NOWAIT);
if (res == -1 && errno == ENOMSG) {
goto try_again;
@@ -213,7 +220,7 @@ return_status:
#endif
if (res == -1 && errno == ENOMSG) {
/* just to be consistent with other IPC types.
- */
+ */
return -EAGAIN;
}
if (res == -1) {
@@ -223,7 +230,8 @@ return_status:
return received;
}
-static void qb_ipcc_smq_disconnect(struct qb_ipcc_connection *c)
+static void
+qb_ipcc_smq_disconnect(struct qb_ipcc_connection *c)
{
struct qb_ipc_request_header hdr;
@@ -232,16 +240,16 @@ static void qb_ipcc_smq_disconnect(struct qb_ipcc_connection *c)
hdr.id = QB_IPC_MSG_DISCONNECT;
hdr.size = sizeof(hdr);
(void)sysv_split_and_send(c->request.u.smq.q,
- (const char *)&hdr, hdr.size,
- QB_TRUE);
+ (const char *)&hdr, hdr.size, QB_TRUE);
msgctl(c->event.u.smq.q, IPC_RMID, NULL);
msgctl(c->response.u.smq.q, IPC_RMID, NULL);
msgctl(c->request.u.smq.q, IPC_RMID, NULL);
}
-int32_t qb_ipcc_smq_connect(struct qb_ipcc_connection *c,
- struct qb_ipc_connection_response *response)
+int32_t
+qb_ipcc_smq_connect(struct qb_ipcc_connection *c,
+ struct qb_ipc_connection_response *response)
{
int32_t res = 0;
@@ -289,7 +297,8 @@ cleanup:
* service functions
* --------------------------------------------------------
*/
-static void qb_ipcs_smq_disconnect(struct qb_ipcs_connection *c)
+static void
+qb_ipcs_smq_disconnect(struct qb_ipcs_connection *c)
{
struct qb_ipc_response_header msg;
@@ -306,9 +315,10 @@ static void qb_ipcs_smq_disconnect(struct qb_ipcs_connection *c)
}
}
-static int32_t qb_ipcs_smq_connect(struct qb_ipcs_service *s,
- struct qb_ipcs_connection *c,
- struct qb_ipc_connection_response *r)
+static int32_t
+qb_ipcs_smq_connect(struct qb_ipcs_service *s,
+ struct qb_ipcs_connection *c,
+ struct qb_ipc_connection_response *r)
{
int32_t res = 0;
@@ -346,7 +356,8 @@ cleanup:
return res;
}
-static ssize_t qb_ipc_smq_q_len_get(struct qb_ipc_one_way *one_way)
+static ssize_t
+qb_ipc_smq_q_len_get(struct qb_ipc_one_way *one_way)
{
struct msqid_ds info;
int32_t res = msgctl(one_way->u.smq.q, IPC_STAT, &info);
@@ -356,7 +367,8 @@ static ssize_t qb_ipc_smq_q_len_get(struct qb_ipc_one_way *one_way)
return -errno;
}
-void qb_ipcs_smq_init(struct qb_ipcs_service *s)
+void
+qb_ipcs_smq_init(struct qb_ipcs_service *s)
{
s->funcs.connect = qb_ipcs_smq_connect;
s->funcs.disconnect = qb_ipcs_smq_disconnect;
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index e21f25d..846db52 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -66,7 +66,8 @@ static int32_t qb_ipcs_us_connection_acceptor(int fd, int revent, void *data);
static int32_t qb_ipc_us_fc_get(struct qb_ipc_one_way *one_way);
#ifdef SO_NOSIGPIPE
-static void socket_nosigpipe(int32_t s)
+static void
+socket_nosigpipe(int32_t s)
{
int32_t on = 1;
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on));
@@ -77,14 +78,16 @@ static void socket_nosigpipe(int32_t s)
#define MSG_NOSIGNAL 0
#endif
-ssize_t qb_ipc_us_send(struct qb_ipc_one_way *one_way, const void *msg, size_t len)
+ssize_t
+qb_ipc_us_send(struct qb_ipc_one_way *one_way, const void *msg, size_t len)
{
int32_t result;
struct msghdr msg_send;
struct iovec iov_send;
char *rbuf = (char *)msg;
int32_t processed = 0;
- struct ipc_us_control *ctl = (struct ipc_us_control *)one_way->u.us.shared_data;
+ struct ipc_us_control *ctl =
+ (struct ipc_us_control *)one_way->u.us.shared_data;
msg_send.msg_iov = &iov_send;
msg_send.msg_iovlen = 1;
@@ -119,19 +122,22 @@ retry_send:
return processed;
}
-static ssize_t qb_ipc_us_sendv(struct qb_ipc_one_way *one_way, const struct iovec *iov, size_t iov_len)
+static ssize_t
+qb_ipc_us_sendv(struct qb_ipc_one_way *one_way, const struct iovec *iov,
+ size_t iov_len)
{
int32_t result;
struct msghdr msg_send;
int32_t processed = 0;
size_t len = 0;
int32_t i;
- struct ipc_us_control *ctl = (struct ipc_us_control *)one_way->u.us.shared_data;
+ struct ipc_us_control *ctl =
+ (struct ipc_us_control *)one_way->u.us.shared_data;
for (i = 0; i < iov_len; i++) {
len += iov[i].iov_len;
}
- msg_send.msg_iov = (struct iovec*)iov;
+ msg_send.msg_iov = (struct iovec *)iov;
msg_send.msg_iovlen = iov_len;
msg_send.msg_name = 0;
msg_send.msg_namelen = 0;
@@ -161,9 +167,8 @@ retry_send:
return processed;
}
-static ssize_t qb_ipc_us_recv_msghdr(int32_t s,
- struct msghdr *hdr,
- char *msg, size_t len)
+static ssize_t
+qb_ipc_us_recv_msghdr(int32_t s, struct msghdr *hdr, char *msg, size_t len)
{
int32_t result;
int32_t processed = 0;
@@ -197,8 +202,8 @@ retry_recv:
return processed;
}
-
-int32_t qb_ipc_us_recv_ready(struct qb_ipc_one_way *one_way, int32_t ms_timeout)
+int32_t
+qb_ipc_us_recv_ready(struct qb_ipc_one_way * one_way, int32_t ms_timeout)
{
struct pollfd ufds;
int32_t poll_events;
@@ -207,25 +212,26 @@ int32_t qb_ipc_us_recv_ready(struct qb_ipc_one_way *one_way, int32_t ms_timeout)
ufds.events = POLLIN;
ufds.revents = 0;
- poll_events = poll (&ufds, 1, ms_timeout);
- if ((poll_events == -1 && errno == EINTR) ||
- poll_events == 0) {
+ poll_events = poll(&ufds, 1, ms_timeout);
+ if ((poll_events == -1 && errno == EINTR) || poll_events == 0) {
return -EAGAIN;
} else if (poll_events == -1) {
return -errno;
- } else if (poll_events == 1 && (ufds.revents & (POLLERR|POLLHUP))) {
+ } else if (poll_events == 1 && (ufds.revents & (POLLERR | POLLHUP))) {
return -ENOTCONN;
}
return 0;
}
-ssize_t qb_ipc_us_recv(struct qb_ipc_one_way *one_way,
- void *msg, size_t len, int32_t timeout)
+ssize_t
+qb_ipc_us_recv(struct qb_ipc_one_way * one_way,
+ void *msg, size_t len, int32_t timeout)
{
int32_t result;
- struct ipc_us_control *ctl = (struct ipc_us_control *)one_way->u.us.shared_data;
+ struct ipc_us_control *ctl =
+ (struct ipc_us_control *)one_way->u.us.shared_data;
- retry_recv:
+retry_recv:
result = recv(one_way->u.us.sock, msg, len, MSG_NOSIGNAL | MSG_WAITALL);
if (timeout == -1 && result == -1 && errno == EAGAIN) {
goto retry_recv;
@@ -243,7 +249,8 @@ ssize_t qb_ipc_us_recv(struct qb_ipc_one_way *one_way,
}
-static int32_t qb_ipcc_us_sock_connect(const char *socket_name, int32_t * sock_pt)
+static int32_t
+qb_ipcc_us_sock_connect(const char *socket_name, int32_t * sock_pt)
{
int32_t request_fd;
struct sockaddr_un address;
@@ -272,9 +279,10 @@ static int32_t qb_ipcc_us_sock_connect(const char *socket_name, int32_t * sock_p
#endif
#if defined(QB_LINUX)
- snprintf(address.sun_path + 1, UNIX_PATH_MAX-1, "%s", socket_name);
+ snprintf(address.sun_path + 1, UNIX_PATH_MAX - 1, "%s", socket_name);
#else
- snprintf(address.sun_path, UNIX_PATH_MAX, "%s/%s", SOCKETDIR, socket_name);
+ snprintf(address.sun_path, UNIX_PATH_MAX, "%s/%s", SOCKETDIR,
+ socket_name);
#endif
if (connect(request_fd, (struct sockaddr *)&address,
QB_SUN_LEN(&address)) == -1) {
@@ -292,14 +300,16 @@ error_connect:
return res;
}
-void qb_ipcc_us_sock_close(int32_t sock)
+void
+qb_ipcc_us_sock_close(int32_t sock)
{
shutdown(sock, SHUT_RDWR);
close(sock);
}
-int32_t qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
- struct qb_ipc_connection_response *r)
+int32_t
+qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
+ struct qb_ipc_connection_response *r)
{
int32_t res;
struct qb_ipc_connection_request request;
@@ -318,7 +328,9 @@ int32_t qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
return res;
}
- res = qb_ipc_us_recv(&c->setup, r, sizeof(struct qb_ipc_connection_response), -1);
+ res =
+ qb_ipc_us_recv(&c->setup, r,
+ sizeof(struct qb_ipc_connection_response), -1);
if (res < 0) {
return res;
}
@@ -329,7 +341,8 @@ int32_t qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
return 0;
}
-static void qb_ipcc_us_disconnect(struct qb_ipcc_connection* c)
+static void
+qb_ipcc_us_disconnect(struct qb_ipcc_connection *c)
{
munmap(c->request.u.us.shared_data, sizeof(struct ipc_us_control));
unlink(c->request.u.us.shared_file_name);
@@ -337,14 +350,15 @@ static void qb_ipcc_us_disconnect(struct qb_ipcc_connection* c)
close(c->event.u.us.sock);
}
-int32_t qb_ipcc_us_connect(struct qb_ipcc_connection *c,
- struct qb_ipc_connection_response *r)
+int32_t
+qb_ipcc_us_connect(struct qb_ipcc_connection *c,
+ struct qb_ipc_connection_response *r)
{
int32_t res;
struct qb_ipc_event_connection_request request;
char path[PATH_MAX];
int32_t fd_hdr;
- struct ipc_us_control * ctl;
+ struct ipc_us_control *ctl;
c->needs_sock_for_poll = QB_FALSE;
c->funcs.send = qb_ipc_us_send;
@@ -358,8 +372,7 @@ int32_t qb_ipcc_us_connect(struct qb_ipcc_connection *c,
c->setup.u.us.sock = -1;
fd_hdr = qb_util_mmap_file_open(path, r->request,
- sizeof(struct ipc_us_control),
- O_RDWR);
+ sizeof(struct ipc_us_control), O_RDWR);
if (fd_hdr < 0) {
res = -errno;
qb_util_perror(LOG_ERR, "couldn't open file for mmap");
@@ -406,13 +419,13 @@ cleanup_hdr:
return res;
}
-
/*
**************************************************************************
* SERVER
*/
-int32_t qb_ipcs_us_publish(struct qb_ipcs_service * s)
+int32_t
+qb_ipcs_us_publish(struct qb_ipcs_service * s)
{
struct sockaddr_un un_addr;
int32_t res;
@@ -444,7 +457,7 @@ int32_t qb_ipcs_us_publish(struct qb_ipcs_service * s)
qb_util_log(LOG_INFO, "server name: %s", s->name);
#if defined(QB_LINUX)
- snprintf(un_addr.sun_path + 1, UNIX_PATH_MAX-1, "%s", s->name);
+ snprintf(un_addr.sun_path + 1, UNIX_PATH_MAX - 1, "%s", s->name);
#else
{
struct stat stat_out;
@@ -456,17 +469,18 @@ int32_t qb_ipcs_us_publish(struct qb_ipcs_service * s)
SOCKETDIR);
goto error_close;
}
- snprintf(un_addr.sun_path, UNIX_PATH_MAX, "%s/%s", SOCKETDIR, s->name);
+ snprintf(un_addr.sun_path, UNIX_PATH_MAX, "%s/%s", SOCKETDIR,
+ s->name);
unlink(un_addr.sun_path);
}
#endif
res = bind(s->server_sock, (struct sockaddr *)&un_addr,
- QB_SUN_LEN(&un_addr));
+ QB_SUN_LEN(&un_addr));
if (res) {
res = -errno;
qb_util_perror(LOG_ERR, "Could not bind AF_UNIX (%s)",
- un_addr.sun_path);
+ un_addr.sun_path);
goto error_close;
}
@@ -482,8 +496,8 @@ int32_t qb_ipcs_us_publish(struct qb_ipcs_service * s)
}
res = s->poll_fns.dispatch_add(s->poll_priority, s->server_sock,
- POLLIN | POLLPRI | POLLNVAL,
- s, qb_ipcs_us_connection_acceptor);
+ POLLIN | POLLPRI | POLLNVAL,
+ s, qb_ipcs_us_connection_acceptor);
return res;
error_close:
@@ -491,7 +505,8 @@ error_close:
return res;
}
-int32_t qb_ipcs_us_withdraw(struct qb_ipcs_service * s)
+int32_t
+qb_ipcs_us_withdraw(struct qb_ipcs_service * s)
{
qb_util_log(LOG_INFO, "withdrawing server sockets");
shutdown(s->server_sock, SHUT_RDWR);
@@ -499,11 +514,11 @@ int32_t qb_ipcs_us_withdraw(struct qb_ipcs_service * s)
return 0;
}
-static int32_t handle_new_connection(struct qb_ipcs_service *s,
- int32_t auth_result,
- int32_t sock,
- void *msg, size_t len,
- struct ipc_auth_ugp *ugp)
+static int32_t
+handle_new_connection(struct qb_ipcs_service *s,
+ int32_t auth_result,
+ int32_t sock,
+ void *msg, size_t len, struct ipc_auth_ugp *ugp)
{
struct qb_ipcs_connection *c = NULL;
struct qb_ipc_connection_request *req = msg;
@@ -533,8 +548,7 @@ static int32_t handle_new_connection(struct qb_ipcs_service *s,
if (auth_result == 0 && c->service->serv_fns.connection_accept) {
res = c->service->serv_fns.connection_accept(c,
- c->euid,
- c->egid);
+ c->euid, c->egid);
}
if (res != 0) {
goto send_response;
@@ -572,7 +586,8 @@ static int32_t handle_new_connection(struct qb_ipcs_service *s,
c,
qb_ipcs_dispatch_connection_request);
if (res < 0) {
- qb_util_log(LOG_ERR, "Error adding socket to mainloop.");
+ qb_util_log(LOG_ERR,
+ "Error adding socket to mainloop.");
}
}
@@ -581,7 +596,7 @@ send_response:
response.hdr.size = sizeof(response);
response.hdr.error = res;
if (res == 0) {
- response.connection = (intptr_t)c;
+ response.connection = (intptr_t) c;
response.connection_type = s->type;
response.max_msg_size = c->request.max_msg_size;
s->stats.active_connections++;
@@ -607,8 +622,8 @@ send_response:
return res;
}
-static void handle_connection_new_sock(struct qb_ipcs_service *s,
- int32_t sock, void *msg)
+static void
+handle_connection_new_sock(struct qb_ipcs_service *s, int32_t sock, void *msg)
{
struct qb_ipcs_connection *c = NULL;
struct qb_ipc_event_connection_request *req = msg;
@@ -617,8 +632,9 @@ static void handle_connection_new_sock(struct qb_ipcs_service *s,
c->event.u.us.sock = sock;
}
-static int32_t qb_ipcs_uc_recv_and_auth(int32_t sock, void *msg, size_t len,
- struct ipc_auth_ugp *ugp)
+static int32_t
+qb_ipcs_uc_recv_and_auth(int32_t sock, void *msg, size_t len,
+ struct ipc_auth_ugp *ugp)
{
int32_t res = 0;
struct msghdr msg_recv;
@@ -729,7 +745,8 @@ cleanup_and_return:
return res;
}
-static int32_t qb_ipcs_us_connection_acceptor(int fd, int revent, void *data)
+static int32_t
+qb_ipcs_us_connection_acceptor(int fd, int revent, void *data)
{
struct sockaddr_un un_addr;
int32_t new_fd;
@@ -748,13 +765,13 @@ retry_accept:
if (new_fd == -1 && errno == EBADF) {
qb_util_perror(LOG_ERR,
- "Could not accept client connection from fd:%d", fd);
+ "Could not accept client connection from fd:%d",
+ fd);
return -1;
}
if (new_fd == -1) {
res = -errno;
- qb_util_perror(LOG_ERR,
- "Could not accept client connection");
+ qb_util_perror(LOG_ERR, "Could not accept client connection");
/* This is an error, but -1 would indicate disconnect
* from the poll loop
*/
@@ -789,14 +806,15 @@ retry_accept:
return 0;
}
-static int32_t qb_ipcs_us_connect(struct qb_ipcs_service *s,
- struct qb_ipcs_connection *c,
- struct qb_ipc_connection_response *r)
+static int32_t
+qb_ipcs_us_connect(struct qb_ipcs_service *s,
+ struct qb_ipcs_connection *c,
+ struct qb_ipc_connection_response *r)
{
char path[PATH_MAX];
int32_t fd_hdr;
int32_t res = 0;
- struct ipc_us_control * ctl;
+ struct ipc_us_control *ctl;
qb_util_log(LOG_DEBUG, "connecting to client [%d]", c->pid);
@@ -839,31 +857,35 @@ cleanup_hdr:
return res;
}
-
-static void qb_ipc_us_fc_set(struct qb_ipc_one_way *one_way,
- int32_t fc_enable)
+static void
+qb_ipc_us_fc_set(struct qb_ipc_one_way *one_way, int32_t fc_enable)
{
- struct ipc_us_control *ctl = (struct ipc_us_control *)one_way->u.us.shared_data;
+ struct ipc_us_control *ctl =
+ (struct ipc_us_control *)one_way->u.us.shared_data;
qb_util_log(LOG_TRACE, "setting fc to %d", fc_enable);
qb_atomic_int_set(&ctl->flow_control, fc_enable);
}
-static int32_t qb_ipc_us_fc_get(struct qb_ipc_one_way *one_way)
+static int32_t
+qb_ipc_us_fc_get(struct qb_ipc_one_way *one_way)
{
- struct ipc_us_control *ctl = (struct ipc_us_control *)one_way->u.us.shared_data;
+ struct ipc_us_control *ctl =
+ (struct ipc_us_control *)one_way->u.us.shared_data;
return qb_atomic_int_get(&ctl->flow_control);
}
-
-static ssize_t qb_ipc_us_q_len_get(struct qb_ipc_one_way *one_way)
+static ssize_t
+qb_ipc_us_q_len_get(struct qb_ipc_one_way *one_way)
{
- struct ipc_us_control *ctl = (struct ipc_us_control *)one_way->u.us.shared_data;
+ struct ipc_us_control *ctl =
+ (struct ipc_us_control *)one_way->u.us.shared_data;
return qb_atomic_int_get(&ctl->sent);
}
-static void qb_ipcs_us_disconnect(struct qb_ipcs_connection *c)
+static void
+qb_ipcs_us_disconnect(struct qb_ipcs_connection *c)
{
munmap(c->request.u.us.shared_data, sizeof(struct ipc_us_control));
unlink(c->request.u.us.shared_file_name);
@@ -872,7 +894,8 @@ static void qb_ipcs_us_disconnect(struct qb_ipcs_connection *c)
close(c->event.u.us.sock);
}
-void qb_ipcs_us_init(struct qb_ipcs_service *s)
+void
+qb_ipcs_us_init(struct qb_ipcs_service *s)
{
s->funcs.connect = qb_ipcs_us_connect;
s->funcs.disconnect = qb_ipcs_us_disconnect;
@@ -888,5 +911,3 @@ void qb_ipcs_us_init(struct qb_ipcs_service *s)
s->needs_sock_for_poll = QB_FALSE;
}
-
-
diff --git a/lib/ipcc.c b/lib/ipcc.c
index ec1fdd3..9b51266 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -26,7 +26,8 @@
#include <qb/qbdefs.h>
#include <qb/qbipcc.h>
-qb_ipcc_connection_t *qb_ipcc_connect(const char *name, size_t max_msg_size)
+qb_ipcc_connection_t *
+qb_ipcc_connect(const char *name, size_t max_msg_size)
{
int32_t res;
qb_ipcc_connection_t *c = NULL;
@@ -75,7 +76,7 @@ qb_ipcc_connection_t *qb_ipcc_connect(const char *name, size_t max_msg_size)
}
return c;
- disconnect_and_cleanup:
+disconnect_and_cleanup:
qb_ipcc_us_sock_close(c->setup.u.us.sock);
free(c->receive_buf);
free(c);
@@ -83,8 +84,8 @@ qb_ipcc_connection_t *qb_ipcc_connect(const char *name, size_t max_msg_size)
return NULL;
}
-ssize_t qb_ipcc_send(struct qb_ipcc_connection * c, const void *msg_ptr,
- size_t msg_len)
+ssize_t
+qb_ipcc_send(struct qb_ipcc_connection * c, const void *msg_ptr, size_t msg_len)
{
ssize_t res;
ssize_t res2;
@@ -120,8 +121,9 @@ ssize_t qb_ipcc_send(struct qb_ipcc_connection * c, const void *msg_ptr,
return res;
}
-ssize_t qb_ipcc_sendv(struct qb_ipcc_connection* c, const struct iovec* iov,
- size_t iov_len)
+ssize_t
+qb_ipcc_sendv(struct qb_ipcc_connection * c, const struct iovec * iov,
+ size_t iov_len)
{
int32_t total_size = 0;
int32_t i;
@@ -163,8 +165,9 @@ ssize_t qb_ipcc_sendv(struct qb_ipcc_connection* c, const struct iovec* iov,
return res;
}
-ssize_t qb_ipcc_recv(struct qb_ipcc_connection * c, void *msg_ptr,
- size_t msg_len, int32_t ms_timeout)
+ssize_t
+qb_ipcc_recv(struct qb_ipcc_connection * c, void *msg_ptr,
+ size_t msg_len, int32_t ms_timeout)
{
int32_t res = 0;
int32_t res2 = 0;
@@ -181,10 +184,10 @@ ssize_t qb_ipcc_recv(struct qb_ipcc_connection * c, void *msg_ptr,
return res;
}
-ssize_t qb_ipcc_sendv_recv(qb_ipcc_connection_t *c,
- const struct iovec *iov, uint32_t iov_len,
- void *res_msg, size_t res_len,
- int32_t ms_timeout)
+ssize_t
+qb_ipcc_sendv_recv(qb_ipcc_connection_t * c,
+ const struct iovec * iov, uint32_t iov_len,
+ void *res_msg, size_t res_len, int32_t ms_timeout)
{
ssize_t res = 0;
@@ -209,7 +212,8 @@ ssize_t qb_ipcc_sendv_recv(qb_ipcc_connection_t *c,
return qb_ipcc_recv(c, res_msg, res_len, ms_timeout);
}
-int32_t qb_ipcc_fd_get(struct qb_ipcc_connection * c, int32_t * fd)
+int32_t
+qb_ipcc_fd_get(struct qb_ipcc_connection * c, int32_t * fd)
{
if (c->type == QB_IPC_SOCKET) {
*fd = c->event.u.us.sock;
@@ -219,8 +223,9 @@ int32_t qb_ipcc_fd_get(struct qb_ipcc_connection * c, int32_t * fd)
return 0;
}
-ssize_t qb_ipcc_event_recv(struct qb_ipcc_connection * c, void *msg_pt,
- size_t msg_len, int32_t ms_timeout)
+ssize_t
+qb_ipcc_event_recv(struct qb_ipcc_connection * c, void *msg_pt,
+ size_t msg_len, int32_t ms_timeout)
{
char one_byte = 1;
int32_t res;
@@ -252,7 +257,8 @@ ssize_t qb_ipcc_event_recv(struct qb_ipcc_connection * c, void *msg_pt,
return size;
}
-void qb_ipcc_disconnect(struct qb_ipcc_connection *c)
+void
+qb_ipcc_disconnect(struct qb_ipcc_connection *c)
{
qb_util_log(LOG_DEBUG, "%s()", __func__);
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 454b19f..abffa9c 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -31,10 +31,10 @@ static void qb_ipcs_flowcontrol_set(struct qb_ipcs_connection *c,
static QB_LIST_DECLARE(qb_ipc_services);
-qb_ipcs_service_t* qb_ipcs_create(const char *name,
- int32_t service_id,
- enum qb_ipc_type type,
- struct qb_ipcs_service_handlers *handlers)
+qb_ipcs_service_t *
+qb_ipcs_create(const char *name,
+ int32_t service_id,
+ enum qb_ipc_type type, struct qb_ipcs_service_handlers *handlers)
{
struct qb_ipcs_service *s;
@@ -65,8 +65,9 @@ qb_ipcs_service_t* qb_ipcs_create(const char *name,
return s;
}
-void qb_ipcs_poll_handlers_set(struct qb_ipcs_service* s,
- struct qb_ipcs_poll_handlers *handlers)
+void
+qb_ipcs_poll_handlers_set(struct qb_ipcs_service *s,
+ struct qb_ipcs_poll_handlers *handlers)
{
s->poll_fns.job_add = handlers->job_add;
s->poll_fns.dispatch_add = handlers->dispatch_add;
@@ -74,7 +75,8 @@ void qb_ipcs_poll_handlers_set(struct qb_ipcs_service* s,
s->poll_fns.dispatch_del = handlers->dispatch_del;
}
-int32_t qb_ipcs_run(struct qb_ipcs_service* s)
+int32_t
+qb_ipcs_run(struct qb_ipcs_service *s)
{
int32_t res;
@@ -105,7 +107,8 @@ int32_t qb_ipcs_run(struct qb_ipcs_service* s)
return res;
}
-static int32_t _modify_dispatch_descriptor_(struct qb_ipcs_connection *c)
+static int32_t
+_modify_dispatch_descriptor_(struct qb_ipcs_connection *c)
{
qb_ipcs_dispatch_mod_fn disp_mod = c->service->poll_fns.dispatch_mod;
@@ -113,7 +116,7 @@ static int32_t _modify_dispatch_descriptor_(struct qb_ipcs_connection *c)
&& !c->service->needs_sock_for_poll) {
return disp_mod(c->service->poll_priority,
(int32_t) c->request.u.pmq.q,
- c->poll_events, c,
+ c->poll_events, c,
qb_ipcs_dispatch_service_request);
} else if (c->service->type == QB_IPC_SOCKET) {
return disp_mod(c->service->poll_priority,
@@ -129,8 +132,9 @@ static int32_t _modify_dispatch_descriptor_(struct qb_ipcs_connection *c)
return -EINVAL;
}
-void qb_ipcs_request_rate_limit(struct qb_ipcs_service *s,
- enum qb_ipcs_rate_limit rl)
+void
+qb_ipcs_request_rate_limit(struct qb_ipcs_service *s,
+ enum qb_ipcs_rate_limit rl)
{
struct qb_ipcs_connection *c;
enum qb_loop_priority old_p = s->poll_priority;
@@ -165,12 +169,14 @@ void qb_ipcs_request_rate_limit(struct qb_ipcs_service *s,
}
}
-void qb_ipcs_ref(struct qb_ipcs_service *s)
+void
+qb_ipcs_ref(struct qb_ipcs_service *s)
{
qb_atomic_int_inc(&s->ref_count);
}
-void qb_ipcs_unref(struct qb_ipcs_service *s)
+void
+qb_ipcs_unref(struct qb_ipcs_service *s)
{
int32_t free_it;
struct qb_ipcs_connection *c = NULL;
@@ -194,7 +200,8 @@ void qb_ipcs_unref(struct qb_ipcs_service *s)
}
}
-void qb_ipcs_destroy(struct qb_ipcs_service* s)
+void
+qb_ipcs_destroy(struct qb_ipcs_service *s)
{
qb_ipcs_unref(s);
}
@@ -203,8 +210,9 @@ void qb_ipcs_destroy(struct qb_ipcs_service* s)
* connection API
*/
-ssize_t qb_ipcs_response_send(struct qb_ipcs_connection *c, const void *data,
- size_t size)
+ssize_t
+qb_ipcs_response_send(struct qb_ipcs_connection *c, const void *data,
+ size_t size)
{
ssize_t res;
@@ -220,7 +228,9 @@ ssize_t qb_ipcs_response_send(struct qb_ipcs_connection *c, const void *data,
return res;
}
-ssize_t qb_ipcs_response_sendv(struct qb_ipcs_connection *c, const struct iovec * iov, size_t iov_len)
+ssize_t
+qb_ipcs_response_sendv(struct qb_ipcs_connection * c, const struct iovec * iov,
+ size_t iov_len)
{
ssize_t res;
@@ -236,7 +246,8 @@ ssize_t qb_ipcs_response_sendv(struct qb_ipcs_connection *c, const struct iovec
return res;
}
-static int32_t send_event_notification(int32_t fd, int32_t revents, void *data)
+static int32_t
+send_event_notification(int32_t fd, int32_t revents, void *data)
{
ssize_t res = 0;
struct qb_ipcs_connection *c = data;
@@ -252,13 +263,13 @@ static int32_t send_event_notification(int32_t fd, int32_t revents, void *data)
} else {
c->outstanding_notifiers = 0;
c->poll_events = POLLIN | POLLPRI | POLLNVAL,
- (void)_modify_dispatch_descriptor_(c);
+ (void)_modify_dispatch_descriptor_(c);
}
return 0;
}
-ssize_t qb_ipcs_event_send(struct qb_ipcs_connection * c, const void *data,
- size_t size)
+ssize_t
+qb_ipcs_event_send(struct qb_ipcs_connection * c, const void *data, size_t size)
{
ssize_t res;
ssize_t res2 = 0;
@@ -283,7 +294,7 @@ ssize_t qb_ipcs_event_send(struct qb_ipcs_connection * c, const void *data,
*/
c->outstanding_notifiers++;
c->poll_events = POLLOUT | POLLIN | POLLPRI | POLLNVAL,
- (void)_modify_dispatch_descriptor_(c);
+ (void)_modify_dispatch_descriptor_(c);
}
}
@@ -294,8 +305,9 @@ deref_and_return:
return res;
}
-ssize_t qb_ipcs_event_sendv(struct qb_ipcs_connection * c,
- const struct iovec * iov, size_t iov_len)
+ssize_t
+qb_ipcs_event_sendv(struct qb_ipcs_connection * c,
+ const struct iovec * iov, size_t iov_len)
{
ssize_t res;
ssize_t res2;
@@ -320,7 +332,7 @@ ssize_t qb_ipcs_event_sendv(struct qb_ipcs_connection * c,
*/
c->outstanding_notifiers++;
c->poll_events = POLLOUT | POLLIN | POLLPRI | POLLNVAL,
- (void)_modify_dispatch_descriptor_(c);
+ (void)_modify_dispatch_descriptor_(c);
}
}
@@ -331,7 +343,8 @@ deref_and_return:
return res;
}
-qb_ipcs_connection_t *qb_ipcs_connection_first_get(struct qb_ipcs_service * s)
+qb_ipcs_connection_t *
+qb_ipcs_connection_first_get(struct qb_ipcs_service * s)
{
struct qb_ipcs_connection *c;
struct qb_list_head *iter;
@@ -347,8 +360,9 @@ qb_ipcs_connection_t *qb_ipcs_connection_first_get(struct qb_ipcs_service * s)
return c;
}
-qb_ipcs_connection_t * qb_ipcs_connection_next_get(struct qb_ipcs_service* s,
- struct qb_ipcs_connection *current)
+qb_ipcs_connection_t *
+qb_ipcs_connection_next_get(struct qb_ipcs_service * s,
+ struct qb_ipcs_connection * current)
{
struct qb_ipcs_connection *c;
struct qb_list_head *iter;
@@ -364,14 +378,17 @@ qb_ipcs_connection_t * qb_ipcs_connection_next_get(struct qb_ipcs_service* s,
return c;
}
-int32_t qb_ipcs_service_id_get(struct qb_ipcs_connection *c)
+int32_t
+qb_ipcs_service_id_get(struct qb_ipcs_connection * c)
{
return c->service->service_id;
}
-struct qb_ipcs_connection *qb_ipcs_connection_alloc(struct qb_ipcs_service *s)
+struct qb_ipcs_connection *
+qb_ipcs_connection_alloc(struct qb_ipcs_service *s)
{
- struct qb_ipcs_connection *c = calloc(1, sizeof(struct qb_ipcs_connection));
+ struct qb_ipcs_connection *c =
+ calloc(1, sizeof(struct qb_ipcs_connection));
if (c == NULL) {
return NULL;
@@ -391,18 +408,21 @@ struct qb_ipcs_connection *qb_ipcs_connection_alloc(struct qb_ipcs_service *s)
return c;
}
-void qb_ipcs_connection_ref(struct qb_ipcs_connection *c)
+void
+qb_ipcs_connection_ref(struct qb_ipcs_connection *c)
{
qb_atomic_int_inc(&c->refcount);
}
-void qb_ipcs_connection_unref(struct qb_ipcs_connection *c)
+void
+qb_ipcs_connection_unref(struct qb_ipcs_connection *c)
{
int32_t free_it;
if (c->refcount < 1) {
qb_util_log(LOG_ERR, "%s() ref:%d state:%d fd:%d",
- __func__, c->refcount, c->state, c->setup.u.us.sock);
+ __func__, c->refcount, c->state,
+ c->setup.u.us.sock);
assert(0);
}
free_it = qb_atomic_int_dec_and_test(&c->refcount);
@@ -419,7 +439,8 @@ void qb_ipcs_connection_unref(struct qb_ipcs_connection *c)
}
}
-void qb_ipcs_disconnect(struct qb_ipcs_connection *c)
+void
+qb_ipcs_disconnect(struct qb_ipcs_connection *c)
{
int32_t res = 0;
qb_loop_job_dispatch_fn rerun_job;
@@ -431,8 +452,7 @@ void qb_ipcs_disconnect(struct qb_ipcs_connection *c)
c->service->stats.active_connections--;
c->service->stats.closed_connections++;
- if (c->service->needs_sock_for_poll &&
- c->setup.u.us.sock > 0) {
+ if (c->service->needs_sock_for_poll && c->setup.u.us.sock > 0) {
qb_ipcc_us_sock_close(c->setup.u.us.sock);
c->setup.u.us.sock = -1;
qb_ipcs_connection_unref(c);
@@ -448,8 +468,10 @@ void qb_ipcs_disconnect(struct qb_ipcs_connection *c)
} else {
/* OK, so they want the connection_closed
* function re-run */
- rerun_job = (qb_loop_job_dispatch_fn)qb_ipcs_disconnect;
- res = c->service->poll_fns.job_add(QB_LOOP_LOW, c,
+ rerun_job =
+ (qb_loop_job_dispatch_fn) qb_ipcs_disconnect;
+ res = c->service->poll_fns.job_add(QB_LOOP_LOW,
+ c,
rerun_job);
if (res != 0) {
/* last ditch attempt to cleanup */
@@ -459,7 +481,8 @@ void qb_ipcs_disconnect(struct qb_ipcs_connection *c)
}
}
-static void qb_ipcs_flowcontrol_set(struct qb_ipcs_connection *c, int32_t fc_enable)
+static void
+qb_ipcs_flowcontrol_set(struct qb_ipcs_connection *c, int32_t fc_enable)
{
if (c->fc_enabled != fc_enable) {
c->service->funcs.fc_set(&c->request, fc_enable);
@@ -469,8 +492,8 @@ static void qb_ipcs_flowcontrol_set(struct qb_ipcs_connection *c, int32_t fc_ena
}
}
-static int32_t _process_request_(struct qb_ipcs_connection *c,
- int32_t ms_timeout)
+static int32_t
+_process_request_(struct qb_ipcs_connection *c, int32_t ms_timeout)
{
int32_t res = 0;
ssize_t size;
@@ -479,16 +502,19 @@ static int32_t _process_request_(struct qb_ipcs_connection *c,
qb_ipcs_connection_ref(c);
if (c->service->funcs.peek && c->service->funcs.reclaim) {
- size = c->service->funcs.peek(&c->request, (void**)&hdr,
+ size = c->service->funcs.peek(&c->request, (void **)&hdr,
ms_timeout);
} else {
hdr = c->receive_buf;
- size = c->service->funcs.recv(&c->request, hdr, c->request.max_msg_size,
+ size = c->service->funcs.recv(&c->request,
+ hdr,
+ c->request.max_msg_size,
ms_timeout);
}
if (size < 0) {
if (size != -EAGAIN && size != -ETIMEDOUT) {
- qb_util_perror(LOG_ERR, "recv from client connection failed");
+ qb_util_perror(LOG_ERR,
+ "recv from client connection failed");
} else {
c->stats.recv_retries++;
}
@@ -523,8 +549,8 @@ cleanup:
#define IPC_REQUEST_TIMEOUT 10
#define MAX_RECV_MSGS 50
-int32_t qb_ipcs_dispatch_service_request(int32_t fd, int32_t revents,
- void *data)
+int32_t
+qb_ipcs_dispatch_service_request(int32_t fd, int32_t revents, void *data)
{
int32_t res = _process_request_((struct qb_ipcs_connection *)data,
IPC_REQUEST_TIMEOUT);
@@ -534,7 +560,8 @@ int32_t qb_ipcs_dispatch_service_request(int32_t fd, int32_t revents,
return res;
}
-static ssize_t _request_q_len_get(struct qb_ipcs_connection *c)
+static ssize_t
+_request_q_len_get(struct qb_ipcs_connection *c)
{
ssize_t q_len;
if (c->service->funcs.q_len_get) {
@@ -554,8 +581,8 @@ static ssize_t _request_q_len_get(struct qb_ipcs_connection *c)
return q_len;
}
-int32_t qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents,
- void *data)
+int32_t
+qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents, void *data)
{
struct qb_ipcs_connection *c = (struct qb_ipcs_connection *)data;
char bytes[MAX_RECV_MSGS];
@@ -612,19 +639,22 @@ int32_t qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents,
return res;
}
-void qb_ipcs_context_set(struct qb_ipcs_connection *c, void *context)
+void
+qb_ipcs_context_set(struct qb_ipcs_connection *c, void *context)
{
c->context = context;
}
-void *qb_ipcs_context_get(struct qb_ipcs_connection *c)
+void *
+qb_ipcs_context_get(struct qb_ipcs_connection *c)
{
return c->context;
}
-int32_t qb_ipcs_connection_stats_get(qb_ipcs_connection_t *c,
- struct qb_ipcs_connection_stats* stats,
- int32_t clear_after_read)
+int32_t
+qb_ipcs_connection_stats_get(qb_ipcs_connection_t * c,
+ struct qb_ipcs_connection_stats * stats,
+ int32_t clear_after_read)
{
memcpy(stats, &c->stats, sizeof(struct qb_ipcs_connection_stats));
if (clear_after_read) {
@@ -634,9 +664,9 @@ int32_t qb_ipcs_connection_stats_get(qb_ipcs_connection_t *c,
return 0;
}
-int32_t qb_ipcs_stats_get(struct qb_ipcs_service* s,
- struct qb_ipcs_stats* stats,
- int32_t clear_after_read)
+int32_t
+qb_ipcs_stats_get(struct qb_ipcs_service * s,
+ struct qb_ipcs_stats * stats, int32_t clear_after_read)
{
memcpy(stats, &s->stats, sizeof(struct qb_ipcs_stats));
if (clear_after_read) {
@@ -644,4 +674,3 @@ int32_t qb_ipcs_stats_get(struct qb_ipcs_service* s,
}
return 0;
}
-
diff --git a/lib/log.c b/lib/log.c
index 5a3139c..29a0b80 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -42,8 +42,8 @@ static QB_LIST_DECLARE(tags_head);
static QB_LIST_DECLARE(callsite_sections);
struct callsite_section {
- struct qb_log_callsite * start;
- struct qb_log_callsite * stop;
+ struct qb_log_callsite *start;
+ struct qb_log_callsite *stop;
struct qb_list_head list;
};
@@ -60,15 +60,16 @@ static void _log_filter_apply_to_cs(struct qb_log_callsite *cs,
/* deprecated method of getting internal log messages */
static qb_util_log_fn_t old_internal_log_fn = NULL;
-void qb_util_set_log_function(qb_util_log_fn_t fn)
+void
+qb_util_set_log_function(qb_util_log_fn_t fn)
{
old_internal_log_fn = fn;
}
-static int32_t _cs_matches_filter_(struct qb_log_callsite *cs,
- enum qb_log_filter_type type,
- const char * text,
- uint8_t priority)
+static int32_t
+_cs_matches_filter_(struct qb_log_callsite *cs,
+ enum qb_log_filter_type type,
+ const char *text, uint8_t priority)
{
int32_t match = QB_FALSE;
@@ -94,7 +95,8 @@ static int32_t _cs_matches_filter_(struct qb_log_callsite *cs,
return match;
}
-static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
+static void
+_log_real_msg(struct qb_log_callsite *cs, const char *msg)
{
int32_t found_threaded;
struct qb_log_target *t;
@@ -110,7 +112,8 @@ static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
if (old_internal_log_fn) {
if (qb_bit_is_set(cs->tags, QB_LOG_TAG_LIBQB_MSG_BIT)) {
- old_internal_log_fn(cs->filename, cs->lineno, cs->priority, msg);
+ old_internal_log_fn(cs->filename, cs->lineno,
+ cs->priority, msg);
}
}
@@ -124,7 +127,8 @@ static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
for (pos = active_targets.next; pos != &active_targets; pos = pos->next) {
t = qb_list_entry(pos, struct qb_log_target, active_list);
if (t->threaded) {
- if (!found_threaded && qb_bit_is_set(cs->targets, t->pos)) {
+ if (!found_threaded
+ && qb_bit_is_set(cs->targets, t->pos)) {
found_threaded = QB_TRUE;
}
} else {
@@ -141,8 +145,9 @@ static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
in_logger = QB_FALSE;
}
-void qb_log_thread_log_write(struct qb_log_callsite *cs,
- time_t timestamp, const char *buffer)
+void
+qb_log_thread_log_write(struct qb_log_callsite *cs,
+ time_t timestamp, const char *buffer)
{
struct qb_log_target *t;
struct qb_list_head *pos;
@@ -160,13 +165,12 @@ void qb_log_thread_log_write(struct qb_log_callsite *cs,
pthread_rwlock_unlock(&_listlock);
}
-void qb_log_from_external_source(const char *function,
- const char *filename,
- const char *format,
- uint8_t priority,
- uint32_t lineno,
- uint32_t tags,
- const char *msg)
+void
+qb_log_from_external_source(const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno, uint32_t tags, const char *msg)
{
struct qb_log_target *t;
struct qb_log_filter *flt;
@@ -203,7 +207,8 @@ void qb_log_from_external_source(const char *function,
_log_real_msg(cs, msg);
}
-void qb_log_real_(struct qb_log_callsite *cs, ...)
+void
+qb_log_real_(struct qb_log_callsite *cs, ...)
{
va_list ap;
char buf[QB_LOG_MAX_LEN];
@@ -220,7 +225,9 @@ void qb_log_real_(struct qb_log_callsite *cs, ...)
_log_real_msg(cs, buf);
}
-int32_t qb_log_callsites_register(struct qb_log_callsite *_start, struct qb_log_callsite *_stop)
+int32_t
+qb_log_callsites_register(struct qb_log_callsite *_start,
+ struct qb_log_callsite *_stop)
{
struct callsite_section *sect;
struct qb_log_target *t;
@@ -268,7 +275,8 @@ int32_t qb_log_callsites_register(struct qb_log_callsite *_start, struct qb_log_
return 0;
}
-void qb_log_callsites_dump(void)
+void
+qb_log_callsites_dump(void)
{
struct callsite_section *sect;
struct qb_log_callsite *cs;
@@ -292,10 +300,10 @@ void qb_log_callsites_dump(void)
pthread_rwlock_unlock(&_listlock);
}
-static int32_t _log_filter_exists(struct qb_list_head *list_head,
- enum qb_log_filter_type type,
- const char *text, uint8_t priority,
- uint32_t new_value)
+static int32_t
+_log_filter_exists(struct qb_list_head *list_head,
+ enum qb_log_filter_type type,
+ const char *text, uint8_t priority, uint32_t new_value)
{
struct qb_log_filter *flt;
@@ -310,9 +318,10 @@ static int32_t _log_filter_exists(struct qb_list_head *list_head,
return QB_FALSE;
}
-static int32_t _log_filter_store(uint32_t t, enum qb_log_filter_conf c,
- enum qb_log_filter_type type,
- const char *text, uint8_t priority)
+static int32_t
+_log_filter_store(uint32_t t, enum qb_log_filter_conf c,
+ enum qb_log_filter_type type,
+ const char *text, uint8_t priority)
{
struct qb_log_filter *flt;
struct qb_list_head *iter;
@@ -357,8 +366,7 @@ static int32_t _log_filter_store(uint32_t t, enum qb_log_filter_conf c,
flt->priority = priority;
flt->new_value = t;
qb_list_add_tail(&flt->list, list_head);
- } else if (c == QB_LOG_FILTER_REMOVE ||
- c == QB_LOG_TAG_CLEAR) {
+ } else if (c == QB_LOG_FILTER_REMOVE || c == QB_LOG_TAG_CLEAR) {
qb_list_for_each_safe(iter, next, list_head) {
flt = qb_list_entry(iter, struct qb_log_filter, list);
if (flt->type == type &&
@@ -371,8 +379,7 @@ static int32_t _log_filter_store(uint32_t t, enum qb_log_filter_conf c,
}
}
- } else if (c == QB_LOG_FILTER_CLEAR_ALL ||
- c == QB_LOG_TAG_CLEAR_ALL) {
+ } else if (c == QB_LOG_FILTER_CLEAR_ALL || c == QB_LOG_TAG_CLEAR_ALL) {
qb_list_for_each_safe(iter, next, list_head) {
flt = qb_list_entry(iter, struct qb_log_filter, list);
qb_list_del(iter);
@@ -383,10 +390,11 @@ static int32_t _log_filter_store(uint32_t t, enum qb_log_filter_conf c,
return 0;
}
-static void _log_filter_apply(struct callsite_section *sect,
- uint32_t t, enum qb_log_filter_conf c,
- enum qb_log_filter_type type,
- const char *text, uint8_t priority)
+static void
+_log_filter_apply(struct callsite_section *sect,
+ uint32_t t, enum qb_log_filter_conf c,
+ enum qb_log_filter_type type,
+ const char *text, uint8_t priority)
{
struct qb_log_callsite *cs;
@@ -399,10 +407,11 @@ static void _log_filter_apply(struct callsite_section *sect,
}
/* #define _QB_FILTER_DEBUGGING_ 1 */
-static void _log_filter_apply_to_cs(struct qb_log_callsite *cs,
- uint32_t t, enum qb_log_filter_conf c,
- enum qb_log_filter_type type,
- const char *text, uint8_t priority)
+static void
+_log_filter_apply_to_cs(struct qb_log_callsite *cs,
+ uint32_t t, enum qb_log_filter_conf c,
+ enum qb_log_filter_type type,
+ const char *text, uint8_t priority)
{
if (c == QB_LOG_FILTER_CLEAR_ALL) {
@@ -435,16 +444,16 @@ static void _log_filter_apply_to_cs(struct qb_log_callsite *cs,
}
if (old_tags != cs->tags) {
printf("tags: %s:%u value(%d) %d -> %d\n",
- cs->filename, cs->lineno, t,
- old_tags, cs->tags);
+ cs->filename, cs->lineno, t, old_tags, cs->tags);
}
#endif /* _QB_FILTER_DEBUGGING_ */
}
}
-int32_t qb_log_filter_ctl(int32_t t, enum qb_log_filter_conf c,
- enum qb_log_filter_type type,
- const char *text, uint8_t priority)
+int32_t
+qb_log_filter_ctl(int32_t t, enum qb_log_filter_conf c,
+ enum qb_log_filter_type type,
+ const char *text, uint8_t priority)
{
struct callsite_section *sect;
int32_t rc;
@@ -457,8 +466,7 @@ int32_t qb_log_filter_ctl(int32_t t, enum qb_log_filter_conf c,
}
if (text == NULL ||
priority > LOG_TRACE ||
- type > QB_LOG_FILTER_FORMAT ||
- c > QB_LOG_TAG_CLEAR_ALL) {
+ type > QB_LOG_FILTER_FORMAT || c > QB_LOG_TAG_CLEAR_ALL) {
return -EINVAL;
}
pthread_rwlock_wrlock(&_listlock);
@@ -489,7 +497,7 @@ _log_so_walk_callback(struct dl_phdr_info *info, size_t size, void *data)
error = dlerror();
if (!handle || error) {
qb_log(LOG_ERR, "%s", error);
- if(handle) {
+ if (handle) {
dlclose(handle);
}
return 0;
@@ -516,7 +524,8 @@ done:
}
#endif /* QB_HAVE_ATTRIBUTE_SECTION */
-void qb_log_init(const char *name, int32_t facility, uint8_t priority)
+void
+qb_log_init(const char *name, int32_t facility, uint8_t priority)
{
int32_t i;
@@ -554,7 +563,8 @@ void qb_log_init(const char *name, int32_t facility, uint8_t priority)
(void)qb_log_syslog_open(&conf[QB_LOG_SYSLOG]);
}
-void qb_log_fini(void)
+void
+qb_log_fini(void)
{
struct qb_log_target *t;
struct qb_log_filter *flt;
@@ -595,7 +605,8 @@ void qb_log_fini(void)
}
}
-struct qb_log_target *qb_log_target_alloc(void)
+struct qb_log_target *
+qb_log_target_alloc(void)
{
int32_t i;
for (i = 0; i < 32; i++) {
@@ -607,7 +618,8 @@ struct qb_log_target *qb_log_target_alloc(void)
return NULL;
}
-void qb_log_target_free(struct qb_log_target *t)
+void
+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);
@@ -617,12 +629,14 @@ void qb_log_target_free(struct qb_log_target *t)
qb_log_format_set(t->pos, NULL);
}
-struct qb_log_target *qb_log_target_get(int32_t pos)
+struct qb_log_target *
+qb_log_target_get(int32_t pos)
{
return &conf[pos];
}
-void *qb_log_target_user_data_get(int32_t t)
+void *
+qb_log_target_user_data_get(int32_t t)
{
if (!logger_inited) {
errno = -EINVAL;
@@ -636,7 +650,8 @@ void *qb_log_target_user_data_get(int32_t t)
return conf[t].instance;
}
-int32_t qb_log_target_user_data_set(int32_t t, void *user_data)
+int32_t
+qb_log_target_user_data_set(int32_t t, void *user_data)
{
if (!logger_inited) {
return -EINVAL;
@@ -649,10 +664,10 @@ int32_t qb_log_target_user_data_set(int32_t t, void *user_data)
return 0;
}
-int32_t qb_log_custom_open(qb_log_logger_fn log_fn,
- qb_log_close_fn close_fn,
- qb_log_reload_fn reload_fn,
- void *user_data)
+int32_t
+qb_log_custom_open(qb_log_logger_fn log_fn,
+ qb_log_close_fn close_fn,
+ qb_log_reload_fn reload_fn, void *user_data)
{
struct qb_log_target *t;
@@ -671,7 +686,8 @@ int32_t qb_log_custom_open(qb_log_logger_fn log_fn,
return t->pos;
}
-void qb_log_custom_close(int32_t t)
+void
+qb_log_custom_close(int32_t t)
{
struct qb_log_target *target;
@@ -690,7 +706,8 @@ void qb_log_custom_close(int32_t t)
qb_log_target_free(target);
}
-static int32_t _log_target_enable(struct qb_log_target *t)
+static int32_t
+_log_target_enable(struct qb_log_target *t)
{
int32_t rc = 0;
@@ -714,7 +731,8 @@ static int32_t _log_target_enable(struct qb_log_target *t)
return rc;
}
-static void _log_target_disable(struct qb_log_target *t)
+static void
+_log_target_disable(struct qb_log_target *t)
{
if (t->state != QB_LOG_STATE_ENABLED) {
return;
@@ -730,7 +748,8 @@ static void _log_target_disable(struct qb_log_target *t)
pthread_rwlock_unlock(&_listlock);
}
-int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
+int32_t
+qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
{
int32_t rc = 0;
int32_t need_reload = QB_FALSE;
@@ -782,7 +801,8 @@ int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
return rc;
}
-void qb_log_format_set(int32_t t, const char *format)
+void
+qb_log_format_set(int32_t t, const char *format)
{
if (conf[t].format) {
free(conf[t].format);
@@ -792,4 +812,3 @@ void qb_log_format_set(int32_t t, const char *format)
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 60f9e52..be26b79 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -23,7 +23,8 @@
#include <qb/qbrb.h>
#include "log_int.h"
-static void _blackbox_reload(int32_t target)
+static void
+_blackbox_reload(int32_t target)
{
struct qb_log_target *t = qb_log_target_get(target);
@@ -41,9 +42,10 @@ static void _blackbox_reload(int32_t target)
* <u32> buffer length
* <string> buffer
*/
-static void _blackbox_logger(int32_t target,
- struct qb_log_callsite *cs,
- time_t timestamp, const char *buffer)
+static void
+_blackbox_logger(int32_t target,
+ struct qb_log_callsite *cs,
+ time_t timestamp, const char *buffer)
{
size_t size = sizeof(uint32_t);
size_t fn_size;
@@ -84,7 +86,8 @@ static void _blackbox_logger(int32_t target,
(void)qb_rb_chunk_commit(t->instance, size);
}
-static void _blackbox_close(int32_t target)
+static void
+_blackbox_close(int32_t target)
{
struct qb_log_target *t = qb_log_target_get(target);
@@ -94,7 +97,8 @@ static void _blackbox_close(int32_t target)
}
}
-int32_t qb_log_blackbox_open(struct qb_log_target *t)
+int32_t
+qb_log_blackbox_open(struct qb_log_target *t)
{
if (t->size < 1024) {
return -EINVAL;
@@ -111,7 +115,8 @@ int32_t qb_log_blackbox_open(struct qb_log_target *t)
return 0;
}
-ssize_t qb_log_blackbox_write_to_file(const char *filename)
+ssize_t
+qb_log_blackbox_write_to_file(const char *filename)
{
ssize_t written_size = 0;
struct qb_log_target *t;
@@ -131,7 +136,8 @@ ssize_t qb_log_blackbox_write_to_file(const char *filename)
return written_size;
}
-void qb_log_blackbox_print_from_file(const char *bb_filename)
+void
+qb_log_blackbox_print_from_file(const char *bb_filename)
{
qb_ringbuffer_t *instance;
ssize_t bytes_read;
@@ -156,7 +162,7 @@ void qb_log_blackbox_print_from_file(const char *bb_filename)
uint32_t *fn_size;
uint8_t *function;
time_t *timestamp;
- /*uint32_t *log_size;*/
+ /* uint32_t *log_size; */
bytes_read = qb_rb_chunk_read(instance, chunk, 512, 0);
ptr = chunk;
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
index 29dee61..d9a81b7 100644
--- a/lib/log_dcs.c
+++ b/lib/log_dcs.c
@@ -34,19 +34,18 @@ static qb_array_t *callsite_arr = NULL;
static uint32_t callsite_arr_next = 0;
static uint32_t callsite_num_bins = 0;
static uint32_t callsite_elems_per_bin = 0;
-static qb_thread_lock_t* arr_next_lock = NULL;
-
+static qb_thread_lock_t *arr_next_lock = NULL;
struct callsite_list {
struct qb_log_callsite *cs;
struct callsite_list *next;
};
-
-static void _log_register_callsites(void)
+static void
+_log_register_callsites(void)
{
- struct qb_log_callsite* start;
- struct qb_log_callsite* stop;
+ struct qb_log_callsite *start;
+ struct qb_log_callsite *stop;
int32_t b;
int32_t rc;
uint32_t num_bins = qb_array_num_bins_get(callsite_arr);
@@ -55,7 +54,7 @@ static void _log_register_callsites(void)
/* get the first element in the bin */
rc = qb_array_index(callsite_arr,
b * callsite_elems_per_bin,
- (void**)&start);
+ (void **)&start);
if (rc == 0) {
stop = &start[callsite_elems_per_bin];
if (qb_log_callsites_register(start, stop) != 0) {
@@ -70,18 +69,17 @@ static struct qb_log_callsite *
_log_dcs_new_cs(const char *function,
const char *filename,
const char *format,
- uint8_t priority,
- uint32_t lineno,
- uint32_t tags)
+ uint8_t priority, uint32_t lineno, uint32_t tags)
{
struct qb_log_callsite *cs;
int32_t rc;
int32_t call_register = QB_FALSE;
- if (qb_array_index(callsite_arr, callsite_arr_next, (void**)&cs) < 0) {
+ if (qb_array_index(callsite_arr, callsite_arr_next, (void **)&cs) < 0) {
rc = qb_array_grow(callsite_arr, callsite_arr_next + 255);
assert(rc == 0);
- rc = qb_array_index(callsite_arr, callsite_arr_next, (void**)&cs);
+ rc = qb_array_index(callsite_arr, callsite_arr_next,
+ (void **)&cs);
assert(rc == 0);
assert(cs != NULL);
call_register = QB_TRUE;
@@ -103,13 +101,11 @@ _log_dcs_new_cs(const char *function,
}
struct qb_log_callsite *
-qb_log_dcs_get(int32_t *newly_created,
+qb_log_dcs_get(int32_t * newly_created,
const char *function,
const char *filename,
const char *format,
- uint8_t priority,
- uint32_t lineno,
- uint32_t tags)
+ uint8_t priority, uint32_t lineno, uint32_t tags)
{
int32_t rc;
struct qb_log_callsite *cs = NULL;
@@ -120,8 +116,9 @@ qb_log_dcs_get(int32_t *newly_created,
/*
* 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) {
+ rc = qb_array_index(lookup_arr, lineno, (void **)&csl_head);
+ if (rc == 0 && csl_head->cs
+ && strcmp(filename, csl_head->cs->filename) == 0) {
return csl_head->cs;
}
/*
@@ -131,7 +128,7 @@ qb_log_dcs_get(int32_t *newly_created,
if (rc < 0) {
rc = qb_array_grow(lookup_arr, lineno + 255);
assert(rc == 0);
- rc = qb_array_index(lookup_arr, lineno, (void**)&csl_head);
+ rc = qb_array_index(lookup_arr, lineno, (void **)&csl_head);
assert(rc == 0);
}
if (csl_head->cs == NULL) {
@@ -162,15 +159,14 @@ qb_log_dcs_get(int32_t *newly_created,
}
(void)qb_thread_unlock(arr_next_lock);
-
return cs;
}
-
-void qb_log_dcs_init(void)
+void
+qb_log_dcs_init(void)
{
- lookup_arr = qb_array_create(256, sizeof(struct callsite_list));
- callsite_arr = qb_array_create(256, sizeof(struct qb_log_callsite));
+ lookup_arr = qb_array_create(256, sizeof(struct callsite_list));
+ callsite_arr = qb_array_create(256, sizeof(struct qb_log_callsite));
arr_next_lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
@@ -178,7 +174,7 @@ void qb_log_dcs_init(void)
_log_register_callsites();
}
-void qb_log_dcs_fini(void)
+void
+qb_log_dcs_fini(void)
{
}
-
diff --git a/lib/log_file.c b/lib/log_file.c
index a748fd8..b8c2038 100644
--- a/lib/log_file.c
+++ b/lib/log_file.c
@@ -21,9 +21,9 @@
#include "os_base.h"
#include "log_int.h"
-static void _file_logger(int32_t t,
- struct qb_log_callsite *cs,
- time_t timestamp, const char *msg)
+static void
+_file_logger(int32_t t,
+ struct qb_log_callsite *cs, time_t timestamp, const char *msg)
{
char output_buffer[QB_LOG_MAX_LEN];
FILE *f = qb_log_target_user_data_get(t);
@@ -38,7 +38,8 @@ static void _file_logger(int32_t t,
fflush(f);
}
-static void _file_close(int32_t t)
+static void
+_file_close(int32_t t)
{
FILE *f = qb_log_target_user_data_get(t);
@@ -48,7 +49,8 @@ static void _file_close(int32_t t)
}
}
-static void _file_reload(int32_t target)
+static void
+_file_reload(int32_t target)
{
struct qb_log_target *t = qb_log_target_get(target);
@@ -58,7 +60,8 @@ static void _file_reload(int32_t target)
t->instance = fopen(t->name, "a+");
}
-int32_t qb_log_stderr_open(struct qb_log_target *t)
+int32_t
+qb_log_stderr_open(struct qb_log_target *t)
{
t->logger = _file_logger;
t->reload = NULL;
@@ -68,7 +71,8 @@ int32_t qb_log_stderr_open(struct qb_log_target *t)
return 0;
}
-int32_t qb_log_file_open(const char *filename)
+int32_t
+qb_log_file_open(const char *filename)
{
struct qb_log_target *t;
FILE *fp;
@@ -94,7 +98,8 @@ int32_t qb_log_file_open(const char *filename)
return t->pos;
}
-void qb_log_file_close(int32_t t)
+void
+qb_log_file_close(int32_t t)
{
qb_log_custom_close(t);
}
diff --git a/lib/log_format.c b/lib/log_format.c
index 45de9b6..a052596 100644
--- a/lib/log_format.c
+++ b/lib/log_format.c
@@ -54,13 +54,14 @@ static const char log_month_name[][4] = {
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
-void qb_log_tags_stringify_fn_set(qb_log_tags_stringify_fn fn)
+void
+qb_log_tags_stringify_fn_set(qb_log_tags_stringify_fn fn)
{
_user_tags_stringify_fn = fn;
}
-static int _strcpy_cutoff(char *dest, const char *src, size_t cutoff,
- size_t buf_len)
+static int
+_strcpy_cutoff(char *dest, const char *src, size_t cutoff, size_t buf_len)
{
size_t len = strlen(src);
if (buf_len <= 1) {
@@ -93,10 +94,11 @@ static int _strcpy_cutoff(char *dest, const char *src, size_t cutoff,
*
* any number between % and character specify field length to pad or chop
*/
-void qb_log_target_format(int32_t target,
- struct qb_log_callsite *cs,
- time_t current_time,
- const char *formatted_message, char *output_buffer)
+void
+qb_log_target_format(int32_t target,
+ struct qb_log_callsite *cs,
+ time_t current_time,
+ const char *formatted_message, char *output_buffer)
{
char char_time[128];
struct tm tm_res;
@@ -183,7 +185,8 @@ void qb_log_target_format(int32_t target,
}
len = _strcpy_cutoff(output_buffer + output_buffer_idx,
p, cutoff,
- (QB_LOG_MAX_LEN - output_buffer_idx));
+ (QB_LOG_MAX_LEN -
+ output_buffer_idx));
output_buffer_idx += len;
format_buffer_idx += 1;
}
@@ -192,8 +195,8 @@ void qb_log_target_format(int32_t target,
}
}
- if (output_buffer[output_buffer_idx-1] == '\n') {
- output_buffer[output_buffer_idx-1] = '\0';
+ if (output_buffer[output_buffer_idx - 1] == '\n') {
+ output_buffer[output_buffer_idx - 1] = '\0';
} else {
output_buffer[output_buffer_idx] = '\0';
}
diff --git a/lib/log_syslog.c b/lib/log_syslog.c
index d6709c1..8d6a448 100644
--- a/lib/log_syslog.c
+++ b/lib/log_syslog.c
@@ -22,9 +22,9 @@
#include <syslog.h>
#include "log_int.h"
-static void _syslog_logger(int32_t target,
- struct qb_log_callsite *cs,
- time_t timestamp, const char *msg)
+static void
+_syslog_logger(int32_t target,
+ struct qb_log_callsite *cs, time_t timestamp, const char *msg)
{
char output_buffer[QB_LOG_MAX_LEN];
struct qb_log_target *t = qb_log_target_get(target);
@@ -40,19 +40,22 @@ static void _syslog_logger(int32_t target,
syslog(final_priority, "%s", output_buffer);
}
-static void _syslog_close(int32_t target)
+static void
+_syslog_close(int32_t target)
{
closelog();
}
-static void _syslog_reload(int32_t target)
+static void
+_syslog_reload(int32_t target)
{
struct qb_log_target *t = qb_log_target_get(target);
closelog();
openlog(t->name, LOG_PID, t->facility);
}
-int32_t qb_log_syslog_open(struct qb_log_target *t)
+int32_t
+qb_log_syslog_open(struct qb_log_target *t)
{
t->logger = _syslog_logger;
t->reload = _syslog_reload;
diff --git a/lib/log_thread.c b/lib/log_thread.c
index 6d8d9c0..0d245ed 100644
--- a/lib/log_thread.c
+++ b/lib/log_thread.c
@@ -57,7 +57,8 @@ static int logt_after_log_ops_yield = 10;
static pthread_t logt_thread_id = 0;
static void *qb_logt_worker_thread(void *data) __attribute__ ((noreturn));
-static void *qb_logt_worker_thread(void *data)
+static void *
+qb_logt_worker_thread(void *data)
{
struct qb_log_record *rec;
int dropped = 0;
@@ -110,9 +111,10 @@ retry_sem_wait:
}
}
-static int logt_thread_priority_set(int policy,
- const struct sched_param *param,
- unsigned int after_log_ops_yield)
+static int
+logt_thread_priority_set(int policy,
+ const struct sched_param *param,
+ unsigned int after_log_ops_yield)
{
int res = 0;
if (param == NULL) {
@@ -135,7 +137,8 @@ static int logt_thread_priority_set(int policy,
return res;
}
-static void wthread_create(void)
+static void
+wthread_create(void)
{
int res;
@@ -168,14 +171,16 @@ static void wthread_create(void)
}
}
-void qb_log_thread_start(void)
+void
+qb_log_thread_start(void)
{
wthread_create();
logt_wthread_lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
-void qb_log_thread_log_post(struct qb_log_callsite *cs,
- time_t timestamp, const char *buffer)
+void
+qb_log_thread_log_post(struct qb_log_callsite *cs,
+ time_t timestamp, const char *buffer)
{
struct qb_log_record *rec;
size_t buf_size;
@@ -221,7 +226,8 @@ free_record:
free(rec);
}
-void qb_log_thread_stop(void)
+void
+qb_log_thread_stop(void)
{
int res;
int value;
@@ -241,13 +247,16 @@ void qb_log_thread_stop(void)
}
sem_wait(&logt_print_finished);
- rec = qb_list_entry(logt_print_finished_records.next, struct qb_log_record, list);
+ rec = qb_list_entry(logt_print_finished_records.next,
+ struct qb_log_record, list);
qb_list_del(&rec->list);
- logt_memory_used = logt_memory_used - strlen(rec->buffer) -
- sizeof(struct qb_log_record) - 1;
+ logt_memory_used = logt_memory_used -
+ strlen(rec->buffer) -
+ sizeof(struct qb_log_record) - 1;
(void)qb_thread_unlock(logt_wthread_lock);
- qb_log_thread_log_write(rec->cs, rec->timestamp, rec->buffer);
+ qb_log_thread_log_write(rec->cs, rec->timestamp,
+ rec->buffer);
free(rec->buffer);
free(rec);
}
diff --git a/lib/loop.c b/lib/loop.c
index 5cf594b..8cb0ab2 100644
--- a/lib/loop.c
+++ b/lib/loop.c
@@ -26,19 +26,20 @@
#include "loop_int.h"
#include "util_int.h"
-static int32_t qb_loop_run_level(struct qb_loop_level *level)
+static int32_t
+qb_loop_run_level(struct qb_loop_level *level)
{
struct qb_loop_item *job;
struct qb_list_head *iter;
int32_t processed = 0;
- Ill_have_another:
+Ill_have_another:
iter = level->job_head.next;
if (iter != &level->job_head) {
job = qb_list_entry(iter, struct qb_loop_item, list);
- qb_list_del (&job->list);
- qb_list_init (&job->list);
+ qb_list_del(&job->list);
+ qb_list_init(&job->list);
job->source->dispatch_and_take_back(job, level->priority);
level->todo--;
processed++;
@@ -52,23 +53,24 @@ static int32_t qb_loop_run_level(struct qb_loop_level *level)
return processed;
}
-void qb_loop_level_item_add(struct qb_loop_level *level,
- struct qb_loop_item *job)
+void
+qb_loop_level_item_add(struct qb_loop_level *level, struct qb_loop_item *job)
{
qb_list_init(&job->list);
qb_list_add_tail(&job->list, &level->job_head);
level->todo++;
}
-void qb_loop_level_item_del(struct qb_loop_level *level,
- struct qb_loop_item *job)
+void
+qb_loop_level_item_del(struct qb_loop_level *level, struct qb_loop_item *job)
{
qb_list_del(&job->list);
qb_list_init(&job->list);
level->todo--;
}
-struct qb_loop * qb_loop_create(void)
+struct qb_loop *
+qb_loop_create(void)
{
struct qb_loop *l = malloc(sizeof(struct qb_loop));
int32_t p;
@@ -95,7 +97,8 @@ struct qb_loop * qb_loop_create(void)
return l;
}
-void qb_loop_destroy(struct qb_loop * l)
+void
+qb_loop_destroy(struct qb_loop *l)
{
qb_loop_timer_destroy(l);
qb_loop_jobs_destroy(l);
@@ -104,12 +107,14 @@ void qb_loop_destroy(struct qb_loop * l)
free(l);
}
-void qb_loop_stop(struct qb_loop *l)
+void
+qb_loop_stop(struct qb_loop *l)
{
l->stop_requested = QB_TRUE;
}
-void qb_loop_run(struct qb_loop *l)
+void
+qb_loop_run(struct qb_loop *l)
{
int32_t p;
int32_t p_stop = QB_LOOP_LOW;
@@ -149,4 +154,3 @@ void qb_loop_run(struct qb_loop *l)
}
} while (!l->stop_requested);
}
-
diff --git a/lib/loop_job.c b/lib/loop_job.c
index 3ed783f..c17663d 100644
--- a/lib/loop_job.c
+++ b/lib/loop_job.c
@@ -30,8 +30,8 @@ struct qb_loop_job {
qb_loop_job_dispatch_fn dispatch_fn;
};
-static void job_dispatch(struct qb_loop_item * item,
- enum qb_loop_priority p)
+static void
+job_dispatch(struct qb_loop_item *item, enum qb_loop_priority p)
{
struct qb_loop_job *job = qb_list_entry(item, struct qb_loop_job, item);
@@ -43,7 +43,8 @@ static void job_dispatch(struct qb_loop_item * item,
*/
}
-static int32_t get_more_jobs(struct qb_loop_source* s, int32_t ms_timeout)
+static int32_t
+get_more_jobs(struct qb_loop_source *s, int32_t ms_timeout)
{
int32_t p;
int32_t new_jobs = 0;
@@ -54,7 +55,8 @@ static int32_t get_more_jobs(struct qb_loop_source* s, int32_t ms_timeout)
for (p = QB_LOOP_LOW; p <= QB_LOOP_HIGH; p++) {
if (!qb_list_empty(&s->l->level[p].wait_head)) {
new_jobs += qb_list_length(&s->l->level[p].wait_head);
- qb_list_splice(&s->l->level[p].wait_head, &s->l->level[p].job_head);
+ qb_list_splice(&s->l->level[p].wait_head,
+ &s->l->level[p].job_head);
qb_list_init(&s->l->level[p].wait_head);
}
}
@@ -75,15 +77,16 @@ qb_loop_jobs_create(struct qb_loop *l)
return s;
}
-void qb_loop_jobs_destroy(struct qb_loop *l)
+void
+qb_loop_jobs_destroy(struct qb_loop *l)
{
free(l->job_source);
}
-int32_t qb_loop_job_add(struct qb_loop *l,
- enum qb_loop_priority p,
- void *data,
- qb_loop_job_dispatch_fn dispatch_fn)
+int32_t
+qb_loop_job_add(struct qb_loop *l,
+ enum qb_loop_priority p,
+ void *data, qb_loop_job_dispatch_fn dispatch_fn)
{
struct qb_loop_job *job;
@@ -107,4 +110,3 @@ int32_t qb_loop_job_add(struct qb_loop *l,
return 0;
}
-
diff --git a/lib/loop_poll.c b/lib/loop_poll.c
index e60b51d..adf93c3 100644
--- a/lib/loop_poll.c
+++ b/lib/loop_poll.c
@@ -56,10 +56,10 @@ enum qb_poll_type {
QB_TIMER,
};
-
struct qb_poll_entry;
-typedef int32_t (*qb_poll_add_to_jobs_fn) (struct qb_loop* l, struct qb_poll_entry* pe);
+typedef int32_t(*qb_poll_add_to_jobs_fn) (struct qb_loop * l,
+ struct qb_poll_entry * pe);
struct qb_poll_entry {
struct qb_loop_item item;
@@ -88,35 +88,49 @@ struct qb_poll_source {
int32_t not_enough_fds;
};
-static int32_t _qb_signal_add_to_jobs_(struct qb_loop* l,
- struct qb_poll_entry* pe);
+static int32_t _qb_signal_add_to_jobs_(struct qb_loop *l,
+ struct qb_poll_entry *pe);
#ifdef HAVE_EPOLL
-static int32_t _poll_to_epoll_event_(int32_t event)
+static int32_t
+_poll_to_epoll_event_(int32_t event)
{
int32_t out = 0;
- if (event & POLLIN) out |= EPOLLIN;
- if (event & POLLOUT) out |= EPOLLOUT;
- if (event & POLLPRI) out |= EPOLLPRI;
- if (event & POLLERR) out |= EPOLLERR;
- if (event & POLLHUP) out |= EPOLLHUP;
- if (event & POLLNVAL) out |= EPOLLERR;
+ if (event & POLLIN)
+ out |= EPOLLIN;
+ if (event & POLLOUT)
+ out |= EPOLLOUT;
+ if (event & POLLPRI)
+ out |= EPOLLPRI;
+ if (event & POLLERR)
+ out |= EPOLLERR;
+ if (event & POLLHUP)
+ out |= EPOLLHUP;
+ if (event & POLLNVAL)
+ out |= EPOLLERR;
return out;
}
-static int32_t _epoll_to_poll_event_(int32_t event)
+static int32_t
+_epoll_to_poll_event_(int32_t event)
{
int32_t out = 0;
- if (event & EPOLLIN) out |= POLLIN;
- if (event & EPOLLOUT) out |= POLLOUT;
- if (event & EPOLLPRI) out |= POLLPRI;
- if (event & EPOLLERR) out |= POLLERR;
- if (event & EPOLLHUP) out |= POLLHUP;
+ if (event & EPOLLIN)
+ out |= POLLIN;
+ if (event & EPOLLOUT)
+ out |= POLLOUT;
+ if (event & EPOLLPRI)
+ out |= POLLPRI;
+ if (event & EPOLLERR)
+ out |= POLLERR;
+ if (event & EPOLLHUP)
+ out |= POLLHUP;
return out;
}
#endif /* HAVE_EPOLL */
-static void _poll_entry_check_generate_(struct qb_poll_entry *pe)
+static void
+_poll_entry_check_generate_(struct qb_poll_entry *pe)
{
int32_t i;
@@ -130,16 +144,16 @@ static void _poll_entry_check_generate_(struct qb_poll_entry *pe)
}
#if defined(HAVE_TIMERFD) || defined(HAVE_EPOLL)
-static int32_t _poll_entry_from_handle_(struct qb_poll_source *s,
- uint64_t handle_in,
- struct qb_poll_entry **pe_pt)
+static int32_t
+_poll_entry_from_handle_(struct qb_poll_source *s,
+ uint64_t handle_in, struct qb_poll_entry **pe_pt)
{
int32_t res = 0;
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
struct qb_poll_entry *pe;
- res = qb_array_index(s->poll_entries, handle, (void**)&pe);
+ res = qb_array_index(s->poll_entries, handle, (void **)&pe);
if (res != 0) {
return res;
}
@@ -151,21 +165,24 @@ static int32_t _poll_entry_from_handle_(struct qb_poll_source *s,
}
#endif /* HAVE_TIMERFD or HAVE_EPOLL */
-static void _poll_entry_mark_deleted_(struct qb_poll_entry *pe)
+static void
+_poll_entry_mark_deleted_(struct qb_poll_entry *pe)
{
pe->ufd.fd = -1;
pe->state = QB_POLL_ENTRY_DELETED;
pe->check = 0;
}
-static void _poll_entry_empty_(struct qb_poll_entry *pe)
+static void
+_poll_entry_empty_(struct qb_poll_entry *pe)
{
memset(pe, 0, sizeof(struct qb_poll_entry));
pe->ufd.fd = -1;
}
-static void _poll_dispatch_and_take_back_(struct qb_loop_item * item,
- enum qb_loop_priority p)
+static void
+_poll_dispatch_and_take_back_(struct qb_loop_item *item,
+ enum qb_loop_priority p)
{
struct qb_poll_entry *pe = (struct qb_poll_entry *)item;
int32_t res;
@@ -180,7 +197,9 @@ static void _poll_dispatch_and_take_back_(struct qb_loop_item * item,
assert(pe->state == QB_POLL_ENTRY_JOBLIST);
if (pe->type == QB_POLL) {
- res = pe->poll_dispatch_fn(pe->ufd.fd, pe->ufd.revents, pe->item.user_data);
+ res = pe->poll_dispatch_fn(pe->ufd.fd,
+ pe->ufd.revents,
+ pe->item.user_data);
if (res < 0) {
_poll_entry_mark_deleted_(pe);
} else {
@@ -191,8 +210,9 @@ static void _poll_dispatch_and_take_back_(struct qb_loop_item * item,
_poll_entry_mark_deleted_(pe);
pe->timer_dispatch_fn(pe->item.user_data);
} else {
- qb_util_log(LOG_WARNING, "poll entry of unknown type:%d state:%d",
- pe->type, pe->state);
+ qb_util_log(LOG_WARNING,
+ "poll entry of unknown type:%d state:%d", pe->type,
+ pe->state);
return;
}
if (pe->state == QB_POLL_ENTRY_ACTIVE) {
@@ -211,26 +231,29 @@ static void _poll_dispatch_and_take_back_(struct qb_loop_item * item,
"[fd:%d] dispatch:%p runs:%d duration:%d ms",
pe->ufd.fd, pe->poll_dispatch_fn,
pe->runs,
- (int32_t)((stop - start)/QB_TIME_NS_IN_MSEC));
+ (int32_t) ((stop -
+ start) / QB_TIME_NS_IN_MSEC));
} else if (log_warn && pe->type == QB_TIMER) {
qb_util_log(LOG_INFO,
"[timer] dispatch:%p runs:%d duration:%d ms",
pe->timer_dispatch_fn,
pe->runs,
- (int32_t)((stop - start)/QB_TIME_NS_IN_MSEC));
+ (int32_t) ((stop -
+ start) / QB_TIME_NS_IN_MSEC));
}
#endif /* DEBUG_DISPATCH_TIME */
}
}
-static void _poll_fds_usage_check_(struct qb_poll_source *s)
+static void
+_poll_fds_usage_check_(struct qb_poll_source *s)
{
struct rlimit lim;
static int32_t socks_limit = 0;
int32_t send_event = 0;
int32_t socks_used = 0;
int32_t socks_avail = 0;
- struct qb_poll_entry * pe;
+ struct qb_poll_entry *pe;
int32_t i;
if (socks_limit == 0) {
@@ -246,10 +269,9 @@ static void _poll_fds_usage_check_(struct qb_poll_source *s)
}
for (i = 0; i < s->poll_entry_count; i++) {
- assert(qb_array_index(s->poll_entries, i, (void**)&pe) == 0);
+ assert(qb_array_index(s->poll_entries, i, (void **)&pe) == 0);
if ((pe->state == QB_POLL_ENTRY_ACTIVE ||
- pe->state == QB_POLL_ENTRY_JOBLIST) &&
- pe->ufd.fd != -1) {
+ pe->state == QB_POLL_ENTRY_JOBLIST) && pe->ufd.fd != -1) {
socks_used++;
}
if (pe->state == QB_POLL_ENTRY_DELETED) {
@@ -274,26 +296,26 @@ static void _poll_fds_usage_check_(struct qb_poll_source *s)
}
}
if (send_event && s->low_fds_event_fn) {
- s->low_fds_event_fn(s->not_enough_fds,
- socks_avail);
+ s->low_fds_event_fn(s->not_enough_fds, socks_avail);
}
}
#ifdef HAVE_EPOLL
#define MAX_EVENTS 12
-static int32_t _poll_and_add_to_jobs_(struct qb_loop_source* src, int32_t ms_timeout)
+static int32_t
+_poll_and_add_to_jobs_(struct qb_loop_source *src, int32_t ms_timeout)
{
int32_t i;
int32_t res;
int32_t event_count;
int32_t new_jobs = 0;
- struct qb_poll_entry * pe = NULL;
- struct qb_poll_source * s = (struct qb_poll_source *)src;
+ struct qb_poll_entry *pe = NULL;
+ struct qb_poll_source *s = (struct qb_poll_source *)src;
struct epoll_event events[MAX_EVENTS];
_poll_fds_usage_check_(s);
- retry_poll:
+retry_poll:
event_count = epoll_wait(s->epollfd, events, MAX_EVENTS, ms_timeout);
@@ -306,11 +328,13 @@ static int32_t _poll_and_add_to_jobs_(struct qb_loop_source* src, int32_t ms_tim
for (i = 0; i < event_count; i++) {
res = _poll_entry_from_handle_(s, events[i].data.u64, &pe);
if (res != 0) {
- qb_util_log(LOG_WARNING, "can't find poll entry for new event.");
+ qb_util_log(LOG_WARNING,
+ "can't find poll entry for new event.");
continue;
}
if (pe->ufd.fd == -1 || pe->state == QB_POLL_ENTRY_DELETED) {
- qb_util_log(LOG_WARNING, "can't post new event to a deleted entry.");
+ qb_util_log(LOG_WARNING,
+ "can't post new event to a deleted entry.");
/*
* empty/deleted
*/
@@ -331,22 +355,23 @@ static int32_t _poll_and_add_to_jobs_(struct qb_loop_source* src, int32_t ms_tim
return new_jobs;
}
#else
-static int32_t _poll_and_add_to_jobs_(struct qb_loop_source* src, int32_t ms_timeout)
+static int32_t
+_poll_and_add_to_jobs_(struct qb_loop_source *src, int32_t ms_timeout)
{
int32_t i;
int32_t res;
int32_t new_jobs = 0;
- struct qb_poll_entry * pe;
- struct qb_poll_source * s = (struct qb_poll_source *)src;
+ struct qb_poll_entry *pe;
+ struct qb_poll_source *s = (struct qb_poll_source *)src;
_poll_fds_usage_check_(s);
for (i = 0; i < s->poll_entry_count; i++) {
- assert(qb_array_index(s->poll_entries, i, (void**)&pe) == 0);
+ assert(qb_array_index(s->poll_entries, i, (void **)&pe) == 0);
memcpy(&s->ufds[i], &pe->ufd, sizeof(struct pollfd));
}
- retry_poll:
+retry_poll:
res = poll(s->ufds, s->poll_entry_count, ms_timeout);
if (errno == EINTR && res == -1) {
goto retry_poll;
@@ -361,7 +386,7 @@ static int32_t _poll_and_add_to_jobs_(struct qb_loop_source* src, int32_t ms_tim
*/
continue;
}
- assert(qb_array_index(s->poll_entries, i, (void**)&pe) == 0);
+ assert(qb_array_index(s->poll_entries, i, (void **)&pe) == 0);
if (pe->state != QB_POLL_ENTRY_ACTIVE ||
s->ufds[i].revents == pe->ufd.revents) {
/*
@@ -377,7 +402,7 @@ static int32_t _poll_and_add_to_jobs_(struct qb_loop_source* src, int32_t ms_tim
}
#endif /* HAVE_EPOLL */
-struct qb_loop_source*
+struct qb_loop_source *
qb_loop_poll_create(struct qb_loop *l)
{
struct qb_poll_source *s = malloc(sizeof(struct qb_poll_source));
@@ -399,12 +424,13 @@ qb_loop_poll_create(struct qb_loop *l)
s->ufds = 0;
#endif /* HAVE_EPOLL */
- return (struct qb_loop_source*)s;
+ return (struct qb_loop_source *)s;
}
-void qb_loop_poll_destroy(struct qb_loop *l)
+void
+qb_loop_poll_destroy(struct qb_loop *l)
{
- struct qb_poll_source * s = (struct qb_poll_source *)l->fd_source;
+ struct qb_poll_source *s = (struct qb_poll_source *)l->fd_source;
qb_array_free(s->poll_entries);
#ifdef HAVE_EPOLL
if (s->epollfd != -1) {
@@ -415,16 +441,18 @@ void qb_loop_poll_destroy(struct qb_loop *l)
free(s);
}
-int32_t qb_loop_poll_low_fds_event_set(struct qb_loop *l,
- qb_loop_poll_low_fds_event_fn fn)
+int32_t
+qb_loop_poll_low_fds_event_set(struct qb_loop *l,
+ qb_loop_poll_low_fds_event_fn fn)
{
- struct qb_poll_source * s = (struct qb_poll_source *)l->fd_source;
+ struct qb_poll_source *s = (struct qb_poll_source *)l->fd_source;
s->low_fds_event_fn = fn;
return 0;
}
-static int32_t _get_empty_array_position_(struct qb_poll_source * s)
+static int32_t
+_get_empty_array_position_(struct qb_poll_source *s)
{
int32_t found = 0;
uint32_t install_pos;
@@ -437,7 +465,8 @@ static int32_t _get_empty_array_position_(struct qb_poll_source * s)
for (found = 0, install_pos = 0;
install_pos < s->poll_entry_count; install_pos++) {
- assert(qb_array_index(s->poll_entries, install_pos, (void**)&pe) == 0);
+ assert(qb_array_index
+ (s->poll_entries, install_pos, (void **)&pe) == 0);
if (pe->state == QB_POLL_ENTRY_EMPTY) {
found = 1;
break;
@@ -448,14 +477,12 @@ static int32_t _get_empty_array_position_(struct qb_poll_source * s)
/*
* Grow pollfd list
*/
- res = qb_array_grow(s->poll_entries,
- s->poll_entry_count + 1);
+ res = qb_array_grow(s->poll_entries, s->poll_entry_count + 1);
if (res != 0) {
return res;
}
-
#ifndef HAVE_EPOLL
- new_size = (s->poll_entry_count+ 1) * sizeof(struct pollfd);
+ new_size = (s->poll_entry_count + 1) * sizeof(struct pollfd);
ufds = realloc(s->ufds, new_size);
if (ufds == NULL) {
return -ENOMEM;
@@ -469,17 +496,15 @@ static int32_t _get_empty_array_position_(struct qb_poll_source * s)
return install_pos;
}
-static int32_t _poll_add_(struct qb_loop *l,
- enum qb_loop_priority p,
- int32_t fd,
- int32_t events,
- void *data,
- struct qb_poll_entry **pe_pt)
+static int32_t
+_poll_add_(struct qb_loop *l,
+ enum qb_loop_priority p,
+ int32_t fd, int32_t events, void *data, struct qb_poll_entry **pe_pt)
{
struct qb_poll_entry *pe;
uint32_t install_pos;
int32_t res = 0;
- struct qb_poll_source * s;
+ struct qb_poll_source *s;
#ifdef HAVE_EPOLL
struct epoll_event ev;
#endif /* HAVE_EPOLL */
@@ -492,7 +517,7 @@ static int32_t _poll_add_(struct qb_loop *l,
install_pos = _get_empty_array_position_(s);
- assert(qb_array_index(s->poll_entries, install_pos, (void**)&pe) == 0);
+ assert(qb_array_index(s->poll_entries, install_pos, (void **)&pe) == 0);
pe->state = QB_POLL_ENTRY_ACTIVE;
pe->install_pos = install_pos;
_poll_entry_check_generate_(pe);
@@ -500,7 +525,7 @@ static int32_t _poll_add_(struct qb_loop *l,
pe->ufd.events = events;
pe->ufd.revents = 0;
pe->item.user_data = data;
- pe->item.source = (struct qb_loop_source*)l->fd_source;
+ pe->item.source = (struct qb_loop_source *)l->fd_source;
pe->p = p;
pe->runs = 0;
#ifdef HAVE_EPOLL
@@ -516,7 +541,8 @@ static int32_t _poll_add_(struct qb_loop *l,
return (res);
}
-static int32_t _qb_poll_add_to_jobs_(struct qb_loop* l, struct qb_poll_entry* pe)
+static int32_t
+_qb_poll_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
{
assert(pe->type == QB_POLL);
qb_loop_level_item_add(&l->level[pe->p], &pe->item);
@@ -524,12 +550,12 @@ static int32_t _qb_poll_add_to_jobs_(struct qb_loop* l, struct qb_poll_entry* pe
return 1;
}
-int32_t qb_loop_poll_add(struct qb_loop *l,
- enum qb_loop_priority p,
- int32_t fd,
- int32_t events,
- void *data,
- qb_loop_poll_dispatch_fn dispatch_fn)
+int32_t
+qb_loop_poll_add(struct qb_loop * l,
+ enum qb_loop_priority p,
+ int32_t fd,
+ int32_t events,
+ void *data, qb_loop_poll_dispatch_fn dispatch_fn)
{
struct qb_poll_entry *pe = NULL;
int32_t size;
@@ -546,24 +572,23 @@ int32_t qb_loop_poll_add(struct qb_loop *l,
if (new_size > size) {
qb_util_log(LOG_TRACE,
- "grown poll array to %d for FD %d",
- new_size, fd);
+ "grown poll array to %d for FD %d", new_size, fd);
}
return res;
}
-int32_t qb_loop_poll_mod(struct qb_loop *l,
- enum qb_loop_priority p,
- int32_t fd,
- int32_t events,
- void *data,
- qb_loop_poll_dispatch_fn dispatch_fn)
+int32_t
+qb_loop_poll_mod(struct qb_loop * l,
+ enum qb_loop_priority p,
+ int32_t fd,
+ int32_t events,
+ void *data, qb_loop_poll_dispatch_fn dispatch_fn)
{
uint32_t i;
int32_t res = 0;
struct qb_poll_entry *pe;
- struct qb_poll_source * s = (struct qb_poll_source *)l->fd_source;
+ struct qb_poll_source *s = (struct qb_poll_source *)l->fd_source;
#ifdef HAVE_EPOLL
struct epoll_event ev;
#endif /* HAVE_EPOLL */
@@ -572,7 +597,7 @@ int32_t qb_loop_poll_mod(struct qb_loop *l,
* Find file descriptor to modify events and dispatch function
*/
for (i = 0; i < s->poll_entry_count; i++) {
- assert(qb_array_index(s->poll_entries, i, (void**)&pe) == 0);
+ assert(qb_array_index(s->poll_entries, i, (void **)&pe) == 0);
if (pe->ufd.fd != fd) {
continue;
}
@@ -601,15 +626,16 @@ int32_t qb_loop_poll_mod(struct qb_loop *l,
return -EBADF;
}
-int32_t qb_loop_poll_del(struct qb_loop *l, int32_t fd)
+int32_t
+qb_loop_poll_del(struct qb_loop * l, int32_t fd)
{
int32_t i;
int32_t res = 0;
struct qb_poll_entry *pe;
- struct qb_poll_source * s = (struct qb_poll_source *)l->fd_source;
+ struct qb_poll_source *s = (struct qb_poll_source *)l->fd_source;
for (i = 0; i < s->poll_entry_count; i++) {
- assert(qb_array_index(s->poll_entries, i, (void**)&pe) == 0);
+ assert(qb_array_index(s->poll_entries, i, (void **)&pe) == 0);
if (pe->ufd.fd != fd || pe->type != QB_POLL) {
continue;
}
@@ -638,7 +664,8 @@ int32_t qb_loop_poll_del(struct qb_loop *l, int32_t fd)
}
#ifdef HAVE_TIMERFD
-static int32_t _qb_timer_add_to_jobs_(struct qb_loop* l, struct qb_poll_entry* pe)
+static int32_t
+_qb_timer_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
{
uint64_t expired = 0;
ssize_t bytes = 0;
@@ -648,7 +675,8 @@ static int32_t _qb_timer_add_to_jobs_(struct qb_loop* l, struct qb_poll_entry* p
bytes = read(pe->ufd.fd, &expired, sizeof(expired));
if (bytes != sizeof(expired)) {
qb_util_perror(LOG_WARNING,
- "couldn't read from timer fd %zd", bytes);
+ "couldn't read from timer fd %zd",
+ bytes);
}
qb_loop_level_item_add(&l->level[pe->p], &pe->item);
} else {
@@ -661,27 +689,30 @@ static int32_t _qb_timer_add_to_jobs_(struct qb_loop* l, struct qb_poll_entry* p
return 1;
}
-int32_t qb_loop_timer_msec_duration_to_expire(struct qb_loop_source *timer_source)
+int32_t
+qb_loop_timer_msec_duration_to_expire(struct qb_loop_source * timer_source)
{
return -1;
}
-struct qb_loop_source*
+struct qb_loop_source *
qb_loop_timer_create(struct qb_loop *l)
{
return NULL;
}
-void qb_loop_timer_destroy(struct qb_loop *l)
+void
+qb_loop_timer_destroy(struct qb_loop *l)
{
}
-int32_t qb_loop_timer_add(struct qb_loop *l,
- enum qb_loop_priority p,
- uint64_t nsec_duration,
- void *data,
- qb_loop_timer_dispatch_fn timer_fn,
- qb_loop_timer_handle * timer_handle_out)
+int32_t
+qb_loop_timer_add(struct qb_loop *l,
+ enum qb_loop_priority p,
+ uint64_t nsec_duration,
+ void *data,
+ qb_loop_timer_dispatch_fn timer_fn,
+ qb_loop_timer_handle * timer_handle_out)
{
struct qb_poll_entry *pe;
int32_t fd;
@@ -695,10 +726,11 @@ int32_t qb_loop_timer_add(struct qb_loop *l,
return -EINVAL;
}
if (timer_handle_out == NULL) {
- qb_util_log(LOG_ERR, "can't add a timer with (timer_handle_out == NULL)");
+ qb_util_log(LOG_ERR,
+ "can't add a timer with (timer_handle_out == NULL)");
return -ENOENT;
}
- fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC|TFD_NONBLOCK);
+ fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
if (fd == -1) {
res = -errno;
qb_util_perror(LOG_ERR, "failed to create timer");
@@ -735,12 +767,13 @@ int32_t qb_loop_timer_add(struct qb_loop *l,
return res;
- close_and_return:
+close_and_return:
close(fd);
return res;
}
-int32_t qb_loop_timer_del(struct qb_loop *l, qb_loop_timer_handle th)
+int32_t
+qb_loop_timer_del(struct qb_loop * l, qb_loop_timer_handle th)
{
struct qb_poll_entry *pe;
struct qb_poll_source *s;
@@ -776,9 +809,11 @@ int32_t qb_loop_timer_del(struct qb_loop *l, qb_loop_timer_handle th)
}
if (pe->ufd.fd != -1) {
#ifdef HAVE_EPOLL
- if (epoll_ctl(s->epollfd, EPOLL_CTL_DEL, pe->ufd.fd, NULL) == -1) {
+ if (epoll_ctl(s->epollfd, EPOLL_CTL_DEL, pe->ufd.fd, NULL) ==
+ -1) {
res = -errno;
- qb_util_perror(LOG_WARNING, "epoll_ctl(del:%d)", pe->ufd.fd);
+ qb_util_perror(LOG_WARNING, "epoll_ctl(del:%d)",
+ pe->ufd.fd);
}
#else
s->ufds[pe->install_pos].fd = -1;
@@ -792,7 +827,8 @@ int32_t qb_loop_timer_del(struct qb_loop *l, qb_loop_timer_handle th)
return 0;
}
-uint64_t qb_loop_timer_expire_time_get(struct qb_loop *l, qb_loop_timer_handle th)
+uint64_t
+qb_loop_timer_expire_time_get(struct qb_loop * l, qb_loop_timer_handle th)
{
struct qb_poll_entry *pe;
struct qb_poll_source *s;
@@ -816,8 +852,7 @@ uint64_t qb_loop_timer_expire_time_get(struct qb_loop *l, qb_loop_timer_handle t
#endif /* HAVE_TIMERFD */
-
-static int32_t pipe_fds[2] = {-1, -1};
+static int32_t pipe_fds[2] = { -1, -1 };
struct qb_signal_source {
struct qb_loop_source s;
@@ -833,25 +868,27 @@ struct qb_loop_sig {
struct qb_loop_sig *cloned_from;
};
-static void _handle_real_signal_(int signal_num, siginfo_t * si, void *context)
+static void
+_handle_real_signal_(int signal_num, siginfo_t * si, void *context)
{
int32_t sig = signal_num;
int32_t res = 0;
if (pipe_fds[1] > 0) {
- try_again:
+try_again:
res = write(pipe_fds[1], &sig, sizeof(int32_t));
if (res == -1 && errno == EAGAIN) {
goto try_again;
} else if (res != sizeof(int32_t)) {
- qb_util_log(LOG_ERR, "failed to write signal to pipe [%d]",
- res);
+ qb_util_log(LOG_ERR,
+ "failed to write signal to pipe [%d]", res);
}
}
}
-static void _signal_dispatch_and_take_back_(struct qb_loop_item * item,
- enum qb_loop_priority p)
+static void
+_signal_dispatch_and_take_back_(struct qb_loop_item *item,
+ enum qb_loop_priority p)
{
struct qb_loop_sig *sig = (struct qb_loop_sig *)item;
int32_t res;
@@ -864,7 +901,6 @@ static void _signal_dispatch_and_take_back_(struct qb_loop_item * item,
free(sig);
}
-
struct qb_loop_source *
qb_loop_signals_create(struct qb_loop *l)
{
@@ -889,8 +925,7 @@ qb_loop_signals_create(struct qb_loop *l)
(void)qb_util_fd_nonblock_cloexec_set(pipe_fds[1]);
res = _poll_add_(l, QB_LOOP_HIGH,
- pipe_fds[0], POLLIN,
- NULL, &pe);
+ pipe_fds[0], POLLIN, NULL, &pe);
if (res == 0) {
pe->poll_dispatch_fn = NULL;
pe->type = QB_SIGNAL;
@@ -903,13 +938,14 @@ qb_loop_signals_create(struct qb_loop *l)
return (struct qb_loop_source *)s;
- error_exit:
+error_exit:
free(s);
errno = -res;
return NULL;
}
-void qb_loop_signals_destroy(struct qb_loop *l)
+void
+qb_loop_signals_destroy(struct qb_loop *l)
{
close(pipe_fds[0]);
pipe_fds[0] = -1;
@@ -918,10 +954,11 @@ void qb_loop_signals_destroy(struct qb_loop *l)
free(l->signal_source);
}
-static int32_t _qb_signal_add_to_jobs_(struct qb_loop* l,
- struct qb_poll_entry* pe)
+static int32_t
+_qb_signal_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
{
- struct qb_signal_source *s = (struct qb_signal_source *)l->signal_source;
+ struct qb_signal_source *s =
+ (struct qb_signal_source *)l->signal_source;
struct qb_list_head *list;
struct qb_loop_sig *sig;
struct qb_loop_item *item;
@@ -946,14 +983,16 @@ static int32_t _qb_signal_add_to_jobs_(struct qb_loop* l,
memcpy(new_sig_job, sig, sizeof(struct qb_loop_sig));
new_sig_job->cloned_from = sig;
- qb_loop_level_item_add(&l->level[pe->p], &new_sig_job->item);
+ qb_loop_level_item_add(&l->level[pe->p],
+ &new_sig_job->item);
jobs_added++;
}
}
return jobs_added;
}
-static void _adjust_sigactions_(struct qb_signal_source *s)
+static void
+_adjust_sigactions_(struct qb_signal_source *s)
{
struct qb_loop_sig *sig;
struct qb_loop_item *item;
@@ -985,12 +1024,13 @@ static void _adjust_sigactions_(struct qb_signal_source *s)
}
}
-int32_t qb_loop_signal_add(qb_loop_t *l,
- enum qb_loop_priority p,
- int32_t the_sig,
- void *data,
- qb_loop_signal_dispatch_fn dispatch_fn,
- qb_loop_signal_handle *handle)
+int32_t
+qb_loop_signal_add(qb_loop_t * l,
+ enum qb_loop_priority p,
+ int32_t the_sig,
+ void *data,
+ qb_loop_signal_dispatch_fn dispatch_fn,
+ qb_loop_signal_handle * handle)
{
struct qb_loop_sig *sig;
struct qb_signal_source *s;
@@ -1023,12 +1063,13 @@ int32_t qb_loop_signal_add(qb_loop_t *l,
return 0;
}
-int32_t qb_loop_signal_mod(qb_loop_t *l,
- enum qb_loop_priority p,
- int32_t the_sig,
- void *data,
- qb_loop_signal_dispatch_fn dispatch_fn,
- qb_loop_signal_handle handle)
+int32_t
+qb_loop_signal_mod(qb_loop_t * l,
+ enum qb_loop_priority p,
+ int32_t the_sig,
+ void *data,
+ qb_loop_signal_dispatch_fn dispatch_fn,
+ qb_loop_signal_handle handle)
{
struct qb_signal_source *s;
struct qb_loop_sig *sig = (struct qb_loop_sig *)handle;
@@ -1053,8 +1094,8 @@ int32_t qb_loop_signal_mod(qb_loop_t *l,
return 0;
}
-int32_t qb_loop_signal_del(qb_loop_t *l,
- qb_loop_signal_handle handle)
+int32_t
+qb_loop_signal_del(qb_loop_t * l, qb_loop_signal_handle handle)
{
struct qb_loop_sig *sig = (struct qb_loop_sig *)handle;
@@ -1062,5 +1103,3 @@ int32_t qb_loop_signal_del(qb_loop_t *l,
free(sig);
return 0;
}
-
-
diff --git a/lib/loop_timerlist.c b/lib/loop_timerlist.c
index 2792ec9..afdebf4 100644
--- a/lib/loop_timerlist.c
+++ b/lib/loop_timerlist.c
@@ -46,8 +46,8 @@ struct qb_timer_source {
size_t timer_entry_count;
};
-static void timer_dispatch(struct qb_loop_item * item,
- enum qb_loop_priority p)
+static void
+timer_dispatch(struct qb_loop_item *item, enum qb_loop_priority p)
{
struct qb_loop_timer *timer = (struct qb_loop_timer *)item;
@@ -58,7 +58,8 @@ static void timer_dispatch(struct qb_loop_item * item,
}
static int32_t expired_timers;
-static void make_job_from_tmo(void *data)
+static void
+make_job_from_tmo(void *data)
{
struct qb_loop_timer *t = (struct qb_loop_timer *)data;
struct qb_loop *l = t->item.source->l;
@@ -69,7 +70,8 @@ static void make_job_from_tmo(void *data)
expired_timers++;
}
-static int32_t expire_the_timers(struct qb_loop_source* s, int32_t ms_timeout)
+static int32_t
+expire_the_timers(struct qb_loop_source *s, int32_t ms_timeout)
{
struct qb_timer_source *ts = (struct qb_timer_source *)s;
expired_timers = 0;
@@ -77,9 +79,10 @@ static int32_t expire_the_timers(struct qb_loop_source* s, int32_t ms_timeout)
return expired_timers;
}
-int32_t qb_loop_timer_msec_duration_to_expire(struct qb_loop_source *timer_source)
+int32_t
+qb_loop_timer_msec_duration_to_expire(struct qb_loop_source * timer_source)
{
- struct qb_timer_source * my_src = (struct qb_timer_source *)timer_source;
+ struct qb_timer_source *my_src = (struct qb_timer_source *)timer_source;
uint64_t left = timerlist_msec_duration_to_expire(&my_src->timerlist);
if (left != -1 && left > 0xFFFFFFFF) {
left = 0xFFFFFFFE;
@@ -87,10 +90,10 @@ int32_t qb_loop_timer_msec_duration_to_expire(struct qb_loop_source *timer_sourc
return left;
}
-struct qb_loop_source*
+struct qb_loop_source *
qb_loop_timer_create(struct qb_loop *l)
{
- struct qb_timer_source * my_src = malloc(sizeof(struct qb_timer_source));
+ struct qb_timer_source *my_src = malloc(sizeof(struct qb_timer_source));
if (my_src == NULL) {
return NULL;
}
@@ -102,25 +105,27 @@ qb_loop_timer_create(struct qb_loop *l)
my_src->timers = qb_array_create(64, sizeof(struct qb_loop_timer));
my_src->timer_entry_count = 0;
- return (struct qb_loop_source*)my_src;
+ return (struct qb_loop_source *)my_src;
}
-
-void qb_loop_timer_destroy(struct qb_loop *l)
+void
+qb_loop_timer_destroy(struct qb_loop *l)
{
- struct qb_timer_source * my_src = (struct qb_timer_source *)l->timer_source;
+ struct qb_timer_source *my_src =
+ (struct qb_timer_source *)l->timer_source;
qb_array_free(my_src->timers);
free(l->timer_source);
}
-static int32_t _timer_from_handle_(struct qb_timer_source *s,
- qb_loop_timer_handle handle_in,
- struct qb_loop_timer **timer_pt)
+static int32_t
+_timer_from_handle_(struct qb_timer_source *s,
+ qb_loop_timer_handle handle_in,
+ struct qb_loop_timer **timer_pt)
{
int32_t rc;
uint32_t check;
uint32_t install_pos;
- struct qb_loop_timer * timer;
+ struct qb_loop_timer *timer;
if (handle_in == 0) {
return -EINVAL;
@@ -129,7 +134,7 @@ static int32_t _timer_from_handle_(struct qb_timer_source *s,
check = ((uint32_t) (((uint64_t) handle_in) >> 32));
install_pos = handle_in & 0xffffffff;
- rc = qb_array_index(s->timers, install_pos, (void**)&timer);
+ rc = qb_array_index(s->timers, install_pos, (void **)&timer);
if (rc != 0) {
return rc;
}
@@ -140,16 +145,16 @@ static int32_t _timer_from_handle_(struct qb_timer_source *s,
return 0;
}
-
-static int32_t _get_empty_array_position_(struct qb_timer_source * s)
+static int32_t
+_get_empty_array_position_(struct qb_timer_source *s)
{
int32_t install_pos;
int32_t res = 0;
struct qb_loop_timer *timer;
- for (install_pos = 0;
- install_pos < s->timer_entry_count; install_pos++) {
- assert(qb_array_index(s->timers, install_pos, (void**)&timer) == 0);
+ for (install_pos = 0; install_pos < s->timer_entry_count; install_pos++) {
+ assert(qb_array_index(s->timers, install_pos, (void **)&timer)
+ == 0);
if (timer->state == QB_POLL_ENTRY_EMPTY) {
return install_pos;
}
@@ -165,16 +170,16 @@ static int32_t _get_empty_array_position_(struct qb_timer_source * s)
return install_pos;
}
-
-int32_t qb_loop_timer_add(struct qb_loop *l,
- enum qb_loop_priority p,
- uint64_t nsec_duration,
- void *data,
- qb_loop_timer_dispatch_fn timer_fn,
- qb_loop_timer_handle * timer_handle_out)
+int32_t
+qb_loop_timer_add(struct qb_loop * l,
+ enum qb_loop_priority p,
+ uint64_t nsec_duration,
+ void *data,
+ qb_loop_timer_dispatch_fn timer_fn,
+ qb_loop_timer_handle * timer_handle_out)
{
struct qb_loop_timer *t;
- struct qb_timer_source * my_src;
+ struct qb_timer_source *my_src;
int32_t i;
if (l == NULL || timer_fn == NULL) {
@@ -186,11 +191,11 @@ int32_t qb_loop_timer_add(struct qb_loop *l,
}
i = _get_empty_array_position_(my_src);
- assert(qb_array_index(my_src->timers, i, (void**)&t) >= 0);
+ assert(qb_array_index(my_src->timers, i, (void **)&t) >= 0);
t->state = QB_POLL_ENTRY_ACTIVE;
t->install_pos = i;
t->item.user_data = data;
- t->item.source = (struct qb_loop_source*)my_src;
+ t->item.source = (struct qb_loop_source *)my_src;
t->dispatch_fn = timer_fn;
t->p = p;
qb_list_init(&t->item.list);
@@ -206,13 +211,13 @@ int32_t qb_loop_timer_add(struct qb_loop *l,
*timer_handle_out = (((uint64_t) (t->check)) << 32) | t->install_pos;
return timerlist_add_duration(&my_src->timerlist,
make_job_from_tmo, t,
- nsec_duration,
- &t->timerlist_handle);
+ nsec_duration, &t->timerlist_handle);
}
-int32_t qb_loop_timer_del(struct qb_loop *l, qb_loop_timer_handle th)
+int32_t
+qb_loop_timer_del(struct qb_loop * l, qb_loop_timer_handle th)
{
- struct qb_timer_source * s = (struct qb_timer_source *)l->timer_source;
+ struct qb_timer_source *s = (struct qb_timer_source *)l->timer_source;
struct qb_loop_timer *t;
int32_t res;
@@ -238,7 +243,8 @@ int32_t qb_loop_timer_del(struct qb_loop *l, qb_loop_timer_handle th)
return 0;
}
-uint64_t qb_loop_timer_expire_time_get(struct qb_loop *l, qb_loop_timer_handle th)
+uint64_t
+qb_loop_timer_expire_time_get(struct qb_loop * l, qb_loop_timer_handle th)
{
struct qb_timer_source *s = (struct qb_timer_source *)l->timer_source;
struct qb_loop_timer *t;
@@ -253,6 +259,5 @@ uint64_t qb_loop_timer_expire_time_get(struct qb_loop *l, qb_loop_timer_handle t
return 0;
}
- return timerlist_expire_time (&s->timerlist, t->timerlist_handle);
+ return timerlist_expire_time(&s->timerlist, t->timerlist_handle);
}
-
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index 6f56e51..2238485 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -86,7 +86,7 @@ static void qb_rb_chunk_check(qb_ringbuffer_t * rb, uint32_t pointer);
qb_ringbuffer_t *
qb_rb_open(const char *name, size_t size, uint32_t flags,
- size_t shared_user_data_size)
+ size_t shared_user_data_size)
{
struct qb_ringbuffer_s *rb;
size_t real_size;
@@ -101,10 +101,11 @@ qb_rb_open(const char *name, size_t size, uint32_t flags,
long page_size = sysconf(_SC_PAGESIZE);
#ifdef QB_FORCE_SHM_ALIGN
- page_size = QB_MAX(page_size, 16*1024);
+ page_size = QB_MAX(page_size, 16 * 1024);
#endif /* QB_FORCE_SHM_ALIGN */
real_size = QB_ROUNDUP(size, page_size);
- shared_size = sizeof(struct qb_ringbuffer_shared_s) + shared_user_data_size;
+ shared_size =
+ sizeof(struct qb_ringbuffer_shared_s) + shared_user_data_size;
if (flags & QB_RB_FLAG_CREATE) {
file_flags |= O_CREAT | O_TRUNC;
@@ -120,8 +121,7 @@ qb_rb_open(const char *name, size_t size, uint32_t flags,
*/
snprintf(filename, PATH_MAX, "qb-%s-header", name);
fd_hdr = qb_util_mmap_file_open(path, filename,
- shared_size,
- file_flags);
+ shared_size, file_flags);
if (fd_hdr < 0) {
error = fd_hdr;
qb_util_log(LOG_ERR, "couldn't create file for mmap");
@@ -181,8 +181,7 @@ qb_rb_open(const char *name, size_t size, uint32_t flags,
"shm size:%zd; real_size:%zd; rb->size:%d", size,
real_size, rb->shared_hdr->size);
- error = qb_util_circular_mmap(fd_data,
- &shm_addr, real_size);
+ error = qb_util_circular_mmap(fd_data, &shm_addr, real_size);
rb->shared_data = shm_addr;
if (error != 0) {
qb_util_log(LOG_ERR, "couldn't create circular mmap on %s",
@@ -224,7 +223,8 @@ cleanup_hdr:
return NULL;
}
-void qb_rb_close(qb_ringbuffer_t * rb)
+void
+qb_rb_close(qb_ringbuffer_t * rb)
{
if (rb == NULL) {
return;
@@ -240,30 +240,33 @@ void qb_rb_close(qb_ringbuffer_t * rb)
rb->shared_hdr->hdr_path);
} else {
qb_util_log(LOG_DEBUG,
- "Closing ringbuffer: %s",
- rb->shared_hdr->hdr_path);
+ "Closing ringbuffer: %s", rb->shared_hdr->hdr_path);
}
munmap(rb->shared_data, (rb->shared_hdr->size * sizeof(uint32_t)) << 1);
munmap(rb->shared_hdr, sizeof(struct qb_ringbuffer_shared_s));
free(rb);
}
-char *qb_rb_name_get(qb_ringbuffer_t * rb)
+char *
+qb_rb_name_get(qb_ringbuffer_t * rb)
{
return rb->shared_hdr->hdr_path;
}
-void *qb_rb_shared_user_data_get(qb_ringbuffer_t * rb)
+void *
+qb_rb_shared_user_data_get(qb_ringbuffer_t * rb)
{
return rb->shared_hdr->user_data;
}
-int32_t qb_rb_refcount_get(qb_ringbuffer_t * rb)
+int32_t
+qb_rb_refcount_get(qb_ringbuffer_t * rb)
{
return qb_atomic_int_get(&rb->shared_hdr->ref_count);
}
-ssize_t qb_rb_space_free(qb_ringbuffer_t * rb)
+ssize_t
+qb_rb_space_free(qb_ringbuffer_t * rb)
{
uint32_t write_size;
uint32_t read_size;
@@ -288,7 +291,8 @@ ssize_t qb_rb_space_free(qb_ringbuffer_t * rb)
return (space_free * sizeof(uint32_t));
}
-ssize_t qb_rb_space_used(qb_ringbuffer_t * rb)
+ssize_t
+qb_rb_space_used(qb_ringbuffer_t * rb)
{
uint32_t write_size;
uint32_t read_size;
@@ -309,12 +313,14 @@ ssize_t qb_rb_space_used(qb_ringbuffer_t * rb)
return (space_used * sizeof(uint32_t));
}
-ssize_t qb_rb_chunks_used(struct qb_ringbuffer_s * rb)
+ssize_t
+qb_rb_chunks_used(struct qb_ringbuffer_s *rb)
{
return rb->sem_getvalue_fn(rb);
}
-void *qb_rb_chunk_alloc(qb_ringbuffer_t * rb, size_t len)
+void *
+qb_rb_chunk_alloc(qb_ringbuffer_t * rb, size_t len)
{
uint32_t write_pt;
@@ -327,8 +333,7 @@ void *qb_rb_chunk_alloc(qb_ringbuffer_t * rb, size_t len)
qb_rb_chunk_reclaim(rb);
}
} else {
- if (qb_rb_space_free(rb) <
- (len + QB_RB_CHUNK_HEADER_SIZE + 4)) {
+ if (qb_rb_space_free(rb) < (len + QB_RB_CHUNK_HEADER_SIZE + 4)) {
errno = EAGAIN;
return NULL;
}
@@ -350,7 +355,8 @@ void *qb_rb_chunk_alloc(qb_ringbuffer_t * rb, size_t len)
}
-static uint32_t qb_rb_chunk_step(qb_ringbuffer_t * rb, uint32_t pointer)
+static uint32_t
+qb_rb_chunk_step(qb_ringbuffer_t * rb, uint32_t pointer)
{
uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, pointer);
/*
@@ -372,7 +378,8 @@ static uint32_t qb_rb_chunk_step(qb_ringbuffer_t * rb, uint32_t pointer)
return pointer;
}
-int32_t qb_rb_chunk_commit(qb_ringbuffer_t * rb, size_t len)
+int32_t
+qb_rb_chunk_commit(qb_ringbuffer_t * rb, size_t len)
{
uint32_t old_write_pt = rb->shared_hdr->write_pt;
@@ -397,7 +404,8 @@ int32_t qb_rb_chunk_commit(qb_ringbuffer_t * rb, size_t len)
return rb->sem_post_fn(rb);
}
-ssize_t qb_rb_chunk_write(qb_ringbuffer_t * rb, const void *data, size_t len)
+ssize_t
+qb_rb_chunk_write(qb_ringbuffer_t * rb, const void *data, size_t len)
{
char *dest = qb_rb_chunk_alloc(rb, len);
int32_t res = 0;
@@ -416,7 +424,8 @@ ssize_t qb_rb_chunk_write(qb_ringbuffer_t * rb, const void *data, size_t len)
return len;
}
-void qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
+void
+qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
{
uint32_t old_read_pt = rb->shared_hdr->read_pt;
@@ -439,7 +448,8 @@ void qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
rb->shared_hdr->write_pt);
}
-ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t timeout)
+ssize_t
+qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t timeout)
{
uint32_t read_pt;
uint32_t chunk_size;
@@ -505,7 +515,8 @@ qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
return chunk_size;
}
-static void print_header(qb_ringbuffer_t * rb)
+static void
+print_header(qb_ringbuffer_t * rb)
{
printf("Ringbuffer: \n");
if (rb->flags & QB_RB_FLAG_OVERWRITE) {
@@ -522,7 +533,8 @@ static void print_header(qb_ringbuffer_t * rb)
#endif /* S_SPLINT_S */
}
-static void qb_rb_chunk_check(qb_ringbuffer_t * rb, uint32_t pointer)
+static void
+qb_rb_chunk_check(qb_ringbuffer_t * rb, uint32_t pointer)
{
uint32_t chunk_size;
uint32_t chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, pointer);
@@ -536,7 +548,8 @@ static void qb_rb_chunk_check(qb_ringbuffer_t * rb, uint32_t pointer)
}
}
-ssize_t qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd)
+ssize_t
+qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd)
{
ssize_t result;
ssize_t written_size = 0;
@@ -575,7 +588,8 @@ ssize_t qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd)
return written_size;
}
-qb_ringbuffer_t *qb_rb_create_from_file(int32_t fd, uint32_t flags)
+qb_ringbuffer_t *
+qb_rb_create_from_file(int32_t fd, uint32_t flags)
{
ssize_t n_read;
size_t n_required;
@@ -635,13 +649,14 @@ qb_ringbuffer_t *qb_rb_create_from_file(int32_t fd, uint32_t flags)
return rb;
- cleanup_fail:
+cleanup_fail:
free(rb->shared_hdr);
free(rb);
return NULL;
}
-int32_t qb_rb_chown(qb_ringbuffer_t * rb, uid_t owner, gid_t group)
+int32_t
+qb_rb_chown(qb_ringbuffer_t * rb, uid_t owner, gid_t group)
{
int32_t res = chown(rb->shared_hdr->data_path, owner, group);
if (res < 0) {
@@ -653,4 +668,3 @@ int32_t qb_rb_chown(qb_ringbuffer_t * rb, uid_t owner, gid_t group)
}
return 0;
}
-
diff --git a/lib/ringbuffer_helper.c b/lib/ringbuffer_helper.c
index 1e97ed9..5e3be4f 100644
--- a/lib/ringbuffer_helper.c
+++ b/lib/ringbuffer_helper.c
@@ -21,7 +21,8 @@
#include "ringbuffer_int.h"
#include <qb/qbdefs.h>
-static int32_t my_posix_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
+static int32_t
+my_posix_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
{
struct timespec ts_timeout;
int32_t res;
@@ -52,15 +53,15 @@ sem_wait_again:
break;
default:
res = -errno;
- qb_util_perror(LOG_ERR,
- "error waiting for semaphore");
+ qb_util_perror(LOG_ERR, "error waiting for semaphore");
break;
}
}
return res;
}
-static int32_t my_posix_sem_post(qb_ringbuffer_t * rb)
+static int32_t
+my_posix_sem_post(qb_ringbuffer_t * rb)
{
if (sem_post(&rb->shared_hdr->posix_sem) < 0) {
return -errno;
@@ -69,7 +70,8 @@ static int32_t my_posix_sem_post(qb_ringbuffer_t * rb)
}
}
-static ssize_t my_posix_getvalue_fn(struct qb_ringbuffer_s *rb)
+static ssize_t
+my_posix_getvalue_fn(struct qb_ringbuffer_s *rb)
{
int val;
if (sem_getvalue(&rb->shared_hdr->posix_sem, &val) < 0) {
@@ -79,7 +81,8 @@ static ssize_t my_posix_getvalue_fn(struct qb_ringbuffer_s *rb)
}
}
-static int32_t my_posix_sem_destroy(qb_ringbuffer_t * rb)
+static int32_t
+my_posix_sem_destroy(qb_ringbuffer_t * rb)
{
if (sem_destroy(&rb->shared_hdr->posix_sem) == -1) {
return -errno;
@@ -88,7 +91,8 @@ static int32_t my_posix_sem_destroy(qb_ringbuffer_t * rb)
}
}
-static int32_t my_posix_sem_create(struct qb_ringbuffer_s *rb, uint32_t flags)
+static int32_t
+my_posix_sem_create(struct qb_ringbuffer_s *rb, uint32_t flags)
{
int32_t pshared = 0;
if (flags & QB_RB_FLAG_SHARED_PROCESS) {
@@ -105,7 +109,8 @@ static int32_t my_posix_sem_create(struct qb_ringbuffer_s *rb, uint32_t flags)
}
#ifndef HAVE_POSIX_SHARED_SEMAPHORE
-static int32_t my_sysv_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
+static int32_t
+my_sysv_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
{
struct sembuf sops[1];
int32_t res = 0;
@@ -152,15 +157,15 @@ semop_again:
res = -ETIMEDOUT;
} else {
res = -errno;
- qb_util_perror(LOG_ERR,
- "error waiting for semaphore");
+ qb_util_perror(LOG_ERR, "error waiting for semaphore");
}
return res;
}
return 0;
}
-static int32_t my_sysv_sem_post(qb_ringbuffer_t * rb)
+static int32_t
+my_sysv_sem_post(qb_ringbuffer_t * rb)
{
struct sembuf sops[1];
@@ -186,7 +191,8 @@ semop_again:
return 0;
}
-static ssize_t my_sysv_getvalue_fn(struct qb_ringbuffer_s *rb)
+static ssize_t
+my_sysv_getvalue_fn(struct qb_ringbuffer_s *rb)
{
ssize_t res = semctl(rb->sem_id, 0, GETVAL, 0);
if (res == -1) {
@@ -195,7 +201,8 @@ static ssize_t my_sysv_getvalue_fn(struct qb_ringbuffer_s *rb)
return res;
}
-static int32_t my_sysv_sem_destroy(qb_ringbuffer_t * rb)
+static int32_t
+my_sysv_sem_destroy(qb_ringbuffer_t * rb)
{
if (semctl(rb->sem_id, 0, IPC_RMID, 0) == -1) {
return -errno;
@@ -204,7 +211,8 @@ static int32_t my_sysv_sem_destroy(qb_ringbuffer_t * rb)
}
}
-static int32_t my_sysv_sem_create(qb_ringbuffer_t * rb, uint32_t flags)
+static int32_t
+my_sysv_sem_create(qb_ringbuffer_t * rb, uint32_t flags)
{
union semun options;
int32_t res;
@@ -243,7 +251,8 @@ static int32_t my_sysv_sem_create(qb_ringbuffer_t * rb, uint32_t flags)
}
#endif /* NOT HAVE_POSIX_SHARED_SEMAPHORE */
-int32_t qb_rb_sem_create(struct qb_ringbuffer_s * rb, uint32_t flags)
+int32_t
+qb_rb_sem_create(struct qb_ringbuffer_s * rb, uint32_t flags)
{
#ifndef HAVE_POSIX_SHARED_SEMAPHORE
if (rb->flags & QB_RB_FLAG_SHARED_PROCESS) {
@@ -262,4 +271,3 @@ int32_t qb_rb_sem_create(struct qb_ringbuffer_s * rb, uint32_t flags)
return my_posix_sem_create(rb, flags);
}
}
-
diff --git a/lib/util.c b/lib/util.c
index e4b0824..e639a3f 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -36,7 +36,8 @@ struct qb_thread_lock_s {
pthread_mutex_t mutex;
};
-qb_thread_lock_t *qb_thread_lock_create(qb_thread_lock_type_t type)
+qb_thread_lock_t *
+qb_thread_lock_create(qb_thread_lock_type_t type)
{
struct qb_thread_lock_s *tl = malloc(sizeof(struct qb_thread_lock_s));
int32_t res;
@@ -44,7 +45,6 @@ qb_thread_lock_t *qb_thread_lock_create(qb_thread_lock_type_t type)
if (tl == NULL) {
return NULL;
}
-
#ifdef HAVE_PTHREAD_SHARED_SPIN_LOCK
if (type == QB_THREAD_LOCK_SHORT) {
tl->type = QB_THREAD_LOCK_SHORT;
@@ -63,7 +63,8 @@ qb_thread_lock_t *qb_thread_lock_create(qb_thread_lock_type_t type)
}
}
-int32_t qb_thread_lock(qb_thread_lock_t * tl)
+int32_t
+qb_thread_lock(qb_thread_lock_t * tl)
{
int32_t res;
#ifdef HAVE_PTHREAD_SHARED_SPIN_LOCK
@@ -77,7 +78,8 @@ int32_t qb_thread_lock(qb_thread_lock_t * tl)
return res;
}
-int32_t qb_thread_unlock(qb_thread_lock_t * tl)
+int32_t
+qb_thread_unlock(qb_thread_lock_t * tl)
{
int32_t res;
#ifdef HAVE_PTHREAD_SHARED_SPIN_LOCK
@@ -91,7 +93,8 @@ int32_t qb_thread_unlock(qb_thread_lock_t * tl)
return res;
}
-int32_t qb_thread_trylock(qb_thread_lock_t * tl)
+int32_t
+qb_thread_trylock(qb_thread_lock_t * tl)
{
int32_t res;
#ifdef HAVE_PTHREAD_SHARED_SPIN_LOCK
@@ -105,7 +108,8 @@ int32_t qb_thread_trylock(qb_thread_lock_t * tl)
return res;
}
-int32_t qb_thread_lock_destroy(qb_thread_lock_t * tl)
+int32_t
+qb_thread_lock_destroy(qb_thread_lock_t * tl)
{
int32_t res;
#ifdef HAVE_PTHREAD_SHARED_SPIN_LOCK
@@ -120,7 +124,8 @@ int32_t qb_thread_lock_destroy(qb_thread_lock_t * tl)
return res;
}
-void qb_timespec_add_ms(struct timespec *ts, int32_t ms)
+void
+qb_timespec_add_ms(struct timespec *ts, int32_t ms)
{
#ifndef S_SPLINT_S
ts->tv_sec = ms / 1000;
@@ -133,7 +138,8 @@ void qb_timespec_add_ms(struct timespec *ts, int32_t ms)
}
#ifdef HAVE_MONOTONIC_CLOCK
-uint64_t qb_util_nano_current_get(void)
+uint64_t
+qb_util_nano_current_get(void)
{
uint64_t nano_monotonic;
struct timespec ts;
@@ -141,10 +147,12 @@ uint64_t qb_util_nano_current_get(void)
clock_gettime(CLOCK_MONOTONIC, &ts);
nano_monotonic =
- (ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t)ts.tv_nsec;
+ (ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t) ts.tv_nsec;
return (nano_monotonic);
}
-uint64_t qb_util_nano_from_epoch_get(void)
+
+uint64_t
+qb_util_nano_from_epoch_get(void)
{
uint64_t nano_monotonic;
struct timespec ts;
@@ -152,11 +160,12 @@ uint64_t qb_util_nano_from_epoch_get(void)
clock_gettime(CLOCK_REALTIME, &ts);
nano_monotonic =
- (ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t)ts.tv_nsec;
+ (ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t) ts.tv_nsec;
return (nano_monotonic);
}
-uint64_t qb_util_nano_monotonic_hz(void)
+uint64_t
+qb_util_nano_monotonic_hz(void)
{
uint64_t nano_monotonic_hz;
struct timespec ts;
@@ -164,28 +173,31 @@ uint64_t qb_util_nano_monotonic_hz(void)
clock_getres(CLOCK_MONOTONIC, &ts);
nano_monotonic_hz =
- QB_TIME_NS_IN_SEC / ((ts.tv_sec * QB_TIME_NS_IN_SEC) +
- ts.tv_nsec);
+ QB_TIME_NS_IN_SEC / ((ts.tv_sec * QB_TIME_NS_IN_SEC) + ts.tv_nsec);
return (nano_monotonic_hz);
}
-void qb_util_timespec_from_epoch_get(struct timespec *ts)
+void
+qb_util_timespec_from_epoch_get(struct timespec *ts)
{
clock_gettime(CLOCK_REALTIME, ts);
}
#else
-uint64_t qb_util_nano_current_get(void)
+uint64_t
+qb_util_nano_current_get(void)
{
return qb_util_nano_from_epoch_get();
}
-uint64_t qb_util_nano_monotonic_hz(void)
+uint64_t
+qb_util_nano_monotonic_hz(void)
{
return HZ;
}
-void qb_util_timespec_from_epoch_get(struct timespec *ts)
+void
+qb_util_timespec_from_epoch_get(struct timespec *ts)
{
struct timeval time_from_epoch;
gettimeofday(&time_from_epoch, 0);
@@ -196,7 +208,8 @@ void qb_util_timespec_from_epoch_get(struct timespec *ts)
#endif /* S_SPLINT_S */
}
-uint64_t qb_util_nano_from_epoch_get(void)
+uint64_t
+qb_util_nano_from_epoch_get(void)
{
uint64_t nano_from_epoch;
struct timeval time_from_epoch;
@@ -209,7 +222,8 @@ uint64_t qb_util_nano_from_epoch_get(void)
}
#endif
-static int32_t open_mmap_file(char *path, uint32_t file_flags)
+static int32_t
+open_mmap_file(char *path, uint32_t file_flags)
{
if (strstr(path, "XXXXXX") != NULL) {
return mkstemp(path);
@@ -222,8 +236,9 @@ static int32_t open_mmap_file(char *path, uint32_t file_flags)
* ---------------------------------------------------
* shared memory functions.
*/
-int32_t qb_util_mmap_file_open(char *path, const char *file, size_t bytes,
- uint32_t file_flags)
+int32_t
+qb_util_mmap_file_open(char *path, const char *file, size_t bytes,
+ uint32_t file_flags)
{
int32_t fd;
int32_t i;
@@ -257,7 +272,6 @@ int32_t qb_util_mmap_file_open(char *path, const char *file, size_t bytes,
goto unlink_exit;
}
-
if (file_flags & O_CREAT) {
long page_size = sysconf(_SC_PAGESIZE);
if (page_size < 0) {
@@ -271,30 +285,31 @@ int32_t qb_util_mmap_file_open(char *path, const char *file, size_t bytes,
}
for (i = 0; i < (bytes / page_size); i++) {
retry_write:
- written = write (fd, buffer, page_size);
+ written = write(fd, buffer, page_size);
if (written == -1 && errno == EINTR) {
goto retry_write;
}
if (written != page_size) {
res = -ENOSPC;
- free (buffer);
+ free(buffer);
goto unlink_exit;
}
}
- free (buffer);
+ free(buffer);
}
return fd;
unlink_exit:
- unlink (path);
+ unlink(path);
if (fd > 0) {
- close (fd);
+ close(fd);
}
return res;
}
-int32_t qb_util_circular_mmap(int32_t fd, void **buf, size_t bytes)
+int32_t
+qb_util_circular_mmap(int32_t fd, void **buf, size_t bytes)
{
void *addr_orig = NULL;
void *addr;
@@ -350,7 +365,7 @@ int32_t qb_util_circular_mmap(int32_t fd, void **buf, size_t bytes)
*buf = addr_orig;
return 0;
- cleanup_fail:
+cleanup_fail:
if (addr_orig) {
munmap(addr_orig, bytes << 1);
@@ -359,7 +374,8 @@ int32_t qb_util_circular_mmap(int32_t fd, void **buf, size_t bytes)
return res;
}
-int32_t qb_util_fd_nonblock_cloexec_set(int32_t fd)
+int32_t
+qb_util_fd_nonblock_cloexec_set(int32_t fd)
{
int32_t res;
int32_t oldflags = fcntl(fd, F_GETFD, 0);
@@ -379,10 +395,7 @@ int32_t qb_util_fd_nonblock_cloexec_set(int32_t fd)
res = fcntl(fd, F_SETFL, O_NONBLOCK);
if (res == -1) {
res = -errno;
- qb_util_log(LOG_ERR,
- "Could not set non-blocking on fd:%d", fd);
+ qb_util_log(LOG_ERR, "Could not set non-blocking on fd:%d", fd);
}
return res;
}
-
-
--
1.7.5.2
12 years, 9 months
[PATCH 1/2] TEST: add support for services
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/assembly.py | 12 ++++++++++++
tests/deployable.py | 14 +++-----------
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/tests/assembly.py b/tests/assembly.py
index cc6f819..d21bc2a 100644
--- a/tests/assembly.py
+++ b/tests/assembly.py
@@ -26,6 +26,7 @@ class Assembly(FedoraGuest):
def __init__(self, name, number, config, tdl):
self.name = name
self.number = number
+ self.services = {}
tdl_filename = '%s/%d.tdl' % (name, number)
kickstart_filename = '%s/%d.ks' % (name, number)
@@ -46,6 +47,14 @@ class Assembly(FedoraGuest):
def __del__(self):
self.stop()
+ def insert_service_config(self, ass_node):
+ servs = ass_node.newChild(None, "services", None)
+
+ for n, a in self.services.iteritems():
+ srv = servs.newChild(None, 'service', None)
+ srv.setProp("name", n)
+ srv.setProp("monitor_interval", "30s")
+
def rsh(self, command):
if self.guestaddr is None:
retcode = 1
@@ -79,6 +88,9 @@ class Assembly(FedoraGuest):
def ipaddr_get(self):
return self.guestaddr
+ def service_add(self, srv):
+ self.services[srv.name] = srv
+
def start(self):
print '%s fix_network ' % self.name
diff --git a/tests/deployable.py b/tests/deployable.py
index 9eecf36..bbea1c6 100644
--- a/tests/deployable.py
+++ b/tests/deployable.py
@@ -120,7 +120,6 @@ class Deployable(object):
self.name = name
self.uuid = name # TODO
self.assemblies = {}
- self.services = {}
self.cpe = Cpe()
self.l = logging.getLogger()
@@ -131,27 +130,20 @@ class Deployable(object):
def assembly_add(self, ass):
self.assemblies[ass.name] = ass
- def service_add(self, srv):
- self.services[srv.name] = srv
-
def generate_config(self):
doc = libxml2.newDoc("1.0")
dep = doc.newChild(None, "deployable", None)
dep.setProp("name", self.name)
+ dep.setProp("uuid", self.uuid)
asses = dep.newChild(None, "assemblies", None)
- servs = dep.newChild(None, "services", None)
constraints = dep.newChild(None, 'constraints', None)
for n, a in self.assemblies.iteritems():
ass = asses.newChild(None, 'assembly', None)
ass.setProp("name", n)
-# ass.setProp("uuid", 'TODO')
+ ass.setProp("uuid", n) # TODO
ass.setProp("ipaddr", a.ipaddr_get())
-
- for n, a in self.services.iteritems():
- srv = servs.newChild(None, 'service', None)
- srv.setProp("name", n)
- srv.setProp("HA", "True")
+ a.insert_service_config(ass)
open(self.name + '.xml', 'w').write(doc.serialize(None, 1))
doc.freeDoc()
--
1.7.5.2
12 years, 9 months
[PATCH] ipc: don't leak a "struct qb_ipcs_connection" upon successful return
by Jim Meyering
* lib/ipc_us.c (handle_new_connection): Remove unnecessary
initialization of "c".
Don't leak a "struct qb_ipcs_connection" upon successful return.
---
Hi,
coverity spotted this leak.
Here's a fix (that also removes the unneeded init).
lib/ipc_us.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index e21f25d..1ba86e9 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -505,7 +505,7 @@ static int32_t handle_new_connection(struct qb_ipcs_service *s,
void *msg, size_t len,
struct ipc_auth_ugp *ugp)
{
- struct qb_ipcs_connection *c = NULL;
+ struct qb_ipcs_connection *c;
struct qb_ipc_connection_request *req = msg;
int32_t res = auth_result;
struct qb_ipc_connection_response response;
@@ -604,6 +604,7 @@ send_response:
}
qb_ipcs_disconnect(c);
}
+ free(c);
return res;
}
--
1.7.6.rc2.295.gb63f3
12 years, 9 months
resources.test fails
by Dietmar Maurer
resources.test fails if there is some program (running) already using libqb. I guess the check made should be more specific than:
# ls /dev/shm/qb*
and should only include shared memory segments created by test cases (if that is possible)
- Dietmar
12 years, 9 months