In /etc/rc.d/rc.sysinit, there is a section that is supposed to clear old
lock and runtime files:
# Clean up /var
# I'd use find, but /usr may not be mounted.
for afile in /var/lock/* /var/run/*; do
if [ -d $afile ]; then
rm -f $afile/*
rm -f $afile
However, some programs (sudo in particular), use subdirectories under
The rc.sysinit code will handle single-level subdirectories, but not
multiple-level subdirectories like the above example.
The following will properly handle nested subdirectories:
# rm_under_dir() - Scott Anderson 3-21-2000
# to properly handle nested subdirs under /var/run (as
# with 'sudo' runtime directories)
for xfile in $1/*; do
if [ -d $xfile ] ; then
You might wish to add some sort of counter to detect rediculously nested
directories (some sort of DOS attack). Alternatively, simply replace "rm
-f $afile/*" in the original script with "rm -f -r $afile/*". Such a
solution will remove directories as well, instead of files only as with my
This is fixed in the current initscripts packages; it clears
all directories except /var/run/news (important for crash
recovery) and /var/run/sudo.