if the server is dead then is_connected will cause the resourses
to be properly cleaned up.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ipcc.c | 15 +++++++++++++++
lib/ipcs.c | 4 ++--
tests/check_ipc.c | 12 ++++++++----
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 6bcc5d5..43c7d43 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -306,11 +306,26 @@ qb_ipcc_event_recv(struct qb_ipcc_connection * c, void *msg_pt,
void
qb_ipcc_disconnect(struct qb_ipcc_connection *c)
{
+ struct qb_ipc_one_way *ow = NULL;
+
qb_util_log(LOG_DEBUG, "%s()", __func__);
if (c == NULL) {
return;
}
+
+ if (c->needs_sock_for_poll) {
+ ow = &c->setup;
+ }
+ if (c->type == QB_IPC_SOCKET) {
+ ow = &c->event;
+ }
+ if (ow) {
+ if (qb_ipc_us_recv_ready(ow, 1000) == -ENOTCONN) {
+ c->is_connected = QB_FALSE;
+ }
+ }
+
qb_ipcc_us_sock_close(c->setup.u.us.sock);
if (c->funcs.disconnect) {
c->funcs.disconnect(c);
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 92c24c2..bf1f9f2 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -467,8 +467,8 @@ qb_ipcs_connection_unref(struct qb_ipcs_connection *c)
return;
}
if (c->refcount < 1) {
- qb_util_log(LOG_ERR, "%s() ref:%d state:%d fd:%d",
- __func__, c->refcount, c->state,
+ qb_util_log(LOG_ERR, "ref:%d state:%d fd:%d",
+ c->refcount, c->state,
c->setup.u.us.sock);
assert(0);
}
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index 95919b4..225d379 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -340,11 +340,14 @@ test_ipc_exit(void)
/* kill the server */
stop_process(pid);
- /* assertion: we can call send/recv without locking up */
- rc = send_and_check(100, recv_timeout, QB_FALSE);
- ck_assert_int_eq(rc, -ENOTCONN);
+ /*
+ * wait a bit for the server to die.
+ */
+ sleep(1);
- /* this needs to free up the shared mem */
+ /*
+ * this needs to free up the shared mem
+ */
qb_ipcc_disconnect(conn);
}
@@ -565,6 +568,7 @@ test_ipc_server_fail(void)
sleep(1);
/*
* try recv from the exit'ed server
+ * assertion: we can call recv without locking up
*/
res = qb_ipcc_recv(conn, &res_header,
sizeof(struct qb_ipc_response_header), 100);
--
1.7.7.5
Show replies by date