/etc/rc: clearing /tmp with files having flags

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jiri B.
Date: Saturday, December 4, 2010 - 4:37 am

Hi,

I was playing with file flags in /tmp, after reboot I saw
that /etc/rc cannot `rm' files with flags.

OK, my stupidity to keep those files but maybe following patch
to /etc/rc could be useful (my sed kungfu is not nice but using
awk I got quoting trouble).

jirib

Index: rc
===================================================================
RCS file: /cvs/src/etc/rc,v
retrieving revision 1.345
diff -u -p -r1.345 rc
--- rc	8 Nov 2010 19:44:36 -0000	1.345
+++ rc	4 Dec 2010 11:32:46 -0000
@@ -542,10 +542,15 @@ echo clearing /tmp
 
 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
 # (not needed with mfs /tmp, but doesn't hurt there...)
-(cd /tmp && rm -rf [a-km-pr-zA-Z]*)
+(cd /tmp && rm -rf [a-km-pr-zA-Z]* 2>/dev/null)
 (cd /tmp &&
-    find . ! -name . ! -name lost+found ! -name quota.user \
-	! -name quota.group -execdir rm -rf -- {} \; -type d -prune)
+    find . ! -name . ! -name lost+found ! -name quota.user ! -name quota.group \
+	-execdir sh -c 'i="{}"
+	flag="`ls -ldo $i | sed "s/\([^ ]*\)\  \([^ ]*\)\ \([^ ]*\)\  \([^ ]*\)\  \([^ ]*\)\(.*\)/\5/"`"
+	if [ X"$flag" != X"-" ]; then
+	chflags -R nosappnd,noschg,nouappnd,nouchg $i
+	fi
+    rm -rf -- $i' \; -type d -prune)
 
 # create Unix sockets directories for X if needed and make sure they have
 # correct permissions
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
/etc/rc: clearing /tmp with files having flags, Jiri B., (Sat Dec 4, 4:37 am)
Re: /etc/rc: clearing /tmp with files having flags, Ingo Schwarze, (Sat Dec 4, 5:53 am)
Re: /etc/rc: clearing /tmp with files having flags, Ted Unangst, (Sat Dec 4, 9:24 am)
Re: /etc/rc: clearing /tmp with files having flags, Eric Furman, (Sat Dec 4, 9:48 am)