Fixes for various compiler warnings
Subsystems (2)
cover Fixes for various compiler warnings
Hi,
here's some assorted fixes for compiler warnings I'm seeing on my platform. Most warnings are probably due to using musl libc, but the fixes should be the correct thing to do regardless. With this patchset, I can now compile nfs-utils with -Werror just fine.
Regards
Patrick
Patrick Steinhardt (6):
Annotate unused fields with UNUSED
Use <fcntl.h> header instead of <sys/fcntl.h> Use <poll.h> header instead of <sys/poll.h> configure.ac: Add <sys/socket.h> header when checking
sizeof(socklen_t)
nfsd_path: Include missing header for struct stat
mountd: Use unsigned for filesystem type magic constants
configure.ac | 5 ++++- support/export/xtab.c | 2 +- support/include/nfsd_path.h | 2 ++ support/misc/xstat.c | 3 ++- support/nfs/rmtab.c | 2 +- support/nfs/rpc_socket.c | 3 ++- support/nfs/svc_socket.c | 2 +- support/nfs/xio.c | 2 +- utils/gssd/svcgssd_main_loop.c | 2 +- utils/mountd/cache.c | 4 ++-- utils/statd/sm-notify.c | 2 +- 11 files changed, 18 insertions(+), 11 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/6 Annotate unused fields with UNUSED
There are some parameters that may be potentially unused. Add the UNUSED macro to avoid any warnings.
--- support/misc/xstat.c | 3 ++- support/nfs/rpc_socket.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
support/misc/xstat.c +2 -1
@@ -9,6 +9,7 @@#include <sys/sysmacros.h> #include <unistd.h> +#include "nfslib.h" #include "xstat.h" #ifdef HAVE_FSTATAT
@@ -66,7 +67,7 @@ statx_stat_nosync(int fd, const char *pathname, struct stat *statbuf, int flags)#else static int -statx_stat_nosync (int fd,const char *pathname,struct stat *statbuf,int flags) +statx_stat_nosync (int UNUSED (fd ),const char *UNUSED (pathname ),struct stat *UNUSED (statbuf ),int UNUSED (flags )) { errno =ENOSYS ;return -1 ;
support/nfs/rpc_socket.c +2 -1
@@ -41,6 +41,7 @@#include <rpc/pmap_prot.h> #include "sockaddr.h" +#include "nfslib.h" #include "nfsrpc.h" #ifdef HAVE_LIBTIRPC
@@ -519,7 +520,7 @@ CLIENT *nfs_get_priv_rpcclient(const struct sockaddr *sap,* Returns program number of first name to be successfully looked * up, or the default program number if all lookups fail. */ -rpcprog_t nfs_getrpcbyname (const rpcprog_t program,const char *table[]) +rpcprog_t nfs_getrpcbyname (const rpcprog_t program,const char *UNUSED (table [])) {#ifdef HAVE_GETRPCBYNAME struct rpcent *entry;
Signature · 1 line
2.23.0
PATCH 2/6 Use <fcntl.h> header instead of <sys/fcntl.h>
In reply to Patrick SteinhardtWhile most source files already use the standard header <fcntl.h> instead of <sys/fcntl.h>, some do not, causing warnings on musl libc systems.
Fix the remaining ones to use <fcntl.h>. As we already use the header unconditionally in a lot of places, this change should not cause any problems for other platforms.
--- support/export/xtab.c | 2 +- support/nfs/rmtab.c | 2 +- support/nfs/svc_socket.c | 2 +- support/nfs/xio.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
support/export/xtab.c +1 -1
@@ -10,7 +10,7 @@#include <config.h> #endif -#include <sys/fcntl.h> +#include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <string.h>
support/nfs/rmtab.c +1 -1
@@ -10,7 +10,7 @@#include <config.h> #endif -#include <sys/fcntl.h> +#include <fcntl.h> #include <stdlib.h> #include <string.h> #include <stdio.h>
support/nfs/svc_socket.c +1 -1
@@ -22,7 +22,7 @@#include <netdb.h> #include <rpc/rpc.h> #include <sys/socket.h> -#include <sys/fcntl.h> +#include <fcntl.h> #include <errno.h> #include "xlog.h" #include "rpcmisc.h"
support/nfs/xio.c +1 -1
@@ -10,7 +10,7 @@#include <config.h> #endif -#include <sys/fcntl.h> +#include <fcntl.h> #include <string.h> #include <stdlib.h> #include <stdio.h>
Signature · 1 line
2.23.0
PATCH 3/6 Use <poll.h> header instead of <sys/poll.h>
In reply to Patrick SteinhardtThe POSIX standard specifies that poll(3P) should be declared in the header <poll.h> instead of <sys/poll.h>. While there is one location where we use the correct header, two others do not, causing warnings on musl libc systems.
Fix the warning by switching from <sys/poll.h> to <poll.h>. As we're already using the latter one already, this change should not cause any problems for other platforms.
--- utils/gssd/svcgssd_main_loop.c | 2 +- utils/statd/sm-notify.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
utils/gssd/svcgssd_main_loop.c +1 -1
@@ -34,7 +34,7 @@#include <sys/param.h> #include <sys/socket.h> -#include <sys/poll.h> +#include <poll.h> #include <sys/types.h> #include <sys/stat.h> #include <netinet/in.h>
utils/statd/sm-notify.c +1 -1
@@ -12,7 +12,7 @@#include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> -#include <sys/poll.h> +#include <poll.h> #include <sys/param.h> #include <sys/syslog.h> #include <arpa/inet.h>
Signature · 1 line
2.23.0
PATCH 4/6 configure.ac: Add <sys/socket.h> header when checking sizeof(socklen_t)
In reply to Patrick SteinhardtWe're checking for various sizes in configure.ac, among them the size of the socklen_t type. If socklen_t's size is not found and thus reported to be zero, we will typedef our own socklen_t as "unsigned int".
The check for socklen_t is insufficient, though. While the type is declared via <sys/socket.h>, we only search AC_INCLUDES_DEFAULT for its declaration, which doesn't include <sys/socket.h>. On musl libc, this causes us to not find the declaration and redeclare it with an incompatible type.
Fix the issue by searching both the default includes as well as <sys/socket.h>.
--- configure.ac | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
configure.ac +4 -1
@@ -545,7 +545,10 @@ AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(size_t) -AC_CHECK_SIZEOF(socklen_t) +AC_CHECK_SIZEOF(socklen_t,, [AC_INCLUDES_DEFAULT + #ifdef HAVE_SYS_SOCKET_H + # include <sys/socket.h> + #endif]) dnl *************************************************************
Signature · 1 line
2.23.0
PATCH 5/6 nfsd_path: Include missing header for `struct stat`
In reply to Patrick SteinhardtThe header "nfsd_path.h" uses struct stat in its function signatures, but doesn't include the <sys/stat.h> header. This may cause compiler warnings if a compilation unit includes "nfsd_path.h" while not transitively including <sys/stat.h>.
Fix the potential warning by including <sys/stat.h> in the header.
--- support/include/nfsd_path.h | 2 ++ 1 file changed, 2 insertions(+)
support/include/nfsd_path.h +2 -0
@@ -4,6 +4,8 @@#ifndef NFSD_PATH_H #define NFSD_PATH_H +#include <sys/stat.h> +void nfsd_path_init (void );const char *nfsd_path_nfsd_rootdir (void );
Signature · 1 line
2.23.0
PATCH 6/6 mountd: Use unsigned for filesystem type magic constants
In reply to Patrick SteinhardtThe filesystem type magic constants are all unsigned integers, but we declare them as signed ones. This may cause a compiler warning when comparing our own signed magic constants with the unsigned ones return by statfs64(3).
Fix the issue by uniformly usign unsigned types.
--- utils/mountd/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
utils/mountd/cache.c +2 -2
@@ -302,7 +302,7 @@ static int get_uuid(const char *val, size_t uuidlen, char *u)* we generate the identifier from statfs->f_fsid. The rest are network or * pseudo filesystems. (See <linux/magic.h> for the basic IDs.) */ -static const long int nonblkid_filesystems[] = { +static const unsigned long nonblkid_filesystems[] = {0x2fc12fc1 ,/* ZFS_SUPER_MAGIC */ 0x9123683E ,/* BTRFS_SUPER_MAGIC */ 0xFF534D42 ,/* CIFS_MAGIC_NUMBER */
@@ -355,7 +355,7 @@ static int uuid_by_path(char *path, int type, size_t uuidlen, char *uuid) rc =statfs64 (path, &st);if (type ==0 && rc ==0 ) { -const long int *bad; +const unsigned long *bad;for (bad = nonblkid_filesystems; *bad; bad++) {if (*bad == st.f_type)break ;
Signature · 1 line
2.23.0
Quoted 6 lines · Patrick Steinhardt
Hi,
here's some assorted fixes for compiler warnings I'm seeing on my platform. Most warnings are probably due to using musl libc, but the fixes should be the correct thing to do regardless. With this patchset, I can now compile nfs-utils with -Werror just fine.
Patchset committed....
steved.
Quoted 26 lines
Regards
PatrickPatrick Steinhardt (6):
Annotate unused fields with UNUSED
Use <fcntl.h> header instead of <sys/fcntl.h> Use <poll.h> header instead of <sys/poll.h> configure.ac: Add <sys/socket.h> header when checking
sizeof(socklen_t)
nfsd_path: Include missing header forstruct stat
mountd: Use unsigned for filesystem type magic constantsconfigure.ac | 5 ++++- support/export/xtab.c | 2 +- support/include/nfsd_path.h | 2 ++ support/misc/xstat.c | 3 ++- support/nfs/rmtab.c | 2 +- support/nfs/rpc_socket.c | 3 ++- support/nfs/svc_socket.c | 2 +- support/nfs/xio.c | 2 +- utils/gssd/svcgssd_main_loop.c | 2 +- utils/mountd/cache.c | 4 ++-- utils/statd/sm-notify.c | 2 +- 11 files changed, 18 insertions(+), 11 deletions(-)