zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _fuser Solaris and SVR4 support
@ 2005-03-10 15:04 Andrey Borzenkov
  2005-03-11  9:37 ` Oliver Kiddle
  2005-03-11 10:47 ` Danek Duvall
  0 siblings, 2 replies; 10+ messages in thread
From: Andrey Borzenkov @ 2005-03-10 15:04 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 245 bytes --]

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

Completion for SVR4 is not quite right - it should complete
signal names only after -k, but it seems to be too much work.

-andrey

[-- Attachment #2: _fuser.diff --]
[-- Type: text/plain, Size: 2428 bytes --]

Index: Completion/Unix/Command/_fuser
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_fuser,v
retrieving revision 1.1
diff -u -r1.1 _fuser
--- Completion/Unix/Command/_fuser	7 Mar 2005 02:52:30 -0000	1.1
+++ Completion/Unix/Command/_fuser	10 Mar 2005 14:58:43 -0000
@@ -1,17 +1,42 @@
 #compdef fuser
 
-_arguments \
-       '(-s)-a[show all files specified on the command line]' \
-       {-c,-m}'[list all processes accessing files on the filesystem specified by name]' \
-       '-k[kill processes accessing the file]' \
-       '-i[ask for confirmation before killing]' \
-       '-l[list all known signal names]' \
-       '-n[select name space]:namespace:(file udp tcp)' \
-       '(-a)-s[silent operation]' \
-       '-signal[send alternate signal with -k]:signal:_signals' \
-       '-u[append the user name of the process owner to each PID]' \
-       '-v[verbose mode]' \
-       '-V[display version information]' \
-       '-4[search only for IPv4 sockets]' \
-       '-6[search only for IPv6 sockets]' \
-       ':name:_files'
+local -a args arg1
+
+if _pick_variant -c $words[1] gnu=GNU unix -V; then
+  _arguments \
+	 '(-s)-a[show all files specified on the command line]' \
+	 {-c,-m}'[list all processes accessing files on the filesystem specified by name]' \
+	 '-k[kill processes accessing the file]' \
+	 '-i[ask for confirmation before killing]' \
+	 '-l[list all known signal names]' \
+	 '-n[select name space]:namespace:(file udp tcp)' \
+	 '(-a)-s[silent operation]' \
+	 '-signal[send alternate signal with -k]:signal:_signals' \
+	 '-u[append the user name of the process owner to each PID]' \
+	 '-v[verbose mode]' \
+	 '-V[display version information]' \
+	 '-4[search only for IPv4 sockets]' \
+	 '-6[search only for IPv6 sockets]' \
+	 ':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' 
+      )
+    ;;
+    sysv4 )
+      arg1=( ':signal:_signals -p' )
+    ;;
+  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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-10 15:04 [PATCH] _fuser Solaris and SVR4 support Andrey Borzenkov
@ 2005-03-11  9:37 ` Oliver Kiddle
  2005-03-12  7:46   ` Andrey Borzenkov
  2005-03-11 10:47 ` Danek Duvall
  1 sibling, 1 reply; 10+ messages in thread
From: Oliver Kiddle @ 2005-03-11  9:37 UTC (permalink / raw)
  To: zsh-workers

Andrey 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).

Solaris 8 only has the basic set of options so no changes are needed for
it and, presumably, earlier versions.

> Completion for SVR4 is not quite right - it should complete
> signal names only after -k, but it seems to be too much work.

It isn't too hard and it is always very annoying to break file
completion (as this does for Solaris). Does this patch do the right
thing?

Oliver

Index: _fuser
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_fuser,v
retrieving revision 1.2
diff -u -r1.2 _fuser
--- _fuser	10 Mar 2005 18:38:16 -0000	1.2
+++ _fuser	11 Mar 2005 09:31:04 -0000
@@ -1,6 +1,6 @@
 #compdef fuser
 
-local -a args arg1
+local -a args kopt
 
 if _pick_variant -c $words[1] gnu=GNU unix -V; then
   _arguments \
@@ -19,6 +19,7 @@
 	 '-6[search only for IPv6 sockets]' \
 	 ':name:_files'
 else
+  kopt='-k[kill processes accessing the file]'
   case $OSTYPE in
     solaris2.9 )
       args=(
@@ -27,16 +28,15 @@
       )
     ;;
     sysv4 )
-      arg1=( ':signal:_signals -p' )
+      kopt+=':signal:_signals -p'
     ;;
   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]' \
+	 $kopt \
 	 $args \
-	 $arg1 \
 	 ':name:_files'
 fi


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-10 15:04 [PATCH] _fuser Solaris and SVR4 support Andrey Borzenkov
  2005-03-11  9:37 ` Oliver Kiddle
