git: 6b0b026ae1a4 - stable/13 - nfsd.c: Synchronize error handling

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Sun, 13 Oct 2024 21:00:29 UTC
The branch stable/13 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=6b0b026ae1a492736e955bda60a60d1b5aecea5d

commit 6b0b026ae1a492736e955bda60a60d1b5aecea5d
Author:     Joyu Liao <joyul@juniper.net>
AuthorDate: 2024-09-29 20:11:54 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-10-13 20:58:47 +0000

    nfsd.c: Synchronize error handling
    
    Synchronize the error handling in nfsd. If you check other error
    handlings in those same condition blocks, it uses nfsd_exit instead,
    which will call killchildren() and call the rpcbind service to do
    the service un-mapping.
---
 usr.sbin/nfsd/nfsd.c | 72 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 48 insertions(+), 24 deletions(-)

diff --git a/usr.sbin/nfsd/nfsd.c b/usr.sbin/nfsd/nfsd.c
index be26e0be77e8..c1995580e142 100644
--- a/usr.sbin/nfsd/nfsd.c
+++ b/usr.sbin/nfsd/nfsd.c
@@ -558,18 +558,24 @@ main(int argc, char **argv)
 				nfsd_exit(1);
 			}
 			nconf_udp = getnetconfigent("udp");
-			if (nconf_udp == NULL)
-				err(1, "getnetconfigent udp failed");
+			if (nconf_udp == NULL) {
+				syslog(LOG_ERR, "getnetconfigent udp failed");
+				nfsd_exit(1);
+			}
 			nb_udp.buf = ai_udp->ai_addr;
 			nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
 			if (nfs_minvers == NFS_VER2)
 				if (!rpcb_set(NFS_PROGRAM, 2, nconf_udp,
-				    &nb_udp))
-					err(1, "rpcb_set udp failed");
+				    &nb_udp)) {
+					syslog(LOG_ERR, "rpcb_set udp failed");
+					nfsd_exit(1);
+				}
 			if (nfs_minvers <= NFS_VER3)
 				if (!rpcb_set(NFS_PROGRAM, 3, nconf_udp,
-				    &nb_udp))
-					err(1, "rpcb_set udp failed");
+				    &nb_udp)) {
+					syslog(LOG_ERR, "rpcb_set udp failed");
+					nfsd_exit(1);
+				}
 			freeaddrinfo(ai_udp);
 		}
 	}
@@ -632,20 +638,26 @@ main(int argc, char **argv)
 				nfsd_exit(1);
 			}
 			nconf_udp6 = getnetconfigent("udp6");
-			if (nconf_udp6 == NULL)
-				err(1, "getnetconfigent udp6 failed");
+			if (nconf_udp6 == NULL) {
+				syslog(LOG_ERR, "getnetconfigent udp6 failed");
+				nfsd_exit(1);
+			}
 			nb_udp6.buf = ai_udp6->ai_addr;
 			nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
 			if (nfs_minvers == NFS_VER2)
 				if (!rpcb_set(NFS_PROGRAM, 2, nconf_udp6,
-				    &nb_udp6))
-					err(1,
+				    &nb_udp6)) {
+					syslog(LOG_ERR,
 					    "rpcb_set udp6 failed");
+					nfsd_exit(1);
+				}
 			if (nfs_minvers <= NFS_VER3)
 				if (!rpcb_set(NFS_PROGRAM, 3, nconf_udp6,
-				    &nb_udp6))
-					err(1,
+				    &nb_udp6)) {
+					syslog(LOG_ERR,
 					    "rpcb_set udp6 failed");
+					nfsd_exit(1);
+				}
 			freeaddrinfo(ai_udp6);
 		}
 	}
@@ -704,18 +716,24 @@ main(int argc, char **argv)
 				nfsd_exit(1);
 			}
 			nconf_tcp = getnetconfigent("tcp");
-			if (nconf_tcp == NULL)
-				err(1, "getnetconfigent tcp failed");
+			if (nconf_tcp == NULL) {
+				syslog(LOG_ERR, "getnetconfigent tcp failed");
+				nfsd_exit(1);
+			}
 			nb_tcp.buf = ai_tcp->ai_addr;
 			nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
 			if (nfs_minvers == NFS_VER2)
 				if (!rpcb_set(NFS_PROGRAM, 2, nconf_tcp,
-				    &nb_tcp))
-					err(1, "rpcb_set tcp failed");
+				    &nb_tcp)) {
+					syslog(LOG_ERR, "rpcb_set tcp failed");
+					nfsd_exit(1);
+				}
 			if (nfs_minvers <= NFS_VER3)
 				if (!rpcb_set(NFS_PROGRAM, 3, nconf_tcp,
-				    &nb_tcp))
-					err(1, "rpcb_set tcp failed");
+				    &nb_tcp)) {
+					syslog(LOG_ERR, "rpcb_set tcp failed");
+					nfsd_exit(1);
+				}
 			freeaddrinfo(ai_tcp);
 		}
 	}
@@ -782,18 +800,24 @@ main(int argc, char **argv)
 				nfsd_exit(1);
 			}
 			nconf_tcp6 = getnetconfigent("tcp6");
-			if (nconf_tcp6 == NULL)
-				err(1, "getnetconfigent tcp6 failed");
+			if (nconf_tcp6 == NULL) {
+				syslog(LOG_ERR, "getnetconfigent tcp6 failed");
+				nfsd_exit(1);
+			}
 			nb_tcp6.buf = ai_tcp6->ai_addr;
 			nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
 			if (nfs_minvers == NFS_VER2)
 				if (!rpcb_set(NFS_PROGRAM, 2, nconf_tcp6,
-				    &nb_tcp6))
-					err(1, "rpcb_set tcp6 failed");
+				    &nb_tcp6)) {
+					syslog(LOG_ERR, "rpcb_set tcp6 failed");
+					nfsd_exit(1);
+				}
 			if (nfs_minvers <= NFS_VER3)
 				if (!rpcb_set(NFS_PROGRAM, 3, nconf_tcp6,
-				    &nb_tcp6))
-					err(1, "rpcb_set tcp6 failed");
+				    &nb_tcp6)) {
+					syslog(LOG_ERR, "rpcb_set tcp6 failed");
+					nfsd_exit(1);
+				}
 			freeaddrinfo(ai_tcp6);
 		}
 	}