Skip to contentSkip to conversation

mountd: Check for return of stat function

PATCH In review Khem Raj 2 participants 5 messages Aug 16, 2022 – Sep 13, 2022

Subsystems (2)
lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH v2 1/2 mountd: Check for return of stat function

simplify the check, stat() return 0 on success -1 on failure

Fixes clang reported errors e.g.

| v4clients.c:29:6: error: logical not is only applied to the left hand side of this comparison [-Werror,-Wlogical-not-parentheses]
|         if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
|             ^                                   ~~
Cc Konstantin Khorenko <[email protected]>
Cc Steve Dickson <[email protected]>

---
v2: rebased

 support/export/v4clients.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
support/export/v4clients.c +1 -1
index 5f15b61..3230251 100644
@@ -26,7 +26,7 @@ void v4clients_init(void)
 {
 	struct stat sb;
 
-	if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
+	if (stat("/proc/fs/nfsd/clients", &sb) != 0 ||
 	    !S_ISDIR(sb.st_mode))
 		return;
 	if (clients_fd >= 0)
Signature · 1 line
2.37.2
author
#1 lore raw

PATCH v2 2/2 Fix function prototypes

Clang is now erroring out on functions with out parameter types

Fixes errors like
error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

Cc Steve Dickson <[email protected]>

---
v2: Add Steve to Cc list

 support/export/auth.c     | 2 +-
 support/export/v4root.c   | 2 +-
 support/export/xtab.c     | 2 +-
 utils/exportfs/exportfs.c | 4 ++--
 utils/mount/network.c     | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
support/export/auth.c +1 -1
index 03ce4b8..2d7960f 100644
@@ -82,7 +82,7 @@ check_useipaddr(void)
 }
 
 unsigned int
