git: b96f027b7102 - stable/12 - bootparamd: Fix several warnings and increase warn level to 6.
Yoshihiro Takahashi
nyan at FreeBSD.org
Tue Jan 19 14:58:00 UTC 2021
The branch stable/12 has been updated by nyan:
URL: https://cgit.FreeBSD.org/src/commit/?id=b96f027b71024cccc475d4d9f69176d372956756
commit b96f027b71024cccc475d4d9f69176d372956756
Author: Yoshihiro Takahashi <nyan at FreeBSD.org>
AuthorDate: 2021-01-02 03:36:09 +0000
Commit: Yoshihiro Takahashi <nyan at FreeBSD.org>
CommitDate: 2021-01-19 14:55:16 +0000
bootparamd: Fix several warnings and increase warn level to 6.
- Increase WARNS to 6.
- Except -Wcast-align and -Wincompatible-pointer-types-discards-qualifiers
checks.
- Use ANSI C prototype.
- Statically variables and functions.
- Add extern declaration for global variables.
- Rename local variables to resolve shadow warnings.
PR: 71667
(cherry picked from commit e03764d931d820185a019334259b18df2e3f6b6c)
---
usr.sbin/bootparamd/Makefile.inc | 4 +-
usr.sbin/bootparamd/bootparamd/bootparamd.c | 83 +++++++++++++----------------
usr.sbin/bootparamd/bootparamd/main.c | 15 +++---
usr.sbin/bootparamd/callbootd/callbootd.c | 26 ++++-----
4 files changed, 59 insertions(+), 69 deletions(-)
diff --git a/usr.sbin/bootparamd/Makefile.inc b/usr.sbin/bootparamd/Makefile.inc
index 5c01215dd550..de7ed1c2f55c 100644
--- a/usr.sbin/bootparamd/Makefile.inc
+++ b/usr.sbin/bootparamd/Makefile.inc
@@ -3,4 +3,6 @@
BINDIR?= /usr/sbin
-WARNS?= 2
+NO_WCAST_ALIGN=
+CWARNFLAGS.clang+= -Wno-incompatible-pointer-types-discards-qualifiers
+CWARNFLAGS.gcc+= -Wno-error=discarded-qualifiers
diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.c b/usr.sbin/bootparamd/bootparamd/bootparamd.c
index 9c45cf8d0f38..7cc57d2427a4 100644
--- a/usr.sbin/bootparamd/bootparamd/bootparamd.c
+++ b/usr.sbin/bootparamd/bootparamd/bootparamd.c
@@ -7,10 +7,8 @@ use and modify. Please send modifications and/or suggestions + bug fixes to
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
#ifdef YP
#include <rpc/rpc.h>
@@ -27,26 +25,25 @@ static const char rcsid[] =
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
+
extern int debug, dolog;
extern in_addr_t route_addr;
-extern char *bootpfile;
+extern const char *bootpfile;
#define MAXLEN 800
-struct hostent *he;
+static struct hostent *he;
static char buffer[MAXLEN];
static char hostname[MAX_MACHINE_NAME];
static char askname[MAX_MACHINE_NAME];
static char path[MAX_PATH_LEN];
static char domain_name[MAX_MACHINE_NAME];
-int getthefile(char *, char *, char *, int);
-int checkhost(char *, char *, int);
+static int getthefile(char *, char *, char *, int);
+static int checkhost(char *, char *, int);
bp_whoami_res *
-bootparamproc_whoami_1_svc(whoami, req)
-bp_whoami_arg *whoami;
-struct svc_req *req;
+bootparamproc_whoami_1_svc(bp_whoami_arg *whoami, struct svc_req *req __unused)
{
in_addr_t haddr;
static bp_whoami_res res;
@@ -110,9 +107,7 @@ struct svc_req *req;
bp_getfile_res *
- bootparamproc_getfile_1_svc(getfile, req)
-bp_getfile_arg *getfile;
-struct svc_req *req;
+bootparamproc_getfile_1_svc(bp_getfile_arg *getfile, struct svc_req *req __unused)
{
char *where;
static bp_getfile_res res;
@@ -177,17 +172,14 @@ struct svc_req *req;
return(NULL);
}
-/* getthefile return 1 and fills the buffer with the information
+/* getthefile return 1 and fills the buf with the information
of the file, e g "host:/export/root/client" if it can be found.
- If the host is in the database, but the file is not, the buffer
+ If the host is in the database, but the file is not, the buf
will be empty. (This makes it possible to give the special
empty answer for the file "dump") */
-int
-getthefile(askname,fileid,buffer,blen)
-char *askname;
-char *fileid, *buffer;
-int blen;
+static int
+getthefile(char *l_askname, char *fileid, char *buf, int blen)
{
FILE *bpf;
char *where;
@@ -211,11 +203,11 @@ int blen;
/* XXX see comment below */
while ( fscanf(bpf, "%255s", hostname) > 0 && !match ) {
if ( *hostname != '#' ) { /* comment */
- if ( ! strcmp(hostname, askname) ) {
+ if ( ! strcmp(hostname, l_askname) ) {
match = 1;
} else {
he = gethostbyname(hostname);
- if (he && !strcmp(he->h_name, askname)) match = 1;
+ if (he && !strcmp(he->h_name, l_askname)) match = 1;
}
}
if (*hostname == '+' ) { /* NIS */
@@ -224,16 +216,16 @@ int blen;
if (debug) warn("NIS");
return(0);
}
- if (yp_match(yp_domain, "bootparams", askname, strlen(askname),
+ if (yp_match(yp_domain, "bootparams", l_askname, strlen(l_askname),
&result, &resultlen))
return (0);
if (strstr(result, fileid) == NULL) {
- buffer[0] = '\0';
+ buf[0] = '\0';
} else {
- snprintf(buffer, blen,
+ snprintf(buf, blen,
"%s",strchr(strstr(result,fileid), '=') + 1);
- if (strchr(buffer, ' ') != NULL)
- *(char *)(strchr(buffer, ' ')) = '\0';
+ if (strchr(buf, ' ') != NULL)
+ *(char *)(strchr(buf, ' ')) = '\0';
}
if (fclose(bpf))
warnx("could not close %s", bootpfile);
@@ -265,7 +257,7 @@ int blen;
if (! strncmp(info, fileid, fid_len) && *(info + fid_len) == '=') {
where = info + fid_len + 1;
if ( isprint( *where )) {
- strcpy(buffer, where); /* found file */
+ strcpy(buf, where); /* found file */
res = 1; break;
}
} else {
@@ -284,19 +276,16 @@ int blen;
}
}
if (fclose(bpf)) { warnx("could not close %s", bootpfile); }
- if ( res == -1) buffer[0] = '\0'; /* host found, file not */
+ if ( res == -1) buf[0] = '\0'; /* host found, file not */
return(match);
}
/* checkhost puts the hostname found in the database file in
- the hostname-variable and returns 1, if askname is a valid
+ the l_hostname-variable and returns 1, if l_askname is a valid
name for a host in the database */
-int
-checkhost(askname, hostname, len)
-char *askname;
-char *hostname;
-int len;
+static int
+checkhost(char *l_askname, char *l_hostname, int len)
{
int ch, pch;
FILE *bpf;
@@ -315,36 +304,36 @@ int len;
/* XXX there is no way in ISO C to specify the maximal length for a
conversion in a variable way */
- while ( fscanf(bpf, "%254s", hostname) > 0 ) {
- if ( *hostname != '#' ) { /* comment */
- if ( ! strcmp(hostname, askname) ) {
- /* return true for match of hostname */
+ while ( fscanf(bpf, "%254s", l_hostname) > 0 ) {
+ if ( *l_hostname != '#' ) { /* comment */
+ if ( ! strcmp(l_hostname, l_askname) ) {
+ /* return true for match of l_hostname */
res = 1;
break;
} else {
/* check the alias list */
he = NULL;
- he = gethostbyname(hostname);
- if (he && !strcmp(askname, he->h_name)) {
+ he = gethostbyname(l_hostname);
+ if (he && !strcmp(l_askname, he->h_name)) {
res = 1;
break;
}
}
}
- if (*hostname == '+' ) { /* NIS */
+ if (*l_hostname == '+' ) { /* NIS */
#ifdef YP
if (yp_get_default_domain(&yp_domain)) {
if (debug) warn("NIS");
return(0);
}
- if (!yp_match(yp_domain, "bootparams", askname, strlen(askname),
+ if (!yp_match(yp_domain, "bootparams", l_askname, strlen(l_askname),
&result, &resultlen)) {
/* return true for match of hostname */
he = NULL;
- he = gethostbyname(askname);
- if (he && !strcmp(askname, he->h_name)) {
+ he = gethostbyname(l_askname);
+ if (he && !strcmp(l_askname, he->h_name)) {
res = 1;
- snprintf(hostname, len, "%s", he->h_name);
+ snprintf(l_hostname, len, "%s", he->h_name);
}
}
if (fclose(bpf))
diff --git a/usr.sbin/bootparamd/bootparamd/main.c b/usr.sbin/bootparamd/bootparamd/main.c
index 04f5ceffe36c..95b49f8f39a0 100644
--- a/usr.sbin/bootparamd/bootparamd/main.c
+++ b/usr.sbin/bootparamd/bootparamd/main.c
@@ -7,10 +7,8 @@ use and modify. Please send modifications and/or suggestions + bug fixes to
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
#include <ctype.h>
#include <err.h>
@@ -30,11 +28,16 @@ static const char rcsid[] =
#include <arpa/inet.h>
#include "bootparam_prot.h"
+extern int debug, dolog;
+extern in_addr_t route_addr;
+extern const char *bootpfile;
+
int debug = 0;
int dolog = 0;
in_addr_t route_addr = -1;
-struct sockaddr_in my_addr;
-char *bootpfile = "/etc/bootparams";
+const char *bootpfile = "/etc/bootparams";
+
+static struct sockaddr_in my_addr;
static void usage(void);
diff --git a/usr.sbin/bootparamd/callbootd/callbootd.c b/usr.sbin/bootparamd/callbootd/callbootd.c
index fe875093c5aa..ea1432c3140a 100644
--- a/usr.sbin/bootparamd/callbootd/callbootd.c
+++ b/usr.sbin/bootparamd/callbootd/callbootd.c
@@ -7,10 +7,8 @@ use and modify. Please send modifications and/or suggestions + bug fixes to
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
#include "bootparam_prot.h"
#include <rpc/rpc.h>
@@ -27,11 +25,11 @@ static const char rcsid[] =
#include <stdio.h>
#include <string.h>
-int broadcast;
+static int broadcast;
+static char cln[MAX_MACHINE_NAME+1];
+static char dmn[MAX_MACHINE_NAME+1];
+static char path[MAX_PATH_LEN+1];
-char cln[MAX_MACHINE_NAME+1];
-char dmn[MAX_MACHINE_NAME+1];
-char path[MAX_PATH_LEN+1];
static void usage(void);
int printgetfile(bp_getfile_res *);
int printwhoami(bp_whoami_res *);
@@ -72,8 +70,8 @@ main(int argc, char **argv)
bp_getfile_res *getfile_res, stat_getfile_res;
- long the_inet_addr;
- CLIENT *clnt;
+ in_addr_t the_inet_addr;
+ CLIENT *clnt = NULL; /* Silence warnings */
stat_whoami_res.client_name = cln;
stat_whoami_res.domain_name = dmn;
@@ -151,7 +149,7 @@ main(int argc, char **argv)
static void
-usage()
+usage(void)
{
fprintf(stderr,
"usage: callbootd server procnum (IP-addr | host fileid)\n");
@@ -159,8 +157,7 @@ usage()
}
int
-printwhoami(res)
-bp_whoami_res *res;
+printwhoami(bp_whoami_res *res)
{
if ( res) {
printf("client_name:\t%s\ndomain_name:\t%s\n",
@@ -181,8 +178,7 @@ bp_whoami_res *res;
int
-printgetfile(res)
-bp_getfile_res *res;
+printgetfile(bp_getfile_res *res)
{
if (res) {
printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n",
More information about the dev-commits-src-all
mailing list