Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] _fuser Solaris and SVR4 support



On Thu, Mar 10, 2005 at 06:04:16PM +0300, Andrey Borzenkov wrote:

> I have access to Solaris 9 only so please extend this with
> other versions (BTW Solaris 10 is now 5.10 not 2.10).

Hm?  How's that work?  The zsh that ships with Solaris 10 says solaris2.10
for $OSTYPE ....

Another thing to note is that the value of $OSTYPE is compiled in, so
relying on it may be the wrong thing if zsh is mounted from a shared
directory.  Features also may be backported to older releases, so even the
output of uname -r isn't necessarily going to be right.

Here's a proposed patch that parses the output of "fuser -?".  It works
correctly for Solaris 8, 9, and 10, AFAICT.  Coming up with this was just
too difficult, and someone surely can figure out a better way of doing it.

Index: Completion/Unix/Command/_fuser
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_fuser,v
retrieving revision 1.2
diff -u -r1.2 _fuser
--- Completion/Unix/Command/_fuser	10 Mar 2005 18:38:16 -0000	1.2
+++ Completion/Unix/Command/_fuser	11 Mar 2005 10:46:05 -0000
@@ -1,6 +1,6 @@
 #compdef fuser
 
-local -a args arg1
+local -a args
 
 if _pick_variant -c $words[1] gnu=GNU unix -V; then
   _arguments \
@@ -20,23 +20,54 @@
 	 ':name:_files'
 else
   case $OSTYPE in
-    solaris2.9 )
-      args=(
-	 '-n[list only processes with non-blocking mandatory locks]' 
-	 '-s[send alternate signal with -k]:signal:_signals' 
+    solaris* )
+      local usage b z
+      local -a block arg oarg
+      local -A desc
+
+      usage=${(M)${(f)"$(fuser -\? 2>&1)"}:#Usage*}
+      block=( ${(s:+:)${${${${${${usage[(w)3,(r)files]}[1,(w)-2]}#\[-}%]}//s sig/s}//[\[\]]##/+}} )
+      desc=(
+	c "list all processes accessing files on the filesystem specified by name"
+	d "list all processes accessing minor nodes bound to the same device node"
+	f "list all processes accessing named files"
+	k "kill matched processes with SIGKILL"
+	n "list only processes with non-blocking mandatory locks"
+	s "send signal to matched processes"
+	u "append the user name of the process owner to each PID"
       )
+
+      for b in $block; do
+	if [[ $b == *\|* ]]; then
+	  for z in ${(s:|:)b}; do
+	    if [[ $z == "s" ]]; then
+	      oarg=( -${^${(s:|:)b}:#$z} )
+	      arg=( \($^^oarg\)-$z\[$desc[$z]]:signal:_signals )
+	      args=( $args "$arg" )
+	    else
+	      oarg=( -${^${(s:|:)b}:#$z} )
+	      arg=( \($^^oarg\)-$z\[$desc[$z]] )
+	      args=( $args "$arg" )
+	    fi
+	  done
+	else
+	  for z in ${(s::)b}; do
+	    args=( $args "-${z}[$desc[$z]]")
+	  done
+	fi
+      done
+
+      _arguments $args ':name:_files'
     ;;
     sysv4 )
-      arg1=( ':signal:_signals -p' )
+      _arguments \
+	'(-f)-c[list all processes accessing files on the filesystem specified by name]' \
+	'(-c)-f[list all processes accessing named files]' \
+	'-k[kill processes accessing the file]' \
+	'-u[append the user name of the process owner to each PID]' \
+        ':signal:_signals -p' \
+	':name:_files'
     ;;
   esac
 
-  _arguments \
-	 '(-f)-c[list all processes accessing files on the filesystem specified by name]' \
-	 '(-c)-f[list all processes accessing named files]' \
-	 '-k[kill processes accessing the file]' \
-	 '-u[append the user name of the process owner to each PID]' \
-	 $args \
-	 $arg1 \
-	 ':name:_files'
 fi

Danek



Messages sorted by: Reverse Date, Date, Thread, Author