Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version;
        bh=FN8VX+jGXfHKSiCobL6dgTpBAdsNnogaa8kxtn74HQQ=;
        b=gd4o8TqX/R8W3hn+CGwMm5l+L6eyAYAKixHYBK0jKUzR7Eq+gCUSVEWTF8TVM0dHR3
         02yZfsRLxYwEvtrCt+Q9cwSOOo3ckXR3puWgMPBOl7Uhrjhj4V8zjkzzX4dtfZSgUVxK
         NzKBJZI9jq50mMhX07TR8CUfmMTzDfJkTxy8I3XhQIlhHDT1XihuxKrszLk+7EaoiOXZ
         EQWm747BL3+Pni1V7yowQWAaFdGEQ/+biOLruyC5WE1SXMT9IbYQ6YXYW1mrTe5beyFK
         TnTgsR9FN2wuu+oKOFfgVwf4ZmN4cKvat9joWEM3qDxwMpQa8Es1EkzZ3cNI/L8MRRZG
         BYFA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version;
        bh=FN8VX+jGXfHKSiCobL6dgTpBAdsNnogaa8kxtn74HQQ=;
        b=jyJiifmL1Ui6WgKhkqGX8DDcxK20cW12BpxNMTiQtb+jzgY9CGFNVbLr7WMQrYXZTh
         jbcMhLUwRC1lJ0bz20GPUlOjweuEoxIm/jDNSAVCVyWwiCEgu+pO31dP9icVvhrNvFVP
         m/hCADNZnPg9f+P6KAiSyV7B9IirJy0KQaAt4oVZHG8+ULUYMKXnlXO22am1uRDHho/n
         lyGvA7vrcRrsx3V25529G4FUyCg+mV6LZ+M9tCHSb6tu4Ow2FFnBqqKi9jMYHeS21PNb
         CuAfPIw4FleyZ09PqHGXK+mbFVHz+sLUtyg6LtlUkPOAMp/k1MsijYQg5DFQQCYLI7Y8
         FtxA==
X-Gm-Message-State: ALyK8tJa27NRaEgdIKPFF2TsndlyXkQHNL7UiR/xl/1ITt9IryYNajJAkaUibifCOLlmRg==
X-Received: by 10.98.4.195 with SMTP id 186mr22114035pfe.98.1465173113223;
        Sun, 05 Jun 2016 17:31:53 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160605173157.ZM9449@torch.brasslantern.com>
Date: Sun, 5 Jun 2016 17:31:57 -0700
In-Reply-To: <e065be41-429a-d39e-2db1-791e97f8f49a@gmail.com>
Comments: In reply to Matthew Malcomson <hardenedapple@gmail.com>
        "kill builtin argument parsing" (Jun  5,  5:35pm)
References: <e065be41-429a-d39e-2db1-791e97f8f49a@gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: kill builtin argument parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38622

On Jun 5,  5:35pm, Matthew Malcomson wrote:
}
} The command line I used was:
} kill -1 -- <any pid>
} which ends up killing the current Zsh process.

This is a little odd, because the code that examines argv[1] to see if
it is -l or -s or -n or -<NUM> or -<NAME> also checks whether it is
"--", but then simply discards that.  So you can do

    kill -- 12345

to send the default signal to process 12345, you just can't precede
the "--" with any of the other options.  I suspect this is so that
you can do

    kill -- -12345

i.e. force a negative PID in order to kill a process group instead of
having that interpreted as signal number 12345.

Anyway this is clearly incomplete handling of "--".  The patch below
means that

    kill -- --

will report "not enough arguments" rather than complaining about either
an invalid signal or an invalid PID, but that's probably OK.

diff --git a/Src/jobs.c b/Src/jobs.c
index 2a9dbe7..04cb6b3 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -2527,6 +2527,10 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
 	argv++;
     }
 
+    /* Discard the standard "-" and "--" option breaks */
+    if (*argv && (*argv)[0] == '-' && (!(*argv)[1] || (*argv)[1] == '-'))
+	argv++;
+
     if (!*argv) {
     	zwarnnam(nam, "not enough arguments");
 	return 1;

