Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

kill builtin incorrectly works with -s -n and -PGID options

8 views
Skip to first unread message

Roman Rakus

unread,
Dec 11, 2009, 8:08:14 AM12/11/09
to Bug-...@gnu.org
kill builtin incorrectly thinks that -PGID is signal name even if the
signal name is set by -s or -n option.

Reproducer:
[rrakus@dhcp-lab-170 ~]$ sleep 1d | sleep 2d | sleep 3d &
[1] 5034
[rrakus@dhcp-lab-170 ~]$ ps -j
PID PGID SID TTY TIME CMD
4863 4863 4863 pts/2 00:00:00 bash
5032 5032 4863 pts/2 00:00:00 sleep
5033 5032 4863 pts/2 00:00:00 sleep
5034 5032 4863 pts/2 00:00:00 sleep
5035 5035 4863 pts/2 00:00:00 ps
[rrakus@dhcp-lab-170 ~]$ kill -s TERM -5032
bash: kill: 5032: invalid signal specification

Patch:
diff -up bash-4.0/builtins/kill.def.pgid bash-4.0/builtins/kill.def
--- bash-4.0/builtins/kill.def.pgid 2009-12-11 13:56:26.000000000 +0100
+++ bash-4.0/builtins/kill.def 2009-12-11 13:58:04.000000000 +0100
@@ -121,6 +121,7 @@ kill_builtin (list)
else
sig = decode_signal (sigspec, dflags);
list = list->next;
+ saw_signal++;
}
else
{

RR


Eric Blake

unread,
Dec 11, 2009, 8:17:36 AM12/11/09
to Roman Rakus, Bug-...@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Roman Rakus on 12/11/2009 6:08 AM:


> kill builtin incorrectly thinks that -PGID is signal name even if the
> signal name is set by -s or -n option.
>

> [rrakus@dhcp-lab-170 ~]$ kill -s TERM -5032
> bash: kill: 5032: invalid signal specification

Not necessarily a bug. POSIX requires that portable shell use:

kill -s TERM -- -5032

when targetting a process group. But it is certainly an area for QoI
enhancement, if Chet wants to accept your patch as an extension allowed by
POSIX.

- --
Don't work too hard, make some time for fun as well!

Eric Blake eb...@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksiRnAACgkQ84KuGfSFAYCAHgCfe+m7Q9wz6++tlwUYaKgC6QtI
zHAAnA+I9JLRBOovsr/gyqcQPqGaZw5e
=aXWm
-----END PGP SIGNATURE-----


Stephane CHAZELAS

unread,
Dec 12, 2009, 5:48:25 AM12/12/09
to
2009-12-11, 06:17(-07), Eric Blake:

>
> According to Roman Rakus on 12/11/2009 6:08 AM:
>> kill builtin incorrectly thinks that -PGID is signal name even if the
>> signal name is set by -s or -n option.
>>
>> [rrakus@dhcp-lab-170 ~]$ kill -s TERM -5032
>> bash: kill: 5032: invalid signal specification
>
> Not necessarily a bug. POSIX requires that portable shell use:
>
> kill -s TERM -- -5032

I don't think so. -- is only necessary as the first argument as
in kill -- -5032.

SUSv4:

To avoid an ambiguity of an initial negative number
argument specifying either a signal number or a process
group, POSIX.1-2008 mandates that it is always considered
the former by implementations that support the XSI option.
It also requires that conforming applications always use
the "--" options terminator argument when specifying a
process group, unless an option is also specified.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So I'd say it's a bug.

Now, pdksh, ash and their derivatives also have that bug (zsh
and AT&T ksh are OK), so the advice to use '--' in any case, in
practice should be followed.

--
Stᅵphane

0 new messages