@ 2005-03-11 10:47 ` Danek Duvall
  2005-03-11 11:15   ` Oliver Kiddle
  2005-03-12  7:55   ` Andrey Borzenkov
  1 sibling, 2 replies; 10+ messages in thread
From: Danek Duvall @ 2005-03-11 10:47 UTC (permalink / raw)
  To: Andrey Borzenkov; +Cc: zsh-workers

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-11 10:47 ` Danek Duvall
@ 2005-03-11 11:15   ` Oliver Kiddle
  2005-03-12  7:53     ` Andrey Borzenkov
  2005-03-12  7:55   ` Andrey Borzenkov
  1 sibling, 1 reply; 10+ messages in thread
From: Oliver Kiddle @ 2005-03-11 11:15 UTC (permalink / raw)
  To: Danek Duvall; +Cc: zsh-workers

Danek Duvall wrote:
> 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.

That applies to quite a lot of completion functions then. I suggest we
just stick to $OSTYPE for this for now and worry about fixing the wider
problem separately.

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

Have a look at _finger. It does something very similar in a way that
looks less complicated. If we try something like this, it could be good
if it also handled the psmisc (Linux) implementation of fuser.

Oliver

PS. Imediately after hitting send for my last message I realised that
what I was said about breaking file completion was crap so ignore that.
Sorry.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-11  9:37 ` Oliver Kiddle
@ 2005-03-12  7:46   ` Andrey Borzenkov
  2005-03-21 17:08     ` Oliver Kiddle
  0 siblings, 1 reply; 10+ messages in thread
From: Andrey Borzenkov @ 2005-03-12  7:46 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 849 bytes --]

On Friday 11 March 2005 12:37, Oliver Kiddle wrote:
>
> > Completion for SVR4 is not quite right - it should complete
> > signal names only after -k, but it seems to be too much work.
>
> It isn't too hard and it is always very annoying to break file
> completion (as this does for Solaris). Does this patch do the right
> thing?
>

How does it differ from current completion?

I actually meant - signal names should be completed only if -k is present 
(because they are meaningless without). But currently it is possible to 
implement only using ->state and it seemed too much work for such small 
function.

Will "prerequisite options" be generally useful? I.e. something like

[-a]-b:....

with semantic "-b is offered only if -a is already present". I suspect this 
may have simplified a number of functions.

-andrey


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-11 11:15   ` Oliver Kiddle
@ 2005-03-12  7:53     ` Andrey Borzenkov
  0 siblings, 0 replies; 10+ messages in thread
From: Andrey Borzenkov @ 2005-03-12  7:53 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

On Friday 11 March 2005 14:15, Oliver Kiddle wrote:
> Danek Duvall wrote:
> > 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.
>
> That applies to quite a lot of completion functions then. I suggest we
> just stick to $OSTYPE for this for now and worry about fixing the wider
> problem separately.
>

is OSTYPE readonly? If not immediate workaround is just stick call to 
config.guess somewhere in zshrc.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-11 10:47 ` Danek Duvall
  2005-03-11 11:15   ` Oliver Kiddle
@ 2005-03-12  7:55   ` Andrey Borzenkov
  1 sibling, 0 replies; 10+ messages in thread
From: Andrey Borzenkov @ 2005-03-12  7:55 UTC (permalink / raw)
  To: Danek Duvall, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 384 bytes --]

On Friday 11 March 2005 13:47, Danek Duvall wrote:
> 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 ....
>

OK sorry it is SunOS 5.10 but Solaris 2.10

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-12  7:46   ` Andrey Borzenkov
@ 2005-03-21 17:08     ` Oliver Kiddle
  2005-03-22 18:46       ` Andrey Borzenkov
  0 siblings, 1 reply; 10+ messages in thread
From: Oliver Kiddle @ 2005-03-21 17:08 UTC (permalink / raw)
  To: zsh-workers

