From owner-freebsd-audit Fri Nov 9 12:39:27 2001 Delivered-To: freebsd-audit@freebsd.org Received: from mail.musha.org (daemon.musha.org [61.122.44.178]) by hub.freebsd.org (Postfix) with ESMTP id 1127E37B41B for ; Fri, 9 Nov 2001 12:39:20 -0800 (PST) Received: from archon.local.idaemons.org (archon.local.idaemons.org [192.168.1.32]) by mail.musha.org (Postfix) with ESMTP id 92C484D83D for ; Sat, 10 Nov 2001 05:39:18 +0900 (JST) Date: Sat, 10 Nov 2001 05:39:18 +0900 Message-ID: <86n11vel1l.wl@archon.local.idaemons.org> From: "Akinori MUSHA" To: audit@FreeBSD.org Subject: make test(1) a sh(1) builtin command User-Agent: Wanderlust/2.7.5 (Too Funky) SEMI/1.14.3 (Ushinoya) LIMIT/1.14.7 (Fujiidera) APEL/10.3 MULE XEmacs/21.1 (patch 14) (Cuyahoga Valley) (i386--freebsd) Organization: Associated I. Daemons X-PGP-Public-Key: finger knu@FreeBSD.org X-PGP-Fingerprint: 081D 099C 1705 861D 4B70 B04A 920B EFC7 9FD9 E1EE MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, Why don't we make test(1) a sh(1) builtin command? As we all know, test(1) is one of the most frequently used commands, so making it shell builtin will greatly reduce forking and peak memory usage. Another interest is expr(1), which can sometimes be used repeatedly in a script, however, because it uses regex to provide the `:' operation the binary size increase is so big it might not pay. Currently printf(1) is builtin but it does not seem to be used that often, so it could be an option to remove it if the size increase that the addition of test(1) causes were going to be a problem. For your information, the sizes of the resulted sh binaries are as follows: printf test expr size: N N N 633,148 bytes Y N N 636,456 bytes (original) N Y N 636,964 bytes (*) Y Y N 640,240 bytes (my suggestion) N Y Y 645,928 bytes Y Y Y 649,268 bytes (*) NetBSD's sh(1) already included test as a builtin command in place of printf. I think it would be a great trade to pay just 0.6% size increase for a test(1) builtin command. What do you guys think? -- / /__ __ Akinori.org / MUSHA.org / ) ) ) ) / FreeBSD.org / Ruby-lang.org Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp "Somewhere out of a memory.. of lighted streets on quiet nights.." Index: share/man/man1/builtin.1 =================================================================== RCS file: /home/ncvs/src/share/man/man1/builtin.1,v retrieving revision 1.13 diff -u -r1.13 builtin.1 --- share/man/man1/builtin.1 8 Aug 2001 11:48:26 -0000 1.13 +++ share/man/man1/builtin.1 9 Nov 2001 19:10:22 -0000 @@ -60,6 +60,7 @@ .Nm exec , .Nm exit , .Nm export , +.Nm false , .Nm fc , .Nm fg , .Nm filetest , @@ -107,9 +108,11 @@ .Nm suspend , .Nm switch , .Nm telltc , +.Nm test , .Nm then , .Nm time , .Nm trap , +.Nm true , .Nm type , .Nm ulimit , .Nm umask , @@ -198,6 +201,7 @@ .It Ic exec Ta \&No Ta Yes Ta Yes .It Ic exit Ta \&No Ta Yes Ta Yes .It Ic export Ta \&No Ta \&No Ta Yes +.It Ic false Ta Yes Ta \&No Ta Yes .It Ic fc Ta \&No Ta \&No Ta Yes .It Ic fg Ta \&No Ta Yes Ta Yes .It Ic filetest Ta \&No Ta Yes Ta \&No @@ -245,9 +249,11 @@ .It Ic suspend Ta \&No Ta Yes Ta \&No .It Ic switch Ta \&No Ta Yes Ta \&No .It Ic telltc Ta \&No Ta Yes Ta \&No +.It Ic test Ta Yes Ta \&No Ta Yes .It Ic then Ta \&No Ta \&No Ta Yes .It Ic time Ta Yes Ta Yes Ta \&No .It Ic trap Ta \&No Ta \&No Ta Yes +.It Ic true Ta Yes Ta \&No Ta Yes .It Ic type Ta \&No Ta \&No Ta Yes .It Ic ulimit Ta \&No Ta \&No Ta Yes .It Ic umask Ta \&No Ta Yes Ta Yes Index: bin/sh/Makefile =================================================================== RCS file: /home/ncvs/src/bin/sh/Makefile,v retrieving revision 1.30 diff -u -r1.30 Makefile --- bin/sh/Makefile 8 Sep 1999 15:40:43 -0000 1.30 +++ bin/sh/Makefile 9 Nov 2001 18:53:20 -0000 @@ -5,7 +5,7 @@ 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 \ mystring.c options.c output.c parser.c printf.c redir.c show.c \ - trap.c var.c + test.c trap.c var.c GENSRCS= builtins.c init.c nodes.c syntax.c GENHDRS= builtins.h nodes.h syntax.h token.h y.tab.h SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS} y.tab.h @@ -22,7 +22,9 @@ # for debug: # CFLAGS+= -g -DDEBUG=2 -.PATH: ${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf +.PATH: ${.CURDIR}/bltin \ + ${.CURDIR}/../../bin/test \ + ${.CURDIR}/../../usr.bin/printf CLEANFILES+= mkinit mkinit.o mknodes mknodes.o \ mksyntax mksyntax.o Index: bin/sh/builtins.def =================================================================== RCS file: /home/ncvs/src/bin/sh/builtins.def,v retrieving revision 1.7 diff -u -r1.7 builtins.def --- bin/sh/builtins.def 27 Aug 1999 23:15:08 -0000 1.7 +++ bin/sh/builtins.def 9 Nov 2001 18:53:28 -0000 @@ -62,7 +62,7 @@ exitcmd exit expcmd exp let exportcmd export readonly -#exprcmd expr test [ +#exprcmd expr falsecmd false histcmd -h fc fgcmd -j fg @@ -90,3 +90,4 @@ #foocmd foo aliascmd alias ulimitcmd ulimit +testcmd test [ Index: bin/sh/sh.1 =================================================================== RCS file: /home/ncvs/src/bin/sh/sh.1,v retrieving revision 1.55 diff -u -r1.55 sh.1 --- bin/sh/sh.1 8 Aug 2001 18:31:58 -0000 1.55 +++ bin/sh/sh.1 9 Nov 2001 19:11:41 -0000 @@ -1273,9 +1273,12 @@ This section lists the commands which are builtin because they need to perform some operation that cannot be performed by a separate process. In addition to -these, a builtin version of the +these, builtin versions of the .Xr printf 1 -command is provided for efficiency. +command and +the +.Xr test 1 +are provided for efficiency. .Bl -tag -width Ds .It Ic \&: A null command that returns a 0 (true) exit value. Index: bin/test/test.c =================================================================== RCS file: /home/ncvs/src/bin/test/test.c,v retrieving revision 1.31 diff -u -r1.31 test.c --- bin/test/test.c 20 May 2001 05:33:53 -0000 1.31 +++ bin/test/test.c 9 Nov 2001 19:00:29 -0000 @@ -27,6 +27,11 @@ #include #include +#ifdef SHELL +#define main testcmd +#include "bltin/bltin.h" +#endif + /* test(1) accepts the following grammar: oexpr ::= aexpr | aexpr "-o" oexpr ; aexpr ::= nexpr | nexpr "-a" aexpr ; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message