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

Re: kill builtin argument parsing



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;



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