Change all ints to [u]intXX_t's
by Angus Salkeld
This changes almost all integers from native "int", long, ...
to int32_t, uint_64_t, ...
This helps in producing more portable messaging. This is something
we have wanted to do in corosync for a long time.
[PATCH 1/3] unsigned long long -> uint64_t
[PATCH 2/3] unsigned int -> uint32_t
[PATCH 3/3] int -> int32_t
Regards
Angus
13 years, 9 months
libqb development plan
by Angus Salkeld
After Steve dropped his note about future corosync development it
might make sense to let you know where we are with libqb.
So far I have done the following:
- imported code from corosync
- namespaced everything with "qb_" to prevent name clashes.
- Re licensed to LGPL-2.1 (thanks to all relevant contributors)
- seperated out the ringbuffer functionality out of logsys into seperate
files.
- improved on the ringbuffer to make it usable accross processes
- used the ringbuffer to implement a non blocking ipc send (with flow control).
- started using check (http://check.sourceforge.net/) to do unit testing.
- started documenting the newer API's using doxygen (to produce man pages and html)
- setup up a wiki
I will now start releasing 0.Y.0 releases simply as milestones (as API will change
until 1.0).
I plan to release to following features up until libqb-1.0. This is early
and will probably change but should show the direction I am trying to take.
Taken from http://www.libqb.org/wiki/index.php/Todo_List which I'll keep up-to-date.
Please feel free to suggest any other ideas / suggestions.
==== Ongoing items ====
* coding style
** basically kernel coding style
** define a return code coding style for API
** work towards consistency by 1.0
* Write unit test cases for as much code as possible.
* document all API using doxygen in the headers
* wiki: FAQ
==== libqb-0.1.0 ====
* code: change all ints to [u]intXX_t
* wiki: contributer howto (coding style)
==== libqb-0.2.0 ====
* code: Make sure the poll loop and IPC system can safely operate in other threading models (not
* just corosync).
** Have a close look at the poll loop.
** Create a way of safely passing jobs/messages from thread to thread.
==== libqb-0.3.0 ====
* code: I want to make the IPC API easier to use.
** The server side takes ~300 lines to setup. I want it easier to use.
==== libqb-0.4.0 ====
* code: Implement atomic_get/set/incr functions (or copy from glib/libatomic/...).
** Use these instead of shared locks in the ringbuffer.
** Use these in the handle db instead of locks for reference counters.
==== libqb-0.5.0 ====
* code: simplify / cleanup logsys
==== libqb-0.6.0 ====
* code: data structures
** cleanup make the API more consistent.
** should there be locking in the data structures (easy of use/flexibility)?
==== libqb-0.7.0 ====
* code: Provide some integration (or at least examples) with glib and libevent.
* code/docs: C examples
* infrastructure: buildbot
==== libqb-0.8.0 ... libqb-1.0.0 ====
* code: support porting corosync-3.0 (and any other project) to libqb
* code: Write lots of unit test cases.
* wiki: support - user howto - links to doxygen
Regards
Angus Salkeld
13 years, 9 months
[PATCH 1/3] ipc: convert int -> int32_t; unsigned int -> uint32_t
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbipcc.h | 16 ++--
include/qb/qbipcs.h | 56 +++++++-------
lib/ipcc.c | 92 ++++++++++++-----------
lib/ipcs.c | 205 +++++++++++++++++++++++++--------------------------
4 files changed, 184 insertions(+), 185 deletions(-)
diff --git a/include/qb/qbipcc.h b/include/qb/qbipcc.h
index 517a23b..4ccc626 100644
--- a/include/qb/qbipcc.h
+++ b/include/qb/qbipcc.h
@@ -36,37 +36,37 @@ extern "C" {
int32_t
qb_ipcc_service_connect(const char *socket_name,
- unsigned int service,
+ uint32_t service,
size_t request_size,
size_t respnse__size,
size_t dispatch_size, qb_hdb_handle_t * handle);
int32_t qb_ipcc_service_disconnect(qb_hdb_handle_t handle);
-int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int *fd);
+int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int32_t * fd);
-int32_t qb_ipcc_dispatch_get(qb_hdb_handle_t handle, void **buf, int timeout);
+int32_t qb_ipcc_dispatch_get(qb_hdb_handle_t handle, void **buf,
+ int32_t timeout);
int32_t qb_ipcc_dispatch_put(qb_hdb_handle_t handle);
int32_t
qb_ipcc_dispatch_flow_control_get(qb_hdb_handle_t handle,
- unsigned int *flow_control_state);
+ uint32_t * flow_control_state);
int32_t
qb_ipcc_msg_send(qb_hdb_handle_t handle,
- const struct iovec *iov, unsigned int iov_len);
+ const struct iovec *iov, uint32_t iov_len);
int32_t
qb_ipcc_msg_send_reply_receive(qb_hdb_handle_t handle,
const struct iovec *iov,
- unsigned int iov_len,
- void *res_msg, size_t res_len);
+ uint32_t iov_len, void *res_msg, size_t res_len);
int32_t
qb_ipcc_msg_send_reply_receive_in_buf_get(qb_hdb_handle_t handle,
const struct iovec *iov,
- unsigned int iov_len, void **res_msg);
+ uint32_t iov_len, void **res_msg);
int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_hdb_handle_t handle);
diff --git a/include/qb/qbipcs.h b/include/qb/qbipcs.h
index 8292076..ed6f5c0 100644
--- a/include/qb/qbipcs.h
+++ b/include/qb/qbipcs.h
@@ -33,36 +33,36 @@ extern "C" {
struct iovec;
-typedef int (*qb_ipcs_init_fn_lvalue) (void *conn);
-typedef int (*qb_ipcs_exit_fn_lvalue) (void *conn);
+typedef int32_t(*qb_ipcs_init_fn_lvalue) (void *conn);
+typedef int32_t(*qb_ipcs_exit_fn_lvalue) (void *conn);
typedef void (*qb_ipcs_handler_fn_lvalue) (void *conn, const void *msg);
struct qb_ipcs_init_state {
const char *socket_name;
- int sched_policy;
+ int32_t sched_policy;
const struct sched_param *sched_param;
void *(*malloc) (size_t size);
void (*free) (void *ptr);
- int (*service_available) (unsigned int service);
- int (*private_data_size_get) (unsigned int service);
- int (*security_valid) (int uid, int gid);
+ int32_t(*service_available) (uint32_t service);
+ int32_t(*private_data_size_get) (uint32_t service);
+ int32_t(*security_valid) (int32_t uid, int32_t gid);
void (*serialize_lock) (void);
void (*serialize_unlock) (void);
- int (*sending_allowed) (unsigned int service, unsigned int id,
- const void *msg,
- void *sending_allowed_private_data);
+ int32_t(*sending_allowed) (uint32_t service, uint32_t id,
+ const void *msg,
+ void *sending_allowed_private_data);
void (*sending_allowed_release) (void *sending_allowed_private_data);
- void (*poll_accept_add) (int fd);
- void (*poll_dispatch_add) (int fd, void *context);
- void (*poll_dispatch_modify) (int fd, int events);
- void (*poll_dispatch_destroy) (int fd, void *context);
+ void (*poll_accept_add) (int32_t fd);
+ void (*poll_dispatch_add) (int32_t fd, void *context);
+ void (*poll_dispatch_modify) (int32_t fd, int32_t events);
+ void (*poll_dispatch_destroy) (int32_t fd, void *context);
void (*fatal_error) (const char *error_msg);
- qb_ipcs_init_fn_lvalue(*init_fn_get) (unsigned int service);
- qb_ipcs_exit_fn_lvalue(*exit_fn_get) (unsigned int service);
- qb_ipcs_handler_fn_lvalue(*handler_fn_get) (unsigned int service,
- unsigned int id);
- qb_hdb_handle_t(*stats_create_connection) (const char *name, pid_t pid,
- int fd);
+ qb_ipcs_init_fn_lvalue(*init_fn_get) (uint32_t service);
+ qb_ipcs_exit_fn_lvalue(*exit_fn_get) (uint32_t service);
+ qb_ipcs_handler_fn_lvalue(*handler_fn_get) (uint32_t service,
+ uint32_t id);
+ qb_hdb_handle_t(*stats_create_connection) (const char *name, pid_t pid,
+ int32_t fd);
void (*stats_destroy_connection) (qb_hdb_handle_t handle);
void (*stats_update_value) (qb_hdb_handle_t handle,
const char *name, const void *value,
@@ -77,15 +77,15 @@ void qb_ipcs_ipc_init(struct qb_ipcs_init_state *init_state);
void *qb_ipcs_private_data_get(void *conn);
-int qb_ipcs_response_send(void *conn, const void *msg, size_t mlen);
+int32_t qb_ipcs_response_send(void *conn, const void *msg, size_t mlen);
-int qb_ipcs_response_iov_send(void *conn,
- const struct iovec *iov, unsigned int iov_len);
+int32_t qb_ipcs_response_iov_send(void *conn,
+ const struct iovec *iov, uint32_t iov_len);
-int qb_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen);
+int32_t qb_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen);
-int qb_ipcs_dispatch_iov_send(void *conn,
- const struct iovec *iov, unsigned int iov_len);
+int32_t qb_ipcs_dispatch_iov_send(void *conn,
+ const struct iovec *iov, uint32_t iov_len);
void qb_ipcs_refcount_inc(void *conn);
@@ -93,11 +93,11 @@ void qb_ipcs_refcount_dec(void *conn);
void qb_ipcs_ipc_exit(void);
-int qb_ipcs_ipc_service_exit(unsigned int service);
+int32_t qb_ipcs_ipc_service_exit(uint32_t service);
-int qb_ipcs_handler_accept(int fd, int revent, void *context);
+int32_t qb_ipcs_handler_accept(int32_t fd, int32_t revent, void *context);
-int qb_ipcs_handler_dispatch(int fd, int revent, void *context);
+int32_t qb_ipcs_handler_dispatch(int32_t fd, int32_t revent, void *context);
/* *INDENT-OFF* */
#ifdef __cplusplus
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 259f4be..e35f570 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -43,13 +43,13 @@
#define IPC_SEMWAIT_TIMEOUT 2
struct ipc_instance {
- int fd;
+ int32_t fd;
#if _POSIX_THREAD_PROCESS_SHARED < 1
- int semid;
+ int32_t semid;
#endif
- int flow_control_state;
+ int32_t flow_control_state;
struct control_buffer *control_buffer;
- qb_ringbuffer_t * request_rb;
+ qb_ringbuffer_t *request_rb;
char *response_buffer;
char *dispatch_buffer;
size_t control_size;
@@ -71,9 +71,9 @@ DECLARE_HDB_DATABASE(ipc_hdb, ipc_hdb_destructor);
#endif
#ifdef SO_NOSIGPIPE
-static void socket_nosigpipe(int s)
+static void socket_nosigpipe(int32_t s)
{
- int on = 1;
+ int32_t on = 1;
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on));
}
#endif
@@ -82,14 +82,14 @@ static void socket_nosigpipe(int s)
#define MSG_NOSIGNAL 0
#endif
-static int32_t socket_send(int s, void *msg, size_t len)
+static int32_t socket_send(int32_t s, void *msg, size_t len)
{
int32_t res = 0;
- int result;
+ int32_t result;
struct msghdr msg_send;
struct iovec iov_send;
char *rbuf = msg;
- int processed = 0;
+ int32_t processed = 0;
msg_send.msg_iov = &iov_send;
msg_send.msg_iovlen = 1;
@@ -135,14 +135,14 @@ res_exit:
return (res);
}
-static int32_t socket_recv(int s, void *msg, size_t len)
+static int32_t socket_recv(int32_t s, void *msg, size_t len)
{
int32_t res = 0;
- int result;
+ int32_t result;
struct msghdr msg_recv;
struct iovec iov_recv;
char *rbuf = msg;
- int processed = 0;
+ int32_t processed = 0;
msg_recv.msg_iov = &iov_recv;
msg_recv.msg_iovlen = 1;
@@ -195,11 +195,11 @@ res_exit:
}
#if _POSIX_THREAD_PROCESS_SHARED < 1
-static int priv_change_send(struct ipc_instance *ipc_instance)
+static int32_t priv_change_send(struct ipc_instance *ipc_instance)
{
char buf_req;
mar_req_priv_change req_priv_change;
- unsigned int res;
+ int32_t res;
req_priv_change.euid = geteuid();
/*
@@ -228,21 +228,21 @@ static int priv_change_send(struct ipc_instance *ipc_instance)
#if defined(_SEM_SEMUN_UNDEFINED)
union semun {
- int val;
+ int32_t val;
struct semid_ds *buf;
- unsigned short int *array;
+ unsigned short int32_t *array;
struct seminfo *__buf;
};
#endif
#endif
-static int
+static int32_t
circular_memory_map(char *path, const char *file, void **buf, size_t bytes)
{
- int fd;
+ int32_t fd;
void *addr_orig;
void *addr;
- int res;
+ int32_t res;
sprintf(path, "/dev/shm/%s", file);
@@ -301,7 +301,7 @@ circular_memory_map(char *path, const char *file, void **buf, size_t bytes)
static void memory_unmap(void *addr, size_t bytes)
{
- int res;
+ int32_t res;
res = munmap(addr, bytes);
}
@@ -321,12 +321,13 @@ void ipc_hdb_destructor(void *context)
(ipc_instance->dispatch_size) << 1);
}
-static int memory_map(char *path, const char *file, void **buf, size_t bytes)
+static int32_t memory_map(char *path, const char *file, void **buf,
+ size_t bytes)
{
- int fd;
+ int32_t fd;
void *addr_orig;
void *addr;
- int res;
+ int32_t res;
sprintf(path, "/dev/shm/%s", file);
@@ -374,7 +375,7 @@ static int memory_map(char *path, const char *file, void **buf, size_t bytes)
static int32_t
msg_send(struct ipc_instance *ipc_instance,
- const struct iovec *iov, unsigned int iov_len)
+ const struct iovec *iov, uint32_t iov_len)
{
int32_t i;
size_t size = 0;
@@ -399,7 +400,7 @@ msg_send(struct ipc_instance *ipc_instance,
return qb_rb_chunk_commit(ipc_instance->request_rb, size);
}
-static int32_t ipc_sem_wait(struct ipc_instance *ipc_instance, int sem_num)
+static int32_t ipc_sem_wait(struct ipc_instance *ipc_instance, int32_t sem_num)
{
#if _POSIX_THREAD_PROCESS_SHARED < 1
struct sembuf sop;
@@ -408,7 +409,7 @@ static int32_t ipc_sem_wait(struct ipc_instance *ipc_instance, int sem_num)
struct pollfd pfd;
sem_t *sem = NULL;
#endif
- int res;
+ int32_t res;
#if _POSIX_THREAD_PROCESS_SHARED > 0
switch (sem_num) {
@@ -511,12 +512,12 @@ reply_receive_in_buf(struct ipc_instance *ipc_instance, void **res_msg)
*/
int32_t
qb_ipcc_service_connect(const char *socket_name,
- unsigned int service,
+ uint32_t service,
size_t request_size,
size_t response_size,
size_t dispatch_size, qb_hdb_handle_t * handle)
{
- int request_fd;
+ int32_t request_fd;
struct sockaddr_un address;
int32_t res;
struct ipc_instance *ipc_instance;
@@ -524,7 +525,7 @@ qb_ipcc_service_connect(const char *socket_name,
key_t semkey = 0;
union semun semun;
#endif
- int sys_res;
+ int32_t sys_res;
mar_req_setup_t req_setup;
mar_res_setup_t res_setup;
char control_map_path[128];
@@ -585,8 +586,9 @@ qb_ipcc_service_connect(const char *socket_name,
/* RB request */
ipc_instance->request_rb = qb_rb_open("request_ringbuffer-XXXXXX",
- request_size,
- QB_RB_FLAG_CREATE|QB_RB_FLAG_SHARED_PROCESS);
+ request_size,
+ QB_RB_FLAG_CREATE |
+ QB_RB_FLAG_SHARED_PROCESS);
if (ipc_instance->request_rb == NULL) {
res = EBADE;
goto error_request_buffer;
@@ -735,7 +737,7 @@ int32_t qb_ipcc_service_disconnect(qb_hdb_handle_t handle)
int32_t
qb_ipcc_dispatch_flow_control_get(qb_hdb_handle_t handle,
- unsigned int *flow_control_state)
+ uint32_t * flow_control_state)
{
struct ipc_instance *ipc_instance;
int32_t res;
@@ -751,7 +753,7 @@ qb_ipcc_dispatch_flow_control_get(qb_hdb_handle_t handle,
return (res);
}
-int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int *fd)
+int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int32_t * fd)
{
struct ipc_instance *ipc_instance;
int32_t res;
@@ -767,13 +769,14 @@ int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int *fd)
return (res);
}
-int32_t qb_ipcc_dispatch_get(qb_hdb_handle_t handle, void **data, int timeout)
+int32_t qb_ipcc_dispatch_get(qb_hdb_handle_t handle, void **data,
+ int32_t timeout)
{
struct pollfd ufds;
- int poll_events;
+ int32_t poll_events;
char buf;
struct ipc_instance *ipc_instance;
- int res;
+ int32_t res;
char buf_two = 1;
char *data_addr;
int32_t error = 0;
@@ -864,7 +867,7 @@ int32_t qb_ipcc_dispatch_put(qb_hdb_handle_t handle)
struct ipc_instance *ipc_instance;
int32_t res;
char *addr;
- unsigned int read_idx;
+ uint32_t read_idx;
res =
qb_hdb_handle_get_always(&ipc_hdb, handle, (void **)&ipc_instance);
@@ -896,7 +899,7 @@ error_exit:
int32_t
qb_ipcc_msg_send(qb_hdb_handle_t handle,
- const struct iovec * iov, unsigned int iov_len)
+ const struct iovec * iov, uint32_t iov_len)
{
int32_t res;
struct ipc_instance *ipc_instance;
@@ -919,8 +922,7 @@ qb_ipcc_msg_send(qb_hdb_handle_t handle,
int32_t
qb_ipcc_msg_send_reply_receive(qb_hdb_handle_t handle,
const struct iovec * iov,
- unsigned int iov_len,
- void *res_msg, size_t res_len)
+ uint32_t iov_len, void *res_msg, size_t res_len)
{
int32_t res;
struct ipc_instance *ipc_instance;
@@ -949,9 +951,9 @@ error_exit:
int32_t
qb_ipcc_msg_send_reply_receive_in_buf_get(qb_hdb_handle_t handle,
const struct iovec * iov,
- unsigned int iov_len, void **res_msg)
+ uint32_t iov_len, void **res_msg)
{
- unsigned int res;
+ int32_t res;
struct ipc_instance *ipc_instance;
res = qb_hdb_handle_get(&ipc_hdb, handle, (void **)&ipc_instance);
@@ -976,7 +978,7 @@ error_exit:
int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_hdb_handle_t handle)
{
- unsigned int res;
+ int32_t res;
struct ipc_instance *ipc_instance;
res = qb_hdb_handle_get(&ipc_hdb, handle, (void **)&ipc_instance);
@@ -996,7 +998,7 @@ qb_ipcc_zcb_alloc(qb_hdb_handle_t handle,
struct ipc_instance *ipc_instance;
void *buf = NULL;
char path[128];
- unsigned int res;
+ int32_t res;
mar_req_qb_ipcc_zc_alloc_t req_qb_ipcc_zc_alloc;
qb_ipc_response_header_t res_qb_ipcs_zc_alloc;
size_t map_size;
@@ -1039,7 +1041,7 @@ int32_t qb_ipcc_zcb_free(qb_hdb_handle_t handle, void *buffer)
mar_req_qb_ipcc_zc_free_t req_qb_ipcc_zc_free;
qb_ipc_response_header_t res_qb_ipcs_zc_free;
struct iovec iovec;
- unsigned int res;
+ int32_t res;
struct qb_ipcs_zc_header *header =
(struct qb_ipcs_zc_header *)((char *)buffer -
sizeof(struct qb_ipcs_zc_header));
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 8f9cf8f..296d668 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -76,9 +76,9 @@ struct zcb_mapped {
#if _POSIX_THREAD_PROCESS_SHARED < 1
#if defined(_SEM_SEMUN_UNDEFINED)
union semun {
- int val;
+ int32_t val;
struct semid_ds *buf;
- unsigned short int *array;
+ unsigned short int32_t *array;
struct seminfo *__buf;
};
#endif
@@ -94,21 +94,21 @@ enum conn_state {
};
struct conn_info {
- int fd;
+ int32_t fd;
pthread_t thread;
pid_t client_pid;
pthread_attr_t thread_attr;
- unsigned int service;
+ uint32_t service;
enum conn_state state;
- int notify_flow_control_enabled;
- int flow_control_state;
- int refcount;
+ int32_t notify_flow_control_enabled;
+ int32_t flow_control_state;
+ int32_t refcount;
qb_hdb_handle_t stats_handle;
#if _POSIX_THREAD_PROCESS_SHARED < 1
key_t semkey;
- int semid;
+ int32_t semid;
#endif
- unsigned int pending_semops;
+ uint32_t pending_semops;
pthread_mutex_t mutex;
struct control_buffer *control_buffer;
qb_ringbuffer_t *request_rb;
@@ -122,24 +122,25 @@ struct conn_info {
void *private_data;
struct qb_list_head list;
char setup_msg[sizeof(mar_req_setup_t)];
- unsigned int setup_bytes_read;
+ uint32_t setup_bytes_read;
struct qb_list_head zcb_mapped_qb_list_head;
char *sending_allowed_private_data[64];
};
-static int shared_mem_dispatch_bytes_left(const struct conn_info *conn_info);
+static int32_t shared_mem_dispatch_bytes_left(const struct conn_info
+ *conn_info);
static void outq_flush(struct conn_info *conn_info);
-static int priv_change(struct conn_info *conn_info);
+static int32_t priv_change(struct conn_info *conn_info);
static void ipc_disconnect(struct conn_info *conn_info);
-static void msg_send(void *conn, const struct iovec *iov, unsigned int iov_len,
- int locked);
+static void msg_send(void *conn, const struct iovec *iov, uint32_t iov_len,
+ int32_t locked);
static qb_hdb_handle_t dummy_stats_create_connection(const char *name,
- pid_t pid, int fd)
+ pid_t pid, int32_t fd)
{
return (0ULL);
}
@@ -167,12 +168,12 @@ static void sem_post_exit_thread(struct conn_info *conn_info)
qb_rb_chunk_write(conn_info->request_rb, conn_info, 4);
}
-static int memory_map(const char *path, size_t bytes, void **buf)
+static int32_t memory_map(const char *path, size_t bytes, void **buf)
{
- int fd;
+ int32_t fd;
void *addr_orig;
void *addr;
- int res;
+ int32_t res;
fd = open(path, O_RDWR, 0600);
@@ -215,12 +216,12 @@ static int memory_map(const char *path, size_t bytes, void **buf)
return (0);
}
-static int circular_memory_map(const char *path, size_t bytes, void **buf)
+static int32_t circular_memory_map(const char *path, size_t bytes, void **buf)
{
- int fd;
+ int32_t fd;
void *addr_orig;
void *addr;
- int res;
+ int32_t res;
fd = open(path, O_RDWR, 0600);
@@ -273,18 +274,18 @@ static int circular_memory_map(const char *path, size_t bytes, void **buf)
return (0);
}
-static inline int circular_memory_unmap(void *buf, size_t bytes)
+static inline int32_t circular_memory_unmap(void *buf, size_t bytes)
{
- int res;
+ int32_t res;
res = munmap(buf, bytes << 1);
return (res);
}
-static inline int zcb_free(struct zcb_mapped *zcb_mapped)
+static inline int32_t zcb_free(struct zcb_mapped *zcb_mapped)
{
- unsigned int res;
+ uint32_t res;
res = munmap(zcb_mapped->addr, zcb_mapped->size);
qb_list_del(&zcb_mapped->list);
@@ -292,11 +293,11 @@ static inline int zcb_free(struct zcb_mapped *zcb_mapped)
return (res);
}
-static inline int zcb_by_addr_free(struct conn_info *conn_info, void *addr)
+static inline int32_t zcb_by_addr_free(struct conn_info *conn_info, void *addr)
{
struct qb_list_head *list;
struct zcb_mapped *zcb_mapped;
- unsigned int res = 0;
+ uint32_t res = 0;
for (list = conn_info->zcb_mapped_qb_list_head.next;
list != &conn_info->zcb_mapped_qb_list_head; list = list->next) {
@@ -312,7 +313,7 @@ static inline int zcb_by_addr_free(struct conn_info *conn_info, void *addr)
return (res);
}
-static inline int zcb_all_free(struct conn_info *conn_info)
+static inline int32_t zcb_all_free(struct conn_info *conn_info)
{
struct qb_list_head *list;
struct zcb_mapped *zcb_mapped;
@@ -329,11 +330,12 @@ static inline int zcb_all_free(struct conn_info *conn_info)
return (0);
}
-static inline int zcb_alloc(struct conn_info *conn_info,
- const char *path_to_file, size_t size, void **addr)
+static inline int32_t zcb_alloc(struct conn_info *conn_info,
+ const char *path_to_file,
+ size_t size, void **addr)
{
struct zcb_mapped *zcb_mapped;
- unsigned int res;
+ uint32_t res;
zcb_mapped = malloc(sizeof(struct zcb_mapped));
if (zcb_mapped == NULL) {
@@ -354,10 +356,10 @@ static inline int zcb_alloc(struct conn_info *conn_info,
return (0);
}
-static int ipc_thread_active(void *conn)
+static int32_t ipc_thread_active(void *conn)
{
struct conn_info *conn_info = (struct conn_info *)conn;
- int retval = 0;
+ int32_t retval = 0;
pthread_mutex_lock(&conn_info->mutex);
if (conn_info->state == CONN_STATE_THREAD_ACTIVE) {
@@ -367,10 +369,10 @@ static int ipc_thread_active(void *conn)
return (retval);
}
-static int ipc_thread_exiting(void *conn)
+static int32_t ipc_thread_exiting(void *conn)
{
struct conn_info *conn_info = (struct conn_info *)conn;
- int retval = 1;
+ int32_t retval = 1;
pthread_mutex_lock(&conn_info->mutex);
if (conn_info->state == CONN_STATE_THREAD_INACTIVE) {
@@ -385,9 +387,9 @@ static int ipc_thread_exiting(void *conn)
/*
* returns 0 if should be called again, -1 if finished
*/
-static inline int conn_info_destroy(struct conn_info *conn_info)
+static inline int32_t conn_info_destroy(struct conn_info *conn_info)
{
- unsigned int res;
+ uint32_t res;
void *retval;
qb_list_del(&conn_info->list);
@@ -491,9 +493,8 @@ static void *serveraddr2void(uint64_t server_addr)
};
static void zerocopy_operations_process(struct conn_info *conn_info,
- qb_ipc_request_header_t **
- header_out,
- unsigned int *new_message)
+ qb_ipc_request_header_t **
+ header_out, uint32_t * new_message)
{
qb_ipc_request_header_t *header;
@@ -504,7 +505,7 @@ static void zerocopy_operations_process(struct conn_info *conn_info,
qb_ipc_response_header_t res_header;
void *addr = NULL;
struct qb_ipcs_zc_header *zc_header;
- unsigned int res;
+ uint32_t res;
res = zcb_alloc(conn_info, hdr->path_to_file, hdr->map_size,
&addr);
@@ -554,6 +555,7 @@ static void *pthread_ipc_consumer(void *conn)
int32_t send_ok;
uint32_t new_message;
ssize_t size;
+ void *pri_data = NULL;
#if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
if (api->sched_policy != 0) {
@@ -564,10 +566,10 @@ static void *pthread_ipc_consumer(void *conn)
#endif
for (;;) {
- size = qb_rb_chunk_peek(conn_info->request_rb, (void**)&header, 2000);
+ size = qb_rb_chunk_peek(conn_info->request_rb,
+ (void **)&header, 2000);
if (ipc_thread_active(conn_info) == 0) {
- qb_util_log(LOG_DEBUG,"thread not active");
qb_ipcs_refcount_dec(conn_info);
pthread_exit(0);
}
@@ -588,18 +590,16 @@ static void *pthread_ipc_consumer(void *conn)
qb_ipcs_refcount_inc(conn);
+ pri_data = conn_info->sending_allowed_private_data;
send_ok = api->sending_allowed(conn_info->service,
- header->id,
- header,
- conn_info->sending_allowed_private_data);
+ header->id, header, pri_data);
/*
* This happens when the message contains some kind of invalid
* parameter, such as an invalid size
*/
if (send_ok == -1) {
- response_header.size =
- sizeof(qb_ipc_response_header_t);
+ response_header.size = sizeof(qb_ipc_response_header_t);
response_header.id = 0;
response_header.error = EINVAL;
qb_ipcs_response_send(conn_info,
@@ -620,8 +620,7 @@ static void *pthread_ipc_consumer(void *conn)
*/
api->stats_increment_value(conn_info->stats_handle,
"sem_retry_count");
- response_header.size =
- sizeof(qb_ipc_response_header_t);
+ response_header.size = sizeof(qb_ipc_response_header_t);
response_header.id = 0;
response_header.error = EAGAIN;
qb_ipcs_response_send(conn_info,
@@ -630,18 +629,17 @@ static void *pthread_ipc_consumer(void *conn)
qb_rb_chunk_reclaim(conn_info->request_rb);
}
- api->
- sending_allowed_release
+ api->sending_allowed_release
(conn_info->sending_allowed_private_data);
qb_ipcs_refcount_dec(conn);
}
pthread_exit(0);
}
-static int req_setup_send(struct conn_info *conn_info, int error)
+static int32_t req_setup_send(struct conn_info *conn_info, int32_t error)
{
mar_res_setup_t res_setup;
- unsigned int res;
+ uint32_t res;
memset(&res_setup, 0, sizeof(res_setup));
res_setup.error = error;
@@ -662,18 +660,18 @@ retry_send:
return (0);
}
-static int req_setup_recv(struct conn_info *conn_info)
+static int32_t req_setup_recv(struct conn_info *conn_info)
{
- int res;
+ int32_t res;
struct msghdr msg_recv;
struct iovec iov_recv;
- int authenticated = 0;
+ int32_t authenticated = 0;
#ifdef QB_LINUX
struct cmsghdr *cmsg;
char cmsg_cred[CMSG_SPACE(sizeof(struct ucred))];
- int off = 0;
- int on = 1;
+ int32_t off = 0;
+ int32_t on = 1;
struct ucred *cred;
#endif
@@ -814,7 +812,7 @@ static void ipc_disconnect(struct conn_info *conn_info)
sem_post_exit_thread(conn_info);
}
-static int conn_info_create(int fd)
+static int32_t conn_info_create(int32_t fd)
{
struct conn_info *conn_info;
@@ -851,9 +849,9 @@ static int conn_info_create(int fd)
*/
extern void qb_ipcs_ipc_init(struct qb_ipcs_init_state *init_state)
{
- int server_fd;
+ int32_t server_fd;
struct sockaddr_un un_addr;
- int res;
+ int32_t res;
api = init_state;
api->stats_create_connection = dummy_stats_create_connection;
@@ -938,7 +936,7 @@ void qb_ipcs_ipc_exit(void)
{
struct qb_list_head *list;
struct conn_info *conn_info;
- unsigned int res;
+ uint32_t res;
for (list = conn_info_qb_list_head.next;
list != &conn_info_qb_list_head; list = list->next) {
@@ -970,7 +968,7 @@ void qb_ipcs_ipc_exit(void)
}
}
-int qb_ipcs_ipc_service_exit(unsigned int service)
+int32_t qb_ipcs_ipc_service_exit(uint32_t service)
{
struct qb_list_head *list, *list_next;
struct conn_info *conn_info;
@@ -1025,13 +1023,13 @@ void *qb_ipcs_private_data_get(void *conn)
return (conn_info->private_data);
}
-int qb_ipcs_response_send(void *conn, const void *msg, size_t mlen)
+int32_t qb_ipcs_response_send(void *conn, const void *msg, size_t mlen)
{
struct conn_info *conn_info = (struct conn_info *)conn;
#if _POSIX_THREAD_PROCESS_SHARED < 1
struct sembuf sop;
#endif
- int res;
+ int32_t res;
memcpy(conn_info->response_buffer, msg, mlen);
@@ -1059,16 +1057,16 @@ retry_semop:
return (0);
}
-int qb_ipcs_response_iov_send(void *conn, const struct iovec *iov,
- unsigned int iov_len)
+int32_t qb_ipcs_response_iov_send(void *conn, const struct iovec * iov,
+ uint32_t iov_len)
{
struct conn_info *conn_info = (struct conn_info *)conn;
#if _POSIX_THREAD_PROCESS_SHARED < 1
struct sembuf sop;
#endif
- int res;
- int write_idx = 0;
- int i;
+ int32_t res;
+ int32_t write_idx = 0;
+ int32_t i;
for (i = 0; i < iov_len; i++) {
memcpy(&conn_info->response_buffer[write_idx],
@@ -1100,11 +1098,11 @@ retry_semop:
return (0);
}
-static int shared_mem_dispatch_bytes_left(const struct conn_info *conn_info)
+static int32_t shared_mem_dispatch_bytes_left(const struct conn_info *conn_info)
{
- unsigned int n_read;
- unsigned int n_write;
- unsigned int bytes_left;
+ uint32_t n_read;
+ uint32_t n_write;
+ uint32_t bytes_left;
n_read = conn_info->control_buffer->read;
n_write = conn_info->control_buffer->write;
@@ -1121,10 +1119,9 @@ static int shared_mem_dispatch_bytes_left(const struct conn_info *conn_info)
return (bytes_left);
}
-static void memcpy_dwrap(struct conn_info *conn_info, void *msg,
- unsigned int len)
+static void memcpy_dwrap(struct conn_info *conn_info, void *msg, uint32_t len)
{
- unsigned int write_idx;
+ uint32_t write_idx;
write_idx = conn_info->control_buffer->write;
@@ -1136,9 +1133,9 @@ static void memcpy_dwrap(struct conn_info *conn_info, void *msg,
/**
* simulate the behaviour in qb_ipcc.c
*/
-static int flow_control_event_send(struct conn_info *conn_info, char event)
+static int32_t flow_control_event_send(struct conn_info *conn_info, char event)
{
- int new_fc = 0;
+ int32_t new_fc = 0;
if (event == MESSAGE_RES_OUTQ_NOT_EMPTY ||
event == MESSAGE_RES_ENABLE_FLOWCONTROL) {
@@ -1166,15 +1163,15 @@ static int flow_control_event_send(struct conn_info *conn_info, char event)
return send(conn_info->fd, &event, 1, MSG_NOSIGNAL);
}
-static void msg_send(void *conn, const struct iovec *iov, unsigned int iov_len,
- int locked)
+static void msg_send(void *conn, const struct iovec *iov, uint32_t iov_len,
+ int32_t locked)
{
struct conn_info *conn_info = (struct conn_info *)conn;
#if _POSIX_THREAD_PROCESS_SHARED < 1
struct sembuf sop;
#endif
- int res;
- int i;
+ int32_t res;
+ int32_t i;
for (i = 0; i < iov_len; i++) {
memcpy_dwrap(conn_info, iov[i].iov_base, iov[i].iov_len);
@@ -1225,9 +1222,9 @@ static void outq_flush(struct conn_info *conn_info)
{
struct qb_list_head *list, *list_next;
struct outq_item *outq_item;
- unsigned int bytes_left;
+ uint32_t bytes_left;
struct iovec iov;
- int res;
+ int32_t res;
pthread_mutex_lock(&conn_info->mutex);
if (qb_list_empty(&conn_info->outq_head)) {
@@ -1259,14 +1256,14 @@ static void outq_flush(struct conn_info *conn_info)
pthread_mutex_unlock(&conn_info->mutex);
}
-static int priv_change(struct conn_info *conn_info)
+static int32_t priv_change(struct conn_info *conn_info)
{
mar_req_priv_change req_priv_change;
- unsigned int res;
+ uint32_t res;
#if _POSIX_THREAD_PROCESS_SHARED < 1
union semun semun;
struct semid_ds ipc_set;
- int i;
+ int32_t i;
#endif
retry_recv:
@@ -1311,12 +1308,12 @@ retry_recv:
}
static void msg_send_or_queue(void *conn, const struct iovec *iov,
- unsigned int iov_len)
+ uint32_t iov_len)
{
struct conn_info *conn_info = (struct conn_info *)conn;
- unsigned int bytes_left;
- unsigned int bytes_msg = 0;
- int i;
+ uint32_t bytes_left;
+ uint32_t bytes_msg = 0;
+ int32_t i;
struct outq_item *outq_item;
char *write_buf = 0;
@@ -1384,7 +1381,7 @@ void qb_ipcs_refcount_dec(void *conn)
pthread_mutex_unlock(&conn_info->mutex);
}
-int qb_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen)
+int32_t qb_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen)
{
struct iovec iov;
@@ -1395,22 +1392,22 @@ int qb_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen)
return (0);
}
-int qb_ipcs_dispatch_iov_send(void *conn, const struct iovec *iov,
- unsigned int iov_len)
+int32_t qb_ipcs_dispatch_iov_send(void *conn, const struct iovec * iov,
+ uint32_t iov_len)
{
msg_send_or_queue(conn, iov, iov_len);
return (0);
}
-int qb_ipcs_handler_accept(int fd, int revent, void *data)
+int32_t qb_ipcs_handler_accept(int32_t fd, int32_t revent, void *data)
{
socklen_t addrlen;
struct sockaddr_un un_addr;
- int new_fd;
+ int32_t new_fd;
#ifdef QB_LINUX
- int on = 1;
+ int32_t on = 1;
#endif
- int res;
+ int32_t res;
addrlen = sizeof(struct sockaddr_un);
@@ -1524,11 +1521,11 @@ static void qb_ipcs_init_conn_stats(struct conn_info *conn)
&conn->service, sizeof(conn->service));
}
-int qb_ipcs_handler_dispatch(int fd, int revent, void *context)
+int32_t qb_ipcs_handler_dispatch(int32_t fd, int32_t revent, void *context)
{
mar_req_setup_t *req_setup;
struct conn_info *conn_info = (struct conn_info *)context;
- int res;
+ int32_t res;
char buf;
if (ipc_thread_exiting(conn_info)) {
@@ -1581,8 +1578,8 @@ int qb_ipcs_handler_dispatch(int fd, int revent, void *context)
conn_info->control_size = req_setup->control_size;
conn_info->request_rb = qb_rb_open(req_setup->request_file,
- req_setup->request_size,
- QB_RB_FLAG_SHARED_PROCESS);
+ req_setup->request_size,
+ QB_RB_FLAG_SHARED_PROCESS);
conn_info->request_size = req_setup->request_size;
res = memory_map(req_setup->response_file,
--
1.6.6.1
13 years, 9 months
[PATCH 1/5] rb: fix bit flag numbering
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbrb.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/qb/qbrb.h b/include/qb/qbrb.h
index eb2fccc..94aaa91 100644
--- a/include/qb/qbrb.h
+++ b/include/qb/qbrb.h
@@ -91,13 +91,13 @@ extern "C" {
* This effects the type of locks/semaphores that are used.
* @see qb_rb_open()
*/
-#define QB_RB_FLAG_SHARED_THREAD 0x03
+#define QB_RB_FLAG_SHARED_THREAD 0x04
/**
* The ringbuffer will be shared between processes.
* This effects the type of locks/semaphores that are used.
* @see qb_rb_open()
*/
-#define QB_RB_FLAG_SHARED_PROCESS 0x04
+#define QB_RB_FLAG_SHARED_PROCESS 0x08
struct qb_ringbuffer_s;
typedef struct qb_ringbuffer_s qb_ringbuffer_t;
--
1.6.6.1
13 years, 9 months
Re: [libqb] [Openais] Roadmap plans for v2.0 and v3.0
by Angus Salkeld
On Sat, Jun 12, 2010 at 01:09:07PM -0700, Steven Dake wrote:
>
> The activity of reworking those infrastructure components will take
> place in the libqb project. We will remove these infrastructure
> components from Corosync 3.0 and then depend on libqb for that
> functionality. Corosync will then only act as a HA developer toolkit
> (providing its existing API set, service engines, and protocol). Angus
> has already made some great progress in simplifying the code base and
> reusing some common design elements. One of these is the chunked ring
> buffer mechanism using shared memory. This ring buffer is implemented
> currently separately in ipc and logsys. Over time, Angus plans to
> separate out the ring buffer from these two systems. The result?
>
> Less lines of code
> Individually unit-testable components that don't require a full cluster
> to run.
> Focused performance tuning around one code base for one set of target
> designs
> Focused towards high performance client server application developers
>
> The ring buffer concept is just one idea Angus has. Angus has many
> other great ideas for simplification of the code base. I invite you to
> join in his development especially if you are interested in some real
> cutting edge posix high performance systems programming.
>
> http://www.libqb.org
>
Thanks Steve,
At the moment I am working on:
- Integrating my current ringbuffer implementation
into the IPC code in order achieve asyncronous IPC (with flow control).
Next on my list is: (not in strict order)
- I want to do is to make the IPC API easier to use.
The server side takes ~300 lines to setup. I want it
easier to use.
- Implement atomic_get/set/incr functions.
Use these instead of shared locks in the ringbuffer.
Use these in the handle db instead of locks.
- Make sure the poll loop and IPC system can safely operate in other
threading models (compared to corosync).
- Provide some integration (or at least examples) with glib and libevent.
- I have a corosync git tree that now uses libqb
1) keep that working.
2) possibly publish it so others can see how the integration is going.
3) it would be good to setup a buildbot to run the cts tests on this.
- Write lots of unit test cases.
- Document all the public API (in doxygen comments)
- Put some work into the wiki.
- Get libqb into Fedora (and other distros) so corosync can migrate to it.
Hope to see more of you on the libqb mailing list:
https://fedorahosted.org/mailman/listinfo/quarterback-devel
Post an email to the list if you want to get involved
(if you see anything above that interests you).
Regards
Angus
> Keep in mind this kind of effort is not going to happen overnight. This
> is what some of the core corosync developers have discussed for the next
> 2-3 years of development. If there are gaps we have which are not
> addressed, please let us know.
>
> Regards
> -steve
> _______________________________________________
> Openais mailing list
> Openais(a)lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/openais
13 years, 9 months
[PATCH 1/6] check_hash: test for dict/words before running.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/check_hash.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/tests/check_hash.c b/tests/check_hash.c
index 49384b4..18937aa 100644
--- a/tests/check_hash.c
+++ b/tests/check_hash.c
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <unistd.h>
#include <check.h>
#include <qb/qbhash.h>
@@ -32,6 +33,11 @@ START_TEST(test_hash_load)
void *value;
uint64_t value_len;
+ if (access("/usr/shar/dict/words", R_OK) != 0 ) {
+ printf("no dict/words - not testing\n");
+ return;
+ }
+
res = qb_hash_initialize(&handle, 17, 0);
ck_assert_int_ne(handle, 0);
--
1.6.6.1
13 years, 9 months
[PATCH] rb: cleanup of names and log messages
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/ringbuffer.c | 93 +++++++++++++++++++++++++++--------------------------
1 files changed, 47 insertions(+), 46 deletions(-)
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index 105d415..265f483 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -32,7 +32,6 @@ do { \
#define DEBUG_PRINTF(format, args...)
#endif /* CRAZY_DEBUG_PRINTFS */
-
/* the chunk header is two words
* 1) the chunk data size
* 2) the magic number
@@ -40,11 +39,13 @@ do { \
#define QB_RB_CHUNK_HEADER_WORDS 2
#define QB_RB_CHUNK_HEADER_SIZE (sizeof(uint32_t) * QB_RB_CHUNK_HEADER_WORDS)
#define QB_RB_CHUNK_MAGIC 0xAAAAAAAA
-#define QB_RB_CHUNK_SIZE_GET(rb, pointer) rb->shared_data[pointer]
-#define QB_RB_CHUNK_MAGIC_GET(rb, pointer) rb->shared_data[(pointer + 1) % rb->shared_hdr->size]
+#define QB_RB_CHUNK_SIZE_GET(rb, pointer) \
+ rb->shared_data[pointer]
+#define QB_RB_CHUNK_MAGIC_GET(rb, pointer) \
+ rb->shared_data[(pointer + 1) % rb->shared_hdr->size]
-#define FDHEAD_INDEX (rb->shared_hdr->size)
-#define FDTAIL_INDEX (rb->shared_hdr->size + 1)
+#define QB_RB_WRITE_PT_INDEX (rb->shared_hdr->size)
+#define QB_RB_READ_PT_INDEX (rb->shared_hdr->size + 1)
#define idx_step(idx) \
do { \
@@ -77,8 +78,9 @@ do { \
} while (0)
#endif
-static void _check_chunk_locked_(qb_ringbuffer_t * rb, uint32_t pointer);
+static size_t _qb_rb_space_free_locked_(qb_ringbuffer_t * rb);
static size_t _qb_rb_space_used_locked_(qb_ringbuffer_t * rb);
+static void _qb_rb_chunk_check_locked_(qb_ringbuffer_t * rb, uint32_t pointer);
static void _qb_rb_chunk_reclaim_locked_(qb_ringbuffer_t * rb);
qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t flags)
@@ -157,7 +159,7 @@ qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t flags)
goto cleanup_hdr;
}
- qb_util_log(LOG_INFO,
+ qb_util_log(LOG_DEBUG,
"shm \n size:%zd\n real_size:%zd\n rb->size:%d\n", size,
real_size, rb->shared_hdr->size);
@@ -204,14 +206,14 @@ void qb_rb_close(qb_ringbuffer_t * rb)
rb->lock_fn(rb);
rb->shared_hdr->ref_count--;
- qb_util_log(LOG_INFO, "ref_count:%d", rb->shared_hdr->ref_count);
+ qb_util_log(LOG_DEBUG, "ref_count:%d", rb->shared_hdr->ref_count);
if (rb->shared_hdr->ref_count == 0) {
destroy_it = 1;
}
rb->unlock_fn(rb);
if (destroy_it) {
- qb_util_log(LOG_INFO, "Destroying ringbuffer");
+ qb_util_log(LOG_DEBUG, "Destroying ringbuffer");
rb->lock_destroy_fn(rb);
rb->sem_destroy_fn(rb);
@@ -310,7 +312,7 @@ ssize_t qb_rb_space_used(qb_ringbuffer_t * rb)
void *qb_rb_chunk_writable_alloc(qb_ringbuffer_t * rb, size_t len)
{
- uint32_t idx;
+ uint32_t write_pt;
rb->lock_fn(rb);
/*
@@ -329,24 +331,24 @@ void *qb_rb_chunk_writable_alloc(qb_ringbuffer_t * rb, size_t len)
}
}
- idx = rb->shared_hdr->write_pt;
+ write_pt = rb->shared_hdr->write_pt;
/*
* insert the chunk header
*/
- rb->shared_data[idx++] = 0;
- idx_step(idx);
- rb->shared_data[idx++] = QB_RB_CHUNK_MAGIC;
- idx_step(idx);
+ rb->shared_data[write_pt++] = 0;
+ idx_step(write_pt);
+ rb->shared_data[write_pt++] = QB_RB_CHUNK_MAGIC;
+ idx_step(write_pt);
/*
* return a pointer to the begining of the chunk data
*/
- return (void *)&rb->shared_data[idx];
+ return (void *)&rb->shared_data[write_pt];
}
static uint32_t
-_qb_rb_chunk_step_to_next_locked_(qb_ringbuffer_t * rb, uint32_t pointer)
+_qb_rb_chunk_step_locked_(qb_ringbuffer_t * rb, uint32_t pointer)
{
uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, pointer);
/*
@@ -381,8 +383,7 @@ int32_t qb_rb_chunk_writable_commit(qb_ringbuffer_t * rb, size_t len)
/*
* commit the new write pointer
*/
- rb->shared_hdr->write_pt =
- _qb_rb_chunk_step_to_next_locked_(rb, rb->shared_hdr->write_pt);
+ rb->shared_hdr->write_pt = _qb_rb_chunk_step_locked_(rb, old_write_pt);
DEBUG_PRINTF("%s: read: %u, write: %u (was:%u)\n", __func__,
rb->shared_hdr->read_pt, rb->shared_hdr->write_pt,
@@ -408,9 +409,6 @@ ssize_t qb_rb_chunk_write(qb_ringbuffer_t * rb, const void *data, size_t len)
return -1;
}
- /*
- * copy the data
- */
memcpy(dest, data, len);
qb_rb_chunk_writable_commit(rb, len);
@@ -426,10 +424,9 @@ static void _qb_rb_chunk_reclaim_locked_(qb_ringbuffer_t * rb)
return;
}
- _check_chunk_locked_(rb, rb->shared_hdr->read_pt);
+ _qb_rb_chunk_check_locked_(rb, old_read_pt);
- rb->shared_hdr->read_pt =
- _qb_rb_chunk_step_to_next_locked_(rb, rb->shared_hdr->read_pt);
+ rb->shared_hdr->read_pt = _qb_rb_chunk_step_locked_(rb, old_read_pt);
rb->shared_hdr->count--;
/*
@@ -452,11 +449,11 @@ void qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out)
{
- uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, rb->shared_hdr->read_pt);
- uint32_t chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, rb->shared_hdr->read_pt);
+ uint32_t read_pt = rb->shared_hdr->read_pt;
+ uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, read_pt);
+ uint32_t chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, read_pt);
- *data_out =
- &rb->shared_data[rb->shared_hdr->read_pt + QB_RB_CHUNK_HEADER_WORDS];
+ *data_out = &rb->shared_data[read_pt + QB_RB_CHUNK_HEADER_WORDS];
if (chunk_magic != QB_RB_CHUNK_MAGIC) {
errno = ENODATA;
@@ -470,12 +467,16 @@ ssize_t
qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
int32_t timeout)
{
+ uint32_t read_pt;
uint32_t chunk_size;
int32_t res;
res = rb->sem_timedwait_fn(rb, timeout);
if (res == -1 && errno != EIDRM) {
- printf("%s:%d %s\n", __func__, __LINE__, strerror(errno));
+ if (errno != ETIMEDOUT) {
+ qb_util_log(LOG_ERR,
+ "sem_timedwait %s", strerror(errno));
+ }
return -1;
}
@@ -487,25 +488,24 @@ qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
return -1;
}
if (_qb_rb_space_used_locked_(rb) == 0) {
- printf("%s:%d count:%d\n", __func__, __LINE__,
- rb->shared_hdr->count);
rb->unlock_fn(rb);
errno = ENODATA;
return -1;
}
- _check_chunk_locked_(rb, rb->shared_hdr->read_pt);
- chunk_size = QB_RB_CHUNK_SIZE_GET(rb, rb->shared_hdr->read_pt);
+ read_pt = rb->shared_hdr->read_pt;
+ _qb_rb_chunk_check_locked_(rb, read_pt);
+ chunk_size = QB_RB_CHUNK_SIZE_GET(rb, read_pt);
if (len < chunk_size) {
- printf("%s:%d\n", __func__, __LINE__);
rb->unlock_fn(rb);
- return 0;
+ errno = ENOBUFS;
+ return -1;
}
memcpy(data_out,
- &rb->shared_data[rb->shared_hdr->read_pt +
- QB_RB_CHUNK_HEADER_WORDS], chunk_size);
+ &rb->shared_data[read_pt + QB_RB_CHUNK_HEADER_WORDS],
+ chunk_size);
_qb_rb_chunk_reclaim_locked_(rb);
rb->unlock_fn(rb);
@@ -529,7 +529,7 @@ static void print_header(qb_ringbuffer_t * rb)
printf(" =>used [%zu bytes]\n", qb_rb_space_used(rb));
}
-static void _check_chunk_locked_(qb_ringbuffer_t * rb, uint32_t pointer)
+static void _qb_rb_chunk_check_locked_(qb_ringbuffer_t * rb, uint32_t pointer)
{
uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, pointer);
uint32_t chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, pointer);
@@ -594,29 +594,30 @@ qb_ringbuffer_t *qb_rb_create_from_file(int32_t fd, uint32_t flags)
n_required = sizeof(uint32_t);
n_read = read(fd, &rb->shared_hdr->size, n_required);
if (n_read != n_required) {
- fprintf(stderr, "Unable to read fdata header\n");
+ qb_util_log(LOG_ERR, "Unable to read fdata header %s",
+ strerror(errno));
return NULL;
}
n_required = ((rb->shared_hdr->size + 2) * sizeof(uint32_t));
if ((rb->shared_data = malloc(n_required)) == NULL) {
- fprintf(stderr, "exhausted virtual memory\n");
+ qb_util_log(LOG_ERR, "exhausted virtual memory");
return NULL;
}
n_read = read(fd, rb->shared_data, n_required);
if (n_read < 0) {
- fprintf(stderr, "reading file failed: %s\n", strerror(errno));
+ qb_util_log(LOG_ERR, "file read failed: %s", strerror(errno));
return NULL;
}
if (n_read != n_required) {
- printf("Warning: read %lu bytes, but expected %lu\n",
- (unsigned long)n_read, (unsigned long)n_required);
+ qb_util_log(LOG_WARNING, "read %zd bytes, but expected %zu",
+ n_read, n_required);
}
- rb->shared_hdr->write_pt = rb->shared_data[FDHEAD_INDEX];
- rb->shared_hdr->read_pt = rb->shared_data[FDTAIL_INDEX];
+ rb->shared_hdr->write_pt = rb->shared_data[QB_RB_WRITE_PT_INDEX];
+ rb->shared_hdr->read_pt = rb->shared_data[QB_RB_READ_PT_INDEX];
print_header(rb);
--
1.6.6.1
13 years, 9 months
[PATCH] util: move some handy macros into qbuil.h
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbutil.h | 7 +++++++
lib/logsys.c | 6 ++----
lib/ringbuffer.c | 43 +++++++++++++++++++++----------------------
3 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/include/qb/qbutil.h b/include/qb/qbutil.h
index b878553..80b8c50 100644
--- a/include/qb/qbutil.h
+++ b/include/qb/qbutil.h
@@ -20,6 +20,8 @@
#ifndef QB_UTIL_H_DEFINED
#define QB_UTIL_H_DEFINED
+#include <stdint.h>
+
/**
* @file qbutil.h
* @author Angus Salkeld <asalkeld(a)redhat.com>
@@ -33,6 +35,11 @@ extern "C" {
#endif
/* *INDENT-ON* */
+#define QB_ROUNDUP(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#define QB_MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define QB_MIN(a, b) (((a) < (b)) ? (a) : (b))
+#define QB_FALSE (0)
+#define QB_TRUE (!QB_FALSE)
/**
* @typedef qb_thread_lock_type_t
* QB_THREAD_LOCK_SHORT is a short term lock (spinlock if available on your system)
diff --git a/lib/logsys.c b/lib/logsys.c
index 0ca68ac..280c40d 100644
--- a/lib/logsys.c
+++ b/lib/logsys.c
@@ -34,8 +34,6 @@
#include <qb/qbrb.h>
#include <qb/qblogsys.h>
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-
/*
* syslog prioritynames, facility names to value mapping
* Some C libraries build this in to their headers, but it is non-portable
@@ -259,8 +257,8 @@ static inline int32_t strcpy_cutoff(char *dest, const char *src, size_t cutoff,
cutoff = len;
}
- cutoff = MIN(cutoff, buf_len - 1);
- len = MIN(len, cutoff);
+ cutoff = QB_MIN(cutoff, buf_len - 1);
+ len = QB_MIN(len, cutoff);
memcpy(dest, src, len);
memset(dest + len, ' ', cutoff - len);
dest[cutoff] = '\0';
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index f40e9a4..105d415 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -32,17 +32,16 @@ do { \
#define DEBUG_PRINTF(format, args...)
#endif /* CRAZY_DEBUG_PRINTFS */
-#define ROUNDUP(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
/* the chunk header is two words
* 1) the chunk data size
* 2) the magic number
*/
-#define RB_CHUNK_HEADER_WORDS 2
-#define RB_CHUNK_HEADER_SIZE (sizeof(uint32_t) * RB_CHUNK_HEADER_WORDS)
-#define RB_CHUNK_MAGIC 0xAAAAAAAA
-#define CHUNK_SIZE_GET(rb, pointer) rb->shared_data[pointer]
-#define CHUNK_MAGIC_GET(rb, pointer) rb->shared_data[(pointer + 1) % rb->shared_hdr->size]
+#define QB_RB_CHUNK_HEADER_WORDS 2
+#define QB_RB_CHUNK_HEADER_SIZE (sizeof(uint32_t) * QB_RB_CHUNK_HEADER_WORDS)
+#define QB_RB_CHUNK_MAGIC 0xAAAAAAAA
+#define QB_RB_CHUNK_SIZE_GET(rb, pointer) rb->shared_data[pointer]
+#define QB_RB_CHUNK_MAGIC_GET(rb, pointer) rb->shared_data[(pointer + 1) % rb->shared_hdr->size]
#define FDHEAD_INDEX (rb->shared_hdr->size)
#define FDTAIL_INDEX (rb->shared_hdr->size + 1)
@@ -85,7 +84,7 @@ static void _qb_rb_chunk_reclaim_locked_(qb_ringbuffer_t * rb);
qb_ringbuffer_t *qb_rb_open(const char *name, size_t size, uint32_t flags)
{
struct qb_ringbuffer_s *rb = malloc(sizeof(struct qb_ringbuffer_s));
- size_t real_size = ROUNDUP(size, sysconf(_SC_PAGESIZE));
+ size_t real_size = QB_ROUNDUP(size, sysconf(_SC_PAGESIZE));
char path[PATH_MAX];
int32_t fd_hdr;
int32_t fd_data;
@@ -319,12 +318,12 @@ void *qb_rb_chunk_writable_alloc(qb_ringbuffer_t * rb, size_t len)
*/
if (rb->flags & QB_RB_FLAG_OVERWRITE) {
while (_qb_rb_space_free_locked_(rb) <
- (len + RB_CHUNK_HEADER_SIZE + 4)) {
+ (len + QB_RB_CHUNK_HEADER_SIZE + 4)) {
_qb_rb_chunk_reclaim_locked_(rb);
}
} else {
if (_qb_rb_space_free_locked_(rb) <
- (len + RB_CHUNK_HEADER_SIZE + 4)) {
+ (len + QB_RB_CHUNK_HEADER_SIZE + 4)) {
rb->unlock_fn(rb);
return NULL;
}
@@ -336,7 +335,7 @@ void *qb_rb_chunk_writable_alloc(qb_ringbuffer_t * rb, size_t len)
*/
rb->shared_data[idx++] = 0;
idx_step(idx);
- rb->shared_data[idx++] = RB_CHUNK_MAGIC;
+ rb->shared_data[idx++] = QB_RB_CHUNK_MAGIC;
idx_step(idx);
/*
@@ -349,11 +348,11 @@ void *qb_rb_chunk_writable_alloc(qb_ringbuffer_t * rb, size_t len)
static uint32_t
_qb_rb_chunk_step_to_next_locked_(qb_ringbuffer_t * rb, uint32_t pointer)
{
- uint32_t chunk_size = CHUNK_SIZE_GET(rb, pointer);
+ uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, pointer);
/*
* skip over the chunk header
*/
- pointer += RB_CHUNK_HEADER_WORDS;
+ pointer += QB_RB_CHUNK_HEADER_WORDS;
idx_step(pointer);
/*
@@ -376,7 +375,7 @@ int32_t qb_rb_chunk_writable_commit(qb_ringbuffer_t * rb, size_t len)
* commit the magic & chunk_size
*/
rb->shared_data[old_write_pt] = len;
- rb->shared_data[old_write_pt + 1] = RB_CHUNK_MAGIC;
+ rb->shared_data[old_write_pt + 1] = QB_RB_CHUNK_MAGIC;
rb->shared_hdr->count++;
/*
@@ -453,13 +452,13 @@ void qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out)
{
- uint32_t chunk_size = CHUNK_SIZE_GET(rb, rb->shared_hdr->read_pt);
- uint32_t chunk_magic = CHUNK_MAGIC_GET(rb, rb->shared_hdr->read_pt);
+ uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, rb->shared_hdr->read_pt);
+ uint32_t chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, rb->shared_hdr->read_pt);
*data_out =
- &rb->shared_data[rb->shared_hdr->read_pt + RB_CHUNK_HEADER_WORDS];
+ &rb->shared_data[rb->shared_hdr->read_pt + QB_RB_CHUNK_HEADER_WORDS];
- if (chunk_magic != RB_CHUNK_MAGIC) {
+ if (chunk_magic != QB_RB_CHUNK_MAGIC) {
errno = ENODATA;
return -1;
} else {
@@ -496,7 +495,7 @@ qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
}
_check_chunk_locked_(rb, rb->shared_hdr->read_pt);
- chunk_size = CHUNK_SIZE_GET(rb, rb->shared_hdr->read_pt);
+ chunk_size = QB_RB_CHUNK_SIZE_GET(rb, rb->shared_hdr->read_pt);
if (len < chunk_size) {
printf("%s:%d\n", __func__, __LINE__);
@@ -506,7 +505,7 @@ qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
memcpy(data_out,
&rb->shared_data[rb->shared_hdr->read_pt +
- RB_CHUNK_HEADER_WORDS], chunk_size);
+ QB_RB_CHUNK_HEADER_WORDS], chunk_size);
_qb_rb_chunk_reclaim_locked_(rb);
rb->unlock_fn(rb);
@@ -532,10 +531,10 @@ static void print_header(qb_ringbuffer_t * rb)
static void _check_chunk_locked_(qb_ringbuffer_t * rb, uint32_t pointer)
{
- uint32_t chunk_size = CHUNK_SIZE_GET(rb, pointer);
- uint32_t chunk_magic = CHUNK_MAGIC_GET(rb, pointer);
+ uint32_t chunk_size = QB_RB_CHUNK_SIZE_GET(rb, pointer);
+ uint32_t chunk_magic = QB_RB_CHUNK_MAGIC_GET(rb, pointer);
- if (chunk_magic != RB_CHUNK_MAGIC) {
+ if (chunk_magic != QB_RB_CHUNK_MAGIC) {
printf("size: %x\n", chunk_size);
printf("magic: %x\n", chunk_magic);
print_header(rb);
--
1.6.6.1
13 years, 9 months
[PATCH 1/2] Bring some changes across from corosync.
by Angus Salkeld
My coverity fixes and honzas fixes.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblogsys.h | 85 ++--
lib/ipcc.c | 161 ++++----
lib/ipcs.c | 37 ++-
lib/logsys.c | 1078 +++++++++++++++++++------------------------------
4 files changed, 554 insertions(+), 807 deletions(-)
diff --git a/include/qb/qblogsys.h b/include/qb/qblogsys.h
index e268dbc..3a1a033 100644
--- a/include/qb/qblogsys.h
+++ b/include/qb/qblogsys.h
@@ -23,6 +23,7 @@
#define QB_LOGSYS_H_DEFINED
#include <stdarg.h>
+#include <stdint.h>
#include <stdlib.h>
#include <syslog.h>
#include <pthread.h>
@@ -96,7 +97,7 @@ extern "C" {
/*
* rec_ident explained:
*
- * rec_ident is an unsigned int and carries bitfields information
+ * rec_ident is an uint32_t and carries bitfields information
* on subsys_id, log priority (level) and type of message (RECID).
*
* level values are imported from syslog.h.
@@ -141,38 +142,40 @@ extern "C" {
#ifndef QB_LOGSYS_UTILS_ONLY
-int _logsys_system_setup(const char *mainsystem,
- unsigned int mode,
- unsigned int debug,
- const char *logfile,
- int logfile_priority,
- int syslog_facility, int syslog_priority);
+int32_t _logsys_system_setup(const char *mainsystem,
+ uint32_t mode,
+ uint32_t debug,
+ const char *logfile,
+ int32_t logfile_priority,
+ int32_t syslog_facility, int32_t syslog_priority);
-int _logsys_config_subsys_get(const char *subsys);
+int32_t _logsys_config_subsys_get(const char *subsys);
-unsigned int _logsys_subsys_create(const char *subsys);
+uint32_t _logsys_subsys_create(const char *subsys);
-int _logsys_rec_init(unsigned int size);
+int32_t _logsys_rec_init(uint32_t size);
-void _logsys_log_vprintf(unsigned int rec_ident,
+void _logsys_log_vprintf(uint32_t rec_ident,
const char *function_name,
const char *file_name,
- int file_line, const char *format, va_list ap)
- __attribute__ ((format(printf, 5, 0)));
+ int32_t file_line,
+ const char *format,
+ va_list ap) __attribute__ ((format(printf, 5, 0)));
-void _logsys_log_printf(unsigned int rec_ident,
+void _logsys_log_printf(uint32_t rec_ident,
const char *function_name,
const char *file_name,
- int file_line, const char *format, ...)
- __attribute__ ((format(printf, 5, 6)));
+ int32_t file_line,
+ const char *format,
+ ...) __attribute__ ((format(printf, 5, 6)));
-void _logsys_log_rec(unsigned int rec_ident,
+void _logsys_log_rec(uint32_t rec_ident,
const char *function_name,
- const char *file_name, int file_line, ...);
+ const char *file_name, int32_t file_line, ...);
-int _logsys_wthread_create(void);
+int32_t _logsys_wthread_create(void);
-static int qb_logsys_subsys_id __attribute__ ((unused)) =
+static int32_t qb_logsys_subsys_id __attribute__ ((unused)) =
QB_LOGSYS_MAX_SUBSYS_COUNT;
/*
@@ -192,7 +195,7 @@ void qb_logsys_atexit(void);
*/
void qb_logsys_flush(void);
-int qb_logsys_log_rec_store(const char *filename);
+int32_t qb_logsys_log_rec_store(const char *filename);
/*
* External API - configuration
@@ -201,7 +204,7 @@ int qb_logsys_log_rec_store(const char *filename);
/*
* configuration bits that can only be done for the whole system
*/
-int qb_logsys_format_set(const char *format);
+int32_t qb_logsys_format_set(const char *format);
char *qb_logsys_format_get(void);
@@ -213,52 +216,50 @@ char *qb_logsys_format_get(void);
*
* Pass a NULL subsystem to change them all
*/
-unsigned int qb_logsys_config_syslog_facility_set(const char
- *subsys,
- unsigned int facility);
+int32_t qb_logsys_config_syslog_facility_set(const char *subsys,
+ uint32_t facility);
-unsigned int qb_logsys_config_syslog_priority_set(const char
- *subsys,
- unsigned int priority);
+int32_t qb_logsys_config_syslog_priority_set(const char *subsys,
+ uint32_t priority);
-unsigned int qb_logsys_config_mode_set(const char *subsys, unsigned int mode);
+int32_t qb_logsys_config_mode_set(const char *subsys, uint32_t mode);
-unsigned int qb_logsys_config_mode_get(const char *subsys);
+uint32_t qb_logsys_config_mode_get(const char *subsys);
/*
* to close a logfile, just invoke this function with a NULL
* file or if you want to change logfile, the old one will
* be closed for you.
*/
-int qb_logsys_config_file_set(const char *subsys,
- const char **error_string, const char *file);
+int32_t qb_logsys_config_file_set(const char *subsys,
+ const char **error_string, const char *file);
-unsigned int qb_logsys_config_logfile_priority_set(const char
- *subsys,
- unsigned int priority);
+int32_t qb_logsys_config_logfile_priority_set(const char *subsys,
+ uint32_t priority);
/*
* enabling debug, disable message priority filtering.
* everything is sent everywhere. priority values
* for file and syslog are not overwritten.
*/
-unsigned int qb_logsys_config_debug_set(const char *subsys, unsigned int value);
+int32_t qb_logsys_config_debug_set(const char *subsys, uint32_t value);
/*
* External API - helpers
*
* convert facility/priority to/from name/values
*/
-int qb_logsys_facility_id_get(const char *name);
+int32_t qb_logsys_facility_id_get(const char *name);
-const char *qb_logsys_facility_name_get(unsigned int facility);
+const char *qb_logsys_facility_name_get(uint32_t facility);
-int qb_logsys_priority_id_get(const char *name);
+int32_t qb_logsys_priority_id_get(const char *name);
-const char *qb_logsys_priority_name_get(unsigned int priority);
+const char *qb_logsys_priority_name_get(uint32_t priority);
-int qb_logsys_thread_priority_set(int policy, const struct sched_param
- *param, unsigned int after_log_ops_yield);
+int32_t qb_logsys_thread_priority_set(int32_t policy,
+ const struct sched_param *param,
+ uint32_t after_log_ops_yield);
/*
* External definitions
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 204e5c7..455d3c3 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -255,11 +255,16 @@ circular_memory_map(char *path, const char *file, void **buf, size_t bytes)
}
res = ftruncate(fd, bytes);
+ if (res == -1) {
+ close(fd);
+ return (-1);
+ }
addr_orig = mmap(NULL, bytes << 1, PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (addr_orig == MAP_FAILED) {
+ close(fd);
return (-1);
}
@@ -267,6 +272,7 @@ circular_memory_map(char *path, const char *file, void **buf, size_t bytes)
MAP_FIXED | MAP_SHARED, fd, 0);
if (addr != addr_orig) {
+ close(fd);
return (-1);
}
#ifdef QB_BSD
@@ -276,6 +282,10 @@ circular_memory_map(char *path, const char *file, void **buf, size_t bytes)
addr = mmap(((char *)addr_orig) + bytes,
bytes, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_SHARED, fd, 0);
+ if (addr == MAP_FAILED) {
+ close(fd);
+ return (-1);
+ }
#ifdef QB_BSD
madvise(((char *)addr_orig) + bytes, bytes, MADV_NOSYNC);
#endif
@@ -329,11 +339,16 @@ static int memory_map(char *path, const char *file, void **buf, size_t bytes)
}
res = ftruncate(fd, bytes);
+ if (res == -1) {
+ close(fd);
+ return (-1);
+ }
addr_orig = mmap(NULL, bytes, PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (addr_orig == MAP_FAILED) {
+ close(fd);
return (-1);
}
@@ -341,6 +356,7 @@ static int memory_map(char *path, const char *file, void **buf, size_t bytes)
MAP_FIXED | MAP_SHARED, fd, 0);
if (addr != addr_orig) {
+ close(fd);
return (-1);
}
#ifdef QB_BSD
@@ -405,45 +421,66 @@ retry_semop:
return 0;
}
-static int32_t
-reply_receive(struct ipc_instance *ipc_instance, void *res_msg, size_t res_len)
+static int32_t ipc_sem_wait(struct ipc_instance *ipc_instance, int sem_num)
{
#if _POSIX_THREAD_PROCESS_SHARED < 1
struct sembuf sop;
#else
struct timespec timeout;
struct pollfd pfd;
+ sem_t *sem = NULL;
#endif
- qb_ipc_response_header_t *response_header;
int res;
#if _POSIX_THREAD_PROCESS_SHARED > 0
+ switch (sem_num) {
+ case 0:
+ sem = &ipc_instance->control_buffer->sem0;
+ break;
+ case 1:
+ sem = &ipc_instance->control_buffer->sem1;
+ break;
+ case 2:
+ sem = &ipc_instance->control_buffer->sem2;
+ break;
+ }
+
retry_semwait:
timeout.tv_sec = time(NULL) + IPC_SEMWAIT_TIMEOUT;
timeout.tv_nsec = 0;
- res = sem_timedwait(&ipc_instance->control_buffer->sem1, &timeout);
+ res = sem_timedwait(sem, &timeout);
if (res == -1 && errno == ETIMEDOUT) {
pfd.fd = ipc_instance->fd;
pfd.events = 0;
- poll(&pfd, 1, 0);
- if (pfd.revents == POLLERR || pfd.revents == POLLHUP) {
+ res = poll(&pfd, 1, 0);
+
+ if (res == -1 && errno == EINTR) {
+ return EAGAIN;
+ } else if (res == -1) {
return EBADE;
}
- goto retry_semwait;
- }
+ if (res == 1) {
+ if (pfd.revents == POLLERR || pfd.revents == POLLHUP
+ || pfd.revents == POLLNVAL) {
+ return EBADE;
+ }
+ }
- if (res == -1 && errno == EINTR) {
goto retry_semwait;
+ } else if (res == -1 && errno == EINTR) {
+ return EAGAIN;
+ } else if (res == -1) {
+ return EBADE;
}
#else
/*
- * Wait for semaphore #1 indicating a new message from server
- * to client in the response queue
+ * Wait for semaphore indicating a new message from server
+ * to client in queue
*/
- sop.sem_num = 1;
+ sop.sem_num = sem_num;
sop.sem_op = -1;
sop.sem_flg = 0;
@@ -455,14 +492,26 @@ retry_semop:
priv_change_send(ipc_instance);
goto retry_semop;
} else if (res == -1) {
- return (EBADE);
+ return EBAD;
}
#endif
+ return 0;
+}
+
+static int32_t
+reply_receive(struct ipc_instance *ipc_instance, void *res_msg, size_t res_len)
+{
+ qb_ipc_response_header_t *response_header;
+ int32_t err = 0;
+
+ if ((err = ipc_sem_wait(ipc_instance, 1)) != 0) {
+ return (err);
+ }
response_header =
(qb_ipc_response_header_t *) ipc_instance->response_buffer;
if (response_header->error == EAGAIN) {
- return EAGAIN;
+ return (EAGAIN);
}
memcpy(res_msg, ipc_instance->response_buffer, res_len);
@@ -472,55 +521,11 @@ retry_semop:
static int32_t
reply_receive_in_buf(struct ipc_instance *ipc_instance, void **res_msg)
{
-#if _POSIX_THREAD_PROCESS_SHARED < 1
- struct sembuf sop;
-#else
- struct timespec timeout;
- struct pollfd pfd;
-#endif
- int res;
-
-#if _POSIX_THREAD_PROCESS_SHARED > 0
-retry_semwait:
- timeout.tv_sec = time(NULL) + IPC_SEMWAIT_TIMEOUT;
- timeout.tv_nsec = 0;
-
- res = sem_timedwait(&ipc_instance->control_buffer->sem1, &timeout);
- if (res == -1 && errno == ETIMEDOUT) {
- pfd.fd = ipc_instance->fd;
- pfd.events = 0;
-
- poll(&pfd, 1, 0);
- if (pfd.revents == POLLERR || pfd.revents == POLLHUP) {
- return EBADE;
- }
-
- goto retry_semwait;
- }
-
- if (res == -1 && errno == EINTR) {
- goto retry_semwait;
- }
-#else
- /*
- * Wait for semaphore #1 indicating a new message from server
- * to client in the response queue
- */
- sop.sem_num = 1;
- sop.sem_op = -1;
- sop.sem_flg = 0;
+ int32_t err;
-retry_semop:
- res = semop(ipc_instance->semid, &sop, 1);
- if (res == -1 && errno == EINTR) {
- return (EAGAIN);
- } else if (res == -1 && errno == EACCES) {
- priv_change_send(ipc_instance);
- goto retry_semop;
- } else if (res == -1) {
- return (EBADE);
+ if ((err = ipc_sem_wait(ipc_instance, 1)) != 0) {
+ return (err);
}
-#endif
*res_msg = (char *)ipc_instance->response_buffer;
return 0;
@@ -632,7 +637,6 @@ qb_ipcc_service_connect(const char *socket_name,
sem_init(&ipc_instance->control_buffer->sem1, 1, 0);
sem_init(&ipc_instance->control_buffer->sem2, 1, 0);
#else
-
/*
* Allocate a semaphore segment
*/
@@ -651,6 +655,7 @@ qb_ipcc_service_connect(const char *socket_name,
* an existing shared memory segment for which we have access
*/
if (errno != EEXIST && errno != EACCES) {
+ res = EBAD;
goto error_exit;
}
}
@@ -658,11 +663,13 @@ qb_ipcc_service_connect(const char *socket_name,
semun.val = 0;
res = semctl(ipc_instance->semid, 0, SETVAL, semun);
if (res != 0) {
+ res = EBAD;
goto error_exit;
}
res = semctl(ipc_instance->semid, 1, SETVAL, semun);
if (res != 0) {
+ res = EBAD;
goto error_exit;
}
#endif
@@ -877,12 +884,9 @@ error_put:
int32_t qb_ipcc_dispatch_put(qb_hdb_handle_t handle)
{
-#if _POSIX_THREAD_PROCESS_SHARED < 1
- struct sembuf sop;
-#endif
qb_ipc_response_header_t *header;
struct ipc_instance *ipc_instance;
- int res;
+ int32_t res;
char *addr;
unsigned int read_idx;
@@ -891,29 +895,10 @@ int32_t qb_ipcc_dispatch_put(qb_hdb_handle_t handle)
if (res != 0) {
return (res);
}
-#if _POSIX_THREAD_PROCESS_SHARED > 0
-retry_semwait:
- res = sem_wait(&ipc_instance->control_buffer->sem2);
- if (res == -1 && errno == EINTR) {
- goto retry_semwait;
- }
-#else
- sop.sem_num = 2;
- sop.sem_op = -1;
- sop.sem_flg = 0;
-retry_semop:
- res = semop(ipc_instance->semid, &sop, 1);
- if (res == -1 && errno == EINTR) {
- res = EAGAIN;
- goto error_exit;
- } else if (res == -1 && errno == EACCES) {
- priv_change_send(ipc_instance);
- goto retry_semop;
- } else if (res == -1) {
- res = EBADE;
+
+ if ((res = ipc_sem_wait(ipc_instance, 2)) != 0) {
goto error_exit;
}
-#endif
addr = ipc_instance->dispatch_buffer;
@@ -926,9 +911,7 @@ retry_semop:
*/
res = 0;
-#if _POSIX_THREAD_PROCESS_SHARED < 1
error_exit:
-#endif
qb_hdb_handle_put(&ipc_hdb, handle);
qb_hdb_handle_put(&ipc_hdb, handle);
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 61cd31c..ad99f1f 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -199,12 +199,21 @@ static int memory_map(const char *path, size_t bytes, void **buf)
unlink(path);
+ if (fd == -1) {
+ return (-1);
+ }
+
res = ftruncate(fd, bytes);
+ if (res == -1) {
+ close(fd);
+ return (-1);
+ }
addr_orig = mmap(NULL, bytes, PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (addr_orig == MAP_FAILED) {
+ close(fd);
return (-1);
}
@@ -212,6 +221,7 @@ static int memory_map(const char *path, size_t bytes, void **buf)
MAP_FIXED | MAP_SHARED, fd, 0);
if (addr != addr_orig) {
+ close(fd);
return (-1);
}
#ifdef QB_BSD
@@ -237,12 +247,20 @@ static int circular_memory_map(const char *path, size_t bytes, void **buf)
unlink(path);
+ if (fd == -1) {
+ return (-1);
+ }
res = ftruncate(fd, bytes);
+ if (res == -1) {
+ close(fd);
+ return (-1);
+ }
addr_orig = mmap(NULL, bytes << 1, PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (addr_orig == MAP_FAILED) {
+ close(fd);
return (-1);
}
@@ -250,6 +268,7 @@ static int circular_memory_map(const char *path, size_t bytes, void **buf)
MAP_FIXED | MAP_SHARED, fd, 0);
if (addr != addr_orig) {
+ close(fd);
return (-1);
}
#ifdef QB_BSD
@@ -259,6 +278,10 @@ static int circular_memory_map(const char *path, size_t bytes, void **buf)
addr = mmap(((char *)addr_orig) + bytes,
bytes, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_SHARED, fd, 0);
+ if (addr == MAP_FAILED) {
+ close(fd);
+ return (-1);
+ }
#ifdef QB_BSD
madvise(((char *)addr_orig) + bytes, bytes, MADV_NOSYNC);
#endif
@@ -613,8 +636,7 @@ retry_semop:
send_ok = api->sending_allowed(conn_info->service,
header->id,
header,
- conn_info->
- sending_allowed_private_data);
+ conn_info->sending_allowed_private_data);
/*
* This happens when the message contains some kind of invalid
@@ -650,8 +672,9 @@ retry_semop:
sizeof(qb_ipc_response_header_t));
}
- api->sending_allowed_release(conn_info->
- sending_allowed_private_data);
+ api->
+ sending_allowed_release
+ (conn_info->sending_allowed_private_data);
qb_ipcs_refcount_dec(conn);
}
pthread_exit(0);
@@ -662,6 +685,7 @@ static int req_setup_send(struct conn_info *conn_info, int error)
mar_res_setup_t res_setup;
unsigned int res;
+ memset(&res_setup, 0, sizeof(res_setup));
res_setup.error = error;
retry_send:
@@ -867,7 +891,7 @@ static int conn_info_create(int fd)
/*
* Exported functions
*/
-void qb_ipcs_ipc_init(struct qb_ipcs_init_state *init_state)
+extern void qb_ipcs_ipc_init(struct qb_ipcs_init_state *init_state)
{
int server_fd;
struct sockaddr_un un_addr;
@@ -900,8 +924,7 @@ void qb_ipcs_ipc_init(struct qb_ipcs_init_state *init_state)
qb_util_log(LOG_CRIT,
"Could not set non-blocking operation on server socket: %s\n",
error_str);
- api->
- fatal_error
+ api->fatal_error
("Could not set non-blocking operation on server socket");
}
diff --git a/lib/logsys.c b/lib/logsys.c
index 97e24f4..0ca68ac 100644
--- a/lib/logsys.c
+++ b/lib/logsys.c
@@ -27,15 +27,15 @@
#include <sys/time.h>
#include <syslog.h>
#include <pthread.h>
+#include <semaphore.h>
+#include <qb/qbutil.h>
+#include <qb/qblist.h>
+#include <qb/qbrb.h>
#include <qb/qblogsys.h>
-#define YIELD_AFTER_LOG_OPS 10
-
#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#define ROUNDUP(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
-
/*
* syslog prioritynames, facility names to value mapping
* Some C libraries build this in to their headers, but it is non-portable
@@ -43,7 +43,7 @@
*/
struct syslog_names {
const char *c_name;
- int c_val;
+ int32_t c_val;
};
struct syslog_names prioritynames[] = {
@@ -81,26 +81,14 @@ struct syslog_names facilitynames[] = {
{NULL, -1}
};
-/*
- * These are not static so they can be read from the core file
- */
-int *flt_data;
-
-unsigned int flt_data_size;
-
-#define COMBINE_BUFFER_SIZE 2048
-
-/* values for qb_logsys_logger init_status */
-#define QB_LOGSYS_LOGGER_INIT_DONE 0
-#define QB_LOGSYS_LOGGER_NEEDS_INIT 1
-
-static int qb_logsys_system_needs_init = QB_LOGSYS_LOGGER_NEEDS_INIT;
-
-static int qb_logsys_sched_param_queued = 0;
-static int qb_logsys_sched_policy;
-static struct sched_param qb_logsys_sched_param;
-
-static int qb_logsys_after_log_ops_yield = 10;
+struct record {
+ uint32_t rec_ident;
+ const char *file_name;
+ const char *function_name;
+ int32_t file_line;
+ char *buffer;
+ struct qb_list_head list;
+};
/*
* need unlogical order to preserve 64bit alignment
@@ -109,82 +97,86 @@ struct qb_logsys_logger {
char subsys[QB_LOGSYS_MAX_SUBSYS_NAMELEN]; /* subsystem name */
char *logfile; /* log to file */
FILE *logfile_fp; /* track file descriptor */
- unsigned int mode; /* subsystem mode */
- unsigned int debug; /* debug on|off */
- int syslog_facility; /* facility */
- int syslog_priority; /* priority */
- int logfile_priority; /* priority to file */
- int init_status; /* internal field to handle init queues
+ uint32_t mode; /* subsystem mode */
+ uint32_t debug; /* debug on|off */
+ int32_t syslog_facility; /* facility */
+ int32_t syslog_priority; /* priority */
+ int32_t logfile_priority; /* priority to file */
+ int32_t init_status; /* internal field to handle init queues
for subsystems */
};
-/*
- * operating global variables
- */
+static qb_ringbuffer_t *rb = NULL;
-static struct qb_logsys_logger qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT +
- 1];
+#define COMBINE_BUFFER_SIZE 2048
-static int wthread_active = 0;
+/* values for logsys_logger init_status */
+#define LOGSYS_LOGGER_INIT_DONE 0
+#define LOGSYS_LOGGER_NEEDS_INIT 1
-static int wthread_should_exit = 0;
+static int32_t logsys_system_needs_init = LOGSYS_LOGGER_NEEDS_INIT;
-static pthread_mutex_t qb_logsys_config_mutex = PTHREAD_MUTEX_INITIALIZER;
+static int32_t logsys_memory_used = 0;
-static unsigned int records_written = 1;
+static int32_t logsys_sched_param_queued = 0;
-static pthread_t qb_logsys_thread_id;
+static int32_t logsys_sched_policy;
-static pthread_cond_t qb_logsys_cond;
+static struct sched_param logsys_sched_param;
-static pthread_mutex_t qb_logsys_cond_mutex;
+static int32_t logsys_after_log_ops_yield = 10;
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static pthread_spinlock_t qb_logsys_idx_spinlock;
-#else
-static pthread_mutex_t qb_logsys_idx_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
+static struct qb_logsys_logger logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT + 1];
-static unsigned int log_rec_idx;
+static int32_t wthread_active = 0;
-static int qb_logsys_buffer_full = 0;
+static int32_t wthread_should_exit = 0;
-static char *format_buffer = NULL;
+static pthread_mutex_t qb_logsys_config_mutex = PTHREAD_MUTEX_INITIALIZER;
-static int log_requests_pending = 0;
+static uint32_t records_written = 1;
-static int log_requests_lost = 0;
+static pthread_t logsys_thread_id;
-void *qb_logsys_rec_end;
+static sem_t logsys_thread_start;
-#define FDHEAD_INDEX (flt_data_size)
+static sem_t logsys_print_finished;
-#define FDTAIL_INDEX (flt_data_size + 1)
+static qb_thread_lock_t *logsys_flt_lock;
+static qb_thread_lock_t *logsys_wthread_lock;
+
+static char *format_buffer = NULL;
+
+static int32_t logsys_dropped_messages = 0;
+
+void *qb_logsys_rec_end;
+
+static QB_DECLARE_LIST_INIT(logsys_print_finished_records);
#define FDMAX_ARGS 64
/* forward declarations */
-static void qb_logsys_close_logfile(int subsysid);
+static void qb_logsys_close_logfile(int32_t subsysid);
#ifdef QB_LOGSYS_DEBUG
-static char *decode_mode(int subsysid, char *buf, size_t buflen)
+static char *decode_mode(int32_t subsysid, char *buf, size_t buflen)
{
memset(buf, 0, buflen);
- if (qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_FILE)
+ if (logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_FILE)
snprintf(buf + strlen(buf), buflen, "FILE,");
- if (qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_STDERR)
+ if (logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_STDERR)
snprintf(buf + strlen(buf), buflen, "STDERR,");
- if (qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_SYSLOG)
+ if (logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_SYSLOG)
snprintf(buf + strlen(buf), buflen, "SYSLOG,");
if (subsysid == QB_LOGSYS_MAX_SUBSYS_COUNT) {
- if (qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_FORK)
+ if (logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_FORK)
snprintf(buf + strlen(buf), buflen, "FORK,");
- if (qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_THREADED)
+ if (logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_THREADED)
snprintf(buf + strlen(buf), buflen, "THREADED,");
}
@@ -193,23 +185,23 @@ static char *decode_mode(int subsysid, char *buf, size_t buflen)
return buf;
}
-static const char *decode_debug(int subsysid)
+static const char *decode_debug(int32_t subsysid)
{
- if (qb_logsys_loggers[subsysid].debug)
+ if (logsys_loggers[subsysid].debug)
return "on";
return "off";
}
-static const char *decode_status(int subsysid)
+static const char *decode_status(int32_t subsysid)
{
- if (!qb_logsys_loggers[subsysid].init_status)
+ if (!logsys_loggers[subsysid].init_status)
return "INIT_DONE";
return "NEEDS_INIT";
}
-static void dump_subsys_config(int subsysid)
+static void dump_subsys_config(int32_t subsysid)
{
char modebuf[1024];
@@ -225,143 +217,36 @@ static void dump_subsys_config(int subsysid)
"logfile_pri: %s\n"
"init_status: %s\n",
subsysid,
- qb_logsys_loggers[subsysid].subsys,
- qb_logsys_loggers[subsysid].logfile,
- qb_logsys_loggers[subsysid].logfile_fp,
+ logsys_loggers[subsysid].subsys,
+ logsys_loggers[subsysid].logfile,
+ logsys_loggers[subsysid].logfile_fp,
decode_mode(subsysid, modebuf, sizeof(modebuf)),
decode_debug(subsysid),
- qb_logsys_facility_name_get(qb_logsys_loggers[subsysid].
- syslog_facility),
- qb_logsys_priority_name_get(qb_logsys_loggers[subsysid].
- syslog_priority),
- qb_logsys_priority_name_get(qb_logsys_loggers[subsysid].
- logfile_priority),
+ qb_logsys_facility_name_get(logsys_loggers
+ [subsysid].syslog_facility),
+ qb_logsys_priority_name_get(logsys_loggers
+ [subsysid].syslog_priority),
+ qb_logsys_priority_name_get(logsys_loggers
+ [subsysid].logfile_priority),
decode_status(subsysid));
}
static void dump_full_config(void)
{
- int i;
+ int32_t i;
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- if (strlen(qb_logsys_loggers[i].subsys) > 0)
+ if (strlen(logsys_loggers[i].subsys) > 0)
dump_subsys_config(i);
}
}
#endif
/*
- * Helpers for _logsys_log_rec functionality
- */
-static inline void my_memcpy_32bit(int *dest, const int *src,
- unsigned int words)
-{
- unsigned int word_idx;
- for (word_idx = 0; word_idx < words; word_idx++) {
- dest[word_idx] = src[word_idx];
- }
-}
-
-static inline void my_memcpy_8bit(char *dest, const char *src,
- unsigned int bytes)
-{
- unsigned int byte_idx;
-
- for (byte_idx = 0; byte_idx < bytes; byte_idx++) {
- dest[byte_idx] = src[byte_idx];
- }
-}
-
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
-static void qb_logsys_lock(void)
-{
- pthread_spin_lock(&qb_logsys_idx_spinlock);
-}
-
-static void qb_logsys_unlock(void)
-{
- pthread_spin_unlock(&qb_logsys_idx_spinlock);
-}
-#else
-static void qb_logsys_lock(void)
-{
- pthread_mutex_lock(&qb_logsys_idx_mutex);
-}
-
-static void qb_logsys_unlock(void)
-{
- pthread_mutex_unlock(&qb_logsys_idx_mutex);
-}
-#endif
-
-/*
- * Before any write operation, a reclaim on the buffer area must be executed
- */
-static inline void records_reclaim(unsigned int idx, unsigned int words)
-{
- unsigned int should_reclaim;
-
- should_reclaim = 0;
-
- if ((idx + words) >= flt_data_size) {
- qb_logsys_buffer_full = 1;
- }
- if (qb_logsys_buffer_full == 0) {
- return;
- }
-
- qb_logsys_lock();
- if (flt_data[FDTAIL_INDEX] > flt_data[FDHEAD_INDEX]) {
- if (idx + words >= flt_data[FDTAIL_INDEX]) {
- should_reclaim = 1;
- }
- } else {
- if ((idx + words) >= (flt_data[FDTAIL_INDEX] + flt_data_size)) {
- should_reclaim = 1;
- }
- }
-
- if (should_reclaim) {
- int words_needed = 0;
-
- words_needed = words + 1;
- do {
- unsigned int old_tail;
-
- words_needed -= flt_data[flt_data[FDTAIL_INDEX]];
- old_tail = flt_data[FDTAIL_INDEX];
- flt_data[FDTAIL_INDEX] =
- (flt_data[FDTAIL_INDEX] +
- flt_data[flt_data[FDTAIL_INDEX]]) %
- (flt_data_size);
- if (log_rec_idx == old_tail) {
- log_requests_lost += 1;
- log_rec_idx = flt_data[FDTAIL_INDEX];
- }
- } while (words_needed > 0);
- }
- qb_logsys_unlock();
-}
-
-#define idx_word_step(idx) \
-do { \
- if (idx > (flt_data_size - 1)) { \
- idx = 0; \
- } \
-} while (0);
-
-#define idx_buffer_step(idx) \
-do { \
- if (idx > (flt_data_size - 1)) { \
- idx = ((idx) % (flt_data_size)); \
- } \
-} while (0);
-
-/*
* Internal threaded logging implementation
*/
-static inline int strcpy_cutoff(char *dest, const char *src, size_t cutoff,
- size_t buf_len)
+static inline int32_t strcpy_cutoff(char *dest, const char *src, size_t cutoff,
+ size_t buf_len)
{
size_t len = strlen(src);
if (buf_len <= 1) {
@@ -399,24 +284,24 @@ static const char log_month_name[][4] = {
*
* any number between % and character specify field length to pad or chop
*/
-static void log_printf_to_logs(unsigned int rec_ident,
+static void log_printf_to_logs(uint32_t rec_ident,
const char *file_name,
const char *function_name,
- int file_line, const char *buffer)
+ int32_t file_line, const char *buffer)
{
char normal_output_buffer[COMBINE_BUFFER_SIZE];
char syslog_output_buffer[COMBINE_BUFFER_SIZE];
char char_time[128];
char line_no[30];
- unsigned int format_buffer_idx = 0;
- unsigned int normal_output_buffer_idx = 0;
- unsigned int syslog_output_buffer_idx = 0;
+ uint32_t format_buffer_idx = 0;
+ uint32_t normal_output_buffer_idx = 0;
+ uint32_t syslog_output_buffer_idx = 0;
struct timeval tv;
size_t cutoff;
- unsigned int normal_len, syslog_len;
- int subsysid;
- unsigned int level;
- int c;
+ uint32_t normal_len, syslog_len;
+ int32_t subsysid;
+ uint32_t level;
+ int32_t c;
struct tm tm_res;
if (QB_LOGSYS_DECODE_RECID(rec_ident) != QB_LOGSYS_RECID_LOG) {
@@ -446,8 +331,8 @@ static void log_printf_to_logs(unsigned int rec_ident,
switch (format_buffer[format_buffer_idx]) {
case 's':
- normal_p = qb_logsys_loggers[subsysid].subsys;
- syslog_p = qb_logsys_loggers[subsysid].subsys;
+ normal_p = logsys_loggers[subsysid].subsys;
+ syslog_p = logsys_loggers[subsysid].subsys;
break;
case 'n':
@@ -491,7 +376,7 @@ static void log_printf_to_logs(unsigned int rec_ident,
case 'p':
normal_p =
- qb_logsys_loggers
+ logsys_loggers
[QB_LOGSYS_MAX_SUBSYS_COUNT].subsys;
syslog_p = "";
break;
@@ -533,11 +418,11 @@ static void log_printf_to_logs(unsigned int rec_ident,
/*
* Output to syslog
*/
- if ((qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_SYSLOG) &&
- ((level <= qb_logsys_loggers[subsysid].syslog_priority) ||
- (qb_logsys_loggers[subsysid].debug != 0))) {
- syslog(level | qb_logsys_loggers[subsysid].syslog_facility,
- "%s", syslog_output_buffer);
+ if ((logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_SYSLOG) &&
+ ((level <= logsys_loggers[subsysid].syslog_priority) ||
+ (logsys_loggers[subsysid].debug != 0))) {
+ syslog(level | logsys_loggers[subsysid].syslog_facility, "%s",
+ syslog_output_buffer);
}
/*
@@ -549,18 +434,17 @@ static void log_printf_to_logs(unsigned int rec_ident,
/*
* Output to configured file
*/
- if (((qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_FILE) &&
- (qb_logsys_loggers[subsysid].logfile_fp != NULL)) &&
- ((level <= qb_logsys_loggers[subsysid].logfile_priority) ||
- (qb_logsys_loggers[subsysid].debug != 0))) {
+ if (((logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_FILE) &&
+ (logsys_loggers[subsysid].logfile_fp != NULL)) &&
+ ((level <= logsys_loggers[subsysid].logfile_priority) ||
+ (logsys_loggers[subsysid].debug != 0))) {
/*
* Output to a file
*/
if ((fwrite
(normal_output_buffer, strlen(normal_output_buffer), 1,
- qb_logsys_loggers[subsysid].logfile_fp) < 1)
- || (fflush(qb_logsys_loggers[subsysid].logfile_fp) ==
- EOF)) {
+ logsys_loggers[subsysid].logfile_fp) < 1)
+ || (fflush(logsys_loggers[subsysid].logfile_fp) == EOF)) {
char tmpbuffer[1024];
/*
* if we are here, it's bad.. it's really really bad.
@@ -569,11 +453,11 @@ static void log_printf_to_logs(unsigned int rec_ident,
*/
snprintf(tmpbuffer, sizeof(tmpbuffer),
"QB_LOGSYS EMERGENCY: %s Unable to write to %s.",
- qb_logsys_loggers[subsysid].subsys,
- qb_logsys_loggers[subsysid].logfile);
+ logsys_loggers[subsysid].subsys,
+ logsys_loggers[subsysid].logfile);
pthread_mutex_lock(&qb_logsys_config_mutex);
qb_logsys_close_logfile(subsysid);
- qb_logsys_loggers[subsysid].mode &=
+ logsys_loggers[subsysid].mode &=
~QB_LOGSYS_MODE_OUTPUT_FILE;
pthread_mutex_unlock(&qb_logsys_config_mutex);
log_printf_to_logs(QB_LOGSYS_ENCODE_RECID
@@ -586,9 +470,9 @@ static void log_printf_to_logs(unsigned int rec_ident,
/*
* Output to stderr
*/
- if ((qb_logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_STDERR) &&
- ((level <= qb_logsys_loggers[subsysid].logfile_priority) ||
- (qb_logsys_loggers[subsysid].debug != 0))) {
+ if ((logsys_loggers[subsysid].mode & QB_LOGSYS_MODE_OUTPUT_STDERR) &&
+ ((level <= logsys_loggers[subsysid].logfile_priority) ||
+ (logsys_loggers[subsysid].debug != 0))) {
if (write
(STDERR_FILENO, normal_output_buffer,
strlen(normal_output_buffer)) < 0) {
@@ -599,12 +483,12 @@ static void log_printf_to_logs(unsigned int rec_ident,
* in the calendar and pray a lot...
*/
pthread_mutex_lock(&qb_logsys_config_mutex);
- qb_logsys_loggers[subsysid].mode &=
+ logsys_loggers[subsysid].mode &=
~QB_LOGSYS_MODE_OUTPUT_STDERR;
pthread_mutex_unlock(&qb_logsys_config_mutex);
snprintf(tmpbuffer, sizeof(tmpbuffer),
"QB_LOGSYS EMERGENCY: %s Unable to write to STDERR.",
- qb_logsys_loggers[subsysid].subsys);
+ logsys_loggers[subsysid].subsys);
log_printf_to_logs(QB_LOGSYS_ENCODE_RECID
(QB_LOGSYS_LEVEL_EMERG, subsysid,
QB_LOGSYS_RECID_LOG), __FILE__,
@@ -613,166 +497,102 @@ static void log_printf_to_logs(unsigned int rec_ident,
}
}
-static void record_print(const char *buf)
-{
- const int *buf_uint32t = (const int *)buf;
- unsigned int rec_size = buf_uint32t[0];
- unsigned int rec_ident = buf_uint32t[1];
- unsigned int file_line = buf_uint32t[2];
- unsigned int i;
- unsigned int words_processed;
- unsigned int arg_size_idx;
- const void *arguments[FDMAX_ARGS];
- unsigned int arg_count;
-
- arg_size_idx = 4;
- words_processed = 4;
- arg_count = 0;
-
- for (i = 0; words_processed < rec_size; i++) {
- arguments[arg_count++] = &buf_uint32t[arg_size_idx + 1];
- arg_size_idx += buf_uint32t[arg_size_idx] + 1;
- words_processed += buf_uint32t[arg_size_idx] + 1;
- }
-
- /*
- * (char *)arguments[0] -> subsystem
- * (char *)arguments[1] -> file_name
- * (char *)arguments[2] -> function_name
- * (char *)arguments[3] -> message
- */
-
- log_printf_to_logs(rec_ident,
- (char *)arguments[1],
- (char *)arguments[2],
- file_line, (char *)arguments[3]);
-}
-
-static int record_read(char *buf, int rec_idx, int *log_msg)
+static void log_printf_to_logs_wthread(uint32_t rec_ident,
+ const char *file_name,
+ const char *function_name,
+ int32_t file_line, const char *buffer)
{
- unsigned int rec_size;
- unsigned int rec_ident;
- int firstcopy, secondcopy;
+ struct record *rec;
+ uint32_t length;
- rec_size = flt_data[rec_idx];
- rec_ident = flt_data[(rec_idx + 1) % flt_data_size];
-
- /*
- * Not a log record
- */
- if (QB_LOGSYS_DECODE_RECID(rec_ident) != QB_LOGSYS_RECID_LOG) {
- *log_msg = 0;
- return ((rec_idx + rec_size) % flt_data_size);
+ rec = malloc(sizeof(struct record));
+ if (rec == NULL) {
+ return;
}
- /*
- * A log record
- */
- *log_msg = 1;
-
- firstcopy = rec_size;
- secondcopy = 0;
- if (firstcopy + rec_idx > flt_data_size) {
- firstcopy = flt_data_size - rec_idx;
- secondcopy -= firstcopy - rec_size;
- }
- memcpy(&buf[0], &flt_data[rec_idx], firstcopy << 2);
- if (secondcopy) {
- memcpy(&buf[(firstcopy << 2)], &flt_data[0], secondcopy << 2);
- }
- return ((rec_idx + rec_size) % flt_data_size);
-}
+ length = strlen(buffer);
-static inline void wthread_signal(void)
-{
- if (wthread_active == 0) {
+ rec->rec_ident = rec_ident;
+ rec->file_name = file_name;
+ rec->function_name = function_name;
+ rec->file_line = file_line;
+ rec->buffer = malloc(length + 1);
+ if (rec->buffer == NULL) {
+ free(rec);
return;
}
- pthread_mutex_lock(&qb_logsys_cond_mutex);
- pthread_cond_signal(&qb_logsys_cond);
- pthread_mutex_unlock(&qb_logsys_cond_mutex);
-}
+ memcpy(rec->buffer, buffer, length + 1);
+
+ qb_list_init(&rec->list);
+ qb_thread_lock(logsys_wthread_lock);
+ logsys_memory_used += length + 1 + sizeof(struct record);
+ if (logsys_memory_used > 512000) {
+ free(rec->buffer);
+ free(rec);
+ logsys_memory_used =
+ logsys_memory_used - length - 1 - sizeof(struct record);
+ logsys_dropped_messages += 1;
+ qb_thread_unlock(logsys_wthread_lock);
+ return;
-static inline void wthread_wait(void)
-{
- pthread_mutex_lock(&qb_logsys_cond_mutex);
- pthread_cond_wait(&qb_logsys_cond, &qb_logsys_cond_mutex);
- pthread_mutex_unlock(&qb_logsys_cond_mutex);
-}
+ } else {
+ qb_list_add_tail(&rec->list, &logsys_print_finished_records);
+ }
+ qb_thread_unlock(logsys_wthread_lock);
-static inline void wthread_wait_locked(void)
-{
- pthread_cond_wait(&qb_logsys_cond, &qb_logsys_cond_mutex);
- pthread_mutex_unlock(&qb_logsys_cond_mutex);
+ sem_post(&logsys_print_finished);
}
-static void *qb_logsys_worker_thread(void *data) __attribute__ ((__noreturn__));
-static void *qb_logsys_worker_thread(void *data)
+static void *logsys_worker_thread(void *data) __attribute__ ((noreturn));
+static void *logsys_worker_thread(void *data)
{
- int log_msg;
- char buf[COMBINE_BUFFER_SIZE];
+ struct record *rec;
+ int32_t dropped = 0;
+ int32_t res;
/*
* Signal wthread_create that the initialization process may continue
*/
- wthread_signal();
- qb_logsys_lock();
- log_rec_idx = flt_data[FDTAIL_INDEX];
- qb_logsys_unlock();
-
+ sem_post(&logsys_thread_start);
for (;;) {
- wthread_wait();
- /*
- * Read and copy the logging record index position
- * It may have been updated by records_reclaim if
- * messages were lost or or log_rec on the first new
- * logging record available
- */
- /*
- * Process any pending log messages here
- */
- for (;;) {
- int yield_counter = 1;
-
- qb_logsys_lock();
- if (log_requests_lost > 0) {
- printf("lost %d log requests\n",
- log_requests_lost);
- log_requests_pending -= log_requests_lost;
- log_requests_lost = 0;
- }
- if (log_requests_pending == 0) {
- qb_logsys_unlock();
- break;
- }
- log_rec_idx = record_read(buf, log_rec_idx, &log_msg);
- if (log_msg) {
- log_requests_pending -= 1;
- }
- qb_logsys_unlock();
+ dropped = 0;
+ sem_wait(&logsys_print_finished);
- /*
- * print the stored buffer
- */
- if (log_msg) {
- record_print(buf);
- if (yield_counter++ >
- qb_logsys_after_log_ops_yield) {
- yield_counter = 0;
- sched_yield();
- }
+ qb_thread_lock(logsys_wthread_lock);
+ if (wthread_should_exit) {
+ int32_t value;
+
+ res = sem_getvalue(&logsys_print_finished, &value);
+ if (value == 0) {
+ qb_thread_unlock(logsys_wthread_lock);
+ pthread_exit(NULL);
}
}
- if (wthread_should_exit) {
- pthread_exit(NULL);
+ rec =
+ qb_list_entry(logsys_print_finished_records.next,
+ struct record, list);
+ qb_list_del(&rec->list);
+ logsys_memory_used = logsys_memory_used - strlen(rec->buffer) -
+ sizeof(struct record) - 1;
+ dropped = logsys_dropped_messages;
+ logsys_dropped_messages = 0;
+ qb_thread_unlock(logsys_wthread_lock);
+ if (dropped) {
+ printf("%d messages lost\n", dropped);
}
+ log_printf_to_logs(rec->rec_ident,
+ rec->file_name,
+ rec->function_name,
+ rec->file_line, rec->buffer);
+ free(rec->buffer);
+ free(rec);
}
}
static void wthread_create(void)
{
- int res;
+ int32_t res;
if (wthread_active) {
return;
@@ -780,47 +600,39 @@ static void wthread_create(void)
wthread_active = 1;
- pthread_mutex_init(&qb_logsys_cond_mutex, NULL);
- pthread_cond_init(&qb_logsys_cond, NULL);
- pthread_mutex_lock(&qb_logsys_cond_mutex);
-
/*
* TODO: propagate pthread_create errors back to the caller
*/
- res = pthread_create(&qb_logsys_thread_id, NULL,
- qb_logsys_worker_thread, NULL);
+ res = pthread_create(&logsys_thread_id, NULL,
+ logsys_worker_thread, NULL);
+ sem_wait(&logsys_thread_start);
if (res == 0) {
- /*
- * Wait for thread to be started
- */
- wthread_wait_locked();
- if (qb_logsys_sched_param_queued == 1) {
+ if (logsys_sched_param_queued == 1) {
/*
- * TODO: propagate qb_logsys_thread_priority_set errors back to
+ * TODO: propagate logsys_thread_priority_set errors back to
* the caller
*/
- res =
- qb_logsys_thread_priority_set
- (qb_logsys_sched_policy, &qb_logsys_sched_param,
- qb_logsys_after_log_ops_yield);
- qb_logsys_sched_param_queued = 0;
+ res = qb_logsys_thread_priority_set(logsys_sched_policy,
+ &logsys_sched_param,
+ logsys_after_log_ops_yield);
+ logsys_sched_param_queued = 0;
}
} else {
wthread_active = 0;
}
}
-static int _logsys_config_subsys_get_unlocked(const char *subsys)
+static int32_t _logsys_config_subsys_get_unlocked(const char *subsys)
{
- unsigned int i;
+ uint32_t i;
if (!subsys) {
return QB_LOGSYS_MAX_SUBSYS_COUNT;
}
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- if (strcmp(qb_logsys_loggers[i].subsys, subsys) == 0) {
+ if (strcmp(logsys_loggers[i].subsys, subsys) == 0) {
return i;
}
}
@@ -831,21 +643,21 @@ static int _logsys_config_subsys_get_unlocked(const char *subsys)
static void syslog_facility_reconf(void)
{
closelog();
- openlog(qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].subsys,
+ openlog(logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].subsys,
LOG_CONS | LOG_PID,
- qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].syslog_facility);
+ logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].syslog_facility);
}
/*
* this is always invoked within the mutex, so it's safe to parse the
* whole thing as we need.
*/
-static void qb_logsys_close_logfile(int subsysid)
+static void qb_logsys_close_logfile(int32_t subsysid)
{
- int i;
+ int32_t i;
- if ((qb_logsys_loggers[subsysid].logfile_fp == NULL) &&
- (qb_logsys_loggers[subsysid].logfile == NULL)) {
+ if ((logsys_loggers[subsysid].logfile_fp == NULL) &&
+ (logsys_loggers[subsysid].logfile == NULL)) {
return;
}
@@ -856,11 +668,10 @@ static void qb_logsys_close_logfile(int subsysid)
* Only the last users will be allowed to perform the fclose.
*/
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- if ((qb_logsys_loggers[i].logfile_fp ==
- qb_logsys_loggers[subsysid].logfile_fp)
- && (i != subsysid)) {
- qb_logsys_loggers[subsysid].logfile = NULL;
- qb_logsys_loggers[subsysid].logfile_fp = NULL;
+ if ((logsys_loggers[i].logfile_fp ==
+ logsys_loggers[subsysid].logfile_fp) && (i != subsysid)) {
+ logsys_loggers[subsysid].logfile = NULL;
+ logsys_loggers[subsysid].logfile_fp = NULL;
return;
}
}
@@ -869,27 +680,27 @@ static void qb_logsys_close_logfile(int subsysid)
* if we are here, we are the last users of that fp, so we can safely
* close it.
*/
- fclose(qb_logsys_loggers[subsysid].logfile_fp);
- qb_logsys_loggers[subsysid].logfile_fp = NULL;
- free(qb_logsys_loggers[subsysid].logfile);
- qb_logsys_loggers[subsysid].logfile = NULL;
+ fclose(logsys_loggers[subsysid].logfile_fp);
+ logsys_loggers[subsysid].logfile_fp = NULL;
+ free(logsys_loggers[subsysid].logfile);
+ logsys_loggers[subsysid].logfile = NULL;
}
/*
* we need a version that can work when somebody else is already
* holding a config mutex lock or we will never get out of here
*/
-static int qb_logsys_config_file_set_unlocked(int subsysid,
- const char **error_string,
- const char *file)
+static int32_t qb_logsys_config_file_set_unlocked(int32_t subsysid,
+ const char **error_string,
+ const char *file)
{
static char error_string_response[512];
- int i;
+ int32_t i;
qb_logsys_close_logfile(subsysid);
if ((file == NULL) ||
- (strcmp(qb_logsys_loggers[subsysid].subsys, "") == 0)) {
+ (strcmp(logsys_loggers[subsysid].subsys, "") == 0)) {
return (0);
}
@@ -897,25 +708,25 @@ static int qb_logsys_config_file_set_unlocked(int subsysid,
snprintf(error_string_response,
sizeof(error_string_response),
"%s: logfile name exceed maximum system filename lenght\n",
- qb_logsys_loggers[subsysid].subsys);
+ logsys_loggers[subsysid].subsys);
*error_string = error_string_response;
return (-1);
}
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- if ((qb_logsys_loggers[i].logfile != NULL) &&
- (strcmp(qb_logsys_loggers[i].logfile, file) == 0) &&
+ if ((logsys_loggers[i].logfile != NULL) &&
+ (strcmp(logsys_loggers[i].logfile, file) == 0) &&
(i != subsysid)) {
- qb_logsys_loggers[subsysid].logfile =
- qb_logsys_loggers[i].logfile;
- qb_logsys_loggers[subsysid].logfile_fp =
- qb_logsys_loggers[i].logfile_fp;
+ logsys_loggers[subsysid].logfile =
+ logsys_loggers[i].logfile;
+ logsys_loggers[subsysid].logfile_fp =
+ logsys_loggers[i].logfile_fp;
return (0);
}
}
- qb_logsys_loggers[subsysid].logfile = strdup(file);
- if (qb_logsys_loggers[subsysid].logfile == NULL) {
+ logsys_loggers[subsysid].logfile = strdup(file);
+ if (logsys_loggers[subsysid].logfile == NULL) {
snprintf(error_string_response,
sizeof(error_string_response),
"Unable to allocate memory for logfile '%s'\n", file);
@@ -923,12 +734,12 @@ static int qb_logsys_config_file_set_unlocked(int subsysid,
return (-1);
}
- qb_logsys_loggers[subsysid].logfile_fp = fopen(file, "a+");
- if (qb_logsys_loggers[subsysid].logfile_fp == NULL) {
+ logsys_loggers[subsysid].logfile_fp = fopen(file, "a+");
+ if (logsys_loggers[subsysid].logfile_fp == NULL) {
char error_str[100];
strerror_r(errno, error_str, 100);
- free(qb_logsys_loggers[subsysid].logfile);
- qb_logsys_loggers[subsysid].logfile = NULL;
+ free(logsys_loggers[subsysid].logfile);
+ logsys_loggers[subsysid].logfile = NULL;
snprintf(error_string_response,
sizeof(error_string_response),
"Can't open logfile '%s' for reason (%s).\n",
@@ -940,19 +751,17 @@ static int qb_logsys_config_file_set_unlocked(int subsysid,
return (0);
}
-static void qb_logsys_subsys_init(const char *subsys, int subsysid)
+static void qb_logsys_subsys_init(const char *subsys, int32_t subsysid)
{
- if (qb_logsys_system_needs_init == QB_LOGSYS_LOGGER_NEEDS_INIT) {
- qb_logsys_loggers[subsysid].init_status =
- QB_LOGSYS_LOGGER_NEEDS_INIT;
+ if (logsys_system_needs_init == LOGSYS_LOGGER_NEEDS_INIT) {
+ logsys_loggers[subsysid].init_status = LOGSYS_LOGGER_NEEDS_INIT;
} else {
- memcpy(&qb_logsys_loggers[subsysid],
- &qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT],
- sizeof(qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT]));
- qb_logsys_loggers[subsysid].init_status =
- QB_LOGSYS_LOGGER_INIT_DONE;
+ memcpy(&logsys_loggers[subsysid],
+ &logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT],
+ sizeof(logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT]));
+ logsys_loggers[subsysid].init_status = LOGSYS_LOGGER_INIT_DONE;
}
- strncpy(qb_logsys_loggers[subsysid].subsys, subsys,
+ strncpy(logsys_loggers[subsysid].subsys, subsys,
QB_LOGSYS_MAX_SUBSYS_NAMELEN);
}
@@ -960,14 +769,14 @@ static void qb_logsys_subsys_init(const char *subsys, int subsysid)
* Internal API - exported
*/
-int _logsys_system_setup(const char *mainsystem,
- unsigned int mode,
- unsigned int debug,
- const char *logfile,
- int logfile_priority,
- int syslog_facility, int syslog_priority)
+int32_t _logsys_system_setup(const char *mainsystem,
+ uint32_t mode,
+ uint32_t debug,
+ const char *logfile,
+ int32_t logfile_priority,
+ int32_t syslog_facility, int32_t syslog_priority)
{
- int i;
+ int32_t i;
const char *errstr;
char tempsubsys[QB_LOGSYS_MAX_SUBSYS_NAMELEN];
@@ -980,32 +789,32 @@ int _logsys_system_setup(const char *mainsystem,
pthread_mutex_lock(&qb_logsys_config_mutex);
- snprintf(qb_logsys_loggers[i].subsys,
+ snprintf(logsys_loggers[i].subsys,
QB_LOGSYS_MAX_SUBSYS_NAMELEN, "%s", mainsystem);
- qb_logsys_loggers[i].mode = mode;
+ logsys_loggers[i].mode = mode;
- qb_logsys_loggers[i].debug = debug;
+ logsys_loggers[i].debug = debug;
if (qb_logsys_config_file_set_unlocked(i, &errstr, logfile) < 0) {
pthread_mutex_unlock(&qb_logsys_config_mutex);
return (-1);
}
- qb_logsys_loggers[i].logfile_priority = logfile_priority;
+ logsys_loggers[i].logfile_priority = logfile_priority;
- qb_logsys_loggers[i].syslog_facility = syslog_facility;
- qb_logsys_loggers[i].syslog_priority = syslog_priority;
+ logsys_loggers[i].syslog_facility = syslog_facility;
+ logsys_loggers[i].syslog_priority = syslog_priority;
syslog_facility_reconf();
- qb_logsys_loggers[i].init_status = QB_LOGSYS_LOGGER_INIT_DONE;
+ logsys_loggers[i].init_status = LOGSYS_LOGGER_INIT_DONE;
- qb_logsys_system_needs_init = QB_LOGSYS_LOGGER_INIT_DONE;
+ logsys_system_needs_init = LOGSYS_LOGGER_INIT_DONE;
for (i = 0; i < QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- if ((strcmp(qb_logsys_loggers[i].subsys, "") != 0) &&
- (qb_logsys_loggers[i].init_status ==
- QB_LOGSYS_LOGGER_NEEDS_INIT)) {
- strncpy(tempsubsys, qb_logsys_loggers[i].subsys,
+ if ((strcmp(logsys_loggers[i].subsys, "") != 0) &&
+ (logsys_loggers[i].init_status ==
+ LOGSYS_LOGGER_NEEDS_INIT)) {
+ strncpy(tempsubsys, logsys_loggers[i].subsys,
QB_LOGSYS_MAX_SUBSYS_NAMELEN);
qb_logsys_subsys_init(tempsubsys, i);
}
@@ -1016,9 +825,9 @@ int _logsys_system_setup(const char *mainsystem,
return (0);
}
-unsigned int _logsys_subsys_create(const char *subsys)
+uint32_t _logsys_subsys_create(const char *subsys)
{
- int i;
+ int32_t i;
if ((subsys == NULL) ||
(strlen(subsys) >= QB_LOGSYS_MAX_SUBSYS_NAMELEN)) {
@@ -1034,7 +843,7 @@ unsigned int _logsys_subsys_create(const char *subsys)
}
for (i = 0; i < QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- if (strcmp(qb_logsys_loggers[i].subsys, "") == 0) {
+ if (strcmp(logsys_loggers[i].subsys, "") == 0) {
qb_logsys_subsys_init(subsys, i);
break;
}
@@ -1048,68 +857,30 @@ unsigned int _logsys_subsys_create(const char *subsys)
return i;
}
-int _logsys_wthread_create(void)
+int32_t _logsys_wthread_create(void)
{
- if (((qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].
- mode & QB_LOGSYS_MODE_FORK) == 0)
+ if (((logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].mode &
+ QB_LOGSYS_MODE_FORK) == 0)
&&
- ((qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].
- mode & QB_LOGSYS_MODE_THREADED) != 0)) {
+ ((logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].mode &
+ QB_LOGSYS_MODE_THREADED) != 0)) {
wthread_create();
atexit(qb_logsys_atexit);
}
return (0);
}
-int _logsys_rec_init(unsigned int fltsize)
+int32_t _logsys_rec_init(uint32_t fltsize)
{
- /*
- * we need to allocate:
- * - requested size +
- * 2 extra unsigned ints for HEAD/TAIL tracking
- *
- * then round it up to the next PAGESIZE
- */
- size_t flt_real_size;
-
- /*
- * XXX: kill me for 1.1 because I am a dirty hack
- * temporary workaround that will be replaced by supporting
- * 0 byte size flight recorder buffer.
- * 0 byte size buffer will enable direct printing to logs
- * without flight recoder.
- */
- if (fltsize < 64000) {
- fltsize = 64000;
- }
+ sem_init(&logsys_thread_start, 0, 0);
- flt_real_size = ROUNDUP((fltsize + (2 * sizeof(unsigned int))),
- sysconf(_SC_PAGESIZE));
+ sem_init(&logsys_print_finished, 0, 0);
- flt_data = malloc(flt_real_size);
- if (flt_data == NULL) {
- return (-1);
- }
-
- /*
- * flt_data_size tracks data by ints and not bytes/chars.
- *
- * the last 2 ints are reserved to store HEAD/TAIL information.
- * hide them from the rotating buffer.
- */
+ logsys_flt_lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
+ logsys_wthread_lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
- flt_data_size = ((flt_real_size / sizeof(unsigned int)) - 2);
-
- /*
- * First record starts at zero
- * Last record ends at zero
- */
- flt_data[FDHEAD_INDEX] = 0;
- flt_data[FDTAIL_INDEX] = 0;
-
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
- pthread_spin_init(&qb_logsys_idx_spinlock, 0);
-#endif
+ rb = qb_rb_open("logsys", fltsize,
+ QB_RB_FLAG_OVERWRITE | QB_RB_FLAG_CREATE);
return (0);
}
@@ -1130,20 +901,19 @@ int _logsys_rec_init(unsigned int fltsize)
* ... repeats length & arg
*/
-void _logsys_log_rec(unsigned int rec_ident,
+void _logsys_log_rec(uint32_t rec_ident,
const char *function_name,
- const char *file_name, int file_line, ...)
+ const char *file_name, int32_t file_line, ...)
{
va_list ap;
const void *buf_args[FDMAX_ARGS];
- unsigned int buf_len[FDMAX_ARGS];
- unsigned int i;
- unsigned int idx;
- unsigned int arguments = 0;
- unsigned int record_reclaim_size = 0;
- unsigned int index_start;
- int words_written;
- int subsysid;
+ uint32_t buf_len[FDMAX_ARGS];
+ uint32_t i;
+ uint32_t idx;
+ uint32_t arguments = 0;
+ uint32_t record_reclaim_size = 0;
+ int32_t subsysid;
+ int32_t *flt_data;
subsysid = QB_LOGSYS_DECODE_SUBSYSID(rec_ident);
@@ -1157,7 +927,7 @@ void _logsys_log_rec(unsigned int rec_ident,
if (buf_args[arguments] == QB_LOGSYS_REC_END) {
break;
}
- buf_len[arguments] = va_arg(ap, int);
+ buf_len[arguments] = va_arg(ap, int32_t);
record_reclaim_size += ((buf_len[arguments] + 3) >> 2) + 1;
arguments++;
if (arguments >= FDMAX_ARGS) {
@@ -1169,8 +939,8 @@ void _logsys_log_rec(unsigned int rec_ident,
/*
* Encode qb_logsys subsystem identity, filename, and function
*/
- buf_args[0] = qb_logsys_loggers[subsysid].subsys;
- buf_len[0] = strlen(qb_logsys_loggers[subsysid].subsys) + 1;
+ buf_args[0] = logsys_loggers[subsysid].subsys;
+ buf_len[0] = strlen(logsys_loggers[subsysid].subsys) + 1;
buf_args[1] = file_name;
buf_len[1] = strlen(file_name) + 1;
buf_args[2] = function_name;
@@ -1179,136 +949,70 @@ void _logsys_log_rec(unsigned int rec_ident,
record_reclaim_size += ((buf_len[i] + 3) >> 2) + 1;
}
- idx = flt_data[FDHEAD_INDEX];
- index_start = idx;
-
- /*
- * Reclaim data needed for record including 4 words for the header
- */
- records_reclaim(idx, record_reclaim_size + 4);
+ record_reclaim_size += 4;
+ qb_thread_lock(logsys_flt_lock);
- /*
- * Write record size of zero and rest of header information
- */
- flt_data[idx++] = 0;
- idx_word_step(idx);
+ flt_data =
+ qb_rb_chunk_writable_alloc(rb,
+ (record_reclaim_size *
+ sizeof(uint32_t)));
+ assert(flt_data != NULL);
+ idx = 0;
flt_data[idx++] = rec_ident;
- idx_word_step(idx);
-
flt_data[idx++] = file_line;
- idx_word_step(idx);
-
flt_data[idx++] = records_written;
- idx_word_step(idx);
/*
* Encode all of the arguments into the log message
*/
for (i = 0; i < arguments; i++) {
- unsigned int bytes;
- unsigned int full_words;
- unsigned int total_words;
+ uint32_t bytes;
+ uint32_t full_words;
+ uint32_t total_words;
bytes = buf_len[i];
full_words = bytes >> 2;
total_words = (bytes + 3) >> 2;
flt_data[idx++] = total_words;
- idx_word_step(idx);
+ memcpy(&flt_data[idx], buf_args[i], buf_len[i]);
- /*
- * determine if this is a wrapped write or normal write
- */
- if (idx + total_words < flt_data_size) {
- /*
- * dont need to wrap buffer
- */
- my_memcpy_32bit(&flt_data[idx], buf_args[i],
- full_words);
- if (bytes % 4) {
- my_memcpy_8bit((char *)
- &flt_data[idx + full_words],
- ((const char *)buf_args[i]) +
- (full_words << 2), bytes % 4);
- }
- } else {
- /*
- * need to wrap buffer
- */
- unsigned int first;
- unsigned int second;
-
- first = flt_data_size - idx;
- if (first > full_words) {
- first = full_words;
- }
- second = full_words - first;
- my_memcpy_32bit(&flt_data[idx],
- (const int *)buf_args[i], first);
- my_memcpy_32bit(&flt_data[0],
- (const int
- *)(((const unsigned char *)buf_args[i])
- + (first << 2)), second);
- if (bytes % 4) {
- my_memcpy_8bit((char *)&flt_data[0 + second],
- ((const char *)buf_args[i]) +
- (full_words << 2), bytes % 4);
- }
- }
idx += total_words;
- idx_buffer_step(idx);
- }
- words_written = idx - index_start;
- if (words_written < 0) {
- words_written += flt_data_size;
}
/*
* Commit the write of the record size now that the full record
* is in the memory buffer
*/
- flt_data[index_start] = words_written;
-
- /*
- * If the index of the current head equals the current log_rec_idx,
- * and this is not a log_printf operation, set the log_rec_idx to
- * the new head position and commit the new head.
- */
- qb_logsys_lock();
- if (QB_LOGSYS_DECODE_RECID(rec_ident) == QB_LOGSYS_RECID_LOG) {
- log_requests_pending += 1;
- }
- if (log_requests_pending == 0) {
- log_rec_idx = idx;
+ if (record_reclaim_size < idx) {
+ printf("record_reclaim_size:%u idx:%d commit_size:%lu",
+ record_reclaim_size, idx, (idx * sizeof(uint32_t)));
+ sleep(1);
+ assert(0);
}
- flt_data[FDHEAD_INDEX] = idx;
- qb_logsys_unlock();
+ qb_rb_chunk_writable_commit(rb, (idx * sizeof(uint32_t)));
+
+ qb_thread_unlock(logsys_flt_lock);
records_written++;
}
-void _logsys_log_vprintf(unsigned int rec_ident,
+void _logsys_log_vprintf(uint32_t rec_ident,
const char *function_name,
const char *file_name,
- int file_line, const char *format, va_list ap)
+ int32_t file_line, const char *format, va_list ap)
{
- char qb_logsys_print_buffer[COMBINE_BUFFER_SIZE];
- unsigned int len;
- unsigned int level;
- int subsysid;
+ char logsys_print_buffer[COMBINE_BUFFER_SIZE];
+ uint32_t len;
+ uint32_t level;
+ int32_t subsysid;
const char *short_file_name;
subsysid = QB_LOGSYS_DECODE_SUBSYSID(rec_ident);
level = QB_LOGSYS_DECODE_LEVEL(rec_ident);
- if ((level > qb_logsys_loggers[subsysid].syslog_priority) &&
- (level > qb_logsys_loggers[subsysid].logfile_priority) &&
- (qb_logsys_loggers[subsysid].debug == 0)) {
- return;
- }
-
- len = vsprintf(qb_logsys_print_buffer, format, ap);
- if (qb_logsys_print_buffer[len - 1] == '\n') {
- qb_logsys_print_buffer[len - 1] = '\0';
+ len = vsprintf(logsys_print_buffer, format, ap);
+ if (logsys_print_buffer[len - 1] == '\n') {
+ logsys_print_buffer[len - 1] = '\0';
len -= 1;
}
#ifdef BUILDING_IN_PLACE
@@ -1328,29 +1032,46 @@ void _logsys_log_vprintf(unsigned int rec_ident,
function_name,
short_file_name,
file_line,
- qb_logsys_print_buffer, len + 1, QB_LOGSYS_REC_END);
+ logsys_print_buffer, len + 1, QB_LOGSYS_REC_END);
- if ((qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].
- mode & QB_LOGSYS_MODE_THREADED) == 0) {
+ /*
+ * If logsys is not going to print a message to a log target don't
+ * queue one
+ */
+ if ((level > logsys_loggers[subsysid].syslog_priority &&
+ level > logsys_loggers[subsysid].logfile_priority &&
+ logsys_loggers[subsysid].debug == 0) ||
+ (level == QB_LOGSYS_LEVEL_DEBUG &&
+ logsys_loggers[subsysid].debug == 0)) {
+
+ return;
+ }
+
+ if ((logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].mode &
+ QB_LOGSYS_MODE_THREADED) == 0) {
/*
* Output (and block) if the log mode is not threaded otherwise
* expect the worker thread to output the log data once signaled
*/
log_printf_to_logs(rec_ident,
- short_file_name, function_name, file_line,
- qb_logsys_print_buffer);
+ short_file_name,
+ function_name,
+ file_line, logsys_print_buffer);
} else {
/*
* Signal worker thread to display logging output
*/
- wthread_signal();
+ log_printf_to_logs_wthread(rec_ident,
+ short_file_name,
+ function_name,
+ file_line, logsys_print_buffer);
}
}
-void _logsys_log_printf(unsigned int rec_ident,
+void _logsys_log_printf(uint32_t rec_ident,
const char *function_name,
const char *file_name,
- int file_line, const char *format, ...)
+ int32_t file_line, const char *format, ...)
{
va_list ap;
@@ -1360,9 +1081,9 @@ void _logsys_log_printf(unsigned int rec_ident,
va_end(ap);
}
-int _logsys_config_subsys_get(const char *subsys)
+int32_t _logsys_config_subsys_get(const char *subsys)
{
- unsigned int i;
+ uint32_t i;
pthread_mutex_lock(&qb_logsys_config_mutex);
@@ -1378,25 +1099,24 @@ int _logsys_config_subsys_get(const char *subsys)
*/
void qb_logsys_fork_completed(void)
{
- qb_logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].mode &=
- ~QB_LOGSYS_MODE_FORK;
+ logsys_loggers[QB_LOGSYS_MAX_SUBSYS_COUNT].mode &= ~QB_LOGSYS_MODE_FORK;
_logsys_wthread_create();
}
-unsigned int qb_logsys_config_mode_set(const char *subsys, unsigned int mode)
+int32_t qb_logsys_config_mode_set(const char *subsys, uint32_t mode)
{
- int i;
+ int32_t i;
pthread_mutex_lock(&qb_logsys_config_mutex);
if (subsys != NULL) {
i = _logsys_config_subsys_get_unlocked(subsys);
if (i >= 0) {
- qb_logsys_loggers[i].mode = mode;
+ logsys_loggers[i].mode = mode;
i = 0;
}
} else {
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- qb_logsys_loggers[i].mode = mode;
+ logsys_loggers[i].mode = mode;
}
i = 0;
}
@@ -1405,23 +1125,23 @@ unsigned int qb_logsys_config_mode_set(const char *subsys, unsigned int mode)
return i;
}
-unsigned int qb_logsys_config_mode_get(const char *subsys)
+uint32_t qb_logsys_config_mode_get(const char *subsys)
{
- int i;
+ int32_t i;
i = _logsys_config_subsys_get(subsys);
if (i < 0) {
return i;
}
- return qb_logsys_loggers[i].mode;
+ return logsys_loggers[i].mode;
}
-int qb_logsys_config_file_set(const char *subsys,
- const char **error_string, const char *file)
+int32_t qb_logsys_config_file_set(const char *subsys,
+ const char **error_string, const char *file)
{
- int i;
- int res;
+ int32_t i;
+ int32_t res;
pthread_mutex_lock(&qb_logsys_config_mutex);
@@ -1449,9 +1169,9 @@ int qb_logsys_config_file_set(const char *subsys,
return res;
}
-int qb_logsys_format_set(const char *format)
+int32_t qb_logsys_format_set(const char *format)
{
- int ret = 0;
+ int32_t ret = 0;
pthread_mutex_lock(&qb_logsys_config_mutex);
@@ -1474,16 +1194,16 @@ char *qb_logsys_format_get(void)
return format_buffer;
}
-unsigned int qb_logsys_config_syslog_facility_set(const char *subsys,
- unsigned int facility)
+int32_t qb_logsys_config_syslog_facility_set(const char *subsys,
+ uint32_t facility)
{
- int i;
+ int32_t i;
pthread_mutex_lock(&qb_logsys_config_mutex);
if (subsys != NULL) {
i = _logsys_config_subsys_get_unlocked(subsys);
if (i >= 0) {
- qb_logsys_loggers[i].syslog_facility = facility;
+ logsys_loggers[i].syslog_facility = facility;
if (i == QB_LOGSYS_MAX_SUBSYS_COUNT) {
syslog_facility_reconf();
}
@@ -1491,7 +1211,7 @@ unsigned int qb_logsys_config_syslog_facility_set(const char *subsys,
}
} else {
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- qb_logsys_loggers[i].syslog_facility = facility;
+ logsys_loggers[i].syslog_facility = facility;
}
syslog_facility_reconf();
i = 0;
@@ -1501,21 +1221,21 @@ unsigned int qb_logsys_config_syslog_facility_set(const char *subsys,
return i;
}
-unsigned int qb_logsys_config_syslog_priority_set(const char *subsys,
- unsigned int priority)
+int32_t qb_logsys_config_syslog_priority_set(const char *subsys,
+ uint32_t priority)
{
- int i;
+ int32_t i;
pthread_mutex_lock(&qb_logsys_config_mutex);
if (subsys != NULL) {
i = _logsys_config_subsys_get_unlocked(subsys);
if (i >= 0) {
- qb_logsys_loggers[i].syslog_priority = priority;
+ logsys_loggers[i].syslog_priority = priority;
i = 0;
}
} else {
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- qb_logsys_loggers[i].syslog_priority = priority;
+ logsys_loggers[i].syslog_priority = priority;
}
i = 0;
}
@@ -1524,21 +1244,21 @@ unsigned int qb_logsys_config_syslog_priority_set(const char *subsys,
return i;
}
-unsigned int qb_logsys_config_logfile_priority_set(const char *subsys,
- unsigned int priority)
+int32_t qb_logsys_config_logfile_priority_set(const char *subsys,
+ uint32_t priority)
{
- int i;
+ int32_t i;
pthread_mutex_lock(&qb_logsys_config_mutex);
if (subsys != NULL) {
i = _logsys_config_subsys_get_unlocked(subsys);
if (i >= 0) {
- qb_logsys_loggers[i].logfile_priority = priority;
+ logsys_loggers[i].logfile_priority = priority;
i = 0;
}
} else {
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- qb_logsys_loggers[i].logfile_priority = priority;
+ logsys_loggers[i].logfile_priority = priority;
}
i = 0;
}
@@ -1547,20 +1267,20 @@ unsigned int qb_logsys_config_logfile_priority_set(const char *subsys,
return i;
}
-unsigned int qb_logsys_config_debug_set(const char *subsys, unsigned int debug)
+int32_t qb_logsys_config_debug_set(const char *subsys, uint32_t debug)
{
- int i;
+ int32_t i;
pthread_mutex_lock(&qb_logsys_config_mutex);
if (subsys != NULL) {
i = _logsys_config_subsys_get_unlocked(subsys);
if (i >= 0) {
- qb_logsys_loggers[i].debug = debug;
+ logsys_loggers[i].debug = debug;
i = 0;
}
} else {
for (i = 0; i <= QB_LOGSYS_MAX_SUBSYS_COUNT; i++) {
- qb_logsys_loggers[i].debug = debug;
+ logsys_loggers[i].debug = debug;
}
i = 0;
}
@@ -1569,9 +1289,9 @@ unsigned int qb_logsys_config_debug_set(const char *subsys, unsigned int debug)
return i;
}
-int qb_logsys_facility_id_get(const char *name)
+int32_t qb_logsys_facility_id_get(const char *name)
{
- unsigned int i;
+ uint32_t i;
for (i = 0; facilitynames[i].c_name != NULL; i++) {
if (strcasecmp(name, facilitynames[i].c_name) == 0) {
@@ -1581,9 +1301,9 @@ int qb_logsys_facility_id_get(const char *name)
return (-1);
}
-const char *qb_logsys_facility_name_get(unsigned int facility)
+const char *qb_logsys_facility_name_get(uint32_t facility)
{
- unsigned int i;
+ uint32_t i;
for (i = 0; facilitynames[i].c_name != NULL; i++) {
if (facility == facilitynames[i].c_val) {
@@ -1593,9 +1313,9 @@ const char *qb_logsys_facility_name_get(unsigned int facility)
return (NULL);
}
-int qb_logsys_priority_id_get(const char *name)
+int32_t qb_logsys_priority_id_get(const char *name)
{
- unsigned int i;
+ uint32_t i;
for (i = 0; prioritynames[i].c_name != NULL; i++) {
if (strcasecmp(name, prioritynames[i].c_name) == 0) {
@@ -1605,9 +1325,9 @@ int qb_logsys_priority_id_get(const char *name)
return (-1);
}
-const char *qb_logsys_priority_name_get(unsigned int priority)
+const char *qb_logsys_priority_name_get(uint32_t priority)
{
- unsigned int i;
+ uint32_t i;
for (i = 0; prioritynames[i].c_name != NULL; i++) {
if (priority == prioritynames[i].c_val) {
@@ -1617,11 +1337,11 @@ const char *qb_logsys_priority_name_get(unsigned int priority)
return (NULL);
}
-int qb_logsys_thread_priority_set(int policy,
- const struct sched_param *param,
- unsigned int after_log_ops_yield)
+int32_t qb_logsys_thread_priority_set(int32_t policy,
+ const struct sched_param * param,
+ uint32_t after_log_ops_yield)
{
- int res = 0;
+ int32_t res = 0;
#if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
if (wthread_active == 0) {
@@ -1635,36 +1355,27 @@ int qb_logsys_thread_priority_set(int policy,
#endif
if (after_log_ops_yield > 0) {
- qb_logsys_after_log_ops_yield = after_log_ops_yield;
+ logsys_after_log_ops_yield = after_log_ops_yield;
}
return (res);
}
-int qb_logsys_log_rec_store(const char *filename)
+int32_t qb_logsys_log_rec_store(const char *filename)
{
- int fd;
+ int32_t fd;
ssize_t written_size;
- size_t size_to_write = (flt_data_size + 2) * sizeof(unsigned int);
fd = open(filename, O_CREAT | O_RDWR, 0700);
if (fd < 0) {
return (-1);
}
- written_size = write(fd, &flt_data_size, sizeof(unsigned int));
- if ((written_size < 0) || (written_size != sizeof(unsigned int))) {
- close(fd);
- return (-1);
- }
-
- written_size = write(fd, flt_data, size_to_write);
+ written_size = qb_rb_write_to_file(rb, fd);
if (close(fd) != 0)
return (-1);
if (written_size < 0) {
return (-1);
- } else if ((size_t) written_size != size_to_write) {
- return (-1);
}
return (0);
@@ -1672,14 +1383,43 @@ int qb_logsys_log_rec_store(const char *filename)
void qb_logsys_atexit(void)
{
- if (wthread_active) {
+ int32_t res;
+ int32_t value;
+ struct record *rec;
+
+ if (wthread_active == 0) {
+ for (;;) {
+ qb_thread_lock(logsys_wthread_lock);
+
+ res = sem_getvalue(&logsys_print_finished, &value);
+ if (value == 0) {
+ qb_thread_unlock(logsys_wthread_lock);
+ return;
+ }
+ sem_wait(&logsys_print_finished);
+
+ rec =
+ qb_list_entry(logsys_print_finished_records.next,
+ struct record, list);
+ qb_list_del(&rec->list);
+ logsys_memory_used =
+ logsys_memory_used - strlen(rec->buffer) -
+ sizeof(struct record) - 1;
+ qb_thread_unlock(logsys_wthread_lock);
+ log_printf_to_logs(rec->rec_ident,
+ rec->file_name,
+ rec->function_name,
+ rec->file_line, rec->buffer);
+ free(rec->buffer);
+ free(rec);
+ }
+ } else {
wthread_should_exit = 1;
- wthread_signal();
- pthread_join(qb_logsys_thread_id, NULL);
+ sem_post(&logsys_print_finished);
+ pthread_join(logsys_thread_id, NULL);
}
}
void qb_logsys_flush(void)
{
- wthread_signal();
}
--
1.6.6.1
13 years, 9 months
[PATCH] Add a script for indenting the code (kernel formatting)
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
Lindent | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
create mode 100755 Lindent
diff --git a/Lindent b/Lindent
new file mode 100755
index 0000000..68bf25e
--- /dev/null
+++ b/Lindent
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# This is a copy of the linux kernel's Lindent because
+# we use the same formatting. No point re-inventing that
+# wheel.
+#
+PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
+RES=`indent --version`
+V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
+V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
+V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
+if [ $V1 -gt 2 ]; then
+ PARAM="$PARAM -il0"
+elif [ $V1 -eq 2 ]; then
+ if [ $V2 -gt 2 ]; then
+ PARAM="$PARAM -il0";
+ elif [ $V2 -eq 2 ]; then
+ if [ $V3 -ge 10 ]; then
+ PARAM="$PARAM -il0"
+ fi
+ fi
+fi
+indent $PARAM "$@"
+
--
1.6.6.1
13 years, 9 months