On 12 Mar, Andrey wrote:
>
> I actually meant - signal names should be completed only if -k is present 
> (because they are meaningless without). But currently it is possible to 
> implement only using ->state and it seemed too much work for such small 
> function.

Normally we implement that by just checking for $+words[(r)-k]
Does the new patch below now do the right thing?

> Will "prerequisite options" be generally useful? I.e. something like
> 
> [-a]-b:....

They would. But changing _arguments isn't exactly easy. An alternative
syntax might be something like (!-a), mixing them with the exclusion
lists.

Oliver

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	21 Mar 2005 17:02:20 -0000
@@ -27,7 +27,7 @@
       )
     ;;
     sysv4 )
-      arg1=( ':signal:_signals -p' )
+      (( $+words[(r)-k] )) && arg1=( ':signal:_signals -p' )
     ;;
   esac
 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-21 17:08     ` Oliver Kiddle
@ 2005-03-22 18:46       ` Andrey Borzenkov
  2005-03-22 19:28         ` Oliver Kiddle
  0 siblings, 1 reply; 10+ messages in thread
From: Andrey Borzenkov @ 2005-03-22 18:46 UTC (permalink / raw)
  To: zsh-workers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 21 March 2005 20:08, Oliver Kiddle wrote:
> On 12 Mar, Andrey wrote:
> > I actually meant - signal names should be completed only if -k is present
> > (because they are meaningless without). But currently it is possible to
> > implement only using ->state and it seemed too much work for such small
> > function.
>
> Normally we implement that by just checking for $+words[(r)-k]

Oops.

> Does the new patch below now do the right thing?
>

well, except at it turned out it was impossible to complete file name as first 
argument; also fuser takes more than one file.

Is the following the right way to do it?

- -andrey

===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_fuser,v
retrieving revision 1.2
diff -u -p -r1.2 _fuser
- --- Completion/Unix/Command/_fuser      10 Mar 2005 18:38:16 -0000      1.2
+++ Completion/Unix/Command/_fuser      22 Mar 2005 13:16:45 -0000
@@ -27,7 +27,7 @@ else
       )
     ;;
     sysv4 )
- -      arg1=( ':signal:_signals -p' )
+      (( $+words[(r)-k] )) && arg1=( ':signal: _alternative 
signals\:signals\:_signals\ -p files:files:_files' )
     ;;
   esac

@@ -38,5 +38,5 @@ else
         '-u[append the user name of the process owner to each PID]' \
         $args \
         $arg1 \
- -        ':name:_files'
+        '*:name:_files'
 fi

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCQGf0R6LMutpd94wRAmukAKC2NGrLVjGxAs/ezs8D8Fk+UD0fvACdHbFt
8IuJko+PJDQ0EhYXqmKyhqo=
=bH6f
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] _fuser Solaris and SVR4 support
  2005-03-22 18:46       ` Andrey Borzenkov
@ 2005-03-22 19:28         ` Oliver Kiddle
  0 siblings, 0 replies; 10+ messages in thread
From: Oliver Kiddle @ 2005-03-22 19:28 UTC (permalink / raw)
  To: zsh-workers

Andrey wrote:

> well, except at it turned out it was impossible to complete file
> name as first argument; also fuser takes more than one file.
> 
> Is the following the right way to do it?

Yes, that looks right.

Only thing is that the descriptions passed to _alternative should be
in the singular form - "signal" and "file" instead of "signals" and
"files". That's our convention: you're only completing one file (though
more than one may match and the next argument may also be a file). The
"name" description for the final files should probably also be "file".
I'm not posting another patch for that though. I suggest you just commit
it.

Oliver


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-03-22 19:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-10 15:04 [PATCH] _fuser Solaris and SVR4 support Andrey Borzenkov
2005-03-11  9:37 ` Oliver Kiddle
2005-03-12  7:46   ` Andrey Borzenkov
2005-03-21 17:08     ` Oliver Kiddle
2005-03-22 18:46       ` Andrey Borzenkov
2005-03-22 19:28         ` Oliver Kiddle
2005-03-11 10:47 ` Danek Duvall
2005-03-11 11:15   ` Oliver Kiddle
2005-03-12  7:53     ` Andrey Borzenkov
2005-03-12  7:55   ` Andrey Borzenkov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).