GrepUpgradeBreaksDevPts

From NAS-Central Buffalo - The Linkstation Wiki
Revision as of 17:23, 1 July 2007 by Aspiers (Talk)

Jump to: navigation, search

If you upgrade from the firmware's grep to one of the newer packaged ones floating around, you might find that all of a sudden your telnetd and sshd services don't work. This is most likely because devpts isn't being correctly mounted on /dev/pts any more. Let's take a close look at /etc/init.d/devpts.sh:

 devpts_avail=$(grep -qci '[<[:space:]]devpts' /proc/filesystems || true)
 devpts_mounted=$(grep -qci '/dev/pts' /proc/mounts || true)
 devfs_mounted=$(grep -qci '[<[:space:]]/dev[>[:space:]].*devfs' /proc/mounts || true)

Look at the impact of upgrading grep:

 root@HD-HTGLD03 ~ # grep devpts /proc/filesystems
 nodev   devpts
 root@HD-HTGLD03 ~ # ./grep.old -qci devpts /proc/filesystems
 1
 root@HD-HTGLD03 ~ # grep -qci devpts /proc/filesystems
 root@HD-HTGLD03 ~ #

Oops! The new grep has different behaviour with respect to -qc: it assumes (correctly) that the user does not want any output. This devpts.sh script relies on the dodgy behaviour of the old grep which still issues a match count even when -q is specified.

The fix is to remove the -q switch from the script:

 devpts_avail=$(grep -ci '[<[:space:]]devpts' /proc/filesystems || true)
 devpts_mounted=$(grep -ci '/dev/pts' /proc/mounts || true)
 devfs_mounted=$(grep -ci '[<[:space:]]/dev[>[:space:]].*devfs' /proc/mounts || true)

--Aspiers 19:21, 1 July 2007 (CEST)