[svn-commits] tzafrir: branch tools/tzafrir/sysfs r8775 - /tools/team/tzafrir/sysfs/xpp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jun 14 18:27:28 CDT 2010


Author: tzafrir
Date: Mon Jun 14 18:27:25 2010
New Revision: 8775

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8775
Log:
Safer symlink_span operation during 'remove'

* Extract REAL_SPAN_NUM from DEVPATH (on 'remove' the SPAN_NUM attribute
  is 0)
* Use 'find -lname' for quick and safe garbage collection of dead links:
  - We don't assume names without spaces (-print0)
  - We don't iterate over irrelevant links (only those pertaining our target)

Modified:
    tools/team/tzafrir/sysfs/xpp/symlink_span

Modified: tools/team/tzafrir/sysfs/xpp/symlink_span
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/symlink_span?view=diff&rev=8775&r1=8774&r2=8775
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/symlink_span (original)
+++ tools/team/tzafrir/sysfs/xpp/symlink_span Mon Jun 14 18:27:25 2010
@@ -64,7 +64,8 @@
 
 SPAN_NAMES="/dev/dahdi/span-names"
 SPAN_ALIASES="/dev/dahdi/span-aliases"
-LINK_DEST="/dev/dahdi/spans/${SPAN_NUM}"
+REAL_SPAN_NUM=`echo $DEVPATH | sed 's/^.*-//'`
+LINK_DEST="/dev/dahdi/spans/${REAL_SPAN_NUM}"
 
 create_links() {
 	mkdir -p "$SPAN_NAMES"
@@ -97,19 +98,11 @@
 }
 
 remove_links() {
-	for i in "$SPAN_NAMES/"*
-	do
-		if [ -L "$i" ]; then
-			LINK_DEST=`readlink "$i"`
-			REAL_SPAN_NUM=`echo "$DEVPATH" | sed 's/.*-//'`
-			if [ "$LINK_DEST" = "/dev/dahdi/spans/$REAL_SPAN_NUM" ]; then
-				#echo >&2 "$0($ACTION): Removing '$i'"
-				rm -f "$i" 1>&2
-			fi
-		fi
-	done
-	#echo "$0($ACTION): Try to remove '$SPAN_NAMES'"
-	rmdir "$SPAN_NAMES" 1>&2
+	find /dev/dahdi/span-names \
+		-lname "/dev/dahdi/spans/$REAL_SPAN_NUM" -print0 | \
+		xargs -0 rm -f
+	# Try to garbage collect empty directories (if there are)
+	find /dev/dahdi/span-names -type d -print0 | xargs -0 rmdir -p 2> /dev/null
 }
 
 case "$ACTION" in
@@ -123,7 +116,7 @@
 	remove_links 2>&1 | $LOGGER
 	;;
 online)
-	dahdi_cfg -c "$dahdiconfdir/system.conf" -S "$SPAN_NUM" -k 2>&1 | $LOGGER
+	dahdi_cfg -c "$dahdiconfdir/system.conf" -S "$REAL_SPAN_NUM" -k 2>&1 | $LOGGER
 	( echo 1 > "/sys$DEVPATH/user_ready" ) 2>&1 | $LOGGER
 	;;
 esac




More information about the svn-commits mailing list