From: Chuck Lever Date: Fri, 15 Jan 2010 20:14:38 +0000 (-0500) Subject: tcpwrappers: Use xlog() instead of perror(3) and syslog(2) X-Git-Tag: nfs-utils-1-2-2-rc8~5 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=commitdiff_plain;h=e8c917f53741100d6ea710100dca7c914791880b;hp=fb69c9d6320b303acbb7971da9e8f18d32b33e2f tcpwrappers: Use xlog() instead of perror(3) and syslog(2) Clean up: Replace calls to syslog(2) and perror(3) in from_local.c with calls to xlog(). The problems displayed by the perror(3) calls especially should be reported. Currently they are never seen in the system log. As part of a build test, I defined TEST, and found a couple of problems with main(), which are also addressed in this patch. Signed-off-by: Chuck Lever --- diff --git a/support/misc/from_local.c b/support/misc/from_local.c index 89ccc4a..3f46b99 100644 --- a/support/misc/from_local.c +++ b/support/misc/from_local.c @@ -37,8 +37,8 @@ static char sccsid[] = "@(#) from_local.c 1.3 96/05/31 15:52:57"; #endif -#ifdef TEST -#undef perror +#ifdef HAVE_CONFIG_H +#include #endif #include @@ -49,10 +49,12 @@ static char sccsid[] = "@(#) from_local.c 1.3 96/05/31 15:52:57"; #include #include #include -#include #include #include +#include "tcpwrapper.h" +#include "xlog.h" + #ifndef TRUE #define TRUE 1 #define FALSE 0 @@ -81,7 +83,7 @@ static int grow_addrs(void) new_num = (addrs == 0) ? 1 : num_addrs + num_addrs; new_addrs = (struct in_addr *) malloc(sizeof(*addrs) * new_num); if (new_addrs == 0) { - perror("portmap: out of memory"); + xlog_warn("%s: out of memory", __func__); return (0); } else { if (addrs != 0) { @@ -112,13 +114,13 @@ find_local(void) */ if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - perror("socket"); + xlog_warn("%s: socket(2): %m", __func__); return (0); } ifc.ifc_len = sizeof(buf); ifc.ifc_buf = buf; if (ioctl(sock, SIOCGIFCONF, (char *) &ifc) < 0) { - perror("SIOCGIFCONF"); + xlog_warn("%s: ioctl(SIOCGIFCONF): %m", __func__); (void) close(sock); return (0); } @@ -130,10 +132,10 @@ find_local(void) if (ifr->ifr_addr.sa_family == AF_INET) { /* IP net interface */ ifreq = *ifr; if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifreq) < 0) { - perror("SIOCGIFFLAGS"); + xlog_warn("%s: ioctl(SIOCGIFFLAGS): %m", __func__); } else if (ifreq.ifr_flags & IFF_UP) { /* active interface */ if (ioctl(sock, SIOCGIFADDR, (char *) &ifreq) < 0) { - perror("SIOCGIFADDR"); + xlog_warn("%s: ioctl(SIOCGIFADDR): %m", __func__); } else { if (num_local >= num_addrs) if (grow_addrs() == 0) @@ -160,7 +162,7 @@ from_local(struct sockaddr_in *addr) int i; if (addrs == 0 && find_local() == 0) - syslog(LOG_ERR, "cannot find any active local network interfaces"); + xlog(L_ERROR, "Cannot find any active local network interfaces"); for (i = 0; i < num_local; i++) { if (memcmp((char *) &(addr->sin_addr), (char *) &(addrs[i]), @@ -172,9 +174,8 @@ from_local(struct sockaddr_in *addr) #ifdef TEST -main() +int main(void) { - char *inet_ntoa(); int i; find_local(); @@ -182,4 +183,4 @@ main() printf("%s\n", inet_ntoa(addrs[i])); } -#endif +#endif /* TEST */