Subject: Beware of stale executables in /bin and /sbin
To: None <current-users@NetBSD.ORG>
From: Brian C. Grayson <bgrayson@ece.utexas.edu>
List: current-users
Date: 08/04/1997 23:10:09
  Recently, when upgrading to current, I was also suffering from
NFS mount permission problems, which weren't resolved with adding
-P and -noresvport options, and I eventually tracked it to
the fact that mountd has moved from /sbin to /usr/sbin.
However, the ``stale'' mountd in /sbin was never deleted, and
since /sbin is on root's path before /usr/sbin (see default
/root/.profile file in /usr/src/etc/root/dot.profile), our NFS
server was running the old /sbin/mountd.

  (Quick aside:  is there a reason ``sysctl user.cs_path''
returns /usr/bin:/bin:/usr/sbin:/sbin:... while root's path is
/sbin:/usr/sbin:/bin:/usr/bin?  Why the different ordering?)

  I know for a fact that at least one other NetBSD user has been
bitten by this as well.  There is no good mechanism for tracking
current that will automagically delete such stale binaries when
an executable moves, is there?  I can't think of any.

  Anyway, to help other people see if their system is affected, I
wrote the following script, which checks for executables with
the same name in /bin, /sbin, /usr/bin, and /usr/sbin, and lists
them.  It's a quick hack, but it works.  Sample output from one
of our systems is also included below.  This might be a handy
thing to add to /etc/daily for current-trackers, or to the end
of the ``make build'' command (or to a ``make sanitycheck'' target?).
----------------------
#!/bin/sh
##  Quick program by Brian Grayson (bgrayson@ece.utexas.edu) to
## look for ``stale'' executables in common directories.
tmp=/tmp/bindup.$$

##  Add /usr/local/bin or any other such paths here if you want.
for dir in /bin /sbin /usr/bin /usr/sbin ; do
  cd $dir
  for f in *; do
    echo $f $dir/$f >> $tmp
  done
done
cat $tmp | sort | awk '
{
  if ($1 == f) print $2, full;
  f = $1;
  full = $2;
}
' | xargs -n 2 ls -l > $tmp.result
if [ -s $tmp.result ]; then
  echo "Duplicate executables were found:"
  cat $tmp.result
fi
rm $tmp $tmp.result
----------------------

  Sample output:
Duplicate executables were found:
-r-xr-xr-x  1 bin  bin  53248 May  5 17:02 /sbin/dumpfs
-r-xr-xr-x  1 bin  bin  16384 Jul 28 12:51 /usr/sbin/dumpfs
-r-xr-xr-x  1 bin  bin  53248 May  5 17:02 /sbin/dumplfs
-r-xr-xr-x  1 bin  bin  16384 Jul 28 12:51 /usr/sbin/dumplfs
-r-xr-xr-x  1 bin  bin  57344 Apr 16  1996 /usr/bin/host
-r-xr-xr-x  1 bin  bin  65536 Jul 28 12:52 /usr/sbin/host
-r-xr-xr-x  1 bin  bin  61440 Mar 27 11:59 /sbin/nfsd
-r-xr-xr-x  1 bin  bin  12288 Jul 28 12:52 /usr/sbin/nfsd
-r-xr-xr-x  1 bin  bin  53248 Mar 27 11:59 /sbin/nfsiod
-r-xr-xr-x  1 bin  bin  12288 Jul 28 12:52 /usr/sbin/nfsiod
-r-xr-xr-x  1 bin  bin  135168 May  5 17:01 /sbin/quotacheck
-r-xr-xr-x  1 bin  bin   20480 Jul 28 12:52 /usr/sbin/quotacheck
-r-xr-xr-x  1 bin  bin  118784 May  5 17:02 /sbin/rtquery
-r-xr-xr-x  1 bin  bin  118784 Jul 28 12:47 /usr/sbin/rtquery

  For all of these, the /usr/sbin version is the correct (newer)
one.  I can save nearly .5MB on my / partition by deleting the
stale versions, if nothing else.

  Hope this saves someone else a few minutes/hours of debugging!

  Brian
-- 
Brian Grayson (bgrayson@ece.utexas.edu)
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office:  ENS 406       (512) 471-8011
Finger bgrayson@orac.ece.utexas.edu for PGP key.