Pārlūkot izejas kodu

socket_info.c: logging: convert LOG to LM_*

Ovidiu Sas 11 gadi atpakaļ
vecāks
revīzija
3478802ca2
1 mainītis faili ar 40 papildinājumiem un 52 dzēšanām
  1. 40 52
      socket_info.c

+ 40 - 52
socket_info.c

@@ -159,7 +159,7 @@ static int init_addr_info(struct addr_info* a,
 	a->flags=flags;
 	return 0;
 error:
-	LOG(L_ERR, "ERROR: init_addr_info: memory allocation error\n");
+	LM_ERR("memory allocation error\n");
 	return -1;
 }
 
@@ -178,7 +178,7 @@ static inline struct addr_info* new_addr_info(char* name,
 	if (init_addr_info(al, name, gf)!=0) goto error;
 	return al;
 error:
-	LOG(L_ERR, "ERROR: new_addr_info: memory allocation error\n");
+	LM_ERR("memory allocation error\n");
 	if (al){
 		if (al->name.s) pkg_free(al->name.s);
 		pkg_free(al);
@@ -260,7 +260,7 @@ static inline struct socket_info* new_sock_info(	char* name,
 	si->addr_info_lst=0;
 	for (n=addr_l; n; n=n->next){
 		if (new_addr_info2list(n->name, n->flags, &si->addr_info_lst)!=0){
-			LOG(L_ERR, "ERROR: new_sockk_info:new_addr_info2list failed\n");
+			LM_ERR("new_addr_info2list failed\n");
 			goto error;
 		}
 	}
@@ -296,14 +296,14 @@ static inline struct socket_info* new_sock_info(	char* name,
 
 		he=resolvehost(si->useinfo.name.s);
 		if (he==0){
-			LM_ERR(" unable to resolve advertised name %s\n", si->useinfo.name.s);
+			LM_ERR("unable to resolve advertised name %s\n", si->useinfo.name.s);
 			goto error;
 		}
 		hostent2ip_addr(&si->useinfo.address, he, 0);
 	}
 	return si;
 error:
-	LOG(L_ERR, "ERROR: new_sock_info: memory allocation error\n");
+	LM_ERR("memory allocation error\n");
 	if (si) {
 		if(si->name.s)
 			pkg_free(si->name.s);
@@ -437,7 +437,7 @@ static int fix_sock_str(struct socket_info* si)
 	
 	si->sock_str.s = pkg_malloc(len + 1);
 	if (si->sock_str.s == NULL) {
-		ERR("fix_sock_str: No memory left\n");
+		LM_ERR("No memory left\n");
 		return -1;
 	}
 	if (socketinfo2str(si->sock_str.s, &len, si, 0) < 0) {
@@ -454,7 +454,7 @@ static int fix_sock_str(struct socket_info* si)
 
 		si->useinfo.sock_str.s = pkg_malloc(len + 1);
 		if (si->useinfo.sock_str.s == NULL) {
-			ERR("fix_sock_str: No memory left\n");
+			LM_ERR("No memory left\n");
 			return -1;
 		}
 		if (socketinfo2str(si->useinfo.sock_str.s, &len, si, 1) < 0) {
@@ -495,7 +495,7 @@ struct socket_info** get_sock_info_list(unsigned short proto)
 #endif
 			break;
 		default:
-			LOG(L_CRIT, "BUG: get_sock_info_list: invalid proto %d\n", proto);
+			LM_CRIT("invalid proto %d\n", proto);
 	}
 	return 0;
 }
@@ -726,7 +726,7 @@ static struct socket_info* new_sock2list(char* name, struct name_lst* addr_l,
 	
 	si=new_sock_info(name, addr_l, port, proto, usename, useport, flags);
 	if (si==0){
-		LOG(L_ERR, "ERROR: new_sock2list: new_sock_info failed\n");
+		LM_ERR("new_sock_info failed\n");
 		goto error;
 	}
 	if(socket_workers>0) {
@@ -756,7 +756,7 @@ static struct socket_info* new_sock2list_after(char* name,
 	
 	si=new_sock_info(name, addr_l, port, proto, usename, useport, flags);
 	if (si==0){
-		LOG(L_ERR, "ERROR: new_sock2list_after: new_sock_info failed\n");
+		LM_ERR("new_sock_info failed\n");
 		goto error;
 	}
 	sock_listins(si, after);
@@ -804,7 +804,7 @@ int add_listen_advertise_iface(char* name, struct name_lst* addr_l,
 		if (c_proto!=PROTO_SCTP){
 			if (new_sock2list(name, 0, c_port, c_proto, usename, useport,
 								flags & ~SI_IS_MHOMED, list)==0){
-				LOG(L_ERR, "ERROR: add_listen_iface: new_sock2list failed\n");
+				LM_ERR("new_sock2list failed\n");
 				goto error;
 			}
 			/* add the other addresses in the list as separate sockets
@@ -813,15 +813,14 @@ int add_listen_advertise_iface(char* name, struct name_lst* addr_l,
 				if (new_sock2list(a_l->name, 0, c_port, 
 									c_proto, usename, useport,
 									flags & ~SI_IS_MHOMED, list)==0){
-					LOG(L_ERR, "ERROR: add_listen_iface: new_sock2list"
-								" failed\n");
+					LM_ERR("new_sock2list failed\n");
 					goto error;
 				}
 			}
 		}else{
 			if (new_sock2list(name, addr_l, c_port, c_proto, usename, useport,
 						flags, list)==0){
-				LOG(L_ERR, "ERROR: add_listen_iface: new_sock2list failed\n");
+				LM_ERR("new_sock2list failed\n");
 				goto error;
 			}
 		}
@@ -1190,8 +1189,7 @@ int add_interfaces_via_netlink(char* if_name, int family, unsigned short port,
 					}
 					/* save the info */
 					if (new_addr_info2list(tmp->addr, flags, ai_l)!=0){
-						LOG(L_ERR, "ERROR: add_interfaces: "
-							"new_addr_info2list failed\n");
+						LM_ERR("new_addr_info2list failed\n");
 						goto error;
 			    		}
 				}
@@ -1241,13 +1239,12 @@ int add_interfaces(char* if_name, int family, unsigned short port,
 		ifc.ifc_len=size*sizeof(struct ifreq);
 		ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));
 		if (ifc.ifc_req==0){
-			LOG(L_ERR, "ERROR: add_interfaces: memory allocation failure\n");
+			LM_ERR("memory allocation failure\n");
 			goto error;
 		}
 		if (ioctl(s, SIOCGIFCONF, &ifc)==-1){
 			if(errno==EBADF) return 0; /* invalid descriptor => no such ifs*/
-			LOG(L_ERR, "ERROR: add_interfaces: ioctl failed: %s\n",
-					strerror(errno));
+			LM_ERR("ioctl failed: %s\n", strerror(errno));
 			goto error;
 		}
 		if  ((lastlen) && (ifc.ifc_len==lastlen)) break; /*success,
@@ -1309,8 +1306,7 @@ int add_interfaces(char* if_name, int family, unsigned short port,
 				flags|=SI_IS_LO;
 			/* save the info */
 			if (new_addr_info2list(tmp, flags, ai_l)!=0){
-				LOG(L_ERR, "ERROR: add_interfaces: "
-						"new_addr_info2list failed\n");
+				LM_ERR("new_addr_info2list failed\n");
 				goto error;
 			}
 			ret=0;
@@ -1350,20 +1346,20 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 	/* get "official hostnames", all the aliases etc. */
 	he=resolvehost(name->s);
 	if (he==0){
-		LOG(L_ERR, "ERROR: fix_hostname: could not resolve %s\n", name->s);
+		LM_ERR("could not resolve %s\n", name->s);
 		goto error;
 	}
 	/* check if we got the official name */
 	if (strcasecmp(he->h_name, name->s)!=0){
 		if (sr_auto_aliases && 
 				add_alias(name->s, name->len, s->port_no, s->proto)<0){
-			LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
+			LM_ERR("add_alias failed\n");
 		}
 		/* change the official name */
 		pkg_free(name->s);
 		name->s=(char*)pkg_malloc(strlen(he->h_name)+1);
 		if (name->s==0){
-			LOG(L_ERR,  "ERROR: fix_hostname: out of memory.\n");
+			LM_ERR("out of memory.\n");
 			goto error;
 		}
 		name->len=strlen(he->h_name);
@@ -1372,7 +1368,7 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 	/* add the aliases*/
 	for(h=he->h_aliases; sr_auto_aliases && h && *h; h++)
 		if (add_alias(*h, strlen(*h), s->port_no, s->proto)<0){
-			LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
+			LM_ERR("add_alias failed\n");
 		}
 	hostent2ip_addr(address, he, 0); /*convert to ip_addr format*/
 	if (type_flags){
@@ -1381,7 +1377,7 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 	if ((tmp=ip_addr2a(address))==0) goto error;
 	address_str->s=pkg_malloc(strlen(tmp)+1);
 	if (address_str->s==0){
-		LOG(L_ERR, "ERROR: fix_hostname: out of memory.\n");
+		LM_ERR("out of memory.\n");
 		goto error;
 	}
 	strncpy(address_str->s, tmp, strlen(tmp)+1);
@@ -1393,17 +1389,16 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 		/* do rev. DNS on it (for aliases)*/
 		he=rev_resolvehost(address);
 		if (he==0){
-			LOG(L_WARN, "WARNING: fix_hostname: could not rev. resolve %s\n",
-					name->s);
+			LM_WARN("could not rev. resolve %s\n", name->s);
 		}else{
 			/* add the aliases*/
 			if (add_alias(he->h_name, strlen(he->h_name), s->port_no,
 							s->proto)<0){
-				LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
+				LM_ERR("add_alias failed\n");
 			}
 			for(h=he->h_aliases; h && *h; h++)
 				if (add_alias(*h, strlen(*h), s->port_no, s->proto) < 0){
-					LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
+					LM_ERR("add_alias failed\n");
 				}
 		}
 	}
@@ -1579,13 +1574,12 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
 		}
 		tmp=int2str(si->port_no, &len);
 		if (len>=MAX_PORT_LEN){
-			LOG(L_ERR, "ERROR: fix_socket_list: bad port number: %d\n", 
-						si->port_no);
+			LM_ERR("bad port number: %d\n", si->port_no);
 			goto error;
 		}
 		si->port_no_str.s=(char*)pkg_malloc(len+1);
 		if (si->port_no_str.s==0){
-			LOG(L_ERR, "ERROR: fix_socket_list: out of memory.\n");
+			LM_ERR("out of memory.\n");
 			goto error;
 		}
 		strncpy(si->port_no_str.s, tmp, len+1);
@@ -1772,7 +1766,7 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
 #endif
 			){
 			if (si->flags & SI_IS_MCAST){
-				LOG(L_WARN, "WARNING: removing entry %s:%s [%s]:%s\n",
+				LM_WARN("removing entry %s:%s [%s]:%s\n",
 					get_valid_proto_name(si->proto), si->name.s, 
 					si->address_str.s, si->port_no_str.s);
 				l = si;
@@ -1783,7 +1777,7 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
 				ail=si->addr_info_lst;
 				while(ail){
 					if (ail->flags & SI_IS_MCAST){
-						LOG(L_WARN, "WARNING: removing mh entry %s:%s"
+						LM_WARN("removing mh entry %s:%s"
 								" [%s]:%s\n",
 								get_valid_proto_name(si->proto), ail->name.s, 
 								ail->address_str.s, si->port_no_str.s);
@@ -1892,21 +1886,18 @@ int fix_all_socket_lists()
 			/* if error fall back to get hostname */
 			/* get our address, only the first one */
 			if (uname (&myname) <0){
-				LOG(L_ERR, "ERROR: fix_all_socket_lists: cannot determine"
-						" hostname, try -l address\n");
+				LM_ERR("cannot determine hostname, try -l address\n");
 				goto error;
 			}
 			if (add_listen_iface(myname.nodename, 0, 0, 0, 0)!=0){
-				LOG(L_ERR, "ERROR: fix_all_socket_lists: add_listen_iface "
-						"failed \n");
+				LM_ERR("add_listen_iface failed \n");
 				goto error;
 			}
 		}
 	}
 	flags=0;
 	if (fix_socket_list(&udp_listen, &flags)!=0){
-		LOG(L_ERR, "ERROR: fix_all_socket_lists: fix_socket_list"
-				" udp failed\n");
+		LM_ERR("fix_socket_list udp failed\n");
 		goto error;
 	}
 	if (flags){
@@ -1915,8 +1906,7 @@ int fix_all_socket_lists()
 #ifdef USE_TCP
 	flags=0;
 	if (!tcp_disable && (fix_socket_list(&tcp_listen, &flags)!=0)){
-		LOG(L_ERR, "ERROR: fix_all_socket_lists: fix_socket_list"
-				" tcp failed\n");
+		LM_ERR("fix_socket_list tcp failed\n");
 		goto error;
 	}
 	if (flags){
@@ -1925,8 +1915,7 @@ int fix_all_socket_lists()
 #ifdef USE_TLS
 	flags=0;
 	if (!tls_disable && (fix_socket_list(&tls_listen, &flags)!=0)){
-		LOG(L_ERR, "ERROR: fix_all_socket_lists: fix_socket_list"
-				" tls failed\n");
+		LM_ERR("fix_socket_list tls failed\n");
 		goto error;
 	}
 	if (flags){
@@ -1937,8 +1926,7 @@ int fix_all_socket_lists()
 #ifdef USE_SCTP
 	flags=0;
 	if (!sctp_disable && (fix_socket_list(&sctp_listen, &flags)!=0)){
-		LOG(L_ERR, "ERROR: fix_all_socket_lists: fix_socket_list"
-				" sctp failed\n");
+		LM_ERR("fix_socket_list sctp failed\n");
 		goto error;
 	}
 	if (flags){
@@ -1956,7 +1944,7 @@ int fix_all_socket_lists()
 			&& (sctp_listen==0)
 #endif
 		){
-		LOG(L_ERR, "ERROR: fix_all_socket_lists: no listening sockets\n");
+		LM_ERR("no listening sockets\n");
 		goto error;
 	}
 	return 0;
@@ -2127,16 +2115,16 @@ int parse_protohostport(str* ins, sr_phostp_t *r)
 end:
 	return 0;
 error_brackets:
-	LOG(L_ERR, "too many brackets in %.*s\n", ins->len, ins->s);
+	LM_ERR("too many brackets in %.*s\n", ins->len, ins->s);
 	return -1;
 error_colons:
-	LOG(L_ERR, "too many colons in %.*s\n", ins->len, ins->s);
+	LM_ERR("too many colons in %.*s\n", ins->len, ins->s);
 	return -1;
 error_proto:
-	LOG(L_ERR, "bad protocol in %.*s\n", ins->len, ins->s);
+	LM_ERR("bad protocol in %.*s\n", ins->len, ins->s);
 	return -1;
 error_port:
-	LOG(L_ERR, "bad port number in %.*s\n", ins->len, ins->s);
+	LM_ERR("bad port number in %.*s\n", ins->len, ins->s);
 	return -1;
 }