Bug 10283 - rc.sysinit does not clear /var/run subdirectories
rc.sysinit does not clear /var/run subdirectories
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: initscripts (Show other bugs)
6.1
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Bill Nottingham
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-03-21 09:10 EST by sanderson
Modified: 2014-03-16 22:13 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-03-21 12:18:24 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description sanderson 2000-03-21 09:10:30 EST
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 12:18:59 EST
This is fixed in the current initscripts packages; it clears
all directories except /var/run/news (important for crash
recovery) and /var/run/sudo.

Note You need to log in before you can comment on or make changes to this bug.