tac: new applet. ~240 bytes.
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 6 Jan 2008 06:27:17 +0000 (06:27 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 6 Jan 2008 06:27:17 +0000 (06:27 -0000)
Copyright (C) 2003  Yang Xiaopeng  <yxp at hanwang.com.cn>
Copyright (C) 2007  Natanael Copa  <natanael.copa@gmail.com>
Copyright (C) 2007  Tito Ragusa    <farmatito@tiscali.it>

coreutils/Config.in
coreutils/Kbuild
docs/nofork_noexec.txt
include/applets.h
include/usage.h

index d3cbc4213af4f91075fd5486cea1c9a8d3421df9..3b3f7b33306d645781de08a5e6216a9cb1220211 100644 (file)
@@ -579,6 +579,12 @@ config SYNC
        help
          sync is used to flush filesystem buffers.
 
+config TAC
+       bool "tac"
+       default n
+       help
+         tac is used to concatenate and print files in reverse.
+
 config TAIL
        bool "tail"
        default n
index ce21b3a891913b0c7dd1e8990fde2679f4084ad3..8ada8b056cd8a79c20821742f17b254c3b2dc5f9 100644 (file)
@@ -66,6 +66,7 @@ lib-$(CONFIG_STAT)      += stat.o
 lib-$(CONFIG_STTY)      += stty.o
 lib-$(CONFIG_SUM)       += sum.o
 lib-$(CONFIG_SYNC)      += sync.o
+lib-$(CONFIG_TAC)       += tac.o
 lib-$(CONFIG_TAIL)      += tail.o
 lib-$(CONFIG_TEE)       += tee.o
 lib-$(CONFIG_TEST)      += test.o
index d4abdf45288b7133f24e2468067631de94d4ca72..06c789affdee4a513036980c73d2e198b8fcbd0b 100644 (file)
@@ -2,7 +2,7 @@
 
 Unix shells traditionally execute some commands internally in the attempt
 to dramatically speed up execution. It will be slow as hell if for every
-"echo blah" shell will fork and exec /bin/echo. For this end, shells
+"echo blah" shell will fork and exec /bin/echo. To this end, shells
 have to _reimplement_ these commands internally.
 
 Busybox is unique in this regard because it already is a collection
@@ -11,14 +11,20 @@ for speeding up busybox shells, and more. NOEXEC and NOFORK applets
 are exactly those applets which are eligible for these tricks.
 
 Applet will be subject to NOFORK/NOEXEC tricks if it is marked as such
-in applets.h. CONFIG_FEATURE_PREFER_APPLETS is a config option which
+in applets.h. FEATURE_PREFER_APPLETS is a config option which
 globally enables usage of NOFORK/NOEXEC tricks.
+If it is enabled, FEATURE_SH_STANDALONE can be enabled too,
+and then shells will use NOFORK/NOEXEC tricks for ordinary commands.
+NB: shell builtins use these tricks regardless of FEATURE_SH_STANDALONE
+or FEATURE_PREFER_APPLETS.
 
-If you want to call a program and wait for it, use spawn_and_wait(argv).
-It will check whether argv[0] is an applet name and will optionally
-do NOFORK/NOEXEC thing.
+In C, if you want to call a program and wait for it, use
+spawn_and_wait(argv), BB_EXECVP(prog,argv) or BB_EXECLP(prog,argv0,...).
+They check whether program name is an applet name and optionally
+do NOFORK/NOEXEC thing depending on configuration.
 
-NOEXEC
+
+       NOEXEC
 
 NOEXEC applet should work correctly if another applet forks and then
 executes exit(<applet>_main(argc,argv)) in the child. The rules
@@ -32,9 +38,10 @@ roughly are:
 * ...
 
 NOEXEC applets save only one half of fork+exec overhead.
-NOEXEC trick is disabled for NOMMU compile.
+NOEXEC trick is disabled for NOMMU build.
+
 
-NOFORK
+       NOFORK
 
 NOFORK applet should work correctly if another applet simply runs
 <applet>_main(argc,argv) and then continues with its business (xargs,
@@ -55,6 +62,8 @@ on what applet can/cannot do:
 * if you allocate memory, you can use xmalloc() only on the very first
   allocation. All other allocations should use malloc[_or_warn]().
   After first allocation, you cannot use any xfuncs.
+  Otherwise, failing xfunc will return to caller applet
+  without freeing malloced data!
 * All allocated data, opened files, signal handlers, termios settings,
   O_NONBLOCK flags etc should be freed/closed/restored prior to return.
 * ...
index c6331cb05c06847084c6e54e1ba027610a8f813d..4934d18cd314fd1287e57ddcebd85fbb65881106 100644 (file)
@@ -334,6 +334,7 @@ USE_SWITCH_ROOT(APPLET(switch_root, _BB_DIR_SBIN, _BB_SUID_NEVER))
 USE_SYNC(APPLET_NOFORK(sync, sync, _BB_DIR_BIN, _BB_SUID_NEVER, sync))
 USE_BB_SYSCTL(APPLET(sysctl, _BB_DIR_SBIN, _BB_SUID_NEVER))
 USE_SYSLOGD(APPLET(syslogd, _BB_DIR_SBIN, _BB_SUID_NEVER))
+USE_TAC(APPLET_NOEXEC(tac, tac, _BB_DIR_USR_BIN, _BB_SUID_NEVER, tac))
 USE_TAIL(APPLET(tail, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
 USE_TAR(APPLET(tar, _BB_DIR_BIN, _BB_SUID_NEVER))
 USE_TASKSET(APPLET(taskset, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
index 12d2cefd9c1ab4d0950dc1e18f90c851a1c6c6eb..464fb614b256357df15da8dc2192609381c4fce4 100644 (file)
@@ -3542,6 +3542,11 @@ USE_FEATURE_RUN_PARTS_FANCY("\n  -l      Prints names of all matching files even when
        "$ syslogd -R masterlog:514\n" \
        "$ syslogd -R 192.168.1.1:601\n"
 
+#define tac_trivial_usage \
+       "[FILE]..."
+#define tac_full_usage \
+       "Concatenates FILE(s) and prints them to stdout in reverse"
+
 #define tail_trivial_usage \
        "[OPTION]... [FILE]..."
 #define tail_full_usage \