svn commit: r335602 - head/sbin/dhclient
Eitan Adler
eadler at FreeBSD.org
Sun Jun 24 13:23:30 UTC 2018
Author: eadler
Date: Sun Jun 24 13:23:27 2018
New Revision: 335602
URL: https://svnweb.freebsd.org/changeset/base/335602
Log:
dhclient: build with WARNS=6
- add static in a number of places
- initialize __progname rather than rely on magical extern values
- use nitems() instead of manually spelling it out
- unshadow 'idi'
- teach 'error' that it is '__dead2'
- add missing 'break'
Modified:
head/sbin/dhclient/Makefile
head/sbin/dhclient/bpf.c
head/sbin/dhclient/clparse.c
head/sbin/dhclient/conflex.c
head/sbin/dhclient/dhclient.c
head/sbin/dhclient/dhcpd.h
head/sbin/dhclient/dispatch.c
head/sbin/dhclient/options.c
head/sbin/dhclient/privsep.c
head/sbin/dhclient/privsep.h
Modified: head/sbin/dhclient/Makefile
==============================================================================
--- head/sbin/dhclient/Makefile Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/Makefile Sun Jun 24 13:23:27 2018 (r335602)
@@ -50,7 +50,6 @@ LIBADD+= cap_syslog
CFLAGS+=-DWITH_CASPER
.endif
-WARNS?= 4
NO_WCAST_ALIGN= yes
HAS_TESTS=
Modified: head/sbin/dhclient/bpf.c
==============================================================================
--- head/sbin/dhclient/bpf.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/bpf.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -95,7 +95,7 @@ if_register_bpf(struct interface_info *info, int flags
* Packet write filter program:
* 'ip and udp and src port bootps and dst port (bootps or bootpc)'
*/
-struct bpf_insn dhcp_bpf_wfilter[] = {
+static struct bpf_insn dhcp_bpf_wfilter[] = {
BPF_STMT(BPF_LD + BPF_B + BPF_IND, 14),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (IPVERSION << 4) + 5, 0, 12),
@@ -129,7 +129,7 @@ struct bpf_insn dhcp_bpf_wfilter[] = {
BPF_STMT(BPF_RET+BPF_K, 0),
};
-int dhcp_bpf_wfilter_len = sizeof(dhcp_bpf_wfilter) / sizeof(struct bpf_insn);
+static int dhcp_bpf_wfilter_len = nitems(dhcp_bpf_wfilter);
void
if_register_send(struct interface_info *info)
@@ -184,7 +184,7 @@ if_register_send(struct interface_info *info)
* XXX: Changes to the filter program may require changes to the
* constant offsets used in if_register_send to patch the BPF program!
*/
-struct bpf_insn dhcp_bpf_filter[] = {
+static struct bpf_insn dhcp_bpf_filter[] = {
/* Make sure this is an IP packet... */
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8),
@@ -211,7 +211,7 @@ struct bpf_insn dhcp_bpf_filter[] = {
BPF_STMT(BPF_RET+BPF_K, 0),
};
-int dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(struct bpf_insn);
+static int dhcp_bpf_filter_len = nitems(dhcp_bpf_filter);
void
if_register_receive(struct interface_info *info)
Modified: head/sbin/dhclient/clparse.c
==============================================================================
--- head/sbin/dhclient/clparse.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/clparse.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -49,10 +49,9 @@ __FBSDID("$FreeBSD$");
#include "dhctoken.h"
struct client_config top_level_config;
-struct interface_info *dummy_interfaces;
-extern struct interface_info *ifi;
+static struct interface_info *dummy_interfaces;
-char client_script_name[] = "/sbin/dhclient-script";
+static char client_script_name[] = "/sbin/dhclient-script";
/*
* client-conf-file :== client-declarations EOF
Modified: head/sbin/dhclient/conflex.c
==============================================================================
--- head/sbin/dhclient/conflex.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/conflex.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -53,8 +53,8 @@ __FBSDID("$FreeBSD$");
int lexline;
int lexchar;
char *token_line;
-char *prev_line;
-char *cur_line;
+static char *prev_line;
+static char *cur_line;
const char *tlname;
int eol_token;
@@ -347,6 +347,7 @@ intern(char *atom, int dfv)
return (BOOTING);
if (!strcasecmp(atom + 1, "oot-unknown-clients"))
return (BOOT_UNKNOWN_CLIENTS);
+ break;
case 'c':
if (!strcasecmp(atom + 1, "lass"))
return (CLASS);
Modified: head/sbin/dhclient/dhclient.c
==============================================================================
--- head/sbin/dhclient/dhclient.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/dhclient.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -65,9 +65,11 @@ __FBSDID("$FreeBSD$");
#include <sys/endian.h>
#include <capsicum_helpers.h>
+#include <libgen.h>
#include <net80211/ieee80211_freebsd.h>
+
#ifndef _PATH_VAREMPTY
#define _PATH_VAREMPTY "/var/empty"
#endif
@@ -91,21 +93,21 @@ __FBSDID("$FreeBSD$");
cap_channel_t *capsyslog;
time_t cur_time;
-time_t default_lease_time = 43200; /* 12 hours... */
+static time_t default_lease_time = 43200; /* 12 hours... */
const char *path_dhclient_conf = _PATH_DHCLIENT_CONF;
char *path_dhclient_db = NULL;
int log_perror = 1;
-int privfd;
-int nullfd = -1;
+static int privfd;
+static int nullfd = -1;
-char hostname[_POSIX_HOST_NAME_MAX + 1];
+static char hostname[_POSIX_HOST_NAME_MAX + 1];
-struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
-struct in_addr inaddr_any, inaddr_broadcast;
+static struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
+static struct in_addr inaddr_any, inaddr_broadcast;
-char *path_dhclient_pidfile;
+static char *path_dhclient_pidfile;
struct pidfh *pidfile;
/*
@@ -121,9 +123,9 @@ struct pidfh *pidfile;
#define TIME_MAX ((((time_t) 1 << (sizeof(time_t) * CHAR_BIT - 2)) - 1) * 2 + 1)
int log_priority;
-int no_daemon;
-int unknown_ok = 1;
-int routefd;
+static int no_daemon;
+static int unknown_ok = 1;
+static int routefd;
struct interface_info *ifi;
@@ -147,6 +149,7 @@ int fork_privchld(int, int);
#define MIN_MTU 68
static time_t scripttime;
+static char *__progname;
int
findproto(char *cp, int n)
@@ -197,8 +200,8 @@ get_ifa(char *cp, int n)
return (NULL);
}
-struct iaddr defaddr = { .len = 4 };
-uint8_t curbssid[6];
+static struct iaddr defaddr = { .len = 4 };
+static uint8_t curbssid[6];
static void
disassoc(void *arg)
@@ -369,7 +372,6 @@ init_casper(void)
int
main(int argc, char *argv[])
{
- extern char *__progname;
int ch, fd, quiet = 0, i = 0;
int pipe_fd[2];
int immediate_daemon = 0;
@@ -377,6 +379,8 @@ main(int argc, char *argv[])
pid_t otherpid;
cap_rights_t rights;
+ __progname = basename(argv[0]);
+
init_casper();
/* Initially, log errors to stderr as well as to syslogd. */
@@ -561,7 +565,6 @@ main(int argc, char *argv[])
void
usage(void)
{
- extern char *__progname;
fprintf(stderr, "usage: %s [-bdqu] ", __progname);
fprintf(stderr, "[-c conffile] [-l leasefile] interface\n");
@@ -1903,7 +1906,7 @@ free_client_lease(struct client_lease *lease)
free(lease);
}
-FILE *leaseFile;
+static FILE *leaseFile;
void
rewrite_client_leases(void)
Modified: head/sbin/dhclient/dhcpd.h
==============================================================================
--- head/sbin/dhclient/dhcpd.h Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/dhcpd.h Sun Jun 24 13:23:27 2018 (r335602)
@@ -265,7 +265,7 @@ void do_packet(struct interface_info *, struct dhcp_pa
/* errwarn.c */
extern int warnings_occurred;
-void error(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+void error(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))) __dead2;
int warning(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
int note(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
int debug(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
@@ -368,6 +368,8 @@ extern int log_perror;
extern struct client_config top_level_config;
extern struct pidfh *pidfile;
+
+extern struct interface_info *ifi;
void dhcpoffer(struct packet *);
void dhcpack(struct packet *);
Modified: head/sbin/dhclient/dispatch.c
==============================================================================
--- head/sbin/dhclient/dispatch.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/dispatch.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -57,8 +57,8 @@ __FBSDID("$FreeBSD$");
/* Assert that pointer p is aligned to at least align bytes */
#define assert_aligned(p, align) assert((((uintptr_t)p) & ((align) - 1)) == 0)
-struct protocol *protocols;
-struct timeout *timeouts;
+static struct protocol *protocols;
+static struct timeout *timeouts;
static struct timeout *free_timeouts;
static int interfaces_invalidated;
void (*bootp_packet_handler)(struct interface_info *,
Modified: head/sbin/dhclient/options.c
==============================================================================
--- head/sbin/dhclient/options.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/options.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -50,8 +50,8 @@ __FBSDID("$FreeBSD$");
#define DHCP_OPTION_DATA
#include "dhcpd.h"
-int bad_options = 0;
-int bad_options_max = 5;
+static int bad_options = 0;
+static int bad_options_max = 5;
void parse_options(struct packet *);
void parse_option_buffer(struct packet *, unsigned char *, int);
Modified: head/sbin/dhclient/privsep.c
==============================================================================
--- head/sbin/dhclient/privsep.c Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/privsep.c Sun Jun 24 13:23:27 2018 (r335602)
@@ -102,7 +102,7 @@ buf_read(int sock, void *buf, size_t nbytes)
}
void
-dispatch_imsg(struct interface_info *ifi, int fd)
+dispatch_imsg(struct interface_info *ifix, int fd)
{
struct imsg_hdr hdr;
char *medium, *reason, *filename,
@@ -235,14 +235,14 @@ dispatch_imsg(struct interface_info *ifi, int fd)
error("buf_close: %m");
break;
case IMSG_SEND_PACKET:
- send_packet_priv(ifi, &hdr, fd);
+ send_packet_priv(ifix, &hdr, fd);
break;
case IMSG_SET_INTERFACE_MTU:
if (hdr.len < sizeof(hdr) + sizeof(u_int16_t))
error("corrupted message received");
buf_read(fd, &mtu, sizeof(u_int16_t));
- interface_set_mtu_priv(ifi->name, mtu);
+ interface_set_mtu_priv(ifix->name, mtu);
break;
default:
error("received unknown message, code %d", hdr.code);
Modified: head/sbin/dhclient/privsep.h
==============================================================================
--- head/sbin/dhclient/privsep.h Sun Jun 24 13:14:04 2018 (r335601)
+++ head/sbin/dhclient/privsep.h Sun Jun 24 13:23:27 2018 (r335602)
@@ -44,8 +44,3 @@ struct imsg_hdr {
enum imsg_code code;
size_t len;
};
-
-struct buf *buf_open(size_t);
-int buf_add(struct buf *, const void *, size_t);
-int buf_close(int, struct buf *);
-ssize_t buf_read(int sock, void *, size_t);
More information about the svn-src-all
mailing list