change the ownership of the two mmap'ed files.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbrb.h | 10 ++++++++++
lib/ringbuffer.c | 16 +++++++++++++++-
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/include/qb/qbrb.h b/include/qb/qbrb.h
index 953f376..e7c626b 100644
--- a/include/qb/qbrb.h
+++ b/include/qb/qbrb.h
@@ -248,6 +248,16 @@ ssize_t qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd);
*/
qb_ringbuffer_t *qb_rb_create_from_file(int32_t fd, uint32_t flags);
+/**
+ * Like 'chown' it changes the owner and group of the ringbuffers
+ * resources.
+ * @param owner uid of the owner to change to
+ * @param group gid of the group to change to
+ * @param rb ringbuffer instance
+ * @return status (0 = ok, -errno for error)
+ */
+int32_t qb_rb_chown(qb_ringbuffer_t * rb, uid_t owner, gid_t group);
+
/* *INDENT-OFF* */
#ifdef __cplusplus
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index 79702fe..3aa25a5 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -99,7 +99,7 @@ qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t
flags)
fd_hdr = qb_util_mmap_file_open(path, name,
sizeof(struct qb_ringbuffer_shared_s),
file_flags);
- if (fd_hdr == -1) {
+ if (fd_hdr < 0) {
qb_util_log(LOG_ERR, "couldn't create file for mmap");
return NULL;
}
@@ -675,3 +675,17 @@ qb_ringbuffer_t *qb_rb_create_from_file(int32_t fd, uint32_t flags)
return rb;
}
+
+int32_t qb_rb_chown(qb_ringbuffer_t * rb, uid_t owner, gid_t group)
+{
+ int32_t res = chown(rb->shared_hdr->data_path, owner, group);
+ if (res < 0) {
+ return -errno;
+ }
+ res = chown(rb->shared_hdr->hdr_path, owner, group);
+ if (res < 0) {
+ return -errno;
+ }
+ return 0;
+}
+
--
1.7.2.3