From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id b118c584 for ; Sat, 15 Feb 2020 13:53:42 +0000 (UTC) Received: (qmail 12327 invoked by alias); 15 Feb 2020 13:53:34 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45430 Received: (qmail 11785 invoked by uid 1010); 15 Feb 2020 13:53:34 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr1-f66.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25718. spamassassin: 3.4.2. Clear:RC:0(209.85.221.66):SA:0(-2.0/5.0):. Processed in 3.660513 secs); 15 Feb 2020 13:53:34 -0000 X-Envelope-From: chris@chrisdown.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.221.66 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:in-reply-to; bh=U8lzOYl8zDYn8KvVdbJJMxPXDjjg80C1D51gwm8LrIc=; b=qWvdhbFavQZyZ7WLfDLEMzzPhr05GQrrUPBumZyLs9tfP5AEoNp3LuS0RJcpJiNDhP SQ7Xyuq6HLcST0DPTUmlvvPsMV6kPep4sxtJVS59XLyaGi6a4Q+PAN46y74bk+9Hi8Yq +5eb2DMJebw+jgwTeZ77e2tWX0eJVqWxO/F+CN884wiAr+SDYeBCgRQh0b2WijrtRz+0 a64DiiJYrtxXiIzR0GnMXKnfqr9j8wvlI8JaAr0BDDd+4GaxJkCLWUjJwUx6p1UOuEhK G4mLEyDWe/ggX4b67fCzwwiASS0EbQWpML5+vkyGBgLrLEYG72XTCregYWUCSAKrte5J wPeA== X-Gm-Message-State: APjAAAVLB0xzqnwxCtl8R0ef5bWTgtS9LrqlT4ExKdI5pesF4zqDx581 e8Kj9H3lPUZeV14/9sZEm+d5aHkFNV1eqw== X-Google-Smtp-Source: APXvYqypwbtHsBZsRj7XLZrYetov68THqWbDFLVh7uj3U+U7+AUY+YV4Xo9hLigzK+o2COKaiNtyVw== X-Received: by 2002:a5d:494f:: with SMTP id r15mr10576062wrs.143.1581774775130; Sat, 15 Feb 2020 05:52:55 -0800 (PST) Date: Sat, 15 Feb 2020 09:52:48 -0400 From: Chris Down To: zsh-workers@zsh.org Subject: [PATCH ALTERNATE] builtins: kill: Do not set signal on current pgroup when pid is empty Message-ID: <20200215135248.GA662294@chrisdown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200214151556.GA624243@chrisdown.name> This was first noticed in the `kill` builtin: % zsh; echo "$?" % trap 'exit 5' TERM % kill '' 5 This behaviour seems more likely to be the result of bugs in programs (eg. `kill -9 "$unsetvar") rather than be desirable behaviour to me. It seems unintentional judging by the code and documentation, since it comes about as a result of the fact that: - `isanum` returns true for empty strings (since an empty string technically only consists of digits and minuses...); - `atoi`, when passed a pointer to an invalid number, returns 0; - kill(0, signal) sends the signal in question to all processes in the current process group. There are two ways to solve this issue: 1. Add special handling to `kill` to avoid this case. See this patch[0] for a version that does that. 2. Change how isanum behaves. Since the only two call sites that use it both seem like they should handle the case where the input char array is empty, that seems like a reasonable overall change to me, but either works. After this patch: % trap 'exit 5' TERM % kill '' kill: illegal pid: 0: https://www.zsh.org/mla/workers/2020/msg00251.html --- Src/jobs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Src/jobs.c b/Src/jobs.c index e7438251e..0485f2c7c 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1854,13 +1854,14 @@ scanjobs(void) /* This simple function indicates whether or not s may represent * * a number. It returns true iff s consists purely of digits and * - * minuses. Note that minus may appear more than once, and the empty * - * string will produce a `true' response. */ + * minuses. Note that minus may appear more than once. */ /**/ static int isanum(char *s) { + if (*s == '\0') + return 0; while (*s == '-' || idigit(*s)) s++; return *s == '\0'; -- 2.25.0