X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=builtins%2Fkill.def;h=d7aba5b6d2fe374632ee56e5ecf9829a559583c0;hb=f73dda092b33638d2d5e9c35375f687a607b5403;hp=ea78bd52c49f6ce5e83a266b87fefcc1e0cba57b;hpb=d166f048818e10cf3799aa24a174fb22835f1acc;p=platform%2Fupstream%2Fbash.git diff --git a/builtins/kill.def b/builtins/kill.def index ea78bd5..d7aba5b 100644 --- a/builtins/kill.def +++ b/builtins/kill.def @@ -7,7 +7,7 @@ This file is part of GNU Bash, the Bourne Again SHell. Bash is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 1, or (at your option) any later +Software Foundation; either version 2, or (at your option) any later version. Bash is distributed in the hope that it will be useful, but WITHOUT ANY @@ -17,7 +17,7 @@ for more details. You should have received a copy of the GNU General Public License along with Bash; see the file COPYING. If not, write to the Free Software -Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. $PRODUCES kill.c @@ -39,6 +39,9 @@ $END #include #include #if defined (HAVE_UNISTD_H) +# ifdef _MINIX +# include +# endif # include #endif @@ -55,8 +58,6 @@ extern int errno; #endif /* !errno */ #if defined (JOB_CONTROL) -extern int interactive; -extern int job_control; extern int posixly_correct; #if !defined (CONTINUE_AFTER_KILL_ERROR) @@ -75,9 +76,13 @@ kill_builtin (list) int signal, any_succeeded, listing, saw_signal; char *sigspec, *word; pid_t pid; + long pid_value; if (list == 0) - return (EXECUTION_SUCCESS); + { + builtin_usage (); + return (EXECUTION_FAILURE); + } any_succeeded = listing = saw_signal = 0; signal = SIGTERM; @@ -145,6 +150,12 @@ kill_builtin (list) return (EXECUTION_FAILURE); } + if (list == 0) + { + builtin_usage (); + return (EXECUTION_FAILURE); + } + while (list) { word = list->word->word; @@ -152,22 +163,22 @@ kill_builtin (list) if (*word == '-') word++; - if (all_digits (word)) + if (*word && legal_number (word, &pid_value) && (pid_value == (pid_t)pid_value)) { /* Use the entire argument in case of minus sign presence. */ - pid = (pid_t) atoi (list->word->word); + pid = (pid_t) pid_value; if (kill_pid (pid, signal, 0) < 0) goto signal_error; else any_succeeded++; } - else if (*list->word->word != '%') + else if (*list->word->word && *list->word->word != '%') { builtin_error ("%s: no such pid", list->word->word); CONTINUE_OR_FAIL; } - else if (interactive || job_control) + else if (*word && (interactive || job_control)) /* Posix.2 says you can kill without job control active (4.32.4) */ { /* Must be a job spec. Check it out. */ int job; @@ -195,12 +206,10 @@ kill_builtin (list) if (kill_pid (pid, signal, 1) < 0) { signal_error: - if (errno == EPERM) - builtin_error ("(%d) - Not owner", (int)pid); - else if (errno == ESRCH) - builtin_error ("(%d) - No such pid", (int)pid); - else + if (errno == EINVAL) builtin_error ("Invalid signal %d", signal); + else + builtin_error ("(%ld) - %s", (long)pid, strerror (errno)); CONTINUE_OR_FAIL; } else @@ -208,7 +217,7 @@ kill_builtin (list) } else { - builtin_error ("`%s' is not a pid or valid job spec", list->word->word); + builtin_error ("`%s': not a pid or valid job spec", list->word->word); CONTINUE_OR_FAIL; } continue_killing: