From 6ed63b12d43ea41a40234952f6e755f68b60feb3 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Tue, 23 Jul 2013 13:17:32 +0200 Subject: [PATCH] Cleanup of fprintf's --- core/adminusers.c | 1 + core/config.c | 10 ++++++---- core/dbusers.c | 18 ++++++++++-------- core/dcb.c | 9 +++++++-- core/load_utils.c | 16 +++++++++++----- core/monitor.c | 4 +++- core/utils.c | 6 ++++-- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/core/adminusers.c b/core/adminusers.c index c824e8b35..ea8412317 100644 --- a/core/adminusers.c +++ b/core/adminusers.c @@ -142,6 +142,7 @@ char fname[1024], *home, *cpasswd; sprintf(fname, "/usr/local/skysql/MaxScale/etc/passwd"); if (users == NULL) { + skygw_log_write(NULL, LOGFILE_MESSAGE, "Create initial password file.\n"); if ((users = users_alloc()) == NULL) return ADMIN_ERR_NOMEM; if ((fp = fopen(fname, "w")) == NULL) diff --git a/core/config.c b/core/config.c index 267009439..005c02281 100644 --- a/core/config.c +++ b/core/config.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include static int process_config_context(CONFIG_CONTEXT *); static int process_config_update(CONFIG_CONTEXT *); @@ -168,7 +170,7 @@ CONFIG_CONTEXT *obj; { char *type = config_get_value(obj->parameters, "type"); if (type == NULL) - fprintf(stderr, "Object %s has no type\n", obj->object); + skygw_log_write(NULL, LOGFILE_ERROR, "Object %s has no type\n", obj->object); else if (!strcmp(type, "service")) { char *router = config_get_value(obj->parameters, "router"); @@ -181,7 +183,7 @@ CONFIG_CONTEXT *obj; serviceSetUser(obj->element, user, auth); } else - fprintf(stderr, "No router define for service '%s'\n", + skygw_log_write(NULL, LOGFILE_ERROR, "No router define for service '%s'\n", obj->object); } else if (!strcmp(type, "server")) @@ -397,7 +399,7 @@ SERVER *server; { char *type = config_get_value(obj->parameters, "type"); if (type == NULL) - fprintf(stderr, "Object %s has no type\n", obj->object); + skygw_log_write(NULL, LOGFILE_ERROR, "Object %s has no type\n", obj->object); else if (!strcmp(type, "service")) { char *router = config_get_value(obj->parameters, "router"); @@ -420,7 +422,7 @@ SERVER *server; } } else - fprintf(stderr, "No router defined for service '%s'\n", + skygw_log_write(NULL, LOGFILE_ERROR, "No router defined for service '%s'\n", obj->object); } else if (!strcmp(type, "server")) diff --git a/core/dbusers.c b/core/dbusers.c index 8530914a2..1129129c0 100644 --- a/core/dbusers.c +++ b/core/dbusers.c @@ -107,7 +107,7 @@ getUsers(SERVICE *service, struct users *users) con = mysql_init(NULL); if (con == NULL) { - fprintf(stderr, "%s\n", mysql_error(con)); + skygw_log_write(NULL, LOGFILE_ERROR, "mysql_init: %s\n", mysql_error(con)); return -1; } @@ -135,13 +135,17 @@ getUsers(SERVICE *service, struct users *users) } if (server == NULL) { - fprintf(stderr, "%s\n", mysql_error(con)); + skygw_log_write(NULL, LOGFILE_ERROR, + "Unable to find a to load user data from for service %s\n", + service->name); mysql_close(con); return -1; } if (mysql_query(con, "SELECT user, password FROM mysql.user")) { - fprintf(stderr, ">>>>> %s\n", mysql_error(con)); + skygw_log_write(NULL, LOGFILE_ERROR, + "Loading users for service %s encountered error: %s\n", + service->name, mysql_error(con)); mysql_close(con); return -1; } @@ -149,7 +153,9 @@ getUsers(SERVICE *service, struct users *users) result = mysql_store_result(con); if (result == NULL) { - fprintf(stderr, "%s\n", mysql_error(con)); + skygw_log_write(NULL, LOGFILE_ERROR, + "Loading users for service %s encountered error: %s\n", + service->name, mysql_error(con)); mysql_close(con); return -1; } @@ -158,8 +164,6 @@ getUsers(SERVICE *service, struct users *users) while ((row = mysql_fetch_row(result))) { // we assume here two fields are returned !!! - //printf("User %s , Passwd %s\n", row[0], row[1]); - // now adding to the hastable user and passwd+1 (escaping the first byte that is '*') users_add(users, row[0], row[1]+1); total_users++; @@ -171,5 +175,3 @@ getUsers(SERVICE *service, struct users *users) return total_users; } -///// - diff --git a/core/dcb.c b/core/dcb.c index 697319a25..27c0ebb92 100644 --- a/core/dcb.c +++ b/core/dcb.c @@ -39,6 +39,7 @@ * for handling backend asynchronous protocol connection * and a generic lock for backend authentication * 16/07/2013 Massimiliano Pinto Added command type for dcb + * 23/07/13 Mark Riddoch Tidy up logging * * @endverbatim */ @@ -57,6 +58,8 @@ #include #include #include +#include +#include static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */ static DCB *zombies = NULL; @@ -262,7 +265,8 @@ GWPROTOCOL *funcs; if ((funcs = (GWPROTOCOL *)load_module(protocol, MODULE_PROTOCOL)) == NULL) { dcb_final_free(dcb); - fprintf(stderr, "Failed to load protocol module for %s, feee dcb %p\n", protocol, dcb); + skygw_log_write(NULL, LOGFILE_ERROR, + "Failed to load protocol module for %s, feee dcb %p\n", protocol, dcb); return NULL; } memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL)); @@ -271,7 +275,8 @@ GWPROTOCOL *funcs; if ((dcb->fd = dcb->func.connect(dcb, server, session)) == -1) { dcb_final_free(dcb); - fprintf(stderr, "Failed to connect to server, feee dcb %p\n", dcb); + skygw_log_write(NULL, LOGFILE_ERROR, "Failed to connect to server %s:%d, free dcb %p\n", + server->name, server->port, dcb); return NULL; } atomic_add(&server->stats.n_connections, 1); diff --git a/core/load_utils.c b/core/load_utils.c index cd7b2e721..eeb14f944 100644 --- a/core/load_utils.c +++ b/core/load_utils.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include static MODULES *registered = NULL; @@ -79,19 +81,22 @@ MODULES *mod; sprintf(fname, "%s/modules/lib%s.so", home, module); if (access(fname, F_OK) == -1) { - fprintf(stderr, "Unable to find library for module: %s\n", module); + skygw_log_write(NULL, LOGFILE_ERROR, + "Unable to find library for module: %s\n", module); return NULL; } } if ((dlhandle = dlopen(fname, RTLD_NOW|RTLD_LOCAL)) == NULL) { - fprintf(stderr, "Unable to load library for module: %s, %s\n", module, dlerror()); + skygw_log_write(NULL, LOGFILE_ERROR, + "Unable to load library for module: %s, %s\n", module, dlerror()); return NULL; } if ((sym = dlsym(dlhandle, "version")) == NULL) { - fprintf(stderr, "Version interface not supported by module: %s, %s\n", module, dlerror()); + skygw_log_write(NULL, LOGFILE_ERROR, + "Version interface not supported by module: %s, %s\n", module, dlerror()); dlclose(dlhandle); return NULL; } @@ -109,14 +114,15 @@ MODULES *mod; if ((sym = dlsym(dlhandle, "GetModuleObject")) == NULL) { - fprintf(stderr, "Expected entry point interface missing from module: %s, %s\n", module, dlerror()); + skygw_log_write(NULL, LOGFILE_ERROR, + "Expected entry point interface missing from module: %s, %s\n", module, dlerror()); dlclose(dlhandle); return NULL; } ep = sym; modobj = ep(); - fprintf(stderr, "Loaded module %s: %s\n", module, version); + skygw_log_write(NULL, LOGFILE_MESSAGE, "Loaded module %s: %s\n", module, version); register_module(module, type, dlhandle, version, modobj); } else diff --git a/core/monitor.c b/core/monitor.c index 1ba454a10..922e17e82 100644 --- a/core/monitor.c +++ b/core/monitor.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include static MONITOR *allMonitors = NULL; @@ -59,7 +61,7 @@ MONITOR *mon; mon->name = strdup(name); if ((mon->module = load_module(module, MODULE_MONITOR)) == NULL) { - fprintf(stderr, "Unable to load monitor module '%s'\n", name); + skygw_log_write(NULL, LOGFILE_ERROR, "Unable to load monitor module '%s'\n", name); free(mon->name); free(mon); return NULL; diff --git a/core/utils.c b/core/utils.c index 604bb0af4..982528427 100644 --- a/core/utils.c +++ b/core/utils.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include // used in the hex2bin function #define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ @@ -60,12 +62,12 @@ int setnonblocking(int fd) { int fl; if ((fl = fcntl(fd, F_GETFL, 0)) == -1) { - fprintf(stderr, "Can't GET fcntli for %i, errno = %d, %s", fd, errno, strerror(errno)); + skygw_log_write(NULL, LOGFILE_ERROR, "Can't GET fcntl for %i, errno = %d, %s", fd, errno, strerror(errno)); return 1; } if (fcntl(fd, F_SETFL, fl | O_NONBLOCK) == -1) { - fprintf(stderr, "Can't SET fcntl for %i, errno = %d, %s", fd, errno, strerror(errno)); + skygw_log_write(NULL, LOGFILE_ERROR, "Can't SET fcntl for %i, errno = %d, %s", fd, errno, strerror(errno)); return 1; }