Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] cleaning ifwatchd



Hi List

When using plently of gcc warning flags I had these errors when
compiling ifwatchd from -current.

#   compile  ifwatchd/ifwatchd.o
cc -Os -march=pentium-m -pedantic -Wall -Wunused -Wimplicit -Wshadow
-Wformat=2 -Wmissing-declarations -Wno-missing-prototypes
-Wwrite-strings -Wbad-function-cast -Wnested-externs -Wcomment -Winline
-Wchar-subscripts -Wcast-align -Wno-format-nonliteral
-Wdeclaration-after-statement -Wsequence-point -Wextra  -Wall
-Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
-Wno-sign-compare -Wno-traditional  -Werror      -c    ifwatchd.c
cc1: warnings being treated as errors
ifwatchd.c: In function 'main':
ifwatchd.c:206: warning: ISO C does not support the '%m' printf format
ifwatchd.c: In function 'usage':
ifwatchd.c:249: warning: string length '804' is greater than the length
'509' ISO C89 compilers are required to support
ifwatchd.c: In function 'dispatch':
ifwatchd.c:254: warning: unused parameter 'len'
ifwatchd.c: In function 'invoke_script':
ifwatchd.c:398: warning: ISO C does not support the '%m' printf format
ifwatchd.c: In function 'find_interface':
ifwatchd.c:527: warning: declaration of 'index' shadows a global
declaration
/usr/include/strings.h:54: warning: shadowed declaration is here
ifwatchd.c: In function 'check_is_connected':
ifwatchd.c:605: warning: declaration of 'err' shadows a global
declaration
/usr/include/err.h:49: warning: shadowed declaration is here
*** Error code 1

Stop.
make: stopped in /usr/src/usr.sbin/ifwatchd

The attached patch cleans up all these.
Hunks #5 and #6 deal with a subsequent error of vfork potentially
clobbering the ifname variable.

Thanks

Roy
Index: ifwatchd.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/ifwatchd/ifwatchd.c,v
retrieving revision 1.23
diff -u -p -r1.23 ifwatchd.c
--- ifwatchd.c  24 May 2008 17:45:14 -0000      1.23
+++ ifwatchd.c  5 Sep 2008 08:37:10 -0000
@@ -50,6 +50,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include <errno.h>
 #include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -203,7 +204,8 @@ main(int argc, char **argv)
 
        s = socket(PF_ROUTE, SOCK_RAW, 0);
        if (s < 0) {
-               syslog(LOG_ERR, "error opening routing socket: %m");
+               syslog(LOG_ERR, "error opening routing socket: %s",
+                               strerror(errno));
                perror("open routing socket");
                exit(EXIT_FAILURE);
        }
@@ -239,7 +241,8 @@ usage(void)
            "\t -A <cmd> specify command to run on interface arrival event\n"
            "\t -c <cmd> specify command to run on interface carrier-detect 
event\n"
            "\t -D <cmd> specify command to run on interface departure event\n"
-           "\t -d <cmd> specify command to run on interface down event\n"
+           "\t -d <cmd> specify command to run on interface down event\n");
+       fprintf(stderr,
            "\t -n <cmd> specify command to run on interface no-carrier-detect 
event\n"
            "\t -h       show this help message\n"
            "\t -i       no (!) initial run of the up script if the interface\n"
@@ -257,6 +260,7 @@ dispatch(void *msg, size_t len)
        struct if_msghdr *ifmp;
        struct ifa_msghdr *ifam;
        enum event ev;
+       len = 1;
 
        switch (hd->rtm_type) {
        case RTM_NEWADDR:
@@ -337,8 +341,7 @@ static void
 invoke_script(struct sockaddr *sa, struct sockaddr *dest, enum event ev,
     int ifindex, const char *ifname_hint)
 {
-       char addr[NI_MAXHOST], daddr[NI_MAXHOST], ifname_buf[IFNAMSIZ];
-       const char *ifname;
+       char addr[NI_MAXHOST], daddr[NI_MAXHOST], ifname[IFNAMSIZ];
        const char *script;
        int status;
 
@@ -354,11 +357,13 @@ invoke_script(struct sockaddr *sa, struc
                        return;
        }
 
-       addr[0] = daddr[0] = 0;
-       ifname = if_indextoname(ifindex, ifname_buf);
-       ifname = ifname ? ifname : ifname_hint;
-       if (ifname == NULL)
-               return;
+       addr[0] = daddr[0] = ifname[0] = 0;
+       if (if_indextoname(ifindex, ifname) == NULL) {
+               if (ifname_hint)
+                       strlcpy(ifname, ifname_hint, sizeof(ifname));
+               else
+                       return;
+       }
 
        if (sa != NULL) {
                if (getnameinfo(sa, sa->sa_len, addr, sizeof addr, NULL, 0,
@@ -394,8 +399,8 @@ invoke_script(struct sockaddr *sa, struc
        case 0:
                if (execl(script, script, ifname, DummyTTY, DummySpeed,
                    addr, daddr, NULL) == -1) {
-                       syslog(LOG_ERR, "could not execute \"%s\": %m",
-                           script);
+                       syslog(LOG_ERR, "could not execute \"%s\": %s",
+                           script, strerror(errno));
                        perror(script);
                }
                _exit(EXIT_FAILURE);
@@ -524,12 +529,12 @@ free_interfaces(void)
 }
 
 static int
-find_interface(int index)
+find_interface(int idx)
 {
        struct interface_data * p;
 
        SLIST_FOREACH(p, &ifs, next)
-               if (p->index == index)
+               if (p->index == idx)
                        return 1;
        return 0;
 }
@@ -602,7 +607,7 @@ out:
 static int
 check_is_connected(const char *ifname, int def_retval)
 {
-       int s, err;
+       int s, errn;
        struct spppstatus oldstatus;
        struct spppstatusncp status;
 
@@ -614,10 +619,10 @@ check_is_connected(const char *ifname, i
        s = socket(AF_INET, SOCK_DGRAM, 0);
        if (s < 0)
                return 1;       /* no idea how to handle this... */
-       err = ioctl(s, SPPPGETSTATUSNCP, &status);
-       if (err != 0) {
-               err = ioctl(s, SPPPGETSTATUS, &oldstatus);
-               if (err != 0) {
+       errn = ioctl(s, SPPPGETSTATUSNCP, &status);
+       if (errn != 0) {
+               errn = ioctl(s, SPPPGETSTATUS, &oldstatus);
+               if (errn != 0) {
                        /* not if_spppsubr.c based - return default */
                        close(s);
                        return def_retval;


Home | Main Index | Thread Index | Old Index