diff options
author | jilles <jilles@FreeBSD.org> | 2010-12-21 22:47:34 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-12-21 22:47:34 +0000 |
commit | ae2aabc34981e0a4fc74b41bde3cfd6ff4166022 (patch) | |
tree | 571f5b4935a3ac4f69aff2b5cfb327687b1f59fe /bin/sh | |
parent | 0a77d10ec99ee3d8cfd396b81e6fb1d1a9c4e1de (diff) | |
download | FreeBSD-src-ae2aabc34981e0a4fc74b41bde3cfd6ff4166022.zip FreeBSD-src-ae2aabc34981e0a4fc74b41bde3cfd6ff4166022.tar.gz |
sh: Add kill builtin.
This allows specifying a %job (which is equivalent to the corresponding
process group).
Additionally, it improves reliability of kill from sh in high-load
situations and ensures "kill" finds the correct utility regardless of PATH,
as required by POSIX (unless the undocumented %builtin mechanism is used).
Side effect: fatal errors (any error other than kill(2) failure) now return
exit status 2 instead of 1. (This is consistent with other sh builtins, but
not in NetBSD.)
Code size increases about 1K on i386.
Obtained from: NetBSD
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/Makefile | 3 | ||||
-rw-r--r-- | bin/sh/bltin/bltin.h | 5 | ||||
-rw-r--r-- | bin/sh/builtins.def | 1 | ||||
-rw-r--r-- | bin/sh/jobs.c | 8 | ||||
-rw-r--r-- | bin/sh/sh.1 | 7 |
5 files changed, 22 insertions, 2 deletions
diff --git a/bin/sh/Makefile b/bin/sh/Makefile index a606c9b..47642df 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -4,7 +4,7 @@ PROG= sh INSTALLFLAGS= -S SHSRCS= alias.c arith.y arith_lex.l cd.c echo.c error.c eval.c exec.c expand.c \ - histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \ + histedit.c input.c jobs.c kill.c mail.c main.c memalloc.c miscbltin.c \ mystring.c options.c output.c parser.c printf.c redir.c show.c \ test.c trap.c var.c GENSRCS= builtins.c init.c nodes.c syntax.c @@ -26,6 +26,7 @@ WARNS?= 2 WFORMAT=0 .PATH: ${.CURDIR}/bltin \ + ${.CURDIR}/../kill \ ${.CURDIR}/../test \ ${.CURDIR}/../../usr.bin/printf diff --git a/bin/sh/bltin/bltin.h b/bin/sh/bltin/bltin.h index f6e7883..e449673 100644 --- a/bin/sh/bltin/bltin.h +++ b/bin/sh/bltin/bltin.h @@ -43,6 +43,7 @@ #include "../mystring.h" #ifdef SHELL #include "../output.h" +#define FILE struct output #undef stdout #define stdout out1 #undef stderr @@ -58,6 +59,7 @@ #define fflush flushout #define INITARGS(argv) #define warnx warning +#define warn(fmt, ...) warning(fmt ": %s", __VA_ARGS__, strerror(errno)) #define errx(exitstatus, ...) error(__VA_ARGS__) #else @@ -67,8 +69,11 @@ #define INITARGS(argv) if ((commandname = argv[0]) == NULL) {fputs("Argc is zero\n", stderr); exit(2);} else #endif +#include <unistd.h> + pointer stalloc(int); void error(const char *, ...) __printf0like(1, 2); +pid_t getjobpgrp(char *); int echocmd(int, char **); int testcmd(int, char **); diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def index b72f887..cfc6361 100644 --- a/bin/sh/builtins.def +++ b/bin/sh/builtins.def @@ -70,6 +70,7 @@ hashcmd hash histcmd -h fc jobidcmd jobid jobscmd jobs +killcmd kill localcmd local printfcmd printf pwdcmd pwd diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index 6a781ea..fda167b 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -632,6 +632,14 @@ currentjob: if ((jp = getcurjob(NULL)) == NULL) } +pid_t +getjobpgrp(char *name) +{ + struct job *jp; + + jp = getjob(name); + return -jp->ps[0].pid; +} /* * Return a new job structure, diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index a6fd7be..8f92bbb 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd December 3, 2010 +.Dd December 21, 2010 .Dt SH 1 .Os .Sh NAME @@ -2049,6 +2049,10 @@ If the .Fl s option is specified, only the PIDs of the job commands are printed, one per line. +.It Ic kill +A built-in equivalent of +.Xr kill 1 +that additionally supports sending signals to jobs. .It Ic local Oo Ar variable ... Oc Op Fl See the .Sx Functions @@ -2477,6 +2481,7 @@ will return the argument. .Xr echo 1 , .Xr ed 1 , .Xr emacs 1 , +.Xr kill 1 , .Xr printf 1 , .Xr pwd 1 , .Xr test 1 , |