changeset 26:f700e79e9497 draft

Add loads of debugging CFLAGS so we can remove all compiler warnings
author Roy Marples <roy@marples.name>
date Thu, 14 Dec 2006 23:17:27 +0000
parents 2fb1ab954ee6
children 6b6fb3350708
files Makefile arp.c arp.h client.c common.c configure.c configure.h dhcp.c dhcpcd.8 dhcpcd.c dhcpcd.h interface.c interface.h logger.c signals.c socket.c socket.h
diffstat 17 files changed, 74 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Dec 11 13:16:28 2006 +0000
+++ b/Makefile	Thu Dec 14 23:17:27 2006 +0000
@@ -1,9 +1,15 @@
 # Should work for both GNU make and BSD make
 
-VERSION = 3.0.6
+VERSION = 3.0.7_pre1
 
 INSTALL ?= install
-CFLAGS ?= -Wall -O2 -pedantic -std=gnu99
+CFLAGS = -O2 -pedantic -std=gnu99 \
+    -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  \
+    -Wsequence-point -Wextra
+# -Wdeclaration-after-statement 
 
 DESTDIR =
 SBINDIR = $(DESTDIR)/sbin
--- a/arp.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/arp.c	Thu Dec 14 23:17:27 2006 +0000
@@ -24,10 +24,10 @@
 
 #define _BSD_SOURCE
 
+#include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/select.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <netinet/in_systm.h>
 #ifdef __linux
 #include <netinet/ether.h>
@@ -40,6 +40,7 @@
 #include <unistd.h>
 
 #include "common.h"
+#include "arp.h"
 #include "interface.h"
 #include "logger.h"
 #include "socket.h"
@@ -58,7 +59,7 @@
 #define arphdr_len(ap) (arphdr_len2 ((ap)->ar_hln, (ap)->ar_pln))
 #endif
 
