zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] builtins: kill: Do not set signal on current shell when pid is empty
@ 2020-02-14 15:15 Chris Down
  2020-02-14 16:02 ` Chris Down
  2020-02-15 13:52 ` [PATCH ALTERNATE] builtins: kill: Do not set signal on current pgroup " Chris Down
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Down @ 2020-02-14 15:15 UTC (permalink / raw)
  To: zsh-workers

As an example:

    % 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 `isanum` returns true for empty strings
(since an empty string technically only consists of digits and
minuses...) and `atoi`, when passed a pointer to an invalid number,
returns 0.

With this patch:

    % trap 'exit 5' TERM
    % kill ''
    kill: empty pid provided
---
 Src/jobs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Src/jobs.c b/Src/jobs.c
index e7438251e..a64368e10 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -2745,6 +2745,9 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
 	} else if (!isanum(*argv)) {
 	    zwarnnam("kill", "illegal pid: %s", *argv);
 	    returnval++;
+	} else if ((*argv)[0] == '\0')  {
+	    zwarnnam("kill", "empty pid provided");
+	    returnval++;
 	} else {
 	    int pid = atoi(*argv);
 	    if (kill(pid, sig) == -1) {
-- 
2.25.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-15 15:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 15:15 [PATCH] builtins: kill: Do not set signal on current shell when pid is empty Chris Down
2020-02-14 16:02 ` Chris Down
2020-02-15 13:52 ` [PATCH ALTERNATE] builtins: kill: Do not set signal on current pgroup " Chris Down
2020-02-15 14:10   ` Daniel Shahaf
2020-02-15 15:15     ` Chris Down

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).