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

Re: [PATCH ALTERNATE] builtins: kill: Do not set signal on current pgroup when pid is empty



Chris Down wrote on Sat, 15 Feb 2020 09:52 -0400:
> 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.

Thanks for the patch and the revisions.  I prefer #2.  If no one
objects (or says POSIX requires «kill ''» to be equivalent to
«kill 0»…) I'll apply it.

It would be nice to have a regression test for this.
Test/C03traps.ztst has the examples, but the test should be added to
a B*.ztst file (probably a new one).  Would you happen to have time to
look into this?  No worries if not.

Cheers,

Daniel

> 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';



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