From: Roy Marples Date: Thu, 14 Dec 2006 23:17:27 +0000 (+0000) Subject: Add loads of debugging CFLAGS so we can remove all compiler warnings X-Git-Tag: v3.2.3~348 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=262fe7db607e2fe9b7a20d8b8b32760fe4b0d32f;p=thirdparty%2Fdhcpcd.git Add loads of debugging CFLAGS so we can remove all compiler warnings --- diff --git a/Makefile b/Makefile index 0a2cc47f..e856bc42 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/arp.c b/arp.c index 5afa3aed..0cf9ea0d 100644 --- a/arp.c +++ b/arp.c @@ -24,10 +24,10 @@ #define _BSD_SOURCE +#include #include #include #include -#include #include #ifdef __linux #include @@ -40,6 +40,7 @@ #include #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 @@ int arp_check (interface_t *iface, struct in_addr address) 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)", diff --git a/arp.h b/arp.h index 4dfd007d..09822779 100644 --- a/arp.h +++ b/arp.h @@ -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 diff --git a/client.c b/client.c index c84c63d9..7137cea0 100644 --- a/client.c +++ b/client.c @@ -34,8 +34,9 @@ #include #include -#include "arp.h" #include "common.h" +#include "arp.h" +#include "client.h" #include "configure.h" #include "dhcp.h" #include "dhcpcd.h" @@ -94,7 +95,7 @@ static int daemonise (char *pidfile) return 0; } -unsigned long random_xid (void) +static unsigned long random_xid (void) { static int initialized; @@ -174,7 +175,7 @@ int dhcp_run (options_t *options) 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 @@ int dhcp_run (options_t *options) dhcp->rebindtime); } - if (dhcp->leasetime == -1) + if (dhcp->leasetime == (unsigned) -1) logger (LOG_INFO, "leased %s for infinity", inet_ntoa (dhcp->address)); else diff --git a/common.c b/common.c index 9288def4..e1f5f513 100644 --- a/common.c +++ b/common.c @@ -24,6 +24,7 @@ #include #include +#include "common.h" #include "logger.h" /* This requires us to link to rt on glibc, so we use sysinfo instead */ diff --git a/configure.c b/configure.c index 14a4132a..63e0a461 100644 --- a/configure.c +++ b/configure.c @@ -26,10 +26,10 @@ #include +#include #ifdef __linux__ #include #endif -#include #include #include #include @@ -38,6 +38,7 @@ #include #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 @@ static char *cleanmetas (char *cstr) 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 @@ void exec_script (char *script, char *infofile, char *arg) 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 @@ void exec_script (char *script, char *infofile, char *arg) 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 @@ static int make_resolv (char *ifname, dhcp_t *dhcp) return 0; } -static void restore_resolv(char *ifname) +static void restore_resolv(const char *ifname) { struct stat buf; @@ -153,12 +151,7 @@ static void restore_resolv(char *ifname) 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 @@ static void restore_resolv(char *ifname) 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 @@ static int make_ntp (char *ifname, dhcp_t *dhcp) 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 @@ static int make_nis (char *ifname, dhcp_t *dhcp) 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 @@ static int write_info(interface_t *iface, dhcp_t *dhcp) 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; diff --git a/configure.h b/configure.h index ce8514bd..59b7003d 100644 --- a/configure.h +++ b/configure.h @@ -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 diff --git a/dhcp.c b/dhcp.c index 87aa93b1..1f3eb8c3 100644 --- a/dhcp.c +++ b/dhcp.c @@ -19,8 +19,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include +#include #include #include @@ -32,6 +32,7 @@ #include #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", diff --git a/dhcpcd.8 b/dhcpcd.8 index 07aae5c1..a53a18a9 100644 --- a/dhcpcd.8 +++ b/dhcpcd.8 @@ -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 diff --git a/dhcpcd.c b/dhcpcd.c index 150dd818..f46d5903 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) 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; diff --git a/dhcpcd.h b/dhcpcd.h index 13c80d42..6c68d50e 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -20,10 +20,8 @@ #ifndef DHCPCD_H #define DHCPCD_H +#include #include -#ifdef __linux__ -#include -#endif #include #include #include diff --git a/interface.c b/interface.c index 6e5aa276..224ccca0 100644 --- a/interface.c +++ b/interface.c @@ -148,9 +148,11 @@ interface_t *read_interface (const char *ifname, int metric) } #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 @@ static int do_route (const char *ifname, 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 @@ static int send_netlink(struct nlmsghdr *hdr) 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 @@ static int send_netlink(struct nlmsghdr *hdr) /* 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 @@ static int send_netlink(struct nlmsghdr *hdr) 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 @@ static int send_netlink(struct nlmsghdr *hdr) } 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 @@ static int send_netlink(struct nlmsghdr *hdr) 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 @@ eexit: #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 @@ static int add_attr_l(struct nlmsghdr *n, int maxlen, int type, const void *data 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; diff --git a/interface.h b/interface.h index 8b855459..0ba4b892 100644 --- a/interface.h +++ b/interface.h @@ -23,10 +23,11 @@ #define INTERFACE_H #include +#include #include #include -#include #include +#include #include #include diff --git a/logger.c b/logger.c index e2760e10..d9e3700f 100644 --- a/logger.c +++ b/logger.c @@ -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 @@ static char *syslog_level_msg[] = { [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 @@ void logger(int level, const char *fmt, ...) { 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); } diff --git a/signals.c b/signals.c index b565b8d2..9e441e0f 100644 --- a/signals.c +++ b/signals.c @@ -28,6 +28,7 @@ #include #include "logger.h" +#include "signals.h" static int signal_pipe[2]; diff --git a/socket.c b/socket.c index fb5864d3..d789638a 100644 --- a/socket.c +++ b/socket.c @@ -22,9 +22,9 @@ /* We use BSD structure so our code is more portable */ #define _BSD_SOURCE +#include #include #include -#include #include #include #include @@ -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 @@ static uint16_t checksum (unsigned char *addr, uint16_t len) } 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 @@ int open_socket (interface_t *iface, bool arp) 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 @@ int get_packet (interface_t *iface, unsigned char *data, 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 @@ int send_packet (interface_t *iface, int type, unsigned char *data, int len) /* 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 @@ size_t get_packet (interface_t *iface, unsigned char *data, 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; diff --git a/socket.h b/socket.h index a35f5b56..db3058aa 100644 --- a/socket.h +++ b/socket.h @@ -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