Răsfoiți Sursa

totemip: Add debug information to totemip_parse

It's required to create TOTEM logsys subsys before totemip_parse is used
(so before totem_config_read). Logsys is not yet fully initialized, but
it's good enough.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 7 ani în urmă
părinte
comite
aa7daf8c77
2 a modificat fișierele cu 25 adăugiri și 4 ștergeri
  1. 9 3
      exec/main.c
  2. 16 1
      exec/totemip.c

+ 9 - 3
exec/main.c

@@ -1220,6 +1220,7 @@ int main (int argc, char **argv, char **envp)
 	long int tmpli;
 	long int tmpli;
 	char *ep;
 	char *ep;
 	char *tmp_str;
 	char *tmp_str;
+	int log_subsys_id_totem;
 
 
 	/* default configuration
 	/* default configuration
 	 */
 	 */
@@ -1323,6 +1324,13 @@ int main (int argc, char **argv, char **envp)
 		log_printf (LOGSYS_LEVEL_INFO, "Corosync built-in features:" PACKAGE_FEATURES "");
 		log_printf (LOGSYS_LEVEL_INFO, "Corosync built-in features:" PACKAGE_FEATURES "");
 	}
 	}
 
 
+	/*
+	 * Create totem logsys subsys before totem_config_read so log functions can be used
+	 */
+	log_subsys_id_totem = _logsys_subsys_create("TOTEM", "totem,"
+			"totemip.c,totemconfig.c,totemcrypto.c,totemsrp.c,"
+			"totempg.c,totemudp.c,totemudpu.c,totemnet.c,totemknet.c");
+
 	/*
 	/*
 	 * Make sure required directory is present
 	 * Make sure required directory is present
 	 */
 	 */
@@ -1452,9 +1460,7 @@ int main (int argc, char **argv, char **envp)
 	totem_config.totem_memb_ring_id_store = corosync_ring_id_store;
 	totem_config.totem_memb_ring_id_store = corosync_ring_id_store;
 
 
 	totem_config.totem_logging_configuration = totem_logging_configuration;
 	totem_config.totem_logging_configuration = totem_logging_configuration;
-	totem_config.totem_logging_configuration.log_subsys_id = _logsys_subsys_create("TOTEM", "totem,"
-			"totemip.c,totemconfig.c,totemcrypto.c,totemsrp.c,"
-			"totempg.c,totemudp.c,totemudpu.c,totemnet.c,totemknet.c");
+	totem_config.totem_logging_configuration.log_subsys_id = log_subsys_id_totem;
 
 
 	totem_config.totem_logging_configuration.log_level_security = LOGSYS_LEVEL_WARNING;
 	totem_config.totem_logging_configuration.log_level_security = LOGSYS_LEVEL_WARNING;
 	totem_config.totem_logging_configuration.log_level_error = LOGSYS_LEVEL_ERROR;
 	totem_config.totem_logging_configuration.log_level_error = LOGSYS_LEVEL_ERROR;

+ 16 - 1
exec/totemip.c

@@ -52,6 +52,7 @@
 #include <ifaddrs.h>
 #include <ifaddrs.h>
 
 
 #include <corosync/totem/totemip.h>
 #include <corosync/totem/totemip.h>
+#include <corosync/logsys.h>
 #include <corosync/swab.h>
 #include <corosync/swab.h>
 
 
 #define LOCALHOST_IPV4 "127.0.0.1"
 #define LOCALHOST_IPV4 "127.0.0.1"
@@ -289,6 +290,7 @@ int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family
 	struct sockaddr_in *sa;
 	struct sockaddr_in *sa;
 	struct sockaddr_in6 *sa6;
 	struct sockaddr_in6 *sa6;
 	int ret;
 	int ret;
+	int debug_ip_family;
 
 
 	memset(&ahints, 0, sizeof(ahints));
 	memset(&ahints, 0, sizeof(ahints));
 	ahints.ai_socktype = SOCK_DGRAM;
 	ahints.ai_socktype = SOCK_DGRAM;
@@ -306,8 +308,18 @@ int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family
 	} else {
 	} else {
 		ret = getaddrinfo(addr, NULL, &ahints, &ainfo);
 		ret = getaddrinfo(addr, NULL, &ahints, &ainfo);
 	}
 	}
-	if (ret)
+
+	debug_ip_family = 4;
+	if (ahints.ai_family == AF_INET6) {
+		debug_ip_family = 6;
+	}
+
+	if (ret) {
+		log_printf (LOGSYS_LEVEL_DEBUG, "totemip_parse: IPv%u address of %s not resolvable",
+		    debug_ip_family, addr);
+
 		return -1;
 		return -1;
+	}
 
 
 	sa = (struct sockaddr_in *)ainfo->ai_addr;
 	sa = (struct sockaddr_in *)ainfo->ai_addr;
 	sa6 = (struct sockaddr_in6 *)ainfo->ai_addr;
 	sa6 = (struct sockaddr_in6 *)ainfo->ai_addr;
@@ -318,6 +330,9 @@ int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family
 	else
 	else
 		memcpy(totemip->addr, &sa6->sin6_addr, sizeof(struct in6_addr));
 		memcpy(totemip->addr, &sa6->sin6_addr, sizeof(struct in6_addr));
 
 
+	log_printf (LOGSYS_LEVEL_DEBUG, "totemip_parse: IPv%u address of %s resolved as %s",
+		    debug_ip_family, addr, totemip_print(totemip));
+
 	freeaddrinfo(ainfo);
 	freeaddrinfo(ainfo);
 	return 0;
 	return 0;
 }
 }