Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Feb 2023 22:10:23 GMT
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: fe5c211ba873 - main - nfsd.c: Log a more meaningful failure message
Message-ID:  <202302222210.31MMANLQ081919@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by rmacklem:

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

commit fe5c211ba87315b098769a7e6d50b41f00f6fed4
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2023-02-22 22:09:15 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2023-02-22 22:09:15 +0000

    nfsd.c: Log a more meaningful failure message
    
    For the cases where the nfsd(8) daemon is already running or
    has failed to start within a prison due to an incorrect prison
    configuration, the failure message logged is:
      Can't read stable storage file: operation not permitted
    
    This patch replaces the above with more meaningful messages.
    It depends on commit 10dff9da9748 to differentiate between the
    above two cases, however even without this commit, the messages
    should be an improvement.
    
    MFC after:      3 months
---
 usr.sbin/nfsd/nfsd.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/nfsd/nfsd.c b/usr.sbin/nfsd/nfsd.c
index 0222d23f2312..3a7f58c7b4e5 100644
--- a/usr.sbin/nfsd/nfsd.c
+++ b/usr.sbin/nfsd/nfsd.c
@@ -170,8 +170,8 @@ main(int argc, char **argv)
 	int udpflag, ecode, error, s;
 	int bindhostc, bindanyflag, rpcbreg, rpcbregcnt;
 	int nfssvc_addsock;
-	int longindex = 0;
-	size_t nfs_minvers_size;
+	int jailed, longindex = 0;
+	size_t jailed_size, nfs_minvers_size;
 	const char *lopt;
 	char **bindhost = NULL;
 	pid_t pid;
@@ -465,7 +465,21 @@ main(int argc, char **argv)
 	/* This system call will fail for old kernels, but that's ok. */
 	nfssvc(NFSSVC_BACKUPSTABLE, NULL);
 	if (nfssvc(NFSSVC_STABLERESTART, (caddr_t)&stablefd) < 0) {
-		syslog(LOG_ERR, "Can't read stable storage file: %m\n");
+		if (errno == EPERM) {
+			jailed = 0;
+			jailed_size = sizeof(jailed);
+			sysctlbyname("security.jail.jailed", &jailed,
+			    &jailed_size, NULL, 0);
+			if (jailed != 0)
+				syslog(LOG_ERR, "nfssvc stablerestart failed: "
+				    "allow.nfsd might not be configured");
+			else
+				syslog(LOG_ERR, "nfssvc stablerestart failed");
+		} else if (errno == ENXIO)
+			syslog(LOG_ERR, "nfssvc stablerestart failed: is nfsd "
+			    "already running?");
+		else
+			syslog(LOG_ERR, "Can't read stable storage file: %m\n");
 		exit(1);
 	}
 	nfssvc_addsock = NFSSVC_NFSDADDSOCK;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302222210.31MMANLQ081919>