[PATCH 1/2] Use SCHED_BATCH only on platforms where available
by Jan Friesse
Signed-off-by: Jan Friesse <jfriesse(a)redhat.com>
---
lib/log_thread.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/log_thread.c b/lib/log_thread.c
index d9939d6..0a908f2 100644
--- a/lib/log_thread.c
+++ b/lib/log_thread.c
@@ -121,7 +121,7 @@ qb_log_thread_priority_set(int32_t policy, int32_t priority)
#ifdef SCHED_IDLE
|| policy == SCHED_IDLE
#endif
-#ifndef QB_DARWIN
+#if defined(SCHED_BATCH) && !defined(QB_DARWIN)
|| policy == SCHED_BATCH
#endif
) {
--
1.7.7.2
12 years
[PATCH 1/4] Try and improve the portability on bsd variants.
by Angus Salkeld
Also add a QB_IPC_NATIVE type that selects the best ipc type available.
Signed-off-by: Angus <angus@anguss-mac-mini>
---
check | 2 +-
configure.ac | 10 +--
examples/ipcserver.c | 2 +-
include/os_base.h | 18 +++--
include/qb/qbipc_common.h | 1 +
lib/Makefile.am | 5 ++
lib/ipc_int.h | 4 --
lib/ipcs.c | 12 +++-
lib/ringbuffer_helper.c | 36 +++++-----
lib/ringbuffer_int.h | 6 +-
lib/rpl_sem.c | 165 +++++++++++++++++++++++++++++++++++++++++++++
lib/rpl_sem.h | 64 ++++++++++++++++++
tests/check_ipc.c | 121 ++++++++++++++++++++-------------
13 files changed, 353 insertions(+), 93 deletions(-)
create mode 100644 lib/rpl_sem.c
create mode 100644 lib/rpl_sem.h
diff --git a/check b/check
index 0fc50b9..3584ef2 100755
--- a/check
+++ b/check
@@ -120,7 +120,7 @@ check_bsd() {
# bsd-like
echo "checking bed"
echo "======================="
- check "ac_cv_func_clock_gettime=no ac_cv_func_epoll_create1=no ac_cv_func_epoll_create=no"
+ check "ac_cv_func_sem_timedwait=no ac_cv_func_clock_gettime=no ac_cv_func_epoll_create1=no ac_cv_func_epoll_create=no"
}
check_mac() {
diff --git a/configure.ac b/configure.ac
index 2ff9fb8..b498c08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -143,18 +143,18 @@ AC_FUNC_MMAP
AC_CHECK_FUNCS([alarm clock_gettime ftruncate gettimeofday localtime localtime_r \
memset munmap socket strchr strrchr strdup strerror strstr \
poll epoll_create epoll_create1 random rand getrlimit sysconf \
- pthread_spin_lock pthread_setschedparam \
+ pthread_spin_lock pthread_setschedparam sem_timedwait \
sched_get_priority_max sched_setscheduler])
+AM_CONDITIONAL(HAVE_SEM_TIMEDWAIT,
+ [test "x$ac_cv_func_sem_timedwait" = xyes])
+
AC_CONFIG_LIBOBJ_DIR(lib)
AC_REPLACE_FUNCS(strlcpy strlcat strchrnul)
## local defines
PACKAGE_FEATURES=""
-if test x$ac_cv_func_timerfd_create = xyes; then
- PACKAGE_FEATURES="$PACKAGE_FEATURES timerfd"
-fi
if test x$ac_cv_func_epoll_create = xyes; then
PACKAGE_FEATURES="$PACKAGE_FEATURES epoll"
fi
@@ -243,7 +243,7 @@ case "$host_os" in
AC_DEFINE_UNQUOTED([QB_BSD], [1],
[Compiling for BSD platform])
AC_DEFINE_UNQUOTED([MAP_ANONYMOUS], [MAP_ANON],
- [Shared memory define for Darwin platform])
+ [Shared memory define for BSD platform])
case "$host_os" in
*freebsd[[234567]]*)
;;
diff --git a/examples/ipcserver.c b/examples/ipcserver.c
index 6e2fc6a..7e62fc7 100644
--- a/examples/ipcserver.c
+++ b/examples/ipcserver.c
@@ -247,7 +247,7 @@ main(int32_t argc, char *argv[])
{
const char *options = "mpsugh";
int32_t opt;
- enum qb_ipc_type ipc_type = QB_IPC_SHM;
+ enum qb_ipc_type ipc_type = QB_IPC_NATIVE;
struct qb_ipcs_service_handlers sh = {
.connection_accept = s1_connection_accept_fn,
.connection_created = s1_connection_created_fn,
diff --git a/include/os_base.h b/include/os_base.h
index 1420fe5..4dd0555 100644
--- a/include/os_base.h
+++ b/include/os_base.h
@@ -112,17 +112,15 @@
* but it really does not. The unistd.h header file is wrong.
*/
#if defined(DISABLE_POSIX_THREAD_PROCESS_SHARED) || defined(__UCLIBC__)
-#undef HAVE_POSIX_SHARED_SEMAPHORE
-#undef HAVE_PTHREAD_SHARED_SPIN_LOCK
+ #undef HAVE_POSIX_SHARED_SEMAPHORE
+ #undef HAVE_PTHREAD_SHARED_SPIN_LOCK
#else
-#if _POSIX_THREAD_PROCESS_SHARED > 0
-#define HAVE_POSIX_SHARED_SEMAPHORE 1
-
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-#define HAVE_PTHREAD_SHARED_SPIN_LOCK 1
-#endif /* HAVE_PTHREAD_SPIN_LOCK */
-
-#endif /* _POSIX_THREAD_PROCESS_SHARED */
+ #if _POSIX_THREAD_PROCESS_SHARED > 0
+ #define HAVE_POSIX_SHARED_SEMAPHORE 1
+ #if defined(HAVE_PTHREAD_SPIN_LOCK)
+ #define HAVE_PTHREAD_SHARED_SPIN_LOCK 1
+ #endif /* HAVE_PTHREAD_SPIN_LOCK */
+ #endif /* _POSIX_THREAD_PROCESS_SHARED */
#endif /* DISABLE_POSIX_THREAD_PROCESS_SHARED */
#ifndef HAVE_STRCHRNUL
diff --git a/include/qb/qbipc_common.h b/include/qb/qbipc_common.h
index 269de56..0a4118c 100644
--- a/include/qb/qbipc_common.h
+++ b/include/qb/qbipc_common.h
@@ -47,6 +47,7 @@ enum qb_ipc_type {
QB_IPC_SHM,
QB_IPC_POSIX_MQ,
QB_IPC_SYSV_MQ,
+ QB_IPC_NATIVE,
};
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 14a00a8..dec3d28 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -56,6 +56,11 @@ if HAVE_POSIX_MQ
libqb_la_SOURCES+=ipc_posix_mq.c
endif
+if HAVE_SEM_TIMEDWAIT
+else
+ libqb_la_SOURCES+=rpl_sem.c
+endif
+
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libqb.pc
diff --git a/lib/ipc_int.h b/lib/ipc_int.h
index 16bc5c7..62559bd 100644
--- a/lib/ipc_int.h
+++ b/lib/ipc_int.h
@@ -35,10 +35,6 @@
#include <qb/qbipc_common.h>
#include <qb/qbrb.h>
-#ifdef HAVE_POSIX_SHARED_SEMAPHORE
-#include <semaphore.h>
-#endif /* HAVE_POSIX_SHARED_SEMAPHORE */
-
#define QB_IPC_MAX_WAIT_MS 2000
/*
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 5f5560f..49c995f 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -42,9 +42,15 @@ qb_ipcs_create(const char *name,
if (s == NULL) {
return NULL;
}
+ if (type == QB_IPC_NATIVE) {
+#ifdef HAVE_SEM_TIMEDWAIT
+ s->type = QB_IPC_SHM;
+#else
+ s->type = QB_IPC_SOCKET;
+#endif /* HAVE_SEM_TIMEDWAIT */
+ }
s->pid = getpid();
- s->type = type;
s->needs_sock_for_poll = QB_FALSE;
s->poll_priority = QB_LOOP_MED;
s->ref_count = 1;
@@ -91,7 +97,11 @@ qb_ipcs_run(struct qb_ipcs_service *s)
qb_ipcs_us_init((struct qb_ipcs_service *)s);
break;
case QB_IPC_SHM:
+#ifdef HAVE_SEM_TIMEDWAIT
qb_ipcs_shm_init((struct qb_ipcs_service *)s);
+#else
+ res = -ENOTSUP;
+#endif /* HAVE_SEM_TIMEDWAIT */
break;
case QB_IPC_POSIX_MQ:
#ifdef HAVE_POSIX_MQ
diff --git a/lib/ringbuffer_helper.c b/lib/ringbuffer_helper.c
index 4634771..f66d9bf 100644
--- a/lib/ringbuffer_helper.c
+++ b/lib/ringbuffer_helper.c
@@ -34,11 +34,11 @@ my_posix_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
sem_wait_again:
if (ms_timeout > 0) {
- res = sem_timedwait(&rb->shared_hdr->posix_sem, &ts_timeout);
+ res = rpl_sem_timedwait(&rb->shared_hdr->posix_sem, &ts_timeout);
} else if (ms_timeout == 0) {
- res = sem_trywait(&rb->shared_hdr->posix_sem);
+ res = rpl_sem_trywait(&rb->shared_hdr->posix_sem);
} else {
- res = sem_wait(&rb->shared_hdr->posix_sem);
+ res = rpl_sem_wait(&rb->shared_hdr->posix_sem);
}
if (res == -1) {
switch (errno) {
@@ -63,7 +63,7 @@ sem_wait_again:
static int32_t
my_posix_sem_post(qb_ringbuffer_t * rb)
{
- if (sem_post(&rb->shared_hdr->posix_sem) < 0) {
+ if (rpl_sem_post(&rb->shared_hdr->posix_sem) < 0) {
return -errno;
} else {
return 0;
@@ -74,7 +74,7 @@ static ssize_t
my_posix_getvalue_fn(struct qb_ringbuffer_s *rb)
{
int val;
- if (sem_getvalue(&rb->shared_hdr->posix_sem, &val) < 0) {
+ if (rpl_sem_getvalue(&rb->shared_hdr->posix_sem, &val) < 0) {
return -errno;
} else {
return val;
@@ -84,7 +84,7 @@ my_posix_getvalue_fn(struct qb_ringbuffer_s *rb)
static int32_t
my_posix_sem_destroy(qb_ringbuffer_t * rb)
{
- if (sem_destroy(&rb->shared_hdr->posix_sem) == -1) {
+ if (rpl_sem_destroy(&rb->shared_hdr->posix_sem) == -1) {
return -errno;
} else {
return 0;
@@ -101,14 +101,13 @@ my_posix_sem_create(struct qb_ringbuffer_s *rb, uint32_t flags)
}
pshared = 1;
}
- if (sem_init(&rb->shared_hdr->posix_sem, pshared, 0) == -1) {
+ if (rpl_sem_init(&rb->shared_hdr->posix_sem, pshared, 0) == -1) {
return -errno;
} else {
return 0;
}
}
-#ifndef HAVE_POSIX_SHARED_SEMAPHORE
static int32_t
my_sysv_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
{
@@ -249,25 +248,24 @@ my_sysv_sem_create(qb_ringbuffer_t * rb, uint32_t flags)
return res;
}
-#endif /* NOT HAVE_POSIX_SHARED_SEMAPHORE */
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) {
+ int32_t rc;
+
+ rc = my_posix_sem_create(rb, flags);
+ if (rc == 0) {
+ rb->sem_timedwait_fn = my_posix_sem_timedwait;
+ rb->sem_post_fn = my_posix_sem_post;
+ rb->sem_getvalue_fn = my_posix_getvalue_fn;
+ rb->sem_destroy_fn = my_posix_sem_destroy;
+ } else {
rb->sem_timedwait_fn = my_sysv_sem_timedwait;
rb->sem_post_fn = my_sysv_sem_post;
rb->sem_getvalue_fn = my_sysv_getvalue_fn;
rb->sem_destroy_fn = my_sysv_sem_destroy;
return my_sysv_sem_create(rb, flags);
- } else
-#endif /* NOT HAVE_POSIX_SHARED_SEMAPHORE */
- {
- rb->sem_timedwait_fn = my_posix_sem_timedwait;
- rb->sem_post_fn = my_posix_sem_post;
- rb->sem_getvalue_fn = my_posix_getvalue_fn;
- rb->sem_destroy_fn = my_posix_sem_destroy;
- return my_posix_sem_create(rb, flags);
}
+ return rc;
}
diff --git a/lib/ringbuffer_int.h b/lib/ringbuffer_int.h
index 3a7f22d..35283c7 100644
--- a/lib/ringbuffer_int.h
+++ b/lib/ringbuffer_int.h
@@ -32,9 +32,7 @@
#ifdef HAVE_SYS_IPC_H
#include <sys/ipc.h>
#endif
-#include <pthread.h>
-#include <semaphore.h>
-
+#include "rpl_sem.h"
#include "util_int.h"
#include <qb/qbutil.h>
#include <qb/qbrb.h>
@@ -55,7 +53,7 @@ struct qb_ringbuffer_shared_s {
char hdr_path[PATH_MAX];
char data_path[PATH_MAX];
int32_t ref_count;
- sem_t posix_sem;
+ rpl_sem_t posix_sem;
char user_data[1];
};
diff --git a/lib/rpl_sem.c b/lib/rpl_sem.c
new file mode 100644
index 0000000..cdc005c
--- /dev/null
+++ b/lib/rpl_sem.c
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement.
+ * Contributors retain copyright to elements licensed under a Contributor Agreement.
+ * Licensed to the User under the LGPL license.
+ *
+ * Modified by: Angus Salkeld <asalkeld(a)redhat.com>
+ * Copyright (C) 2012 Red Hat, Inc.
+ * To conform to posix API and support process shared semaphores.
+ *
+ * The bsd posix semaphore implementation does not have support for timing
+ * out while waiting for a synchronization object. This uses the
+ * pthread_cond_timedwait function and a mutex to build all the other
+ * synchronization objecs with timeout capabilities.
+ */
+
+#include "os_base.h"
+#include <pthread.h>
+#include "rpl_sem.h"
+
+int
+rpl_sem_init(rpl_sem_t * sem, int pshared, unsigned int count)
+{
+ int rc;
+ pthread_mutexattr_t mattr;
+ pthread_condattr_t cattr;
+
+#if defined(DISABLE_POSIX_THREAD_PROCESS_SHARED)
+ if (pshared) {
+ errno = ENOSYS;
+ return -1;
+ }
+#endif
+ sem->count = count;
+
+ (void)pthread_mutexattr_init(&mattr);
+ (void)pthread_condattr_init(&cattr);
+ if (pshared) {
+ rc = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
+ if (rc != 0) {
+ goto cleanup;
+ }
+ rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
+ if (rc != 0) {
+ goto cleanup;
+ }
+ }
+ rc = pthread_mutex_init(&sem->mutex, &mattr);
+ if (rc != 0) {
+ goto cleanup;
+ }
+ rc = pthread_cond_init(&sem->cond, &cattr);
+
+ if (rc != 0) {
+ goto cleanup_mutex;
+ }
+ return 0;
+
+cleanup_mutex:
+ pthread_mutex_destroy(&sem->mutex);
+
+cleanup:
+ pthread_mutexattr_destroy(&mattr);
+ pthread_condattr_destroy(&cattr);
+ return rc;
+}
+
+int
+rpl_sem_wait(rpl_sem_t * sem)
+{
+ int retval = 0;
+
+ pthread_mutex_lock(&sem->mutex);
+
+ /* wait for sem->count to be not zero, or error
+ */
+ while (retval == 0 && !sem->count) {
+ retval = pthread_cond_wait(&sem->cond, &sem->mutex);
+ }
+ switch (retval) {
+ case 0:
+ /* retval is 0 and sem->count is not, the sem is ours
+ */
+ sem->count--;
+ break;
+
+ default:
+ errno = retval;
+ retval = -1;
+ }
+
+ pthread_mutex_unlock(&sem->mutex);
+ return retval;
+}
+
+int
+rpl_sem_timedwait(rpl_sem_t * sem, const struct timespec *timeout)
+{
+ int retval = 0;
+ pthread_mutex_lock(&sem->mutex);
+
+ /* wait for sem->count to be not zero, or error
+ */
+ while (0 == retval && !sem->count) {
+ retval = pthread_cond_timedwait(&sem->cond, &sem->mutex, timeout);
+ }
+
+ switch (retval) {
+ case 0:
+ /* retval is 0 and sem->count is not, the sem is ours
+ */
+ sem->count--;
+ break;
+
+ case ETIMEDOUT:
+ /* timedout waiting for count to be not zero
+ */
+ errno = EAGAIN;
+ retval = -1;
+ break;
+
+ default:
+ errno = retval;
+ retval = -1;
+ }
+ pthread_mutex_unlock(&sem->mutex);
+ return retval;
+}
+
+int
+rpl_sem_trywait(rpl_sem_t * sem)
+{
+ pthread_mutex_lock(&sem->mutex);
+ if (sem->count) {
+ sem->count--;
+ pthread_mutex_unlock(&sem->mutex);
+ return 0;
+ }
+ errno = EAGAIN;
+ pthread_mutex_unlock(&sem->mutex);
+ return -1;
+}
+
+int
+rpl_sem_post(rpl_sem_t * sem)
+{
+ pthread_mutex_lock(&sem->mutex);
+ sem->count++;
+ pthread_cond_broadcast(&sem->cond);
+ pthread_mutex_unlock(&sem->mutex);
+ return 0;
+}
+
+int
+rpl_sem_getvalue(rpl_sem_t * sem, int *sval)
+{
+ *sval = sem->count;
+ return 0;
+}
+
+int
+rpl_sem_destroy(rpl_sem_t * sem)
+{
+ return pthread_mutex_destroy(&sem->mutex) |
+ pthread_cond_destroy(&sem->cond);
+}
diff --git a/lib/rpl_sem.h b/lib/rpl_sem.h
new file mode 100644
index 0000000..23724e4
--- /dev/null
+++ b/lib/rpl_sem.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement.
+ * Contributors retain copyright to elements licensed under a Contributor Agreement.
+ * Licensed to the User under the LGPL license.
+ *
+ * Modified by: Angus Salkeld <asalkeld(a)redhat.com>
+ * Copyright (C) 2012 Red Hat, Inc.
+ * To conform to official implementation and support process shared semaphores.
+ *
+ * The bsd posix semaphore implementation does not have support for timing
+ * out while waiting for a synchronization object. This uses the
+ * pthread_cond_timedwait function and a mutex to build all the other
+ * synchronization objecs with timeout capabilities.
+ */
+
+#ifndef _RPL_SEM_H
+#define _RPL_SEM_H
+
+#include "os_base.h"
+#include <pthread.h>
+#include <semaphore.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_SEM_TIMEDWAIT
+#define rpl_sem_t sem_t
+#define rpl_sem_init sem_init
+#define rpl_sem_wait sem_wait
+#define rpl_sem_timedwait sem_timedwait
+#define rpl_sem_post sem_post
+#define rpl_sem_getvalue sem_getvalue
+#define rpl_sem_destroy sem_destroy
+#define rpl_sem_trywait sem_trywait
+#else
+
+typedef struct rpl_sem {
+ unsigned int count;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+} rpl_sem_t;
+
+int rpl_sem_init(rpl_sem_t * sem, int pshared, unsigned int count);
+
+int rpl_sem_wait(rpl_sem_t *sem);
+
+int rpl_sem_timedwait(rpl_sem_t *sem,const struct timespec *timeout);
+
+int rpl_sem_trywait(rpl_sem_t *sem);
+
+int rpl_sem_post(rpl_sem_t *sem);
+
+int rpl_sem_getvalue(rpl_sem_t * sem, int *sval);
+
+int rpl_sem_destroy(rpl_sem_t *sem);
+
+#endif /* HAVE_SEM_TIMEDWAIT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RPL_SEM_H */
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index 87c5a48..8e0d3a3 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -21,12 +21,8 @@
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
+#include "os_base.h"
#include <sys/wait.h>
-#include <errno.h>
#include <signal.h>
#include <check.h>
@@ -312,9 +308,12 @@ test_ipc_txrx(void)
static void
test_ipc_exit(void)
{
+ struct qb_ipc_request_header req_header;
+ struct qb_ipc_response_header res_header;
+ struct iovec iov[1];
+ int32_t res;
int32_t c = 0;
int32_t j = 0;
- int32_t rc = 0;
pid_t pid;
pid = run_function_in_new_process(run_ipc_server);
@@ -332,9 +331,16 @@ test_ipc_exit(void)
} while (conn == NULL && c < 5);
fail_if(conn == NULL);
- /* confirm we can send one message */
- rc = send_and_check(100, recv_timeout, QB_TRUE);
- _ck_assert_int(rc, >=, 0);
+ req_header.id = IPC_MSG_REQ_TX_RX;
+ req_header.size = sizeof(struct qb_ipc_request_header);
+
+ iov[0].iov_len = req_header.size;
+ iov[0].iov_base = &req_header;
+
+ res = qb_ipcc_sendv_recv(conn, iov, 1,
+ &res_header,
+ sizeof(struct qb_ipc_response_header), -1);
+ ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header));
/* kill the server */
stop_process(pid);
@@ -350,7 +356,16 @@ test_ipc_exit(void)
qb_ipcc_disconnect(conn);
}
+START_TEST(test_ipc_exit_us)
+{
+ ipc_type = QB_IPC_SOCKET;
+ ipc_name = __func__;
+ recv_timeout = 5000;
+ test_ipc_exit();
+}
+END_TEST
+#ifdef HAVE_SEM_TIMEDWAIT
START_TEST(test_ipc_exit_shm)
{
ipc_type = QB_IPC_SHM;
@@ -380,32 +395,33 @@ START_TEST(test_ipc_txrx_shm_block)
}
END_TEST
-START_TEST(test_ipc_txrx_us_block)
+START_TEST(test_ipc_fc_shm)
{
- turn_on_fc = QB_FALSE;
- ipc_type = QB_IPC_SOCKET;
+ turn_on_fc = QB_TRUE;
+ ipc_type = QB_IPC_SHM;
+ recv_timeout = 500;
ipc_name = __func__;
- recv_timeout = -1;
test_ipc_txrx();
}
END_TEST
+#endif /* HAVE_SEM_TIMEDWAIT */
-START_TEST(test_ipc_txrx_us_tmo)
+START_TEST(test_ipc_txrx_us_block)
{
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
- recv_timeout = 1000;
+ recv_timeout = -1;
test_ipc_txrx();
}
END_TEST
-START_TEST(test_ipc_fc_shm)
+START_TEST(test_ipc_txrx_us_tmo)
{
- turn_on_fc = QB_TRUE;
- ipc_type = QB_IPC_SHM;
- recv_timeout = 500;
+ turn_on_fc = QB_FALSE;
+ ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
+ recv_timeout = 1000;
test_ipc_txrx();
}
END_TEST
@@ -503,14 +519,6 @@ test_ipc_dispatch(void)
stop_process(pid);
}
-START_TEST(test_ipc_disp_shm)
-{
- ipc_type = QB_IPC_SHM;
- ipc_name = __func__;
- test_ipc_dispatch();
-}
-END_TEST
-
START_TEST(test_ipc_disp_us)
{
ipc_type = QB_IPC_SOCKET;
@@ -574,6 +582,15 @@ START_TEST(test_ipc_server_fail_soc)
}
END_TEST
+#ifdef HAVE_SEM_TIMEDWAIT
+START_TEST(test_ipc_disp_shm)
+{
+ ipc_type = QB_IPC_SHM;
+ ipc_name = __func__;
+ test_ipc_dispatch();
+}
+END_TEST
+
START_TEST(test_ipc_server_fail_shm)
{
ipc_type = QB_IPC_SHM;
@@ -581,6 +598,7 @@ START_TEST(test_ipc_server_fail_shm)
test_ipc_server_fail();
}
END_TEST
+#endif /* HAVE_SEM_TIMEDWAIT */
static Suite *
ipc_suite(void)
@@ -589,16 +607,12 @@ ipc_suite(void)
uid_t uid;
Suite *s = suite_create("ipc");
+#ifdef HAVE_SEM_TIMEDWAIT
tc = tcase_create("ipc_server_fail_shm");
tcase_add_test(tc, test_ipc_server_fail_shm);
tcase_set_timeout(tc, 6);
suite_add_tcase(s, tc);
- tc = tcase_create("ipc_server_fail_soc");
- tcase_add_test(tc, test_ipc_server_fail_soc);
- tcase_set_timeout(tc, 6);
- suite_add_tcase(s, tc);
-
tc = tcase_create("ipc_txrx_shm_block");
tcase_add_test(tc, test_ipc_txrx_shm_block);
tcase_set_timeout(tc, 6);
@@ -609,6 +623,27 @@ ipc_suite(void)
tcase_set_timeout(tc, 6);
suite_add_tcase(s, tc);
+ tc = tcase_create("ipc_fc_shm");
+ tcase_add_test(tc, test_ipc_fc_shm);
+ tcase_set_timeout(tc, 6);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("ipc_dispatch_shm");
+ tcase_add_test(tc, test_ipc_disp_shm);
+ tcase_set_timeout(tc, 16);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("ipc_exit_shm");
+ tcase_add_test(tc, test_ipc_exit_shm);
+ tcase_set_timeout(tc, 3);
+ suite_add_tcase(s, tc);
+#endif /* HAVE_SEM_TIMEDWAIT */
+
+ tc = tcase_create("ipc_server_fail_soc");
+ tcase_add_test(tc, test_ipc_server_fail_soc);
+ tcase_set_timeout(tc, 6);
+ suite_add_tcase(s, tc);
+
tc = tcase_create("ipc_txrx_us_block");
tcase_add_test(tc, test_ipc_txrx_us_block);
tcase_set_timeout(tc, 6);
@@ -619,16 +654,16 @@ ipc_suite(void)
tcase_set_timeout(tc, 6);
suite_add_tcase(s, tc);
- tc = tcase_create("ipc_fc_shm");
- tcase_add_test(tc, test_ipc_fc_shm);
- tcase_set_timeout(tc, 6);
- suite_add_tcase(s, tc);
-
tc = tcase_create("ipc_fc_us");
tcase_add_test(tc, test_ipc_fc_us);
tcase_set_timeout(tc, 6);
suite_add_tcase(s, tc);
+ tc = tcase_create("ipc_exit_us");
+ tcase_add_test(tc, test_ipc_exit_us);
+ tcase_set_timeout(tc, 3);
+ suite_add_tcase(s, tc);
+
uid = geteuid();
if (uid == 0) {
tc = tcase_create("ipc_txrx_posix_mq");
@@ -641,21 +676,11 @@ ipc_suite(void)
tcase_set_timeout(tc, 10);
suite_add_tcase(s, tc);
}
- tc = tcase_create("ipc_dispatch_shm");
- tcase_add_test(tc, test_ipc_disp_shm);
- tcase_set_timeout(tc, 16);
- suite_add_tcase(s, tc);
-
tc = tcase_create("ipc_dispatch_us");
tcase_add_test(tc, test_ipc_disp_us);
tcase_set_timeout(tc, 16);
suite_add_tcase(s, tc);
- tc = tcase_create("ipc_exit_shm");
- tcase_add_test(tc, test_ipc_exit_shm);
- tcase_set_timeout(tc, 3);
- suite_add_tcase(s, tc);
-
return s;
}
@@ -670,7 +695,7 @@ main(void)
qb_log_init("check", LOG_USER, LOG_EMERG);
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
- QB_LOG_FILTER_FILE, "*", LOG_INFO);
+ QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
srunner_run_all(sr, CK_VERBOSE);
--
1.7.9.3
12 years
Test fail report
by Andrew Eross
Hi,
Just thought I'd share, as requested by the build program.
Building from a nearly clean Debian Squeeze 32-bit while building proxmox:
gcc -DHAVE_CONFIG_H -I. -I../include -I../include/qb -I../include
-I../include -I../include -fPIC -Wall -Wshadow -Wmissing-prototypes
-Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement
-Wpointer-arith -Wwrite-strings -Wcast-align -Wbad-function-cast
-Wmissing-format-attribute -Wformat=2 -Wformat-security
-Wno-format-nonliteral -Wno-long-long -Wno-strict-aliasing -c -o
util_test-check_util.o `test -f 'check_util.c' || echo './'`check_util.c
CCLD util.test
make[5]: Nothing to be done for `resources.test'.
make[5]: Leaving directory
`/home/superfrog/proxmox32/libqb/libqb-0.10.1/tests'
make check-TESTS
make[5]: Entering directory
`/home/superfrog/proxmox32/libqb/libqb-0.10.1/tests'
make[6]: Entering directory
`/home/superfrog/proxmox32/libqb/libqb-0.10.1/tests'
PASS: array.test
PASS: map.test
PASS: util.test
PASS: rb.test
PASS: log.test
PASS: loop.test
FAIL: ipc.test
FAIL: resources.test
===================================================
2 of 8 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
`/home/superfrog/proxmox32/libqb/libqb-0.10.1/tests'
make[5]: *** [check-TESTS] Error 2
make[5]: Leaving directory
`/home/superfrog/proxmox32/libqb/libqb-0.10.1/tests'
make[4]: *** [check-am] Error 2
make[4]: Leaving directory
`/home/superfrog/proxmox32/libqb/libqb-0.10.1/tests'
make[3]: *** [check-recursive] Error 1
make[3]: Leaving directory `/home/superfrog/proxmox32/libqb/libqb-0.10.1'
make[2]: *** [check] Error 2
make[2]: Leaving directory `/home/superfrog/proxmox32/libqb/libqb-0.10.1'
dh_auto_test: make -j1 check returned exit code 2
make[1]: *** [build] Error 29
make[1]: Leaving directory `/home/superfrog/proxmox32/libqb/libqb-0.10.1'
dpkg-buildpackage: error: debian/rules build gave error exit status 2
make: *** [libqb_0.10.1-2_i386.deb] Error 2
superfrog@cs03:~/proxmox32/libqb/libqb-0.10.1/tests$ cat test-suite.log
================================================
libqb 0.10.1.4-b298e: tests/test-suite.log
================================================
2 of 8 tests failed.
.. contents:: :depth: 2
FAIL: ipc.test (exit: 1)
========================
Running suite(s): ipc
[info] server name: test_ipc_server_fail_shm
[info] IPC credentials authenticated
[info] server name: test_ipc_server_fail_soc
[info] IPC credentials authenticated
[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] qb_ipcc_send: Resource temporarily unavailable (11)
[info] server name: test_ipc_fc_us
[info] IPC credentials authenticated
[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)
[info] server name: test_ipc_exit_shm
[info] IPC credentials authenticated
90%: Checks: 11, Failures: 0, Errors: 1
check_ipc.c:563:P:ipc_server_fail_shm:test_ipc_server_fail_shm:0: Passed
check_ipc.c:563:P:ipc_server_fail_soc:test_ipc_server_fail_soc:0: Passed
check_ipc.c:282:P:ipc_txrx_shm_block:test_ipc_txrx_shm_block:0: Passed
check_ipc.c:282:P:ipc_txrx_shm_tmo:test_ipc_txrx_shm_tmo:0: Passed
check_ipc.c:282:P:ipc_txrx_us_block:test_ipc_txrx_us_block:0: Passed
check_ipc.c:282:P:ipc_txrx_us_tmo:test_ipc_txrx_us_tmo:0: Passed
check_ipc.c:282:P:ipc_fc_shm:test_ipc_fc_shm:0: Passed
check_ipc.c:282:P:ipc_fc_us:test_ipc_fc_us:0: Passed
check_ipc.c:457:P:ipc_dispatch_shm:test_ipc_disp_shm:0: Passed
check_ipc.c:469:E:ipc_dispatch_us:test_ipc_disp_us:0: (after this point)
Test timeout expired
check_ipc.c:337:P:ipc_exit_shm:test_ipc_exit_shm:0: Passed
FAIL: resources.test (exit: 1)
==============================
/dev/shm/qb-test_ipc_disp_us-control-5594-8
Error: shared memory segments not closed/unlinked
Cheers,
Andrew
Andrew Eross
CTO
Locatrix Communications
Office: +61 7 3123 1469
Mobile: +55 11 8654 7834
eross(a)locatrix.com
12 years, 1 month
[PATCH 1/9] TIMER: check for null timer handle
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/loop_timerlist.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/loop_timerlist.c b/lib/loop_timerlist.c
index 722f29b..f4d32fb 100644
--- a/lib/loop_timerlist.c
+++ b/lib/loop_timerlist.c
@@ -248,7 +248,9 @@ qb_loop_timer_del(struct qb_loop * lp, qb_loop_timer_handle th)
qb_loop_level_item_del(&l->level[t->p], &t->item);
}
- timerlist_del(&s->timerlist, t->timerlist_handle);
+ if (t->timerlist_handle) {
+ timerlist_del(&s->timerlist, t->timerlist_handle);
+ }
t->state = QB_POLL_ENTRY_EMPTY;
return 0;
}
--
1.7.9.1
12 years, 1 month
ANNOUNCE libqb version 0.11.0
by Angus Salkeld
Hi all
New release time! This has a bunch of bug fixes and performance
improvements.
Get all the goodies here:
https://github.com/asalkeld/libqb/wiki#wiki-Releases
-Angus
ARRAY: cleanup the pointer sizeof()
LOG: turn off __attribute__(section) for powerpc (not working)
TESTS: move the util tests into "slow-tests" (i.e. optional)
TEST: make the test_priority the same type as in the callsite
LOG: make the log arrays manually grow-able since we need to lock the calls.
RB: fix test failure on ppc
RB: change the name of the size to word_size to be more clear
TEST: add some more signal tests.
LOOP: fix deletion of signal handlers when they are pending
LOOP: signal handlers were always added as high priority.
TEST: deal with mac's limited sed
check: add debugging to the configure options and remove unused options
TEST: properly clear the filters
LOG: expose the mechanism to get a dynamic callsite.
Revert part of my COARSE grained timer commit
Remove timerfd usage and go back to timelist.
UTIL: if possible use COARSE resolution clocks - they are much faster.
ARRAY: save memory (in the bins array) and allow holes in the array
LOOP: add qb_loop_timer_is_running()
LOOP: allow stop() and run() to be called with NULL loop instance.
LOOP: fix doxygen parameter comment
LOG: add stdout target
LOOP: add a function to delete jobs
LOG: remove debug printf's
LOG: remove an old/incorrect doxygen comment.
LOG: add a hostname %H format specifier.
LOG: Add qb_log_filter_fn_set()
12 years, 1 month
[PATCH 1/2] LOG: turn off __attribute__(section) for powerpc (not working)
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
configure.ac | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 53b7abf..2ff9fb8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -177,6 +177,7 @@ case $host_cpu in
powerpc*)
AC_MSG_RESULT([powerpc])
AC_DEFINE_UNQUOTED([QB_ARCH_POWERPC], [1], [powerpc])
+ ac_cv_link_attribute_section=no
nongcc_memory_barrier_needed=yes
arch_force_shmlba=yes
;;
--
1.7.9.1
12 years, 1 month
[PATCH] TESTS: move the util tests into "slow-tests" (i.e. optional)
by Angus Salkeld
So this this test is timing sensitive and can easily fail on slow
build farm machines. So I have enabled it on the --enable-slow-tests
configure option and put this into ./check as the default.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
check | 5 +++--
tests/Makefile.am | 7 ++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/check b/check
index b3b1c61..0fc50b9 100755
--- a/check
+++ b/check
@@ -60,10 +60,11 @@ then
fi
check() {
- echo "./configure $1 --enable-debug --enable-fatal-warnings --quiet"
+ options="$1 --enable-debug --enable-slow-tests --enable-fatal-warnings --quiet"
+ echo "./configure $options"
echo "ENV CFLAGS=\"$CFLAGS\""
echo "ENV MAKEFLAGS=\"$MAKEFLAGS\""
- ( ./configure $1 --enable-debug --enable-fatal-warnings --quiet )
+ ( ./configure $options )
make check
if [ $? -ne 0 ]
then
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5fdf3b2..c77f7bc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -89,13 +89,18 @@ bench_log_LDADD = $(LIB_RT) $(top_builddir)/lib/libqb.la
if HAVE_CHECK
EXTRA_DIST += resources.test
-TESTS = array.test map.test util.test rb.test log.test loop.test ipc.test resources.test
+TESTS = array.test map.test rb.test log.test loop.test ipc.test resources.test
resources.log: rb.log log.log ipc.log
check_PROGRAMS = array.test map.test rb.test log.test loop.test ipc.test util.test
check_SCRIPTS = resources.test
+if HAVE_SLOW_TESTS
+TESTS += util.test
+check_PROGRAMS += util.test
+endif
+
array_test_SOURCES = check_array.c $(top_builddir)/include/qb/qbarray.h
array_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include
array_test_LDADD = $(top_builddir)/lib/libqb.la $(LIB_RT) @CHECK_LIBS@
--
1.7.9.1
12 years, 1 month
[PATCH 1/2] LOG: make the log arrays manually grow-able since we need to lock the calls.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log_dcs.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
index dde7c60..303ce55 100644
--- a/lib/log_dcs.c
+++ b/lib/log_dcs.c
@@ -78,6 +78,8 @@ _log_dcs_new_cs(const char *function,
int32_t call_register = QB_FALSE;
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);
assert(rc == 0);
@@ -125,8 +127,7 @@ 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);
- assert(rc == 0);
- if (csl_head->cs &&
+ if (rc == 0 && csl_head->cs &&
format == csl_head->cs->format &&
priority == csl_head->cs->priority &&
strcmp(safe_filename, csl_head->cs->filename) == 0) {
@@ -136,6 +137,12 @@ qb_log_dcs_get(int32_t * newly_created,
* so we will either have to create it or go through a list, so lock it.
*/
(void)qb_thread_lock(arr_next_lock);
+ if (rc < 0) {
+ rc = qb_array_grow(lookup_arr, lineno + 255);
+ assert(rc == 0);
+ rc = qb_array_index(lookup_arr, lineno, (void **)&csl_head);
+ assert(rc == 0);
+ }
if (csl_head->cs == NULL) {
csl_head->cs = _log_dcs_new_cs(safe_function, safe_filename, format,
priority, lineno, tags);
@@ -176,8 +183,8 @@ cleanup:
void
qb_log_dcs_init(void)
{
- lookup_arr = qb_array_create_2(16, sizeof(struct callsite_list), 16);
- callsite_arr = qb_array_create_2(16, sizeof(struct qb_log_callsite), 16);
+ lookup_arr = qb_array_create(16, sizeof(struct callsite_list));
+ callsite_arr = qb_array_create(16, sizeof(struct qb_log_callsite));
arr_next_lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
--
1.7.9.1
12 years, 1 month
[PATCH 1/2] RB: change the name of the size to word_size to be more clear
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ringbuffer.c | 50 +++++++++++++++++++++++-----------------------
lib/ringbuffer_helper.c | 2 +-
lib/ringbuffer_int.h | 2 +-
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index b840981..ec83cb0 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -44,15 +44,15 @@ do { \
#define QB_RB_CHUNK_SIZE_GET(rb, pointer) \
rb->shared_data[pointer]
#define QB_RB_CHUNK_MAGIC_GET(rb, pointer) \
- rb->shared_data[(pointer + 1) % rb->shared_hdr->size]
+ rb->shared_data[(pointer + 1) % rb->shared_hdr->word_size]
-#define QB_RB_WRITE_PT_INDEX (rb->shared_hdr->size)
-#define QB_RB_READ_PT_INDEX (rb->shared_hdr->size + 1)
+#define QB_RB_WRITE_PT_INDEX (rb->shared_hdr->word_size)
+#define QB_RB_READ_PT_INDEX (rb->shared_hdr->word_size + 1)
#define idx_step(idx) \
do { \
- if (idx > (rb->shared_hdr->size - 1)) { \
- idx = ((idx) % (rb->shared_hdr->size)); \
+ if (idx > (rb->shared_hdr->word_size - 1)) { \
+ idx = ((idx) % (rb->shared_hdr->word_size)); \
} \
} while (0)
@@ -69,15 +69,15 @@ do { \
if (idx % 8) { \
idx += (8 - (idx % 8)); \
} \
- if (idx > (rb->shared_hdr->size - 1)) { \
- idx = ((idx) % (rb->shared_hdr->size)); \
+ if (idx > (rb->shared_hdr->word_size - 1)) { \
+ idx = ((idx) % (rb->shared_hdr->word_size)); \
} \
} while (0)
#else
#define idx_cache_line_step(idx) \
do { \
- if (idx > (rb->shared_hdr->size - 1)) { \
- idx = ((idx) % (rb->shared_hdr->size)); \
+ if (idx > (rb->shared_hdr->word_size - 1)) { \
+ idx = ((idx) % (rb->shared_hdr->word_size)); \
} \
} while (0)
#endif
@@ -145,8 +145,8 @@ qb_rb_open(const char *name, size_t size, uint32_t flags,
*/
if (flags & QB_RB_FLAG_CREATE) {
rb->shared_data = NULL;
- /* rb->shared_hdr->size tracks data by ints and not bytes/chars. */
- rb->shared_hdr->size = real_size / sizeof(uint32_t);
+ /* rb->shared_hdr->word_size tracks data by ints and not bytes/chars. */
+ rb->shared_hdr->word_size = real_size / sizeof(uint32_t);
rb->shared_hdr->write_pt = 0;
rb->shared_hdr->read_pt = 0;
(void)strlcpy(rb->shared_hdr->hdr_path, path, PATH_MAX);
@@ -178,8 +178,8 @@ qb_rb_open(const char *name, size_t size, uint32_t flags,
}
qb_util_log(LOG_DEBUG,
- "shm size:%zd; real_size:%zd; rb->size:%d", size,
- real_size, rb->shared_hdr->size);
+ "shm size:%zd; real_size:%zd; rb->word_size:%d", size,
+ real_size, rb->shared_hdr->word_size);
error = qb_sys_circular_mmap(fd_data, &shm_addr, real_size);
rb->shared_data = shm_addr;
@@ -191,7 +191,7 @@ qb_rb_open(const char *name, size_t size, uint32_t flags,
if (flags & QB_RB_FLAG_CREATE) {
memset(rb->shared_data, 0, real_size);
- rb->shared_data[rb->shared_hdr->size] = 5;
+ rb->shared_data[rb->shared_hdr->word_size] = 5;
rb->shared_hdr->ref_count = 1;
} else {
qb_atomic_int_inc(&rb->shared_hdr->ref_count);
@@ -242,7 +242,7 @@ qb_rb_close(struct qb_ringbuffer_s * rb)
qb_util_log(LOG_DEBUG,
"Closing ringbuffer: %s", rb->shared_hdr->hdr_path);
}
- munmap(rb->shared_data, (rb->shared_hdr->size * sizeof(uint32_t)) << 1);
+ munmap(rb->shared_data, (rb->shared_hdr->word_size * sizeof(uint32_t)) << 1);
munmap(rb->shared_hdr, sizeof(struct qb_ringbuffer_shared_s));
free(rb);
}
@@ -260,7 +260,7 @@ qb_rb_force_close(struct qb_ringbuffer_s * rb)
qb_util_log(LOG_DEBUG,
"Force free'ing ringbuffer: %s",
rb->shared_hdr->hdr_path);
- munmap(rb->shared_data, (rb->shared_hdr->size * sizeof(uint32_t)) << 1);
+ munmap(rb->shared_data, (rb->shared_hdr->word_size * sizeof(uint32_t)) << 1);
munmap(rb->shared_hdr, sizeof(struct qb_ringbuffer_shared_s));
free(rb);
}
@@ -310,11 +310,11 @@ qb_rb_space_free(struct qb_ringbuffer_s * rb)
if (write_size > read_size) {
space_free =
- (read_size - write_size + rb->shared_hdr->size) - 1;
+ (read_size - write_size + rb->shared_hdr->word_size) - 1;
} else if (write_size < read_size) {
space_free = (read_size - write_size) - 1;
} else {
- space_free = rb->shared_hdr->size;
+ space_free = rb->shared_hdr->word_size;
}
/* word -> bytes */
@@ -338,7 +338,7 @@ qb_rb_space_used(struct qb_ringbuffer_s * rb)
space_used = write_size - read_size;
} else if (write_size < read_size) {
space_used =
- (write_size - read_size + rb->shared_hdr->size) - 1;
+ (write_size - read_size + rb->shared_hdr->word_size) - 1;
} else {
space_used = 0;
}
@@ -582,7 +582,7 @@ print_header(struct qb_ringbuffer_s * rb)
}
printf(" ->write_pt [%d]\n", rb->shared_hdr->write_pt);
printf(" ->read_pt [%d]\n", rb->shared_hdr->read_pt);
- printf(" ->size [%d words]\n", rb->shared_hdr->size);
+ printf(" ->size [%d words]\n", rb->shared_hdr->word_size);
#ifndef S_SPLINT_S
printf(" =>free [%zu bytes]\n", qb_rb_space_free(rb));
printf(" =>used [%zu bytes]\n", qb_rb_space_used(rb));
@@ -615,15 +615,15 @@ qb_rb_write_to_file(struct qb_ringbuffer_s * rb, int32_t fd)
}
print_header(rb);
- result = write(fd, &rb->shared_hdr->size, sizeof(uint32_t));
+ result = write(fd, &rb->shared_hdr->word_size, sizeof(uint32_t));
if (result != sizeof(uint32_t)) {
return -errno;
}
written_size += result;
result = write(fd, rb->shared_data,
- rb->shared_hdr->size * sizeof(uint32_t));
- if (result != rb->shared_hdr->size * sizeof(uint32_t)) {
+ rb->shared_hdr->word_size * sizeof(uint32_t));
+ if (result != rb->shared_hdr->word_size * sizeof(uint32_t)) {
return -errno;
}
written_size += result;
@@ -672,14 +672,14 @@ qb_rb_create_from_file(int32_t fd, uint32_t flags)
rb->flags = flags;
n_required = sizeof(uint32_t);
- n_read = read(fd, &rb->shared_hdr->size, n_required);
+ n_read = read(fd, &rb->shared_hdr->word_size, n_required);
if (n_read != n_required) {
qb_util_perror(LOG_ERR, "Unable to read blackbox file header");
goto cleanup_fail;
}
total_read += n_read;
- n_required = (rb->shared_hdr->size * sizeof(uint32_t));
+ n_required = (rb->shared_hdr->word_size * sizeof(uint32_t));
if ((rb->shared_data = malloc(n_required)) == NULL) {
qb_util_perror(LOG_ERR, "exhausted virtual memory");
diff --git a/lib/ringbuffer_helper.c b/lib/ringbuffer_helper.c
index 5e3be4f..4634771 100644
--- a/lib/ringbuffer_helper.c
+++ b/lib/ringbuffer_helper.c
@@ -218,7 +218,7 @@ my_sysv_sem_create(qb_ringbuffer_t * rb, uint32_t flags)
int32_t res;
key_t sem_key;
- sem_key = ftok(rb->shared_hdr->hdr_path, (rb->shared_hdr->size + 1));
+ sem_key = ftok(rb->shared_hdr->hdr_path, (rb->shared_hdr->word_size + 1));
if (sem_key == -1) {
res = -errno;
diff --git a/lib/ringbuffer_int.h b/lib/ringbuffer_int.h
index d2f24fa..3a7f22d 100644
--- a/lib/ringbuffer_int.h
+++ b/lib/ringbuffer_int.h
@@ -51,7 +51,7 @@ typedef int32_t(*qb_rb_sem_destroy_fn_t) (struct qb_ringbuffer_s * rb);
struct qb_ringbuffer_shared_s {
volatile uint32_t write_pt;
volatile uint32_t read_pt;
- uint32_t size;
+ uint32_t word_size;
char hdr_path[PATH_MAX];
char data_path[PATH_MAX];
int32_t ref_count;
--
1.7.9.1
12 years, 1 month
[PATCH 1/3] LOOP: signal handlers were always added as high priority.
by Angus Salkeld
This now adds them as requested by the user.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/loop_poll.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/loop_poll.c b/lib/loop_poll.c
index 3dda460..61fe0dc 100644
--- a/lib/loop_poll.c
+++ b/lib/loop_poll.c
@@ -830,7 +830,7 @@ _qb_signal_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
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],
+ qb_loop_level_item_add(&l->level[sig->p],
&new_sig_job->item);
jobs_added++;
}
--
1.7.9.1
12 years, 1 month