Bug 10283 - rc.sysinit does not clear /var/run subdirectories
Summary: rc.sysinit does not clear /var/run subdirectories
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: initscripts   
(Show other bugs)
Version: 6.1
Hardware: i386 Linux
medium
low
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-03-21 14:10 UTC by sanderson
Modified: 2014-03-17 02:13 UTC (History)
1 user (show)

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: ---


Attachments (Terms of Use)

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.


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