Преглед на файлове

CTS: convert the test agents to use qb logging

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Angus Salkeld преди 14 години
родител
ревизия
fa9f239d06
променени са 5 файла, в които са добавени 256 реда и са изтрити 261 реда
  1. 31 20
      cts/agents/common_test_agent.c
  2. 3 1
      cts/agents/common_test_agent.h
  3. 3 11
      cts/agents/cpg_test_agent.c
  4. 196 196
      cts/agents/sam_test_agent.c
  5. 23 33
      cts/agents/votequorum_test_agent.c

+ 31 - 20
cts/agents/common_test_agent.c

@@ -43,13 +43,11 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#include <syslog.h>
 #include <poll.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <qb/qbloop.h>
-#include "common_test_agent.h"
 
+#include "common_test_agent.h"
 
 int32_t parse_debug = 0;
 static char big_and_buf_rx[HOW_BIG_AND_BUF];
@@ -84,7 +82,7 @@ static void ta_handle_command (int sock, char* msg)
 	char* func = NULL;
 
 	if (parse_debug)
-		syslog (LOG_DEBUG,"%s (MSG:%s)\n", __func__, msg);
+		qb_log (LOG_DEBUG,"%s (MSG:%s)\n", __func__, msg);
 
 	str_len = strtok_r (str, ":", &saveptr);
 	assert (str_len);
@@ -96,14 +94,14 @@ static void ta_handle_command (int sock, char* msg)
 		if (func == NULL) {
 			/* first "arg" is the function */
 			if (parse_debug)
-				syslog (LOG_DEBUG, "(LEN:%s, FUNC:%s)", str_len, str_arg);
+				qb_log (LOG_DEBUG, "(LEN:%s, FUNC:%s)", str_len, str_arg);
 			func = str_arg;
 			a = 0;
 		} else {
 			args[a] = str_arg;
 			a++;
 			if (parse_debug)
-				syslog (LOG_DEBUG, "(LEN:%s, ARG:%s)", str_len, str_arg);
+				qb_log (LOG_DEBUG, "(LEN:%s, ARG:%s)", str_len, str_arg);
 		}
 	}
 	do_command (sock, func, args, a+1);
