[PATCH] Remove unused local variable
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/loop_poll_epoll.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/loop_poll_epoll.c b/lib/loop_poll_epoll.c
index a2eb12d..b4039b0 100644
--- a/lib/loop_poll_epoll.c
+++ b/lib/loop_poll_epoll.c
@@ -110,7 +110,6 @@ _mod(struct qb_poll_source *s, struct qb_poll_entry *pe, int32_t fd, int32_t eve
static int32_t
_del(struct qb_poll_source *s, struct qb_poll_entry *pe, int32_t fd, int32_t arr_index)
{
- struct epoll_event ev;
int32_t res = 0;
if (epoll_ctl(s->epollfd, EPOLL_CTL_DEL, fd, NULL) == -1) {
--
1.7.10
11 years, 12 months
[PATCH 1/3] TEST: improve the tracing in the ipc tests.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/check_ipc.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index 70e41ef..f2124b2 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -383,99 +383,119 @@ test_ipc_exit(void)
START_TEST(test_ipc_exit_us)
{
+ qb_enter();
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
recv_timeout = 5000;
test_ipc_exit();
+ qb_leave();
}
END_TEST
#ifdef HAVE_SEM_TIMEDWAIT
START_TEST(test_ipc_exit_shm)
{
+ qb_enter();
ipc_type = QB_IPC_SHM;
ipc_name = __func__;
recv_timeout = 1000;
test_ipc_exit();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_txrx_shm_tmo)
{
+ qb_enter();
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_SHM;
ipc_name = __func__;
recv_timeout = 1000;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_txrx_shm_block)
{
+ qb_enter();
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_SHM;
ipc_name = __func__;
recv_timeout = -1;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_fc_shm)
{
+ qb_enter();
turn_on_fc = QB_TRUE;
ipc_type = QB_IPC_SHM;
recv_timeout = 500;
ipc_name = __func__;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
#endif /* HAVE_SEM_TIMEDWAIT */
START_TEST(test_ipc_txrx_us_block)
{
+ qb_enter();
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
recv_timeout = -1;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_txrx_us_tmo)
{
+ qb_enter();
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
recv_timeout = 1000;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_fc_us)
{
+ qb_enter();
turn_on_fc = QB_TRUE;
ipc_type = QB_IPC_SOCKET;
recv_timeout = 500;
ipc_name = __func__;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_txrx_pmq)
{
+ qb_enter();
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_POSIX_MQ;
ipc_name = __func__;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_txrx_smq)
{
+ qb_enter();
turn_on_fc = QB_FALSE;
ipc_type = QB_IPC_SYSV_MQ;
ipc_name = __func__;
test_ipc_txrx();
+ qb_leave();
}
END_TEST
@@ -524,9 +544,11 @@ test_ipc_dispatch(void)
START_TEST(test_ipc_disp_us)
{
+ qb_enter();
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
test_ipc_dispatch();
+ qb_leave();
}
END_TEST
@@ -594,9 +616,11 @@ test_ipc_bulk_events(void)
START_TEST(test_ipc_bulk_events_us)
{
+ qb_enter();
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
test_ipc_bulk_events();
+ qb_leave();
}
END_TEST
@@ -649,34 +673,42 @@ test_ipc_server_fail(void)
START_TEST(test_ipc_server_fail_soc)
{
+ qb_enter();
ipc_type = QB_IPC_SOCKET;
ipc_name = __func__;
test_ipc_server_fail();
+ qb_leave();
}
END_TEST
#ifdef HAVE_SEM_TIMEDWAIT
START_TEST(test_ipc_disp_shm)
{
+ qb_enter();
ipc_type = QB_IPC_SHM;
ipc_name = __func__;
test_ipc_dispatch();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_bulk_events_shm)
{
+ qb_enter();
ipc_type = QB_IPC_SHM;
ipc_name = __func__;
test_ipc_bulk_events();
+ qb_leave();
}
END_TEST
START_TEST(test_ipc_server_fail_shm)
{
+ qb_enter();
ipc_type = QB_IPC_SHM;
ipc_name = __func__;
test_ipc_server_fail();
+ qb_leave();
}
END_TEST
#endif /* HAVE_SEM_TIMEDWAIT */
@@ -788,7 +820,7 @@ main(void)
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
- qb_log_format_set(QB_LOG_STDERR, "[%p] %f:%l %b");
+ qb_log_format_set(QB_LOG_STDERR, "lib/%f|%l| %b");
srunner_run_all(sr, CK_VERBOSE);
number_failed = srunner_ntests_failed(sr);
--
1.7.10
11 years, 12 months
[PATCH 1/2] TEST: reuse send_and_check for events.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/check_ipc.c | 60 +++++++++++++++++++++--------------------------------
1 file changed, 24 insertions(+), 36 deletions(-)
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index 191d005..d15eea1 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -222,13 +222,14 @@ struct my_req {
static struct my_req request;
static int32_t
-send_and_check(uint32_t size, int32_t ms_timeout, int32_t expect_perfection)
+send_and_check(int32_t req_id, uint32_t size,
+ int32_t ms_timeout, int32_t expect_perfection)
{
struct qb_ipc_response_header res_header;
int32_t res;
int32_t try_times = 0;
- request.hdr.id = IPC_MSG_REQ_TX_RX;
+ request.hdr.id = req_id;
request.hdr.size = sizeof(struct qb_ipc_request_header) + size;
repeat_send:
@@ -247,8 +248,15 @@ repeat_send:
return res;
}
}
- res = qb_ipcc_recv(conn, &res_header,
- sizeof(struct qb_ipc_response_header), ms_timeout);
+ if (req_id == IPC_MSG_REQ_TX_RX) {
+ res = qb_ipcc_recv(conn, &res_header,
+ sizeof(struct qb_ipc_response_header),
+ ms_timeout);
+ } else {
+ res = qb_ipcc_event_recv(conn, &res_header,
+ sizeof(struct qb_ipc_response_header),
+ ms_timeout);
+ }
if (res == -EINTR) {
return -1;
}
@@ -259,7 +267,7 @@ repeat_send:
}
if (expect_perfection) {
ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header));
- ck_assert_int_eq(res_header.id, IPC_MSG_RES_TX_RX);
+ ck_assert_int_eq(res_header.id, req_id + 1);
ck_assert_int_eq(res_header.size, sizeof(struct qb_ipc_response_header));
}
return res;
@@ -294,7 +302,8 @@ test_ipc_txrx(void)
size *= 2;
if (size >= MAX_MSG_SIZE)
break;
- if (send_and_check(size, recv_timeout, QB_TRUE) < 0) {
+ if (send_and_check(IPC_MSG_REQ_TX_RX, size,
+ recv_timeout, QB_TRUE) < 0) {
break;
}
}
@@ -463,11 +472,10 @@ static struct my_res response;
static void
test_ipc_dispatch(void)
{
- int32_t res;
int32_t j;
int32_t c = 0;
pid_t pid;
- struct qb_ipc_request_header req_header;
+ int32_t size;
pid = run_function_in_new_process(run_ipc_server);
fail_if(pid == -1);
@@ -484,36 +492,16 @@ test_ipc_dispatch(void)
} while (conn == NULL && c < 5);
fail_if(conn == NULL);
- req_header.id = IPC_MSG_REQ_DISPATCH;
- req_header.size = sizeof(struct qb_ipc_request_header);
-
- repeat_send:
- res = qb_ipcc_send(conn, &req_header, req_header.size);
- if (res < 0) {
- if (res == -EAGAIN) {
- goto repeat_send;
- } else if (res == -EINVAL || res == -EINTR) {
- qb_perror(LOG_INFO, "qb_ipcc_send");
- return;
- } else {
- errno = -res;
- qb_perror(LOG_INFO, "qb_ipcc_send");
- goto repeat_send;
- }
- }
- repeat_event_recv:
- res = qb_ipcc_event_recv(conn, &response, sizeof(struct my_res), 0);
- if (res < 0) {
- if (res == -EAGAIN || res == -ETIMEDOUT) {
- goto repeat_event_recv;
- } else {
- errno = -res;
- qb_perror(LOG_INFO, "qb_ipcc_event_recv");
- goto repeat_send;
+ size = QB_MIN(sizeof(struct qb_ipc_request_header), 64);
+ for (j = 1; j < 19; j++) {
+ size *= 2;
+ if (size >= MAX_MSG_SIZE)
+ break;
+ if (send_and_check(IPC_MSG_REQ_DISPATCH, size,
+ recv_timeout, QB_TRUE) < 0) {
+ break;
}
}
- ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header));
- ck_assert_int_eq(response.hdr.id, IPC_MSG_RES_DISPATCH);
qb_ipcc_disconnect(conn);
stop_process(pid);
--
1.7.10
11 years, 12 months
[PATCH] IPC: make it possible for a root client to talk to a non-root server.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ringbuffer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index f46d735..67b2fb4 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -736,11 +736,11 @@ qb_rb_chown(struct qb_ringbuffer_s * rb, uid_t owner, gid_t group)
return -EINVAL;
}
res = chown(rb->shared_hdr->data_path, owner, group);
- if (res < 0) {
+ if (res < 0 && errno != EPERM) {
return -errno;
}
res = chown(rb->shared_hdr->hdr_path, owner, group);
- if (res < 0) {
+ if (res < 0 && errno != EPERM) {
return -errno;
}
return 0;
--
1.7.10
11 years, 12 months
[PATCH 1/3] IPC: make sure ipc (socket) clients can connect to a server running as root.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ipc_us.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index 2607fb9..579fa90 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -892,6 +892,7 @@ qb_ipcs_us_connect(struct qb_ipcs_service *s,
}
(void)strlcpy(r->request, path, PATH_MAX);
(void)strlcpy(c->request.u.us.shared_file_name, r->request, NAME_MAX);
+ (void)chown(r->request, c->euid, c->egid);
c->request.u.us.shared_data = mmap(0,
sizeof(struct ipc_us_control),
--
1.7.9.3
12 years
[RFC] incorrect __attributes__ on qb_ipc_header structs
by Angus Salkeld
Hi all
Fabio noticed that we have some odd attributes on the qb_ipc_header structs.
They currently have (aligned(8)) and should really have (packed) for
efficient packing on-wire (http://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Type-Attributes.html).
He noticed this while doing some valgind testing.
This is not so easy to fix as it will break ABI.
So like this:
diff --git a/include/qb/qbipc_common.h b/include/qb/qbipc_common.h
index 0a4118c..7af2c7e 100644
--- a/include/qb/qbipc_common.h
+++ b/include/qb/qbipc_common.h
@@ -32,15 +32,15 @@ extern "C" {
/* *INDENT-ON* */
struct qb_ipc_request_header {
- int32_t id __attribute__ ((aligned(8)));
- int32_t size __attribute__ ((aligned(8)));
-} __attribute__ ((aligned(8)));
+ int32_t id;
+ int32_t size;
+} __attribute__ (packed);
struct qb_ipc_response_header {
- int32_t id __attribute__ ((aligned(8)));
- int32_t size __attribute__ ((aligned(8)));
- int32_t error __attribute__ ((aligned(8)));
-} __attribute__ ((aligned(8)));
+ int32_t id;
+ int32_t size;
+ int32_t error;
+} __attribute__ (packed);
enum qb_ipc_type {
QB_IPC_SOCKET,
Because the alignment changes per arch, this is not so easy to work
around.
Is this a problem? Can we just leave it as-is? What other options are there?
Regards
-Angus
12 years
[PATCH] IPC: allow qb to bump the max_message_size
by Angus Salkeld
I think this is more user friendly.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ipcc.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/lib/ipcc.c b/lib/ipcc.c
index ec59b25..8ce9ca2 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -40,12 +40,8 @@ qb_ipcc_connect(const char *name, size_t max_msg_size)
return NULL;
}
- if (max_msg_size < sizeof(struct qb_ipc_connection_response)) {
- errno = EINVAL;
- return NULL;
- }
-
- c->setup.max_msg_size = max_msg_size;
+ c->setup.max_msg_size = QB_MAX(max_msg_size,
+ sizeof(struct qb_ipc_connection_response));
(void)strlcpy(c->name, name, NAME_MAX);
res = qb_ipcc_us_setup_connect(c, &response);
if (res < 0) {
--
1.7.9.3
12 years
[PATCH] IPC: check for a sane minimum max_message_size
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ipc_us.c | 1 +
lib/ipcc.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index 08bedd7..2607fb9 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -676,6 +676,7 @@ send_response:
if (res == -EACCES) {
qb_util_log(LOG_ERR, "Invalid IPC credentials.");
} else {
+ errno = -res;
qb_util_perror(LOG_ERR, "Error in connection setup");
}
qb_ipcs_disconnect(c);
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 6322994..ec59b25 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -40,6 +40,11 @@ qb_ipcc_connect(const char *name, size_t max_msg_size)
return NULL;
}
+ if (max_msg_size < sizeof(struct qb_ipc_connection_response)) {
+ errno = EINVAL;
+ return NULL;
+ }
+
c->setup.max_msg_size = max_msg_size;
(void)strlcpy(c->name, name, NAME_MAX);
res = qb_ipcc_us_setup_connect(c, &response);
--
1.7.9.3
12 years
[PATCH] add rpl_sem.h loop_poll_int.h to noinst_headers
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/Makefile.am | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 28a86fd..847e08a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -21,7 +21,8 @@
MAINTAINERCLEANFILES = Makefile.in
-noinst_HEADERS = ipc_int.h util_int.h ringbuffer_int.h loop_int.h log_int.h map_int.h
+noinst_HEADERS = ipc_int.h util_int.h ringbuffer_int.h loop_int.h \
+ log_int.h map_int.h rpl_sem.h loop_poll_int.h
#
# Here are a set of rules to help you update your library version information:
--
1.7.9.3
12 years
[PATCH 1/6] Get the example socket includes right.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
configure.ac | 2 +-
examples/tcpclient.c | 11 ++++++++++-
examples/tcpserver.c | 16 ++++++++++++++--
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index a957844..fda5ea4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -120,7 +120,7 @@ AC_CHECK_HEADERS([arpa/inet.h link.h fcntl.h inttypes.h limits.h netinet/in.h st
dlfcn.h time.h sys/time.h stdlib.h string.h strings.h sys/types.h sys/stat.h \
sys/param.h sys/socket.h sys/time.h sys/poll.h sys/epoll.h sys/uio.h sys/event.h \
sys/sockio.h sys/un.h sys/resource.h syslog.h errno.h unistd.h sys/mman.h \
- sys/sem.h sys/ipc.h sys/msg.h mqueue.h])
+ sys/sem.h sys/ipc.h sys/msg.h mqueue.h netdb.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
diff --git a/examples/tcpclient.c b/examples/tcpclient.c
index b4bb33e..e78f523 100644
--- a/examples/tcpclient.c
+++ b/examples/tcpclient.c
@@ -20,9 +20,18 @@
*/
#include "os_base.h"
+#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
+#endif /* HAVE_ARPA_INET_H */
+#ifdef HAVE_NETDB_H
#include <netdb.h>
-
+#endif /* HAVE_NETDB_H */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif /* HAVE_SYS_SOCKET_H */
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif /* HAVE_NETINET_IN_H */
int
main(int argc, char *argv[])
diff --git a/examples/tcpserver.c b/examples/tcpserver.c
index fddaa39..8d70fe1 100644
--- a/examples/tcpserver.c
+++ b/examples/tcpserver.c
@@ -20,9 +20,21 @@
*/
#include "os_base.h"
-#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
-#include <poll.h>
+#endif /* HAVE_ARPA_INET_H */
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif /* HAVE_NETDB_H */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif /* HAVE_SYS_SOCKET_H */
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif /* HAVE_NETINET_IN_H */
+#ifdef HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#endif /* HAVE_SYS_POLL_H */
#include <qb/qbdefs.h>
#include <qb/qbloop.h>
--
1.7.9.3
12 years