This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: master - ccsd: port to logthread infrastructure
- From: "Fabio M. Di Nitto" <fabbione at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Wed, 17 Dec 2008 08:06:13 +0000 (UTC)
- Subject: cluster: master - ccsd: port to logthread infrastructure
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=13d6d2cccdd70769c5681e8294a17bd021814a2b
Commit: 13d6d2cccdd70769c5681e8294a17bd021814a2b
Parent: 7f422440a1c236d52f08ef045efb9cce976fa93b
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate: Wed Dec 17 09:04:54 2008 +0100
Committer: Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Wed Dec 17 09:04:54 2008 +0100
ccsd: port to logthread infrastructure
Several changes across the whole tree to use logthread instead of logsys.
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
config/daemons/ccsd/Makefile | 4 +-
config/daemons/ccsd/ccsd.c | 145 ++++++++----------
config/daemons/ccsd/cluster_mgr.c | 100 ++++++------
config/daemons/ccsd/cnx_mgr.c | 292 ++++++++++++++++++------------------
config/daemons/ccsd/debug.h | 4 +-
config/daemons/ccsd/misc.c | 302 ++++++++++++++++++++++++------------
config/daemons/ccsd/misc.h | 2 +-
7 files changed, 466 insertions(+), 383 deletions(-)
diff --git a/config/daemons/ccsd/Makefile b/config/daemons/ccsd/Makefile
index 4e3efd3..97802ea 100644
--- a/config/daemons/ccsd/Makefile
+++ b/config/daemons/ccsd/Makefile
@@ -17,12 +17,12 @@ OBJS= ccsd.o \
globals.o
CFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
-CFLAGS += -I${cmanincdir} `xml2-config --cflags` -I${corosyncincdir}
+CFLAGS += -I${cmanincdir} `xml2-config --cflags` -I${logtincdir}
CFLAGS += -I$(S)
CFLAGS += -I${incdir}
LDFLAGS += -L${cmanlibdir} -lcman
-LDFLAGS += -L${corosynclibdir} -llogsys
+LDFLAGS += -L${logtlibdir} -llogthread
LDFLAGS += `xml2-config --libs` -lpthread
LDFLAGS += -L${libdir}
diff --git a/config/daemons/ccsd/ccsd.c b/config/daemons/ccsd/ccsd.c
index d3b63d8..452fcec 100644
--- a/config/daemons/ccsd/ccsd.c
+++ b/config/daemons/ccsd/ccsd.c
@@ -13,7 +13,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <libxml/parser.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include "debug.h"
#include "cnx_mgr.h"
@@ -25,13 +25,12 @@
#include "copyright.cf"
int debug = 0;
+int nodaemon = 0;
extern volatile int quorate;
int no_manager_opt=0;
static int exit_now=0;
-static unsigned int flags=0;
static sigset_t signal_mask;
static int signal_received = 0;
-#define FLAG_NODAEMON 1
static char *parse_cli_args(int argc, char *argv[]);
static int check_cluster_conf(void);
@@ -51,33 +50,17 @@ int main(int argc, char *argv[]){
int addr_size=0;
fd_set rset, tmp_set;
char *msg;
- unsigned int logmode;
- logsys_init("CCS", LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE | LOG_MODE_FILTER_DEBUG_FROM_SYSLOG | LOG_MODE_BUFFER_BEFORE_CONFIG, SYSLOGFACILITY, SYSLOGLEVEL, LOGDIR "/ccs.log");
-
- msg = parse_cli_args(argc, argv);
-
- if(getenv("CCS_DEBUGLOG"))
+ if(getenv("CCS_DEBUGLOG"))
debug = 1;
- /* enable debug as early as possible */
- if(debug)
- logsys_config_priority_set (LOG_LEVEL_DEBUG);
+ msg = parse_cli_args(argc, argv);
if(check_cluster_conf()){
/* check_cluster_conf will print out errors if there are any */
exit(EXIT_FAILURE);
}
- logmode = logsys_config_mode_get();
-
- if(logmode & LOG_MODE_BUFFER_BEFORE_CONFIG) {
- log_printf(LOG_DEBUG, "Using default CCS logsys config options\n");
- logmode &= ~LOG_MODE_BUFFER_BEFORE_CONFIG;
- logmode |= LOG_MODE_FLUSH_AFTER_CONFIG;
- logsys_config_mode_set (logmode);
- }
-
daemonize();
print_start_msg(msg);
@@ -88,7 +71,7 @@ int main(int argc, char *argv[]){
if (!no_manager_opt){
if(start_cluster_monitor_thread()){
- log_printf(LOG_ERR, "Unable to create thread.\n");
+ logt_print(LOG_ERR, "Unable to create thread.\n");
exit(EXIT_FAILURE);
}
}
@@ -98,10 +81,10 @@ int main(int argc, char *argv[]){
/** Setup the socket to communicate with the CCS library **/
if(IPv6 && (sfds[0] = socket(PF_INET6, SOCK_STREAM, 0)) < 0){
if(IPv6 == -1){
- log_printf(LOG_DEBUG, "Unable to create IPv6 socket:: %s\n", strerror(errno));
+ logt_print(LOG_DEBUG, "Unable to create IPv6 socket:: %s\n", strerror(errno));
IPv6=0;
} else {
- log_printf(LOG_ERR, "Unable to create IPv6 socket");
+ logt_print(LOG_ERR, "Unable to create IPv6 socket");
exit(EXIT_FAILURE);
}
} else {
@@ -110,15 +93,15 @@ int main(int argc, char *argv[]){
*/
}
- log_printf(LOG_DEBUG, "Using %s\n", IPv6?"IPv6":"IPv4");
+ logt_print(LOG_DEBUG, "Using %s\n", IPv6?"IPv6":"IPv4");
if(!IPv6 && (sfds[0] = socket(PF_INET, SOCK_STREAM, 0)) < 0){
- log_printf(LOG_ERR, "Unable to create IPv4 socket");
+ logt_print(LOG_ERR, "Unable to create IPv4 socket");
exit(EXIT_FAILURE);
}
if(setsockopt(sfds[0], SOL_SOCKET, SO_REUSEADDR, &trueint, sizeof(int))){
- log_printf(LOG_ERR, "Unable to set socket option");
+ logt_print(LOG_ERR, "Unable to set socket option");
exit(EXIT_FAILURE);
}
@@ -136,7 +119,7 @@ int main(int argc, char *argv[]){
}
if(bind(sfds[0], (struct sockaddr *)&addr, addr_size) < 0){
- log_printf(LOG_ERR, "Unable to bind socket");
+ logt_print(LOG_ERR, "Unable to bind socket");
close(sfds[0]);
exit(EXIT_FAILURE);
}
@@ -147,12 +130,12 @@ int main(int argc, char *argv[]){
/** Setup the socket to communicate with the CCS library **/
sfds[1] = socket((IPv6)? PF_INET6: PF_INET, SOCK_DGRAM, 0);
if(sfds[1] < 0){
- log_printf(LOG_ERR, "Socket creation failed");
+ logt_print(LOG_ERR, "Socket creation failed");
exit(EXIT_FAILURE);
} else {
int trueint = 1;
if(setsockopt(sfds[1], SOL_SOCKET, SO_REUSEADDR, &trueint, sizeof(int))){
- log_printf(LOG_ERR, "Unable to set socket option");
+ logt_print(LOG_ERR, "Unable to set socket option");
exit(EXIT_FAILURE);
}
}
@@ -168,14 +151,14 @@ int main(int argc, char *argv[]){
}
if(bind(sfds[1], (struct sockaddr *)&addr, addr_size) < 0){
- log_printf(LOG_ERR, "Unable to bind socket");
+ logt_print(LOG_ERR, "Unable to bind socket");
close(sfds[1]);
return -errno;
}
if(IPv6 || multicast_address){
if(join_group(sfds[1], 1, backend_port)){
- log_printf(LOG_ERR, "Unable to join multicast group.\n");
+ logt_print(LOG_ERR, "Unable to join multicast group.\n");
exit(EXIT_FAILURE);
}
}
@@ -189,7 +172,7 @@ int main(int argc, char *argv[]){
if (sfds[2] >= 0)
FD_SET(sfds[2], &rset);
- log_printf(LOG_DEBUG, "Sending SIGTERM to parent\n");
+ logt_print(LOG_DEBUG, "Sending SIGTERM to parent\n");
kill(getppid(), SIGTERM);
while(1){
@@ -201,7 +184,7 @@ int main(int argc, char *argv[]){
if((select(FD_SETSIZE, &tmp_set, NULL,NULL,NULL) < 0)){
if(errno != EINTR){
- log_printf(LOG_ERR, "Select failed");
+ logt_print(LOG_ERR, "Select failed");
}
continue;
}
@@ -212,49 +195,48 @@ int main(int argc, char *argv[]){
}
if(i == 0){
uint16_t port;
- log_printf(LOG_DEBUG, "NORMAL CCS REQUEST.\n");
+ logt_print(LOG_DEBUG, "NORMAL CCS REQUEST.\n");
afd = accept(sfds[i], (struct sockaddr *)&addr, &len);
if(afd < 0){
- log_printf(LOG_ERR, "Unable to accept connection");
+ logt_print(LOG_ERR, "Unable to accept connection");
continue;
}
port = (IPv6) ? addr6->sin6_port : addr4->sin_port;
- log_printf(LOG_DEBUG, "Connection requested from port %u.\n", ntohs(port));
+ logt_print(LOG_DEBUG, "Connection requested from port %u.\n", ntohs(port));
if(ntohs(port) > 1024){
- log_printf(LOG_ERR, "Refusing connection from port > 1024: port = %d", ntohs(port));
+ logt_print(LOG_ERR, "Refusing connection from port > 1024: port = %d", ntohs(port));
close(afd);
continue;
}
if((error = process_request(afd))){
- log_printf(LOG_ERR, "Error while processing request: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing request: %s\n", strerror(-error));
}
close(afd);
} else if (i == 2) {
- log_printf(LOG_DEBUG, "NORMAL CCS REQUEST.\n");
+ logt_print(LOG_DEBUG, "NORMAL CCS REQUEST.\n");
afd = accept(sfds[i], NULL, NULL);
if(afd < 0){
- log_printf(LOG_ERR, "Unable to accept connection");
+ logt_print(LOG_ERR, "Unable to accept connection");
continue;
}
- log_printf(LOG_DEBUG, "Connection requested from local socket\n");
+ logt_print(LOG_DEBUG, "Connection requested from local socket\n");
if((error = process_request(afd))){
- log_printf(LOG_ERR, "Error while processing request: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing request: %s\n", strerror(-error));
}
close(afd);
} else {
- log_printf(LOG_DEBUG, "BROADCAST REQUEST.\n");
+ logt_print(LOG_DEBUG, "BROADCAST REQUEST.\n");
if((error = process_broadcast(sfds[i]))){
- log_printf(LOG_ERR, "Error while processing broadcast: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing broadcast: %s\n", strerror(-error));
}
}
}
}
- logsys_exit();
exit(EXIT_SUCCESS);
}
@@ -315,8 +297,7 @@ static int is_multicast_addr(char *addr_string){
* @argc:
* @argv:
*
- * This function parses the command line arguments and sets the
- * appropriate flags in the global 'flags' variable. Additionally,
+ * This function parses the command line arguments. Additionally,
* it sets the global 'config_file_location'. This function
* will either succeed or cause the program to exit.
*
@@ -421,7 +402,7 @@ static char *parse_cli_args(int argc, char *argv[]){
" Multicast (%s):: SET\n", optarg);
break;
case 'n':
- flags |= FLAG_NODAEMON;
+ nodaemon = 1;
buff_index += snprintf(buff+buff_index, buff_size-buff_index,
" No Daemon:: SET\n");
break;
@@ -530,23 +511,25 @@ static int check_cluster_conf(void){
if(!stat(config_file_location, &stat_buf)){
doc = xmlParseFile(config_file_location);
if(!doc){
- log_printf(LOG_ERR, "\nUnable to parse %s.\n"
+ fprintf(stderr, "\nUnable to parse %s.\n"
"You should either:\n"
" 1. Correct the XML mistakes, or\n"
" 2. (Re)move the file and attempt to grab a "
"valid copy from the network.\n", config_file_location);
return -1;
}
- set_ccs_logging(doc);
- xmlFreeDoc(doc);
} else {
/* no cluster.conf file. This is fine, just need to get it from the network */
if(no_manager_opt){
- log_printf(LOG_ERR, "\nNo local config file found: %s\n", config_file_location);
+ fprintf(stderr, "\nNo local config file found: %s\n", config_file_location);
return -1;
}
}
+ set_ccs_logging(doc, 0);
+ if(doc)
+ xmlFreeDoc(doc);
+
CCSEXIT("check_cluster_conf");
return 0;
}
@@ -569,12 +552,12 @@ static int create_lockfile(char *lockfile){
if(!strncmp(lockfile, "/var/run/cluster/", 17)){
if(stat("/var/run/cluster", &stat_buf)){
if(mkdir("/var/run/cluster", S_IRWXU)){
- log_printf(LOG_ERR, "Cannot create lockfile directory");
+ logt_print(LOG_ERR, "Cannot create lockfile directory");
error = -errno;
goto fail;
}
} else if(!S_ISDIR(stat_buf.st_mode)){
- log_printf(LOG_ERR, "/var/run/cluster is not a directory.\n"
+ logt_print(LOG_ERR, "/var/run/cluster is not a directory.\n"
"Cannot create lockfile.\n");
error = -ENOTDIR;
goto fail;
@@ -583,7 +566,7 @@ static int create_lockfile(char *lockfile){
if((fd = open(lockfile, O_CREAT | O_WRONLY,
(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0){
- log_printf(LOG_ERR, "Cannot create lockfile");
+ logt_print(LOG_ERR, "Cannot create lockfile");
error = -errno;
goto fail;
}
@@ -595,7 +578,7 @@ static int create_lockfile(char *lockfile){
if (fcntl(fd, F_SETLK, &lock) < 0) {
close(fd);
- log_printf(LOG_ERR, "The ccsd process is already running.\n");
+ logt_print(LOG_ERR, "The ccsd process is already running.\n");
error = -errno;
goto fail;
}
@@ -657,24 +640,24 @@ static void process_signal(int sig){
switch(sig) {
case SIGINT:
- log_printf(LOG_INFO, "Stopping ccsd, SIGINT received.\n");
+ logt_print(LOG_INFO, "Stopping ccsd, SIGINT received.\n");
err = EXIT_SUCCESS;
break;
case SIGQUIT:
- log_printf(LOG_INFO, "Stopping ccsd, SIGQUIT received.\n");
+ logt_print(LOG_INFO, "Stopping ccsd, SIGQUIT received.\n");
err = EXIT_SUCCESS;
break;
case SIGTERM:
- log_printf(LOG_INFO, "Stopping ccsd, SIGTERM received.\n");
+ logt_print(LOG_INFO, "Stopping ccsd, SIGTERM received.\n");
err = EXIT_SUCCESS;
break;
case SIGHUP:
- log_printf(LOG_INFO, "SIGHUP received.\n");
- log_printf(LOG_INFO, "Use ccs_tool for updates.\n");
+ logt_print(LOG_INFO, "SIGHUP received.\n");
+ logt_print(LOG_INFO, "Use ccs_tool for updates.\n");
return;
break;
default:
- log_printf(LOG_ERR, "Stopping ccsd, unknown signal %d received.\n", sig);
+ logt_print(LOG_ERR, "Stopping ccsd, unknown signal %d received.\n", sig);
err = EXIT_FAILURE;
}
@@ -717,20 +700,20 @@ static void daemonize(void){
CCSENTER("daemonize");
- if(flags & FLAG_NODAEMON){
- log_printf(LOG_DEBUG, "Entering non-daemon mode.\n");
+ if(nodaemon){
+ logt_print(LOG_DEBUG, "Entering non-daemon mode.\n");
if((error = create_lockfile(lockfile_location))){
goto fail;
}
} else {
- log_printf(LOG_DEBUG, "Entering daemon mode.\n");
+ logt_print(LOG_DEBUG, "Entering daemon mode.\n");
signal(SIGTERM, &parent_exit_handler);
pid = fork();
if(pid < 0){
- log_printf(LOG_ERR, "Unable to fork().\n");
+ logt_print(LOG_ERR, "Unable to fork().\n");
error = pid;
goto fail;
}
@@ -744,11 +727,11 @@ static void daemonize(void){
switch(WEXITSTATUS(status)){
case EXIT_CLUSTER_FAIL:
- log_printf(LOG_ERR, "Failed to connect to cluster manager.\n");
+ logt_print(LOG_ERR, "Failed to connect to cluster manager.\n");
break;
case EXIT_LOCKFILE:
- log_printf(LOG_ERR, "Failed to create lockfile.\n");
- log_printf(LOG_ERR, "Hint: ccsd is already running.\n");
+ logt_print(LOG_ERR, "Failed to create lockfile.\n");
+ logt_print(LOG_ERR, "Hint: ccsd is already running.\n");
break;
}
exit(EXIT_FAILURE);
@@ -769,7 +752,7 @@ static void daemonize(void){
}
/* Make the parent stop waiting */
- //log_printf(LOG_DEBUG, "Die early\n");
+ //logt_print(LOG_DEBUG, "Die early\n");
//kill(getppid(), SIGTERM);
}
@@ -797,11 +780,11 @@ static void daemonize(void){
static void print_start_msg(char *msg){
CCSENTER("print_start_msg");
/* We want the start message to print every time */
- log_printf(LOG_INFO, "Starting ccsd %s:\n", RELEASE_VERSION);
- log_printf(LOG_INFO, " Built: "__DATE__" "__TIME__"\n");
- log_printf(LOG_INFO, " %s\n", REDHAT_COPYRIGHT);
+ logt_print(LOG_INFO, "Starting ccsd %s:\n", RELEASE_VERSION);
+ logt_print(LOG_INFO, " Built: "__DATE__" "__TIME__"\n");
+ logt_print(LOG_INFO, " %s\n", REDHAT_COPYRIGHT);
if(msg){
- log_printf(LOG_INFO, "%s\n", msg);
+ logt_print(LOG_INFO, "%s\n", msg);
}
CCSEXIT("print_start_msg");
}
@@ -844,13 +827,13 @@ static int join_group(int sfd, int loopback, int port){
if(setsockopt(sfd, IPPROTO_IP, IP_MULTICAST_LOOP,
&loopback, sizeof(loopback)) < 0){
- log_printf(LOG_ERR, "Unable to %s loopback.\n", loopback?"SET":"UNSET");
+ logt_print(LOG_ERR, "Unable to %s loopback.\n", loopback?"SET":"UNSET");
error = -errno;
goto fail;
}
if(setsockopt(sfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(const void *)&mreq, sizeof(mreq)) < 0){
- log_printf(LOG_ERR, "Unable to add to membership.\n");
+ logt_print(LOG_ERR, "Unable to add to membership.\n");
error = -errno;
goto fail;
}
@@ -863,18 +846,18 @@ static int join_group(int sfd, int loopback, int port){
if(setsockopt(sfd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
&loopback, sizeof(loopback)) < 0){
- log_printf(LOG_ERR, "Unable to %s loopback.\n", loopback?"SET":"UNSET");
+ logt_print(LOG_ERR, "Unable to %s loopback.\n", loopback?"SET":"UNSET");
error = -errno;
goto fail;
}
if(setsockopt(sfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
(const void *)&mreq, sizeof(mreq)) < 0){
- log_printf(LOG_ERR, "Unable to add to membership: %s\n", strerror(errno));
+ logt_print(LOG_ERR, "Unable to add to membership: %s\n", strerror(errno));
error = -errno;
goto fail;
}
} else {
- log_printf(LOG_ERR, "Unknown address family.\n");
+ logt_print(LOG_ERR, "Unknown address family.\n");
error = -EINVAL;
}
fail:
@@ -911,7 +894,7 @@ int setup_local_socket(int backlog)
if (listen(sock, backlog) < 0)
goto fail;
- log_printf(LOG_DEBUG, "Set up local socket on %s\n", su.sun_path);
+ logt_print(LOG_DEBUG, "Set up local socket on %s\n", su.sun_path);
CCSEXIT("setup_local_socket");
return sock;
fail:
diff --git a/config/daemons/ccsd/cluster_mgr.c b/config/daemons/ccsd/cluster_mgr.c
index 236933f..bdfcd59 100644
--- a/config/daemons/ccsd/cluster_mgr.c
+++ b/config/daemons/ccsd/cluster_mgr.c
@@ -11,7 +11,7 @@
#include <sys/ioctl.h>
#include <errno.h>
#include <libxml/parser.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include "comm_headers.h"
#include "debug.h"
@@ -47,29 +47,29 @@ static int check_update_doc(xmlDocPtr tmp_doc)
CCSENTER("check_update_doc");
if (!(str1 = get_cluster_name(tmp_doc))) {
- log_printf(LOG_ERR, "Unable to get cluster name from new config file.\n");
+ logt_print(LOG_ERR, "Unable to get cluster name from new config file.\n");
error = -EINVAL;
goto fail;
}
if (master_doc && master_doc->od_doc &&
!(str2 = get_cluster_name(master_doc->od_doc))) {
- log_printf(LOG_DEBUG, "Unable to get cluster name from current master doc.\n");
+ logt_print(LOG_DEBUG, "Unable to get cluster name from current master doc.\n");
}
if (str2 && strcmp(str1, str2)) {
- log_printf(LOG_ERR, "Cluster names for current and update configs do not match.\n");
- log_printf(LOG_ERR, " Current cluster name:: <%s>\n", str2);
- log_printf(LOG_ERR, " Proposed update name:: <%s>\n", str1);
+ logt_print(LOG_ERR, "Cluster names for current and update configs do not match.\n");
+ logt_print(LOG_ERR, " Current cluster name:: <%s>\n", str2);
+ logt_print(LOG_ERR, " Proposed update name:: <%s>\n", str1);
error = -EINVAL;
goto fail;
}
if (master_doc && master_doc->od_doc &&
(get_doc_version(tmp_doc) <= get_doc_version(master_doc->od_doc))) {
- log_printf(LOG_ERR, "Proposed updated config file does not have greater version number.\n");
- log_printf(LOG_ERR, " Current config_version :: %d\n", get_doc_version(master_doc->od_doc));
- log_printf(LOG_ERR, " Proposed config_version:: %d\n", get_doc_version(tmp_doc));
+ logt_print(LOG_ERR, "Proposed updated config file does not have greater version number.\n");
+ logt_print(LOG_ERR, " Current config_version :: %d\n", get_doc_version(master_doc->od_doc));
+ logt_print(LOG_ERR, " Proposed config_version:: %d\n", get_doc_version(tmp_doc));
error = -EINVAL;
}
@@ -107,37 +107,37 @@ static int handle_cluster_message(int fd)
CCSENTER("handle_cluster_message");
- log_printf(LOG_DEBUG, "Cluster message on socket: %d\n", fd);
+ logt_print(LOG_DEBUG, "Cluster message on socket: %d\n", fd);
client_len = sizeof(client_addr);
if ((socket = accept(fd, &client_addr, &client_len)) < 0) {
- log_printf(LOG_ERR, "Failed to accept connection.\n");
+ logt_print(LOG_ERR, "Failed to accept connection.\n");
goto fail;
}
if ((nodeid = member_addr_to_id(members, &client_addr)) < 0) {
- log_printf(LOG_ERR, "Unable to determine node ID.\n");
+ logt_print(LOG_ERR, "Unable to determine node ID.\n");
goto fail;
}
- log_printf(LOG_DEBUG, "Accept socket: %d\n", socket);
+ logt_print(LOG_DEBUG, "Accept socket: %d\n", socket);
error = recv(socket, &ch, sizeof(comm_header_t), MSG_PEEK);
if (error < 0) {
- log_printf(LOG_ERR, "Failed to receive message from %s\n",
+ logt_print(LOG_ERR, "Failed to receive message from %s\n",
member_id_to_name(members, nodeid));
goto fail;
}
- log_printf(LOG_DEBUG, "Message (%d bytes) received from %s\n",
+ logt_print(LOG_DEBUG, "Message (%d bytes) received from %s\n",
error, member_id_to_name(members, nodeid));
swab_header(&ch);
if (ch.comm_type != COMM_UPDATE) {
- log_printf(LOG_ERR, "Unexpected communication type (%d)... ignoring.\n",
+ logt_print(LOG_ERR, "Unexpected communication type (%d)... ignoring.\n",
ch.comm_type);
error = -EINVAL;
goto fail;
@@ -146,12 +146,12 @@ static int handle_cluster_message(int fd)
if (ch.comm_flags == COMM_UPDATE_NOTICE) {
buffer = malloc(ch.comm_payload_size + sizeof(comm_header_t));
if (!buffer) {
- log_printf(LOG_ERR, "Unable to allocate space to perform update.\n");
+ logt_print(LOG_ERR, "Unable to allocate space to perform update.\n");
error = -ENOMEM;
goto fail;
}
- log_printf(LOG_DEBUG, "Updated config size:: %d\n", ch.comm_payload_size);
+ logt_print(LOG_DEBUG, "Updated config size:: %d\n", ch.comm_payload_size);
tv.tv_sec = 5;
tv.tv_usec = 0;
@@ -159,19 +159,19 @@ static int handle_cluster_message(int fd)
error = read_retry(socket, buffer, ch.comm_payload_size + sizeof(comm_header_t), &tv);
if (error < 0) {
- log_printf(LOG_ERR, "Unable to retrieve updated config");
+ logt_print(LOG_ERR, "Unable to retrieve updated config");
goto fail;
}
pthread_mutex_lock(&update_lock);
unlock = 1;
- log_printf(LOG_DEBUG, "Got lock 0\n");
+ logt_print(LOG_DEBUG, "Got lock 0\n");
tmp_doc = xmlParseMemory(buffer+sizeof(comm_header_t), ch.comm_payload_size);
if (!tmp_doc) {
- log_printf(LOG_ERR, "Unable to parse updated config file.\n");
+ logt_print(LOG_ERR, "Unable to parse updated config file.\n");
/* ATTENTION -- need better error code */
error = -EIO;
goto fail;
@@ -188,28 +188,28 @@ static int handle_cluster_message(int fd)
umask(old_mode);
if (!fp) {
- log_printf(LOG_ERR, "Unable to open " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "-update");
+ logt_print(LOG_ERR, "Unable to open " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "-update");
error = -errno;
goto fail;
}
if (xmlDocDump(fp, tmp_doc) < 0) {
- log_printf(LOG_ERR, "Unable to write " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "-update");
+ logt_print(LOG_ERR, "Unable to write " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "-update");
goto fail;
}
- log_printf(LOG_DEBUG, "Upload of new config file from %s complete.\n",
+ logt_print(LOG_DEBUG, "Upload of new config file from %s complete.\n",
member_id_to_name(members, nodeid));
ch.comm_payload_size = 0;
ch.comm_flags = COMM_UPDATE_NOTICE_ACK;
- log_printf(LOG_DEBUG, "Sending COMM_UPDATE_NOTICE_ACK.\n");
+ logt_print(LOG_DEBUG, "Sending COMM_UPDATE_NOTICE_ACK.\n");
swab_header(&ch);
if ((error = write(socket, &ch, sizeof(comm_header_t))) < 0) {
- log_printf(LOG_ERR, "Unable to send COMM_UPDATE_NOTICE_ACK.\n");
+ logt_print(LOG_ERR, "Unable to send COMM_UPDATE_NOTICE_ACK.\n");
goto fail;
}
@@ -225,8 +225,8 @@ static int handle_cluster_message(int fd)
error = read_retry(socket, &ch, sizeof(comm_header_t), &tv);
if (master_node != nodeid) {
- log_printf(LOG_ERR, "COMM_UPDATE_COMMIT received from node other than initiator.\n");
- log_printf(LOG_ERR, "Hint: There may be multiple updates happening at once.\n");
+ logt_print(LOG_ERR, "COMM_UPDATE_COMMIT received from node other than initiator.\n");
+ logt_print(LOG_ERR, "Hint: There may be multiple updates happening at once.\n");
error = -EPERM;
goto fail;
}
@@ -235,12 +235,12 @@ static int handle_cluster_message(int fd)
unlock = 1;
- log_printf(LOG_DEBUG, "Got lock 1\n");
+ logt_print(LOG_DEBUG, "Got lock 1\n");
tmp_doc = xmlParseFile(DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "-update");
if (!tmp_doc) {
- log_printf(LOG_ERR, "Unable to parse updated config file.\n");
+ logt_print(LOG_ERR, "Unable to parse updated config file.\n");
/* ATTENTION -- need better error code */
error = -EIO;
goto fail;
@@ -257,13 +257,13 @@ static int handle_cluster_message(int fd)
umask(old_mode);
if (!fp) {
- log_printf(LOG_ERR, "Unable to open " DEFAULT_CONFIG_DIR "/." DEFAULT_CONFIG_FILE);
+ logt_print(LOG_ERR, "Unable to open " DEFAULT_CONFIG_DIR "/." DEFAULT_CONFIG_FILE);
error = -errno;
goto fail;
}
if (xmlDocDump(fp, tmp_doc) < 0) {
- log_printf(LOG_ERR, "Unable to write " DEFAULT_CONFIG_DIR "/." DEFAULT_CONFIG_FILE);
+ logt_print(LOG_ERR, "Unable to write " DEFAULT_CONFIG_DIR "/." DEFAULT_CONFIG_FILE);
goto fail;
}
@@ -272,12 +272,12 @@ static int handle_cluster_message(int fd)
update_required = 1;
ch.comm_flags = COMM_UPDATE_COMMIT_ACK;
- log_printf(LOG_DEBUG, "Sending COMM_UPDATE_COMMIT_ACK.\n");
+ logt_print(LOG_DEBUG, "Sending COMM_UPDATE_COMMIT_ACK.\n");
swab_header(&ch);
if ((error = write(socket, &ch, sizeof(comm_header_t))) < 0) {
- log_printf(LOG_ERR, "Unable to send COMM_UPDATE_NOTICE_ACK.\n");
+ logt_print(LOG_ERR, "Unable to send COMM_UPDATE_NOTICE_ACK.\n");
goto fail;
}
@@ -355,7 +355,7 @@ static void cluster_communicator(void)
int opt = 1;
int max_fd;
int n;
- int flags;
+ int cc_flags;
fd_set rset;
cman_handle_t handle = NULL;
@@ -372,7 +372,7 @@ static void cluster_communicator(void)
if (IPv6) {
if ((ccsd_fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
if(IPv6 == -1) {
- log_printf(LOG_DEBUG, "Unable to create IPv6 socket:: %s\n", strerror(errno));
+ logt_print(LOG_DEBUG, "Unable to create IPv6 socket:: %s\n", strerror(errno));
IPv6=0;
}
}
@@ -380,13 +380,13 @@ static void cluster_communicator(void)
if (!IPv6) {
if ((ccsd_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- log_printf(LOG_ERR, "Unable to create IPv4 socket.\n");
+ logt_print(LOG_ERR, "Unable to create IPv4 socket.\n");
exit(EXIT_FAILURE);
}
}
if (setsockopt(ccsd_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, sizeof(opt)) < 0) {
- log_printf(LOG_ERR, "Unable to set socket option");
+ logt_print(LOG_ERR, "Unable to set socket option");
exit(EXIT_FAILURE);
}
@@ -402,18 +402,18 @@ static void cluster_communicator(void)
addr4->sin_port = htons(cluster_base_port);
}
- flags = fcntl(ccsd_fd, F_GETFD, 0);
- flags |= FD_CLOEXEC;
- fcntl(ccsd_fd, F_SETFD, flags);
+ cc_flags = fcntl(ccsd_fd, F_GETFD, 0);
+ cc_flags |= FD_CLOEXEC;
+ fcntl(ccsd_fd, F_SETFD, cc_flags);
if (bind(ccsd_fd, (struct sockaddr *)&addr, addr_size) < 0) {
- log_printf(LOG_ERR, "Unable to bind to socket.\n");
+ logt_print(LOG_ERR, "Unable to bind to socket.\n");
close(ccsd_fd);
exit(EXIT_FAILURE);
}
if (listen(ccsd_fd, 15) < 0) {
- log_printf(LOG_ERR, "Unable to listen to socket.\n");
+ logt_print(LOG_ERR, "Unable to listen to socket.\n");
close(ccsd_fd);
exit(EXIT_FAILURE);
}
@@ -430,7 +430,7 @@ restart:
if (!(warn_user % 30))
{
- log_printf(LOG_ERR, "Unable to connect to cluster infrastructure after %d seconds.\n",
+ logt_print(LOG_ERR, "Unable to connect to cluster infrastructure after %d seconds.\n",
warn_user);
}
@@ -447,7 +447,7 @@ restart:
quorate = cman_is_quorate(handle);
- log_printf(LOG_INFO, "Initial status:: %s\n", (quorate)? "Quorate" : "Inquorate");
+ logt_print(LOG_INFO, "Initial status:: %s\n", (quorate)? "Quorate" : "Inquorate");
members = get_member_list(handle);
@@ -461,18 +461,18 @@ restart:
max_fd = (ccsd_fd > cman_fd) ? ccsd_fd : cman_fd;
- log_printf(LOG_DEBUG, "Waiting for cluster event.\n");
+ logt_print(LOG_DEBUG, "Waiting for cluster event.\n");
if ((n = select((max_fd + 1), &rset, NULL, NULL, NULL)) < 0) {
- log_printf(LOG_ERR, "Select failed");
+ logt_print(LOG_ERR, "Select failed");
continue;
}
- log_printf(LOG_DEBUG, "There are %d cluster messages waiting.\n", n);
+ logt_print(LOG_DEBUG, "There are %d cluster messages waiting.\n", n);
while (n)
{
- log_printf(LOG_DEBUG, "There are %d messages remaining.\n", n);
+ logt_print(LOG_DEBUG, "There are %d messages remaining.\n", n);
n--;
@@ -505,7 +505,7 @@ int start_cluster_monitor_thread(void) {
error = pthread_create(&thread, NULL, (void *)cluster_communicator, NULL);
if (error) {
- log_printf(LOG_ERR, "Failed to create thread: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Failed to create thread: %s\n", strerror(-error));
goto fail;
}
diff --git a/config/daemons/ccsd/cnx_mgr.c b/config/daemons/ccsd/cnx_mgr.c
index fddd834..edd5724 100644
--- a/config/daemons/ccsd/cnx_mgr.c
+++ b/config/daemons/ccsd/cnx_mgr.c
@@ -17,7 +17,7 @@
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
-#include <corosync/engine/logsys.h>
+#include <liblogthread.h>
#include "comm_headers.h"
#include "debug.h"
@@ -69,19 +69,19 @@ static int _update_config(char *location){
tmp_doc = xmlParseFile(location);
if(!tmp_doc){
- log_printf(LOG_ERR, "Unable to parse %s\n", location);
+ logt_print(LOG_ERR, "Unable to parse %s\n", location);
error = -EINVAL;
goto fail;
} else if((v2 = get_doc_version(tmp_doc)) < 0){
- log_printf(LOG_ERR, "Unable to get config_version from %s.\n", location);
+ logt_print(LOG_ERR, "Unable to get config_version from %s.\n", location);
error = v2;
goto fail;
} else if(master_doc && master_doc->od_doc){
v1 = get_doc_version(master_doc->od_doc);
if(v1 >= v2){
- log_printf(LOG_ERR, "%s on-disk version is <= to in-memory version.\n", location);
- log_printf(LOG_ERR, " On-disk version : %d\n", v2);
- log_printf(LOG_ERR, " In-memory version : %d\n", v1);
+ logt_print(LOG_ERR, "%s on-disk version is <= to in-memory version.\n", location);
+ logt_print(LOG_ERR, " On-disk version : %d\n", v2);
+ logt_print(LOG_ERR, " In-memory version : %d\n", v1);
error = -EPERM;
goto fail;
}
@@ -97,10 +97,10 @@ static int _update_config(char *location){
tmp_odoc->od_doc = tmp_doc;
- log_printf(LOG_DEBUG, "There are %d references open on version %d of the config file.\n",
+ logt_print(LOG_DEBUG, "There are %d references open on version %d of the config file.\n",
(master_doc)?master_doc->od_refs:0, v1);
if(master_doc && !master_doc->od_refs){
- log_printf(LOG_DEBUG, "Freeing version %d\n", v1);
+ logt_print(LOG_DEBUG, "Freeing version %d\n", v1);
xmlFreeDoc(master_doc->od_doc);
free(master_doc);
master_doc = tmp_odoc;
@@ -108,7 +108,7 @@ static int _update_config(char *location){
master_doc = tmp_odoc;
}
- log_printf(LOG_INFO, "Update of "DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE " complete (version %d -> %d).\n", v1, v2);
+ logt_print(LOG_INFO, "Update of "DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE " complete (version %d -> %d).\n", v1, v2);
fail:
if(tmp_odoc != master_doc){
free(tmp_odoc);
@@ -133,7 +133,7 @@ static int update_config(void){
error = _update_config(DEFAULT_CONFIG_DIR "/." DEFAULT_CONFIG_FILE);
update_required = 0;
if(error){
- log_printf(LOG_ERR, "Previous update could not be completed.\n");
+ logt_print(LOG_ERR, "Previous update could not be completed.\n");
goto fail;
}
}
@@ -172,13 +172,13 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
try_again:
if(!master_doc){
- log_printf(LOG_ERR, "No master_doc!!!\n");
+ logt_print(LOG_ERR, "No master_doc!!!\n");
exit(EXIT_FAILURE);
}
if(quorate && !cluster_name){
- log_printf(LOG_ERR, "Node is part of quorate cluster, but the cluster name is unknown.\n");
- log_printf(LOG_ERR, " Unable to validate remote config files. Refusing connection.\n");
+ logt_print(LOG_ERR, "Node is part of quorate cluster, but the cluster name is unknown.\n");
+ logt_print(LOG_ERR, " Unable to validate remote config files. Refusing connection.\n");
error = -ECONNREFUSED;
goto fail;
}
@@ -191,13 +191,13 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
memset(ch, 0, sizeof(comm_header_t));
if(IPv6 && (sfd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) <0){
- log_printf(LOG_ERR, "Unable to create IPv6 socket");
+ logt_print(LOG_ERR, "Unable to create IPv6 socket");
error = -errno;
goto fail;
}
if(!IPv6 && ((sfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)){
- log_printf(LOG_ERR, "Unable to create socket for broadcast");
+ logt_print(LOG_ERR, "Unable to create socket for broadcast");
error = -errno;
goto fail;
}
@@ -212,16 +212,16 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
addr6->sin6_port = htons(backend_port);
if(!multicast_address || !strcmp(multicast_address, "default")){
- log_printf(LOG_DEBUG, "Trying IPv6 multicast (default).\n");
+ logt_print(LOG_DEBUG, "Trying IPv6 multicast (default).\n");
if(inet_pton(AF_INET6, "ff02::3:1", &(addr6->sin6_addr)) <= 0){
- log_printf(LOG_ERR, "Unable to convert multicast address");
+ logt_print(LOG_ERR, "Unable to convert multicast address");
error = -errno;
goto fail;
}
} else {
- log_printf(LOG_DEBUG, "Trying IPv6 multicast (%s).\n", multicast_address);
+ logt_print(LOG_DEBUG, "Trying IPv6 multicast (%s).\n", multicast_address);
if(inet_pton(AF_INET6, multicast_address, &(addr6->sin6_addr)) <= 0){
- log_printf(LOG_ERR, "Unable to convert multicast address");
+ logt_print(LOG_ERR, "Unable to convert multicast address");
error = -errno;
goto fail;
}
@@ -233,7 +233,7 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
if(setsockopt(sfd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
&opt, sizeof(opt)) < 0){
- log_printf(LOG_ERR, "Unable to %s loopback.\n", opt?"SET":"UNSET");
+ logt_print(LOG_ERR, "Unable to %s loopback.\n", opt?"SET":"UNSET");
error = -errno;
goto fail;
}
@@ -241,28 +241,28 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
addr4->sin_family = AF_INET;
addr4->sin_port = htons(backend_port);
if(!multicast_address){
- log_printf(LOG_DEBUG, "Trying IPv4 broadcast.\n");
+ logt_print(LOG_DEBUG, "Trying IPv4 broadcast.\n");
addr4->sin_addr.s_addr = INADDR_BROADCAST;
if((error = setsockopt(sfd, SOL_SOCKET, SO_BROADCAST, &trueint, sizeof(int)))){
- log_printf(LOG_ERR, "Unable to set socket options");
+ logt_print(LOG_ERR, "Unable to set socket options");
error = -errno;
goto fail;
} else {
- log_printf(LOG_DEBUG, " Broadcast enabled.\n");
+ logt_print(LOG_DEBUG, " Broadcast enabled.\n");
}
} else {
if(!strcmp(multicast_address, "default")){
- log_printf(LOG_DEBUG, "Trying IPv4 multicast (default).\n");
+ logt_print(LOG_DEBUG, "Trying IPv4 multicast (default).\n");
if(inet_pton(AF_INET, "224.0.2.5", &(addr4->sin_addr)) <= 0){
- log_printf(LOG_ERR, "Unable to convert multicast address");
+ logt_print(LOG_ERR, "Unable to convert multicast address");
error = -errno;
goto fail;
}
} else {
- log_printf(LOG_DEBUG, "Trying IPv4 multicast (%s).\n", multicast_address);
+ logt_print(LOG_DEBUG, "Trying IPv4 multicast (%s).\n", multicast_address);
if(inet_pton(AF_INET, multicast_address, &(addr4->sin_addr)) <= 0){
- log_printf(LOG_ERR, "Unable to convert multicast address");
+ logt_print(LOG_ERR, "Unable to convert multicast address");
error = -errno;
goto fail;
}
@@ -270,7 +270,7 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
opt = 0;
setsockopt(sfd, IPPROTO_IP, IP_MULTICAST_LOOP, &opt, sizeof(opt));
if(setsockopt(sfd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0){
- log_printf(LOG_ERR, "Unable to set multicast threshold.\n");
+ logt_print(LOG_ERR, "Unable to set multicast threshold.\n");
}
}
}
@@ -281,12 +281,12 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
do {
ch->comm_type = COMM_BROADCAST;
- log_printf(LOG_DEBUG, "Sending broadcast.\n");
+ logt_print(LOG_DEBUG, "Sending broadcast.\n");
swab_header(ch);
if(sendto(sfd, (char *)ch, sizeof(comm_header_t), 0,
(struct sockaddr *)&addr, addr_size) < 0){
- log_printf(LOG_ERR, "Unable to perform sendto");
+ logt_print(LOG_ERR, "Unable to perform sendto");
if(retry > 0){
retry--;
close(sfd);
@@ -305,19 +305,19 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
tv.tv_usec = 250000 + (random()%500000);
#if defined(__sparc__)
- log_printf(LOG_DEBUG, "Select waiting %d usec\n", tv.tv_usec);
+ logt_print(LOG_DEBUG, "Select waiting %d usec\n", tv.tv_usec);
#else
- log_printf(LOG_DEBUG, "Select waiting %ld usec\n", tv.tv_usec);
+ logt_print(LOG_DEBUG, "Select waiting %ld usec\n", tv.tv_usec);
#endif
while((error = select(sfd+1, &rset, NULL,NULL, &tv))){
- log_printf(LOG_DEBUG, "Select returns %d\n", error);
+ logt_print(LOG_DEBUG, "Select returns %d\n", error);
if(error < 0){
- log_printf(LOG_ERR, "Select failed");
+ logt_print(LOG_ERR, "Select failed");
error = -errno;
goto fail;
}
if(error){
- log_printf(LOG_DEBUG, "Checking broadcast response.\n");
+ logt_print(LOG_DEBUG, "Checking broadcast response.\n");
error = 0;
recvfrom(sfd, (char *)ch, sizeof(comm_header_t), MSG_PEEK,
(struct sockaddr *)&recv_addr, (socklen_t *)&len);
@@ -342,22 +342,22 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
tmp_doc = xmlParseMemory(bdoc+sizeof(comm_header_t),
ch->comm_payload_size);
if(!tmp_doc){
- log_printf(LOG_ERR, "Unable to parse remote configuration.\n");
+ logt_print(LOG_ERR, "Unable to parse remote configuration.\n");
free(bdoc); bdoc = NULL;
goto reset_timer;
}
tmp_name = get_cluster_name(tmp_doc);
- log_printf(LOG_DEBUG, " Given cluster name = %s\n", cluster_name);
- log_printf(LOG_DEBUG, " Remote cluster name= %s\n", tmp_name);
+ logt_print(LOG_DEBUG, " Given cluster name = %s\n", cluster_name);
+ logt_print(LOG_DEBUG, " Remote cluster name= %s\n", tmp_name);
if(!tmp_name){
- log_printf(LOG_ERR, "Unable to find cluster name in remote configuration.\n");
+ logt_print(LOG_ERR, "Unable to find cluster name in remote configuration.\n");
free(bdoc); bdoc = NULL;
xmlFreeDoc(tmp_doc); tmp_doc = NULL;
goto reset_timer;
} else if(cluster_name && strcmp(cluster_name, tmp_name)){
- log_printf(LOG_DEBUG, "Remote and local configuration have different cluster names.\n");
- log_printf(LOG_DEBUG, "Skipping...\n");
+ logt_print(LOG_DEBUG, "Remote and local configuration have different cluster names.\n");
+ logt_print(LOG_DEBUG, "Skipping...\n");
free(tmp_name); tmp_name = NULL;
free(bdoc); bdoc = NULL;
xmlFreeDoc(tmp_doc); tmp_doc = NULL;
@@ -366,7 +366,7 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
free(tmp_name); tmp_name = NULL;
if(!master_doc->od_doc){
if((v2 = get_doc_version(tmp_doc)) >= 0){
- log_printf(LOG_INFO, "Remote configuration copy (version = %d) found.\n", v2);
+ logt_print(LOG_INFO, "Remote configuration copy (version = %d) found.\n", v2);
master_doc->od_doc = tmp_doc;
tmp_doc = NULL;
write_to_disk = 1;
@@ -375,11 +375,11 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
if(((v1 = get_doc_version(master_doc->od_doc)) >= 0) &&
((v2 = get_doc_version(tmp_doc)) >= 0)){
if(ch->comm_flags & COMM_BROADCAST_FROM_QUORATE){
- log_printf(LOG_INFO, "Remote configuration copy is from quorate node.\n");
- log_printf(LOG_INFO, " Local version # : %d\n", v1);
- log_printf(LOG_INFO, " Remote version #: %d\n", v2);
+ logt_print(LOG_INFO, "Remote configuration copy is from quorate node.\n");
+ logt_print(LOG_INFO, " Local version # : %d\n", v1);
+ logt_print(LOG_INFO, " Remote version #: %d\n", v2);
if(v1 != v2){
- log_printf(LOG_INFO, "Switching to remote copy.\n");
+ logt_print(LOG_INFO, "Switching to remote copy.\n");
}
if(master_doc->od_refs){
open_doc_t *tmp_odoc;
@@ -398,9 +398,9 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
write_to_disk = 1;
goto out;
} else if(v2 > v1){
- log_printf(LOG_INFO, "Remote configuration copy is newer than local copy.\n");
- log_printf(LOG_INFO, " Local version # : %d\n", v1);
- log_printf(LOG_INFO, " Remote version #: %d\n", v2);
+ logt_print(LOG_INFO, "Remote configuration copy is newer than local copy.\n");
+ logt_print(LOG_INFO, " Local version # : %d\n", v1);
+ logt_print(LOG_INFO, " Remote version #: %d\n", v2);
if(master_doc->od_refs){
open_doc_t *tmp_odoc;
if(!(tmp_odoc = malloc(sizeof(open_doc_t)))){
@@ -430,9 +430,9 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
tv.tv_sec = 0;
tv.tv_usec = 250000 + (random()%500000);
#if defined(__sparc__)
- log_printf(LOG_DEBUG, "Select waiting %d usec\n", tv.tv_usec);
+ logt_print(LOG_DEBUG, "Select waiting %d usec\n", tv.tv_usec);
#else
- log_printf(LOG_DEBUG, "Select waiting %ld usec\n", tv.tv_usec);
+ logt_print(LOG_DEBUG, "Select waiting %ld usec\n", tv.tv_usec);
#endif
}
} while(blocking && !master_doc);
@@ -451,12 +451,12 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
** but it has not been written to disk....................................... */
if(stat(DEFAULT_CONFIG_DIR, &stat_buf)){
if(mkdir(DEFAULT_CONFIG_DIR, S_IRWXU | S_IRWXG)){
- log_printf(LOG_ERR, "Unable to create directory " DEFAULT_CONFIG_DIR);
+ logt_print(LOG_ERR, "Unable to create directory " DEFAULT_CONFIG_DIR);
error = -errno;
goto fail;
}
} else if(!S_ISDIR(stat_buf.st_mode)){
- log_printf(LOG_ERR, DEFAULT_CONFIG_DIR " is not a directory.\n");
+ logt_print(LOG_ERR, DEFAULT_CONFIG_DIR " is not a directory.\n");
error = -ENOTDIR;
goto fail;
}
@@ -465,7 +465,7 @@ static int broadcast_for_doc(char *cluster_name, int blocking){
f = fopen(DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE, "w");
umask(old_mode);
if(!f){
- log_printf(LOG_ERR, "Unable to open " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE);
+ logt_print(LOG_ERR, "Unable to open " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE);
error = -errno;
goto fail;
}
@@ -503,7 +503,7 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
ch->comm_payload_size = 0;
- log_printf(LOG_DEBUG, "Given cluster name is = %s\n", cluster_name);
+ logt_print(LOG_DEBUG, "Given cluster name is = %s\n", cluster_name);
if(!ocs){
/* this will never be freed - unless exit */
@@ -516,7 +516,7 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
}
if(!quorate && !(ch->comm_flags & COMM_CONNECT_FORCE)){
- log_printf(LOG_INFO, "Cluster is not quorate. Refusing connection.\n");
+ logt_print(LOG_INFO, "Cluster is not quorate. Refusing connection.\n");
error = -ECONNREFUSED;
goto fail;
}
@@ -535,28 +535,28 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
if(!master_doc->od_doc){
master_doc->od_doc = xmlParseFile(DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE);
if(!master_doc->od_doc){
- log_printf(LOG_INFO, "Unable to parse " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "\n");
- log_printf(LOG_INFO, "Searching cluster for valid copy.\n");
+ logt_print(LOG_INFO, "Unable to parse " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE "\n");
+ logt_print(LOG_INFO, "Searching cluster for valid copy.\n");
} else if((error = get_doc_version(master_doc->od_doc)) < 0){
- log_printf(LOG_ERR, "Unable to get config_version from " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
- log_printf(LOG_ERR, "Discarding data and searching for valid copy.\n");
+ logt_print(LOG_ERR, "Unable to get config_version from " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
+ logt_print(LOG_ERR, "Discarding data and searching for valid copy.\n");
xmlFreeDoc(master_doc->od_doc);
master_doc->od_doc = NULL;
} else if(!(tmp_name = get_cluster_name(master_doc->od_doc))){
- log_printf(LOG_ERR, "Unable to get cluster name from " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
- log_printf(LOG_ERR, "Discarding data and searching for valid copy.\n");
+ logt_print(LOG_ERR, "Unable to get cluster name from " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
+ logt_print(LOG_ERR, "Discarding data and searching for valid copy.\n");
xmlFreeDoc(master_doc->od_doc);
master_doc->od_doc = NULL;
} else if(cluster_name && strcmp(cluster_name, tmp_name)){
- log_printf(LOG_ERR, "Given cluster name does not match local " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
- log_printf(LOG_ERR, "Discarding data and searching for matching copy.\n");
+ logt_print(LOG_ERR, "Given cluster name does not match local " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
+ logt_print(LOG_ERR, "Discarding data and searching for matching copy.\n");
xmlFreeDoc(master_doc->od_doc);
master_doc->od_doc = NULL;
free(tmp_name); tmp_name = NULL;
- } else if(set_ccs_logging(master_doc->od_doc) < 0){
- log_printf(LOG_ERR, "Unable to set logging parameters.\n");
+ } else if(set_ccs_logging(master_doc->od_doc, 1) < 0){
+ logt_print(LOG_ERR, "Unable to set logging parameters.\n");
} else { /* Either the names match, or a name wasn't specified. */
- log_printf(LOG_INFO, DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE " (cluster name = %s, version = %d) found.\n",
+ logt_print(LOG_INFO, DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE " (cluster name = %s, version = %d) found.\n",
tmp_name, error);
/* We must check with the others to make sure this is valid. */
}
@@ -570,8 +570,8 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
** for the config of the name specified............................... */
if(cluster_name && strcmp(cluster_name, tmp_name)){
- log_printf(LOG_ERR, "Request for configuration with cluster name, %s\n", cluster_name);
- log_printf(LOG_ERR, " However, a configuration with cluster name, %s, is already loaded.\n",
+ logt_print(LOG_ERR, "Request for configuration with cluster name, %s\n", cluster_name);
+ logt_print(LOG_ERR, " However, a configuration with cluster name, %s, is already loaded.\n",
tmp_name);
error = -EINVAL;
goto fail;
@@ -589,32 +589,32 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
}
}
- log_printf(LOG_DEBUG, "Blocking is %s.\n",
+ logt_print(LOG_DEBUG, "Blocking is %s.\n",
(ch->comm_flags & COMM_CONNECT_BLOCKING)? "SET": "UNSET");
- log_printf(LOG_DEBUG, "Flags = 0x%x\n", ch->comm_flags);
+ logt_print(LOG_DEBUG, "Flags = 0x%x\n", ch->comm_flags);
/* Need to broadcast regardless (unless quorate) to check version # */
if(bcast_needed){
- log_printf(LOG_DEBUG, "Broadcast is neccessary.\n");
+ logt_print(LOG_DEBUG, "Broadcast is neccessary.\n");
}
if(bcast_needed &&
(error = broadcast_for_doc(tmp_name, ch->comm_flags & COMM_CONNECT_BLOCKING)) &&
!master_doc->od_doc){
- log_printf(LOG_ERR, "Broadcast for config file failed: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Broadcast for config file failed: %s\n", strerror(-error));
goto fail;
}
error = 0;
if(!master_doc || !master_doc->od_doc){
- log_printf(LOG_ERR, "The appropriate config file could not be loaded.\n");
+ logt_print(LOG_ERR, "The appropriate config file could not be loaded.\n");
error = -ENODATA;
goto fail;
}
if(update_required){
- log_printf(LOG_DEBUG, "Update is required.\n");
+ logt_print(LOG_DEBUG, "Update is required.\n");
if((error = update_config())){
- log_printf(LOG_ERR, "Failed to update config file, required by cluster.\n");
+ logt_print(LOG_ERR, "Failed to update config file, required by cluster.\n");
/* ATTENTION -- remove all open_doc_t's ? */
goto fail;
}
@@ -626,7 +626,7 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
if (!ocs[i])
continue;
if (now >= ocs[i]->oc_expire) {
- log_printf(LOG_DEBUG, "Recycling connection descriptor %d: Expired\n",
+ logt_print(LOG_DEBUG, "Recycling connection descriptor %d: Expired\n",
ocs[i]->oc_desc );
_cleanup_descriptor(i);
}
@@ -669,7 +669,7 @@ static int process_connect(comm_header_t *ch, char *cluster_name){
if(!ocs[i]->oc_ctx){
ocs[i]->oc_odoc->od_refs--;
free(ocs[i]);
- log_printf(LOG_ERR, "Error: unable to create new XPath context.\n");
+ logt_print(LOG_ERR, "Error: unable to create new XPath context.\n");
error = -EIO; /* ATTENTION -- what should this be? */
goto fail;
}
@@ -710,12 +710,12 @@ _cleanup_descriptor(int desc)
}
tmp_odoc = ocs[desc]->oc_odoc;
if(tmp_odoc->od_refs < 1){
- log_printf(LOG_ERR, "Number of references on an open doc should never be < 1.\n");
- log_printf(LOG_ERR, "This is a fatal error. Exiting...\n");
+ logt_print(LOG_ERR, "Number of references on an open doc should never be < 1.\n");
+ logt_print(LOG_ERR, "This is a fatal error. Exiting...\n");
exit(EXIT_FAILURE);
}
if(tmp_odoc != master_doc && tmp_odoc->od_refs == 1){
- log_printf(LOG_DEBUG, "No more references on version %d of config file, freeing...\n",
+ logt_print(LOG_DEBUG, "No more references on version %d of config file, freeing...\n",
get_doc_version(tmp_odoc->od_doc));
xmlFreeDoc(tmp_odoc->od_doc);
free(tmp_odoc);
@@ -745,15 +745,15 @@ static int process_disconnect(comm_header_t *ch){
ch->comm_payload_size = 0;
if(desc < 0){
- log_printf(LOG_ERR, "Invalid descriptor specified (%d).\n", desc);
- log_printf(LOG_ERR, "Someone may be attempting something evil.\n");
+ logt_print(LOG_ERR, "Invalid descriptor specified (%d).\n", desc);
+ logt_print(LOG_ERR, "Someone may be attempting something evil.\n");
error = -EBADR;
goto fail;
}
if(!ocs || !ocs[desc] || (ocs[desc]->oc_desc != ch->comm_desc)){
/* send failure to requestor ? */
- log_printf(LOG_ERR, "Attempt to close an unopened CCS descriptor (%d).\n",
+ logt_print(LOG_ERR, "Attempt to close an unopened CCS descriptor (%d).\n",
ch->comm_desc);
error = -EBADR;
@@ -794,31 +794,31 @@ static int _process_get(comm_header_t *ch, char **payload){
CCSENTER("_process_get");
if(!ch->comm_payload_size){
- log_printf(LOG_ERR, "process_get: payload size is zero.\n");
+ logt_print(LOG_ERR, "process_get: payload size is zero.\n");
error = -EINVAL;
goto fail;
}
if(ch->comm_desc < 0){
- log_printf(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
- log_printf(LOG_ERR, "Someone may be attempting something evil.\n");
+ logt_print(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
+ logt_print(LOG_ERR, "Someone may be attempting something evil.\n");
error = -EBADR;
goto fail;
}
if(!ocs || !ocs[desc] || (ocs[desc]->oc_desc != ch->comm_desc)){
- log_printf(LOG_ERR, "process_get: Invalid connection descriptor received.\n");
+ logt_print(LOG_ERR, "process_get: Invalid connection descriptor received.\n");
error = -EBADR;
goto fail;
}
if(ocs[desc]->oc_query && !strcmp(*payload,ocs[desc]->oc_query)){
ocs[desc]->oc_index++;
- log_printf(LOG_DEBUG, "Index = %d\n",ocs[desc]->oc_index);
- log_printf(LOG_DEBUG, " Query = %s\n", *payload);
+ logt_print(LOG_DEBUG, "Index = %d\n",ocs[desc]->oc_index);
+ logt_print(LOG_DEBUG, " Query = %s\n", *payload);
} else {
- log_printf(LOG_DEBUG, "Index reset (new query).\n");
- log_printf(LOG_DEBUG, " Query = %s\n", *payload);
+ logt_print(LOG_DEBUG, "Index reset (new query).\n");
+ logt_print(LOG_DEBUG, " Query = %s\n", *payload);
ocs[desc]->oc_index = 0;
if(ocs[desc]->oc_query){
free(ocs[desc]->oc_query);
@@ -830,7 +830,7 @@ static int _process_get(comm_header_t *ch, char **payload){
if(((ch->comm_payload_size > 1) &&
((*payload)[0] == '/')) ||
!ocs[desc]->oc_cwp){
- log_printf(LOG_DEBUG, "Query involves absolute path or cwp is not set.\n");
+ logt_print(LOG_DEBUG, "Query involves absolute path or cwp is not set.\n");
query = (char *)strdup(*payload);
if(!query){
error = -ENOMEM;
@@ -838,7 +838,7 @@ static int _process_get(comm_header_t *ch, char **payload){
}
} else {
/* +2 because of NULL and '/' character */
- log_printf(LOG_DEBUG, "Query involves relative path.\n");
+ logt_print(LOG_DEBUG, "Query involves relative path.\n");
query = malloc(strlen(*payload)+strlen(ocs[desc]->oc_cwp)+2);
if(!query){
error = -ENOMEM;
@@ -852,8 +852,8 @@ static int _process_get(comm_header_t *ch, char **payload){
obj = xmlXPathEvalExpression((xmlChar *)query, ocs[desc]->oc_ctx);
if(obj){
- log_printf(LOG_DEBUG, "Obj type = %d (%s)\n", obj->type, (obj->type == 1)?"XPATH_NODESET":"");
- log_printf(LOG_DEBUG, "Number of matches: %d\n", (obj->nodesetval)?obj->nodesetval->nodeNr:0);
+ logt_print(LOG_DEBUG, "Obj type = %d (%s)\n", obj->type, (obj->type == 1)?"XPATH_NODESET":"");
+ logt_print(LOG_DEBUG, "Number of matches: %d\n", (obj->nodesetval)?obj->nodesetval->nodeNr:0);
if(obj->nodesetval && (obj->nodesetval->nodeNr > 0) ){
xmlNodePtr node;
int size=0;
@@ -862,17 +862,17 @@ static int _process_get(comm_header_t *ch, char **payload){
if(ocs[desc]->oc_index >= obj->nodesetval->nodeNr){
ocs[desc]->oc_index = 0;
error = 1;
- log_printf(LOG_DEBUG, "Index reset to zero (end of list).\n");
+ logt_print(LOG_DEBUG, "Index reset to zero (end of list).\n");
}
node = obj->nodesetval->nodeTab[ocs[desc]->oc_index];
- log_printf(LOG_DEBUG, "Node (%s) type = %d (%s)\n", node->name, node->type,
+ logt_print(LOG_DEBUG, "Node (%s) type = %d (%s)\n", node->name, node->type,
(node->type == 1)? "XML_ELEMENT_NODE":
(node->type == 2)? "XML_ATTRIBUTE_NODE":"");
if(!node) {
- log_printf(LOG_DEBUG, "No content found.\n");
+ logt_print(LOG_DEBUG, "No content found.\n");
error = -ENODATA;
goto fail;
}
@@ -898,7 +898,7 @@ static int _process_get(comm_header_t *ch, char **payload){
}
if(size <= ch->comm_payload_size){ /* do we already have enough space? */
- log_printf(LOG_DEBUG, "No extra space needed.\n");
+ logt_print(LOG_DEBUG, "No extra space needed.\n");
if(nnv){
if(child)
sprintf(*payload, "%s=%s", node->name, (char *)node->children->content);
@@ -910,7 +910,7 @@ static int _process_get(comm_header_t *ch, char **payload){
}
} else {
- log_printf(LOG_DEBUG, "Extra space needed.\n");
+ logt_print(LOG_DEBUG, "Extra space needed.\n");
free(*payload);
*payload = (char *)malloc(size);
if(!*payload){
@@ -928,16 +928,16 @@ static int _process_get(comm_header_t *ch, char **payload){
node->name);
}
}
- log_printf(LOG_DEBUG, "Query results:: %s\n", *payload);
+ logt_print(LOG_DEBUG, "Query results:: %s\n", *payload);
ch->comm_payload_size = size;
} else {
- log_printf(LOG_DEBUG, "No nodes found.\n");
+ logt_print(LOG_DEBUG, "No nodes found.\n");
ch->comm_payload_size = 0;
error = -ENODATA;
goto fail;
}
} else {
- log_printf(LOG_ERR, "Error: unable to evaluate xpath query \"%s\"\n", *payload);
+ logt_print(LOG_ERR, "Error: unable to evaluate xpath query \"%s\"\n", *payload);
error = -EINVAL;
goto fail;
}
@@ -986,20 +986,20 @@ static int process_set(comm_header_t *ch, char *payload){
CCSENTER("process_set");
if(!ch->comm_payload_size){
- log_printf(LOG_ERR, "process_set: payload size is zero.\n");
+ logt_print(LOG_ERR, "process_set: payload size is zero.\n");
error = -EINVAL;
goto fail;
}
if(ch->comm_desc < 0){
- log_printf(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
- log_printf(LOG_ERR, "Someone may be attempting something evil.\n");
+ logt_print(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
+ logt_print(LOG_ERR, "Someone may be attempting something evil.\n");
error = -EBADR;
goto fail;
}
if(!ocs || !ocs[desc] || (ocs[desc]->oc_desc != ch->comm_desc)){
- log_printf(LOG_ERR, "process_set: Invalid connection descriptor received.\n");
+ logt_print(LOG_ERR, "process_set: Invalid connection descriptor received.\n");
error = -EBADR;
goto fail;
}
@@ -1023,20 +1023,20 @@ static int process_get_state(comm_header_t *ch, char **payload){
CCSENTER("process_get_state");
if(ch->comm_payload_size){
- log_printf(LOG_ERR, "process_get_state: payload size is nonzero.\n");
+ logt_print(LOG_ERR, "process_get_state: payload size is nonzero.\n");
error = -EINVAL;
goto fail;
}
if(ch->comm_desc < 0){
- log_printf(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
- log_printf(LOG_ERR, "Someone may be attempting something evil.\n");
+ logt_print(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
+ logt_print(LOG_ERR, "Someone may be attempting something evil.\n");
error = -EBADR;
goto fail;
}
if(!ocs || !ocs[desc] || (ocs[desc]->oc_desc != ch->comm_desc)){
- log_printf(LOG_ERR, "process_get_state: Invalid connection descriptor received.\n");
+ logt_print(LOG_ERR, "process_get_state: Invalid connection descriptor received.\n");
error = -EBADR;
goto fail;
}
@@ -1044,7 +1044,7 @@ static int process_get_state(comm_header_t *ch, char **payload){
if(ocs[desc]->oc_cwp && ocs[desc]->oc_query){
int size = strlen(ocs[desc]->oc_cwp) +
strlen(ocs[desc]->oc_query) + 2;
- log_printf(LOG_DEBUG, "Both cwp and query are set.\n");
+ logt_print(LOG_DEBUG, "Both cwp and query are set.\n");
load = malloc(size);
if(!load){
error = -ENOMEM;
@@ -1054,7 +1054,7 @@ static int process_get_state(comm_header_t *ch, char **payload){
strcpy(load+strlen(ocs[desc]->oc_cwp)+1, ocs[desc]->oc_query);
ch->comm_payload_size = size;
} else if(ocs[desc]->oc_cwp){
- log_printf(LOG_DEBUG, "Only cwp is set.\n");
+ logt_print(LOG_DEBUG, "Only cwp is set.\n");
load = (char *)strdup(ocs[desc]->oc_cwp);
if(!load){
error = -ENOMEM;
@@ -1063,7 +1063,7 @@ static int process_get_state(comm_header_t *ch, char **payload){
ch->comm_payload_size = strlen(load)+1;
} else if(ocs[desc]->oc_query){
int size = strlen(ocs[desc]->oc_query) + 2;
- log_printf(LOG_DEBUG, "Only query is set.\n");
+ logt_print(LOG_DEBUG, "Only query is set.\n");
load = malloc(size);
if(!load){
error = -ENOMEM;
@@ -1093,20 +1093,20 @@ static int process_set_state(comm_header_t *ch, char *payload){
CCSENTER("process_set_state");
if(!ch->comm_payload_size){
- log_printf(LOG_ERR, "process_set_state: payload size is zero.\n");
+ logt_print(LOG_ERR, "process_set_state: payload size is zero.\n");
error = -EINVAL;
goto fail;
}
if(ch->comm_desc < 0){
- log_printf(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
- log_printf(LOG_ERR, "Someone may be attempting something evil.\n");
+ logt_print(LOG_ERR, "Invalid descriptor specified (%d).\n", ch->comm_desc);
+ logt_print(LOG_ERR, "Someone may be attempting something evil.\n");
error = -EBADR;
goto fail;
}
if(!ocs || !ocs[desc] || (ocs[desc]->oc_desc != ch->comm_desc)){
- log_printf(LOG_ERR, "process_set_state: Invalid connection descriptor received.\n");
+ logt_print(LOG_ERR, "process_set_state: Invalid connection descriptor received.\n");
error = -EBADR;
goto fail;
}
@@ -1158,10 +1158,10 @@ int process_request(int afd){
error = read(afd, ch, sizeof(comm_header_t));
if(error < 0){
- log_printf(LOG_ERR, "Unable to read comm_header_t");
+ logt_print(LOG_ERR, "Unable to read comm_header_t");
goto fail;
} else if(error < sizeof(comm_header_t)){
- log_printf(LOG_ERR, "Unable to read complete comm_header_t.\n");
+ logt_print(LOG_ERR, "Unable to read complete comm_header_t.\n");
error = -EBADE;
goto fail;
}
@@ -1173,10 +1173,10 @@ int process_request(int afd){
}
error = read(afd, payload, ch->comm_payload_size);
if(error < 0){
- log_printf(LOG_ERR, "Unable to read payload");
+ logt_print(LOG_ERR, "Unable to read payload");
goto fail;
} else if(error < ch->comm_payload_size){
- log_printf(LOG_ERR, "Unable to read complete payload.\n");
+ logt_print(LOG_ERR, "Unable to read complete payload.\n");
error = -EBADE;
goto fail;
}
@@ -1185,20 +1185,20 @@ int process_request(int afd){
switch(ch->comm_type){
case COMM_CONNECT:
if((error = process_connect(ch, payload)) < 0){
- log_printf(LOG_ERR, "Error while processing connect: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing connect: %s\n", strerror(-error));
goto fail;
}
break;
case COMM_DISCONNECT:
if((error = process_disconnect(ch)) < 0){
- log_printf(LOG_ERR, "Error while processing disconnect: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing disconnect: %s\n", strerror(-error));
goto fail;
}
break;
case COMM_GET:
if((error = process_get(ch, &payload)) < 0){
if(error != -ENODATA){
- log_printf(LOG_ERR, "Error while processing get: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing get: %s\n", strerror(-error));
}
goto fail;
}
@@ -1206,43 +1206,43 @@ int process_request(int afd){
case COMM_GET_LIST:
if((error = process_get_list(ch, &payload)) < 0){
if(error != -ENODATA){
- log_printf(LOG_ERR, "Error while processing get: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing get: %s\n", strerror(-error));
}
goto fail;
}
break;
case COMM_SET:
if((error = process_set(ch, payload)) < 0){
- log_printf(LOG_ERR, "Error while processing set: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing set: %s\n", strerror(-error));
goto fail;
}
break;
case COMM_GET_STATE:
if((error = process_get_state(ch, &payload)) < 0){
- log_printf(LOG_ERR, "Error while processing get_state: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing get_state: %s\n", strerror(-error));
goto fail;
}
break;
case COMM_SET_STATE:
if((error = process_set_state(ch, payload)) < 0){
- log_printf(LOG_ERR, "Error while processing set_state: %s\n", strerror(-error));
+ logt_print(LOG_ERR, "Error while processing set_state: %s\n", strerror(-error));
goto fail;
}
break;
default:
- log_printf(LOG_ERR, "Unknown connection request received.\n");
+ logt_print(LOG_ERR, "Unknown connection request received.\n");
error = -EINVAL;
ch->comm_error = error;
ch->comm_payload_size = 0;
}
if(ch->comm_payload_size){
- log_printf(LOG_DEBUG, "Reallocating transfer buffer.\n");
+ logt_print(LOG_DEBUG, "Reallocating transfer buffer.\n");
tmp_ch = (comm_header_t *)
realloc(ch,sizeof(comm_header_t)+ch->comm_payload_size);
if(tmp_ch) { ch = tmp_ch; } else {
- log_printf(LOG_ERR, "Not enough memory to complete request.\n");
+ logt_print(LOG_ERR, "Not enough memory to complete request.\n");
error = -ENOMEM;
goto fail;
}
@@ -1257,10 +1257,10 @@ int process_request(int afd){
if (errno == EPIPE) {
error = 0;
} else {
- log_printf(LOG_ERR, "Unable to write package back to sender");
+ logt_print(LOG_ERR, "Unable to write package back to sender");
}
} else if(error < (sizeof(comm_header_t)+ch->comm_payload_size)){
- log_printf(LOG_ERR, "Unable to write complete package.\n");
+ logt_print(LOG_ERR, "Unable to write complete package.\n");
error = -EBADE;
goto fail;
} else {
@@ -1301,9 +1301,9 @@ int process_broadcast(int sfd){
memset(ch, 0, sizeof(comm_header_t));
memset(&addr, 0, sizeof(struct sockaddr_storage)); /* just to make sure */
- log_printf(LOG_DEBUG, "Waiting to receive broadcast request.\n");
+ logt_print(LOG_DEBUG, "Waiting to receive broadcast request.\n");
if(recvfrom(sfd, ch, sizeof(comm_header_t), 0, (struct sockaddr *)&addr, &len) < 0){
- log_printf(LOG_ERR, "Unable to perform recvfrom");
+ logt_print(LOG_ERR, "Unable to perform recvfrom");
error = -errno;
goto fail;
}
@@ -1313,7 +1313,7 @@ int process_broadcast(int sfd){
/* Either someone is pinging this port, or there is an older version **
** of ccs trying to get bcast response. Either way, we should not **
** respond to them.................................................. */
- log_printf(LOG_DEBUG, "Received invalid request on broadcast port. %x\n",ch->comm_type);
+ logt_print(LOG_DEBUG, "Received invalid request on broadcast port. %x\n",ch->comm_type);
error = -EINVAL;
goto fail;
}
@@ -1326,7 +1326,7 @@ int process_broadcast(int sfd){
if(!master_doc){
discard = 1;
- log_printf(LOG_DEBUG, "master_doc not loaded. Attempting to load it.\n");
+ logt_print(LOG_DEBUG, "master_doc not loaded. Attempting to load it.\n");
if(!(master_doc = malloc(sizeof(open_doc_t)))){
error = -ENOMEM;
goto fail;
@@ -1336,15 +1336,15 @@ int process_broadcast(int sfd){
if(!master_doc->od_doc){
free(master_doc);
master_doc = NULL;
- log_printf(LOG_ERR, "Unable to parse " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
+ logt_print(LOG_ERR, "Unable to parse " DEFAULT_CONFIG_DIR "/" DEFAULT_CONFIG_FILE ".\n");
error = -ENODATA;
goto fail;
}
- log_printf(LOG_DEBUG, "master_doc found and loaded.\n");
+ logt_print(LOG_DEBUG, "master_doc found and loaded.\n");
} else if(update_required){
- log_printf(LOG_DEBUG, "Update is required.\n");
+ logt_print(LOG_DEBUG, "Update is required.\n");
if((error = update_config())){
- log_printf(LOG_ERR, "Failed to update config file, required by cluster.\n");
+ logt_print(LOG_ERR, "Failed to update config file, required by cluster.\n");
/* ATTENTION -- remove all open_doc_t's ? */
goto fail;
}
@@ -1357,7 +1357,7 @@ int process_broadcast(int sfd){
0);
if(!ch->comm_payload_size){
error = -ENOMEM;
- log_printf(LOG_ERR, "Document dump to memory failed.\n");
+ logt_print(LOG_ERR, "Document dump to memory failed.\n");
goto fail;
}
@@ -1376,11 +1376,11 @@ int process_broadcast(int sfd){
swab_header(ch); /* Swab back to dip into ch for payload_size */
memcpy(buffer+sizeof(comm_header_t), payload, ch->comm_payload_size);
- log_printf(LOG_DEBUG, "Sending configuration (version %d)...\n", get_doc_version(master_doc->od_doc));
+ logt_print(LOG_DEBUG, "Sending configuration (version %d)...\n", get_doc_version(master_doc->od_doc));
sendlen = ch->comm_payload_size + sizeof(comm_header_t);
if(sendto(sfd, buffer, sendlen, 0,
(struct sockaddr *)&addr, (socklen_t)len) < 0){
- log_printf(LOG_ERR, "Sendto failed");
+ logt_print(LOG_ERR, "Sendto failed");
error = -errno;
}
diff --git a/config/daemons/ccsd/debug.h b/config/daemons/ccsd/debug.h
index 4ed365c..00b9db9 100644
--- a/config/daemons/ccsd/debug.h
+++ b/config/daemons/ccsd/debug.h
@@ -1,8 +1,8 @@
#ifndef __DEBUG_DOT_H__
#define __DEBUG_DOT_H__
-#define CCSENTER(x) log_printf(LOG_DEBUG, "Entering " x "\n")
-#define CCSEXIT(x) log_printf(LOG_DEBUG, "Exiting " x "\n")
+#define CCSENTER(x) logt_print(LOG_DEBUG, "Entering " x "\n")
+#define CCSEXIT(x) logt_print(LOG_DEBUG, "Exiting " x "\n")
extern int debug;
diff --git a/config/daemons/ccsd/misc.c b/config/daemons/ccsd/misc.c
index 543dd31..b39833e 100644
--- a/config/daemons/ccsd/misc.c
+++ b/config/daemons/ccsd/misc.c
@@ -11,12 +11,14 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <errno.h>
-#include <errno.h>
+#include <limits.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
-#include <corosync/engine/logsys.h>
+#define SYSLOG_NAMES
+#include <syslog.h>
+#include <liblogthread.h>
#include "comm_headers.h"
#include "debug.h"
@@ -29,6 +31,8 @@ pthread_mutex_t update_lock;
open_doc_t *master_doc = NULL;
+extern int nodaemon;
+
/**
* do_simple_xml_query
* @ctx: xml context
@@ -44,14 +48,14 @@ static char *do_simple_xml_query(xmlXPathContextPtr ctx, char *query) {
obj = xmlXPathEvalExpression((xmlChar *)query, ctx);
if(!obj || !obj->nodesetval || (obj->nodesetval->nodeNr != 1))
- log_printf(LOG_DEBUG, "Error processing query: %s.\n", query);
+ logt_print(LOG_DEBUG, "Error processing query: %s.\n", query);
else {
node = obj->nodesetval->nodeTab[0];
if(node->type != XML_ATTRIBUTE_NODE)
- log_printf(LOG_DEBUG, "Object returned is not of attribute type.\n");
+ logt_print(LOG_DEBUG, "Object returned is not of attribute type.\n");
else {
if(!node->children->content || !strlen((char *)node->children->content))
- log_printf(LOG_DEBUG, "No content found.\n");
+ logt_print(LOG_DEBUG, "No content found.\n");
else {
CCSEXIT("do_simple_xml_query");
return strdup((char *)node->children->content);
@@ -76,7 +80,7 @@ int get_doc_version(xmlDocPtr ldoc){
ctx = xmlXPathNewContext(ldoc);
if(!ctx){
- log_printf(LOG_ERR, "Error: unable to create new XPath context.\n");
+ logt_print(LOG_ERR, "Error: unable to create new XPath context.\n");
error = -EIO; /* ATTENTION -- what should this be? */
goto fail;
}
@@ -85,7 +89,7 @@ int get_doc_version(xmlDocPtr ldoc){
if(res) {
for(i=0; i < strlen(res); i++){
if(!isdigit(res[i])){
- log_printf(LOG_ERR, "config_version is not a valid integer.\n");
+ logt_print(LOG_ERR, "config_version is not a valid integer.\n");
error = -EINVAL;
goto fail;
}
@@ -125,7 +129,7 @@ char *get_cluster_name(xmlDocPtr ldoc){
ctx = xmlXPathNewContext(ldoc);
if(!ctx){
- log_printf(LOG_ERR, "Error: unable to create new XPath context.\n");
+ logt_print(LOG_ERR, "Error: unable to create new XPath context.\n");
error = -EIO; /* ATTENTION -- what should this be? */
goto fail;
}
@@ -141,147 +145,243 @@ fail:
return rtn;
}
+static int facility_id_get(char *name)
+{
+ unsigned int i;
+
+ for (i = 0; facilitynames[i].c_name != NULL; i++) {
+ if (strcasecmp(name, facilitynames[i].c_name) == 0) {
+ return (facilitynames[i].c_val);
+ }
+ }
+ return (-1);
+}
+
+static int priority_id_get(char *name)
+{
+ unsigned int i;
+
+ for (i = 0; prioritynames[i].c_name != NULL; i++) {
+ if (strcasecmp(name, prioritynames[i].c_name) == 0) {
+ return (prioritynames[i].c_val);
+ }
+ }
+ return (-1);
+}
+
/**
* set_ccs_logging
* @ldoc:
*
* Returns: -1 on failure. NULL on success.
*/
-int set_ccs_logging(xmlDocPtr ldoc){
- int facility = SYSLOGFACILITY, loglevel = SYSLOGLEVEL, global_debug = 0;
- char *res = NULL, *error = NULL;
+int set_ccs_logging(xmlDocPtr ldoc, int reconf){
+ int mode = LOG_MODE_OUTPUT_FILE | LOG_MODE_OUTPUT_SYSLOG;
+ int syslog_facility = SYSLOGFACILITY;
+ int syslog_priority = SYSLOGLEVEL;
+ char logfile[PATH_MAX];
+ int logfile_priority = SYSLOGLEVEL;
+ int val;
+ char *res = NULL;
xmlXPathContextPtr ctx = NULL;
- unsigned int logmode;
CCSENTER("set_ccs_logging");
+ /* defaults */
+ memset(logfile, 0, PATH_MAX);
+ sprintf(logfile, LOGDIR "/ccs.log");
+
+ if(nodaemon)
+ mode |= LOG_MODE_OUTPUT_STDERR;
+
+ if(!reconf) /* init defaults here */
+ logt_init("CCS", mode, syslog_facility, syslog_priority, logfile_priority, logfile);
+
+ if(!ldoc) {
+ CCSEXIT("set_ccs_logging (default settings)");
+ return 0;
+ }
+
+ if(!ldoc && reconf) {
+ CCSEXIT("set_ccs_logging (reconf with no doc?)");
+ return -1;
+ }
+
ctx = xmlXPathNewContext(ldoc);
if(!ctx){
- log_printf(LOG_ERR, "Error: unable to create new XPath context.\n");
+ logt_print(LOG_ERR, "Error: unable to create new XPath context.\n");
return -1;
}
- logmode = logsys_config_mode_get();
-
- if(!debug) {
- res = do_simple_xml_query(ctx, "/cluster/logging/@debug");
- if(res) {
- if(!strcmp(res, "on")) {
- global_debug = 1;
- } else
- if(!strcmp(res, "off")) {
- global_debug = 0;
- } else
- log_printf(LOG_ERR, "global debug: unknown value\n");
- free(res);
- res=NULL;
- }
+ /** This clone the same stuff in ccs_read_logging
+ ** that unfortunately we cannot use in ccsd itself..
+ **/
- res = do_simple_xml_query(ctx, "/cluster/logging/logger_subsys[@subsys=\"CCS\"]/@debug");
- if(res) {
- if(!strcmp(res, "on")) {
- debug = 1;
- } else
- if(!strcmp(res, "off")) { /* debug from cmdline/envvars override config */
- debug = 0;
- } else
- log_printf(LOG_ERR, "subsys debug: unknown value\n");
- free(res);
- res=NULL;
- } else
- debug = global_debug; /* global debug overrides subsystem only if latter is not specified */
-
- res = do_simple_xml_query(ctx, "/cluster/logging/logger_subsys[@subsys=\"CCS\"]/@syslog_level");
- if(res) {
- loglevel = logsys_priority_id_get (res);
- if (loglevel < 0)
- loglevel = SYSLOGLEVEL;
-
- if(!debug) {
- if(loglevel == LOG_LEVEL_DEBUG)
- debug = 1;
-
- logsys_config_priority_set (loglevel);
- }
+ /* to_syslog */
+ res = do_simple_xml_query(ctx, "/cluster/logging/@to_syslog");
+ if(res) {
+ if(!strcmp(res, "yes"))
+ mode |= LOG_MODE_OUTPUT_SYSLOG;
+ else if(!strcmp(res, "no"))
+ mode &= ~LOG_MODE_OUTPUT_SYSLOG;
- free(res);
- res=NULL;
- }
- } else
- logsys_config_priority_set (LOG_LEVEL_DEBUG);
+ free(res);
+ res=NULL;
+ }
- res = do_simple_xml_query(ctx, "/cluster/logging/@to_stderr");
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@to_syslog");
if(res) {
- if(!strcmp(res, "yes")) {
- logmode |= LOG_MODE_OUTPUT_STDERR;
- } else
- if(!strcmp(res, "no")) {
- logmode &= ~LOG_MODE_OUTPUT_STDERR;
- } else
- log_printf(LOG_ERR, "to_stderr: unknown value\n");
+ if(!strcmp(res, "yes"))
+ mode |= LOG_MODE_OUTPUT_SYSLOG;
+ else if(!strcmp(res, "no"))
+ mode &= ~LOG_MODE_OUTPUT_SYSLOG;
+
free(res);
res=NULL;
}
- res = do_simple_xml_query(ctx, "/cluster/logging/@to_syslog");
+ /* to logfile */
+ res = do_simple_xml_query(ctx, "/cluster/logging/@to_logfile");
if(res) {
- if(!strcmp(res, "yes")) {
- logmode |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
- } else
- if(!strcmp(res, "no")) {
- logmode &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
- } else
- log_printf(LOG_ERR, "to_syslog: unknown value\n");
+ if(!strcmp(res, "yes"))
+ mode |= LOG_MODE_OUTPUT_FILE;
+ else if(!strcmp(res, "no"))
+ mode &= ~LOG_MODE_OUTPUT_FILE;
+
free(res);
res=NULL;
}
- res = do_simple_xml_query(ctx, "/cluster/logging/@to_file");
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@to_logfile");
if(res) {
- if(!strcmp(res, "yes")) {
- logmode |= LOG_MODE_OUTPUT_FILE;
- } else
- if(!strcmp(res, "no")) {
- logmode &= ~LOG_MODE_OUTPUT_FILE;
- } else
- log_printf(LOG_ERR, "to_file: unknown value\n");
+ if(!strcmp(res, "yes"))
+ mode |= LOG_MODE_OUTPUT_FILE;
+ else if(!strcmp(res, "no"))
+ mode &= ~LOG_MODE_OUTPUT_FILE;
+
+ free(res);
+ res=NULL;
+ }
+
+ /* syslog_facility */
+ res = do_simple_xml_query(ctx, "/cluster/logging/@syslog_facility");
+ if(res) {
+ val = facility_id_get(res);
+ if (val >= 0)
+ syslog_facility = val;
+
+ free(res);
+ res=NULL;
+ }
+
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@syslog_facility");
+ if(res) {
+ val = facility_id_get(res);
+ if (val >= 0)
+ syslog_facility = val;
+
free(res);
res=NULL;
}
+ /* syslog_priority */
+ res = do_simple_xml_query(ctx, "/cluster/logging/@syslog_priority");
+ if(res) {
+ val = priority_id_get(res);
+ if (val >= 0)
+ syslog_priority = val;
+
+ free(res);
+ res=NULL;
+ }
+
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@syslog_priority");
+ if(res) {
+ val = priority_id_get(res);
+ if (val >= 0)
+ syslog_priority = val;
+
+ free(res);
+ res=NULL;
+ }
+
+ /* logfile */
res = do_simple_xml_query(ctx, "/cluster/logging/@logfile");
if(res) {
- if(logsys_config_file_set(&error, res))
- log_printf(LOG_ERR, "logfile: unable to open %s for logging\n", res);
+ memset(logfile, 0, PATH_MAX);
+ strcpy(logfile, res);
+
free(res);
res=NULL;
- } else
- log_printf(LOG_DEBUG, "logfile: use default built-in log file: %s\n", LOGDIR "/ccs.log");
+ }
- res = do_simple_xml_query(ctx, "/cluster/logging/@syslog_facility");
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@logfile");
if(res) {
- facility = logsys_facility_id_get (res);
- if (facility < 0) {
- log_printf(LOG_ERR, "syslog_facility: unknown value\n");
- facility = SYSLOGFACILITY;
- }
+ memset(logfile, 0, PATH_MAX);
+ strcpy(logfile, res);
+
+ free(res);
+ res=NULL;
+ }
+
+ if(debug) {
+ logfile_priority = LOG_DEBUG;
+ goto debug_out;
+ }
+
+ /* debug */
+ res = do_simple_xml_query(ctx, "/cluster/logging/@debug");
+ if(res) {
+ if(!strcmp(res, "on"))
+ debug = 1;
+
+ free(res);
+ res=NULL;
+ }
+
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@debug");
+ if(res) {
+ if(!strcmp(res, "on"))
+ debug = 1;
+ else if(!strcmp(res, "off"))
+ debug = 0;
- logsys_config_facility_set ("CCS", facility);
- log_printf(LOG_DEBUG, "log_facility: %s (%d).\n", res, facility);
free(res);
res=NULL;
}
+ if (debug) {
+ logfile_priority = LOG_DEBUG;
+ goto debug_out;
+ }
+
+ /* logfile_priority */
+ res = do_simple_xml_query(ctx, "/cluster/logging/@logfile_priority");
+ if(res) {
+ val = priority_id_get(res);
+ if (val >= 0)
+ syslog_priority = val;
+
+ free(res);
+ res=NULL;
+ }
+
+ res = do_simple_xml_query(ctx, "/cluster/logging/logging_subsys[@subsys=\"CCS\"]/@logfile_priority");
+ if(res) {
+ val = priority_id_get(res);
+ if (val >= 0)
+ syslog_priority = val;
+
+ free(res);
+ res=NULL;
+ }
+
+debug_out:
if(ctx){
xmlXPathFreeContext(ctx);
}
- if(logmode & LOG_MODE_BUFFER_BEFORE_CONFIG) {
- log_printf(LOG_DEBUG, "logsys config enabled from set_ccs_logging\n");
- logmode &= ~LOG_MODE_BUFFER_BEFORE_CONFIG;
- logmode |= LOG_MODE_FLUSH_AFTER_CONFIG;
- logsys_config_mode_set (logmode);
- }
+ logt_conf("CCS", mode, syslog_facility, syslog_priority, logfile_priority, logfile);
CCSEXIT("set_ccs_logging");
return 0;
diff --git a/config/daemons/ccsd/misc.h b/config/daemons/ccsd/misc.h
index 0636c7e..706d605 100644
--- a/config/daemons/ccsd/misc.h
+++ b/config/daemons/ccsd/misc.h
@@ -14,6 +14,6 @@ extern open_doc_t *master_doc;
char *get_cluster_name(xmlDocPtr ldoc);
int get_doc_version(xmlDocPtr ldoc);
-int set_ccs_logging(xmlDocPtr ldoc);
+int set_ccs_logging(xmlDocPtr ldoc, int reconf);
#endif /* __MISC_H__ */