]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
tcpwrappers: Use xlog() instead of perror(3) and syslog(2)
authorChuck Lever <chuck.lever@oracle.com>
Fri, 15 Jan 2010 20:14:38 +0000 (15:14 -0500)
committerSteve Dickson <steved@redhat.com>
Sun, 17 Jan 2010 21:44:59 +0000 (16:44 -0500)
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 <chuck.lever@oracle.com>
support/misc/from_local.c

index 89ccc4aca8644385980595966365120815518cff..3f46b998742b5be9e60979351c50840ed6b32cec 100644 (file)
@@ -37,8 +37,8 @@
 static char sccsid[] = "@(#) from_local.c 1.3 96/05/31 15:52:57";
 #endif
 
 static char sccsid[] = "@(#) from_local.c 1.3 96/05/31 15:52:57";
 #endif
 
-#ifdef TEST
-#undef perror
+#ifdef HAVE_CONFIG_H
+#include <config.h>
 #endif
 
 #include <sys/types.h>
 #endif
 
 #include <sys/types.h>
@@ -49,10 +49,12 @@ static char sccsid[] = "@(#) from_local.c 1.3 96/05/31 15:52:57";
 #include <netinet/in.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
-#include <syslog.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include <stdlib.h>
 #include <string.h>
 
+#include "tcpwrapper.h"
+#include "xlog.h"
+
 #ifndef TRUE
 #define        TRUE    1
 #define FALSE  0
 #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) {
     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) {
        return (0);
     } else {
        if (addrs != 0) {
@@ -112,13 +114,13 @@ find_local(void)
      */
 
     if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
      */
 
     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) {
        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);
     }
        (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) {
        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) {
            } 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)
                } 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)
     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]),
 
     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
 
 
 #ifdef TEST
 
-main()
+int main(void)
 {
 {
-    char   *inet_ntoa();
     int     i;
 
     find_local();
     int     i;
 
     find_local();
@@ -182,4 +183,4 @@ main()
        printf("%s\n", inet_ntoa(addrs[i]));
 }
 
        printf("%s\n", inet_ntoa(addrs[i]));
 }
 
-#endif
+#endif /* TEST */