Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbipcs.h | 12 ------------
lib/Makefile.am | 5 +++++
lib/hash.c | 3 +++
lib/ipcc.c | 1 +
lib/ipcs.c | 36 +++++++++++-------------------------
lib/poll.c | 1 +
lib/util_int.h | 4 +++-
tests/bms.c | 18 ++++++++----------
8 files changed, 32 insertions(+), 48 deletions(-)
diff --git a/include/qb/qbipcs.h b/include/qb/qbipcs.h
index 6a35792..73ad6e2 100644
--- a/include/qb/qbipcs.h
+++ b/include/qb/qbipcs.h
@@ -41,9 +41,6 @@ struct qb_ipcs_init_state {
const struct sched_param *sched_param;
void *(*malloc) (size_t size);
void (*free) (void *ptr);
- void (*old_log_printf) (
- const char *format,
- ...) __attribute__((format(printf, 1, 2)));
int (*service_available)(unsigned int service);
int (*private_data_size_get)(unsigned int service);
int (*security_valid)(int uid, int gid);
@@ -60,21 +57,12 @@ struct qb_ipcs_init_state {
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);
- /* v2 functions */
qb_hdb_handle_t (*stats_create_connection) (const char* name,
pid_t pid, int 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, size_t value_len);
void (*stats_increment_value) (qb_hdb_handle_t handle, const char* name);
- void (*log_printf) (
- unsigned int rec_ident,
- const char *function_name,
- const char *file_name,
- int file_line,
- const char *format,
- ...) __attribute__((format(printf, 5, 6)));
- int log_subsys_id;
void (*stats_decrement_value) (qb_hdb_handle_t handle, const char* name);
};
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ee2a7c4..90c6248 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -53,10 +53,12 @@ libqbutil_la_SOURCES = util.c
libqbhash_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqbhash_la_LDFLAGS = -version-info 0:0:0
libqbhash_la_SOURCES = hash.c
+libqbhash_la_LIBADD = libqbutil.la
libqbpoll_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqbpoll_la_LDFLAGS = -version-info 0:0:0
libqbpoll_la_SOURCES = poll.c
+libqbpoll_la_LIBADD = libqbutil.la
libqbtimer_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqbtimer_la_LDFLAGS = -version-info 0:0:0
@@ -73,12 +75,15 @@ libqbtsafe_la_SOURCES = tsafe.c
libqbwthread_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqbwthread_la_LDFLAGS = -version-info 0:0:0
libqbwthread_la_SOURCES = wthread.c
+libqbwthread_la_LIBADD = libqbutil.la
libqbipcc_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqbipcc_la_LDFLAGS = -version-info 0:0:0
libqbipcc_la_SOURCES = ipcc.c
+libqbipcc_la_LIBADD = libqbutil.la
libqbipcs_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqbipcs_la_LDFLAGS = -version-info 0:0:0
libqbipcs_la_SOURCES = ipcs.c
+libqbipcs_la_LIBADD = libqbutil.la
diff --git a/lib/hash.c b/lib/hash.c
index cdd2319..b0800d3 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -24,6 +24,7 @@
#include <config.h>
#include "os_base.h"
+#include "util_int.h"
#include <qb/qbhdb.h>
#include <qb/qblist.h>
@@ -87,10 +88,12 @@ int32_t qb_hash_initialize (
res = qb_hdb_handle_create (&qb_hash_handle_db, size, handle);
if (res != 0) {
+ qb_util_log(LOG_ERR, "could not create handle (%s)", strerror(errno));
return (res);
}
res = qb_hdb_handle_get (&qb_hash_handle_db, *handle, (void *)&hash_table);
if (res != 0) {
+ qb_util_log(LOG_ERR, "could not get handle (%s)", strerror(errno));
goto hash_destroy;
}
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 062c70d..fb7d578 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -28,6 +28,7 @@
#include <qb/qbipcc.h>
#include <qb/qbhdb.h>
#include "ipc_int.h"
+#include "util_int.h"
#if _POSIX_THREAD_PROCESS_SHARED > 0
#include <semaphore.h>
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 4265937..5824c83 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -37,10 +37,7 @@
#include <qb/qbhdb.h>
#include <qb/qbipcs.h>
#include "ipc_int.h"
-
-//#define LOGSYS_UTILS_ONLY 1
-#include <syslog.h>
-//#include <qb/engine/logsys.h>
+#include "util_int.h"
#if _POSIX_THREAD_PROCESS_SHARED > 0
#include <semaphore.h>
@@ -141,16 +138,6 @@ 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);
-#define log_printf(level, format, args...) \
-do { \
- api->log_printf ( level, \
- /*LOGSYS_ENCODE_RECID(level, */\
- /*api->log_subsys_id,*/ \
- /*LOGSYS_RECID_LOG),*/ \
- __FUNCTION__, __FILE__, __LINE__, \
- (const char *)format, ##args); \
-} while (0)
-
static qb_hdb_handle_t dummy_stats_create_connection (
const char *name,
pid_t pid,
@@ -819,11 +806,11 @@ retry_recv:
#else /* no credentials */
authenticated = 1;
- log_printf (LOG_ERR, "Platform does not support IPC authentication. Using no
authentication\n");
+ qb_util_log (LOG_ERR, "Platform does not support IPC authentication. Using no
authentication\n");
#endif /* no credentials */
if (authenticated == 0) {
- log_printf (LOG_ERR, "Invalid IPC credentials.\n");
+ qb_util_log (LOG_ERR, "Invalid IPC credentials.\n");
ipc_disconnect (conn_info);
return (-1);
}
@@ -898,7 +885,6 @@ extern void qb_ipcs_ipc_init (
int res;
api = init_state;
- api->old_log_printf = NULL;
api->stats_create_connection = dummy_stats_create_connection;
api->stats_destroy_connection = dummy_stats_destroy_connection;
api->stats_update_value = dummy_stats_update_value;
@@ -913,7 +899,7 @@ extern void qb_ipcs_ipc_init (
server_fd = socket (PF_LOCAL, SOCK_STREAM, 0);
#endif
if (server_fd == -1) {
- log_printf (LOG_CRIT, "Cannot create client connections socket.\n");
+ qb_util_log (LOG_CRIT, "Cannot create client connections socket.\n");
api->fatal_error ("Can't create library listen socket");
};
@@ -921,7 +907,7 @@ extern void qb_ipcs_ipc_init (
if (res == -1) {
char error_str[100];
strerror_r (errno, error_str, 100);
- log_printf (LOG_CRIT, "Could not set non-blocking operation on server socket:
%s\n", error_str);
+ qb_util_log (LOG_CRIT, "Could not set non-blocking operation on server socket:
%s\n", error_str);
api->fatal_error ("Could not set non-blocking operation on server
socket");
}
@@ -938,7 +924,7 @@ extern void qb_ipcs_ipc_init (
struct stat stat_out;
res = stat (SOCKETDIR, &stat_out);
if (res == -1 || (res == 0 && !S_ISDIR(stat_out.st_mode))) {
- log_printf (LOG_CRIT, "Required directory not present %s\n", SOCKETDIR);
+ qb_util_log (LOG_CRIT, "Required directory not present %s\n", SOCKETDIR);
api->fatal_error ("Please create required directory.");
}
sprintf (un_addr.sun_path, "%s/%s", SOCKETDIR, api->socket_name);
@@ -950,7 +936,7 @@ extern void qb_ipcs_ipc_init (
if (res) {
char error_str[100];
strerror_r (errno, error_str, 100);
- log_printf (LOG_CRIT, "Could not bind AF_UNIX (%s): %s.\n", un_addr.sun_path,
error_str);
+ qb_util_log (LOG_CRIT, "Could not bind AF_UNIX (%s): %s.\n",
un_addr.sun_path, error_str);
api->fatal_error ("Could not bind to AF_UNIX socket\n");
}
@@ -1180,10 +1166,10 @@ static int flow_control_event_send (struct conn_info *conn_info,
char event)
if (conn_info->flow_control_state != new_fc) {
if (new_fc == 1) {
- log_printf (LOG_INFO, "Enabling flow control for %d, event %d\n",
+ qb_util_log (LOG_INFO, "Enabling flow control for %d, event %d\n",
conn_info->client_pid, event);
} else {
- log_printf (LOG_INFO, "Disabling flow control for %d, event %d\n",
+ qb_util_log (LOG_INFO, "Disabling flow control for %d, event %d\n",
conn_info->client_pid, event);
}
conn_info->flow_control_state = new_fc;
@@ -1446,7 +1432,7 @@ retry_accept:
if (new_fd == -1) {
char error_str[100];
strerror_r (errno, error_str, 100);
- log_printf (LOG_ERR,
+ qb_util_log (LOG_ERR,
"Could not accept Library connection: %s\n", error_str);
return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
}
@@ -1455,7 +1441,7 @@ retry_accept:
if (res == -1) {
char error_str[100];
strerror_r (errno, error_str, 100);
- log_printf (LOG_ERR,
+ qb_util_log (LOG_ERR,
"Could not set non-blocking operation on library connection: %s\n",
error_str);
close (new_fd);
diff --git a/lib/poll.c b/lib/poll.c
index f1fed9d..3d4a322 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -32,6 +32,7 @@
#include <qb/qbpoll.h>
#include <qb/qblist.h>
#include "tlist.h"
+#include "util_int.h"
typedef int (*dispatch_fn_t) (qb_hdb_handle_t hdb_handle, int fd, int revents, void
*data);
diff --git a/lib/util_int.h b/lib/util_int.h
index d91f205..76a3b84 100644
--- a/lib/util_int.h
+++ b/lib/util_int.h
@@ -20,6 +20,8 @@
#ifndef QB_UTIL_INT_H_DEFINED
#define QB_UTIL_INT_H_DEFINED
+#include <syslog.h>
+
#define qb_util_log(severity, args...) \
do { \
_qb_util_log (__FILE__, __LINE__, severity, ##args); \
@@ -29,7 +31,7 @@ void _qb_util_log (const char *file_name,
int32_t file_line,
int32_t severity,
const char *format,
- ...);
+ ...) __attribute__((format(printf, 4, 5)));
#endif /* QB_UTIL_INT_H_DEFINED */
diff --git a/tests/bms.c b/tests/bms.c
index f197e4f..4bb6985 100644
--- a/tests/bms.c
+++ b/tests/bms.c
@@ -42,6 +42,7 @@
#include <stdarg.h>
#include <sched.h>
+#include <qb/qbutil.h>
#include <qb/qbpoll.h>
#include <qb/qbipcs.h>
@@ -183,16 +184,12 @@ static void bms_sending_allowed_release (void
*sending_allowed_private_data)
{
}
-static void ipc_log_printf (const char *format, ...) __attribute__((format(printf, 1,
2)));
-static void ipc_log_printf (const char *format, ...)
+static void ipc_log_fn(const char *file_name,
+ int32_t file_line,
+ int32_t severity,
+ const char *msg)
{
- va_list ap;
-
- va_start (ap, format);
-
- vfprintf (stderr, format, ap);
-
- va_end (ap);
+ fprintf (stderr, "%s:%d [%d] %s", file_name, file_line, severity, msg);
}
static void ipc_fatal_error (const char *error_msg)
@@ -264,7 +261,6 @@ struct qb_ipcs_init_state ipc_init_state = {
.sched_param = NULL,
.malloc = malloc,
.free = free,
- .log_printf = ipc_log_printf,
.fatal_error = ipc_fatal_error,
.security_valid = bms_security_valid,
.service_available = bms_service_available,
@@ -324,6 +320,8 @@ int main (int argc, char *argv[])
}
signal (SIGUSR1, sigusr1_handler);
+ qb_util_set_log_function (ipc_log_fn);
+
bms_poll_handle = qb_poll_create ();
qb_ipcs_ipc_init (&ipc_init_state);
--
1.6.6.1