@@ -121,7 +119,8 @@ static int server_process_data_fn (
 	char *cmd;
 	int32_t nbytes;
 
-	if (revents & POLLHUP) {
+	if (revents & POLLHUP || revents & POLLERR) {
+		qb_log (LOG_INFO, "command sockect got POLLHUP exiting...");
 		shut_me_down();
 		return -1;
 	}
@@ -130,9 +129,9 @@ static int server_process_data_fn (
 		/* got error or connection closed by client */
 		if (nbytes == 0) {
 			/* connection closed */
-			syslog (LOG_WARNING, "socket %d hung up: exiting...\n", fd);
+			qb_log (LOG_WARNING, "socket %d hung up: exiting...\n", fd);
 		} else {
-			syslog (LOG_ERR,"recv() failed: %s", strerror(errno));
+			qb_perror(LOG_ERR, "recv() failed");
 		}
 		shut_me_down();
 		return -1;
@@ -160,7 +159,8 @@ static int server_accept_fn (
 	int new_fd;
 	int res;
 
-	if (revents & POLLHUP) {
+	if (revents & POLLHUP || revents & POLLERR) {
+		qb_log (LOG_INFO, "command sockect got POLLHUP exiting...");
 		shut_me_down();
 		return -1;
 	}
@@ -174,14 +174,14 @@ retry_accept:
 	}
 
 	if (new_fd == -1) {
-		syslog (LOG_ERR,
+		qb_log (LOG_ERR,
 			"Could not accept connection: %s\n", strerror (errno));
 		return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
 	}
 
 	res = fcntl (new_fd, F_SETFL, O_NONBLOCK);
 	if (res == -1) {
-		syslog (LOG_ERR,
+		qb_log (LOG_ERR,
 			"Could not set non-blocking operation on connection: %s\n",
 			strerror (errno));
 		close (new_fd);
@@ -216,7 +216,7 @@ static int create_server_sockect (int server_port)
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_flags = AI_PASSIVE;
 	if ((rv = getaddrinfo (NULL, server_port_str, &hints, &ai)) != 0) {
-		syslog (LOG_ERR, "%s", gai_strerror (rv));
+		qb_log (LOG_ERR, "%s", gai_strerror (rv));
 		exit (1);
 	}
 
@@ -230,7 +230,7 @@ static int create_server_sockect (int server_port)
 		 */
 		if (setsockopt (listener, SOL_SOCKET, SO_REUSEADDR,
 				&yes, sizeof(int)) < 0) {
-			syslog (LOG_ERR, "setsockopt() failed: %s", strerror (errno));
+			qb_log (LOG_ERR, "setsockopt() failed: %s", strerror (errno));
 		}
 
 		switch (p->ai_family)
@@ -242,17 +242,17 @@ static int create_server_sockect (int server_port)
 			ptr = &((struct sockaddr_in6 *) p->ai_addr)->sin6_addr;
 			break;
 		default:
-			syslog (LOG_ERR, "address family wrong");
+			qb_log (LOG_ERR, "address family wrong");
 			exit (4);
 			
 		}
 
 		if (inet_ntop(p->ai_family, ptr, addr_str, INET_ADDRSTRLEN) == NULL) {
-			syslog (LOG_ERR, "inet_ntop() failed: %s", strerror (errno));
+			qb_log (LOG_ERR, "inet_ntop() failed: %s", strerror (errno));
 		}
 
 		if (bind (listener, p->ai_addr, p->ai_addrlen) < 0) {
-			syslog (LOG_ERR, "bind(%s) failed: %s\n", addr_str, strerror (errno));
+			qb_log (LOG_ERR, "bind(%s) failed: %s\n", addr_str, strerror (errno));
 			close (listener);
 			continue;
 		}
@@ -261,14 +261,14 @@ static int create_server_sockect (int server_port)
 	}
 
 	if (p == NULL) {
-		syslog (LOG_ERR, "failed to bind");
+		qb_log (LOG_ERR, "failed to bind");
 		exit (2);
 	}
 
 	freeaddrinfo (ai);
 
 	if (listen (listener, 10) == -1) {
-		syslog (LOG_ERR, "listen() failed: %s", strerror(errno));
+		qb_log (LOG_ERR, "listen() failed: %s", strerror(errno));
 		exit (3);
 	}
 
@@ -277,14 +277,22 @@ static int create_server_sockect (int server_port)
 
 static int32_t sig_exit_handler (int num, void *data)
 {
+	qb_log (LOG_INFO, "got signal %d, exiting", num);
 	shut_me_down();
 	return 0;
 }
 
-int test_agent_run(int server_port, ta_do_command_fn func, pre_exit_fn exit_fn)
+int
+test_agent_run(const char * prog_name, int server_port,
+		ta_do_command_fn func, pre_exit_fn exit_fn)
 {
 	int listener;
 
+	qb_log_init(prog_name, LOG_DAEMON, LOG_DEBUG);
+	qb_log_format_set(QB_LOG_SYSLOG, "%n() [%p] %b");
+
+	qb_log (LOG_INFO, "STARTING");
+
 	do_command = func;
 	pre_exit = exit_fn;
 	poll_handle = qb_loop_create ();
@@ -306,6 +314,9 @@ int test_agent_run(int server_port, ta_do_command_fn func, pre_exit_fn exit_fn)
 			  NULL, server_accept_fn);
 
 	qb_loop_run (poll_handle);
+
+	qb_log (LOG_INFO, "EXITING");
+	qb_log_fini();
 	return 0;
 }
 

+ 3 - 1
cts/agents/common_test_agent.h

@@ -37,6 +37,7 @@
 
 #include <corosync/hdb.h>
 #include <qb/qbloop.h>
+#include <qb/qblog.h>
 
 #define OK_STR "OK"
 #define FAIL_STR "FAIL"
@@ -48,7 +49,8 @@ extern int32_t parse_debug;
 typedef void (*ta_do_command_fn) (int sock, char* func, char*args[], int num_args);
 typedef void (*pre_exit_fn) (void);
 
-int test_agent_run(int server_port, ta_do_command_fn func, pre_exit_fn exit_fn);
+int test_agent_run(const char * prog_name, int server_port,
+		   ta_do_command_fn func, pre_exit_fn exit_fn);
 
 qb_loop_t *ta_poll_handle_get(void);
 

+ 3 - 11
cts/agents/cpg_test_agent.c

@@ -773,20 +773,12 @@ static void my_pre_exit(void)
 	}
 }
 
-int main (int argc, char *argv[])
+int
+main(int argc, char *argv[])
 {
-	int res = 0;
-
-	qb_log_init("cpg_test_agent", LOG_DAEMON, LOG_DEBUG);
-	qb_log_format_set(QB_LOG_SYSLOG, "%n() [%p] %b");
-	qb_log (LOG_INFO, "STARTING");
-
 	list_init (&msg_log_head);
 	list_init (&config_chg_log_head);
 
-	res = test_agent_run (9034, do_command, my_pre_exit);
-	qb_log (LOG_INFO, "EXITING");
-	qb_log_fini();
-	return res;
+	return test_agent_run ("cpg_test_agent", 9034, do_command, my_pre_exit);
 }
 

Файловите разлики са ограничени, защото са твърде много
+ 196 - 196
cts/agents/sam_test_agent.c


+ 23 - 33
cts/agents/votequorum_test_agent.c

@@ -45,7 +45,6 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <sys/un.h>
-#include <syslog.h>
 #include <poll.h>
 
 #include <qb/qbloop.h>
@@ -65,7 +64,7 @@ static void votequorum_notification_fn(
 	uint32_t node_list_entries,
 	votequorum_node_t node_list[])
 {
-	syslog (LOG_INFO, "VQ notification quorate: %d", quorate);
+	qb_log (LOG_INFO, "VQ notification quorate: %d", quorate);
 }
 
 static void quorum_notification_fn(
@@ -75,7 +74,7 @@ static void quorum_notification_fn(
 	uint32_t view_list_entries,
 	uint32_t *view_list)
 {
-	syslog (LOG_INFO, "NQ notification quorate: %d", quorate);
+	qb_log (LOG_INFO, "NQ notification quorate: %d", quorate);
 }
 
 
@@ -86,7 +85,7 @@ static int vq_dispatch_wrapper_fn (
 {
 	cs_error_t error = votequorum_dispatch (vq_handle, CS_DISPATCH_ALL);
 	if (error != CS_OK) {
-		syslog (LOG_ERR, "%s() got %s error, disconnecting.",
+		qb_log (LOG_ERR, "%s() got %s error, disconnecting.",
 			__func__, cs_strerror(error));
 		votequorum_finalize(vq_handle);
 		qb_loop_poll_del (ta_poll_handle_get(), fd);
@@ -104,7 +103,7 @@ static int q_dispatch_wrapper_fn (
 {
 	cs_error_t error = quorum_dispatch (q_handle, CS_DISPATCH_ALL);
 	if (error != CS_OK) {
-		syslog (LOG_ERR, "%s() got %s error, disconnecting.",
+		qb_log (LOG_ERR, "%s() got %s error, disconnecting.",
 			__func__, cs_strerror(error));
 		quorum_finalize(q_handle);
 		qb_loop_poll_del (ta_poll_handle_get(), fd);
@@ -124,7 +123,7 @@ static int q_lib_init(void)
 	int fd;
 
 	if (vq_handle == 0) {
-		syslog (LOG_INFO, "votequorum_initialize");
+		qb_log (LOG_INFO, "votequorum_initialize");
 		vq_callbacks.votequorum_notify_fn = votequorum_notification_fn;
 		vq_callbacks.votequorum_expectedvotes_notify_fn = NULL;
 		ret = CS_ERR_NOT_EXIST;
@@ -136,13 +135,13 @@ static int q_lib_init(void)
 			}
 		}
 		if (ret != CS_OK) {
-			syslog (LOG_ERR, "votequorum_initialize FAILED: %d\n", ret);
+			qb_log (LOG_ERR, "votequorum_initialize FAILED: %d\n", ret);
 			vq_handle = 0;
 		}
 		else {
 			ret = votequorum_trackstart (vq_handle, vq_handle, CS_TRACK_CHANGES);
 			if (ret != CS_OK) {
-				syslog (LOG_ERR, "votequorum_trackstart FAILED: %d\n", ret);
+				qb_log (LOG_ERR, "votequorum_trackstart FAILED: %d\n", ret);
 			}
 
 			votequorum_fd_get (vq_handle, &fd);
@@ -152,17 +151,17 @@ static int q_lib_init(void)
 	}
 	if (q_handle == 0) {
 		uint32_t q_type;
-		syslog (LOG_INFO, "quorum_initialize");
+		qb_log (LOG_INFO, "quorum_initialize");
 		q_callbacks.quorum_notify_fn = quorum_notification_fn;
 		ret = quorum_initialize (&q_handle, &q_callbacks, &q_type);
 		if (ret != CS_OK) {
-			syslog (LOG_ERR, "quorum_initialize FAILED: %d\n", ret);
+			qb_log (LOG_ERR, "quorum_initialize FAILED: %d\n", ret);
 			q_handle = 0;
 		}
 		else {
 			ret = quorum_trackstart (q_handle, CS_TRACK_CHANGES);
 			if (ret != CS_OK) {
-				syslog (LOG_ERR, "quorum_trackstart FAILED: %d\n", ret);
+				qb_log (LOG_ERR, "quorum_trackstart FAILED: %d\n", ret);
 			}
 			quorum_fd_get (q_handle, &fd);
 			qb_loop_poll_add (ta_poll_handle_get(), QB_LOOP_MED, fd,
@@ -182,7 +181,7 @@ static void lib_init (int sock)
 
 	if (ret != CS_OK) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "q_lib_init FAILED: %d\n", ret);
+		qb_log (LOG_ERR, "q_lib_init FAILED: %d\n", ret);
 	}
 
 	send (sock, response, strlen (response), 0);
@@ -199,7 +198,7 @@ static void getinfo (int sock)
 	ret = votequorum_getinfo(vq_handle, 0, &info);
 	if (ret != CS_OK) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "votequorum_getinfo FAILED: %d\n", ret);
+		qb_log (LOG_ERR, "votequorum_getinfo FAILED: %d\n", ret);
 		goto send_response;
 	}
 
@@ -225,7 +224,7 @@ static void setexpected (int sock, char *arg)
 	ret = votequorum_setexpected (vq_handle, atoi(arg));
 	if (ret != CS_OK) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "set expected votes FAILED: %d\n", ret);
+		qb_log (LOG_ERR, "set expected votes FAILED: %d\n", ret);
 		goto send_response;
 	}
 
@@ -245,7 +244,7 @@ static void setvotes (int sock, char *arg)
 	ret = votequorum_setvotes (vq_handle, 0, atoi(arg));
 	if (ret != CS_OK) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "set votes FAILED: %d\n", ret);
+		qb_log (LOG_ERR, "set votes FAILED: %d\n", ret);
 		goto send_response;
 	}
 
@@ -267,7 +266,7 @@ static void getquorate (int sock)
 	ret = quorum_getquorate (q_handle, &quorate);
 	if (ret != CS_OK) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "getquorate FAILED: %d\n", ret);
+		qb_log (LOG_ERR, "getquorate FAILED: %d\n", ret);
 		goto send_response;
 	}
 
@@ -288,14 +287,14 @@ static void context_test (int sock)
 	votequorum_context_get (vq_handle, (void**)&cmp);
 	if (response != cmp) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "votequorum context not the same");
+		qb_log (LOG_ERR, "votequorum context not the same");
 	}
 
 	quorum_context_set (q_handle, response);
 	quorum_context_get (q_handle, (const void**)&cmp);
 	if (response != cmp) {
 		snprintf (response, 100, "%s", FAIL_STR);
-		syslog (LOG_ERR, "quorum context not the same");
+		qb_log (LOG_ERR, "quorum context not the same");
 	}
 	send (sock, response, strlen (response) + 1, 0);
 }
