Long-standing bug in /etc/rc.d/rc.nfsd?
by ZlatkO from LinuxQuestions.org on (#590NY)
I might be wrong, but there seems to be a long-standing bug in /etc/rc.d/rc.nfsd. Here's the code block in question:
Code:[root@disclosure:~]# grep -n -A7 "2.4.x" /etc/rc.d/rc.nfsd
25: # For kernels newer than 2.4.x, use the new way of handling nfs client requests.
26- if [ ! "$(/bin/uname -r | /bin/cut -f 1,2 -d .)" = "2.4" ]; then
27- if grep -wq nfsd /proc/filesystems 2> /dev/null ; then
28- if grep -vwq nfsd /proc/mounts 2> /dev/null ; then
29- /sbin/mount -t nfsd nfsd /proc/fs/nfs 2> /dev/null
30- fi
31- fi
32- fiThe intention in line# 28 seems to be "if there is no entry of type nfsd in /proc/mounts yet", but the actual semantics of the chosen grep invocation are "if any other fs type besides nfsd has been mounted already". At the time this script runs, at least the root fs will have been mounted already, so the grep will always return true, and the if-clause might as well be left off altogether.
The following patch changes the grep invocation to match the intended semantics of the if-clause:
Code:--- rc.nfsd.orig 2008-04-01 05:09:11.000000000 +0200
+++ rc.nfsd 2008-08-16 15:56:14.000000000 +0200
@@ -25,7 +25,7 @@
# For kernels newer than 2.4.x, use the new way of handling nfs client requests.
if [ ! "$(/bin/uname -r | /bin/cut -f 1,2 -d .)" = "2.4" ]; then
if grep -wq nfsd /proc/filesystems 2> /dev/null ; then
- if grep -vwq nfsd /proc/mounts 2> /dev/null ; then
+ if ! grep -wq nfsd /proc/mounts 2> /dev/null ; then
/sbin/mount -t nfsd nfsd /proc/fs/nfs 2> /dev/null
fi
fiComments welcome & appreciated! :)


Code:[root@disclosure:~]# grep -n -A7 "2.4.x" /etc/rc.d/rc.nfsd
25: # For kernels newer than 2.4.x, use the new way of handling nfs client requests.
26- if [ ! "$(/bin/uname -r | /bin/cut -f 1,2 -d .)" = "2.4" ]; then
27- if grep -wq nfsd /proc/filesystems 2> /dev/null ; then
28- if grep -vwq nfsd /proc/mounts 2> /dev/null ; then
29- /sbin/mount -t nfsd nfsd /proc/fs/nfs 2> /dev/null
30- fi
31- fi
32- fiThe intention in line# 28 seems to be "if there is no entry of type nfsd in /proc/mounts yet", but the actual semantics of the chosen grep invocation are "if any other fs type besides nfsd has been mounted already". At the time this script runs, at least the root fs will have been mounted already, so the grep will always return true, and the if-clause might as well be left off altogether.
The following patch changes the grep invocation to match the intended semantics of the if-clause:
Code:--- rc.nfsd.orig 2008-04-01 05:09:11.000000000 +0200
+++ rc.nfsd 2008-08-16 15:56:14.000000000 +0200
@@ -25,7 +25,7 @@
# For kernels newer than 2.4.x, use the new way of handling nfs client requests.
if [ ! "$(/bin/uname -r | /bin/cut -f 1,2 -d .)" = "2.4" ]; then
if grep -wq nfsd /proc/filesystems 2> /dev/null ; then
- if grep -vwq nfsd /proc/mounts 2> /dev/null ; then
+ if ! grep -wq nfsd /proc/mounts 2> /dev/null ; then
/sbin/mount -t nfsd nfsd /proc/fs/nfs 2> /dev/null
fi
fiComments welcome & appreciated! :)