Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ipc_shm.c | 18 +++++++++++-------
lib/ipc_us.c | 17 ++++++++++-------
lib/ringbuffer.c | 21 +++++++++++++++------
lib/util.c | 2 ++
4 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/lib/ipc_shm.c b/lib/ipc_shm.c
index 220586c..e9b60d5 100644
--- a/lib/ipc_shm.c
+++ b/lib/ipc_shm.c
@@ -149,14 +149,15 @@ int32_t qb_ipcc_shm_connect(struct qb_ipcc_connection *c,
QB_RB_FLAG_SHARED_PROCESS,
sizeof(int32_t));
if (c->request.u.shm.rb == NULL) {
- perror("qb_rb_open:REQUEST");
- return -errno;
+ res = -errno;
+ goto return_error;
}
c->response.u.shm.rb = qb_rb_open(response->response,
c->response.max_msg_size,
QB_RB_FLAG_SHARED_PROCESS, 0);
if (c->response.u.shm.rb == NULL) {
+ res = -errno;
perror("qb_rb_open:RESPONSE");
goto cleanup_request;
}
@@ -171,13 +172,15 @@ 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);
- qb_util_log(LOG_DEBUG, "connection failed %d\n", res);
+ return_error:
+ qb_util_log(LOG_ERR, "connection failed %s\n",
+ strerror(-res));
return res;
}
@@ -226,7 +229,6 @@ static int32_t qb_ipcs_shm_connect(struct qb_ipcs_service *s,
snprintf(r->response, NAME_MAX, "qb-%s-response-%d-%d", s->name,
c->pid, c->setup.u.us.sock);
snprintf(r->event, NAME_MAX, "qb-%s-event-%d-%d", s->name, c->pid,
c->setup.u.us.sock);
- qb_util_log(LOG_DEBUG, "rb_open:%s", r->request);
c->request.u.shm.rb = qb_rb_open(r->request,
c->request.max_msg_size,
QB_RB_FLAG_CREATE |
@@ -257,7 +259,7 @@ static int32_t qb_ipcs_shm_connect(struct qb_ipcs_service *s,
if (c->event.u.shm.rb == NULL) {
res = -errno;
- perror("mq_open:EVENT");
+ perror("qb_rb_open:EVENT");
goto cleanup_request_response;
}
res = qb_rb_chown(c->event.u.shm.rb, c->euid, c->egid);
@@ -273,6 +275,8 @@ cleanup_request:
cleanup:
r->hdr.error = res;
+ qb_util_log(LOG_ERR, "shm connection FAILED [%s]\n",
+ strerror(-res));
return res;
}
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index cf55b22..2f11daf 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -567,7 +567,6 @@ static int32_t handle_new_connection(struct qb_ipcs_service *s,
struct qb_ipc_connection_request *req = msg;
int32_t res = auth_result;
struct qb_ipc_connection_response response;
- char error_str[100];
if (res != 0) {
goto send_response;
@@ -638,8 +637,13 @@ send_response:
s->stats.active_connections++;
}
- if (qb_ipc_us_send(&c->setup, &response, response.hdr.size) < 0) {
- qb_util_log(LOG_ERR, "Error send connection response.");
+ res = qb_ipc_us_send(&c->setup, &response, response.hdr.size);
+ if (res == response.hdr.size) {
+ res = 0;
+ }
+ if (res < 0) {
+ qb_util_log(LOG_ERR, "Error sending connection response: %s",
+ strerror(-res));
}
if (res == 0) {
@@ -649,9 +653,8 @@ send_response:
} else if (res == -EACCES) {
qb_util_log(LOG_ERR, "Invalid IPC credentials.");
} else {
- strerror_r(-response.hdr.error, error_str, 100);
qb_util_log(LOG_ERR, "Error in connection setup: %s.",
- error_str);
+ strerror(-res));
}
if (res != 0 && c) {
qb_ipcs_disconnect(c);
@@ -806,10 +809,10 @@ retry_accept:
return -1;
}
if (new_fd == -1) {
- strerror_r(errno, error_str, 100);
+ res = -errno;
qb_util_log(LOG_ERR,
"Could not accept Library connection: [%d] %s\n",
- errno, error_str);
+ errno, strerror(-res));
return 0; /* This is an error, but -1 would indicate disconnect from poll loop */
}
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index bc57a7d..17365e5 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -91,6 +91,7 @@ qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t
flags,
uint32_t file_flags = O_RDWR;
size_t shared_size = sizeof(struct qb_ringbuffer_shared_s);
char filename[PATH_MAX];
+ int32_t error = 0;
shared_size += shared_user_data_size;
@@ -105,15 +106,17 @@ qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t
flags,
shared_size,
file_flags);
if (fd_hdr < 0) {
+ error = fd_hdr;
qb_util_log(LOG_ERR, "couldn't create file for mmap");
return NULL;
}
rb->shared_hdr = mmap(0,
- sizeof(struct qb_ringbuffer_shared_s),
+ shared_size,
PROT_READ | PROT_WRITE, MAP_SHARED, fd_hdr, 0);
if (rb->shared_hdr == MAP_FAILED) {
+ error = -errno;
qb_util_log(LOG_ERR, "couldn't create mmap for header");
goto cleanup_hdr;
}
@@ -131,9 +134,10 @@ qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t
flags,
rb->shared_hdr->read_pt = 0;
strncpy(rb->shared_hdr->hdr_path, path, PATH_MAX);
}
- if (qb_rb_sem_create(rb, flags) < 0) {
+ error = qb_rb_sem_create(rb, flags);
+ if (error < 0) {
qb_util_log(LOG_ERR, "couldn't get a semaphore %s",
- strerror(errno));
+ strerror(-error));
goto cleanup_hdr;
}
@@ -152,16 +156,20 @@ qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t
flags,
real_size, file_flags);
}
if (fd_data < 0) {
+ error = fd_data;
qb_util_log(LOG_ERR, "couldn't create file for mmap");
goto cleanup_hdr;
}
qb_util_log(LOG_DEBUG,
- "shm \n size:%zd\n real_size:%zd\n rb->size:%d\n", size,
+ "shm size:%zd; real_size:%zd; rb->size:%d", size,
real_size, rb->shared_hdr->size);
- if (qb_util_circular_mmap(fd_data,
- (void **)&rb->shared_data, real_size) != 0) {
+ error = qb_util_circular_mmap(fd_data,
+ (void **)&rb->shared_data, real_size);
+ if (error != 0) {
+ qb_util_log(LOG_ERR, "couldn't create circular mmap on %s",
+ rb->shared_hdr->data_path);
goto cleanup_data;
}
@@ -193,6 +201,7 @@ cleanup_hdr:
munmap(rb->shared_hdr, sizeof(struct qb_ringbuffer_shared_s));
}
free(rb);
+ errno = -error;
return NULL;
}
diff --git a/lib/util.c b/lib/util.c
index 0452354..0ab5f1a 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -288,6 +288,7 @@ int32_t qb_util_mmap_file_open(char *path, const char *file, size_t
bytes,
long page_size = sysconf(_SC_PAGESIZE);
buffer = calloc(1, page_size);
if (buffer == NULL) {
+ res = -ENOMEM;
goto unlink_exit;
}
for (i = 0; i < (bytes / page_size); i++) {
@@ -297,6 +298,7 @@ retry_write:
goto retry_write;
}
if (written != page_size) {
+ res = -ENOSPC;
free (buffer);
goto unlink_exit;
}
--
1.7.3.1