Bug 10283

Summary: rc.sysinit does not clear /var/run subdirectories
Product: [Retired] Red Hat Linux Reporter: sanderson
Component: initscriptsAssignee: Bill Nottingham <notting>
Status: CLOSED RAWHIDE QA Contact:
Severity: low Docs Contact:
Priority: medium    
Version: 6.1CC: rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-03-21 17:18:24 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description sanderson 2000-03-21 14:10:30 UTC
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/*
   else
      rm -f $afile
   fi
done


However, some programs (sudo in particular), use subdirectories under
/var/run:

/var/run/sudo/user-name/

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)

rm_under_dir()
{
    for xfile in $1/*; do
	if [ -d $xfile ] ; then
	    rm_under_dir $xfile
	else
	    echo $xfile
	fi
    done
}

rm_under_dir "/var/run"
rm_under_dir "/var/lock"


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
code.

Comment 1 Bill Nottingham 2000-03-21 17:18:59 UTC
This is fixed in the current initscripts packages; it clears
all directories except /var/run/news (important for crash
recovery) and /var/run/sudo.