-int arp_check (interface_t *iface, struct in_addr address)
+int arp_check (interface_t *iface, const struct in_addr address)
 {
   if (! iface->arpable)
     {
@@ -138,7 +139,7 @@
 
 	  if (ah->ar_hln != ETHER_ADDR_LEN)
 	    continue;
-	  if (bytes < sizeof (*ah) + 2 * (4 + ah->ar_hln))
+	  if ((unsigned) bytes < sizeof (*ah) + 2 * (4 + ah->ar_hln))
 	    continue;
 
 	  logger (LOG_ERR, "ARPOP_REPLY received from %s (%s)",
--- a/arp.h	Mon Dec 11 13:16:28 2006 +0000
+++ b/arp.h	Thu Dec 14 23:17:27 2006 +0000
@@ -24,6 +24,6 @@
 
 #include "interface.h"
 
-int arp_check (interface_t *iface, struct in_addr address);
+int arp_check (interface_t *iface, const struct in_addr address);
 
 #endif
--- a/client.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/client.c	Thu Dec 14 23:17:27 2006 +0000
@@ -34,8 +34,9 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "common.h"
 #include "arp.h"
-#include "common.h"
+#include "client.h"
 #include "configure.h"
 #include "dhcp.h"
 #include "dhcpcd.h"
@@ -94,7 +95,7 @@
   return 0;
 }
 
-unsigned long random_xid (void)
+static unsigned long random_xid (void)
 {
   static int initialized;
 
@@ -174,7 +175,7 @@
       if (timeout > 0 || (options->timeout == 0 &&
 			  (state != STATE_INIT || xid)))
 	{
-	  if (options->timeout == 0 || dhcp->leasetime == -1)
+	  if (options->timeout == 0 || dhcp->leasetime == (unsigned) -1)
 	    {
 	      logger (LOG_DEBUG, "waiting on select for infinity");
 	      maxfd = signal_fd_set (&rset, iface->fd);
@@ -507,7 +508,7 @@
 			      dhcp->rebindtime);
 		    }
 
-		  if (dhcp->leasetime == -1)
+		  if (dhcp->leasetime == (unsigned) -1)
 		    logger (LOG_INFO, "leased %s for infinity",
 			    inet_ntoa (dhcp->address));
 		  else
--- a/common.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/common.c	Thu Dec 14 23:17:27 2006 +0000
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "common.h"
 #include "logger.h"
 
 /* This requires us to link to rt on glibc, so we use sysinfo instead */
--- a/configure.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/configure.c	Thu Dec 14 23:17:27 2006 +0000
@@ -26,10 +26,10 @@
 
 #include <arpa/inet.h>
 
+#include <netinet/in.h>
 #ifdef __linux__
 #include <netinet/ether.h>
 #endif
-#include <netinet/in.h>
 #include <string.h>
 #include <errno.h>
 #include <netdb.h>
@@ -38,6 +38,7 @@
 #include <unistd.h>
 
 #include "common.h"
+#include "configure.h"
 #include "dhcp.h"
 #include "interface.h"
 #include "dhcpcd.h"
@@ -48,7 +49,7 @@
 static char *cleanmetas (char *cstr)
 {
   if (! cstr)
-    return "";
+    return NULL;
   
   register char *c = cstr;
 
@@ -60,7 +61,8 @@
   return cstr;
 }
 
-void exec_script (char *script, char *infofile, char *arg)
+static void exec_script (const char *script, const char *infofile,
+			 const char *arg)
 {
   if (! script || ! infofile || ! arg)
     return;
@@ -73,12 +75,8 @@
       return;
     }
   
-  char *argc[4];
-
-  argc[0] = script;
-  argc[1] = infofile;
-  argc[2] = arg;
-  argc[3] = NULL;
+  char *const argc[4] =
+    { (char *) script, (char *) infofile, (char *) arg, NULL };
   logger (LOG_DEBUG, "exec \"%s %s %s\"", script, infofile, arg);
   
   /* We don't wait for the user script to finish - do we trust it? */
@@ -96,7 +94,7 @@
     logger (LOG_ERR, "fork: %s", strerror (errno));
 }
 
-static int make_resolv (char *ifname, dhcp_t *dhcp)
+static int make_resolv (const char *ifname, const dhcp_t *dhcp)
 {
   FILE *f;
   struct stat buf;
@@ -144,7 +142,7 @@
   return 0;
 }
 
-static void restore_resolv(char *ifname)
+static void restore_resolv(const char *ifname)
 {
   struct stat buf;
 
@@ -153,12 +151,7 @@
 
   logger (LOG_DEBUG, "removing information from resolvconf");
 
-  char *argc[4];
-
-  argc[0] = RESOLVCONF;
-  argc[1] = "-d";
-  argc[2] = ifname;
-  argc[3] = NULL;
+  char *const argc[4] = { (char *) RESOLVCONF, (char *) "-d", (char *) ifname, NULL };
 
   /* Don't wait around here as we should only be called when
      dhcpcd is closing down and something may do a kill -9
@@ -177,7 +170,7 @@
     logger (LOG_ERR, "fork: %s", strerror (errno));
 }
 
-static int make_ntp (char *ifname, dhcp_t *dhcp)
+static int make_ntp (const char *ifname, const dhcp_t *dhcp)
 {
   FILE *f;
   address_t *address;
@@ -206,7 +199,7 @@
   return 0;
 }
 
-static int make_nis (char *ifname, dhcp_t *dhcp)
+static int make_nis (const char *ifname, const dhcp_t *dhcp)
 {
   FILE *f;
   address_t *address;
@@ -240,7 +233,7 @@
   return 0;
 }
 
-static int write_info(interface_t *iface, dhcp_t *dhcp)
+static int write_info(const interface_t *iface, const dhcp_t *dhcp)
 {
   FILE *f;
   route_t *route;
@@ -346,7 +339,8 @@
   return 0;
 }
 
-int configure (options_t *options, interface_t *iface, dhcp_t *dhcp)
+int configure (const options_t *options, interface_t *iface,
+	       const dhcp_t *dhcp)
 {
   route_t *route = NULL;
   route_t *new_route = NULL;
--- a/configure.h	Mon Dec 11 13:16:28 2006 +0000
+++ b/configure.h	Thu Dec 14 23:17:27 2006 +0000
@@ -26,6 +26,7 @@
 #include "interface.h"
 #include "dhcp.h"
 
-int configure (options_t *options, interface_t *iface, dhcp_t *dhcp);
+int configure (const options_t *options, interface_t *iface,
+	       const dhcp_t *dhcp);
 
 #endif
--- a/dhcp.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/dhcp.c	Thu Dec 14 23:17:27 2006 +0000
@@ -19,8 +19,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 
 #include <netinet/in.h>
 #include <net/if_arp.h>
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include "common.h"
+#include "dhcpcd.h"
 #include "dhcp.h"
 #include "interface.h"
 #include "logger.h"
@@ -39,7 +40,7 @@
 
 #define BROADCAST_FLAG 0x8000
 
-static char *dhcp_message[] = {
+static const char *dhcp_message[] = {
   [DHCP_DISCOVER] 	= "DHCP_DISCOVER",
   [DHCP_OFFER]		= "DHCP_OFFER",
   [DHCP_REQUEST]	= "DHCP_REQUEST",
--- a/dhcpcd.8	Mon Dec 11 13:16:28 2006 +0000
+++ b/dhcpcd.8	Thu Dec 14 23:17:27 2006 +0000
@@ -1,6 +1,6 @@
 .\" $Id$
 .\"
-.TH dhcpcd 8 "06 December 2006" "dhcpcd 3.0"
+.TH DHCPCD 8 "06 December 2006" "dhcpcd 3.0"
 
 .SH NAME
 dhcpcd \- DHCP client daemon
--- a/dhcpcd.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/dhcpcd.c	Thu Dec 14 23:17:27 2006 +0000
@@ -110,7 +110,7 @@
   openlog (PACKAGE, LOG_PID, LOG_LOCAL0);
 
   memset (&options, 0, sizeof (options_t));
-  options.script = DEFAULT_SCRIPT;
+  options.script = (char *) DEFAULT_SCRIPT;
   snprintf (options.classid, CLASS_ID_MAX_LEN, "%s %s", PACKAGE, VERSION); 
 
   options.doarp = false;
--- a/dhcpcd.h	Mon Dec 11 13:16:28 2006 +0000
+++ b/dhcpcd.h	Thu Dec 14 23:17:27 2006 +0000
@@ -20,10 +20,8 @@
 #ifndef DHCPCD_H
 #define DHCPCD_H
 
+#include <sys/param.h>
 #include <sys/socket.h>
-#ifdef __linux__
-#include <linux/limits.h>
-#endif
 #include <net/if.h>
 #include <netinet/in.h>
 #include <limits.h>
--- a/interface.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/interface.c	Thu Dec 14 23:17:27 2006 +0000
@@ -148,9 +148,11 @@
     }
 
 #ifdef __linux__
+  /* Do something with the metric parameter to satisfy the compiler warning */
+  metric = 0;
   if (ioctl (s, SIOCGIFHWADDR, &ifr) <0)
     {
-      logger (LOG_ERR, "ioctl SIOCGIFHWADDR: %s", strerror(errno));
+      logger (LOG_ERR, "ioctl SIOCGIFHWADDR: %s", strerror (errno));
       close (s);
       return NULL;
     }
@@ -262,6 +264,9 @@
   if (! ifname)
     return -1;
 
+  /* Do something with metric to satisfy compiler warnings */
+  metric = 0;
+
   char *destd = strdup (inet_ntoa (destination));
   char *gend = strdup (inet_ntoa (netmask));
   logger (LOG_INFO, "%s route to %s (%s) via %s",
@@ -344,7 +349,7 @@
       return -1;
     }
 
-  int mypid = getpid ();
+  pid_t mypid = getpid ();
   struct sockaddr_nl nl;
   memset (&nl, 0, sizeof (struct sockaddr_nl));
   nl.nl_family = AF_NETLINK;
@@ -369,7 +374,7 @@
 
   /* Request a reply */
   hdr->nlmsg_flags |= NLM_F_ACK;
-  static int seq;
+  static unsigned int seq;
   hdr->nlmsg_seq = ++seq;
 
   if (sendmsg (s, &msg, 0) < 0)
@@ -408,7 +413,7 @@
 	  goto eexit;
 	}
 
-      for (h = (struct nlmsghdr *) buffer; bytes >= sizeof (*h); )
+      for (h = (struct nlmsghdr *) buffer; bytes >= (signed) sizeof (*h); )
 	{
 	  int len = h->nlmsg_len;
 	  int l = len - sizeof (*h);
@@ -423,7 +428,7 @@
 	    }
 
 	  if (nl.nl_pid != 0 ||
-	      h->nlmsg_pid != mypid ||
+	      (pid_t) h->nlmsg_pid != mypid ||
 	      h->nlmsg_seq != seq)
 	    /* Message isn't for us, so skip it */
 	    goto next;
@@ -432,7 +437,7 @@
 	  if (h->nlmsg_type == NLMSG_ERROR)
 	    {
 	      struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h);
-	      if (l < sizeof (struct nlmsgerr))
+	      if ((unsigned) l < sizeof (struct nlmsgerr))
 		logger (LOG_ERR, "truncated error message");
 	      else
 		{
@@ -477,7 +482,7 @@
 #define NLMSG_TAIL(nmsg) \
  ((struct rtattr *) (((unsigned char *) (nmsg)) \
 		     + NLMSG_ALIGN((nmsg)->nlmsg_len)))
-static int add_attr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
+static int add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type, const void *data,
 		      int alen)
 {
   int len = RTA_LENGTH(alen);
@@ -498,7 +503,7 @@
   return 0;
 }
 
-static int add_attr_32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
+static int add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type, uint32_t data)
 {
   int len = RTA_LENGTH (sizeof (uint32_t));
   struct rtattr *rta;
--- a/interface.h	Mon Dec 11 13:16:28 2006 +0000
+++ b/interface.h	Thu Dec 14 23:17:27 2006 +0000
@@ -23,10 +23,11 @@
 #define INTERFACE_H
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <net/if.h>
+#include <netinet/in.h>
 #include <netinet/if_ether.h>
-#include <netinet/in.h>
 #include <limits.h>
 #include <stdbool.h>
 
--- a/logger.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/logger.c	Thu Dec 14 23:17:27 2006 +0000
@@ -31,7 +31,7 @@
 static int loglevel = LOG_WARNING;
 static char logprefix[12] = {0};
 
-static char *syslog_level_msg[] = {
+static const char *syslog_level_msg[] = {
   [LOG_EMERG]   	= "EMERGENCY!",
   [LOG_ALERT]   	= "ALERT!",
   [LOG_CRIT]    	= "Critical!",
@@ -42,7 +42,7 @@
   [LOG_DEBUG + 1]	= NULL
 };
 
-static char *syslog_level[] = {
+static const char *syslog_level[] = {
   [LOG_EMERG]   	= "LOG_EMERG",
   [LOG_ALERT]   	= "LOG_ALERT",
   [LOG_CRIT]    	= "LOG_CRIT",
@@ -99,10 +99,10 @@
     {
       int len = strlen (logprefix);
       char *fmt2 = xmalloc (strlen (fmt) + len + 1);
-      char *p = fmt2;
-      memcpy (p, logprefix, len);
-      p += len;
-      strcpy (p, fmt);
+      char *pf = fmt2;
+      memcpy (pf, logprefix, len);
+      pf += len;
+      strcpy (pf, fmt);
       vsyslog (level, fmt2, p2);
       free (fmt2);
     }
--- a/signals.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/signals.c	Thu Dec 14 23:17:27 2006 +0000
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include "logger.h"
+#include "signals.h"
 
 static int signal_pipe[2];
 
--- a/socket.c	Mon Dec 11 13:16:28 2006 +0000
+++ b/socket.c	Thu Dec 14 23:17:27 2006 +0000
@@ -22,9 +22,9 @@
 /* We use BSD structure so our code is more portable */
 #define _BSD_SOURCE
 
+#include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <sys/uio.h>
 #include <arpa/inet.h>
 #include <netinet/in_systm.h>
@@ -43,6 +43,7 @@
 #include "dhcp.h"
 #include "interface.h"
 #include "logger.h"
+#include "socket.h"
 
 /* A suitably large buffer for all transactions.
    BPF buffer size is set by the kernel, so no define. */
@@ -76,7 +77,7 @@
 }
 
 void make_dhcp_packet(struct udp_dhcp_packet *packet,
-		      unsigned char *data, unsigned int length,
+		      unsigned char *data, int length,
 		      struct in_addr source, struct in_addr dest)
 {
   struct ip *ip = &packet->ip;
@@ -293,8 +294,7 @@
   return fd;
 }
 
-int send_packet (interface_t *iface, int type, unsigned char *data,
-		 unsigned int len)
+int send_packet (interface_t *iface, int type, unsigned char *data, int len)
 {
   /* We only support ethernet atm */
   struct ether_header hw;
@@ -348,7 +348,8 @@
   while (packet)
     {
       /* Ensure that the entire packet is in our buffer */
-      if (*buffer_pos + packet->bh_hdrlen + packet->bh_caplen > *buffer_len)
+      if (*buffer_pos + packet->bh_hdrlen + packet->bh_caplen
+          > (unsigned) *buffer_len)
         break;
 
       hw = (struct ether_header *) ((char *) packet + packet->bh_hdrlen);
@@ -464,7 +465,7 @@
 
 /* Linux has no need for the buffer as we can read as much as we want.
    We only have the buffer listed to keep the same API. */
-size_t get_packet (interface_t *iface, unsigned char *data,
+int get_packet (interface_t *iface, unsigned char *data,
 		   unsigned char *buffer, int *buffer_len, int *buffer_pos)
 {
   long bytes;
@@ -492,7 +493,7 @@
       return bytes;
     }
 
-  if (bytes < (sizeof (struct ip) + sizeof (struct udphdr)))
+  if ((unsigned) bytes < (sizeof (struct ip) + sizeof (struct udphdr)))
     {
       logger (LOG_DEBUG, "message too short, ignoring");
       return -1;
--- a/socket.h	Mon Dec 11 13:16:28 2006 +0000
+++ b/socket.h	Thu Dec 14 23:17:27 2006 +0000
@@ -29,11 +29,11 @@
 #include "interface.h"
 
 void make_dhcp_packet(struct udp_dhcp_packet *packet,
-		      unsigned char *data, unsigned int length,
+		      unsigned char *data, int length,
 		      struct in_addr source, struct in_addr dest);
 
 int open_socket (interface_t *iface, bool arp);
-int send_packet (interface_t *iface, int type, unsigned char *data, unsigned int len);
+int send_packet (interface_t *iface, int type, unsigned char *data, int len);
 int get_packet (interface_t *iface, unsigned char *data,
 		unsigned char *buffer, int *buffer_len, int *buffer_pos);
 #endif