Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] sudo strace -e <TAB>
- X-seq: zsh-workers 34693
 
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
 
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
 
- Subject: Re: [PATCH] sudo strace -e <TAB>
 
- Date: Mon, 9 Mar 2015 19:57:19 +0000
 
- Cc: zsh-workers@xxxxxxx
 
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=	daniel.shahaf.name; h=x-sasl-enc:date:from:to:cc:subject	:message-id:references:mime-version:content-type:in-reply-to; s=	mesmtp; bh=7GzkhQ8KjgGbsJ2bsFbaew2amyg=; b=teAOip4BqRlJF+r4Sp/sx	dwBsAy8xXfcejW5gPj2+Znkmhd0nE5Ck0IxQMAHj9ARo+LEOxVDznwHwApu/llRD	SBxv2yQXeytwfc8obOwUQxMP0rjCFZsIF8zF07tB6uInv3iIloUZqHJyf3pA0R1W	8gPlltdal7zgLVgLishJFY=
 
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=	messagingengine.com; h=x-sasl-enc:date:from:to:cc:subject	:message-id:references:mime-version:content-type:in-reply-to; s=	smtpout; bh=7GzkhQ8KjgGbsJ2bsFbaew2amyg=; b=VsdQQ8KjaSj62px4KuQu	ZZE1Moa708vJ0ERTf4EP/xX4NUxunbKYMXjf3KBM+jbDMkQNtd3icbzMyfE3E4OX	lM5KyLSSOVCfFt0s8NxYDiQNcS3sLjLc9KXQiLZoT3W7321PAJ7DKepLhyRJO4c5	ctWUa2tRDUERm4CJYSN5eeY=
 
- In-reply-to: <150306234225.ZM12537@torch.brasslantern.com>
 
- List-help: <mailto:zsh-workers-help@zsh.org>
 
- List-id: Zsh Workers List <zsh-workers.zsh.org>
 
- List-post: <mailto:zsh-workers@zsh.org>
 
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
 
- References: <20150307042733.GF2206@tarsus.local2> <150306234225.ZM12537@torch.brasslantern.com>
 
Bart Schaefer wrote on Fri, Mar 06, 2015 at 23:42:25 -0800:
> On Mar 7,  4:27am, Daniel Shahaf wrote:
> } Subject: [PATCH] sudo strace -e <TAB>
> }
> } Is there a smarter way to detect whether -e was passed to sudo?
> 
> Perhaps
> 
>     (( $words[(i)-e] < $words[(i)[^-]*] ))
> 
> would do?  That is, the -e appears before the first word that doesn't
> begin with a hyphen.  The way (i) works in subscripts, the above will
> always be true if all the words begin with a hyphen.
Good idea, but the RHS will evaluate to 1 since the command word doesn't
begin with a hyphen.  This seems to work (with extended_glob):
	(( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] ))
> A slight tweak might fix the problem with -Ae not working:
> 
>     (( $words[(i)-(e|Ae)] < $words[(i)[^-]*] ))
-Ae was just an example, 'sudoedit' takes a few other flags (equivalent
to getopts "AnSC:g:p:u:").  As you can see, some of these flags take
arguments, which may be in separate words.  And then there's the '--'
arguments terminator.
I'm not going to try and handle all those cases.  (How common is
sudoedit -[x] to begin with, anyway?)  The right way is for _arguments
to extract that information and provide it back to _sudo.  (I don't
think that's currently possible; the -> syntax is in the {action} field
and -e doesn't take an argument, so there's no way to specify an
{action} for it.)
Cheers,
Daniel
From 46aed0420bb7b01db8a7ad60fbd2e6d78a0ec087 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
Date: Sat, 7 Mar 2015 15:28:27 +0000
Subject: [PATCH 1/2] _strace: Fix variable leakage of $sys_calls
---
 Completion/Linux/Command/_strace | 1 +
 1 file changed, 1 insertion(+)
diff --git a/Completion/Linux/Command/_strace b/Completion/Linux/Command/_strace
index 45ebfcf..d6dabfd 100644
--- a/Completion/Linux/Command/_strace
+++ b/Completion/Linux/Command/_strace
@@ -5,6 +5,7 @@
 #	- allow negated calls (e.g. -e!write)
 _sys_calls () {
 	local expl
+	local -a sys_calls
 
 	sys_calls=(_llseek _newselect _sysctl accept access acct
 		adjtimex afs_syscall alarm bdflush bind break brk cacheflush
-- 
1.9.1
From 8baf05d0ad7ea482df6329da13c67695085a0d87 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
Date: Sat, 7 Mar 2015 15:31:14 +0000
Subject: [PATCH 2/2] sudo completion: Don't false positive 'sudo -e' detection
---
 Completion/Unix/Command/_sudo | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo
index ee238b4..63ac37f 100644
--- a/Completion/Unix/Command/_sudo
+++ b/Completion/Unix/Command/_sudo
@@ -1,5 +1,7 @@
 #compdef sudo sudoedit
 
+setopt localoptions extended_glob
+
 local environ e
 local -a args
 
@@ -29,7 +31,12 @@ args=(
   '(-v --validate)'{-v,--validate}"[update user's timestamp without running a command]"
 )
 
-if [[ $service = sudoedit || -n ${words[(r)-e]} ]]; then
+# Does -e appears before the first word that doesn't begin with a hyphen?
+# The way (i) works in subscripts, the test will always be true if all the
+# words begin with a hyphen.
+# 
+# TODO: use _arguments' $opt_args to detect the cases '-u jrandom -e' and '-Ae'
+if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] ))  ; then
   args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' )
 else
   args+=(
-- 
1.9.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author