@@ -305,7 +304,7 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 	char response[100];
 
 	if (parse_debug)
-		syslog (LOG_DEBUG,"RPC:%s() called.", func);
+		qb_log (LOG_DEBUG,"RPC:%s() called.", func);
 
 	if (strcmp ("votequorum_getinfo", func) == 0) {
 		getinfo (sock);
@@ -323,7 +322,7 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 		snprintf (response, 100, "%s", OK_STR);
 		send (sock, response, strlen (response) + 1, 0);
 	} else {
-		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
+		qb_log (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
 		snprintf (response, 100, "%s", NOT_SUPPORTED_STR);
 		send (sock, response, strlen (response), 0);
 	}
@@ -331,7 +330,7 @@ static void do_command (int sock, char* func, char*args[], int num_args)
 
 static void my_pre_exit(void)
 {
-	syslog (LOG_INFO, "PRE EXIT");
+	qb_log (LOG_INFO, "PRE EXIT");
 	if (vq_handle) {
 		votequorum_finalize(vq_handle);
 		vq_handle = 0;
@@ -342,18 +341,9 @@ static void my_pre_exit(void)
 	}
 }
 
-int main (int argc, char *argv[])
+int
+main(int argc, char *argv[])
 {
-	int ret;
-
-	openlog (NULL, LOG_CONS|LOG_PID, LOG_DAEMON);
-	syslog (LOG_INFO, "%s STARTING", __FILE__);
-
 	parse_debug = 1;
-	ret = test_agent_run (9037, do_command, my_pre_exit);
-	syslog (LOG_INFO, "EXITING");
-
-	return ret;
+	return test_agent_run ("quorum_test_agent", 9037, do_command, my_pre_exit);
 }
-
-

Някои файлове не бяха показани, защото твърде много файлове са промени