-auth_reload()
+auth_reload(void)
 {
 	struct stat		stb;
 	static ino_t		last_inode;
support/export/v4root.c +1 -1
index c12a7d8..fbb0ad5 100644
@@ -198,7 +198,7 @@ static int v4root_add_parents(nfs_export *exp)
  * looking for components of the v4 mount.
  */
 void
-v4root_set()
+v4root_set(void)
 {
 	nfs_export	*exp;
 	int	i;
support/export/xtab.c +1 -1
index c888a80..e210ca9 100644
@@ -135,7 +135,7 @@ xtab_write(char *xtab, char *xtabtmp, char *lockfn, int is_export)
 }
 
 int
-xtab_export_write()
+xtab_export_write(void)
 {
 	return xtab_write(etab.statefn, etab.tmpfn, etab.lockfn, 1);
 }
utils/exportfs/exportfs.c +2 -2
index 6ba615d..0897b22 100644
@@ -69,14 +69,14 @@ static int _lockfd = -1;
  * need these additional lockfile() routines.
  */
 static void
-grab_lockfile()
+grab_lockfile(void)
 {
 	_lockfd = open(lockfile, O_CREAT|O_RDWR, 0666);
 	if (_lockfd != -1)
 		lockf(_lockfd, F_LOCK, 0);
 }
 static void
-release_lockfile()
+release_lockfile(void)
 {
 	if (_lockfd != -1) {
 		lockf(_lockfd, F_ULOCK, 0);
utils/mount/network.c +1 -1
index ed2f825..01ead49 100644
@@ -179,7 +179,7 @@ static const unsigned long probe_mnt3_only[] = {
 
 static const unsigned int *nfs_default_proto(void);
 #ifdef MOUNT_CONFIG
-static const unsigned int *nfs_default_proto()
+static const unsigned int *nfs_default_proto(void)
 {
 	extern unsigned long config_default_proto;
 	/*
Signature · 1 line
2.37.2
#2 lore raw

Re: [PATCH v2 2/2] Fix function prototypes

Quoted 6 lines · Khem Raj

Clang is now erroring out on functions with out parameter types

Fixes errors like
error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

Committed... (tag: nfs-utils-2-6-3-rc1)

steved.

Quoted 84 lines
Cc Steve Dickson <[email protected]>

---
v2: Add Steve to Cc list

  support/export/auth.c     | 2 +-
  support/export/v4root.c   | 2 +-
  support/export/xtab.c     | 2 +-
  utils/exportfs/exportfs.c | 4 ++--
  utils/mount/network.c     | 2 +-
  5 files changed, 6 insertions(+), 6 deletions(-)
support/export/auth.c +1 -1
index 03ce4b8..2d7960f 100644
@@ -82,7 +82,7 @@ check_useipaddr(void)
  }
 
  unsigned int
-auth_reload()
+auth_reload(void)
  {
  	struct stat		stb;
  	static ino_t		last_inode;
support/export/v4root.c +1 -1
index c12a7d8..fbb0ad5 100644
@@ -198,7 +198,7 @@ static int v4root_add_parents(nfs_export *exp)
   * looking for components of the v4 mount.
   */
  void
-v4root_set()
+v4root_set(void)
  {
  	nfs_export	*exp;
  	int	i;
support/export/xtab.c +1 -1
index c888a80..e210ca9 100644
@@ -135,7 +135,7 @@ xtab_write(char *xtab, char *xtabtmp, char *lockfn, int is_export)
  }
 
  int
-xtab_export_write()
+xtab_export_write(void)
  {
  	return xtab_write(etab.statefn, etab.tmpfn, etab.lockfn, 1);
  }
utils/exportfs/exportfs.c +2 -2
index 6ba615d..0897b22 100644
@@ -69,14 +69,14 @@ static int _lockfd = -1;
   * need these additional lockfile() routines.
   */
  static void
-grab_lockfile()
+grab_lockfile(void)
  {
  	_lockfd = open(lockfile, O_CREAT|O_RDWR, 0666);
  	if (_lockfd != -1)
  		lockf(_lockfd, F_LOCK, 0);
  }
  static void
-release_lockfile()
+release_lockfile(void)
  {
  	if (_lockfd != -1) {
  		lockf(_lockfd, F_ULOCK, 0);
utils/mount/network.c +1 -1
index ed2f825..01ead49 100644
@@ -179,7 +179,7 @@ static const unsigned long probe_mnt3_only[] = {
 
  static const unsigned int *nfs_default_proto(void);
  #ifdef MOUNT_CONFIG
-static const unsigned int *nfs_default_proto()
+static const unsigned int *nfs_default_proto(void)
  {
  	extern unsigned long config_default_proto;
  	/*
#3 lore raw
In reply to Khem Raj
Quoted 9 lines · Khem Raj

simplify the check, stat() return 0 on success -1 on failure

Fixes clang reported errors e.g.

| v4clients.c:29:6: error: logical not is only applied to the left hand side of this comparison [-Werror,-Wlogical-not-parentheses]
|         if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
|             ^                                   ~~

Committed... (tag: nfs-utils-2-6-3-rc1)

steved

Quoted 21 lines
Cc Konstantin Khorenko <[email protected]>
Cc Steve Dickson <[email protected]>

---
v2: rebased

  support/export/v4clients.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
support/export/v4clients.c +1 -1
index 5f15b61..3230251 100644
@@ -26,7 +26,7 @@ void v4clients_init(void)
  {
  	struct stat sb;
 
-	if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
+	if (stat("/proc/fs/nfsd/clients", &sb) != 0 ||
  	    !S_ISDIR(sb.st_mode))
  		return;
  	if (clients_fd >= 0)
#4 lore raw
In reply to Khem Raj
Quoted 10 lines · Khem Raj

simplify the check, stat() return 0 on success -1 on failure

Fixes clang reported errors e.g.

| v4clients.c:29:6: error: logical not is only applied to the left hand side of this comparison [-Werror,-Wlogical-not-parentheses]
|         if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
|             ^                                   ~~
Cc Konstantin Khorenko <[email protected]>

Committed... (tag: nfs-utils-2-6-3-rc1)

steved

Quoted 20 lines
Cc Steve Dickson <[email protected]>

---
v2: rebased

  support/export/v4clients.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
support/export/v4clients.c +1 -1
index 5f15b61..3230251 100644
@@ -26,7 +26,7 @@ void v4clients_init(void)
  {
  	struct stat sb;
 
-	if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
+	if (stat("/proc/fs/nfsd/clients", &sb) != 0 ||
  	    !S_ISDIR(sb.st_mode))
  		return;
  	if (clients_fd >= 0)