[PATCH] rewrite ipc to have multiple implementations & simpler API.
by Angus Salkeld
- implement using posix message queues
- implement using sys-v message queues
- implement shared memory ringbuffers
- add auth via unix sockets
- add items to the TODO
This is still a bit rough, more work to follow...
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
TODO | 9 +
configure.ac | 7 +-
include/qb/qbipc_common.h | 31 +-
include/qb/qbipcc.h | 47 +-
include/qb/qbipcs.h | 93 +--
include/qb/qblist.h | 2 +
include/qb/qbrb.h | 1 +
lib/Makefile.am | 4 +-
lib/hash.c | 1 -
lib/ipc_int.h | 247 +++++--
lib/ipc_posix_mq.c | 436 +++++++++++
lib/ipc_shm.c | 326 +++++++++
lib/ipc_sysv_mq.c | 416 +++++++++++
lib/ipc_us.c | 568 +++++++++++++++
lib/ipcc.c | 1136 +++--------------------------
lib/ipcs.c | 1779 +++++----------------------------------------
lib/poll.c | 11 +-
tests/bmc.c | 110 ++--
tests/bmcpt.c | 68 +-
tests/bms.c | 252 ++------
tests/check_rb.c | 14 +-
21 files changed, 2422 insertions(+), 3136 deletions(-)
13 years, 7 months
[PATCH] automake: check for more headers
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
configure.ac | 17 +++++++++-----
include/os_base.h | 53 +++++++++++++++++++++++++++++++++++++++-------
lib/hash.c | 9 ++-----
lib/hdb.c | 1 +
lib/ipcc.c | 8 ++++--
lib/ipcs.c | 15 +++++--------
lib/logsys.c | 6 +----
lib/plugin_loader.c | 14 ++++++------
lib/poll.c | 7 +-----
lib/ringbuffer.c | 2 -
lib/ringbuffer_helper.c | 2 -
lib/ringbuffer_int.h | 7 ------
lib/timer.c | 4 ---
lib/tsafe.c | 49 ++++++++++++++++++++++++++++---------------
lib/util.c | 7 +-----
lib/wthread.c | 13 ++++-------
16 files changed, 118 insertions(+), 96 deletions(-)
diff --git a/configure.ac b/configure.ac
index caba670..645a745 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,13 +3,13 @@
AC_PREREQ([2.61])
AC_INIT([libqb], [0.1.0], [quarterback-devel(a)fedorahosted.org])
+AC_CONFIG_SRCDIR([lib/ringbuffer.c])
+AC_CONFIG_HEADERS([include/config.h])
AM_INIT_AUTOMAKE([-Wno-portability])
LT_PREREQ([2.2.6])
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
-AC_CONFIG_SRCDIR([lib/tsafe.c])
-AC_CONFIG_HEADER([include/config.h])
AC_CANONICAL_HOST
AC_PROG_LIBTOOL
@@ -81,6 +81,7 @@ case $exec_prefix in
esac
# Checks for libraries.
+AC_CHECK_LIB([rt], [mq_open])
AC_CHECK_LIB([dl], [dlopen])
AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([socket], [socket])
@@ -92,10 +93,11 @@ AM_CONDITIONAL(HAVE_CHECK, test "${with_check}" = "yes")
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stdint.h \
+
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h locale.h netdb.h netinet/in.h nl_types.h stdint.h \
stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h \
- sys/time.h syslog.h unistd.h sys/types.h getopt.h malloc.h \
- sys/sockio.h utmpx.h])
+ time.h sys/time.h syslog.h unistd.h sys/types.h getopt.h malloc.h \
+ sys/sockio.h sys/un.h utmpx.h errno.h dlfcn.h dirent.h fnmatch.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@@ -105,6 +107,7 @@ AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
+AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_HEADER_TIME
@@ -121,8 +124,10 @@ AC_REPLACE_FNMATCH
AC_FUNC_FORK
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
+AC_FUNC_MMAP
AC_FUNC_MEMCMP
AC_FUNC_REALLOC
+AC_FUNC_STRERROR_R
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
@@ -130,11 +135,11 @@ AC_CHECK_FUNCS([alarm alphasort atexit bzero dup2 endgrent endpwent fcntl \
getcwd getpeerucred getpeereid gettimeofday inet_ntoa memmove \
memset mkdir scandir select socket strcasecmp strchr strdup \
strerror strrchr strspn strstr pthread_spin_lock \
+ clock_gettime localeconv localtime_r munmap pathconf putenv setenv \
pthread_spin_unlock pututxline lgammal setkey \
crypt encrypt getdate strsignal])
-
## local defines
PACKAGE_FEATURES=""
diff --git a/include/os_base.h b/include/os_base.h
index b0fcaf9..296407e 100644
--- a/include/os_base.h
+++ b/include/os_base.h
@@ -21,29 +21,66 @@
#ifndef QB_OS_BASE_H_DEFINED
#define QB_OS_BASE_H_DEFINED
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif /* _GNU_SOURCE */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <limits.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif /* HAVE_STDINT_H */
+
+#include <assert.h>
+
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
-#include <stdio.h>
-#include <stdint.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif /* HAVE_STRING_H */
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif /* HAVE_STRINGS_H */
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
+
+#ifdef HAVE_ERRNO_H
#include <errno.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif /* HAVE_STRING_H */
+#endif /*HAVE_ERRNO_H*/
+
#ifdef HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif /* HAVE_SYS_TIME_H */
+
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif /* HAVE_FCNTL_H */
-#include <sys/types.h>
-#include <sys/un.h>
+
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif /* HAVE_SYS_SOCKET_H */
-#include <assert.h>
+
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif /* HAVE_SYSLOG_H */
#endif /* QB_OS_BASE_H_DEFINED */
diff --git a/lib/hash.c b/lib/hash.c
index cd4984c..00df6ac 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -18,14 +18,11 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <stdint.h>
-#include <qb/qbhdb.h>
-
-#include <config.h>
-
#include "os_base.h"
-#include "util_int.h"
+#include <pthread.h>
+#include "util_int.h"
+#include <qb/qbhdb.h>
#include <qb/qbhdb.h>
#include <qb/qblist.h>
#include <qb/qbhash.h>
diff --git a/lib/hdb.c b/lib/hdb.c
index f71a998..edec694 100644
--- a/lib/hdb.c
+++ b/lib/hdb.c
@@ -19,6 +19,7 @@
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os_base.h"
+
#include <qb/qbutil.h>
#include <qb/qbhdb.h>
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 975e05c..87648ab 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -18,12 +18,14 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#include <config.h>
-
#include "os_base.h"
+
#include <sys/shm.h>
#include <sys/mman.h>
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif /* HAVE_SYS_UN_H */
+
#include <qb/qbipcc.h>
#include <qb/qbhdb.h>
diff --git a/lib/ipcs.c b/lib/ipcs.c
index b99268b..b73f133 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -18,21 +18,18 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#include <config.h>
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
-
#include "os_base.h"
+
#include <sys/mman.h>
#include <sys/poll.h>
#include <pthread.h>
-#if defined(HAVE_GETPEERUCRED)
+#ifdef HAVE_GETPEERUCRED
#include <ucred.h>
-#endif
+#endif /* HAVE_GETPEERUCRED */
#include <sys/shm.h>
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif /* HAVE_SYS_UN_H */
#include <qb/qblist.h>
#include <qb/qbhdb.h>
diff --git a/lib/logsys.c b/lib/logsys.c
index 5449f75..d0bf6db 100644
--- a/lib/logsys.c
+++ b/lib/logsys.c
@@ -19,13 +19,9 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#include <config.h>
-
#include "os_base.h"
+
#include <ctype.h>
-#include <sys/time.h>
-#include <syslog.h>
#include <pthread.h>
#include <semaphore.h>
diff --git a/lib/plugin_loader.c b/lib/plugin_loader.c
index c487fb3..11fc611 100644
--- a/lib/plugin_loader.c
+++ b/lib/plugin_loader.c
@@ -16,17 +16,17 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "os_base.h"
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
+#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
+#endif /* HAVE_DLFCN_H */
+#ifdef HAVE_DIRENT_H
#include <dirent.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
+#endif /* HAVE_DIRENT_H */
+#ifdef HAVE_FNMATCH_H
#include <fnmatch.h>
+#endif /* HAVE_FNMATCH_H */
#ifdef QB_SOLARIS
#include <iso/limits_iso.h>
#endif
diff --git a/lib/poll.c b/lib/poll.c
index 780188d..ec67ff5 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -18,15 +18,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "os_base.h"
-#include <config.h>
-
-#include <errno.h>
#include <pthread.h>
#include <sys/poll.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
#include <qb/qbhdb.h>
#include <qb/qbpoll.h>
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index 1ff2dd9..009d23e 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -18,8 +18,6 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
-
#include "ringbuffer_int.h"
//#define CRAZY_DEBUG_PRINTFS 1
diff --git a/lib/ringbuffer_helper.c b/lib/ringbuffer_helper.c
index 6839f5c..8d31638 100644
--- a/lib/ringbuffer_helper.c
+++ b/lib/ringbuffer_helper.c
@@ -18,8 +18,6 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
-
#include "ringbuffer_int.h"
static int32_t my_null_fn(struct qb_ringbuffer_s *rb)
diff --git a/lib/ringbuffer_int.h b/lib/ringbuffer_int.h
index ab9da90..b772354 100644
--- a/lib/ringbuffer_int.h
+++ b/lib/ringbuffer_int.h
@@ -21,15 +21,8 @@
#ifndef _RINGBUFFER_H_
#define _RINGBUFFER_H_
-#include <config.h>
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
-
#include "os_base.h"
-#include <limits.h>
#include <sys/mman.h>
#include <sys/sem.h>
#include <sys/ipc.h>
diff --git a/lib/timer.c b/lib/timer.c
index 4a615cb..9d3592f 100644
--- a/lib/timer.c
+++ b/lib/timer.c
@@ -18,14 +18,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#include <config.h>
-
#include "os_base.h"
#include <poll.h>
#include <signal.h>
-#include <time.h>
#include "tlist.h"
diff --git a/lib/tsafe.c b/lib/tsafe.c
index 1cf2c09..1459084 100644
--- a/lib/tsafe.c
+++ b/lib/tsafe.c
@@ -18,36 +18,35 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "os_base.h"
-#include <config.h>
-
-#define _XOPEN_SOURCE 600
-#define _GNU_SOURCE 1
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <math.h>
-
-#include <string.h>
-#include <assert.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
+#endif /* HAVE_NETINET_IN_H */
+#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
+#endif /* HAVE_ARPA_INET_H */
#include <grp.h>
#include <pwd.h>
+#ifdef HAVE_NETDB_H
#include <netdb.h>
+#endif /* HAVE_NETDB_H */
+#ifdef HAVE_NL_TYPES_H
#include <nl_types.h>
+#endif /* HAVE_NL_TYPES_H */
#include <libgen.h>
+#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
+#endif /* HAVE_DLFCN_H */
#ifdef HAVE_UTMPX_H
#include <utmpx.h>
#endif /* HAVE_UTMPX_H */
#include <search.h>
#include <locale.h>
+#ifdef HAVE_DIRENT_H
#include <dirent.h>
+#endif /* HAVE_DIRENT_H */
#include <pthread.h>
#include <qb/qbtsafe.h>
@@ -389,14 +388,22 @@ double drand48(void)
}
#ifdef HAVE_ENCRYPT
-void encrypt(char block[64], int edflag)
+#ifdef QB_BSD
+int encrypt(char *block, int edflag)
+#else
+void encrypt(char *block, int edflag)
+#endif
{
+ #ifdef QB_BSD
+ static int (*real_encrypt) (char block[64], int edflag) = NULL;
+ #else
static void (*real_encrypt) (char block[64], int edflag) = NULL;
+ #endif
if (!tsafe_inited || tsafe_disabled) {
if (real_encrypt == NULL) {
real_encrypt = _get_real_func_("encrypt");
}
- return real_encrypt(edflag);
+ return real_encrypt(block, edflag);
}
assert(0);
}
@@ -924,7 +931,7 @@ struct dirent *readdir(DIR * dirp)
return NULL;
}
-#ifdef COROSYNC_BSD
+#ifdef QB_BSD
int setgrent(void)
{
static int (*real_setgrent) (void) = NULL;
@@ -952,9 +959,17 @@ void setgrent(void)
#endif
#ifdef HAVE_SETKEY
+#ifdef QB_BSD
+int setkey(const char *key)
+#else
void setkey(const char *key)
+#endif
{
+#ifdef QB_BSD
+ static int (*real_setkey) (const char *key) = NULL;
+#else
static void (*real_setkey) (const char *key) = NULL;
+#endif
if (!tsafe_inited || tsafe_disabled) {
if (real_setkey == NULL) {
real_setkey = _get_real_func_("setkey");
diff --git a/lib/util.c b/lib/util.c
index 76204dd..0a71b59 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -18,12 +18,9 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
-
#include "os_base.h"
+
#include "util_int.h"
-#include <syslog.h>
-#include <stdarg.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include <pthread.h>
@@ -33,8 +30,6 @@
#include <sys/sem.h>
#endif
#include <sys/stat.h>
-#include <fcntl.h>
-#include <limits.h>
#include <qb/qbutil.h>
struct qb_thread_lock_s {
diff --git a/lib/wthread.c b/lib/wthread.c
index f531e9e..510fb5e 100644
--- a/lib/wthread.c
+++ b/lib/wthread.c
@@ -18,20 +18,17 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "os_base.h"
+
+#include <pthread.h>
+#include <qb/qbqueue.h>
+#include <qb/qbwthread.h>
/*
* Add work to a work group and have threads process the work
* Provide blocking for all work to complete
*/
-#include <config.h>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <errno.h>
-#include <qb/qbqueue.h>
-#include <qb/qbwthread.h>
struct thread_data {
void *thread_state;
--
1.7.1
13 years, 7 months
[PATCH] RB: add function qb_rb_chunks_used()
by Angus Salkeld
This is to make it easier to to see if there is
a chunk available to be read.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbrb.h | 7 +++++++
lib/ringbuffer.c | 18 +++++++++++++++++-
lib/ringbuffer_int.h | 2 +-
tests/check_rb.c | 1 +
4 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/include/qb/qbrb.h b/include/qb/qbrb.h
index a944e10..72c1513 100644
--- a/include/qb/qbrb.h
+++ b/include/qb/qbrb.h
@@ -224,6 +224,13 @@ ssize_t qb_rb_space_free(qb_ringbuffer_t * rb);
ssize_t qb_rb_space_used(qb_ringbuffer_t * rb);
/**
+ * The total number of chunks in the buffer.
+ *
+ * @param rb ringbuffer instance
+ */
+ssize_t qb_rb_chunks_used(qb_ringbuffer_t * rb);
+
+/**
* Write the contents of the Ring Buffer to file.
* @param fd open file to write the ringbuffer data to.
* @param rb ringbuffer instance
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index 0210a12..1ff2dd9 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -315,6 +315,22 @@ ssize_t qb_rb_space_used(qb_ringbuffer_t * rb)
return used;
}
+ssize_t qb_rb_chunks_used(qb_ringbuffer_t * rb)
+{
+ ssize_t count = -1;
+ if (rb->lock_fn(rb) == -1) {
+ return -1;
+ }
+ count = rb->shared_hdr->count;
+ if (rb->unlock_fn(rb) == -1) {
+ /* aarg stuck locked! */
+ qb_util_log(LOG_ERR, "failed to unlock ringbuffer lock %s",
+ strerror(errno));
+ return -1;
+ }
+ return count;
+}
+
void *qb_rb_chunk_alloc(qb_ringbuffer_t * rb, size_t len)
{
uint32_t write_pt;
@@ -462,7 +478,7 @@ ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t timeout)
res = rb->sem_timedwait_fn(rb, timeout);
if (res == -1 && errno == ETIMEDOUT && rb->shared_hdr->count > 0) {
qb_util_log(LOG_ERR,
- "sem timedout but count is %d",
+ "sem timedout but count is %zu",
rb->shared_hdr->count);
} else if (res == -1 && errno != EIDRM) {
if (errno != ETIMEDOUT) {
diff --git a/lib/ringbuffer_int.h b/lib/ringbuffer_int.h
index 68c3269..ab9da90 100644
--- a/lib/ringbuffer_int.h
+++ b/lib/ringbuffer_int.h
@@ -57,7 +57,7 @@ struct qb_ringbuffer_shared_s {
volatile uint32_t write_pt;
volatile uint32_t read_pt;
uint32_t size;
- uint32_t count;
+ size_t count;
char hdr_path[PATH_MAX];
char data_path[PATH_MAX];
int32_t ref_count;
diff --git a/tests/check_rb.c b/tests/check_rb.c
index e262876..7c5cd64 100644
--- a/tests/check_rb.c
+++ b/tests/check_rb.c
@@ -71,6 +71,7 @@ START_TEST(test_ring_buffer1)
for (i = 0; i < 15; i++) {
actual = qb_rb_chunk_read(rb, hdr, 512, 0);
if (actual == -1) {
+ ck_assert_int_eq(0, qb_rb_chunks_used(rb));
break;
}
str[actual - sizeof(qb_ipc_request_header_t)] = '\0';
--
1.7.1
13 years, 7 months