Compare commits

...
398 Commits
Author SHA1 Message Date
Bernhard Reutner-Fischer b30688a799 - forgot to add ipsvd 2008-04-11 10:29:46 +00:00
Bernhard Reutner-Fischer baa9a71fa0 - pull fix for SYSLOG_NAMES_CONST from trunk 2008-04-11 10:22:45 +00:00
Bernhard Reutner-Fischer 21756c7d10 - pull updates from trunk 2008-04-11 10:22:12 +00:00
Denis Vlasenko fd8494d114 httpd: remove stray double assignment 2008-03-21 20:39:30 +00:00
Denis Vlasenko a8e183a577 Bump to 1.9.2 2008-03-21 09:44:25 +00:00
Denis Vlasenko 77d390dc70 apply five post-1.9.1 patches 2008-03-21 09:44:02 +00:00
Denis Vlasenko d4394120f7 Bump version to 1.9.1 2008-02-12 17:15:04 +00:00
Denis Vlasenko a68cb75a2e Applied post 1.9.0 fixes 2008-02-12 17:12:28 +00:00
Mike Frysinger 0b18cd3d04 merge fix for blank lines from trunk 2008-02-12 15:27:17 +00:00
Bernhard Reutner-Fischer aeb725e185 - Fix hdparm's ioctl parameter passing (John Brandwood)
This was applied to trunk as r20876.
2008-01-19 11:27:40 +00:00
Bernhard Reutner-Fischer 4e9b8ea910 - correct helptext of stat (Cristian Ionescu-Idbohrn) 2008-01-17 11:09:45 +00:00
Denis Vlasenko 299c5c379e Announce 1.9.0 2007-12-24 14:43:25 +00:00
Denis Vlasenko 3b4921674e hush: fixlet for NOMMU
update TODO_config_nommu
2007-12-24 14:26:57 +00:00
Denis Vlasenko f7be20e70c nameif: extended matching (Nico Erfurth <masta@perlgolf.de>)
*: whitespace fixes

function                                             old     new   delta
prepend_new_eth_table                                  -     304    +304
nameif_main                                          620     684     +64
cc_macaddr                                            51       -     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/0 up/down: 368/-51)           Total: 317 bytes
2007-12-24 14:09:19 +00:00
Denis Vlasenko fcfb5c04bb defconfig: update
appletli.c: add vda's (C)
top: fixlet for incorrect display of "0"
Makefile: reduce stack size from 20k to 16k
2007-12-24 12:16:24 +00:00
Denis Vlasenko e4bc603f0b od: reduce data/bss usage (code size went down too) 2007-12-24 12:14:24 +00:00
Denis Vlasenko ef36c04ccf umount: fix fallout from stack reduction change 2007-12-24 12:11:57 +00:00
Denis Vlasenko f882f08627 vi: speed up some string ops 2007-12-23 02:36:51 +00:00
Denis Vlasenko 528a8b9769 cttyhack: trivial build fixlet 2007-12-22 19:57:28 +00:00
Denis Vlasenko 4baed3a080 vi: reduce amount of memset'ing on each screen refresh 2007-12-22 17:31:29 +00:00
Denis Vlasenko e3cbfb91d2 vi: introduce FEATURE_VI_8BIT (as vi currently is not Unicode capable,
people may want to disable display of high-bit chars)
ip: build fixlet
2007-12-22 17:00:11 +00:00
Denis Vlasenko 94e3365b8f perror_nomsg: don't print extra colon
losetup: print name of loop device in error messages
2007-12-22 15:44:23 +00:00
Denis Vlasenko 88adfcd178 vi: change MAX_LINELEN meaning: now it is the biggest supported
screen wigth. Introduce MAX_TABSTOP and MAX_INPUT_LEN. Fix redraw
of very long lines and cursor movement past NULs.
2007-12-22 15:40:13 +00:00
Denis Vlasenko ee87ebf381 fix buglets found by randomconfig 2007-12-21 22:18:16 +00:00
Denis Vlasenko 26b6fba9d3 vi: fix a problem with displaying overlong lines 2007-12-21 21:34:37 +00:00
Denis Vlasenko 619879246d udhcp: decided to not send "short" dhcp packets,
but lets add comments how to do it if needed.
2007-12-21 16:32:30 +00:00
Denis Vlasenko fff145dba3 udhcp: fix oversized packet sending (introduced by "slack for bad dhcp servers" options);
slight optimizations and function renaming

udhcp_send_raw_packet                                  -     391    +391
udhcp_send_kernel_packet                               -     197    +197
udhcp_recv_packet                                      -     134    +134
get_raw_packet                                       353     326     -27
udhcp_get_packet                                     134       -    -134
udhcp_kernel_packet                                  197       -    -197
udhcp_raw_packet                                     391       -    -391
------------------------------------------------------------------------------
(add/remove: 3/3 grow/shrink: 0/1 up/down: 722/-749)          Total: -27 bytes
2007-12-20 21:11:38 +00:00
Denis Vlasenko f77f369ce8 fdisk: reduce global data/bss usage. 8k data+bss build is achievable soon ;)
(add/remove: 0/13 grow/shrink: 6/19 up/down: 74/-492)        Total: -418 bytes
   text    data     bss     dec     hex filename
 778330     860    7408  786598   c00a6 busybox_old
 777970     840    7376  786186   bff0a busybox_unstripped
2007-12-16 17:22:33 +00:00
Denis Vlasenko c794c51a1a msh: reduce global data/bss usage
(add/remove: 1/5 grow/shrink: 28/6 up/down: 464/-394)          Total: 70 bytes
   text    data     bss     dec     hex filename
 778077     908    7568  786553   c0079 busybox_old
 778330     860    7408  786598   c00a6 busybox_unstripped
2007-12-16 17:21:29 +00:00
Denis Vlasenko 0163111325 ash: reduce global data/bss usage
(add/remove: 4/29 grow/shrink: 76/21 up/down: 1007/-1713)    Total: -706 bytes
   text    data     bss     dec     hex filename
 777206    1084    8976  787266   c0342 busybox_old
 778077     908    7568  786553   c0079 busybox_unstripped
2007-12-16 17:20:38 +00:00
Denis Vlasenko 9ad2cb3f1a traceroute: stop using global data/bss
(add/remove: 0/15 grow/shrink: 0/1 up/down: 0/-95)            Total: -95 bytes
   text    data     bss     dec     hex filename
 777245    1094    9008  787347   c0393 busybox_old
 777206    1084    8976  787266   c0342 busybox_unstripped
2007-12-16 17:19:40 +00:00
Denis Vlasenko 4ca2965b99 add a link to vda's pet projects 2007-12-13 00:15:50 +00:00
Denis Vlasenko 2cd4a747e5 num conversions: allow for leading '+' (renice needs that) 2007-12-11 13:15:11 +00:00
Denis Vlasenko d7e2e127a9 cttyhack: add missing ';'
init: remove pointless access() check
2007-12-10 08:40:29 +00:00
Denis Vlasenko 2afabe8b83 init: remove superfluous forks and messing up with argv[0]
cttyhack: add stealing of ctty
2007-12-10 07:06:04 +00:00
Denis Vlasenko 191836845e udhcpc: support for -O <option>.
Two important notes:
* nissrv and nisdomain are not requested by default anymore!
* inconsistency between "XXXsvr" and "XXsrv" in option names resolved,
  all are "XXXsrv" now.

function                                             old     new   delta
udhcpc_main                                         2494    2600    +106
packed_usage                                       23023   23067     +44
add_requests                                          91     119     +28
static.udhcpc_longopts                               209     226     +17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 195/0)             Total: 195 bytes
2007-12-10 07:03:38 +00:00
Denis Vlasenko 75aa615bef find: add -iname support (Alexander Griesser <alexander.griesser@lkh-vil.or.at>) 2007-12-09 10:07:39 +00:00
Denis Vlasenko 9cb220be9d lineedit: don't violate API if we do simple fgets
ash: cosmetic style fixes, no code changes
2007-12-09 10:03:28 +00:00
Denis Vlasenko a96425fe82 vi: don't use common_bufsiz as read buffer, it can be too small
(found by Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>)
2007-12-09 04:13:43 +00:00
Denis Vlasenko b851c42a14 signal names hack was wrong, it broke "get signal name" function.
Reverting :(
2007-12-04 21:44:52 +00:00
Denis Vlasenko f3fca91e9f getty: a small code shrink
touch                                                  -      40     +40
fakehost                                               4       -      -4
getty_main                                          2546    2493     -53
2007-12-04 18:46:01 +00:00
Denis Vlasenko c689fcfdb0 Make signal table a bit smaller
get_signum                                           136     151     +15
signals                                              224     192     -32
2007-12-04 10:20:48 +00:00
Denis Vlasenko 5f934b0785 guard against SIGxxx >= 32 (no code changes on i386) 2007-12-04 10:05:28 +00:00
Denis Vlasenko d0bbbdcd6e getty: don't accept ancient '#' and '@' as backspace/kill line,
it only confuses people.
(Alexander Griesser <alexander.griesser@lkh-vil.or.at> (LKH Villach))
various other cleanups.

function                                             old     new   delta
getty_main                                          2526    2546     +20
static.baud_index                                      4       -      -4
parse_speeds                                          91       -     -91
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 20/-95)            Total: -75 bytes
   text    data     bss     dec     hex filename
 773152    1086    9008  783246   bf38e busybox_old
 773081    1086    9008  783175   bf347 busybox_unstripped
2007-12-04 09:48:40 +00:00
Denis Vlasenko 7221c8c22d lineedit: reduce stack usage
netstat: reduce stack usage; fix handling of NULs in unix socket filenames

static.has_inode                                       1       -      -1
do_info                                              119     116      -3
deinit_S                                              60      51      -9
unix_do_one                                          578     451    -127
parse_and_put_prompt                                 966     825    -141
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/4 up/down: 0/-281)           Total: -281 bytes
2007-12-03 10:45:14 +00:00
Denis Vlasenko 2bec513996 fix whitespace damage 2007-12-02 08:56:53 +00:00
Denis Vlasenko 7ab3699b58 mkfs.minix: add testsuite; disable code which makes images variable 2007-12-02 08:55:34 +00:00
Denis Vlasenko ab801874f8 attack the biggest stack users:
-mkfs_minix_main [busybox_unstripped]:                  4288
-mkfs_minix_main [busybox_unstripped]:                  4276
-grave [busybox_unstripped]:                            4260
(bzip2 users too - not listed)

price we pay in code size increase:
mainSort                                            2458    2515     +57
grave                                               1005    1058     +53
sendMTFValues                                       2177    2195     +18
BZ2_blockSort                                        122     125      +3
mkfs_minix_main                                     3070    3022     -48
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 131/-48)            Total: 83 bytes
2007-12-02 08:35:37 +00:00
Denis Vlasenko 8003e266ed explain why we use mmap instead of malloc 2007-12-02 07:18:29 +00:00
Denis Vlasenko 8723a94c25 libnetlink: comment out unused code; don't use 8k stack buffers
function                                             old     new   delta
ipaddr_modify                                       1305    1297      -8
do_iprule                                            963     955      -8
do_iproute                                          2193    2169     -24
xrtnl_dump_filter                                    418     391     -27
rtnl_talk                                            671     536    -135
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-202)           Total: -202 bytes
2007-12-02 06:30:57 +00:00
Denis Vlasenko 5cb40bbbd3 Fix minor discrepancy in "make help" 2007-12-02 05:36:37 +00:00
Denis Vlasenko 4c13922961 Introduce FEATURE_COPYBUF_KB.
People who want smaller stack at any cost may use it
to reduce cp's stack usage (FEATURE_COPYBUF_KB=1).
Desktop people may get faster copy of big files
(FEATURE_COPYBUF_KB=32 is ~30% faster than 4kb)
2007-12-02 03:27:42 +00:00
Denis Vlasenko e2532ab5f2 dd: fix a bug where we don't report write errors
testsuite: small cleanup

full_write_or_warn                                    38      40      +2
write_and_stats                                       66      67      +1
dd_main                                             1358    1335     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 3/-23)             Total: -20 bytes
2007-12-02 01:44:42 +00:00
Denis Vlasenko 1796e2c495 dd: add testsuite entry for write errors 2007-12-02 01:43:18 +00:00
Denis Vlasenko 6672c8e480 test: stop using lots of bss.
function                                             old     new   delta
test_main                                            425     456     +31
t_lex                                                 69      73      +4
syntax                                               100     104      +4
ptr_to_statics                                         8      12      +4
t_wp_op                                                4       -      -4
t_wp                                                   4       -      -4
ngroups                                                4       -      -4
group_array                                            4       -      -4
binop                                                590     585      -5
oexpr                                                104      97      -7
aexpr                                                101      94      -7
nexpr                                                831     820     -11
leaving                                              156       -    -156
------------------------------------------------------------------------------
(add/remove: 0/5 grow/shrink: 4/4 up/down: 43/-202)          Total: -159 bytes
   text    data     bss     dec     hex filename
 775098     929    9084  785111   bfad7 busybox_old
 775107     933    8908  784948   bfa34 busybox_unstripped
2007-11-30 07:29:05 +00:00
Denis Vlasenko b539c8452f dhcp: heed TODO item - divorced options from their string descriptions
code shrink while at it.

function                                             old     new   delta
dhcp_option_strings                                    -     258    +258
udhcp_run_script                                    1135    1174     +39
dhcp_option_lengths                                    -      11     +11
udhcp_add_simple_option                               93      92      -1
packet_num                                             4       -      -4
read_opt                                             746     739      -7
udhcp_option_lengths                                  11       -     -11
udhcpc_main                                         2590    2494     -96
dhcp_options                                         490      70    -420
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/4 up/down: 308/-539)         Total: -231 bytes
   text    data     bss     dec     hex filename
 775309     929    9100  785338   bfbba busybox_old
 775098     929    9084  785111   bfad7 busybox_unstripped
2007-11-29 08:17:45 +00:00
Denis Vlasenko 64309f8669 sysctl: add -e: supress warnings about invalid key (Jeremy Kerr <jk@ozlabs.org>)
code shrink:

   text    data     bss     dec     hex filename
 775565     929    9100  785594   bfcba busybox_old
 775296     929    9100  785325   bfbad busybox_unstripped
2007-11-29 06:40:28 +00:00
Denis Vlasenko 745cd17926 Further optimize applet tables; prettify build output
text    data     bss     dec     hex filename
 775923     929    9100  785952   bfe20 busybox_old
 775565     929    9100  785594   bfcba busybox_unstripped
2007-11-29 03:31:20 +00:00
Denis Vlasenko c253778de9 touch: accept and ignore -f 2007-11-28 19:25:32 +00:00
Denis Vlasenko 35ff74676b dhcpc: let server know we don't like oversized packets.
add TODO comment
2007-11-28 19:23:12 +00:00
Denis Vlasenko 41f5add965 forgotten part of previous commit 2007-11-28 06:49:42 +00:00
Denis Vlasenko 1aa7e477b1 reorganize applet table. Eliminates pointers to names.
Should be a big win for libbusybox. busybox wins too:

   text    data     bss     dec     hex filename
 776524     929    9100  786553   c0079 busybox_old
 775903     929    9100  785932   bfe0c busybox_unstripped
2007-11-28 06:49:03 +00:00
Denis Vlasenko 79c6904faf ip route: add comment, no code changes 2007-11-27 09:42:33 +00:00
Denis Vlasenko 186c2b3d0e iproute: fix a bug where "ip r flush table main" was rejected,
add "ip r flush cache" (however I'm unsure it is really valid syntax)
Add a few comments and stop mixing params and params' keywords.
2007-11-26 18:29:52 +00:00
Denis Vlasenko 30297a5b83 fix vda's testsuite bogons, part 2 2007-11-26 07:23:27 +00:00
Denis Vlasenko bd9a48bc9c fix vda's testsuite bogons, part 1 2007-11-26 07:23:09 +00:00
Denis Vlasenko 4e1e720523 testsuite: add tests for cut and grep;
slight improvements to infrastructure
2007-11-26 05:38:20 +00:00
Denis Vlasenko ed270a5f32 ash: make code simpler, and do not do close(-1) - it's rude 2007-11-26 05:37:07 +00:00
Denis Vlasenko b1bac0dab2 zcip: simplify code a bit 2007-11-25 12:53:25 +00:00
Denis Vlasenko a09300a88c zcip: use low-order 4 bytes of MAC as random seed, not 4 high-order
arping: fix wrong roundtrip calculation
arping,zcip: cleanups and code shrink

run                                                  389     402     +13
arp                                                  195     188      -7
zcip_main                                           1524    1495     -29
arping_main                                         1874    1823     -51
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 13/-87)            Total: -74 bytes
   text    data     bss     dec     hex filename
 776587     929    9100  786616   c00b8 busybox_old
 776499     929    9100  786528   c0060 busybox_unstripped
2007-11-25 12:40:56 +00:00
Denis Vlasenko 7c9d533a85 cttyhack should be in /bin, not /usr/bin 2007-11-25 07:58:42 +00:00
Denis Vlasenko 6446c2d4ab which: fix testsuite failure
pidof: do not output empty line if nothing found
testsuite: disable false positive
2007-11-25 04:54:13 +00:00
Denis Vlasenko 72e76044cf dhcpc: cope with buggy DHCP servers which send oversized packets
(Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>)
2007-11-25 03:15:24 +00:00
Denis Vlasenko a8875efa85 Announce 1.8.2 and 1.7.4 2007-11-24 04:49:07 +00:00
Denis Vlasenko dd8bbfd084 stty: reorganize data tables - save 0.5k
function                                             old     new   delta
mode_name                                              -     496    +496
control_name                                           -      91     +91
stty_main                                           1235    1255     +20
find_mode                                             45      63     +18
find_control                                          45      63     +18
do_display                                           482     493     +11
wrapf                                                165     166      +1
set_mode                                             761     759      -2
max_col                                                4       -      -4
device_name                                            4       -      -4
control_info                                         153      34    -119
mode_info                                           1700     680   -1020
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 5/3 up/down: 655/-1149)        Total: -494 bytes
   text    data     bss     dec     hex filename
 777037     937    9100  787074   c0282 busybox_old
 776551     929    9100  786580   c0094 busybox_unstripped
2007-11-24 04:32:49 +00:00
Denis Vlasenko fe5e23bf75 remove echo_main -> bb_echo indirection 2007-11-24 02:23:51 +00:00
Denis Vlasenko c3c6659f12 hush: fix segfault in "echo $@" when we have no arguments 2007-11-24 00:22:42 +00:00
Denis Vlasenko d2023283ac fix buglets found by randomconfig 2007-11-23 23:39:01 +00:00
Denis Vlasenko 1da0ad13fb update defconfig 2007-11-23 23:37:19 +00:00
Denis Vlasenko 96702ca945 kill lash. "lash" builtin still exists, but it runs hush. 2007-11-23 23:28:55 +00:00
Denis Vlasenko 8ec6ee47f1 Add an RFC for future ipv6 ftp work 2007-11-23 21:43:40 +00:00
Denis Vlasenko 5bc593ccb8 hush: implement echo builtin
builtin_echo                                           -      36     +36
bltins                                               384     396     +12
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 48/0)               Total: 48 bytes
2007-11-23 21:20:21 +00:00
Denis Vlasenko cccdc4e01a hush: fix $ expansion in redirections, add testcase for that 2007-11-23 21:08:38 +00:00
Denis Vlasenko 835068637e hush: implement test builtin 2007-11-23 13:11:42 +00:00
Denis Vlasenko f962a0354e hush: plug memory leak 2007-11-23 12:50:54 +00:00
Denis Vlasenko f23c3f95e8 arping: fix help text (-i -> -I), and shorten it a bit 2007-11-23 09:27:05 +00:00
Denis Vlasenko fff9b699f1 arping: fix a bug where there is implicit count of 4G;
eliminate data/bss usage; code shrink

function                                             old     new   delta
timeout_us                                             4       -      -4
static.start                                           4       -      -4
src                                                    4       -      -4
sock                                                   4       -      -4
sent                                                   4       -      -4
req_recv                                               4       -      -4
received                                               4       -      -4
last                                                   4       -      -4
dst                                                    4       -      -4
count                                                  4       -      -4
brd_sent                                               4       -      -4
brd_recv                                               4       -      -4
catcher                                              375     365     -10
me                                                    20       -     -20
he                                                    20       -     -20
arping_main                                         1941    1874     -67
------------------------------------------------------------------------------
(add/remove: 0/14 grow/shrink: 0/2 up/down: 0/-165)          Total: -165 bytes
   text    data     bss     dec     hex filename
 783035     941    9244  793220   c1a84 busybox_old
 782907     937    9156  793000   c19a8 busybox_unstripped
2007-11-23 09:15:26 +00:00
Denis Vlasenko 3831c91c95 cut: add proper stdout error handling, fix "-" handling;
modest code shrink
2007-11-23 07:26:15 +00:00
Denis Vlasenko e85dbae389 logread: add forgotten INIT_G(); 2007-11-23 03:41:20 +00:00
Denis Vlasenko ff2b6d2185 logread: eliminate usage of data/bss
ifup: don't remove virtual iface prefixes (eth0:0)

function                                             old     new   delta
shbuf                                                  4       -      -4
SMrup                                                  6       -      -6
SMrdn                                                 12       -     -12
static.label_buf                                      20       4     -16
get_var                                              158     140     -18
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 0/2 up/down: 0/-56)             Total: -56 bytes
   text    data     bss     dec     hex filename
 783501     962    9260  793723   c1c7b busybox_old
 783483     942    9244  793669   c1c45 busybox_unstripped
2007-11-23 03:39:45 +00:00
Denis Vlasenko 6884f665bd dhcp: stop using magic constants; use (htonl(CONST) != a) - it's smaller
function                                             old     new   delta
udhcp_get_packet                                     146     134     -12
get_raw_packet                                       368     353     -15
2007-11-23 00:08:54 +00:00
Denis Vlasenko 68af8e7a08 udhcpc: remove -W option, -A can be reused for that
help texts: trimmed a bit

static.udhcpc_longopts                               227     209     -18
udhcpc_main                                         2633    2590     -43
packed_usage                                       22927   22871     -56
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-117)           Total: -117 bytes
2007-11-22 21:41:14 +00:00
Denis Vlasenko b559105cfb fix a thinko in build system 2007-11-22 20:09:41 +00:00
Denis Vlasenko 7d75a96b15 ash: fix bug where redirection of closed fd was leaving it open afterwards.
redirect                                             983    1024     +41
bb_echo                                              276     301     +25
popredir                                             118     132     +14
evalcommand                                         1163    1176     +13
bbunpack                                             358     366      +8
echocmd                                               13       5      -8
echo_main                                             13       5      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/2 up/down: 101/-16)            Total: 85 bytes
   text    data     bss     dec     hex filename
 774999     962    9236  785197   bfb2d busybox_old
 775084     962    9236  785282   bfb82 busybox_unstripped
2007-11-22 08:16:57 +00:00
Denis Vlasenko 705eaf8b40 sestatus: new SELinux applet (KaiGai Kohei <kaigai@ak.jp.nec.com>) 2007-11-22 01:10:41 +00:00
Denis Vlasenko 9cdfd14223 dhcpc: cleanup and comments; fix buggy timeout handling in corner cases.
-25 bytes.
2007-11-22 01:00:00 +00:00
Denis Vlasenko 223bc97f61 udhcpc: an option to perform ARP check (Jonas Danielsson <jonas.danielsson@axis.com>)
configurable, ~+300 bytes when on.
2007-11-22 00:58:49 +00:00
Mike Frysinger c881c733bb cleanup comments and coding style and rewrite the mdev.conf parser to use common busybox functions and call strdup() less often ... saves a ~few hundred bytes 2007-11-19 09:04:22 +00:00
Denis Vlasenko ed6a49c657 ip: stop propagating argc; optimize ip_parse_common_args
function                                             old     new   delta
find_pair                                            167     187     +20
static.families                                        -      17     +17
die_must_be_on_off                                     -      11     +11
...
on_off                                                33      22     -11
do_ipaddr                                            103      90     -13
do_iptunnel                                         1001     986     -15
iproute_list_or_flush                               1237    1217     -20
static.ip_common_commands                             43      22     -21
do_iproute                                          2217    2193     -24
parse_args                                          1444    1414     -30
ip_do                                                 47      16     -31
do_iprule                                            994     963     -31
ip_main                                              153     113     -40
ipaddr_modify                                       1357    1305     -52
ipaddr_list_or_flush                                2543    2490     -53
ip_parse_common_args                                 294     159    -135
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 4/24 up/down: 85/-563)         Total: -478 bytes
   text    data     bss     dec     hex filename
 775561     966    9236  785763   bfd63 busybox_old
 775073     962    9236  785271   bfb77 busybox_unstripped
2007-11-18 22:56:25 +00:00
Denis Vlasenko 2a587df80a stty: mark variable as static 2007-11-18 11:47:25 +00:00
Mike Frysinger 49d15890e0 make output a little more friendly 2007-11-18 06:42:56 +00:00
Mike Frysinger e13bd362e3 merge from upstream for systems that dont integrate libintl into their C library:
commit aa1e5ef5c1d95e7ebf0821d9ba27debe43a87a22
Author: Sam Ravnborg <sam@ravnborg.org>
Date:   Sun Aug 12 23:15:44 2007 +0200

    kbuild: check if we can link gettext not just compile

    cygwin provides the header file but the lib file needs
    to be added manually. A generic fix is to check if
    we can compile and link a program that uses gettext()
    and if it fails fall back to NO_NLS.

    International users of cygwin may have to specify
    HOST_LOADLIBES := "-lintl" on the make command line.

    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
2007-11-18 06:17:52 +00:00
Mike Frysinger dbd18f639c exported symbols may be weak, so allow symbols marked as W 2007-11-18 06:13:58 +00:00
Denis Vlasenko 70ab28f907 syslogd: use DEV_CONSOLE consistently
init: remove obsolete comment
2007-11-18 05:43:05 +00:00
Denis Vlasenko fbe5f39f0f hexdump: add hd alias, add -R option 2007-11-18 05:36:50 +00:00
Paul Fox 16aec39ebe add comment clarifying busybox's use of non-standard tar header 2007-11-17 19:11:05 +00:00
Denis Vlasenko 8512862163 tar: fix a case where glibc detects bogus buffer overrun
which is not really there!
2007-11-16 20:35:30 +00:00
Denis Vlasenko 7e3a5f58bc dmesg,klogd: make code more readable
libbb: explain why we declare klogctl
libbb: move defs around so that order makes more sense
2007-11-16 20:18:54 +00:00
Bernhard Reutner-Fischer 7c2db5c198 - use standard-imposed constants some more 2007-11-16 12:39:16 +00:00
Bernhard Reutner-Fischer a702457eac - remove most of the forward declarations. No obj-code changes. 2007-11-16 12:20:30 +00:00
Bernhard Reutner-Fischer e8979889b4 - add note about SUSv3 missing options. 2007-11-16 11:52:42 +00:00
Denis Vlasenko 01cd9570c7 who: add -a (by Tito) 2007-11-16 05:24:43 +00:00
Denis Vlasenko a6899c3587 lash: fix compile-time warning 2007-11-15 17:47:45 +00:00
Denis Vlasenko 6d38dc3af4 df: add -a
df: don't special case rootfs and /dev/root

function                                             old     new   delta
df_main                                              746     684     -62
find_block_device                                    111       -    -111
find_block_device_in_dir                             243       -    -243
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-416)           Total: -416 bytes
2007-11-15 09:02:12 +00:00
Denis Vlasenko f430cdbf2e df: add -i (conditional on CONFIG)
uasge: trim a bit
2007-11-15 07:02:55 +00:00
Denis Vlasenko 1fe4e9e573 cosmetic change in message text 2007-11-15 00:57:40 +00:00
Paul Fox ae6bf96659 bad syntax error should go to stderr 2007-11-14 23:48:35 +00:00
Denis Vlasenko 9d6c46955f Introduce FEATURE_PREFER_IPV4_ADDRESS. If selected, we have:
function                                             old     new   delta
str2sockaddr                                         328     344     +16
2007-11-14 10:18:33 +00:00
Denis Vlasenko 8d0a734d91 tr: more of code shrink (getopt32-ification)
runtest: cleanup. Method of getting $applets was truly bizarre

function                                             old     new   delta
tr_main                                              655     527    -128
2007-11-13 22:23:57 +00:00
Denis Vlasenko 3d461676a9 tr: better comments, small code shrink
function                                             old     new   delta
expand                                              2232    2230      -2
tr_main                                              677     655     -22
2007-11-13 22:22:29 +00:00
Denis Vlasenko a89d50fb9a tr: properly detect read errors (Fernando Silveira <fsilveira@gmail.com>)
readprofile: use xwrite

function                                             old     new   delta
tr_main                                              679     677      -2
readprofile_main                                    1964    1944     -20
2007-11-13 17:51:40 +00:00
Denis Vlasenko 130f559f4d trylink: accomodate older versions of ld 2007-11-13 17:36:12 +00:00
Denis Vlasenko 05c8c4f745 who: code shrink by Tito <farmatito@tiscali.it>
function                                             old     new   delta
who_main                                             271     259     -12
2007-11-13 17:26:21 +00:00
Denis Vlasenko 72cc9641f8 add sed mini-doc 2007-11-13 17:13:31 +00:00
Denis Vlasenko 40276648ab sed: support GNU-like '\t' escape in substitutions 2007-11-13 16:48:10 +00:00
Denis Vlasenko 6df9e3c9a3 inetd: revert bogus fix for bug 1562; shrink inetd a bit
function                                             old     new   delta
dupconfig                                            159     146     -13
getconfigent                                        1123    1073     -50
2007-11-12 21:21:35 +00:00
Denis Vlasenko 059c91711f open_transformer: do not duplicate "<program> -cf -"
text    data     bss     dec     hex filename
 677858     738    7236  685832   a7708 busybox_old
 677804     738    7236  685778   a76d2 busybox_unstripped
2007-11-12 02:13:12 +00:00
Denis Vlasenko 4bfb84db4e gzip: fix a case where tar xzf fails (we use uninitialized fd) 2007-11-12 01:44:49 +00:00
Denis Vlasenko e5569cb52e who: fix wrong date/time field size 2007-11-11 06:35:41 +00:00
Denis Vlasenko 40702dac93 Announce 1.8.1 2007-11-10 03:24:21 +00:00
Denis Vlasenko f6ccc62c70 init: fix bug 1584: improper check for fork error 2007-11-10 01:57:35 +00:00
Denis Vlasenko 5cc6459c46 umount: stop using excessive aounts of stack. Surprisingly,
code shrank a lot too

function                                             old     new   delta
umount_main                                          751     640    -111
2007-11-10 01:45:03 +00:00
Denis Vlasenko 73cb1fdfea lineedit: stop using both data/bss and tons of stack.
stack usage was ~10 kb!
unfortunately, noticeable code size growth:
   text    data     bss     dec     hex filename
   9252      12     181    9445    24e5 busybox.t7/libbb/lineedit.o
   9714       4       0    9718    25f6 busybox.t8/libbb/lineedit.o
2007-11-10 01:35:47 +00:00
Denis Vlasenko e7fca5125a *: remove superfluous "?" in option parsing 2007-11-10 01:32:18 +00:00
Denis Vlasenko b4f608d8e0 readlink: realpath requires PATH_MAX, bb_common_bufsiz1 can be too small
umount: don't actually need char[2 * PATH_MAX] for realpath
2007-11-10 01:31:19 +00:00
Denis Vlasenko d031b203c7 syslogd: support "symlink to symlink" for /dev/log; reduce stack usage
function                                             old     new   delta
create_socket                                          -     134    +134
syslogd_main                                        1132     865    -267
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 134/-267)         Total: -133 bytes
   text    data     bss     dec     hex filename
 775603     974    9420  785997   bfe4d busybox_old
 775445     974    9420  785839   bfdaf busybox_unstripped
2007-11-10 01:28:19 +00:00
Bernhard Reutner-Fischer 9bd8d0c23e - commentary fixes
- use common exit sequence for failure path:
   text	   data	    bss	    dec	    hex	filename
    308	      0	      0	    308	    134	libbb/xreadlink.o.pgf
    296	      0	      0	    296	    128	libbb/xreadlink.o
2007-11-08 21:11:43 +00:00
Paul Fox 599bbfbd9b xmalloc_follow_symlinks() -- fix ELOOP issue with absolute paths,
return full path in cases where path doesn't resolve to a link. 
change name to better differentiate from xmalloc_readlink().
2007-11-08 20:00:36 +00:00
Denis Vlasenko abbd363261 xreadlink: code shrink
udhcp: add missing tryagain member to client_config

function                                             old     new   delta
xmalloc_readlink_follow                              169     154     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-15)             Total: -15 bytes
2007-11-08 17:40:23 +00:00
Paul Fox 53bd4015aa follow symlinks to find the true passwd file before updating. 2007-11-08 01:12:38 +00:00
Paul Fox 459a2ba1ef new xmalloc_readlink_follow() routine to fully expand trailing symlinks
to get to a "real" file (or directory).
2007-11-08 01:11:41 +00:00
Paul Fox 49cce2b838 add "-A N" / "--tryagain=N" option to client, to allow altering the
default 60 second wait after failure to get a lease.
2007-11-07 16:01:28 +00:00
Paul Fox 6e1b62b18c flush typeahead before prompt 2007-11-07 15:51:35 +00:00
Denis Vlasenko a29a5e40ae login: fix PAM login (was unable to complete Kerberos login) 2007-11-07 00:23:47 +00:00
Denis Vlasenko cb12cb2407 modprobe: fix a bug where we were entering endless loop
syslogd: strip trailing '\n' too, not only NULs
2007-11-06 11:34:03 +00:00
Denis Vlasenko 5281630229 login: clear dangerous environment variables if started by non-root 2007-11-06 05:26:51 +00:00
Denis Vlasenko 6bef3d1d22 fbset: fix buglet where we were using wrong pointer
readahead: stop using stdio.h
*: style fixes
2007-11-06 03:05:54 +00:00
Denis Vlasenko 1bec1b980e telnet: use poll, it's shorter
*: style fixes
2007-11-06 02:23:39 +00:00
Denis Vlasenko cd0fbb5e77 unzip: hmm... gcc doesn't like ATTRIBUTE_PACKED?? Document that... 2007-11-06 02:16:01 +00:00
Denis Vlasenko ef66d75704 insmod: make error reporting less verbose 2007-11-06 02:02:45 +00:00
Denis Vlasenko 018b155ad9 telnetd: fix problem with zombies (by Paul Fox <pgf@brightstareng.com>)
syslogd: strip trailing NULs
2007-11-06 01:38:46 +00:00
Paul Fox cb981638f5 change safety check on zip header to allow for extra length, and
revert the header read to use the correct constant rather than
sizeof.  at least one version of gcc (armv4-linux-gcc-3.4.1) pads
the struct to 28 bytes in spite of the packing.
2007-11-05 23:09:03 +00:00
Denis Vlasenko f8b21d0933 swaponoff: prevent arithmetic overflow (spotted by Paul Fox <pgf@brightstareng.com>) 2007-11-05 19:33:38 +00:00
Denis Vlasenko 15c3885688 fix incorrect text of link-time error message. No code changes 2007-11-05 19:31:01 +00:00
Denis Vlasenko 9fcd799b98 webpage: fix typo, remove inconsistent trailing dots
Makefile: version is 1.9.0.svn now
2007-11-05 16:26:34 +00:00
Denis Vlasenko 3a3e50e3db update screenshot 2007-11-04 15:57:35 +00:00
Denis Vlasenko 6cee58e9cf Announce 1.8.0 2007-11-04 15:43:26 +00:00
Denis Vlasenko 360362dc57 docs: fix new-applet-HOWTO.txt, delete ipv4_ipv6.txt (it's obsolete) 2007-11-04 04:46:46 +00:00
Denis Vlasenko 06200348be Announce 1.7.3 on website 2007-11-04 04:30:20 +00:00
Denis Vlasenko bfc3d82256 ifconfig: code shrink
adjtimex: code shrink
libbb: move nth_string function into libbb
hdparm: nth_string was here

   text    data     bss     dec     hex filename
 730013   10334   12032  752379   b7afb busybox_old
 730093   10134   12032  752259   b7a83 busybox_unstripped
2007-11-04 04:10:17 +00:00
Denis Vlasenko 681023650e grep: fix -Fo 2007-11-04 00:46:03 +00:00
Denis Vlasenko b68979aefa insmod: code shrink, stop exporting insmod_ng_main.
function                                             old     new   delta
add_ksymoops_symbols                                   -     421    +421
static.section_names                                  20      40     +20
lsmod_main                                           425     424      -1
set_tainted                                          153     150      -3
main_opts                                              4       -      -4
obj_symbol_patch                                      47      42      -5
obj_string_patch                                     144     139      -5
already_loaded                                       144     138      -6
check_dep                                            348     341      -7
append_option                                         75      68      -7
obj_allocate_commons                                 515     501     -14
new_process_module_arguments                        1039    1018     -21
arch_new_symbol                                       31       9     -22
check_module_name_match                               85      61     -24
obj_create_alloced_section                           164     136     -28
include_conf                                         930     902     -28
modprobe_main                                       1643    1535    -108
obj_load                                             924     777    -147
insmod_ng_main                                       245       -    -245
insmod_main                                         4122    3794    -328
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/16 up/down: 441/-1003)       Total: -562 bytes
   text    data     bss     dec     hex filename
 776020     974    9420  786414   bffee busybox_old
 775384     974    9420  785778   bfd72 busybox_unstripped
2007-11-02 23:31:10 +00:00
Denis Vlasenko 9d1afdb571 inetd: fix bug 1562 "inetd does not set argv[0] properly" (fix by IlyaPanfilov)
inetd: code shrink while at it

function                                             old     new   delta
static.SOCK_xxx                                        -       6      +6
getconfigent                                        1222    1123     -99
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 6/-99)             Total: -93 bytes
   text    data     bss     dec     hex filename
 776099     974    9420  786493   c003d busybox_old
 776020     974    9420  786414   bffee busybox_unstripped
2007-10-30 19:54:39 +00:00
Denis Vlasenko 9130340adf hdparm: code shrink
text    data     bss     dec     hex filename
 776494     974    9420  786888   c01c8 busybox_old
 776099     974    9420  786493   c003d busybox_unstripped
2007-10-30 19:36:54 +00:00
Denis Vlasenko d059ddc1bb e2fsprogs: code shrink
text    data     bss     dec     hex filename
 776594     974    9420  786988   c022c busybox_old
 776494     974    9420  786888   c01c8 busybox_unstripped
2007-10-30 19:36:07 +00:00
Bernhard Reutner-Fischer 1641d614fa - fix typo in helptext 2007-10-29 21:21:27 +00:00
Denis Vlasenko 968dbf9685 minor fix in comment, no code changes 2007-10-29 19:52:21 +00:00
Denis Vlasenko dfc0740b04 ll_types.c: optimize link type table, make it conditional
on FEATURE_IP_RARE_PROTOCOLS

function                                             old     new   delta
static.arphrd_name                                     -     373    +373
static.arphrd_type                                     -     124    +124
ll_type_n2a                                           58      78     +20
static.arphrd_names                                  496       -    -496
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/0 up/down: 517/-496)           Total: 21 bytes
   text    data     bss     dec     hex filename
 776880     974    9420  787274   c034a busybox_old
 776594     974    9420  786988   c022c busybox_unstripped
2007-10-29 19:33:26 +00:00
Denis Vlasenko 15ca51e3e2 appletlib.c: make it actally follow _BB_SUID_ALWAYS rules
adduser: implement -S and code shrink / fix uid selection
*: sanitize getspnam_r use

   text    data     bss     dec     hex filename
 777042     974    9676  787692   c04ec busybox_old
 776883     974    9676  787533   c044d busybox_unstripped
2007-10-29 19:25:45 +00:00
Denis Vlasenko 5a28a25b9d syscall: code shrink
text    data     bss     dec     hex filename
 777209     974    9676  787859   c0593 busybox_old
 777042     974    9676  787692   c04ec busybox_unstripped
2007-10-29 19:22:13 +00:00
Denis Vlasenko 63430ae35a mount: size-optimize mount_options[] and nfs_errtbl[]
777253     974    9676  787903   c05bf busybox_old
 777209     974    9676  787859   c0593 busybox_unstripped
2007-10-29 19:18:39 +00:00
Denis Vlasenko a59f435b5f ash: if tcgetattr(stdin) fails, don't mess with tcsetattr
ash: size-optimize ulimit's table of limits

   text    data     bss     dec     hex filename
 777345     974    9676  787995   c061b busybox_old
 777253     974    9676  787903   c05bf busybox_unstripped
2007-10-29 19:17:29 +00:00
Denis Vlasenko 7ab5e3dfcd svlogd: fix compat problem: svlogd -tt should timestanp stderr too 2007-10-22 15:53:34 +00:00
Denis Vlasenko 78ee7c853a httpd: fix trivial bug (spotted by Alex Landau) 2007-10-21 23:24:42 +00:00
Denis Vlasenko 6fa3ab3cf1 bzip2: make -d actually work 2007-10-21 18:59:58 +00:00
Denis Vlasenko e5387a0574 bb_askpass: handle Ctrl-C, restore termoios on Ctrl-C.
sulogin: remove alarm handling, as it is redundant there.
code shrink. After all differences cancel out:

   text    data     bss     dec     hex filename
 777543    1000    9532  788075   c066b busybox_old
 777543    1000    9532  788075   c066b busybox_unstripped
2007-10-20 19:20:22 +00:00
Denis Vlasenko 037576d77b read_line_input: fix it to not do any fancy editing if echoing is disabled.
ash: make read handling both more correct and smaller

read_line_input                                     4037    4101     +64
input_backward                                       140     139      -1
readcmd                                             1079    1070      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 65/-10)             Total: 54 bytes
   text    data     bss     dec     hex filename
 777575    1000    9532  788107   c068b busybox_old
 777629    1000    9532  788161   c06c1 busybox_unstripped
2007-10-20 18:30:38 +00:00
Denis Vlasenko 99014e8965 more fixes for help text wrt long options 2007-10-20 14:54:58 +00:00
Denis Vlasenko a03945aa84 website: add link to "No ifup" document 2007-10-20 04:44:08 +00:00
Denis Vlasenko 2edbc2ab85 ping: fix breakage from -I fix
passwd: SELinux support by KaiGai Kohei <kaigai@ak.jp.nec.com>
2007-10-20 02:00:49 +00:00
Denis Vlasenko aa7a888e42 kbd_mode: new applet by Loïc Grenié <loic.grenie@gmail.com>
kbd_mode_main                                          -     189    +189
packed_usage                                       22745   22833     +88
applets                                             3132    3144     +12
static.opts                                            7      12      +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 294/0)             Total: 294 bytes
   text    data     bss     dec     hex filename
 777210    1000    9532  787742   c051e busybox_old
 777575    1000    9532  788107   c068b busybox_unstripped
2007-10-20 00:17:34 +00:00
Denis Vlasenko 85ff862753 mkswap: selinux support by KaiGai Kohei <kaigai@ak.jp.nec.com> 2007-10-19 21:49:48 +00:00
Denis Vlasenko 1a7afb48da paing: make -I ethN work too (-I addr already worked) 2007-10-19 21:39:25 +00:00
Denis Vlasenko fcc569637b unzip: add a comment explaining why we don't die 2007-10-19 21:03:09 +00:00
Denis Vlasenko bc7c5d082e unzip: fix endianness bugs 2007-10-18 23:27:46 +00:00
Denis Vlasenko 34cd7afc49 httpd: free big buffer after use; improve grep-ability of 'headers' variable 2007-10-18 13:01:22 +00:00
Denis Vlasenko f74194e942 xatonum.h: add comment
lineedit: fix typo in comment
httpd: support for proxying connection to other http server
(by Alex Landau <landau_alex@yahoo.com>)
2007-10-18 12:54:39 +00:00
Denis Vlasenko 0363078437 more of usage text fixes wrt long options 2007-10-18 11:11:12 +00:00
Denis Vlasenko 73e5ed2206 exclude --longopts from usage texts if those are disabled 2007-10-18 10:52:36 +00:00
Denis Vlasenko 740eae0585 snv add setsebool 2007-10-18 10:46:42 +00:00
Denis Vlasenko e87b8689d2 telnetd: make sure telnetd -K exits if child dies 2007-10-17 14:33:31 +00:00
Denis Vlasenko 9e23767ef5 telnetd: trivial optimization 2007-10-17 11:18:49 +00:00
Denis Vlasenko 0de37e10ed ash: use fdprintf, not dprintf.
*: trailing whitespace removed
2007-10-17 11:08:53 +00:00
Denis Vlasenko 31acd1ba0a bzip2: more of code shrink
compressStream                                       503     473     -30
BZ2_bzCompress                                        78       -     -78
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-108)           Total: -108 bytes
   text    data     bss     dec     hex filename
 676300    2538   12104  690942   a8afe busybox_old
 676192    2538   12104  690834   a8a92 busybox_unstripped
2007-10-17 10:14:11 +00:00
Denis Vlasenko 16e74b7464 another fix for build failure found by randomconfig 2007-10-17 09:59:01 +00:00
Denis Vlasenko aff3a306b8 even more fixes from randomconfig runs 2007-10-16 23:00:50 +00:00
Denis Vlasenko 5576136563 fixes revealed by randomconfig run 2007-10-16 22:53:05 +00:00
Denis Vlasenko 23c8128916 telnetd: fix comment 2007-10-16 22:01:23 +00:00
Denis Vlasenko f472b237a1 telnetd: code shrink suggested by Ralf Friedl <Ralf.Friedl@online.de> 2007-10-16 21:35:17 +00:00
Denis Vlasenko 686b0ef7d8 bzip2: move state pointer to the offset 0 (smaller code)
ifdef out DecompressEnd if FEATURE_CLEAN_UP is not seleted

fallbackSort                                        1655    1672     +17
mainSort                                            2447    2458     +11
bzip2_main                                           109     119     +10
.rodata                                           123466  123469      +3
generateMTFValues                                    433     435      +2
handle_compress                                      355     356      +1
BZ2_bzCompress                                        79      78      -1
prepare_new_block                                     55      48      -7
compressStream                                       547     503     -44
sendMTFValues                                       2225    2140     -85
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/4 up/down: 44/-137)           Total: -93 bytes
   text    data     bss     dec     hex filename
 676421    2538   12104  691063   a8b77 busybox_old
 676328    2538   12104  690970   a8b1a busybox_unstripped
2007-10-16 14:07:41 +00:00
Denis Vlasenko 008eda2c54 bzip2: make -s equivalent to -2 (compatible with standard bzip2)
telnetd: typo fix in comment
2007-10-16 10:47:27 +00:00
Denis Vlasenko 2450c450ab telnetd: at Alexander Kriegisch <Alexander@kriegisch.name> insistence
add an option to close sessions as soon as child exits.
Maybe it should be a CONFIG option. OTOH, maybe it should be always on,
as it mimics, say, getty's behaviour.

function                                             old     new   delta
handle_sigchld                                         -      49     +49
telnetd_main                                        1312    1355     +43
.rodata                                           123429  123466     +37
packed_usage                                       22770   22806     +36
make_new_session                                     525     532      +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/0 up/down: 172/0)             Total: 172 bytes
   text    data     bss     dec     hex filename
 676285    2538   12104  690927   a8aef busybox_old
 676421    2538   12104  691063   a8b77 busybox_unstripped
2007-10-15 22:09:15 +00:00
Denis Vlasenko 10916c5c6b telnetd: document bug in remove_iacs. reinstate band-aid
which was making it near-impossible to trigger.
remove memmove call which was happening at each network read,
and in 99%+ cases was not needed. Unfortunately, +50 bytes.
2007-10-15 17:28:00 +00:00
Denis Vlasenko 59d7c43dbe telnetd: some simplifications and better error hadling.
telnetd: don't SIGKILL child when closing the session.
kernel will seng SIGHUP for us.

static.iacs_to_send                                    -      15     +15
.rodata                                           123418  123429     +11
make_new_session                                     549     525     -24
send_iac                                              26       -     -26
free_session                                         144     118     -26
telnetd_main                                        1303    1261     -42
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/3 up/down: 26/-118)           Total: -92 bytes
   text    data     bss     dec     hex filename
 676341    2538   12104  690983   a8b27 busybox_old
 676234    2538   12104  690876   a8abc busybox_unstripped
2007-10-15 15:19:36 +00:00
Denis Vlasenko d898b8600c bzip2: update help text 2007-10-14 07:57:26 +00:00
Denis Vlasenko b6ccd32e3f bzip2: implement -1..-9 command line flags 2007-10-14 07:51:19 +00:00
Denis Vlasenko 6a9154b6f6 bzip2: eliminate some divisions 2007-10-14 07:49:48 +00:00
Denis Vlasenko 3f5fdc7572 remove trailing whitespace 2007-10-14 04:55:59 +00:00
Denis Vlasenko be039374f3 setsebool: new applet (Yuichi Nakamura <ynakam@hitachisoft.jp>) 2007-10-14 04:48:44 +00:00
Denis Vlasenko 4a4575686e httpd: fix bug where we were trying to read more POSTDATA than content-length 2007-10-14 02:34:20 +00:00
Denis Vlasenko 9435993b01 bzip2: code size shrink 2007-10-14 01:37:53 +00:00
Denis Vlasenko be5a7b9655 bzip2: remove files which are not used anymore 2007-10-14 00:44:10 +00:00
Denis Vlasenko ef3aabe906 bzip2: size reduction, to just below 9k. 2007-10-14 00:43:01 +00:00
Denis Vlasenko 77f1ec1b9b bzip2: port bzip2 1.0.4 to busybox. note: bzip2 code resides
in separate directory (archival/bz/*)
and is covered by BSD-style license.
code size: 13k
2007-10-13 03:36:03 +00:00
Denis Vlasenko 11c23d7b99 whitespace/style fix 2007-10-11 19:53:10 +00:00
Denis Vlasenko 8add068573 mt: eliminate vector of structures with pointers (bad for libbusybox).
It's a win for static build too:

function                                             old     new   delta
opcode_name                                            -     213    +213
opcode_value                                           -      68     +68
mt_main                                              281     256     -25
opcodes                                              280       -    -280
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 0/1 up/down: 281/-305)          Total: -24 bytes
   text    data     bss     dec     hex filename
 767403     974    9420  777797   bde45 busybox_old
 767224     974    9420  777618   bdd92 busybox_unstripped
2007-10-11 19:38:59 +00:00
Denis Vlasenko 2ea8c40e8f stty: incorporate strings into struct instead of keeping pointers there.
static:
   text    data     bss     dec     hex filename
 767535     974    9420  777929   bdec9 busybox_old
 767403     974    9420  777797   bde45 busybox_unstripped

dynamic -fpic:
   text    data     bss     dec     hex filename
 718954   14030   12032  745016   b5e38 busybox_old
 720278   12534   12032  744844   b5d8c busybox_unstripped
2007-10-11 16:02:36 +00:00
Denis Vlasenko 4f95e5aab8 vi: don't wait 50 ms before reading ESC sequences
inetd,syslogd: use safe_read instead of open-coded EINTR handling
syslogd: bail out if you see null read from Unix socket
(should never happen, but if it does, spinning forever
and eating 100% CPU is not a good idea)
2007-10-11 10:10:15 +00:00
Denis Vlasenko f9566d8c29 trim too verbose help texts 2007-10-11 10:07:24 +00:00
Denis Vlasenko 15cb4a4272 fix a problem with two different applet_name's 2007-10-11 10:06:26 +00:00
Denis Vlasenko 9b49a5ed85 add -fvisibility=hidden to CC flags, mark XXX_main functions
EXTERNALLY_VISIBLE. 5% size reduction of libbusybox.so
2007-10-11 10:05:36 +00:00
Denis Vlasenko 8d82cf72c9 add -fpic to CC flags when we build libbusybox (14% smaller .so) 2007-10-11 10:02:52 +00:00
Denis Vlasenko 52a4388d95 bunzip: small code shrink and consmetics
read_bunzip                                          276     283      +7
get_bits                                             184     162     -22
get_next_block                                      1833    1810     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 7/-45)             Total: -38 bytes
2007-10-10 20:53:41 +00:00
Denis Vlasenko db60bcf1b7 ip tunnel parameter parsing fix by Jean Wolter <jw5@os.inf.tu-dresden.de> 2007-10-10 14:43:03 +00:00
Denis Vlasenko 724d196c75 Move applets/applet.c into libbb, allows to get rid of --whole-archive
(smaller code). Tested in static and shared mode.
2007-10-10 14:41:07 +00:00
Denis Vlasenko 82d38dab91 get rid of global "struct bb_applet *current_applet" 2007-10-10 14:38:47 +00:00
Denis Vlasenko 141750e388 trylink: s/strip/$STRIP/g 2007-10-10 10:05:35 +00:00
Denis Vlasenko 88ce2748e4 typo fix in help text 2007-10-09 18:08:04 +00:00
Denis Vlasenko 42e418292d trylink: trivial cleanup 2007-10-09 18:01:13 +00:00
Denis Vlasenko 01f3b2c91a trylink: reformat link flags for readability
trylink: add --sort-section alignment:
    text           data     bss     dec     hex filename
-   6557            428    3260   10245    2805 busybox
+   6555            428    3260   10243    2803 busybox
- 909621           1076   12108  922805   e14b5 libbusybox.so.1.8.0.svn
+ 908868           1050   12016  921934   e114e libbusybox.so.1.8.0.svn
2007-10-09 13:49:26 +00:00
Denis Vlasenko d19b87ece4 trylink: remove useless redirects, add missing error checks 2007-10-09 13:08:02 +00:00
Denis Vlasenko 8d755adc1a trylink: trivial fixes 2007-10-09 10:15:41 +00:00
Denis Vlasenko e9fd69c8e8 make "individual applets" build less noisy.
add *.tmp to list of files deleted by make mrproper.
2007-10-08 22:16:14 +00:00
Denis Vlasenko d419a9f830 whitespace fix 2007-10-08 20:45:42 +00:00
Denis Vlasenko ac7d0e375e add libbb/appletlib.c 2007-10-08 19:32:12 +00:00
Denis Vlasenko 642a52d65e make --help work for "individual applets" too. 2007-10-07 21:00:41 +00:00
Denis Vlasenko d62fd84d4b libbusybox: move (possibly compressed) help stuff into libbusybox.
Makes individual binaries much smaller.
2007-10-07 20:46:34 +00:00
Denis Vlasenko 7930bcf736 trim too verbose help messages 2007-10-07 19:13:55 +00:00
Denis Vlasenko 5037b21478 website: "BusyBox Weekly News" didn't really work, remove link 2007-10-07 18:10:44 +00:00
Denis Vlasenko 41770226bb ash: revert "cat | jobs" fix, it causes more problems than good 2007-10-07 18:02:52 +00:00
Denis Vlasenko f545be083d reviving libbusybox, adding CONFIG_INDIVIDUAL part 4 2007-10-07 17:06:26 +00:00
Denis Vlasenko def8898596 reviving libbusybox, adding CONFIG_INDIVIDUAL part 3 2007-10-07 17:06:01 +00:00
Denis Vlasenko 76a6b236a9 reviving libbusybox, adding CONFIG_INDIVIDUAL part 2 2007-10-07 17:05:42 +00:00
Denis Vlasenko 3240474c23 reviving libbusybox, adding CONFIG_INDIVIDUAL part 1 2007-10-07 17:05:22 +00:00
Bernhard Reutner-Fischer e747f62ed6 - mark TODO: use index_in_str_array() 2007-10-06 20:47:53 +00:00
Denis Vlasenko 339936be00 chpst: fix whitespace damage
svlogd: fix bug (two different "line" variables); stop using data/bss

function                                             old     new   delta
processorstop                                        419     432     +13
rotate                                               514     525     +11
buffer_pwrite                                        493     499      +6
sig_term_handler                                      68      70      +2
sig_hangup_handler                                    34      36      +2
sig_alarm_handler                                     34      36      +2
rmoldest                                             305     307      +2
processorstart                                       401     403      +2
logdir_close                                         188     190      +2
tmaxflag                                               1       -      -1
rotateasap                                             1       -      -1
repl                                                   1       -      -1
reopenasap                                             1       -      -1
linecomplete                                           1       -      -1
exitasap                                               1       -      -1
wstat                                                  4       -      -4
verbose                                                9       5      -4
replace                                                4       -      -4
nearest_rotate                                         4       -      -4
linemax                                                4       -      -4
linelen                                                4       -      -4
line                                                   4       -      -4
fndir                                                  4       -      -4
fl_flag_0                                              4       -      -4
fdwdir                                                 4       -      -4
dirn                                                   4       -      -4
dir                                                    4       -      -4
blocked_sigset                                         4       -      -4
sig_child_handler                                    248     239      -9
logdirs_reopen                                      1263    1240     -23
buffer_pread                                         532     473     -59
svlogd_main                                         1466    1367     -99
------------------------------------------------------------------------------
(add/remove: 0/18 grow/shrink: 9/5 up/down: 42/-248)         Total: -206 bytes
   text    data     bss     dec     hex filename
 770916     989    9496  781401   bec59 busybox_old
 770768     980    9448  781196   beb8c busybox_unstripped
2007-10-05 22:11:06 +00:00
Denis Vlasenko 23e3e25df6 chpst: stop using data/bss
function                                             old     new   delta
chpst_main                                          1066    1089     +23
set_user                                               4       -      -4
root                                                   4       -      -4
nicelvl                                                4       -      -4
limitt                                                 4       -      -4
limits                                               196     192      -4
limitr                                                 4       -      -4
limitp                                                 4       -      -4
limito                                                 4       -      -4
limitl                                                 4       -      -4
limitf                                                 4       -      -4
limitd                                                 4       -      -4
limitc                                                 4       -      -4
limita                                                 4       -      -4
env_user                                               4       -      -4
env_dir                                                4       -      -4
------------------------------------------------------------------------------
(add/remove: 0/14 grow/shrink: 1/1 up/down: 23/-60)           Total: -37 bytes
   text    data     bss     dec     hex filename
 770892    1029    9520  781441   bec81 busybox_old
 770916     989    9496  781401   bec59 busybox_unstripped
2007-10-05 21:23:49 +00:00
Denis Vlasenko 91e5203205 stat: code shrink; stop using bss; stop using strncat incorrectly
function                                             old     new   delta
printfs                                                -      28     +28
strcatc                                                -      26     +26
human_time                                            41      44      +3
print_it                                             229     219     -10
buf                                                   30       -     -30
print_statfs                                         420     358     -62
print_stat                                          1089     921    -168
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/3 up/down: 57/-270)          Total: -213 bytes
   text    data     bss     dec     hex filename
 771105    1029    9552  781686   bed76 busybox_old
 770892    1029    9520  781441   bec81 busybox_unstripped
2007-10-05 20:31:23 +00:00
Denis Vlasenko 91e80c2be7 delete now unused check_header_gzip.c
sum: do not use uintmax needlessly
2007-10-05 20:29:31 +00:00
Denis Vlasenko 226002ea74 tail: sizeof(buf) is sizeof(char*)! must be BUFSIZ 2007-10-05 19:17:16 +00:00
Denis Vlasenko d21f596ddb add tests for gunzip 2007-10-05 15:27:03 +00:00
Denis Vlasenko 5dd8a03665 gunzip: support concatenated gz files.
text    data     bss     dec     hex filename
 770988    1029    9552  781569   bed01 busybox.t0/busybox
 771105    1029    9552  781686   bed76 busybox.t3/busybox
2007-10-05 15:26:08 +00:00
Denis Vlasenko 368a12efc2 tail: work correctly on /proc files (Kazuo TAKADA <kztakada@sm.sony.co.jp>) 2007-10-02 10:17:56 +00:00
Denis Vlasenko ebeaea04dc logger: fix a problem of losing all argv except first 2007-10-02 09:57:41 +00:00
Bernhard Reutner-Fischer d24d5c84c2 - ditch 2 bytes 2007-10-01 18:04:42 +00:00
Denis Vlasenko feb7ae7f01 printf("%s\n") -> puts() 2007-10-01 12:05:12 +00:00
Denis Vlasenko 0c97c9d437 'simple' error message functions by Loic Grenie <loic.grenie@gmail.com>.
263 bytes saved.
2007-10-01 11:58:38 +00:00
Denis Vlasenko d65ea39ffc hush: fix glob() abuse. Code was making unfounded assumptions how
glob() works, and it broke horribly on specific uclibc config.
2007-10-01 10:02:25 +00:00
Denis Vlasenko ff0976248a hush: int->smallint for flag vars; make some names more "greppable" 2007-10-01 10:00:45 +00:00
Denis Vlasenko 8412d7959a hush: feeble attempt at making it more NOMMU-friendly 2007-10-01 09:59:47 +00:00
Denis Vlasenko a0898170d8 hush: stop doing manual acounting of open fd's, kernel can do it for us 2007-10-01 09:59:01 +00:00
Denis Vlasenko 96e1b38586 introduce and use close_on_exec_on(fd). -50 bytes. 2007-09-30 23:50:48 +00:00
Denis Vlasenko deabacdf91 move udhcp_{client/server}_config to common_bufsiz1
udhcp_run_script                                    1108    1151     +43
init_packet                                          209     210      +1
udhcpc_main                                         2395    2393      -2
udhcp_client_config                                   56       -     -56
udhcp_server_config                                   88       -     -88
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/1 up/down: 44/-146)          Total: -102 bytes
   text    data     bss     dec     hex filename
 771326    1029    9696  782051   beee3 busybox_old
 771383    1029    9552  781964   bee8c busybox_unstripped
2007-09-30 17:55:43 +00:00
Denis Vlasenko d7b3350eb3 dhcpreplay: code shrink, -40 bytes 2007-09-30 17:54:10 +00:00
Denis Vlasenko 5fb09656ca fixlet to pgrep/pkill 2007-09-30 16:36:02 +00:00
Denis Vlasenko a4f4de9b7e print_signames_and_exit -> print_signames (because of "ash calls kill_main") 2007-09-30 16:32:01 +00:00
Denis Vlasenko 605b20e277 replace printf with fputs where appropriate 2007-09-30 16:22:36 +00:00
Denis Vlasenko 1eecaf26b0 libiproute: add missing break's 2007-09-30 16:04:21 +00:00
Denis Vlasenko e03c77fe15 announce 1.7.2 on the website 2007-09-30 00:06:42 +00:00
Denis Vlasenko f60d62638b small code shrink 2007-09-29 23:26:52 +00:00
Denis Vlasenko 64e619c0c8 build system: pass EXTRA_LDFLAGS to final link stage 2007-09-29 22:52:25 +00:00
Denis Vlasenko 304a97a1ec trivial typo fix 2007-09-29 22:49:26 +00:00
Denis Vlasenko 72e1c89d97 pgrep,pkill: new applets by Loic Grenie <loic.grenie@gmail.com> 2007-09-29 22:26:01 +00:00
Denis Vlasenko 2450e4ba44 xrealloc_getcwd_or_warn: smaller cod and less wasted RAM at run time 2007-09-29 19:19:55 +00:00
Denis Vlasenko 1ebd0a6d91 remove if() which is always true 2007-09-29 18:27:14 +00:00
Denis Vlasenko 66bbfbd581 bunzip2: trim verbose messages
text    data     bss     dec     hex filename
 770752    1029    9696  781477   beca5 busybox_old
 770691    1029    9696  781416   bec68 busybox_unstripped
2007-09-28 23:45:56 +00:00
Denis Vlasenko 3d2a9217a7 httpd: trivial simplification 2007-09-28 22:35:29 +00:00
Denis Vlasenko ab8c9378c9 more "if (p) free(p)" fixes; fix a typo in comment 2007-09-28 22:13:55 +00:00
Denis Vlasenko 6081868ee3 fix "if (p) free(p)" constructs 2007-09-28 22:07:23 +00:00
Denis Vlasenko e918e155ed remove stray semicolon 2007-09-28 21:56:36 +00:00
Denis Vlasenko 0afdfdf649 hdparm: paranoia-induced fix against theoretical div-by-0 case 2007-09-28 13:41:41 +00:00
Denis Vlasenko 920c52a5c8 hdparm: more robust (re overflows) code. +38 bytes. 2007-09-28 13:38:08 +00:00
Denis Vlasenko a0ad43b80b trivial fix in setfiles. spotted by Yuichi Nakamura <ynakam@hitachisoft.jp> 2007-09-28 11:37:38 +00:00
Denis Vlasenko a7bc9ac8f8 hdparm: reduce possibility of numeric overflow in -T.
do_time                                              386     410     +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 24/0)               Total: 24 bytes
2007-09-28 11:21:47 +00:00
Denis Vlasenko b925605441 assorted static vars removal
function                                             old     new   delta
tcpudpsvd_main                                      1829    1839     +10
update_status                                        567     569      +2
sigterm                                                1       -      -1
.........
dhcprelay_signal_handler                               8       -      -8
nfs_strerror                                          60      49     -11
singlemount                                         4579    4564     -15
static.p                                              16       -     -16
svstatus                                              20       -     -20
dhcprelay_xid_list                                    32       -     -32
runsv_main                                          1785    1746     -39
static.buf                                            74      28     -46
svd                                                   56       -     -56
dhcprelay_main                                      1141    1080     -61
------------------------------------------------------------------------------
(add/remove: 0/20 grow/shrink: 2/10 up/down: 12/-386)        Total: -374 bytes
2007-09-28 10:29:17 +00:00
Denis Vlasenko c3122bca53 hdparm: simplify timing measurement (it wa the last last user
of setitimer in the tree).

static.thousand                                       16       -     -16
read_big_block                                        81      46     -35
getitimer                                             41       -     -41
setitimer                                             47       -     -47
__GI_setitimer                                        47       -     -47
do_time                                              480     386     -94
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 0/2 up/down: 0/-280)           Total: -280 bytes

M    miscutils/hdparm.c
2007-09-28 10:28:03 +00:00
Denis Vlasenko 0d3c6afc93 hdparm: get rid of static variables
process_dev                                         5309    5311      +2
unregister_hwif                                        1       -      -1
...........
Xreadahead                                             4       -      -4
seek_to_zero                                          25      17      -8
hdparm_main                                         1242    1227     -15
do_time                                              547     480     -67
------------------------------------------------------------------------------
(add/remove: 0/83 grow/shrink: 1/3 up/down: 2/-248)          Total: -246 bytes
2007-09-28 10:25:32 +00:00
Denis Vlasenko 8607677529 libbb: make const_int_0 reside in rodata 2007-09-27 20:49:57 +00:00
Denis Vlasenko 1d31f0f380 libbb: align bb_common_bufsiz1 to "long long" 2007-09-27 20:46:08 +00:00
Denis Vlasenko 78e2d4e361 less: make 'f' page forward 2007-09-27 17:11:48 +00:00
Denis Vlasenko a36535b067 wget: -O FILE is allowed to overwrite existing file (compat) 2007-09-27 15:07:23 +00:00
Denis Vlasenko 6124c37135 zcip: fix unaligned trap on ARM 2007-09-27 11:15:42 +00:00
Denis Vlasenko 7c654ae9df remove stray '/*' within comment 2007-09-27 10:26:59 +00:00
Denis Vlasenko 892536f019 hdparm: use fixed fd #3 for device being interrogated
(surprisingly, on i386 almost no code size change)
2007-09-27 10:23:34 +00:00
Denis Vlasenko 4daad9004d introduce bb_putchar(). saves ~1800 on uclibc (less on glibc). 2007-09-27 10:20:47 +00:00
Denis Vlasenko 1acdc89e99 style and message text fixes 2007-09-27 10:17:53 +00:00
Denis Vlasenko 86b29ea9e8 lineedit: plug memory leak 2007-09-27 10:17:16 +00:00
Denis Vlasenko 33b900f984 vlock: get rid of statics 2007-09-27 10:12:02 +00:00
Denis Vlasenko 5d61e71c3a introduce safe_poll (fixes a problem in top)
function                                             old     new   delta
safe_poll                                              -      77     +77
svlogd_main                                         1470    1466      -4
zcip_main                                           1530    1524      -6
forkexec                                            1345    1338      -7
decode_format_string                                 795     788      -7
collect_blk                                          474     467      -7
buffer_pread                                         540     532      -8
tftp                                                1182    1172     -10
microcom_main                                        763     749     -14
arpping                                              441     424     -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/9 up/down: 77/-80)             Total: -3 bytes
   text    data     bss     dec     hex filename
 770162    1034   10404  781600   bed20 busybox_old
 770158    1034   10404  781596   bed1c busybox_unstripped
2007-09-27 10:09:59 +00:00
Denis Vlasenko c9dc2ac578 make variables static 2007-09-27 10:08:02 +00:00
Denis Vlasenko a619b85ef5 check-lxdialog.sh: no point in giving up, maybe -lcurses will work? 2007-09-26 18:18:59 +00:00
Denis Vlasenko b042bd9514 load_policy: update (Yuichi Nakamura <ynakam@hitachisoft.jp>) 2007-09-26 18:01:32 +00:00
Denis Vlasenko dd5e11bb05 chcon: trivial fix 2007-09-26 17:55:55 +00:00
Denis Vlasenko 7ae209c019 losetup: support -f (Loic Grenie <loic.grenie@gmail.com>)
function                                             old     new   delta
losetup_main                                         238     278     +40
packed_usage                                       23021   23027      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 46/0)               Total: 46 bytes
2007-09-26 17:54:18 +00:00
Denis Vlasenko 137fbe495d runsvdir: fix "linear wait time" bug 2007-09-26 12:18:07 +00:00
Denis Vlasenko 3982407ba4 inetd: move struct fields around -> save .25 k of code
function                                             old     new   delta
freeconfig                                            75      76      +1
register_rpc                                         200     196      -4
dupconfig                                            165     159      -6
reapchild                                            173     166      -7
retry                                                 93      82     -11
goaway                                               112     101     -11
getconfigent                                        1241    1222     -19
setup                                                645     592     -53
inetd_main                                          2160    2107     -53
config                                              1602    1518     -84
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/9 up/down: 1/-248)           Total: -247 bytes
   text    data     bss     dec     hex filename
 773951    1038   10332  785321   bfba9 busybox_old
 773703    1038   10332  785073   bfab1 busybox_unstripped
2007-09-26 10:46:18 +00:00
Denis Vlasenko 4dd4e6d6b9 install: fix bug in "install -c file dir" (tries to copy dir into dir too)
install: 'support' (ignore) -v and -b
2007-09-26 10:34:54 +00:00
Denis Vlasenko 6a5377ac14 documentation bits in comments, no code changes 2007-09-25 18:35:28 +00:00
Denis Vlasenko ea7645bab6 cp: -r and -R imply -d (coreutils compat) 2007-09-25 18:06:36 +00:00
Denis Vlasenko 35465a3f00 httpd: small auth and IPv6 fixes (Kim B. Heino <Kim.Heino@bluegiga.com>) 2007-09-25 11:58:33 +00:00
Denis Vlasenko d9391b15f1 ed: large cleanup
function                                             old     new   delta
bad_nums                                               -      43     +43
skip_blank                                             -      24     +24
getNum                                               557     578     +21
insertLine                                           159     163      +4
setCurNum                                             31      33      +2
lastNum                                                4       -      -4
fileName                                               4       -      -4
dirty                                                  4       -      -4
curNum                                                 4       -      -4
curLine                                                4       -      -4
bufUsed                                                4       -      -4
bufSize                                                4       -      -4
bufPtr                                                 4       -      -4
bufBase                                                4       -      -4
printLines                                           357     345     -12
findLine                                             165     152     -13
lines                                                 16       -     -16
deleteLines                                          203     144     -59
readLines                                            538     473     -65
addLines                                             163      87     -76
marks                                                104       -    -104
termEdit                                             140       -    -140
ed_main                                             3125    2654    -471
------------------------------------------------------------------------------
(add/remove: 2/12 grow/shrink: 3/6 up/down: 94/-992)         Total: -898 bytes
   text    data     bss     dec     hex filename
 771142    1034   10564  782740   bf194 busybox_old
 770265    1034   10404  781703   bed87 busybox_unstripped

# size */ed.o
   text    data     bss     dec     hex filename
   6370       0     156    6526    197e editors.org/ed.o
   5505       0       0    5505    1581 editors/ed.o
2007-09-25 11:55:57 +00:00
Denis Vlasenko a545726d2b insmod: fix help text to not show options if only 2.6 was selected 2007-09-24 20:14:32 +00:00
Denis Vlasenko d9c6a001e3 insmod: shorten message text; style fixes 2007-09-24 19:54:36 +00:00
Denis Vlasenko e9b3321b9f tar: add a comment about previous subtle fix 2007-09-24 19:32:53 +00:00
Denis Vlasenko 86e0a22ec6 tar: strip leading '/' BEFORE memorizing hardlink's name
function                                             old     new   delta
writeFileToTarball                                  1362    1352     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10)             Total: -10 bytes
2007-09-24 19:07:57 +00:00
Denis Vlasenko 46a530626d ash: fix prompt expansion (Natanael Copa <natanael.copa@gmail.com>) 2007-09-24 18:30:02 +00:00
Denis Vlasenko 818322b9b1 *: kill bb_get_last_path_component, replace with two functions
(one which strips trailing slash and one which does not)
wget: straighten out as a result of above change
   text    data     bss     dec     hex filename
   5056       1       0    5057    13c1 busybox.t4/networking/wget.o
   5022       0       0    5022    139e busybox.t5/networking/wget.o
2007-09-24 18:27:04 +00:00
Denis Vlasenko a7ce207bd8 wget: get rid of setitimer
text    data     bss     dec     hex filename
   5110       1       0    5111    13f7 busybox.t3/networking/wget.o
   5056       1       0    5057    13c1 busybox.t4/networking/wget.o
2007-09-24 18:25:08 +00:00
Denis Vlasenko 47ddd01b3c wget: reorder functions, no code changes 2007-09-24 18:24:17 +00:00
Denis Vlasenko 7710563858 wget: code shrink, move data out of bss 2007-09-24 15:04:00 +00:00
Denis Vlasenko 06783a5140 wget: allow dots in header field names.
wget: code shrink

function                                             old     new   delta
gethdr                                               211     190     -21
wget_main                                           2609    2557     -52
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-73)             Total: -73 bytes
2007-09-24 13:51:54 +00:00
Denis Vlasenko 512a545f0d inetd: make some fields smaller, move data out of data/bss sections
function                                             old     new   delta
inetd_main                                          2125    2160     +35
setup                                                640     645      +5
initring                                              48      53      +5
reapchild                                            169     173      +4
retry                                                 92      93      +1
goaway                                               113     112      -1
inetd_setproctitle                                   175     173      -2
chargen_dg                                           229     227      -2
uid                                                    4       -      -4
.......................
Argv                                                   4       -      -4
rlim_ofile_cur                                         8       -      -8
config                                              1610    1602      -8
rlim_ofile                                            16       -     -16
getconfigent                                        1271    1241     -30
builtins                                             176     132     -44
ring                                                 128       -    -128
allsock                                              128       -    -128
------------------------------------------------------------------------------
(add/remove: 0/18 grow/shrink: 5/6 up/down: 50/-423)         Total: -373 bytes
   text    data     bss     dec     hex filename
 774144    1051   10708  785903   bfdef busybox_old
 774108    1039   10380  785527   bfc77 busybox_unstripped
$ size inetd.o inetd_orig.o
   text    data     bss     dec     hex filename
   9027       0       0    9027    2343 inetd.o
   9064      12     324    9400    24b8 inetd_orig.o
2007-09-24 10:41:30 +00:00
Denis Vlasenko 2a1d024333 run_parts: make it sort executables by name (required by API) 2007-09-23 18:34:49 +00:00
Denis Vlasenko 06b3cc2811 make fdisk compile on libc without llseek64 2007-09-23 14:05:54 +00:00
Denis Vlasenko 32a471e4db httpd: simplify CGI i/o loop. -200 bytes. 2007-09-23 13:56:57 +00:00
Denis Vlasenko 9a4e08eaa8 include libbb.h, not busybox.h 2007-09-22 21:37:27 +00:00
Bernhard Reutner-Fischer 73f56bb76d - actually mv microcom.c to miscutils 2007-09-22 21:18:46 +00:00
Bernhard Reutner-Fischer 3a252b8c12 - add microcom to defconfig 2007-09-22 21:13:17 +00:00
Denis Vlasenko 23856ab8e6 move microcom to miscutils 2007-09-22 20:51:41 +00:00
Bernhard Reutner-Fischer f588f70b91 - remove some trailing whitespace 2007-09-22 20:35:32 +00:00
Denis Vlasenko f34e821572 microcom: add copyright/license info 2007-09-22 20:23:57 +00:00
Denis Vlasenko 7b70d78de8 ash: remove erroneously applied patch 2007-09-21 22:48:02 +00:00
Denis Vlasenko f431017535 httpd: optional support for partial downloads 2007-09-21 22:35:18 +00:00
Denis Vlasenko bcceb0c5a4 ash: s/int/smallint/. -60 bytes. 2007-09-21 18:06:20 +00:00
Denis Vlasenko fc5d15912c test: correct confusing placement of "const" 2007-09-21 17:58:43 +00:00
Denis Vlasenko 707669501f microcom: add new applet, this time for real 2007-09-21 17:42:40 +00:00
Denis Vlasenko efd3f38f8c microcom: new applet by Vladimir Dronnikov <dronnikov@gmail.ru> 2007-09-21 13:43:28 +00:00
Denis Vlasenko 0beaff8c19 update Glenn McGrath's email address 2007-09-21 13:16:32 +00:00
Denis Vlasenko 9b0a439f02 remove stray 8-bit chars from copyright banner 2007-09-20 19:44:10 +00:00
Denis Vlasenko 27bd8d7146 announce 1.7.1 on website 2007-09-16 19:41:40 +00:00
Denis Vlasenko 2535f12cf2 httpd: do not clear environment
mount: mount helpers support (by Vladimir Dronnikov <dronnikov@gmail.ru>)
2007-09-15 13:28:30 +00:00
Denis Vlasenko 32eb1f6cb9 webpage: add a link to vda's "init must die" page 2007-09-13 20:20:44 +00:00
Denis Vlasenko a9335eafcf cp: make it a bit closer to POSIX, but still refuse to open and
write to dest which is a symlink.
2007-09-11 16:28:14 +00:00
Denis Vlasenko fa05074eee cp: make "cp file /dev/node" special case; explained in comments
function                                             old     new   delta
copy_file                                           1487    1538     +51
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 51/0)               Total: 51 bytes
   text    data     bss     dec     hex filename
 772502    1051   10724  784277   bf795 busybox_old
 772554    1051   10724  784329   bf7c9 busybox_unstripped
2007-09-11 10:39:13 +00:00
Denis Vlasenko 976690afe0 run_shell: code shrink for selinux 2007-09-10 17:17:01 +00:00
Denis Vlasenko a2f61012b6 setup_environment: code shrink
run_shell: mark as NORETURN
setup_environment, run_shell: add usage comments
login: add FIXME :(

function                                             old     new   delta
UNSPEC_print                                          64      66      +2
sulogin_main                                         509     506      -3
mkfs_minix_main                                     3070    3067      -3
login_main                                          1615    1612      -3
su_main                                              461     448     -13
setup_environment                                    261     206     -55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/5 up/down: 2/-77)             Total: -75 bytes
   text    data     bss     dec     hex filename
 772578    1051   10724  784353   bf7e1 busybox_old
 772502    1051   10724  784277   bf795 busybox_unstripped
2007-09-10 13:15:28 +00:00
Denis Vlasenko ac074b3f87 grep: delete obsolete comment 2007-09-10 12:23:27 +00:00
Denis Vlasenko 04ea11b033 grep: fix grep -F -e str1 -e str2 (was matching str2 only)
by replacing "=" by "|=" here:
  found |= strstr(line, gl->pattern) != NULL;
grep: optimization: stop on first -e match
grep: stop using bss. -40 bytes
2007-09-10 12:18:32 +00:00
Denis Vlasenko 476b070036 style fix, no code changes 2007-09-09 14:11:11 +00:00
Denis Vlasenko bf8fcaceb7 open_transformer: fix vda's goofup 2007-09-09 11:20:55 +00:00
Denis Vlasenko 4d7605af86 top: small fix for command line wrapping 2007-09-08 17:42:00 +00:00
Denis Vlasenko 4c1d88daff top: get rid of on-stack variable buffers, use permanent one.
code shrank with and without TOPMEM:

top_main                                             828     844     +16
display_process_list                                1525    1473     -52
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-52)            Total: -36 bytes

top_main                                            1150    1171     +21
display_topmem_process_list                         1150    1167     +17
display_process_list                                1525    1473     -52
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 38/-52)            Total: -14 bytes
2007-09-08 17:34:05 +00:00
Denis Vlasenko e7c1ad1540 top: add sizeof(G) check; fix style 2007-09-08 17:21:01 +00:00
Denis Vlasenko ff6e8e2974 top: TOPMEM feature - 's(how sizes)' command. +2.5k when enabled,
+80 bytes when disabled (mainly because of text wrapping fixes
in display_process_list).
2007-09-08 16:51:19 +00:00
Paul Fox 9382b3809b overload the existing '-q' flag so that if '-l' and '-q' are used
together, a "short form" listing (just pathnames) is generated.
change a few flag variables to "smallint" as well.
2007-09-07 20:28:25 +00:00
Denis Vlasenko c8d4d2f11d messages: by popular request allow PATH to be customized at build time
mount: smallish code shrink
2007-09-07 19:33:56 +00:00
Denis Vlasenko d7ecd863c8 syslogd: do not need to poll(), we can just block in read().
function                                             old     new   delta
syslogd_main                                        1206    1106    -100
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-100)           Total: -100 bytes
   text    data     bss     dec     hex filename
 769820    1051   10764  781635   bed43 busybox_old
 769702    1051   10764  781517   beccd busybox_unstripped
2007-09-07 13:53:32 +00:00
Denis Vlasenko 87f3b26b3a *: replace select-for-one descriptor with poll, it's smaller.
$ ./.cmk bloatcheck
function                                             old     new   delta
readit                                               406     364     -42
syslogd_main                                        1249    1206     -43
traceroute_main                                     4115    4060     -55
mysleep                                              112      45     -67
arpping                                              579     441    -138
tftp                                                1575    1182    -393
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-738)           Total: -738 bytes
   text    data     bss     dec     hex filename
 770580    1051   10764  782395   bf03b busybox_old
 769820    1051   10764  781635   bed43 busybox_unstripped
2007-09-07 13:43:28 +00:00
Paul Fox 40f0bcf9d3 fix infinite retry bug. also, reduce per-packet receive timeout
to something more reasonable than 5 seconds, and add simple
exponential backoff to compensate.  improves performance on
marginal networks.
2007-09-06 17:52:22 +00:00
Paul Fox dcf9bba3b7 fix -xdev behavior in the presence of two or more nested mount points
on the command line, e.g. "find / /boot -xdev".
2007-09-06 17:45:16 +00:00
Denis Vlasenko fdf9060aa3 umount: support (by ignoring) -i; style fixes 2007-09-06 16:57:05 +00:00
Denis Vlasenko cef23e0d8b usage: trim a bit
function                                             old     new   delta
packed_usage                                       23113   23011    -102
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-102)           Total: -102 bytes
   text    data     bss     dec     hex filename
 770610    1051   10764  782425   bf059 busybox_old
 770508    1051   10764  782323   beff3 busybox_unstripped
2007-09-05 15:45:51 +00:00
Denis Vlasenko 3638cc4462 watchdog: allow millisecond spec (-t 250ms)
function                                             old     new   delta
packed_usage                                       23069   23113     +44
static.suffixes                                        -      24     +24
watchdog_main                                        147     160     +13
static.V                                               -       1      +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 82/0)               Total: 82 bytes
2007-09-05 12:13:51 +00:00
Denis Vlasenko 211f7f88ae tar + gzip/bzip2/etc: support NOMMU machines (by Alex Landau <landau_alex@yahoo.com>) 2007-09-05 11:48:32 +00:00
Denis Vlasenko beffd43d8e busybox --install -s: prevent puzzling "/bin/busybox: Invalid argument" message
libbb: comment out realpath, add readlink which doesn't warn
2007-09-05 11:30:34 +00:00
Denis Vlasenko 7e0fbf9c26 tar: conditionally don't wait for vforked child to exec, as it always
works right on Linux, and anyway mayresult only on less-than-clear error
message only, it will not cause tar to misbehave.

function                                             old     new   delta
open_transformer                                      98      80     -18
writeTarFile                                         714     547    -167
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-185)           Total: -185 bytes
   text    data     bss     dec     hex filename
 770651    1051   10764  782466   bf082 busybox_old
 770463    1051   10764  782278   befc6 busybox_unstripped
2007-09-04 19:33:22 +00:00
Denis Vlasenko f0000653e9 mount: ignore NFS bg option on NOMMU machines 2007-09-04 18:30:26 +00:00
Denis Vlasenko 21b83cfb27 du: remove statics (by Bernhard Fischer <rep.dot.nop@gmail.com>)
$ ./.cmk bloatcheck
function                                             old     new   delta
du_main                                              340     348      +8
print                                                 39      40      +1
status                                               129     125      -4
slink_depth                                            4       -      -4
print_files                                            4       -      -4
one_file_system                                        4       -      -4
max_print_depth                                        4       -      -4
du_depth                                               4       -      -4
disp_hr                                                4       -      -4
count_hardlinks                                        4       -      -4
du                                                   407     401      -6
dir_dev                                                8       -      -8
------------------------------------------------------------------------------
(add/remove: 0/8 grow/shrink: 2/2 up/down: 9/-46)             Total: -37 bytes
   text    data     bss     dec     hex filename
    864      12      28     904     388 busybox.t3/coreutils/du.o
    867       0       0     867     363 busybox.t4/coreutils/du.o
 770647    1063   10788  782498   bf0a2 busybox.t3/busybox_unstripped
 770651    1051   10764  782466   bf082 busybox.t4/busybox_unstripped
2007-09-03 20:05:58 +00:00
Denis Vlasenko 82f3b16713 login: do reject wrong passwords with PAM auth 2007-09-03 11:56:27 +00:00
Denis Vlasenko 9862e6b056 trylink: reinstate accidentally deleted --verbose
trylink: remove commented-out parts
2007-09-03 11:28:14 +00:00
Bernhard Reutner-Fischer fc202427d5 - IFUPDOWN_IFSTATE_PATH depends on IFUPDOWN 2007-09-02 22:12:07 +00:00
Bernhard Reutner-Fischer d2bb2d3918 - Generally strip off -l that does not pull in a lib.
If l_list is non-empty then add the group flags.
2007-09-02 15:28:30 +00:00
Bernhard Reutner-Fischer 8d91c13df5 - fix bug where we linked again -lm even though it is not needed.
For BBOX_LIB_LIST="crypt m" trylink ... with just applet true, we pulled in
  libm because in this case we tried to use invalid flags (plain "-l" without
  a lib) which of course failed, thus the script thought that -lm was needed.

  The fix is not to pass "-l" without a lib if we are about to check if any
  or the last remaining lib is really needed.
2007-09-02 14:51:54 +00:00
Denis Vlasenko 7bc5360bba isrv: use monotonic_sec
runsv: do not use clock_gettime if !MONOTONIC_CLOCK
2007-08-31 21:45:52 +00:00
Denis Vlasenko 05241802a7 top: another readability fix 2007-08-29 18:34:26 +00:00
Denis Vlasenko fc1e9951c6 vsz and rss are unsigned longs (ulong ~= width of void* =>
suitable for expressing total RAM in system). We account
for "32 bit in 64 bit" systems by storing kbytes, not bytes
there. Should allow for up to ~2000 Gb RAM on 32 bits.
2007-08-29 18:23:36 +00:00
Denis Vlasenko 8bdba4d011 top: don't wait before final bailout (try top -b -n1).
top: make code a bit more readable.
2007-08-29 18:18:08 +00:00
Denis Vlasenko fb48f6c982 mount: allow (and ignore) -i 2007-08-29 11:49:41 +00:00
Denis Vlasenko 76c476f817 smart_ulltoa5: emit small letters k,m,g... - makes top
more readable
2007-08-28 20:04:15 +00:00
Denis Vlasenko b308d81e92 top: use poll instead of select for waiting on one descriptor
smart_ulltoa5: make it more cryptic. -50 bytes.

function                                             old     new   delta
passwd_main                                         1095    1103      +8
getNum                                               557     565      +8
buffer_fill_and_print                                 73      76      +3
udhcpc_main                                         2393    2395      +2
mkfs_minix_main                                     3071    3070      -1
dname_enc                                            377     373      -4
expmeta                                              480     472      -8
smart_ulltoa5                                        334     283     -51
top_main                                             911     815     -96
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/5 up/down: 21/-160)          Total: -139 bytes
   text    data     bss     dec     hex filename
 770872    1063   10788  782723   bf183 busybox_old
 770732    1063   10788  782583   bf0f7 busybox_unstripped
2007-08-28 19:35:34 +00:00
Denis Vlasenko 7d8de4d55d mount: don't close fd twice in NFS code 2007-08-28 11:23:23 +00:00
Denis Vlasenko 0f214ecef0 cp: fix recursion check to not waste bytes remembering names of dirs 2007-08-27 17:02:19 +00:00
Denis Vlasenko 8a5fab6333 cp: detect and prevent infinite recursion 2007-08-27 16:51:30 +00:00
Denis Vlasenko 512499c8ca ps: fix RSS parsing (rss field in /proc/PID/stat is in pages, not bytes) 2007-08-26 18:23:13 +00:00
Denis Vlasenko ec9781d5e4 add links to vda's pet projects 2007-08-26 16:39:47 +00:00
Denis Vlasenko 614aca61e5 install: shrink a bit, fix two buglets 2007-08-26 14:21:55 +00:00
Denis Vlasenko 6dd333dfe6 Start a small document "why ifupdown is bad" 2007-08-25 22:16:04 +00:00
Denis Vlasenko 30bab71f7b make copy_file() a bit easier to understand, and smaller
function                                             old     new   delta
copy_file                                           1565    1447    -118
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-118)           Total: -118 bytes
   text    data     bss     dec     hex filename
 770938    1063   10788  782789   bf1c5 busybox_old
 770814    1063   10788  782665   bf149 busybox_unstripped
2007-08-25 21:14:55 +00:00
Denis Vlasenko 737d131e5e support "#!/bin/busybox"-style wrappers. Needed for SELinux.
Patch by Yuichi Nakamura <ynakam@hitachisoft.jp>
2007-08-25 18:25:24 +00:00
Bernhard Reutner-Fischer 5222677176 - add Yann's email-addr 2007-08-25 11:16:18 +00:00
Denis Vlasenko 6666ac42a5 cp,mv: simpler arg[cv] handling -> smallish code savings 2007-08-24 21:46:24 +00:00
Bernhard Reutner-Fischer 2062fc4155 - cosmetic html cleanup 2007-08-24 14:32:23 +00:00
Bernhard Reutner-Fischer 6a7b7ce23e - obfuscate addrs a little bit 2007-08-24 14:30:59 +00:00
Denis Vlasenko 3d829627fb cp: make POSIX-me-harder mode complain with a bit less insane message 2007-08-24 14:23:57 +00:00
Denis Vlasenko cab774d6e5 spelling fixes to website 2007-08-24 12:52:04 +00:00
Denis Vlasenko 46fc23b532 Cosmetic fixes to webpage 2007-08-24 11:49:55 +00:00
Denis Vlasenko 30f00a4286 add missed attribution to httpd sendfile support 2007-08-24 11:18:21 +00:00
Denis Vlasenko 66dc9068eb Start 1.8.x cycle 2007-08-24 11:05:49 +00:00
444 changed files with 20595 additions and 11231 deletions

No files matched your search

+1 -1
View File
@@ -95,7 +95,7 @@ Stephan Linz <linz@li-pro.net>
John Lombardo <john@deltanet.com>
tr
Glenn McGrath <bug1@iinet.net.au>
Glenn McGrath <glenn.l.mcgrath@gmail.com>
Common unarchiving code and unarchiving applets, ifupdown, ftpgetput,
nameif, sed, patch, fold, install, uudecode.
Various bugfixes, review and apply numerous patches.
+99 -50
View File
@@ -186,10 +186,10 @@ config FEATURE_SUID_CONFIG
The file has to be owned by user root, group root and has to be
writeable only by root:
(chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf)
(chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf)
The busybox executable has to be owned by user root, group
root and has to be setuid root for this to work:
(chown 0.0 /bin/busybox; chmod 4755 /bin/busybox)
(chown 0.0 /bin/busybox; chmod 4755 /bin/busybox)
Robert 'sandman' Griebl has more information here:
<url: http://www.softforge.de/bb/suid.html >.
@@ -283,41 +283,80 @@ config STATIC
config BUILD_LIBBUSYBOX
bool "Build shared libbusybox"
default n
depends on !FEATURE_PREFER_APPLETS
help
Build a shared library libbusybox.so which contains all
libraries used inside busybox.
Build a shared library libbusybox.so.N.N.N which contains all
busybox code.
This is an experimental feature intended to support the upcoming
"make standalone" mode. Enabling it against the one big busybox
binary serves no purpose (and increases the size). You should
almost certainly say "no" to this right now.
This feature allows every applet to be built as a tiny
separate executable. Enabling it for "one big busybox binary"
approach serves no purpose and increases code size.
You should almost certainly say "no" to this.
config FEATURE_FULL_LIBBUSYBOX
bool "Feature-complete libbusybox"
default n if !FEATURE_SHARED_BUSYBOX
depends on BUILD_LIBBUSYBOX
help
Build a libbusybox with the complete feature-set, disregarding
the actually selected config.
### config FEATURE_FULL_LIBBUSYBOX
### bool "Feature-complete libbusybox"
### default n if !FEATURE_SHARED_BUSYBOX
### depends on BUILD_LIBBUSYBOX
### help
### Build a libbusybox with the complete feature-set, disregarding
### the actually selected config.
###
### Normally, libbusybox will only contain the features which are
### used by busybox itself. If you plan to write a separate
### standalone application which uses libbusybox say 'Y'.
###
### Note: libbusybox is GPL, not LGPL, and exports no stable API that
### might act as a copyright barrier. We can and will modify the
### exported function set between releases (even minor version number
### changes), and happily break out-of-tree features.
###
### Say 'N' if in doubt.
Normally, libbusybox will only contain the features which are
used by busybox itself. If you plan to write a separate
standalone application which uses libbusybox say 'Y'.
Note: libbusybox is GPL, not LGPL, and exports no stable API that
might act as a copyright barrier. We can and will modify the
exported function set between releases (even minor version number
changes), and happily break out-of-tree features.
Say 'N' if in doubt.
config FEATURE_SHARED_BUSYBOX
bool "Use shared libbusybox for busybox"
default y if BUILD_LIBBUSYBOX
config FEATURE_INDIVIDUAL
bool "Produce a binary for each applet, linked against libbusybox"
default y
depends on !STATIC && BUILD_LIBBUSYBOX
help
Use libbusybox.so also for busybox itself.
You need to have a working dynamic linker to use this variant.
If your CPU architecture doesn't allow for sharing text/rodata
sections of running binaries, but allows for runtime dynamic
libraries, this option will allow you to reduce memory footprint
when you have many different applets running at once.
If your CPU architecture allows for sharing text/rodata,
having single binary is more optimal.
Each applet will be a tiny program, dynamically linked
against libbusybox.so.N.N.N.
You need to have a working dynamic linker.
config FEATURE_SHARED_BUSYBOX
bool "Produce additional busybox binary linked against libbusybox"
default y
depends on !STATIC && BUILD_LIBBUSYBOX
help
Build busybox, dynamically linked against libbusybox.so.N.N.N.
You need to have a working dynamic linker.
### config BUILD_AT_ONCE
### bool "Compile all sources at once"
### default n
### help
### Normally each source-file is compiled with one invocation of
### the compiler.
### If you set this option, all sources are compiled at once.
### This gives the compiler more opportunities to optimize which can
### result in smaller and/or faster binaries.
###
### Setting this option will consume alot of memory, e.g. if you
### enable all applets with all features, gcc uses more than 300MB
### RAM during compilation of busybox.
###
### This option is most likely only beneficial for newer compilers
### such as gcc-4.1 and above.
###
### Say 'N' unless you know what you are doing.
config LFS
bool "Build with Large File Support (for accessing files > 2 GB)"
@@ -331,25 +370,6 @@ config LFS
cp, mount, tar, and many others. If you want to access files larger
than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'.
config BUILD_AT_ONCE
bool "Compile all sources at once"
default n
help
Normally each source-file is compiled with one invocation of
the compiler.
If you set this option, all sources are compiled at once.
This gives the compiler more opportunities to optimize which can
result in smaller and/or faster binaries.
Setting this option will consume alot of memory, e.g. if you
enable all applets with all features, gcc uses more than 300MB
RAM during compilation of busybox.
This option is most likely only beneficial for newer compilers
such as gcc-4.1 and above.
Say 'N' unless you know what you are doing.
endmenu
menu 'Debugging Options'
@@ -465,6 +485,11 @@ config INSTALL_APPLET_HARDLINKS
Install applets as hard-links to the busybox binary. This might count
on a filesystem with few inodes.
config INSTALL_APPLET_SCRIPT_WRAPPERS
bool "as script wrappers"
help
Install applets as script wrappers that call the busybox binary.
config INSTALL_APPLET_DONT
bool "not installed"
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS
@@ -474,6 +499,30 @@ config INSTALL_APPLET_DONT
endchoice
choice
prompt "/bin/sh applet link"
default INSTALL_SH_APPLET_SYMLINK
depends on INSTALL_APPLET_SCRIPT_WRAPPERS
help
Choose how you install /bin/sh applet link.
config INSTALL_SH_APPLET_SYMLINK
bool "as soft-link"
help
Install /bin/sh applet as soft-link to the busybox binary.
config INSTALL_SH_APPLET_HARDLINK
bool "as hard-link"
help
Install /bin/sh applet as hard-link to the busybox binary.
config INSTALL_SH_APPLET_SCRIPT_WRAPPER
bool "as script wrapper"
help
Install /bin/sh applet as script wrapper that call the busybox binary.
endchoice
config PREFIX
string "BusyBox installation prefix"
default "./_install"
+13 -9
View File
@@ -1,7 +1,7 @@
VERSION = 1
PATCHLEVEL = 7
SUBLEVEL = 0
EXTRAVERSION = .svn
PATCHLEVEL = 9
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
# *DOCUMENTATION*
@@ -568,11 +568,13 @@ busybox-all := $(core-y) $(libs-y)
# Rule to link busybox - also used during CONFIG_KALLSYMS
# May be overridden by arch/$(ARCH)/Makefile
quiet_cmd_busybox__ ?= LINK $@
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
-o $@ -Wl,-Map -Wl,$@.map \
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
-Wl,--start-group $(busybox-all) -Wl,--end-group \
$(LDLIBS)
cmd_busybox__ ?= $(srctree)/scripts/trylink \
"$@" \
"$(CC)" \
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
"$(LDLIBS)"
# Generate System.map
quiet_cmd_sysmap = SYSMAP
@@ -926,6 +928,8 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/autoconf.h \
include/bbconfigopts.h \
include/usage_compressed.h \
include/applet_tables.h \
applets/usage \
.kernelrelease Module.symvers tags TAGS cscope*
# clean - Delete most, but leave enough to build external modules
@@ -968,7 +972,7 @@ distclean: mrproper
@find $(srctree) $(RCS_FIND_IGNORE) \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
-o -name '.*.rej' -o -size 0 \
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
-type f -print | xargs rm -f
+12 -1
View File
@@ -12,6 +12,17 @@ endif
ifeq ($(CONFIG_INSTALL_APPLET_HARDLINKS),y)
INSTALL_OPTS:= --hardlinks
endif
ifeq ($(CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS),y)
ifeq ($(CONFIG_INSTALL_SH_APPLET_SYMLINK),y)
INSTALL_OPTS:= --sw-sh-sym
endif
ifeq ($(CONFIG_INSTALL_SH_APPLET_HARDLINK),y)
INSTALL_OPTS:= --sw-sh-hard
endif
ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
INSTALL_OPTS:= --scriptwrapper
endif
endif
install: $(srctree)/applets/install.sh busybox busybox.links
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
@@ -79,7 +90,7 @@ objsizes: busybox_unstripped
.PHONY: stksizes
stksizes: busybox_unstripped
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH)
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq
.PHONY: bigdata
bigdata: busybox_unstripped
+17 -9
View File
@@ -3,6 +3,7 @@
# ==========================================================================
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
export BB_VER
SKIP_STRIP = n
# -std=gnu99 needed for [U]LLONG_MAX on some systems
@@ -55,31 +56,37 @@ ifeq ($(CONFIG_DEBUG),y)
CFLAGS += $(call cc-option,-g)
endif
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
# on i386: 14% smaller libbusybox.so
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
CFLAGS += -fpic
# and another 4% reduction of libbusybox.so:
# (external entry points must be marked EXTERNALLY_VISIBLE)
CFLAGS += $(call cc-option,-fvisibility=hidden)
endif
ifeq ($(CONFIG_STATIC),y)
LDFLAGS += -static
endif
BBOX_LIB_LIST = m crypt
LDLIBS += m crypt
ifeq ($(CONFIG_PAM),y)
BBOX_LIB_LIST += pam pam_misc
LDLIBS += pam pam_misc
endif
ifeq ($(CONFIG_SELINUX),y)
BBOX_LIB_LIST += selinux sepol
LDLIBS += selinux sepol
endif
ifeq ($(CONFIG_EFENCE),y)
BBOX_LIB_LIST += efence
LDLIBS += efence
endif
ifeq ($(CONFIG_DMALLOC),y)
BBOX_LIB_LIST += dmalloc
LDLIBS += dmalloc
endif
# For scripts/trylink
export BBOX_LIB_LIST
#LDFLAGS += -nostdlib
LDFLAGS_ELF2FLT = -Wl,-elf2flt
@@ -90,4 +97,5 @@ endif
# Busybox is a stack-fatty so make sure we increase default size
# TODO: use "make stksizes" to find & fix big stack users
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
FLTFLAGS += -s 20000
# Reduced from 20k to 16k in 1.9.0.
FLTFLAGS += -s 16000
+2 -3
View File
@@ -16,7 +16,6 @@ help:
@echo 'Configuration:'
@echo ' allnoconfig - disable all symbols in .config'
@echo ' allyesconfig - enable all symbols in .config (see defconfig)'
@echo ' allbareconfig - enable all applets without any sub-features'
@echo ' config - text based configurator (of last resort)'
@echo ' defconfig - set .config to largest generic configuration'
@echo ' menuconfig - interactive curses-based configurator'
@@ -24,10 +23,10 @@ help:
@echo ' hosttools - build sed for the host.'
@echo ' You can use these commands if the commands on the host'
@echo ' is unusable. Afterwards use it like:'
@echo ' make SED="$(objtree)/sed"'
@echo ' make SED="$(objtree)/sed"'
@echo
@echo 'Installation:'
@echo ' install - install busybox into $(CONFIG_PREFIX)'
@echo ' install - install busybox into CONFIG_PREFIX'
@echo ' uninstall'
@echo
@echo 'Development:'
+3 -8
View File
@@ -22,12 +22,9 @@ Rob Landley <rob@landley.net>:
The command shell situation is a big mess. We have three or four different
shells that don't really share any code, and the "standalone shell" doesn't
work all that well (especially not in a chroot environment), due to apps not
being reentrant. I'm writing a new shell (bbsh) to unify the various
shells and configurably add the minimal set of bash features people
actually use. The hardest part is it has to configure down as small as
lash while providing lash's features. The rest is easy in comparison.
bzip2
Compression-side support.
being reentrant.
lash is phased out. hush can be configured down to be nearly as small,
but less buggy :)
init
General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
depmod
@@ -35,8 +32,6 @@ Rob Landley <rob@landley.net>:
use of the depmod.pl (perl is to bloated for most embedded setups) and or orig
modutils. The orig depmod is rather pointless to have to add to a firmware image
in when we already have a insmod/rmmod and friends.
Unify base64 handling.
[done]
Do a SUSv3 audit
Look at the full Single Unix Specification version 3 (available online at
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
+132 -66
View File
@@ -1,11 +1,7 @@
# This .config compiles for NOMMU.
# TODO:
# Pick disabled applet, enable & try to make it compile & work on NOMMU
#
# Automatically generated make config: don't edit
# Busybox version: 1.6.0.svn
# Wed Apr 11 01:29:04 2007
# Busybox version: 1.9.0.svn
# Mon Dec 24 14:21:28 2007
#
CONFIG_HAVE_DOT_CONFIG=y
@@ -16,9 +12,9 @@ CONFIG_HAVE_DOT_CONFIG=y
#
# General Configuration
#
# CONFIG_NITPICK is not set
# CONFIG_DESKTOP is not set
# CONFIG_FEATURE_BUFFERS_USE_MALLOC is not set
CONFIG_NITPICK=y
CONFIG_DESKTOP=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
CONFIG_SHOW_USAGE=y
@@ -31,23 +27,22 @@ CONFIG_FEATURE_DEVPTS=y
# CONFIG_FEATURE_CLEAN_UP is not set
CONFIG_FEATURE_PIDFILE=y
CONFIG_FEATURE_SUID=y
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_SUID_CONFIG is not set
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
# CONFIG_FEATURE_HAVE_RPC is not set
CONFIG_FEATURE_SUID_CONFIG=y
CONFIG_FEATURE_SUID_CONFIG_QUIET=y
# CONFIG_SELINUX is not set
CONFIG_FEATURE_PREFER_APPLETS=y
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
CONFIG_FEATURE_HAVE_RPC=y
#
# Build Options
#
# CONFIG_STATIC is not set
# CONFIG_BUILD_LIBBUSYBOX is not set
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
# CONFIG_FEATURE_INDIVIDUAL is not set
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
CONFIG_LFS=y
# CONFIG_BUILD_AT_ONCE is not set
#
# Debugging Options
@@ -65,7 +60,11 @@ CONFIG_INCLUDE_SUSv2=y
# CONFIG_INSTALL_NO_USR is not set
CONFIG_INSTALL_APPLET_SYMLINKS=y
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
# CONFIG_INSTALL_APPLET_DONT is not set
# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
CONFIG_PREFIX="./_install"
#
@@ -73,14 +72,20 @@ CONFIG_PREFIX="./_install"
#
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SIZE_VS_SPEED=2
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set
# CONFIG_FEATURE_EDITING_VI is not set
CONFIG_FEATURE_EDITING_HISTORY=15
# CONFIG_FEATURE_EDITING_SAVEHISTORY is not set
# CONFIG_FEATURE_TAB_COMPLETION is not set
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
CONFIG_FEATURE_TAB_COMPLETION=y
CONFIG_FEATURE_USERNAME_COMPLETION=y
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
CONFIG_FEATURE_COPYBUF_KB=4
CONFIG_MONOTONIC_SYSCALL=y
CONFIG_IOCTL_HEX2STR_ERROR=y
#
# Applets
@@ -92,23 +97,26 @@ CONFIG_FEATURE_EDITING_HISTORY=15
CONFIG_AR=y
CONFIG_FEATURE_AR_LONG_FILENAMES=y
CONFIG_BUNZIP2=y
CONFIG_BZIP2=y
CONFIG_CPIO=y
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
CONFIG_GZIP=y
CONFIG_RPM2CPIO=y
# CONFIG_RPM is not set
CONFIG_RPM=y
CONFIG_FEATURE_RPM_BZ2=y
CONFIG_TAR=y
CONFIG_FEATURE_TAR_CREATE=y
# CONFIG_FEATURE_TAR_BZIP2 is not set
# CONFIG_FEATURE_TAR_LZMA is not set
CONFIG_FEATURE_TAR_BZIP2=y
CONFIG_FEATURE_TAR_LZMA=y
CONFIG_FEATURE_TAR_FROM=y
# CONFIG_FEATURE_TAR_GZIP is not set
# CONFIG_FEATURE_TAR_COMPRESS is not set
CONFIG_FEATURE_TAR_GZIP=y
CONFIG_FEATURE_TAR_COMPRESS=y
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
CONFIG_UNCOMPRESS=y
@@ -120,9 +128,13 @@ CONFIG_UNZIP=y
# Common options for cpio and tar
#
CONFIG_FEATURE_UNARCHIVE_TAPE=y
# CONFIG_FEATURE_DEB_TAR_GZ is not set
# CONFIG_FEATURE_DEB_TAR_BZ2 is not set
# CONFIG_FEATURE_DEB_TAR_LZMA is not set
#
# Common options for dpkg and dpkg_deb
#
CONFIG_FEATURE_DEB_TAR_GZ=y
CONFIG_FEATURE_DEB_TAR_BZ2=y
CONFIG_FEATURE_DEB_TAR_LZMA=y
#
# Coreutils
@@ -136,7 +148,6 @@ CONFIG_CHMOD=y
CONFIG_CHOWN=y
CONFIG_CHROOT=y
CONFIG_CKSUM=y
CONFIG_CMP=y
CONFIG_COMM=y
CONFIG_CP=y
CONFIG_CUT=y
@@ -146,10 +157,7 @@ CONFIG_DD=y
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
CONFIG_FEATURE_DD_IBS_OBS=y
CONFIG_DF=y
CONFIG_DIFF=y
CONFIG_FEATURE_DIFF_BINARY=y
CONFIG_FEATURE_DIFF_DIR=y
CONFIG_FEATURE_DIFF_MINIMAL=y
CONFIG_FEATURE_DF_INODE=y
CONFIG_DIRNAME=y
CONFIG_DOS2UNIX=y
CONFIG_UNIX2DOS=y
@@ -159,6 +167,8 @@ CONFIG_ECHO=y
CONFIG_FEATURE_FANCY_ECHO=y
CONFIG_ENV=y
CONFIG_FEATURE_ENV_LONG_OPTIONS=y
CONFIG_EXPAND=y
CONFIG_FEATURE_EXPAND_LONG_OPTIONS=y
CONFIG_EXPR=y
CONFIG_EXPR_MATH_SUPPORT_64=y
CONFIG_FALSE=y
@@ -194,6 +204,8 @@ CONFIG_OD=y
CONFIG_PRINTENV=y
CONFIG_PRINTF=y
CONFIG_PWD=y
CONFIG_READLINK=y
CONFIG_FEATURE_READLINK_FOLLOW=y
CONFIG_REALPATH=y
CONFIG_RM=y
CONFIG_RMDIR=y
@@ -223,11 +235,12 @@ CONFIG_FEATURE_TR_EQUIV=y
CONFIG_TRUE=y
CONFIG_TTY=y
CONFIG_UNAME=y
CONFIG_UNEXPAND=y
CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS=y
CONFIG_UNIQ=y
CONFIG_USLEEP=y
CONFIG_UUDECODE=y
CONFIG_UUENCODE=y
CONFIG_WATCH=y
CONFIG_WC=y
CONFIG_FEATURE_WC_LARGE=y
CONFIG_WHO=y
@@ -261,6 +274,7 @@ CONFIG_CHVT=y
CONFIG_CLEAR=y
CONFIG_DEALLOCVT=y
CONFIG_DUMPKMAP=y
CONFIG_KBD_MODE=y
CONFIG_LOADFONT=y
CONFIG_LOADKMAP=y
CONFIG_OPENVT=y
@@ -277,14 +291,12 @@ CONFIG_SETLOGCONS=y
#
CONFIG_MKTEMP=y
CONFIG_PIPE_PROGRESS=y
CONFIG_READLINK=y
CONFIG_FEATURE_READLINK_FOLLOW=y
CONFIG_RUN_PARTS=y
CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS=y
CONFIG_FEATURE_RUN_PARTS_FANCY=y
# CONFIG_START_STOP_DAEMON is not set
# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
CONFIG_START_STOP_DAEMON=y
CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y
CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y
CONFIG_WHICH=y
#
@@ -292,10 +304,17 @@ CONFIG_WHICH=y
#
CONFIG_AWK=y
CONFIG_FEATURE_AWK_MATH=y
CONFIG_CMP=y
CONFIG_DIFF=y
CONFIG_FEATURE_DIFF_BINARY=y
CONFIG_FEATURE_DIFF_DIR=y
CONFIG_FEATURE_DIFF_MINIMAL=y
CONFIG_ED=y
CONFIG_PATCH=y
CONFIG_SED=y
CONFIG_VI=y
CONFIG_FEATURE_VI_MAX_LEN=4096
# CONFIG_FEATURE_VI_8BIT is not set
CONFIG_FEATURE_VI_COLON=y
CONFIG_FEATURE_VI_YANKMARK=y
CONFIG_FEATURE_VI_SEARCH=y
@@ -318,6 +337,7 @@ CONFIG_FEATURE_FIND_MMIN=y
CONFIG_FEATURE_FIND_PERM=y
CONFIG_FEATURE_FIND_TYPE=y
CONFIG_FEATURE_FIND_XDEV=y
CONFIG_FEATURE_FIND_MAXDEPTH=y
CONFIG_FEATURE_FIND_NEWER=y
CONFIG_FEATURE_FIND_INUM=y
CONFIG_FEATURE_FIND_EXEC=y
@@ -328,6 +348,10 @@ CONFIG_FEATURE_FIND_DEPTH=y
CONFIG_FEATURE_FIND_PAREN=y
CONFIG_FEATURE_FIND_SIZE=y
CONFIG_FEATURE_FIND_PRUNE=y
CONFIG_FEATURE_FIND_DELETE=y
CONFIG_FEATURE_FIND_PATH=y
CONFIG_FEATURE_FIND_REGEX=y
# CONFIG_FEATURE_FIND_CONTEXT is not set
CONFIG_GREP=y
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
@@ -361,16 +385,21 @@ CONFIG_USE_BB_PWD_GRP=y
CONFIG_ADDGROUP=y
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
CONFIG_DELGROUP=y
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y
CONFIG_ADDUSER=y
CONFIG_DELUSER=y
CONFIG_GETTY=y
CONFIG_FEATURE_UTMP=y
CONFIG_FEATURE_WTMP=y
CONFIG_LOGIN=y
# CONFIG_PAM is not set
CONFIG_LOGIN_SCRIPTS=y
# CONFIG_FEATURE_NOLOGIN is not set
CONFIG_FEATURE_SECURETTY=y
CONFIG_PASSWD=y
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
CONFIG_CRYPTPW=y
CONFIG_CHPASSWD=y
CONFIG_SU=y
CONFIG_FEATURE_SU_SYSLOG=y
CONFIG_FEATURE_SU_CHECKS_SHELLS=y
@@ -436,6 +465,8 @@ CONFIG_MKFS_MINIX=y
CONFIG_FEATURE_MINIX2=y
CONFIG_GETOPT=y
CONFIG_HEXDUMP=y
CONFIG_HD=y
CONFIG_FEATURE_HEXDUMP_REVERSE=y
CONFIG_HWCLOCK=y
CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS=y
CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
@@ -445,12 +476,14 @@ CONFIG_LOSETUP=y
CONFIG_MDEV=y
CONFIG_FEATURE_MDEV_CONF=y
CONFIG_FEATURE_MDEV_EXEC=y
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
CONFIG_FEATURE_MKSWAP_V0=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_MOUNT=y
# CONFIG_FEATURE_MOUNT_NFS is not set
CONFIG_FEATURE_MOUNT_HELPERS=y
CONFIG_FEATURE_MOUNT_NFS=y
CONFIG_FEATURE_MOUNT_CIFS=y
CONFIG_FEATURE_MOUNT_FLAGS=y
CONFIG_FEATURE_MOUNT_FSTAB=y
@@ -504,25 +537,27 @@ CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
CONFIG_MAKEDEVS=y
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
CONFIG_FEATURE_MAKEDEVS_TABLE=y
CONFIG_MICROCOM=y
CONFIG_MOUNTPOINT=y
CONFIG_MT=y
CONFIG_NMETER=y
CONFIG_RAIDAUTORUN=y
CONFIG_READAHEAD=y
CONFIG_RUNLEVEL=y
CONFIG_RX=y
CONFIG_STRINGS=y
CONFIG_SETSID=y
# CONFIG_TASKSET is not set
# CONFIG_FEATURE_TASKSET_FANCY is not set
CONFIG_TASKSET=y
CONFIG_FEATURE_TASKSET_FANCY=y
CONFIG_TIME=y
CONFIG_TTYSIZE=y
CONFIG_WATCHDOG=y
#
# Networking Utilities
#
CONFIG_FEATURE_IPV6=y
# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
CONFIG_VERBOSE_RESOLUTION_ERRORS=y
CONFIG_ARP=y
CONFIG_ARPING=y
CONFIG_DNSD=y
@@ -532,16 +567,20 @@ CONFIG_FTPGET=y
CONFIG_FTPPUT=y
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
CONFIG_HOSTNAME=y
# CONFIG_HTTPD is not set
# CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP is not set
# CONFIG_FEATURE_HTTPD_SETUID is not set
# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES is not set
# CONFIG_FEATURE_HTTPD_CGI is not set
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
CONFIG_HTTPD=y
CONFIG_FEATURE_HTTPD_RANGES=y
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP=y
CONFIG_FEATURE_HTTPD_SETUID=y
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
CONFIG_FEATURE_HTTPD_AUTH_MD5=y
CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES=y
CONFIG_FEATURE_HTTPD_CGI=y
CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y
CONFIG_FEATURE_HTTPD_ERROR_PAGES=y
CONFIG_FEATURE_HTTPD_PROXY=y
CONFIG_IFCONFIG=y
CONFIG_FEATURE_IFCONFIG_STATUS=y
CONFIG_FEATURE_IFCONFIG_SLIP=y
@@ -549,13 +588,14 @@ CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
CONFIG_FEATURE_IFCONFIG_HW=y
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
# CONFIG_IFUPDOWN is not set
CONFIG_IFUPDOWN_IFSTATE_PATH=""
# CONFIG_FEATURE_IFUPDOWN_IP is not set
# CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN is not set
# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set
# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
# CONFIG_FEATURE_IFUPDOWN_IPX is not set
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
# CONFIG_INETD is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
@@ -570,6 +610,7 @@ CONFIG_FEATURE_IP_ROUTE=y
CONFIG_FEATURE_IP_TUNNEL=y
CONFIG_FEATURE_IP_RULE=y
CONFIG_FEATURE_IP_SHORT_FORMS=y
CONFIG_FEATURE_IP_RARE_PROTOCOLS=y
CONFIG_IPADDR=y
CONFIG_IPLINK=y
CONFIG_IPROUTE=y
@@ -579,35 +620,42 @@ CONFIG_IPCALC=y
CONFIG_FEATURE_IPCALC_FANCY=y
CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
CONFIG_NAMEIF=y
CONFIG_FEATURE_NAMEIF_EXTENDED=y
CONFIG_NC=y
CONFIG_NC_SERVER=y
CONFIG_NC_EXTRA=y
CONFIG_NETSTAT=y
CONFIG_FEATURE_NETSTAT_WIDE=y
CONFIG_NSLOOKUP=y
CONFIG_PING=y
CONFIG_PING6=y
CONFIG_PSCAN=y
CONFIG_FEATURE_FANCY_PING=y
CONFIG_ROUTE=y
CONFIG_SLATTACH=y
CONFIG_TELNET=y
CONFIG_FEATURE_TELNET_TTYPE=y
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
# CONFIG_TELNETD is not set
# CONFIG_FEATURE_TELNETD_STANDALONE is not set
CONFIG_TELNETD=y
CONFIG_FEATURE_TELNETD_STANDALONE=y
CONFIG_TFTP=y
CONFIG_FEATURE_TFTP_GET=y
CONFIG_FEATURE_TFTP_PUT=y
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
# CONFIG_DEBUG_TFTP is not set
CONFIG_TRACEROUTE=y
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
CONFIG_APP_UDHCPD=y
CONFIG_APP_DHCPRELAY=y
CONFIG_APP_DUMPLEASES=y
# CONFIG_APP_UDHCPC is not set
# CONFIG_FEATURE_UDHCP_DEBUG is not set
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
CONFIG_APP_UDHCPC=y
CONFIG_FEATURE_UDHCPC_ARPING=y
CONFIG_FEATURE_UDHCP_DEBUG=y
CONFIG_FEATURE_RFC3397=y
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
CONFIG_VCONFIG=y
CONFIG_WGET=y
CONFIG_FEATURE_WGET_STATUSBAR=y
@@ -623,23 +671,29 @@ CONFIG_FUSER=y
CONFIG_KILL=y
CONFIG_KILLALL=y
CONFIG_KILLALL5=y
CONFIG_NMETER=y
CONFIG_PGREP=y
CONFIG_PIDOF=y
CONFIG_FEATURE_PIDOF_SINGLE=y
CONFIG_FEATURE_PIDOF_OMIT=y
CONFIG_PKILL=y
CONFIG_PS=y
CONFIG_FEATURE_PS_WIDE=y
CONFIG_RENICE=y
CONFIG_BB_SYSCTL=y
CONFIG_TOP=y
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
CONFIG_FEATURE_TOP_DECIMALS=y
CONFIG_FEATURE_TOPMEM=y
CONFIG_UPTIME=y
CONFIG_WATCH=y
#
# Shells
#
# CONFIG_FEATURE_SH_IS_ASH is not set
# CONFIG_FEATURE_SH_IS_HUSH is not set
# CONFIG_FEATURE_SH_IS_LASH is not set
# CONFIG_FEATURE_SH_IS_MSH is not set
CONFIG_FEATURE_SH_IS_NONE=y
# CONFIG_ASH is not set
@@ -657,8 +711,14 @@ CONFIG_FEATURE_SH_IS_NONE=y
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
# CONFIG_ASH_RANDOM_SUPPORT is not set
# CONFIG_ASH_EXPAND_PRMT is not set
# CONFIG_HUSH is not set
# CONFIG_LASH is not set
CONFIG_HUSH=y
CONFIG_HUSH_HELP=y
# CONFIG_HUSH_INTERACTIVE is not set
# CONFIG_HUSH_JOB is not set
CONFIG_HUSH_TICK=y
CONFIG_HUSH_IF=y
CONFIG_HUSH_LOOPS=y
CONFIG_LASH=y
CONFIG_MSH=y
#
@@ -666,6 +726,7 @@ CONFIG_MSH=y
#
CONFIG_FEATURE_SH_EXTRA_QUIET=y
CONFIG_FEATURE_SH_STANDALONE=y
CONFIG_CTTYHACK=y
#
# System Logging Utilities
@@ -684,7 +745,7 @@ CONFIG_LOGGER=y
# Runit Utilities
#
# CONFIG_RUNSV is not set
# CONFIG_RUNSVDIR is not set
CONFIG_RUNSVDIR=y
CONFIG_SV=y
# CONFIG_SVLOGD is not set
CONFIG_CHPST=y
@@ -698,10 +759,15 @@ CONFIG_SOFTLIMIT=y
# CONFIG_GETSEBOOL is not set
# CONFIG_LOAD_POLICY is not set
# CONFIG_MATCHPATHCON is not set
# CONFIG_RESTORECON is not set
# CONFIG_RUNCON is not set
# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set
# CONFIG_SELINUXENABLED is not set
# CONFIG_SETENFORCE is not set
# CONFIG_SETFILES is not set
# CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set
# CONFIG_SETSEBOOL is not set
# CONFIG_SESTATUS is not set
#
# ipsvd utilities
+17 -8
View File
@@ -4,22 +4,31 @@
#
# Licensed under the GPL v2, see the file LICENSE in this tarball.
obj-y:=
obj-y += applets.o
obj-y :=
obj-y += applets.o
hostprogs-y:=
hostprogs-y += usage
hostprogs-y += usage applet_tables
always:= $(hostprogs-y)
always:= $(hostprogs-y)
# Generated files need additional love
HOSTCFLAGS_usage.o = -I$(srctree)/include
applets/applets.o: include/usage_compressed.h include/applet_tables.h
applets/usage: .config $(srctree)/applets/usage_compressed
applets/applet_tables: .config
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
HOSTCFLAGS_usage.o = -I$(srctree)/include
applets/applets.o: include/usage_compressed.h
applets/usage: .config $(srctree)/applets/usage_compressed
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
$(call cmd,gen_usage_compressed)
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h
include/applet_tables.h: applets/applet_tables
$(call cmd,gen_applet_tables)
+115
View File
@@ -0,0 +1,115 @@
/* vi: set sw=4 ts=4: */
/*
* Applet table generator.
* Runs on host and produces include/applet_tables.h
*
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file License in this tarball for details.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "../include/autoconf.h"
#include "../include/busybox.h"
struct bb_applet {
const char *name;
const char *main;
enum bb_install_loc_t install_loc;
enum bb_suid_t need_suid;
/* true if instead of fork(); exec("applet"); waitpid();
* one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
unsigned char noexec;
/* Even nicer */
/* true if instead of fork(); exec("applet"); waitpid();
* one can simply call applet_main(argc,argv); */
unsigned char nofork;
};
/* Define struct bb_applet applets[] */
#include "../include/applets.h"
enum { NUM_APPLETS = sizeof(applets)/sizeof(applets[0]) };
static int offset[NUM_APPLETS];
static int cmp_name(const void *a, const void *b)
{
const struct bb_applet *aa = a;
const struct bb_applet *bb = b;
return strcmp(aa->name, bb->name);
}
int main(int argc, char **argv)
{
int i;
int ofs;
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
ofs = 0;
for (i = 0; i < NUM_APPLETS; i++) {
offset[i] = ofs;
ofs += strlen(applets[i].name) + 1;
}
/* We reuse 4 high-order bits of offset array for other purposes,
* so if they are indeed needed, refuse to proceed */
if (ofs > 0xfff)
return 1;
if (!argv[1])
return 1;
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (i < 0)
return 1;
dup2(i, 1);
/* Keep in sync with include/busybox.h! */
puts("/* This is a generated file, don't edit */");
puts("const char applet_names[] ALIGN1 = \"\" \n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("\"%s\" \"\\0\"\n", applets[i].name);
}
puts(";");
puts("int (*const applet_main[])(int argc, char **argv) = {");
for (i = 0; i < NUM_APPLETS; i++) {
printf("%s_main,\n", applets[i].main);
}
puts("};");
puts("const uint16_t applet_nameofs[] ALIGN2 = {");
for (i = 0; i < NUM_APPLETS; i++) {
printf("0x%04x,\n",
offset[i]
#if ENABLE_FEATURE_PREFER_APPLETS
+ (applets[i].nofork << 12)
+ (applets[i].noexec << 13)
#endif
#if ENABLE_FEATURE_SUID
+ (applets[i].need_suid << 14) /* 2 bits */
#endif
);
}
puts("};");
#if ENABLE_FEATURE_INSTALLER
puts("const uint8_t applet_install_loc[] ALIGN1 = {");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].install_loc; /* 3 bits */
if (++i < NUM_APPLETS)
v |= applets[i].install_loc << 4; /* 3 bits */
printf("0x%02x,\n", v);
i++;
}
puts("};");
#endif
return 0;
}
+7 -647
View File
@@ -1,15 +1,10 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
* Stub for linking busybox binary against libbusybox.
*
* Copyright (C) tons of folks. Tracking down who wrote what
* isn't something I'm going to worry about... If you wrote something
* here, please feel free to acknowledge your work.
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
* Licensed under GPLv2 or later, see file License in this tarball for details.
* Licensed under GPLv2, see file License in this tarball for details.
*/
#include <assert.h>
@@ -22,648 +17,13 @@
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#warning from scripts/trylink and remove this warning.
#error Aborting compilation.
#endif
/* Declare <applet>_main() */
#define PROTOTYPES
#include "applets.h"
#undef PROTOTYPES
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
/* Define usage_messages[] */
static const char usage_messages[] ALIGN1 = ""
#define MAKE_USAGE
#include "usage.h"
#include "applets.h"
;
#undef MAKE_USAGE
#else
#define usage_messages 0
#endif /* SHOW_USAGE */
/* Define struct bb_applet applets[] */
#include "applets.h"
/* The -1 arises because of the {0,NULL,0,-1} entry. */
#if ENABLE_FEATURE_SH_STANDALONE
const unsigned short NUM_APPLETS = ARRAY_SIZE(applets);
#endif
const struct bb_applet *current_applet;
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
#if !BB_MMU
bool re_execed;
#endif
USE_FEATURE_SUID(static uid_t ruid;) /* real uid */
#if ENABLE_FEATURE_SUID_CONFIG
/* applets[] is const, so we have to define this "override" structure */
static struct BB_suid_config {
const struct bb_applet *m_applet;
uid_t m_uid;
gid_t m_gid;
mode_t m_mode;
struct BB_suid_config *m_next;
} *suid_config;
static bool suid_cfg_readable;
/* check if u is member of group g */
static int ingroup(uid_t u, gid_t g)
{
struct group *grp = getgrgid(g);
if (grp) {
char **mem;
for (mem = grp->gr_mem; *mem; mem++) {
struct passwd *pwd = getpwnam(*mem);
if (pwd && (pwd->pw_uid == u))
return 1;
}
}
return 0;
}
/* This should probably be a libbb routine. In that case,
* I'd probably rename it to something like bb_trimmed_slice.
*/
static char *get_trimmed_slice(char *s, char *e)
{
/* First, consider the value at e to be nul and back up until we
* reach a non-space char. Set the char after that (possibly at
* the original e) to nul. */
while (e-- > s) {
if (!isspace(*e)) {
break;
}
}
e[1] = '\0';
/* Next, advance past all leading space and return a ptr to the
* first non-space char; possibly the terminating nul. */
return skip_whitespace(s);
}
/* Don't depend on the tools to combine strings. */
static const char config_file[] ALIGN1 = "/etc/busybox.conf";
/* We don't supply a value for the nul, so an index adjustment is
* necessary below. Also, we use unsigned short here to save some
* space even though these are really mode_t values. */
static const unsigned short mode_mask[] ALIGN2 = {
/* SST sst xxx --- */
S_ISUID, S_ISUID|S_IXUSR, S_IXUSR, 0, /* user */
S_ISGID, S_ISGID|S_IXGRP, S_IXGRP, 0, /* group */
0, S_IXOTH, S_IXOTH, 0 /* other */
};
#define parse_error(x) do { errmsg = x; goto pe_label; } while (0)
static void parse_config_file(void)
{
struct BB_suid_config *sct_head;
struct BB_suid_config *sct;
const struct bb_applet *applet;
FILE *f;
const char *errmsg;
char *s;
char *e;
int i;
unsigned lc;
smallint section;
char buffer[256];
struct stat st;
assert(!suid_config); /* Should be set to NULL by bss init. */
ruid = getuid();
if (ruid == 0) /* run by root - don't need to even read config file */
return;
if ((stat(config_file, &st) != 0) /* No config file? */
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|| (st.st_uid != 0) /* Not owned by root? */
|| (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */
|| !(f = fopen(config_file, "r")) /* Cannot open? */
) {
return;
}
suid_cfg_readable = 1;
sct_head = NULL;
section = lc = 0;
while (1) {
s = buffer;
if (!fgets(s, sizeof(buffer), f)) { /* Are we done? */
if (ferror(f)) { /* Make sure it wasn't a read error. */
parse_error("reading");
}
fclose(f);
suid_config = sct_head; /* Success, so set the pointer. */
return;
}
lc++; /* Got a (partial) line. */
/* If a line is too long for our buffer, we consider it an error.
* The following test does mistreat one corner case though.
* If the final line of the file does not end with a newline and
* yet exactly fills the buffer, it will be treated as too long
* even though there isn't really a problem. But it isn't really
* worth adding code to deal with such an unlikely situation, and
* we do err on the side of caution. Besides, the line would be
* too long if it did end with a newline. */
if (!strchr(s, '\n') && !feof(f)) {
parse_error("line too long");
}
/* Trim leading and trailing whitespace, ignoring comments, and
* check if the resulting string is empty. */
s = get_trimmed_slice(s, strchrnul(s, '#'));
if (!*s) {
continue;
}
/* Check for a section header. */
if (*s == '[') {
/* Unlike the old code, we ignore leading and trailing
* whitespace for the section name. We also require that
* there are no stray characters after the closing bracket. */
e = strchr(s, ']');
if (!e /* Missing right bracket? */
|| e[1] /* Trailing characters? */
|| !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */
) {
parse_error("section header");
}
/* Right now we only have one section so just check it.
* If more sections are added in the future, please don't
* resort to cascading ifs with multiple strcasecmp calls.
* That kind of bloated code is all too common. A loop
* and a string table would be a better choice unless the
* number of sections is very small. */
if (strcasecmp(s, "SUID") == 0) {
section = 1;
continue;
}
section = -1; /* Unknown section so set to skip. */
continue;
}
/* Process sections. */
if (section == 1) { /* SUID */
/* Since we trimmed leading and trailing space above, we're
* now looking for strings of the form
* <key>[::space::]*=[::space::]*<value>
* where both key and value could contain inner whitespace. */
/* First get the key (an applet name in our case). */
e = strchr(s, '=');
if (e) {
s = get_trimmed_slice(s, e);
}
if (!e || !*s) { /* Missing '=' or empty key. */
parse_error("keyword");
}
/* Ok, we have an applet name. Process the rhs if this
* applet is currently built in and ignore it otherwise.
* Note: this can hide config file bugs which only pop
* up when the busybox configuration is changed. */
applet = find_applet_by_name(s);
if (applet) {
/* Note: We currently don't check for duplicates!
* The last config line for each applet will be the
* one used since we insert at the head of the list.
* I suppose this could be considered a feature. */
sct = xmalloc(sizeof(struct BB_suid_config));
sct->m_applet = applet;
sct->m_mode = 0;
sct->m_next = sct_head;
sct_head = sct;
/* Get the specified mode. */
e = skip_whitespace(e+1);
for (i = 0; i < 3; i++) {
/* There are 4 chars + 1 nul for each of user/group/other. */
static const char mode_chars[] ALIGN1 = "Ssx-\0" "Ssx-\0" "Ttx-";
const char *q;
q = strchrnul(mode_chars + 5*i, *e++);
if (!*q) {
parse_error("mode");
}
/* Adjust by -i to account for nul. */
sct->m_mode |= mode_mask[(q - mode_chars) - i];
}
/* Now get the the user/group info. */
s = skip_whitespace(e);
/* Note: we require whitespace between the mode and the
* user/group info. */
if ((s == e) || !(e = strchr(s, '.'))) {
parse_error("<uid>.<gid>");
}
*e++ = '\0';
/* We can't use get_ug_id here since it would exit()
* if a uid or gid was not found. Oh well... */
sct->m_uid = bb_strtoul(s, NULL, 10);
if (errno) {
struct passwd *pwd = getpwnam(s);
if (!pwd) {
parse_error("user");
}
sct->m_uid = pwd->pw_uid;
}
sct->m_gid = bb_strtoul(e, NULL, 10);
if (errno) {
struct group *grp;
grp = getgrnam(e);
if (!grp) {
parse_error("group");
}
sct->m_gid = grp->gr_gid;
}
}
continue;
}
/* Unknown sections are ignored. */
/* Encountering configuration lines prior to seeing a
* section header is treated as an error. This is how
* the old code worked, but it may not be desirable.
* We may want to simply ignore such lines in case they
* are used in some future version of busybox. */
if (!section) {
parse_error("keyword outside section");
}
} /* while (1) */
pe_label:
fprintf(stderr, "Parse error in %s, line %d: %s\n",
config_file, lc, errmsg);
fclose(f);
/* Release any allocated memory before returning. */
while (sct_head) {
sct = sct_head->m_next;
free(sct_head);
sct_head = sct;
}
}
#else
static inline void parse_config_file(void)
{
USE_FEATURE_SUID(ruid = getuid();)
}
#endif /* FEATURE_SUID_CONFIG */
#if ENABLE_FEATURE_SUID
static void check_suid(const struct bb_applet *applet)
{
gid_t rgid; /* real gid */
if (ruid == 0) /* set by parse_config_file() */
return; /* run by root - no need to check more */
rgid = getgid();
#if ENABLE_FEATURE_SUID_CONFIG
if (suid_cfg_readable) {
uid_t uid;
struct BB_suid_config *sct;
mode_t m;
for (sct = suid_config; sct; sct = sct->m_next) {
if (sct->m_applet == applet)
goto found;
}
/* default: drop all privileges */
xsetgid(rgid);
xsetuid(ruid);
return;
found:
m = sct->m_mode;
if (sct->m_uid == ruid)
/* same uid */
m >>= 6;
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid))
/* same group / in group */
m >>= 3;
if (!(m & S_IXOTH)) /* is x bit not set ? */
bb_error_msg_and_die("you have no permission to run this applet!");
/* _both_ sgid and group_exec have to be set for setegid */
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
rgid = sct->m_gid;
/* else (no setegid) we will set egid = rgid */
/* We set effective AND saved ids. If saved-id is not set
* like we do below, seteiud(0) can still later succeed! */
if (setresgid(-1, rgid, rgid))
bb_perror_msg_and_die("setresgid");
/* do we have to set effective uid? */
uid = ruid;
if (sct->m_mode & S_ISUID)
uid = sct->m_uid;
/* else (no seteuid) we will set euid = ruid */
if (setresuid(-1, uid, uid))
bb_perror_msg_and_die("setresuid");
return;
}
#if !ENABLE_FEATURE_SUID_CONFIG_QUIET
{
static bool onetime = 0;
if (!onetime) {
onetime = 1;
fprintf(stderr, "Using fallback suid method\n");
}
}
#endif
#endif
if (applet->need_suid == _BB_SUID_ALWAYS) {
/* Real uid is not 0. If euid isn't 0 too, suid bit
* is most probably not set on our executable */
if (geteuid())
bb_error_msg_and_die("applet requires root privileges!");
} else if (applet->need_suid == _BB_SUID_NEVER) {
xsetgid(rgid); /* drop all privileges */
xsetuid(ruid);
}
}
#else
#define check_suid(x) ((void)0)
#endif /* FEATURE_SUID */
#if ENABLE_FEATURE_COMPRESS_USAGE
#include "usage_compressed.h"
#include "unarchive.h"
static const char *unpack_usage_messages(void)
{
char *outbuf = NULL;
bunzip_data *bd;
int i;
i = start_bunzip(&bd,
/* src_fd: */ -1,
/* inbuf: */ packed_usage,
/* len: */ sizeof(packed_usage));
/* read_bunzip can longjmp to start_bunzip, and ultimately
* end up here with i != 0 on read data errors! Not trivial */
if (!i) {
/* Cannot use xmalloc: will leak bd in NOFORK case! */
outbuf = malloc_or_warn(SIZEOF_usage_messages);
if (outbuf)
read_bunzip(bd, outbuf, SIZEOF_usage_messages);
}
dealloc_bunzip(bd);
return outbuf;
}
#define dealloc_usage_messages(s) free(s)
#else
#define unpack_usage_messages() usage_messages
#define dealloc_usage_messages(s) ((void)(s))
#endif /* FEATURE_COMPRESS_USAGE */
void bb_show_usage(void)
{
if (ENABLE_SHOW_USAGE) {
const char *format_string;
const char *p;
const char *usage_string = p = unpack_usage_messages();
int i;
i = current_applet - applets;
while (i) {
while (*p++) continue;
i--;
}
fprintf(stderr, "%s multi-call binary\n", bb_banner);
format_string = "\nUsage: %s %s\n\n";
if (*p == '\b')
format_string = "\nNo help available.\n\n";
fprintf(stderr, format_string, applet_name, p);
dealloc_usage_messages((char*)usage_string);
}
xfunc_die();
}
static int applet_name_compare(const void *name, const void *vapplet)
{
const struct bb_applet *applet = vapplet;
return strcmp(name, applet->name);
}
const struct bb_applet *find_applet_by_name(const char *name)
{
/* Do a binary search to find the applet entry given the name. */
return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]),
applet_name_compare);
}
#if ENABLE_FEATURE_INSTALLER
/* create (sym)links for each applet */
static void install_links(const char *busybox, int use_symbolic_links)
{
/* directory table
* this should be consistent w/ the enum,
* busybox.h::bb_install_loc_t, or else... */
static const char usr_bin [] ALIGN1 = "/usr/bin";
static const char usr_sbin[] ALIGN1 = "/usr/sbin";
static const char *const install_dir[] = {
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
&usr_bin [4], /* "/bin" */
&usr_sbin[4], /* "/sbin" */
usr_bin,
usr_sbin
};
int (*lf)(const char *, const char *) = link;
char *fpc;
int i;
int rc;
if (use_symbolic_links)
lf = symlink;
for (i = 0; applets[i].name != NULL; i++) {
fpc = concat_path_file(
install_dir[applets[i].install_loc],
applets[i].name);
rc = lf(busybox, fpc);
if (rc != 0 && errno != EEXIST) {
bb_perror_msg("%s", fpc);
}
free(fpc);
}
}
#else
#define install_links(x,y) ((void)0)
#endif /* FEATURE_INSTALLER */
/* If we were called as "busybox..." */
static int busybox_main(char **argv)
{
if (!argv[1]) {
/* Called without arguments */
const struct bb_applet *a;
int col, output_width;
help:
output_width = 80;
if (ENABLE_FEATURE_AUTOWIDTH) {
/* Obtain the terminal width. */
get_terminal_width_height(0, &output_width, NULL);
}
/* leading tab and room to wrap */
output_width -= sizeof("start-stop-daemon, ") + 8;
printf("%s multi-call binary\n", bb_banner); /* reuse const string... */
printf("Copyright (C) 1998-2006  Erik Andersen, Rob Landley, and others.\n"
"Licensed under GPLv2.  See source distribution for full notice.\n"
"\n"
"Usage: busybox [function] [arguments]...\n"
" or: [function] [arguments]...\n"
"\n"
"\tBusyBox is a multi-call binary that combines many common Unix\n"
"\tutilities into a single executable. Most people will create a\n"
"\tlink to busybox for each function they wish to use and BusyBox\n"
"\twill act like whatever it was invoked as!\n"
"\nCurrently defined functions:\n");
col = 0;
a = applets;
while (a->name) {
if (col > output_width) {
puts(",");
col = 0;
}
col += printf("%s%s", (col ? ", " : "\t"), a->name);
a++;
}
puts("\n");
return 0;
}
if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
const char *busybox;
busybox = xmalloc_readlink_or_warn(bb_busybox_exec_path);
if (!busybox)
busybox = bb_busybox_exec_path;
/* -s makes symlinks */
install_links(busybox,
argv[2] && strcmp(argv[2], "-s") == 0);
return 0;
}
if (strcmp(argv[1], "--help") == 0) {
/* "busybox --help [<applet>]" */
if (!argv[2])
goto help;
/* convert to "<applet> --help" */
argv[0] = argv[2];
argv[2] = NULL;
} else {
/* "busybox <applet> arg1 arg2 ..." */
argv++;
}
/* we want "<argv[0]>: applet not found", not "busybox: ..." */
applet_name = argv[0];
run_applet_and_exit(argv[0], argv);
bb_error_msg_and_die("applet not found");
}
void run_current_applet_and_exit(char **argv)
{
int argc = 1;
while (argv[argc])
argc++;
/* Reinit some shared global data */
optind = 1;
xfunc_error_retval = EXIT_FAILURE;
applet_name = current_applet->name;
if (argc == 2 && !strcmp(argv[1], "--help"))
bb_show_usage();
if (ENABLE_FEATURE_SUID)
check_suid(current_applet);
exit(current_applet->main(argc, argv));
}
void run_applet_and_exit(const char *name, char **argv)
{
current_applet = find_applet_by_name(name);
if (current_applet)
run_current_applet_and_exit(argv);
if (!strncmp(name, "busybox", 7))
exit(busybox_main(argv));
}
#ifdef __GLIBC__
/* Make it reside in R/W memory: */
int *const bb_errno __attribute__ ((section (".data")));
#endif
#if ENABLE_BUILD_LIBBUSYBOX
int main(int argc, char **argv)
{
#ifdef __GLIBC__
(*(int **)&bb_errno) = __errno_location();
#endif
#if !BB_MMU
/* NOMMU re-exec trick sets high-order bit in first byte of name */
if (argv[0][0] & 0x80) {
re_execed = 1;
argv[0][0] &= 0x7f;
}
#endif
applet_name = argv[0];
if (applet_name[0] == '-')
applet_name++;
applet_name = bb_basename(applet_name);
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
/* Set locale for everybody except 'init' */
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
setlocale(LC_ALL, "");
run_applet_and_exit(applet_name, argv);
bb_error_msg_and_die("applet not found");
return lbb_main(argc, argv);
}
#endif
+49 -33
View File
@@ -5,19 +5,23 @@ export LC_CTYPE=POSIX
prefix=${1}
if [ -z "$prefix" ]; then
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks]"
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
exit 1;
fi
h=`sort busybox.links | uniq`
scriptwrapper="n"
cleanup="0"
noclobber="0"
case "$2" in
--hardlinks) linkopts="-f";;
--symlinks) linkopts="-fs";;
--cleanup) cleanup="1";;
--noclobber) noclobber="1";;
"") h="";;
*) echo "Unknown install option: $2"; exit 1;;
--hardlinks) linkopts="-f";;
--symlinks) linkopts="-fs";;
--scriptwrapper) scriptwrapper="y";swrapall="y";;
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
--cleanup) cleanup="1";;
--noclobber) noclobber="1";;
"") h="";;
*) echo "Unknown install option: $2"; exit 1;;
esac
if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
@@ -52,6 +56,7 @@ if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
cd "$pd"
done
`
exit 0
fi
rm -f $prefix/bin/busybox || exit 1
@@ -61,33 +66,44 @@ install -m 755 busybox $prefix/bin/busybox || exit 1
for i in $h; do
appdir=`dirname $i`
mkdir -p $prefix/$appdir || exit 1
if [ "$2" = "--hardlinks" ]; then
bb_path="$prefix/bin/busybox"
if [ "$scriptwrapper" = "y" ]; then
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
ln $linkopts busybox $prefix$i || exit 1
else
rm -f $prefix$i
echo "#!/bin/busybox" > $prefix$i
chmod +x $prefix/$i
fi
echo " $prefix$i"
else
case "$appdir" in
/)
bb_path="bin/busybox"
;;
/bin)
bb_path="busybox"
;;
/sbin)
bb_path="../bin/busybox"
;;
/usr/bin|/usr/sbin)
bb_path="../../bin/busybox"
;;
*)
echo "Unknown installation directory: $appdir"
exit 1
;;
esac
fi
if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
echo " $prefix$i -> $bb_path"
ln $linkopts $bb_path $prefix$i || exit 1
else
echo " $prefix$i already exists"
if [ "$2" = "--hardlinks" ]; then
bb_path="$prefix/bin/busybox"
else
case "$appdir" in
/)
bb_path="bin/busybox"
;;
/bin)
bb_path="busybox"
;;
/sbin)
bb_path="../bin/busybox"
;;
/usr/bin|/usr/sbin)
bb_path="../../bin/busybox"
;;
*)
echo "Unknown installation directory: $appdir"
exit 1
;;
esac
fi
if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
echo " $prefix$i -> $bb_path"
ln $linkopts $bb_path $prefix$i || exit 1
else
echo " $prefix$i already exists"
fi
fi
done
+13 -3
View File
@@ -48,12 +48,22 @@ config BUNZIP2
conventional LZ77/LZ78-based compressors, and approaches the
performance of the PPM family of statistical compressors.
The BusyBox bunzip2 applet is limited to de-compression only.
On an x86 system, this applet adds about 11K.
Unless you have a specific application which requires bunzip2, you
should probably say N here.
config BZIP2
bool "bzip2"
default n
help
bzip2 is a compression utility using the Burrows-Wheeler block
sorting text compression algorithm, and Huffman coding. Compression
is generally considerably better than that achieved by more
conventional LZ77/LZ78-based compressors, and approaches the
performance of the PPM family of statistical compressors.
Unless you have a specific application which requires bzip2, you
should probably say N here.
config CPIO
bool "cpio"
default n
+1
View File
@@ -9,6 +9,7 @@ libs-y += libunarchive/
lib-y:=
lib-$(CONFIG_AR) += ar.o
lib-$(CONFIG_BUNZIP2) += bbunzip.o
lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
lib-$(CONFIG_UNLZMA) += bbunzip.o
lib-$(CONFIG_CPIO) += cpio.o
lib-$(CONFIG_DPKG) += dpkg.o
+1 -2
View File
@@ -3,7 +3,6 @@
* Mini ar implementation for busybox
*
* Copyright (C) 2000 by Glenn McGrath
* Written by Glenn McGrath <bug1@iinet.net.au> 1 June 2000
*
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
*
@@ -38,7 +37,7 @@ static void header_verbose_list_ar(const file_header_t *file_header)
#define AR_OPT_CREATE 0x20
#define AR_OPT_INSERT 0x40
int ar_main(int argc, char **argv);
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ar_main(int argc, char **argv)
{
static const char msg_unsupported_err[] ALIGN1 =
+11 -12
View File
@@ -11,7 +11,7 @@
enum {
OPT_STDOUT = 0x1,
OPT_FORCE = 0x2,
/* gunzip only: */
/* gunzip and bunzip2 only: */
OPT_VERBOSE = 0x4,
OPT_DECOMPRESS = 0x8,
OPT_TEST = 0x10,
@@ -49,7 +49,7 @@ int bbunpack(char **argv,
/* Open src */
if (filename) {
if (stat(filename, &stat_buf) != 0) {
bb_perror_msg("%s", filename);
bb_simple_perror_msg(filename);
err:
exitcode = 1;
goto free_name;
@@ -74,7 +74,7 @@ int bbunpack(char **argv,
goto err;
}
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
/* GNU gunzip goes not bail out, but goes to next file */
/* GNU gunzip does not bail out, but goes to next file */
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
stat_buf.st_mode))
goto err;
@@ -138,7 +138,7 @@ char* make_new_name_generic(char *filename, const char *expected_ext)
/*
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
* Modified for busybox by Glenn McGrath
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
@@ -158,10 +158,10 @@ USE_DESKTOP(long long) int unpack_bunzip2(void)
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
}
int bunzip2_main(int argc, char **argv);
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc, char **argv)
{
getopt32(argv, "cf");
getopt32(argv, "cfvdt");
argv += optind;
if (applet_name[2] == 'c')
option_mask32 |= OPT_STDOUT;
@@ -185,7 +185,7 @@ int bunzip2_main(int argc, char **argv)
* handling.
*
* General cleanup to better adhere to the style guide and make use of standard
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
* busybox functions by Glenn McGrath
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
@@ -241,7 +241,6 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
} else if (magic2 == 0x8b) {
check_header_gzip_or_die(STDIN_FILENO);
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
} else {
goto bad_magic;
@@ -257,7 +256,7 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
return status;
}
int gunzip_main(int argc, char **argv);
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc, char **argv)
{
getopt32(argv, "cfvdt");
@@ -295,10 +294,10 @@ USE_DESKTOP(long long) int unpack_unlzma(void)
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
}
int unlzma_main(int argc, char **argv);
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc, char **argv)
{
getopt32(argv, "c");
getopt32(argv, "cf");
argv += optind;
/* lzmacat? */
if (applet_name[4] == 'c')
@@ -337,7 +336,7 @@ USE_DESKTOP(long long) int unpack_uncompress(void)
return status;
}
int uncompress_main(int argc, char **argv);
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uncompress_main(int argc, char **argv)
{
getopt32(argv, "cf");
+61
View File
@@ -0,0 +1,61 @@
#!/bin/sh
# Test that concatenated gz files are unpacking correctly.
# It also tests that unpacking in general is working right.
# Since zip code has many corner cases, run it for a few hours
# to get a decent coverage (200000 tests or more).
gzip="gzip"
gunzip="../busybox gunzip"
# Or the other way around:
#gzip="../busybox gzip"
#gunzip="gunzip"
c=0
i=$PID
while true; do
c=$((c+1))
# RANDOM is not very random on some shells. Spice it up.
# 100003 is prime
len1=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
i=$((i * 1664525 + 1013904223))
len2=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
# Just using urandom will make gzip use method 0 (store) -
# not good for test coverage!
cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
| dd bs=$len1 count=1 >z1 2>/dev/null
cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
| dd bs=$len2 count=1 >z2 2>/dev/null
$gzip <z1 >zz.gz
$gzip <z2 >>zz.gz
$gunzip -c zz.gz >z9 || {
echo "Exitcode $?"
exit
}
sum=`cat z1 z2 | md5sum`
sum9=`md5sum <z9`
test "$sum" == "$sum9" || {
echo "md5sums don't match"
exit
}
echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum"
sum=`cat z1 z2 z1 z2 | md5sum`
rm z1.gz z2.gz 2>/dev/null
$gzip z1
$gzip z2
cat z1.gz z2.gz z1.gz z2.gz >zz.gz
$gunzip -c zz.gz >z9 || {
echo "Exitcode $? (2)"
exit
}
sum9=`md5sum <z9`
test "$sum" == "$sum9" || {
echo "md5sums don't match (1)"
exit
}
echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum (2)"
done
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
# Leak test for gunzip. Watch top for growing process size.
# Just using urandom will make gzip use method 0 (store) -
# not good for test coverage!
cat /dev/urandom \
| while true; do read junk; echo "junk $RANDOM $junk"; done \
| ../busybox gzip \
| ../busybox gunzip -c >/dev/null
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
# Leak test for gunzip. Watch top for growing process size.
# In this case we look for leaks in "concatenated .gz" code -
# we feed gunzip with a stream of .gz files.
i=$PID
c=0
while true; do
c=$((c + 1))
echo "Block# $c" >&2
# RANDOM is not very random on some shells. Spice it up.
i=$((i * 1664525 + 1013904223))
# 100003 is prime
len=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
# Just using urandom will make gzip use method 0 (store) -
# not good for test coverage!
cat /dev/urandom \
| while true; do read junk; echo "junk $c $i $junk"; done \
| dd bs=$len count=1 2>/dev/null \
| gzip >xxx.gz
cat xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz
done | ../busybox gunzip -c >/dev/null
+44
View File
@@ -0,0 +1,44 @@
bzip2 applet in busybox is based on lightly-modified source
of bzip2 version 1.0.4. bzip2 source is distributed
under the following conditions (copied verbatim from LICENSE file)
===========================================================
This program, "bzip2", the associated library "libbzip2", and all
documentation, are copyright (C) 1996-2006 Julian R Seward. All
rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Cambridge, UK.
jseward@bzip.org
bzip2/libbzip2 version 1.0.4 of 20 December 2006
+90
View File
@@ -0,0 +1,90 @@
This file is an abridged version of README from bizp2 1.0.4
Build instructions (which are not relevant to busyboxed bzip2)
are removed.
===========================================================
This is the README for bzip2/libzip2.
This version is fully compatible with the previous public releases.
------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------
Please read and be aware of the following:
WARNING:
This program and library (attempts to) compress data by
performing several non-trivial transformations on it.
Unless you are 100% familiar with *all* the algorithms
contained herein, and with the consequences of modifying them,
you should NOT meddle with the compression or decompression
machinery. Incorrect changes can and very likely *will*
lead to disastrous loss of data.
DISCLAIMER:
I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
Every compression of a file implies an assumption that the
compressed file can be decompressed to reproduce the original.
Great efforts in design, coding and testing have been made to
ensure that this program works correctly. However, the complexity
of the algorithms, and, in particular, the presence of various
special cases in the code which occur with very low but non-zero
probability make it impossible to rule out the possibility of bugs
remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
That is not to say this program is inherently unreliable.
Indeed, I very much hope the opposite is true. bzip2/libbzip2
has been carefully constructed and extensively tested.
PATENTS:
To the best of my knowledge, bzip2/libbzip2 does not use any
patented algorithms. However, I do not have the resources
to carry out a patent search. Therefore I cannot give any
guarantee of the above statement.
I hope you find bzip2 useful. Feel free to contact me at
jseward@bzip.org
if you have any suggestions or queries. Many people mailed me with
comments, suggestions and patches after the releases of bzip-0.15,
bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
feedback. I thank you for your comments.
bzip2's "home" is http://www.bzip.org/
Julian Seward
jseward@bzip.org
Cambridge, UK.
18 July 1996 (version 0.15)
25 August 1996 (version 0.21)
7 August 1997 (bzip2, version 0.1)
29 August 1997 (bzip2, version 0.1pl2)
23 August 1998 (bzip2, version 0.9.0)
8 June 1999 (bzip2, version 0.9.5)
4 Sept 1999 (bzip2, version 0.9.5d)
5 May 2000 (bzip2, version 1.0pre8)
30 December 2001 (bzip2, version 1.0.2pre1)
15 February 2005 (bzip2, version 1.0.3)
20 December 2006 (bzip2, version 1.0.4)
File diff suppressed because it is too large. Load diff
+429
View File
@@ -0,0 +1,429 @@
/*
* bzip2 is written by Julian Seward <jseward@bzip.org>.
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
* See README and LICENSE files in this directory for more information.
*/
/*-------------------------------------------------------------*/
/*--- Library top-level functions. ---*/
/*--- bzlib.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
/* CHANGES
* 0.9.0 -- original version.
* 0.9.0a/b -- no changes in this file.
* 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
* fixed bzWrite/bzRead to ignore zero-length requests.
* fixed bzread to correctly handle read requests after EOF.
* wrong parameter order in call to bzDecompressInit in
* bzBuffToBuffDecompress. Fixed.
*/
/* #include "bzlib_private.h" */
/*---------------------------------------------------*/
/*--- Compression stuff ---*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/
#if BZ_LIGHT_DEBUG
static
void bz_assert_fail(int errcode)
{
/* if (errcode == 1007) bb_error_msg_and_die("probably bad RAM"); */
bb_error_msg_and_die("internal error %d", errcode);
}
#endif
/*---------------------------------------------------*/
static
void prepare_new_block(EState* s)
{
int i;
s->nblock = 0;
s->numZ = 0;
s->state_out_pos = 0;
BZ_INITIALISE_CRC(s->blockCRC);
/* inlined memset would be nice to have here */
for (i = 0; i < 256; i++)
s->inUse[i] = 0;
s->blockNo++;
}
/*---------------------------------------------------*/
static
ALWAYS_INLINE
void init_RL(EState* s)
{
s->state_in_ch = 256;
s->state_in_len = 0;
}
static
int isempty_RL(EState* s)
{
return (s->state_in_ch >= 256 || s->state_in_len <= 0);
}
/*---------------------------------------------------*/
static
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
{
int32_t n;
EState* s;
s = xzalloc(sizeof(EState));
s->strm = strm;
n = 100000 * blockSize100k;
s->arr1 = xmalloc(n * sizeof(uint32_t));
s->mtfv = (uint16_t*)s->arr1;
s->ptr = (uint32_t*)s->arr1;
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
s->block = (uint8_t*)s->arr2;
s->ftab = xmalloc(65537 * sizeof(uint32_t));
s->crc32table = crc32_filltable(NULL, 1);
s->state = BZ_S_INPUT;
s->mode = BZ_M_RUNNING;
s->blockSize100k = blockSize100k;
s->nblockMAX = n - 19;
strm->state = s;
/*strm->total_in = 0;*/
strm->total_out = 0;
init_RL(s);
prepare_new_block(s);
}
/*---------------------------------------------------*/
static
void add_pair_to_block(EState* s)
{
int32_t i;
uint8_t ch = (uint8_t)(s->state_in_ch);
for (i = 0; i < s->state_in_len; i++) {
BZ_UPDATE_CRC(s, s->blockCRC, ch);
}
s->inUse[s->state_in_ch] = 1;
switch (s->state_in_len) {
case 3:
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
/* fall through */
case 2:
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
/* fall through */
case 1:
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
break;
default:
s->inUse[s->state_in_len - 4] = 1;
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
s->block[s->nblock] = (uint8_t)(s->state_in_len - 4);
s->nblock++;
break;
}
}
/*---------------------------------------------------*/
static
void flush_RL(EState* s)
{
if (s->state_in_ch < 256) add_pair_to_block(s);
init_RL(s);
}
/*---------------------------------------------------*/
#define ADD_CHAR_TO_BLOCK(zs, zchh0) \
{ \
uint32_t zchh = (uint32_t)(zchh0); \
/*-- fast track the common case --*/ \
if (zchh != zs->state_in_ch && zs->state_in_len == 1) { \
uint8_t ch = (uint8_t)(zs->state_in_ch); \
BZ_UPDATE_CRC(zs, zs->blockCRC, ch); \
zs->inUse[zs->state_in_ch] = 1; \
zs->block[zs->nblock] = (uint8_t)ch; \
zs->nblock++; \
zs->state_in_ch = zchh; \
} \
else \
/*-- general, uncommon cases --*/ \
if (zchh != zs->state_in_ch || zs->state_in_len == 255) { \
if (zs->state_in_ch < 256) \
add_pair_to_block(zs); \
zs->state_in_ch = zchh; \
zs->state_in_len = 1; \
} else { \
zs->state_in_len++; \
} \
}
/*---------------------------------------------------*/
static
void /*Bool*/ copy_input_until_stop(EState* s)
{
/*Bool progress_in = False;*/
#ifdef SAME_CODE_AS_BELOW
if (s->mode == BZ_M_RUNNING) {
/*-- fast track the common case --*/
while (1) {
/*-- no input? --*/
if (s->strm->avail_in == 0) break;
/*-- block full? --*/
if (s->nblock >= s->nblockMAX) break;
/*progress_in = True;*/
ADD_CHAR_TO_BLOCK(s, (uint32_t)(*(uint8_t*)(s->strm->next_in)));
s->strm->next_in++;
s->strm->avail_in--;
/*s->strm->total_in++;*/
}
} else
#endif
{
/*-- general, uncommon case --*/
while (1) {
/*-- no input? --*/
if (s->strm->avail_in == 0) break;
/*-- block full? --*/
if (s->nblock >= s->nblockMAX) break;
//# /*-- flush/finish end? --*/
//# if (s->avail_in_expect == 0) break;
/*progress_in = True;*/
ADD_CHAR_TO_BLOCK(s, *(uint8_t*)(s->strm->next_in));
s->strm->next_in++;
s->strm->avail_in--;
/*s->strm->total_in++;*/
//# s->avail_in_expect--;
}
}
/*return progress_in;*/
}
/*---------------------------------------------------*/
static
void /*Bool*/ copy_output_until_stop(EState* s)
{
/*Bool progress_out = False;*/
while (1) {
/*-- no output space? --*/
if (s->strm->avail_out == 0) break;
/*-- block done? --*/
if (s->state_out_pos >= s->numZ) break;
/*progress_out = True;*/
*(s->strm->next_out) = s->zbits[s->state_out_pos];
s->state_out_pos++;
s->strm->avail_out--;
s->strm->next_out++;
s->strm->total_out++;
}
/*return progress_out;*/
}
/*---------------------------------------------------*/
static
void /*Bool*/ handle_compress(bz_stream *strm)
{
/*Bool progress_in = False;*/
/*Bool progress_out = False;*/
EState* s = strm->state;
while (1) {
if (s->state == BZ_S_OUTPUT) {
/*progress_out |=*/ copy_output_until_stop(s);
if (s->state_out_pos < s->numZ) break;
if (s->mode == BZ_M_FINISHING
//# && s->avail_in_expect == 0
&& s->strm->avail_in == 0
&& isempty_RL(s))
break;
prepare_new_block(s);
s->state = BZ_S_INPUT;
#ifdef FLUSH_IS_UNUSED
if (s->mode == BZ_M_FLUSHING
&& s->avail_in_expect == 0
&& isempty_RL(s))
break;
#endif
}
if (s->state == BZ_S_INPUT) {
/*progress_in |=*/ copy_input_until_stop(s);
//#if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
if (s->mode != BZ_M_RUNNING && s->strm->avail_in == 0) {
flush_RL(s);
BZ2_compressBlock(s, (s->mode == BZ_M_FINISHING));
s->state = BZ_S_OUTPUT;
} else
if (s->nblock >= s->nblockMAX) {
BZ2_compressBlock(s, 0);
s->state = BZ_S_OUTPUT;
} else
if (s->strm->avail_in == 0) {
break;
}
}
}
/*return progress_in || progress_out;*/
}
/*---------------------------------------------------*/
static
int BZ2_bzCompress(bz_stream *strm, int action)
{
/*Bool progress;*/
EState* s;
s = strm->state;
switch (s->mode) {
case BZ_M_RUNNING:
if (action == BZ_RUN) {
/*progress =*/ handle_compress(strm);
/*return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;*/
return BZ_RUN_OK;
}
#ifdef FLUSH_IS_UNUSED
else
if (action == BZ_FLUSH) {
//#s->avail_in_expect = strm->avail_in;
s->mode = BZ_M_FLUSHING;
goto case_BZ_M_FLUSHING;
}
#endif
else
/*if (action == BZ_FINISH)*/ {
//#s->avail_in_expect = strm->avail_in;
s->mode = BZ_M_FINISHING;
goto case_BZ_M_FINISHING;
}
#ifdef FLUSH_IS_UNUSED
case_BZ_M_FLUSHING:
case BZ_M_FLUSHING:
/*if (s->avail_in_expect != s->strm->avail_in)
return BZ_SEQUENCE_ERROR;*/
/*progress =*/ handle_compress(strm);
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
return BZ_FLUSH_OK;
s->mode = BZ_M_RUNNING;
return BZ_RUN_OK;
#endif
case_BZ_M_FINISHING:
/*case BZ_M_FINISHING:*/
default:
/*if (s->avail_in_expect != s->strm->avail_in)
return BZ_SEQUENCE_ERROR;*/
/*progress =*/ handle_compress(strm);
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
//# return BZ_FINISH_OK;
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
return BZ_FINISH_OK;
/*s->mode = BZ_M_IDLE;*/
return BZ_STREAM_END;
}
/* return BZ_OK; --not reached--*/
}
/*---------------------------------------------------*/
#if ENABLE_FEATURE_CLEAN_UP
static
void BZ2_bzCompressEnd(bz_stream *strm)
{
EState* s;
s = strm->state;
free(s->arr1);
free(s->arr2);
free(s->ftab);
free(s->crc32table);
free(strm->state);
}
#endif
/*---------------------------------------------------*/
/*--- Misc convenience stuff ---*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/
#ifdef EXAMPLE_CODE_FOR_MEM_TO_MEM_COMPRESSION
static
int BZ2_bzBuffToBuffCompress(char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int blockSize100k)
{
bz_stream strm;
int ret;
if (dest == NULL || destLen == NULL ||
source == NULL ||
blockSize100k < 1 || blockSize100k > 9)
return BZ_PARAM_ERROR;
BZ2_bzCompressInit(&strm, blockSize100k);
strm.next_in = source;
strm.next_out = dest;
strm.avail_in = sourceLen;
strm.avail_out = *destLen;
ret = BZ2_bzCompress(&strm, BZ_FINISH);
if (ret == BZ_FINISH_OK) goto output_overflow;
if (ret != BZ_STREAM_END) goto errhandler;
/* normal termination */
*destLen -= strm.avail_out;
BZ2_bzCompressEnd(&strm);
return BZ_OK;
output_overflow:
BZ2_bzCompressEnd(&strm);
return BZ_OUTBUFF_FULL;
errhandler:
BZ2_bzCompressEnd(&strm);
return ret;
}
#endif
/*-------------------------------------------------------------*/
/*--- end bzlib.c ---*/
/*-------------------------------------------------------------*/
+65
View File
@@ -0,0 +1,65 @@
/*
* bzip2 is written by Julian Seward <jseward@bzip.org>.
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
* See README and LICENSE files in this directory for more information.
*/
/*-------------------------------------------------------------*/
/*--- Public header file for the library. ---*/
/*--- bzlib.h ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#define BZ_RUN 0
#define BZ_FLUSH 1
#define BZ_FINISH 2
#define BZ_OK 0
#define BZ_RUN_OK 1
#define BZ_FLUSH_OK 2
#define BZ_FINISH_OK 3
#define BZ_STREAM_END 4
#define BZ_SEQUENCE_ERROR (-1)
#define BZ_PARAM_ERROR (-2)
#define BZ_MEM_ERROR (-3)
#define BZ_DATA_ERROR (-4)
#define BZ_DATA_ERROR_MAGIC (-5)
#define BZ_IO_ERROR (-6)
#define BZ_UNEXPECTED_EOF (-7)
#define BZ_OUTBUFF_FULL (-8)
#define BZ_CONFIG_ERROR (-9)
typedef struct bz_stream {
void *state;
char *next_in;
char *next_out;
unsigned avail_in;
unsigned avail_out;
/*unsigned long long total_in;*/
unsigned long long total_out;
} bz_stream;
/*-- Core (low-level) library functions --*/
static void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k);
static int BZ2_bzCompress(bz_stream *strm, int action);
#if ENABLE_FEATURE_CLEAN_UP
static void BZ2_bzCompressEnd(bz_stream *strm);
#endif
/*-------------------------------------------------------------*/
/*--- end bzlib.h ---*/
/*-------------------------------------------------------------*/
+219
View File
@@ -0,0 +1,219 @@
/*
* bzip2 is written by Julian Seward <jseward@bzip.org>.
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
* See README and LICENSE files in this directory for more information.
*/
/*-------------------------------------------------------------*/
/*--- Private header file for the library. ---*/
/*--- bzlib_private.h ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
/* #include "bzlib.h" */
/*-- General stuff. --*/
typedef unsigned char Bool;
#define True ((Bool)1)
#define False ((Bool)0)
#if BZ_LIGHT_DEBUG
static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
#define AssertH(cond, errcode) \
do { \
if (!(cond)) \
bz_assert_fail(errcode); \
} while (0)
#else
#define AssertH(cond, msg) do { } while (0)
#endif
#if BZ_DEBUG
#define AssertD(cond, msg) \
do { \
if (!(cond)) \
bb_error_msg_and_die("(debug build): internal error %s", msg); \
} while (0)
#else
#define AssertD(cond, msg) do { } while (0)
#endif
/*-- Header bytes. --*/
#define BZ_HDR_B 0x42 /* 'B' */
#define BZ_HDR_Z 0x5a /* 'Z' */
#define BZ_HDR_h 0x68 /* 'h' */
#define BZ_HDR_0 0x30 /* '0' */
#define BZ_HDR_BZh0 0x425a6830
/*-- Constants for the back end. --*/
#define BZ_MAX_ALPHA_SIZE 258
#define BZ_MAX_CODE_LEN 23
#define BZ_RUNA 0
#define BZ_RUNB 1
#define BZ_N_GROUPS 6
#define BZ_G_SIZE 50
#define BZ_N_ITERS 4
#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
/*-- Stuff for doing CRCs. --*/
#define BZ_INITIALISE_CRC(crcVar) \
{ \
crcVar = 0xffffffffL; \
}
#define BZ_FINALISE_CRC(crcVar) \
{ \
crcVar = ~(crcVar); \
}
#define BZ_UPDATE_CRC(s, crcVar, cha) \
{ \
crcVar = (crcVar << 8) ^ s->crc32table[(crcVar >> 24) ^ ((uint8_t)cha)]; \
}
/*-- States and modes for compression. --*/
#define BZ_M_IDLE 1
#define BZ_M_RUNNING 2
#define BZ_M_FLUSHING 3
#define BZ_M_FINISHING 4
#define BZ_S_OUTPUT 1
#define BZ_S_INPUT 2
#define BZ_N_RADIX 2
#define BZ_N_QSORT 12
#define BZ_N_SHELL 18
#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
/*-- Structure holding all the compression-side stuff. --*/
typedef struct EState {
/* pointer back to the struct bz_stream */
bz_stream *strm;
/* mode this stream is in, and whether inputting */
/* or outputting data */
int32_t mode;
int32_t state;
/* remembers avail_in when flush/finish requested */
/* bbox: not needed, strm->avail_in always has the same value */
/* commented out with '//#' throughout the code */
/* uint32_t avail_in_expect; */
/* for doing the block sorting */
int32_t origPtr;
uint32_t *arr1;
uint32_t *arr2;
uint32_t *ftab;
/* aliases for arr1 and arr2 */
uint32_t *ptr;
uint8_t *block;
uint16_t *mtfv;
uint8_t *zbits;
/* guess what */
uint32_t *crc32table;
/* run-length-encoding of the input */
uint32_t state_in_ch;
int32_t state_in_len;
/* input and output limits and current posns */
int32_t nblock;
int32_t nblockMAX;
int32_t numZ;
int32_t state_out_pos;
/* the buffer for bit stream creation */
uint32_t bsBuff;
int32_t bsLive;
/* block and combined CRCs */
uint32_t blockCRC;
uint32_t combinedCRC;
/* misc administratium */
int32_t blockNo;
int32_t blockSize100k;
/* stuff for coding the MTF values */
int32_t nMTF;
/* map of bytes used in block */
int32_t nInUse;
Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
uint8_t unseqToSeq[256];
/* stuff for coding the MTF values */
int32_t mtfFreq [BZ_MAX_ALPHA_SIZE];
uint8_t selector [BZ_MAX_SELECTORS];
uint8_t selectorMtf[BZ_MAX_SELECTORS];
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
/* stack-saving measures: these can be local, but they are too big */
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
/* second dimension: only 3 needed; 4 makes index calculations faster */
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
#endif
int32_t BZ2_hbMakeCodeLengths__heap [BZ_MAX_ALPHA_SIZE + 2];
int32_t BZ2_hbMakeCodeLengths__weight[BZ_MAX_ALPHA_SIZE * 2];
int32_t BZ2_hbMakeCodeLengths__parent[BZ_MAX_ALPHA_SIZE * 2];
int32_t mainSort__runningOrder[256];
int32_t mainSort__copyStart[256];
int32_t mainSort__copyEnd[256];
} EState;
/*-- compression. --*/
static void
BZ2_blockSort(EState*);
static void
BZ2_compressBlock(EState*, int);
static void
BZ2_bsInitWrite(EState*);
static void
BZ2_hbAssignCodes(int32_t*, uint8_t*, int32_t, int32_t, int32_t);
static void
BZ2_hbMakeCodeLengths(EState*, uint8_t*, int32_t*, int32_t, int32_t);
/*-------------------------------------------------------------*/
/*--- end bzlib_private.h ---*/
/*-------------------------------------------------------------*/
+687
View File
@@ -0,0 +1,687 @@
/*
* bzip2 is written by Julian Seward <jseward@bzip.org>.
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
* See README and LICENSE files in this directory for more information.
*/
/*-------------------------------------------------------------*/
/*--- Compression machinery (not incl block sorting) ---*/
/*--- compress.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
/* CHANGES
* 0.9.0 -- original version.
* 0.9.0a/b -- no changes in this file.
* 0.9.0c -- changed setting of nGroups in sendMTFValues()
* so as to do a bit better on small files
*/
/* #include "bzlib_private.h" */
/*---------------------------------------------------*/
/*--- Bit stream I/O ---*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/
static
void BZ2_bsInitWrite(EState* s)
{
s->bsLive = 0;
s->bsBuff = 0;
}
/*---------------------------------------------------*/
static NOINLINE
void bsFinishWrite(EState* s)
{
while (s->bsLive > 0) {
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
s->numZ++;
s->bsBuff <<= 8;
s->bsLive -= 8;
}
}
/*---------------------------------------------------*/
static
/* Helps only on level 5, on other levels hurts. ? */
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
ALWAYS_INLINE
#endif
void bsW(EState* s, int32_t n, uint32_t v)
{
while (s->bsLive >= 8) {
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
s->numZ++;
s->bsBuff <<= 8;
s->bsLive -= 8;
}
s->bsBuff |= (v << (32 - s->bsLive - n));
s->bsLive += n;
}
/*---------------------------------------------------*/
static
void bsPutU32(EState* s, unsigned u)
{
bsW(s, 8, (u >> 24) & 0xff);
bsW(s, 8, (u >> 16) & 0xff);
bsW(s, 8, (u >> 8) & 0xff);
bsW(s, 8, u & 0xff);
}
/*---------------------------------------------------*/
static
void bsPutU16(EState* s, unsigned u)
{
bsW(s, 8, (u >> 8) & 0xff);
bsW(s, 8, u & 0xff);
}
/*---------------------------------------------------*/
/*--- The back end proper ---*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/
static
void makeMaps_e(EState* s)
{
int i;
s->nInUse = 0;
for (i = 0; i < 256; i++) {
if (s->inUse[i]) {
s->unseqToSeq[i] = s->nInUse;
s->nInUse++;
}
}
}
/*---------------------------------------------------*/
static NOINLINE
void generateMTFValues(EState* s)
{
uint8_t yy[256];
int32_t i, j;
int32_t zPend;
int32_t wr;
int32_t EOB;
/*
* After sorting (eg, here),
* s->arr1[0 .. s->nblock-1] holds sorted order,
* and
* ((uint8_t*)s->arr2)[0 .. s->nblock-1]
* holds the original block data.
*
* The first thing to do is generate the MTF values,
* and put them in
* ((uint16_t*)s->arr1)[0 .. s->nblock-1].
* Because there are strictly fewer or equal MTF values
* than block values, ptr values in this area are overwritten
* with MTF values only when they are no longer needed.
*
* The final compressed bitstream is generated into the
* area starting at
* &((uint8_t*)s->arr2)[s->nblock]
*
* These storage aliases are set up in bzCompressInit(),
* except for the last one, which is arranged in
* compressBlock().
*/
uint32_t* ptr = s->ptr;
uint8_t* block = s->block;
uint16_t* mtfv = s->mtfv;
makeMaps_e(s);
EOB = s->nInUse+1;
for (i = 0; i <= EOB; i++)
s->mtfFreq[i] = 0;
wr = 0;
zPend = 0;
for (i = 0; i < s->nInUse; i++)
yy[i] = (uint8_t) i;
for (i = 0; i < s->nblock; i++) {
uint8_t ll_i;
AssertD(wr <= i, "generateMTFValues(1)");
j = ptr[i] - 1;
if (j < 0)
j += s->nblock;
ll_i = s->unseqToSeq[block[j]];
AssertD(ll_i < s->nInUse, "generateMTFValues(2a)");
if (yy[0] == ll_i) {
zPend++;
} else {
if (zPend > 0) {
zPend--;
while (1) {
if (zPend & 1) {
mtfv[wr] = BZ_RUNB; wr++;
s->mtfFreq[BZ_RUNB]++;
} else {
mtfv[wr] = BZ_RUNA; wr++;
s->mtfFreq[BZ_RUNA]++;
}
if (zPend < 2) break;
zPend = (uint32_t)(zPend - 2) / 2;
/* bbox: unsigned div is easier */
};
zPend = 0;
}
{
register uint8_t rtmp;
register uint8_t* ryy_j;
register uint8_t rll_i;
rtmp = yy[1];
yy[1] = yy[0];
ryy_j = &(yy[1]);
rll_i = ll_i;
while (rll_i != rtmp) {
register uint8_t rtmp2;
ryy_j++;
rtmp2 = rtmp;
rtmp = *ryy_j;
*ryy_j = rtmp2;
};
yy[0] = rtmp;
j = ryy_j - &(yy[0]);
mtfv[wr] = j+1;
wr++;
s->mtfFreq[j+1]++;
}
}
}
if (zPend > 0) {
zPend--;
while (1) {
if (zPend & 1) {
mtfv[wr] = BZ_RUNB;
wr++;
s->mtfFreq[BZ_RUNB]++;
} else {
mtfv[wr] = BZ_RUNA;
wr++;
s->mtfFreq[BZ_RUNA]++;
}
if (zPend < 2)
break;
zPend = (uint32_t)(zPend - 2) / 2;
/* bbox: unsigned div is easier */
};
zPend = 0;
}
mtfv[wr] = EOB;
wr++;
s->mtfFreq[EOB]++;
s->nMTF = wr;
}
/*---------------------------------------------------*/
#define BZ_LESSER_ICOST 0
#define BZ_GREATER_ICOST 15
static NOINLINE
void sendMTFValues(EState* s)
{
int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
int32_t nGroups, nBytes;
/*
* uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
* is a global since the decoder also needs it.
*
* int32_t code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
* int32_t rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
* are also globals only used in this proc.
* Made global to keep stack frame size small.
*/
#define code sendMTFValues__code
#define rfreq sendMTFValues__rfreq
#define len_pack sendMTFValues__len_pack
uint16_t cost[BZ_N_GROUPS];
int32_t fave[BZ_N_GROUPS];
uint16_t* mtfv = s->mtfv;
alphaSize = s->nInUse + 2;
for (t = 0; t < BZ_N_GROUPS; t++)
for (v = 0; v < alphaSize; v++)
s->len[t][v] = BZ_GREATER_ICOST;
/*--- Decide how many coding tables to use ---*/
AssertH(s->nMTF > 0, 3001);
if (s->nMTF < 200) nGroups = 2; else
if (s->nMTF < 600) nGroups = 3; else
if (s->nMTF < 1200) nGroups = 4; else
if (s->nMTF < 2400) nGroups = 5; else
nGroups = 6;
/*--- Generate an initial set of coding tables ---*/
{
int32_t nPart, remF, tFreq, aFreq;
nPart = nGroups;
remF = s->nMTF;
gs = 0;
while (nPart > 0) {
tFreq = remF / nPart;
ge = gs - 1;
aFreq = 0;
while (aFreq < tFreq && ge < alphaSize-1) {
ge++;
aFreq += s->mtfFreq[ge];
}
if (ge > gs
&& nPart != nGroups && nPart != 1
&& ((nGroups - nPart) % 2 == 1) /* bbox: can this be replaced by x & 1? */
) {
aFreq -= s->mtfFreq[ge];
ge--;
}
for (v = 0; v < alphaSize; v++)
if (v >= gs && v <= ge)
s->len[nPart-1][v] = BZ_LESSER_ICOST;
else
s->len[nPart-1][v] = BZ_GREATER_ICOST;
nPart--;
gs = ge + 1;
remF -= aFreq;
}
}
/*
* Iterate up to BZ_N_ITERS times to improve the tables.
*/
for (iter = 0; iter < BZ_N_ITERS; iter++) {
for (t = 0; t < nGroups; t++)
fave[t] = 0;
for (t = 0; t < nGroups; t++)
for (v = 0; v < alphaSize; v++)
s->rfreq[t][v] = 0;
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
/*
* Set up an auxiliary length table which is used to fast-track
* the common case (nGroups == 6).
*/
if (nGroups == 6) {
for (v = 0; v < alphaSize; v++) {
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
}
}
#endif
nSelectors = 0;
totc = 0;
gs = 0;
while (1) {
/*--- Set group start & end marks. --*/
if (gs >= s->nMTF)
break;
ge = gs + BZ_G_SIZE - 1;
if (ge >= s->nMTF)
ge = s->nMTF-1;
/*
* Calculate the cost of this group as coded
* by each of the coding tables.
*/
for (t = 0; t < nGroups; t++)
cost[t] = 0;
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
if (nGroups == 6 && 50 == ge-gs+1) {
/*--- fast track the common case ---*/
register uint32_t cost01, cost23, cost45;
register uint16_t icv;
cost01 = cost23 = cost45 = 0;
#define BZ_ITER(nn) \
icv = mtfv[gs+(nn)]; \
cost01 += s->len_pack[icv][0]; \
cost23 += s->len_pack[icv][1]; \
cost45 += s->len_pack[icv][2];
BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4);
BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9);
BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14);
BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19);
BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24);
BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29);
BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34);
BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39);
BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44);
BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49);
#undef BZ_ITER
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
} else
#endif
{
/*--- slow version which correctly handles all situations ---*/
for (i = gs; i <= ge; i++) {
uint16_t icv = mtfv[i];
for (t = 0; t < nGroups; t++)
cost[t] += s->len[t][icv];
}
}
/*
* Find the coding table which is best for this group,
* and record its identity in the selector table.
*/
/*bc = 999999999;*/
/*bt = -1;*/
bc = cost[0];
bt = 0;
for (t = 1 /*0*/; t < nGroups; t++) {
if (cost[t] < bc) {
bc = cost[t];
bt = t;
}
}
totc += bc;
fave[bt]++;
s->selector[nSelectors] = bt;
nSelectors++;
/*
* Increment the symbol frequencies for the selected table.
*/
/* 1% faster compress. +800 bytes */
#if CONFIG_BZIP2_FEATURE_SPEED >= 4
if (nGroups == 6 && 50 == ge-gs+1) {
/*--- fast track the common case ---*/
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4);
BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9);
BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14);
BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19);
BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24);
BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29);
BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34);
BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39);
BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44);
BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49);
#undef BZ_ITUR
gs = ge + 1;
} else
#endif
{
/*--- slow version which correctly handles all situations ---*/
while (gs <= ge) {
s->rfreq[bt][mtfv[gs]]++;
gs++;
}
/* already is: gs = ge + 1; */
}
}
/*
* Recompute the tables based on the accumulated frequencies.
*/
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
* comment in huffman.c for details. */
for (t = 0; t < nGroups; t++)
BZ2_hbMakeCodeLengths(s, &(s->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
}
AssertH(nGroups < 8, 3002);
AssertH(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZ_G_SIZE)), 3003);
/*--- Compute MTF values for the selectors. ---*/
{
uint8_t pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
for (i = 0; i < nGroups; i++)
pos[i] = i;
for (i = 0; i < nSelectors; i++) {
ll_i = s->selector[i];
j = 0;
tmp = pos[j];
while (ll_i != tmp) {
j++;
tmp2 = tmp;
tmp = pos[j];
pos[j] = tmp2;
};
pos[0] = tmp;
s->selectorMtf[i] = j;
}
};
/*--- Assign actual codes for the tables. --*/
for (t = 0; t < nGroups; t++) {
minLen = 32;
maxLen = 0;
for (i = 0; i < alphaSize; i++) {
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
if (s->len[t][i] < minLen) minLen = s->len[t][i];
}
AssertH(!(maxLen > 17 /*20*/), 3004);
AssertH(!(minLen < 1), 3005);
BZ2_hbAssignCodes(&(s->code[t][0]), &(s->len[t][0]), minLen, maxLen, alphaSize);
}
/*--- Transmit the mapping table. ---*/
{
/* bbox: optimized a bit more than in bzip2 */
int inUse16 = 0;
for (i = 0; i < 16; i++) {
if (sizeof(long) <= 4) {
inUse16 = inUse16*2 +
((*(uint32_t*)&(s->inUse[i * 16 + 0])
| *(uint32_t*)&(s->inUse[i * 16 + 4])
| *(uint32_t*)&(s->inUse[i * 16 + 8])
| *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
} else { /* Our CPU can do better */
inUse16 = inUse16*2 +
((*(uint64_t*)&(s->inUse[i * 16 + 0])
| *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
}
}
nBytes = s->numZ;
bsW(s, 16, inUse16);
inUse16 <<= (sizeof(int)*8 - 16); /* move 15th bit into sign bit */
for (i = 0; i < 16; i++) {
if (inUse16 < 0) {
unsigned v16 = 0;
for (j = 0; j < 16; j++)
v16 = v16*2 + s->inUse[i * 16 + j];
bsW(s, 16, v16);
}
inUse16 <<= 1;
}
}
/*--- Now the selectors. ---*/
nBytes = s->numZ;
bsW(s, 3, nGroups);
bsW(s, 15, nSelectors);
for (i = 0; i < nSelectors; i++) {
for (j = 0; j < s->selectorMtf[i]; j++)
bsW(s, 1, 1);
bsW(s, 1, 0);
}
/*--- Now the coding tables. ---*/
nBytes = s->numZ;
for (t = 0; t < nGroups; t++) {
int32_t curr = s->len[t][0];
bsW(s, 5, curr);
for (i = 0; i < alphaSize; i++) {
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
bsW(s, 1, 0);
}
}
/*--- And finally, the block data proper ---*/
nBytes = s->numZ;
selCtr = 0;
gs = 0;
while (1) {
if (gs >= s->nMTF)
break;
ge = gs + BZ_G_SIZE - 1;
if (ge >= s->nMTF)
ge = s->nMTF-1;
AssertH(s->selector[selCtr] < nGroups, 3006);
/* Costs 1300 bytes and is _slower_ (on Intel Core 2) */
#if 0
if (nGroups == 6 && 50 == ge-gs+1) {
/*--- fast track the common case ---*/
uint16_t mtfv_i;
uint8_t* s_len_sel_selCtr = &(s->len[s->selector[selCtr]][0]);
int32_t* s_code_sel_selCtr = &(s->code[s->selector[selCtr]][0]);
#define BZ_ITAH(nn) \
mtfv_i = mtfv[gs+(nn)]; \
bsW(s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i])
BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4);
BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9);
BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14);
BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19);
BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24);
BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29);
BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34);
BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39);
BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44);
BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49);
#undef BZ_ITAH
gs = ge+1;
} else
#endif
{
/*--- slow version which correctly handles all situations ---*/
/* code is bit bigger, but moves multiply out of the loop */
uint8_t* s_len_sel_selCtr = &(s->len [s->selector[selCtr]][0]);
int32_t* s_code_sel_selCtr = &(s->code[s->selector[selCtr]][0]);
while (gs <= ge) {
bsW(s,
s_len_sel_selCtr[mtfv[gs]],
s_code_sel_selCtr[mtfv[gs]]
);
gs++;
}
/* already is: gs = ge+1; */
}
selCtr++;
}
AssertH(selCtr == nSelectors, 3007);
#undef code
#undef rfreq
#undef len_pack
}
/*---------------------------------------------------*/
static
void BZ2_compressBlock(EState* s, int is_last_block)
{
if (s->nblock > 0) {
BZ_FINALISE_CRC(s->blockCRC);
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
s->combinedCRC ^= s->blockCRC;
if (s->blockNo > 1)
s->numZ = 0;
BZ2_blockSort(s);
}
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
/*-- If this is the first block, create the stream header. --*/
if (s->blockNo == 1) {
BZ2_bsInitWrite(s);
/*bsPutU8(s, BZ_HDR_B);*/
/*bsPutU8(s, BZ_HDR_Z);*/
/*bsPutU8(s, BZ_HDR_h);*/
/*bsPutU8(s, BZ_HDR_0 + s->blockSize100k);*/
bsPutU32(s, BZ_HDR_BZh0 + s->blockSize100k);
}
if (s->nblock > 0) {
/*bsPutU8(s, 0x31);*/
/*bsPutU8(s, 0x41);*/
/*bsPutU8(s, 0x59);*/
/*bsPutU8(s, 0x26);*/
bsPutU32(s, 0x31415926);
/*bsPutU8(s, 0x53);*/
/*bsPutU8(s, 0x59);*/
bsPutU16(s, 0x5359);
/*-- Now the block's CRC, so it is in a known place. --*/
bsPutU32(s, s->blockCRC);
/*
* Now a single bit indicating (non-)randomisation.
* As of version 0.9.5, we use a better sorting algorithm
* which makes randomisation unnecessary. So always set
* the randomised bit to 'no'. Of course, the decoder
* still needs to be able to handle randomised blocks
* so as to maintain backwards compatibility with
* older versions of bzip2.
*/
bsW(s, 1, 0);
bsW(s, 24, s->origPtr);
generateMTFValues(s);
sendMTFValues(s);
}
/*-- If this is the last block, add the stream trailer. --*/
if (is_last_block) {
/*bsPutU8(s, 0x17);*/
/*bsPutU8(s, 0x72);*/
/*bsPutU8(s, 0x45);*/
/*bsPutU8(s, 0x38);*/
bsPutU32(s, 0x17724538);
/*bsPutU8(s, 0x50);*/
/*bsPutU8(s, 0x90);*/
bsPutU16(s, 0x5090);
bsPutU32(s, s->combinedCRC);
bsFinishWrite(s);
}
}
/*-------------------------------------------------------------*/
/*--- end compress.c ---*/
/*-------------------------------------------------------------*/
+229
View File
@@ -0,0 +1,229 @@
/*
* bzip2 is written by Julian Seward <jseward@bzip.org>.
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
* See README and LICENSE files in this directory for more information.
*/
/*-------------------------------------------------------------*/
/*--- Huffman coding low-level stuff ---*/
/*--- huffman.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
/* #include "bzlib_private.h" */
/*---------------------------------------------------*/
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
#define ADDWEIGHTS(zw1,zw2) \
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
#define UPHEAP(z) \
{ \
int32_t zz, tmp; \
zz = z; \
tmp = heap[zz]; \
while (weight[tmp] < weight[heap[zz >> 1]]) { \
heap[zz] = heap[zz >> 1]; \
zz >>= 1; \
} \
heap[zz] = tmp; \
}
/* 90 bytes, 0.3% of overall compress speed */
#if CONFIG_BZIP2_FEATURE_SPEED >= 1
/* macro works better than inline (gcc 4.2.1) */
#define DOWNHEAP1(heap, weight, Heap) \
{ \
int32_t zz, yy, tmp; \
zz = 1; \
tmp = heap[zz]; \
while (1) { \
yy = zz << 1; \
if (yy > nHeap) \
break; \
if (yy < nHeap \
&& weight[heap[yy+1]] < weight[heap[yy]]) \
yy++; \
if (weight[tmp] < weight[heap[yy]]) \
break; \
heap[zz] = heap[yy]; \
zz = yy; \
} \
heap[zz] = tmp; \
}
#else
static
void DOWNHEAP1(int32_t *heap, int32_t *weight, int32_t nHeap)
{
int32_t zz, yy, tmp;
zz = 1;
tmp = heap[zz];
while (1) {
yy = zz << 1;
if (yy > nHeap)
break;
if (yy < nHeap
&& weight[heap[yy + 1]] < weight[heap[yy]])
yy++;
if (weight[tmp] < weight[heap[yy]])
break;
heap[zz] = heap[yy];
zz = yy;
}
heap[zz] = tmp;
}
#endif
/*---------------------------------------------------*/
static
void BZ2_hbMakeCodeLengths(EState *s,
uint8_t *len,
int32_t *freq,
int32_t alphaSize,
int32_t maxLen)
{
/*
* Nodes and heap entries run from 1. Entry 0
* for both the heap and nodes is a sentinel.
*/
int32_t nNodes, nHeap, n1, n2, i, j, k;
Bool tooLong;
/* bbox: moved to EState to save stack
int32_t heap [BZ_MAX_ALPHA_SIZE + 2];
int32_t weight[BZ_MAX_ALPHA_SIZE * 2];
int32_t parent[BZ_MAX_ALPHA_SIZE * 2];
*/
#define heap (s->BZ2_hbMakeCodeLengths__heap)
#define weight (s->BZ2_hbMakeCodeLengths__weight)
#define parent (s->BZ2_hbMakeCodeLengths__parent)
for (i = 0; i < alphaSize; i++)
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
while (1) {
nNodes = alphaSize;
nHeap = 0;
heap[0] = 0;
weight[0] = 0;
parent[0] = -2;
for (i = 1; i <= alphaSize; i++) {
parent[i] = -1;
nHeap++;
heap[nHeap] = i;
UPHEAP(nHeap);
}
AssertH(nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001);
while (nHeap > 1) {
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
nNodes++;
parent[n1] = parent[n2] = nNodes;
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
parent[nNodes] = -1;
nHeap++;
heap[nHeap] = nNodes;
UPHEAP(nHeap);
}
AssertH(nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002);
tooLong = False;
for (i = 1; i <= alphaSize; i++) {
j = 0;
k = i;
while (parent[k] >= 0) {
k = parent[k];
j++;
}
len[i-1] = j;
if (j > maxLen)
tooLong = True;
}
if (!tooLong)
break;
/* 17 Oct 04: keep-going condition for the following loop used
to be 'i < alphaSize', which missed the last element,
theoretically leading to the possibility of the compressor
looping. However, this count-scaling step is only needed if
one of the generated Huffman code words is longer than
maxLen, which up to and including version 1.0.2 was 20 bits,
which is extremely unlikely. In version 1.0.3 maxLen was
changed to 17 bits, which has minimal effect on compression
ratio, but does mean this scaling step is used from time to
time, enough to verify that it works.
This means that bzip2-1.0.3 and later will only produce
Huffman codes with a maximum length of 17 bits. However, in
order to preserve backwards compatibility with bitstreams
produced by versions pre-1.0.3, the decompressor must still
handle lengths of up to 20. */
for (i = 1; i <= alphaSize; i++) {
j = weight[i] >> 8;
/* bbox: yes, it is a signed division.
* don't replace with shift! */
j = 1 + (j / 2);
weight[i] = j << 8;
}
}
#undef heap
#undef weight
#undef parent
}
/*---------------------------------------------------*/
static
void BZ2_hbAssignCodes(int32_t *code,
uint8_t *length,
int32_t minLen,
int32_t maxLen,
int32_t alphaSize)
{
int32_t n, vec, i;
vec = 0;
for (n = minLen; n <= maxLen; n++) {
for (i = 0; i < alphaSize; i++) {
if (length[i] == n) {
code[i] = vec;
vec++;
};
}
vec <<= 1;
}
}
/*-------------------------------------------------------------*/
/*--- end huffman.c ---*/
/*-------------------------------------------------------------*/
+184
View File
@@ -0,0 +1,184 @@
/*
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
*
* This file uses bzip2 library code which is written
* by Julian Seward <jseward@bzip.org>.
* See README and LICENSE files in bz/ directory for more information
* about bzip2 library code.
*/
#include "libbb.h"
#define CONFIG_BZIP2_FEATURE_SPEED 1
/* Speed test:
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
* Stock bzip2 is 26.4% slower than bbox bzip2 at SPEED 1
* (time to compress gcc-4.2.1.tar is 126.4% compared to bbox).
* At SPEED 5 difference is 32.7%.
*
* Test run of all CONFIG_BZIP2_FEATURE_SPEED values on a 11Mb text file:
* Size Time (3 runs)
* 0: 10828 4.145 4.146 4.148
* 1: 11097 3.845 3.860 3.861
* 2: 11392 3.763 3.767 3.768
* 3: 11892 3.722 3.724 3.727
* 4: 12740 3.637 3.640 3.644
* 5: 17273 3.497 3.509 3.509
*/
#define BZ_DEBUG 0
/* Takes ~300 bytes, detects corruption caused by bad RAM etc */
#define BZ_LIGHT_DEBUG 0
#include "bz/bzlib.h"
#include "bz/bzlib_private.h"
#include "bz/blocksort.c"
#include "bz/bzlib.c"
#include "bz/compress.c"
#include "bz/huffman.c"
/* No point in being shy and having very small buffer here.
* bzip2 internal buffers are much bigger anyway, hundreds of kbytes.
* If iobuf is several pages long, malloc() may use mmap,
* making iobuf is page aligned and thus (maybe) have one memcpy less
* if kernel is clever enough.
*/
enum {
IOBUF_SIZE = 8 * 1024
};
static uint8_t level;
/* NB: compressStream() has to return -1 on errors, not die.
* bbunpack() will correctly clean up in this case
* (delete incomplete .bz2 file)
*/
/* Returns:
* -1 on errors
* total written bytes so far otherwise
*/
static
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
{
int n, n2, ret;
strm->avail_in = rlen;
strm->next_in = rbuf;
while (1) {
strm->avail_out = IOBUF_SIZE;
strm->next_out = wbuf;
ret = BZ2_bzCompress(strm, rlen ? BZ_RUN : BZ_FINISH);
if (ret != BZ_RUN_OK /* BZ_RUNning */
&& ret != BZ_FINISH_OK /* BZ_FINISHing, but not done yet */
&& ret != BZ_STREAM_END /* BZ_FINISHed */
) {
bb_error_msg_and_die("internal error %d", ret);
}
n = IOBUF_SIZE - strm->avail_out;
if (n) {
n2 = full_write(STDOUT_FILENO, wbuf, n);
if (n2 != n) {
if (n2 >= 0)
errno = 0; /* prevent bogus error message */
bb_perror_msg(n2 >= 0 ? "short write" : "write error");
return -1;
}
}
if (ret == BZ_STREAM_END)
break;
if (rlen && strm->avail_in == 0)
break;
}
return 0 USE_DESKTOP( + strm->total_out );
}
static
USE_DESKTOP(long long) int compressStream(void)
{
USE_DESKTOP(long long) int total;
ssize_t count;
bz_stream bzs; /* it's small */
#define strm (&bzs)
char *iobuf;
#define rbuf iobuf
#define wbuf (iobuf + IOBUF_SIZE)
iobuf = xmalloc(2 * IOBUF_SIZE);
BZ2_bzCompressInit(strm, level);
while (1) {
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
if (count < 0) {
bb_perror_msg("read error");
total = -1;
break;
}
/* if count == 0, bz_write finalizes compression */
total = bz_write(strm, rbuf, count, wbuf);
if (count == 0 || total < 0)
break;
}
#if ENABLE_FEATURE_CLEAN_UP
BZ2_bzCompressEnd(strm);
free(iobuf);
#endif
return total;
}
static
char* make_new_name_bzip2(char *filename)
{
return xasprintf("%s.bz2", filename);
}
int bzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bzip2_main(int argc, char **argv)
{
unsigned opt;
/* standard bzip2 flags
* -d --decompress force decompression
* -z --compress force compression
* -k --keep keep (don't delete) input files
* -f --force overwrite existing output files
* -t --test test compressed file integrity
* -c --stdout output to standard out
* -q --quiet suppress noncritical error messages
* -v --verbose be verbose (a 2nd -v gives more)
* -s --small use less memory (at most 2500k)
* -1 .. -9 set block size to 100k .. 900k
* --fast alias for -1
* --best alias for -9
*/
opt_complementary = "s2"; /* -s means -2 (compatibility) */
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" );
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
if (opt & 0x8) // -d
return bunzip2_main(argc, argv);
opt >>= 4;
#else
opt >>= 3;
#endif
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
opt |= 0x100; /* if nothing else, assume -9 */
level = 1;
while (!(opt & 1)) {
level++;
opt >>= 1;
}
argv += optind;
option_mask32 &= 0x7; /* ignore all except -cfv */
return bbunpack(argv, make_new_name_bzip2, compressStream);
}
+1 -1
View File
@@ -22,7 +22,7 @@
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
#define CPIO_OPT_PRESERVE_MTIME 0x40
int cpio_main(int argc, char **argv);
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cpio_main(int argc, char **argv)
{
archive_handle_t *archive_handle;
+1 -1
View File
@@ -1557,7 +1557,7 @@ static void configure_package(deb_file_t *deb_file)
set_status(status_num, "installed", 3);
}
int dpkg_main(int argc, char **argv);
int dpkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dpkg_main(int argc, char **argv)
{
deb_file_t **deb_file = NULL;
+2 -2
View File
@@ -13,7 +13,7 @@
#define DPKG_DEB_OPT_EXTRACT 8
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
int dpkg_deb_main(int argc, char **argv);
int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dpkg_deb_main(int argc, char **argv)
{
archive_handle_t *ar_archive;
@@ -41,7 +41,7 @@ int dpkg_deb_main(int argc, char **argv)
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
#endif
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt = getopt32(argv, "cefXx");
if (opt & DPKG_DEB_OPT_CONTENTS) {
+7 -8
View File
@@ -686,7 +686,7 @@ static void check_match(IPos start, IPos match, int length)
if (verbose > 1) {
bb_error_msg("\\[%d,%d]", start - match, length);
do {
putc(G1.window[start++], stderr);
fputc(G1.window[start++], stderr);
} while (--length != 0);
}
}
@@ -2025,22 +2025,21 @@ USE_DESKTOP(long long) int pack_gzip(void)
return 0;
}
int gzip_main(int argc, char **argv);
int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gzip_main(int argc, char **argv)
{
unsigned opt;
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789" );
option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
if (opt & 0x8) // -d
return gunzip_main(argc, argv);
#endif
option_mask32 &= 0x7; /* ignore -q, -0..9 */
//if (opt & 0x1) // -c
//if (opt & 0x2) // -f
//if (opt & 0x4) // -v
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
if (opt & 0x8) { // -d
return gunzip_main(argc, argv);
}
#endif
argv += optind;
PTR_TO_GLOBALS = xzalloc(sizeof(struct globals) + sizeof(struct globals2))
+29 -32
View File
@@ -28,43 +28,40 @@ lib-y:= \
find_list_entry.o \
init_handle.o
GUNZIP_FILES:= check_header_gzip.o decompress_unzip.o
DPKG_FILES:= \
get_header_ar.o \
unpack_ar_archive.o \
get_header_tar.o \
filter_accept_list_reassign.o
# open_transformer uses fork(). Compile it only if absolutely necessary
lib-$(CONFIG_RPM) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
lib-$(CONFIG_CPIO) += get_header_cpio.o
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
lib-$(CONFIG_TAR) += get_header_tar.o
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
lib-$(CONFIG_CPIO) += get_header_cpio.o
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_GUNZIP) += decompress_unzip.o
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
lib-$(CONFIG_TAR) += get_header_tar.o
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_FEATURE_TAR_GZIP) += decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNZIP) += decompress_unzip.o
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
-59
View File
@@ -1,59 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include "unarchive.h" /* for external decl of check_header_gzip_or_die */
void check_header_gzip_or_die(int src_fd)
{
union {
unsigned char raw[8];
struct {
unsigned char method;
unsigned char flags;
unsigned int mtime;
unsigned char xtra_flags;
unsigned char os_flags;
} formatted;
} header;
xread(src_fd, header.raw, 8);
/* Check the compression method */
if (header.formatted.method != 8) {
bb_error_msg_and_die("unknown compression method %d",
header.formatted.method);
}
if (header.formatted.flags & 0x04) {
/* bit 2 set: extra field present */
unsigned extra_short;
extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
while (extra_short > 0) {
/* Ignore extra field */
xread_char(src_fd);
extra_short--;
}
}
/* Discard original name if any */
if (header.formatted.flags & 0x08) {
/* bit 3 set: original file name present */
while (xread_char(src_fd) != 0);
}
/* Discard file comment if any */
if (header.formatted.flags & 0x10) {
/* bit 4 set: file comment present */
while (xread_char(src_fd) != 0);
}
/* Read the header checksum */
if (header.formatted.flags & 0x02) {
xread_char(src_fd);
xread_char(src_fd);
}
}
+30 -24
View File
@@ -44,7 +44,7 @@
#define RETVAL_LAST_BLOCK (-1)
#define RETVAL_NOT_BZIP_DATA (-2)
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
#define RETVAL_SHORT_WRITE (-4)
#define RETVAL_DATA_ERROR (-5)
#define RETVAL_OUT_OF_MEMORY (-6)
#define RETVAL_OBSOLETE_INPUT (-7)
@@ -54,22 +54,27 @@
/* This is what we know about each Huffman coding group */
struct group_data {
/* We have an extra slot at the end of limit[] for a sentinal value. */
/* We have an extra slot at the end of limit[] for a sentinel value. */
int limit[MAX_HUFCODE_BITS+1], base[MAX_HUFCODE_BITS], permute[MAX_SYMBOLS];
int minLen, maxLen;
};
/* Structure holding all the housekeeping data, including IO buffers and
memory that persists between calls to bunzip */
* memory that persists between calls to bunzip
* Found the most used member:
* cat this_file.c | sed -e 's/"/ /g' -e "s/'/ /g" | xargs -n1 \
* | grep 'bd->' | sed 's/^.*bd->/bd->/' | sort | $PAGER
* and moved it (inbufBitCount) to offset 0.
*/
struct bunzip_data {
/* State for interrupting output loop */
int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
/* I/O tracking data (file handles, buffers, positions, etc.) */
unsigned inbufBitCount, inbufBits;
int in_fd, out_fd, inbufCount, inbufPos /*, outbufPos*/;
unsigned char *inbuf /*,*outbuf*/;
unsigned inbufBitCount, inbufBits;
/* State for interrupting output loop */
int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
/* The CRC values stored in the block header and calculated from the data */
uint32_t headerCRC, totalCRC, writeCRC;
@@ -80,7 +85,7 @@ struct bunzip_data {
/* For I/O error handling */
jmp_buf jmpbuf;
/* Big things go last (register-relative addressing can be larger for big offsets */
/* Big things go last (register-relative addressing can be larger for big offsets) */
uint32_t crc32Table[256];
unsigned char selectors[32768]; /* nSelectors=15 bits */
struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
@@ -91,7 +96,7 @@ struct bunzip_data {
/* Return the next nnn bits of input. All reads from the compressed input
are done through this function. All reads are big endian */
static unsigned get_bits(bunzip_data *bd, char bits_wanted)
static unsigned get_bits(bunzip_data *bd, int bits_wanted)
{
unsigned bits = 0;
@@ -121,7 +126,7 @@ static unsigned get_bits(bunzip_data *bd, char bits_wanted)
/* Grab next 8 bits of input from buffer. */
bd->inbufBits = (bd->inbufBits<<8) | bd->inbuf[bd->inbufPos++];
bd->inbufBits = (bd->inbufBits << 8) | bd->inbuf[bd->inbufPos++];
bd->inbufBitCount += 8;
}
@@ -205,7 +210,7 @@ static int get_next_block(bunzip_data *bd)
/* Get next value */
for (j = 0; get_bits(bd, 1); j++)
if (j>=groupCount) return RETVAL_DATA_ERROR;
if (j >= groupCount) return RETVAL_DATA_ERROR;
/* Decode MTF to get the next selector */
@@ -320,19 +325,20 @@ static int get_next_block(bunzip_data *bd)
t += temp[i];
base[i+1] = pp - t;
}
limit[maxLen+1] = INT_MAX; /* Sentinal value for reading next sym. */
limit[maxLen+1] = INT_MAX; /* Sentinel value for reading next sym. */
limit[maxLen] = pp + temp[maxLen] - 1;
base[minLen] = 0;
}
/* We've finished reading and digesting the block header. Now read this
block's Huffman coded symbols from the file and undo the Huffman coding
and run length encoding, saving the result into dbuf[dbufCount++]=uc */
and run length encoding, saving the result into dbuf[dbufCount++] = uc */
/* Initialize symbol occurrence counters and symbol Move To Front table */
memset(byteCount, 0, sizeof(byteCount)); /* smaller, maybe slower? */
for (i = 0; i < 256; i++) {
byteCount[i] = 0;
//byteCount[i] = 0;
mtfSymbol[i] = (unsigned char)i;
}
@@ -547,7 +553,7 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* If the output buffer is full, snapshot state and return */
if (gotcount >= len) {
bd->writePos =pos;
bd->writePos = pos;
bd->writeCurrent = current;
bd->writeCopies++;
return len;
@@ -573,8 +579,8 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
current = pos & 0xff;
pos >>= 8;
/* After 3 consecutive copies of the same byte, the 4th is a repeat
count. We count down from 4 instead
/* After 3 consecutive copies of the same byte, the 4th
* is a repeat count. We count down from 4 instead
* of counting up because testing for non-zero is faster */
if (--bd->writeRunCountdown) {
@@ -606,7 +612,7 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* If this block had a CRC error, force file level CRC error. */
if (bd->writeCRC != bd->headerCRC) {
bd->totalCRC = bd->headerCRC+1;
bd->totalCRC = bd->headerCRC + 1;
return RETVAL_LAST_BLOCK;
}
}
@@ -713,8 +719,8 @@ unpack_bz2_stream(int src_fd, int dst_fd)
for (;;) {
i = read_bunzip(bd, outbuf, IOBUF_SIZE);
if (i <= 0) break;
if (i != safe_write(dst_fd, outbuf, i)) {
i = RETVAL_UNEXPECTED_OUTPUT_EOF;
if (i != full_write(dst_fd, outbuf, i)) {
i = RETVAL_SHORT_WRITE;
break;
}
USE_DESKTOP(total_written += i;)
@@ -725,14 +731,14 @@ unpack_bz2_stream(int src_fd, int dst_fd)
if (i == RETVAL_LAST_BLOCK) {
if (bd->headerCRC != bd->totalCRC) {
bb_error_msg("data integrity error when decompressing");
bb_error_msg("CRC error");
} else {
i = RETVAL_OK;
}
} else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
bb_error_msg("compressed file ends unexpectedly");
} else if (i == RETVAL_SHORT_WRITE) {
bb_error_msg("short write");
} else {
bb_error_msg("decompression failed");
bb_error_msg("bunzip error %d", i);
}
dealloc_bunzip(bd);
free(outbuf);
File diff suppressed because it is too large. Load diff
+6 -2
View File
@@ -59,8 +59,12 @@ char get_header_tar(archive_handle_t *archive_handle)
char chksum[8]; /* 148-155 */
char typeflag; /* 156-156 */
char linkname[100]; /* 157-256 */
char magic[6]; /* 257-262 */
char version[2]; /* 263-264 */
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
/* Normally it's defined as magic[6] followed by
* version[2], but we put them together to save code.
*/
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
char gname[32]; /* 297-328 */
char devmajor[8]; /* 329-336 */
+3 -2
View File
@@ -11,9 +11,10 @@ char get_header_tar_bz2(archive_handle_t *archive_handle)
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
/* Can only do one file at a time */
return EXIT_FAILURE;
+10 -4
View File
@@ -8,21 +8,27 @@
char get_header_tar_gz(archive_handle_t *archive_handle)
{
#if BB_MMU
unsigned char magic[2];
#endif
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
/* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
* Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
* need the header. */
#if BB_MMU
xread(archive_handle->src_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("invalid gzip magic");
}
#endif
check_header_gzip_or_die(archive_handle->src_fd);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
/* Can only do one file at a time */
return EXIT_FAILURE;
+3 -2
View File
@@ -14,9 +14,10 @@ char get_header_tar_lzma(archive_handle_t * archive_handle)
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
/* Can only do one file at a time */
return EXIT_FAILURE;
+1 -2
View File
@@ -26,6 +26,5 @@ void header_verbose_list(const file_header_t *file_header)
if (file_header->link_target) {
printf(" -> %s", file_header->link_target);
}
/* putchar isnt used anywhere else i dont think */
puts("");
bb_putchar('\n');
}
+29 -5
View File
@@ -7,27 +7,51 @@
#include "unarchive.h"
/* transformer(), more than meets the eye */
/*
* On MMU machine, the transform_prog is removed by macro magic
* in include/unarchive.h. On NOMMU, transformer is removed.
*/
int open_transformer(int src_fd,
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
const char *transform_prog)
{
int fd_pipe[2];
int pid;
xpipe(fd_pipe);
#if BB_MMU
pid = fork();
if (pid == -1) {
#else
pid = vfork();
#endif
if (pid == -1)
bb_perror_msg_and_die("fork failed");
}
if (pid == 0) {
/* child process */
close(fd_pipe[0]); /* We don't wan't to read from the parent */
// FIXME: error check?
#if BB_MMU
transformer(src_fd, fd_pipe[1]);
close(fd_pipe[1]); /* Send EOF */
close(src_fd);
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd_pipe[1]); /* Send EOF */
close(src_fd);
}
exit(0);
#else
{
char *argv[4];
xmove_fd(src_fd, 0);
xmove_fd(fd_pipe[1], 1);
argv[0] = (char*)transform_prog;
argv[1] = (char*)"-cf";
argv[2] = (char*)"-";
argv[3] = NULL;
BB_EXECVP(transform_prog, argv);
bb_perror_msg_and_die("exec failed");
}
#endif
/* notreached */
}
+24 -5
View File
@@ -80,7 +80,7 @@ static void fileaction_dobackup(char *filename, int fileref);
static void fileaction_setowngrp(char *filename, int fileref);
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
int rpm_main(int argc, char **argv);
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm_main(int argc, char **argv)
{
int opt = 0, func = 0, rpm_fd, offset;
@@ -187,9 +187,15 @@ int rpm_main(int argc, char **argv)
static void extract_cpio_gz(int fd)
{
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
archive_handle_t *archive_handle;
unsigned char magic[2];
#if BB_MMU
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
enum { xformer_prog = 0 };
#else
enum { xformer = 0 };
const char *xformer_prog;
#endif
/* Initialize */
archive_handle = init_handle();
@@ -202,11 +208,19 @@ static void extract_cpio_gz(int fd)
archive_handle->offset = 0;
xread(archive_handle->src_fd, &magic, 2);
#if BB_MMU
xformer = unpack_gz_stream;
#else
xformer_prog = "gunzip";
#endif
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
if (ENABLE_FEATURE_RPM_BZ2
&& (magic[0] == 0x42) && (magic[1] == 0x5a)) {
#if BB_MMU
xformer = unpack_bz2_stream;
#else
xformer_prog = "bunzip2";
#endif
/* We can do better, need modifying unpack_bz2_stream to not require
* first 2 bytes. Not very hard to do... I mean, TODO :) */
xlseek(archive_handle->src_fd, -2, SEEK_CUR);
@@ -214,11 +228,16 @@ static void extract_cpio_gz(int fd)
bb_error_msg_and_die("no gzip"
USE_FEATURE_RPM_BZ2("/bzip")
" magic");
} else
check_header_gzip_or_die(archive_handle->src_fd);
} else {
#if !BB_MMU
/* NOMMU version of open_transformer execs an external unzipper that should
* have the file position at the start of the file */
xlseek(archive_handle->src_fd, 0, SEEK_SET);
#endif
}
xchdir("/"); /* Install RPM's to root */
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog);
archive_handle->offset = 0;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
+1 -2
View File
@@ -49,7 +49,7 @@ static void skip_header(int rpm_fd)
}
/* No getopt required */
int rpm2cpio_main(int argc, char **argv);
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm2cpio_main(int argc, char **argv)
{
struct rpm_lead lead;
@@ -79,7 +79,6 @@ int rpm2cpio_main(int argc, char **argv)
bb_error_msg_and_die("invalid gzip magic");
}
check_header_gzip_or_die(rpm_fd);
if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
bb_error_msg("error inflating");
}
+96 -78
View File
@@ -3,7 +3,7 @@
* Mini tar implementation for busybox
*
* Modified to use common extraction code used by ar, cpio, dpkg-deb, dpkg
* Glenn McGrath <bug1@iinet.net.au>
* by Glenn McGrath
*
* Note, that as of BusyBox-0.43, tar has been completely rewritten from the
* ground up. It still has remnants of the old code lying about, but it is
@@ -50,14 +50,18 @@ struct TarHeader { /* byte offset */
char chksum[8]; /* 148-155 */
char typeflag; /* 156-156 */
char linkname[NAME_SIZE]; /* 157-256 */
char magic[6]; /* 257-262 */
char version[2]; /* 263-264 */
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
/* Normally it's defined as magic[6] followed by
* version[2], but we put them together to save code.
*/
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
char gname[32]; /* 297-328 */
char devmajor[8]; /* 329-336 */
char devminor[8]; /* 337-344 */
char prefix[155]; /* 345-499 */
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
};
/*
@@ -106,7 +110,7 @@ enum TarFileType {
typedef enum TarFileType TarFileType;
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
static void addHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr,
static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
struct stat *statbuf,
const char *fileName)
{
@@ -122,7 +126,7 @@ static void addHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr,
strcpy(hlInfo->name, fileName);
}
static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr)
{
HardLinkInfo *hlInfo;
HardLinkInfo *hlInfoNext;
@@ -139,7 +143,7 @@ static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
}
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
static HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, struct stat *statbuf)
static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf)
{
while (hlInfo) {
if ((statbuf->st_ino == hlInfo->ino) && (statbuf->st_dev == hlInfo->dev))
@@ -386,35 +390,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
const char *header_name;
int inputFileFd = -1;
/*
* Check to see if we are dealing with a hard link.
* If so -
* Treat the first occurance of a given dev/inode as a file while
* treating any additional occurances as hard links. This is done
* by adding the file information to the HardLinkInfo linked list.
*/
tbInfo->hlInfo = NULL;
if (statbuf->st_nlink > 1) {
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
if (tbInfo->hlInfo == NULL)
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, fileName);
}
/* It is against the rules to archive a socket */
if (S_ISSOCK(statbuf->st_mode)) {
bb_error_msg("%s: socket ignored", fileName);
return TRUE;
}
/* It is a bad idea to store the archive we are in the process of creating,
* so check the device and inode to be sure that this particular file isn't
* the new tarball */
if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
tbInfo->statBuf.st_ino == statbuf->st_ino) {
bb_error_msg("%s: file is the archive; skipping", fileName);
return TRUE;
}
/* Strip leading '/' (must be before memorizing hardlink's name) */
header_name = fileName;
while (header_name[0] == '/') {
static smallint warned;
@@ -426,19 +402,49 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
header_name++;
}
if (header_name[0] == '\0')
return TRUE;
/* It is against the rules to archive a socket */
if (S_ISSOCK(statbuf->st_mode)) {
bb_error_msg("%s: socket ignored", fileName);
return TRUE;
}
/*
* Check to see if we are dealing with a hard link.
* If so -
* Treat the first occurance of a given dev/inode as a file while
* treating any additional occurances as hard links. This is done
* by adding the file information to the HardLinkInfo linked list.
*/
tbInfo->hlInfo = NULL;
if (statbuf->st_nlink > 1) {
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
if (tbInfo->hlInfo == NULL)
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name);
}
/* It is a bad idea to store the archive we are in the process of creating,
* so check the device and inode to be sure that this particular file isn't
* the new tarball */
if (tbInfo->statBuf.st_dev == statbuf->st_dev
&& tbInfo->statBuf.st_ino == statbuf->st_ino
) {
bb_error_msg("%s: file is the archive; skipping", fileName);
return TRUE;
}
if (exclude_file(tbInfo->excludeList, header_name))
return SKIP;
#if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (strlen(fileName) >= NAME_SIZE) {
if (strlen(header_name) >= NAME_SIZE) {
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return TRUE;
}
#endif
if (header_name[0] == '\0')
return TRUE;
if (exclude_file(tbInfo->excludeList, header_name))
return SKIP;
/* Is this a regular file? */
if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) {
/* open the file we want to archive, and make sure all is well */
@@ -504,13 +510,21 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
bb_perror_msg_and_die("cannot stat tar file");
if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) {
int gzipDataPipe[2] = { -1, -1 };
int gzipStatusPipe[2] = { -1, -1 };
// On Linux, vfork never unpauses parent early, although standard
// allows for that. Do we want to waste bytes checking for it?
#define WAIT_FOR_CHILD 0
volatile int vfork_exec_errno = 0;
#if WAIT_FOR_CHILD
struct { int rd; int wr; } gzipStatusPipe;
#endif
struct { int rd; int wr; } gzipDataPipe;
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
xpipe(gzipDataPipe);
xpipe(gzipStatusPipe);
xpipe(&gzipDataPipe.rd);
#if WAIT_FOR_CHILD
xpipe(&gzipStatusPipe.rd);
#endif
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
@@ -522,41 +536,45 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
#endif
gzipPid = vfork();
if (gzipPid < 0)
bb_perror_msg_and_die("vfork gzip");
if (gzipPid == 0) {
dup2(gzipDataPipe[0], 0);
close(gzipDataPipe[1]);
dup2(tbInfo.tarFd, 1);
close(gzipStatusPipe[0]);
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */
/* child */
xmove_fd(tbInfo.tarFd, 1);
xmove_fd(gzipDataPipe.rd, 0);
close(gzipDataPipe.wr);
#if WAIT_FOR_CHILD
close(gzipStatusPipe.rd);
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
#endif
/* exec gzip/bzip2 program/applet */
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
vfork_exec_errno = errno;
_exit(1);
}
close(gzipStatusPipe[1]);
exit(-1);
} else if (gzipPid > 0) {
close(gzipDataPipe[0]);
close(gzipStatusPipe[1]);
/* parent */
xmove_fd(gzipDataPipe.wr, tbInfo.tarFd);
close(gzipDataPipe.rd);
#if WAIT_FOR_CHILD
close(gzipStatusPipe.wr);
while (1) {
char buf;
int n;
while (1) {
char buf;
/* Wait until child execs (or fails to) */
n = full_read(gzipStatusPipe.rd, &buf, 1);
if ((n < 0) && (/*errno == EAGAIN ||*/ errno == EINTR))
continue; /* try it again */
int n = full_read(gzipStatusPipe[0], &buf, 1);
if (n == 0 && vfork_exec_errno != 0) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("cannot exec %s", zip_exec);
} else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
continue; /* try it again */
break;
}
close(gzipStatusPipe[0]);
tbInfo.tarFd = gzipDataPipe[1];
} else bb_perror_msg_and_die("vfork gzip");
}
close(gzipStatusPipe.rd);
#endif
if (vfork_exec_errno) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("cannot exec %s", zip_exec);
}
}
tbInfo.excludeList = exclude;
@@ -648,10 +666,10 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
bb_error_msg_and_die("invalid magic");
}
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
/* nothing */;
continue;
/* Can only do one file at a time */
return EXIT_FAILURE;
@@ -755,7 +773,7 @@ static const char tar_longopts[] ALIGN1 =
;
#endif
int tar_main(int argc, char **argv);
int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tar_main(int argc, char **argv)
{
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
+141 -110
View File
@@ -27,37 +27,67 @@
#include "libbb.h"
#include "unarchive.h"
#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
enum {
#if BB_BIG_ENDIAN
ZIP_FILEHEADER_MAGIC = 0x504b0304,
ZIP_CDS_MAGIC = 0x504b0102,
ZIP_CDS_END_MAGIC = 0x504b0506,
ZIP_DD_MAGIC = 0x504b0708,
#else
ZIP_FILEHEADER_MAGIC = 0x04034b50,
ZIP_CDS_MAGIC = 0x02014b50,
ZIP_CDS_END_MAGIC = 0x06054b50,
ZIP_DD_MAGIC = 0x08074b50,
#endif
};
#define ZIP_HEADER_LEN 26
typedef union {
unsigned char raw[26];
uint8_t raw[ZIP_HEADER_LEN];
struct {
unsigned short version; /* 0-1 */
unsigned short flags; /* 2-3 */
unsigned short method; /* 4-5 */
unsigned short modtime; /* 6-7 */
unsigned short moddate; /* 8-9 */
unsigned int crc32 ATTRIBUTE_PACKED; /* 10-13 */
unsigned int cmpsize ATTRIBUTE_PACKED; /* 14-17 */
unsigned int ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
unsigned short filename_len; /* 22-23 */
unsigned short extra_len; /* 24-25 */
uint16_t version; /* 0-1 */
uint16_t flags; /* 2-3 */
uint16_t method; /* 4-5 */
uint16_t modtime; /* 6-7 */
uint16_t moddate; /* 8-9 */
uint32_t crc32 ATTRIBUTE_PACKED; /* 10-13 */
uint32_t cmpsize ATTRIBUTE_PACKED; /* 14-17 */
uint32_t ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
uint16_t filename_len; /* 22-23 */
uint16_t extra_len; /* 24-25 */
} formatted ATTRIBUTE_PACKED;
} zip_header_t;
} zip_header_t; /* ATTRIBUTE_PACKED - gcc 4.2.1 doesn't like it (spews warning) */
/* Check the offset of the last element, not the length. This leniency
* allows for poor packing, whereby the overall struct may be too long,
* even though the elements are all in the right place.
*/
struct BUG_zip_header_must_be_26_bytes {
char BUG_zip_header_must_be_26_bytes[
offsetof(zip_header_t, formatted.extra_len) + 2 ==
ZIP_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS(zip_header) do { \
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
(zip_header).formatted.flags = SWAP_LE16((zip_header).formatted.flags ); \
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
(zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
(zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
(zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
(zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
(zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
(zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
} while (0)
static void unzip_skip(int fd, off_t skip)
{
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
if (errno != ESPIPE)
bb_error_msg_and_die("seek failure");
bb_copyfd_exact_size(fd, -1, skip);
}
bb_copyfd_exact_size(fd, -1, skip);
}
static void unzip_create_leading_dirs(char *fn)
static void unzip_create_leading_dirs(const char *fn)
{
/* Create all leading directories */
char *name = xstrdup(fn);
@@ -67,7 +97,7 @@ static void unzip_create_leading_dirs(char *fn)
free(name);
}
static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
{
if (zip_header->formatted.method == 0) {
/* Method 0 - stored (not compressed) */
@@ -77,64 +107,71 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
} else {
/* Method 8 - inflate */
inflate_unzip_result res;
/* err = */ inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd);
// we should check for -1 error return
if (inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd) < 0)
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
bb_error_msg("invalid compressed data--%s error", "crc");
return 1;
bb_error_msg_and_die("crc error");
}
/* Validate decompression - size */
if (zip_header->formatted.ucmpsize != res.bytes_out) {
bb_error_msg("invalid compressed data--%s error", "length");
return 1;
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
}
}
return 0;
}
int unzip_main(int argc, char **argv);
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unzip_main(int argc, char **argv)
{
enum { O_PROMPT, O_NEVER, O_ALWAYS };
zip_header_t zip_header;
enum {v_silent, v_normal, v_list} verbosity = v_normal;
enum {o_prompt, o_never, o_always} overwrite = o_prompt;
unsigned int total_size = 0;
unsigned int total_entries = 0;
int src_fd = -1, dst_fd = -1;
char *src_fn = NULL, *dst_fn = NULL;
smallint verbose = 1;
smallint listing = 0;
smallint overwrite = O_PROMPT;
unsigned total_size;
unsigned total_entries;
int src_fd = -1;
int dst_fd = -1;
char *src_fn = NULL;
char *dst_fn = NULL;
llist_t *zaccept = NULL;
llist_t *zreject = NULL;
char *base_dir = NULL;
int failed, i, opt, opt_range = 0, list_header_done = 0;
char key_buf[512];
int i, opt;
int opt_range = 0;
char key_buf[80];
struct stat stat_buf;
/* '-' makes getopt return 1 for non-options */
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
switch (opt_range) {
case 0: /* Options */
switch (opt) {
case 'l': /* List */
verbosity = v_list;
listing = 1;
break;
case 'n': /* Never overwrite existing files */
overwrite = o_never;
overwrite = O_NEVER;
break;
case 'o': /* Always overwrite existing files */
overwrite = o_always;
overwrite = O_ALWAYS;
break;
case 'p': /* Extract files to stdout and fall through to set verbosity */
dst_fd = STDOUT_FILENO;
case 'q': /* Be quiet */
verbosity = (verbosity == v_normal) ? v_silent : verbosity;
verbose = 0;
break;
case 1 : /* The zip file */
src_fn = xmalloc(strlen(optarg)+4);
case 1: /* The zip file */
/* +5: space for ".zip" and NUL */
src_fn = xmalloc(strlen(optarg) + 5);
strcpy(src_fn, optarg);
opt_range++;
break;
@@ -148,31 +185,30 @@ int unzip_main(int argc, char **argv)
case 1: /* Include files */
if (opt == 1) {
llist_add_to(&zaccept, optarg);
} else if (opt == 'd') {
break;
}
if (opt == 'd') {
base_dir = optarg;
opt_range += 2;
} else if (opt == 'x') {
opt_range++;
} else {
bb_show_usage();
break;
}
break;
if (opt == 'x') {
opt_range++;
break;
}
bb_show_usage();
case 2 : /* Exclude files */
if (opt == 1) {
llist_add_to(&zreject, optarg);
} else if (opt == 'd') { /* Extract to base directory */
break;
}
if (opt == 'd') { /* Extract to base directory */
base_dir = optarg;
opt_range++;
} else {
bb_show_usage();
break;
}
break;
/* fall through */
default:
bb_show_usage();
@@ -187,17 +223,19 @@ int unzip_main(int argc, char **argv)
if (LONE_DASH(src_fn)) {
src_fd = STDIN_FILENO;
/* Cannot use prompt mode since zip data is arriving on STDIN */
overwrite = (overwrite == o_prompt) ? o_never : overwrite;
if (overwrite == O_PROMPT)
overwrite = O_NEVER;
} else {
static const char *const extn[] = {"", ".zip", ".ZIP"};
static const char extn[][5] = {"", ".zip", ".ZIP"};
int orig_src_fn_len = strlen(src_fn);
for (i = 0; (i < 3) && (src_fd == -1); i++) {
strcpy(src_fn + orig_src_fn_len, extn[i]);
src_fd = open(src_fn, O_RDONLY);
}
if (src_fd == -1) {
src_fn[orig_src_fn_len] = '\0';
bb_error_msg_and_die("cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
}
}
@@ -205,36 +243,31 @@ int unzip_main(int argc, char **argv)
if (base_dir)
xchdir(base_dir);
if (verbosity != v_silent)
if (verbose) {
printf("Archive: %s\n", src_fn);
if (listing){
puts(" Length Date Time Name\n"
" -------- ---- ---- ----");
}
}
failed = 0;
total_size = 0;
total_entries = 0;
while (1) {
unsigned int magic;
uint32_t magic;
/* Check magic number */
xread(src_fd, &magic, 4);
if (magic == ZIP_CDS_MAGIC) {
if (magic == ZIP_CDS_MAGIC)
break;
} else if (magic != ZIP_FILEHEADER_MAGIC) {
if (magic != ZIP_FILEHEADER_MAGIC)
bb_error_msg_and_die("invalid zip magic %08X", magic);
}
/* Read the file header */
xread(src_fd, zip_header.raw, 26);
zip_header.formatted.version = SWAP_LE32(zip_header.formatted.version);
zip_header.formatted.flags = SWAP_LE32(zip_header.formatted.flags);
zip_header.formatted.method = SWAP_LE32(zip_header.formatted.method);
zip_header.formatted.modtime = SWAP_LE32(zip_header.formatted.modtime);
zip_header.formatted.moddate = SWAP_LE32(zip_header.formatted.moddate);
zip_header.formatted.crc32 = SWAP_LE32(zip_header.formatted.crc32);
zip_header.formatted.cmpsize = SWAP_LE32(zip_header.formatted.cmpsize);
zip_header.formatted.ucmpsize = SWAP_LE32(zip_header.formatted.ucmpsize);
zip_header.formatted.filename_len = SWAP_LE32(zip_header.formatted.filename_len);
zip_header.formatted.extra_len = SWAP_LE32(zip_header.formatted.extra_len);
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS(zip_header);
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
bb_error_msg_and_die("unsupported compression method %d", zip_header.formatted.method);
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
}
/* Read filename */
@@ -245,23 +278,17 @@ int unzip_main(int argc, char **argv)
/* Skip extra header bytes */
unzip_skip(src_fd, zip_header.formatted.extra_len);
if ((verbosity == v_list) && !list_header_done){
puts(" Length Date Time Name\n"
" -------- ---- ---- ----");
list_header_done = 1;
}
/* Filter zip entries */
if (find_list_entry(zreject, dst_fn) ||
(zaccept && !find_list_entry(zaccept, dst_fn))) { /* Skip entry */
if (find_list_entry(zreject, dst_fn)
|| (zaccept && !find_list_entry(zaccept, dst_fn))
) { /* Skip entry */
i = 'n';
} else { /* Extract entry */
total_size += zip_header.formatted.ucmpsize;
if (verbosity == v_list) { /* List entry */
unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
if (listing) { /* List entry */
if (verbose) {
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
zip_header.formatted.ucmpsize,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
@@ -269,7 +296,12 @@ int unzip_main(int argc, char **argv)
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
dst_fn);
total_entries++;
total_size += zip_header.formatted.ucmpsize;
total_entries++;
} else {
/* short listing -- filenames only */
puts(dst_fn);
}
i = 'n';
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
i = -1;
@@ -278,7 +310,7 @@ int unzip_main(int argc, char **argv)
if (errno != ENOENT) {
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
}
if (verbosity == v_normal) {
if (verbose) {
printf(" creating: %s\n", dst_fn);
}
unzip_create_leading_dirs(dst_fn);
@@ -300,14 +332,14 @@ int unzip_main(int argc, char **argv)
}
i = 'y';
} else { /* File already exists */
if (overwrite == o_never) {
if (overwrite == O_NEVER) {
i = 'n';
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
if (overwrite == o_always) {
if (overwrite == O_ALWAYS) {
i = 'y';
} else {
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
if (!fgets(key_buf, 512, stdin)) {
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
bb_perror_msg_and_die("cannot read input");
}
i = key_buf[0];
@@ -321,17 +353,15 @@ int unzip_main(int argc, char **argv)
switch (i) {
case 'A':
overwrite = o_always;
overwrite = O_ALWAYS;
case 'y': /* Open file and fall into unzip */
unzip_create_leading_dirs(dst_fn);
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
case -1: /* Unzip */
if (verbosity == v_normal) {
if (verbose) {
printf(" inflating: %s\n", dst_fn);
}
if (unzip_extract(&zip_header, src_fd, dst_fd)) {
failed = 1;
}
unzip_extract(&zip_header, src_fd, dst_fd);
if (dst_fd != STDOUT_FILENO) {
/* closing STDOUT is potentially bad for future business */
close(dst_fd);
@@ -339,7 +369,7 @@ int unzip_main(int argc, char **argv)
break;
case 'N':
overwrite = o_never;
overwrite = O_NEVER;
case 'n':
/* Skip entry data */
unzip_skip(src_fd, zip_header.formatted.cmpsize);
@@ -348,7 +378,7 @@ int unzip_main(int argc, char **argv)
case 'r':
/* Prompt for new name */
printf("new name: ");
if (!fgets(key_buf, 512, stdin)) {
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
bb_perror_msg_and_die("cannot read input");
}
free(dst_fn);
@@ -368,10 +398,11 @@ int unzip_main(int argc, char **argv)
}
}
if (verbosity == v_list) {
if (listing && verbose) {
printf(" -------- -------\n"
"%9d %d files\n", total_size, total_entries);
"%9d %d files\n",
total_size, total_entries);
}
return failed;
return 0;
}
+6
View File
@@ -31,6 +31,12 @@ config DUMPKMAP
This program dumps the kernel's keyboard translation table to
stdout, in binary format. You can then use loadkmap to load it.
config KBD_MODE
bool "kbd_mode"
default n
help
This program reports and sets keyboard mode.
config LOADFONT
bool "loadfont"
default n
+1
View File
@@ -10,6 +10,7 @@ lib-$(CONFIG_CLEAR) += clear.o
lib-$(CONFIG_DEALLOCVT) += deallocvt.o
lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
lib-$(CONFIG_SETCONSOLE) += setconsole.o
lib-$(CONFIG_KBD_MODE) += kbd_mode.o
lib-$(CONFIG_LOADFONT) += loadfont.o
lib-$(CONFIG_LOADKMAP) += loadkmap.o
lib-$(CONFIG_OPENVT) += openvt.o
+2 -2
View File
@@ -15,7 +15,7 @@ enum {
VT_WAITACTIVE = 0x5607 /* wait for vt active */
};
int chvt_main(int argc, char **argv);
int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chvt_main(int argc, char **argv)
{
int fd, num;
@@ -26,7 +26,7 @@ int chvt_main(int argc, char **argv)
fd = get_console_fd();
num = xatou_range(argv[1], 1, 63);
/* double cast suppresses "cast to ptr from int of different size */
/* double cast suppresses "cast to ptr from int of different size" */
xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num);
xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num);
return EXIT_SUCCESS;
+1 -1
View File
@@ -12,7 +12,7 @@
#include "libbb.h"
int clear_main(int argc, char **argv);
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int clear_main(int argc, char **argv)
{
return printf("\033[H\033[J") != 6;
+2 -2
View File
@@ -15,7 +15,7 @@
/* From <linux/vt.h> */
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
int deallocvt_main(int argc, char **argv);
int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int deallocvt_main(int argc, char **argv)
{
/* num = 0 deallocate all unused consoles */
@@ -31,7 +31,7 @@ int deallocvt_main(int argc, char **argv)
bb_show_usage();
}
/* double cast suppresses "cast to ptr from int of different size */
/* double cast suppresses "cast to ptr from int of different size" */
xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -22,7 +22,7 @@ struct kbentry {
#define NR_KEYS 128
#define MAX_NR_KEYMAPS 256
int dumpkmap_main(int argc, char **argv);
int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dumpkmap_main(int argc, char **argv)
{
struct kbentry ke;
+71
View File
@@ -0,0 +1,71 @@
/* vi: set sw=4 ts=4: */
/*
* Mini loadkmap implementation for busybox
*
* Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
* written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
* console-utils v0.2.3, licensed under GNU GPLv2
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
*/
#include <getopt.h>
#include "libbb.h"
#include <linux/kd.h>
int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int kbd_mode_main(int argc, char **argv)
{
static const char opts[] = "saku";
const char *opt = argv[1];
const char *p;
int fd;
fd = get_console_fd();
if (fd < 0) /* get_console_fd() already complained */
return EXIT_FAILURE;
if (opt == NULL) {
/* No arg */
const char *msg = "unknown";
int mode;
ioctl(fd, KDGKBMODE, &mode);
switch(mode) {
case K_RAW:
msg = "raw (scancode)";
break;
case K_XLATE:
msg = "default (ASCII)";
break;
case K_MEDIUMRAW:
msg = "mediumraw (keycode)";
break;
case K_UNICODE:
msg = "Unicode (UTF-8)";
break;
}
printf("The keyboard is in %s mode\n", msg);
}
else if (argc > 2 /* more than 1 arg */
|| *opt != '-' /* not an option */
|| (p = strchr(opts, opt[1])) == NULL /* not an option we expect */
|| opt[2] != '\0' /* more than one option char */
) {
bb_show_usage();
/* return EXIT_FAILURE; - not reached */
}
else {
#if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3
#error kbd_mode must be changed
#endif
/* The options are in the order of the various K_xxx */
ioctl(fd, KDSKBMODE, p - opts);
}
if (ENABLE_FEATURE_CLEAN_UP)
close(fd);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -166,7 +166,7 @@ static void loadnewfont(int fd)
do_loadfont(fd, inbuf + offset, unit, 256);
}
int loadfont_main(int argc, char **argv);
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadfont_main(int argc, char **argv)
{
int fd;
+1 -1
View File
@@ -25,7 +25,7 @@ struct kbentry {
#define NR_KEYS 128
#define MAX_NR_KEYMAPS 256
int loadkmap_main(int argc, char **argv);
int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadkmap_main(int argc, char **argv)
{
struct kbentry ke;
+1 -1
View File
@@ -12,7 +12,7 @@
#include "libbb.h"
int openvt_main(int argc, char **argv);
int openvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int openvt_main(int argc, char **argv)
{
char vtname[sizeof(VC_FORMAT) + 2];
+1 -1
View File
@@ -12,7 +12,7 @@
#include "libbb.h"
int reset_main(int argc, char **argv);
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc, char **argv)
{
if (isatty(1)) {
+1 -1
View File
@@ -20,7 +20,7 @@ onintr(int sig ATTRIBUTE_UNUSED)
exit(1);
}
int resize_main(int argc, char **argv);
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int resize_main(int argc, char **argv)
{
struct termios new;
+1 -1
View File
@@ -18,7 +18,7 @@ static const char setconsole_longopts[] ALIGN1 =
#define OPT_SETCONS_RESET 1
int setconsole_main(int argc, char **argv);
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setconsole_main(int argc, char **argv)
{
unsigned long flags;
+2 -2
View File
@@ -20,8 +20,8 @@ enum {
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
};
int setkeycodes_main(int argc, char** argv);
int setkeycodes_main(int argc, char** argv)
int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setkeycodes_main(int argc, char **argv)
{
int fd, sc;
struct kbkeycode a;
+1 -1
View File
@@ -11,7 +11,7 @@
#include "libbb.h"
int setlogcons_main(int argc, char **argv);
int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setlogcons_main(int argc, char **argv)
{
struct {
+7
View File
@@ -135,6 +135,13 @@ config DF
df reports the amount of disk space used and available
on filesystems.
config FEATURE_DF_INODE
bool "Enable -i (inode information)"
default n
depends on DF
help
This option enables support for df -i.
config DIRNAME
bool "dirname"
default n
+3 -2
View File
@@ -24,7 +24,7 @@
/* This is a NOFORK applet. Be very careful! */
int basename_main(int argc, char **argv);
int basename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int basename_main(int argc, char **argv)
{
size_t m, n;
@@ -34,7 +34,8 @@ int basename_main(int argc, char **argv)
bb_show_usage();
}
s = bb_get_last_path_component(*++argv);
/* It should strip slash: /abc/def/ -> def */
s = bb_get_last_path_component_strip(*++argv);
if (*++argv) {
n = strlen(*argv);
+2 -2
View File
@@ -75,7 +75,7 @@ static char *build_row(char *p, unsigned *dp);
#define J_WEEK_LEN (WEEK_LEN + 7)
#define HEAD_SEP 2 /* spaces between day headings */
int cal_main(int argc, char **argv);
int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cal_main(int argc, char **argv)
{
struct tm *local_time;
@@ -167,7 +167,7 @@ int cal_main(int argc, char **argv)
if (!julian) {
printf("%*s%s", HEAD_SEP, "", day_headings);
}
putchar('\n');
bb_putchar('\n');
for (row = 0; row < (6*7); row += 7) {
for (which_cal = 0; which_cal < 3-julian; which_cal++) {
dp = days[month + which_cal] + row;
+1 -1
View File
@@ -43,7 +43,7 @@ int bb_cat(char **argv)
return retval;
}
int cat_main(int argc, char **argv);
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cat_main(int argc, char **argv)
{
getopt32(argv, "u");
+3 -3
View File
@@ -12,7 +12,7 @@
#include "libbb.h"
int catv_main(int argc, char **argv);
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int catv_main(int argc, char **argv)
{
int retval = EXIT_SUCCESS;
@@ -62,13 +62,13 @@ int catv_main(int argc, char **argv)
if (c < 32) {
if (c == 10) {
if (flags & CATV_OPT_e)
putchar('$');
bb_putchar('$');
} else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
printf("^%c", c+'@');
continue;
}
}
putchar(c);
bb_putchar(c);
}
}
if (ENABLE_FEATURE_CLEAN_UP && fd)
+1 -1
View File
@@ -16,7 +16,7 @@
/* This is a NOEXEC applet. Be very careful! */
int chgrp_main(int argc, char **argv);
int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chgrp_main(int argc, char **argv)
{
/* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
+2 -2
View File
@@ -63,11 +63,11 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
}
err:
if (!OPT_QUIET)
bb_perror_msg("%s", fileName);
bb_simple_perror_msg(fileName);
return FALSE;
}
int chmod_main(int argc, char **argv);
int chmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chmod_main(int argc, char **argv)
{
int retval = EXIT_SUCCESS;
+2 -2
View File
@@ -57,11 +57,11 @@ static int fileAction(const char *fileName, struct stat *statbuf,
return TRUE;
}
if (!OPT_QUIET)
bb_perror_msg("%s", fileName); /* A filename can have % in it... */
bb_simple_perror_msg(fileName); /* A filename can have % in it... */
return FALSE;
}
int chown_main(int argc, char **argv);
int chown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chown_main(int argc, char **argv)
{
int retval = EXIT_SUCCESS;
+1 -1
View File
@@ -11,7 +11,7 @@
#include "libbb.h"
int chroot_main(int argc, char **argv);
int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chroot_main(int argc, char **argv)
{
if (argc < 2) {
+1 -1
View File
@@ -8,7 +8,7 @@
#include "libbb.h"
int cksum_main(int argc, char **argv);
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cksum_main(int argc, char **argv)
{
uint32_t *crc32_table = crc32_filltable(NULL, 1);
+1 -1
View File
@@ -35,7 +35,7 @@ static void writeline(char *line, int class, int flags)
fputs(line, stdout);
}
int comm_main(int argc, char **argv);
int comm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int comm_main(int argc, char **argv)
{
#define LINE_LEN 100
+18 -16
View File
@@ -21,7 +21,7 @@
/* This is a NOEXEC applet. Be very careful! */
int cp_main(int argc, char **argv);
int cp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cp_main(int argc, char **argv)
{
struct stat source_stat;
@@ -40,12 +40,17 @@ int cp_main(int argc, char **argv)
OPT_L = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
};
// Need at least two arguments
// Soft- and hardlinking don't mix
// -P and -d are the same (-P is POSIX, -d is GNU)
// -r and -R are the same
// -R (and therefore -r) switches on -d (coreutils does this)
// -a = -pdR
opt_complementary = "l--s:s--l:Pd:rR:apdR";
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHL");
argc -= optind;
argv += optind;
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
/* Default behavior of cp is to dereference, so we don't have to do
* anything special when we are given -L.
* The behavior of -H is *almost* like -L, but not quite, so let's
@@ -60,17 +65,9 @@ int cp_main(int argc, char **argv)
}
#endif
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
if (optind + 2 > argc) {
bb_show_usage();
}
last = argv[argc - 1];
argv += optind;
/* If there are only two arguments and... */
if (optind + 2 == argc) {
if (argc == 2) {
s_flags = cp_mv_stat2(*argv, &source_stat,
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
if (s_flags < 0)
@@ -85,19 +82,24 @@ int cp_main(int argc, char **argv)
((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
) {
/* ...do a simple copy. */
dest = xstrdup(last);
goto DO_COPY; /* Note: optind+2==argc implies argv[1]==last below. */
dest = last;
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
}
do {
dest = concat_path_file(last, bb_get_last_path_component(*argv));
while (1) {
dest = concat_path_file(last, bb_get_last_path_component_strip(*argv));
DO_COPY:
if (copy_file(*argv, dest, flags) < 0) {
status = 1;
}
if (*++argv == last) {
/* possibly leaking dest... */
break;
}
free((void*)dest);
} while (*++argv != last);
}
/* Exit. We are NOEXEC, not NOFORK. We do exit at the end of main() */
return status;
}
+38 -40
View File
@@ -16,13 +16,11 @@
/* option vars */
static const char optstring[] ALIGN1 = "b:c:f:d:sn";
#define CUT_OPT_BYTE_FLGS (1<<0)
#define CUT_OPT_CHAR_FLGS (1<<1)
#define CUT_OPT_FIELDS_FLGS (1<<2)
#define CUT_OPT_DELIM_FLGS (1<<3)
#define CUT_OPT_SUPPRESS_FLGS (1<<4)
static char delim = '\t'; /* delimiter, default is tab */
#define CUT_OPT_BYTE_FLGS (1 << 0)
#define CUT_OPT_CHAR_FLGS (1 << 1)
#define CUT_OPT_FIELDS_FLGS (1 << 2)
#define CUT_OPT_DELIM_FLGS (1 << 3)
#define CUT_OPT_SUPPRESS_FLGS (1 << 4)
struct cut_list {
int startpos;
@@ -47,7 +45,7 @@ static int cmpfunc(const void *a, const void *b)
}
static void cut_file(FILE * file)
static void cut_file(FILE *file, char delim)
{
char *line = NULL;
unsigned int linenum = 0; /* keep these zero-based to be consistent */
@@ -163,11 +161,10 @@ static void cut_file(FILE * file)
}
}
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
int cut_main(int argc, char **argv);
int cut_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cut_main(int argc, char **argv)
{
char delim = '\t'; /* delimiter, default is tab */
char *sopt, *ltok;
opt_complementary = "b--bcf:c--bcf:f--bcf";
@@ -178,7 +175,7 @@ int cut_main(int argc, char **argv)
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
if (strlen(ltok) > 1) {
if (ltok[0] && ltok[1]) { /* more than 1 char? */
bb_error_msg_and_die("the delimiter must be a single character");
}
delim = ltok[0];
@@ -186,6 +183,8 @@ int cut_main(int argc, char **argv)
/* non-field (char or byte) cutting has some special handling */
if (!(option_mask32 & CUT_OPT_FIELDS_FLGS)) {
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS) {
bb_error_msg_and_die
("suppressing non-delimited lines makes sense%s",
@@ -210,15 +209,12 @@ int cut_main(int argc, char **argv)
while ((ltok = strsep(&sopt, ",")) != NULL) {
/* it's actually legal to pass an empty list */
if (strlen(ltok) == 0)
if (!ltok[0])
continue;
/* get the start pos */
ntok = strsep(&ltok, "-");
if (ntok == NULL) {
bb_error_msg
("internal error: ntok is null for start pos!?\n");
} else if (strlen(ntok) == 0) {
if (!ntok[0]) {
s = BOL;
} else {
s = xatoi_u(ntok);
@@ -229,13 +225,12 @@ int cut_main(int argc, char **argv)
}
/* get the end pos */
ntok = strsep(&ltok, "-");
if (ntok == NULL) {
if (ltok == NULL) {
e = NON_RANGE;
} else if (strlen(ntok) == 0) {
} else if (!ltok[0]) {
e = EOL;
} else {
e = xatoi_u(ntok);
e = xatoi_u(ltok);
/* if the user specified and end position of 0, that means "til the
* end of the line */
if (e == 0)
@@ -245,11 +240,6 @@ int cut_main(int argc, char **argv)
e = NON_RANGE;
}
/* if there's something left to tokenize, the user passed
* an invalid list */
if (ltok)
bb_error_msg_and_die("invalid byte or field list");
/* add the new list */
cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
cut_lists[nlists-1].startpos = s;
@@ -266,23 +256,31 @@ int cut_main(int argc, char **argv)
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
}
/* argv[0..argc-1] should be names of file to process. If no
* files were specified or '-' was specified, take input from stdin.
* Otherwise, we process all the files specified. */
if (argv[0] == NULL || LONE_DASH(argv[0])) {
cut_file(stdin);
} else {
FILE *file;
{
int retval = EXIT_SUCCESS;
FILE *file = stdin;
if (!*argv) {
argv--;
goto jump_in;
}
do {
file = fopen_or_warn(argv[0], "r");
if (file) {
cut_file(file);
fclose(file);
file = stdin;
if (NOT_LONE_DASH(*argv))
file = fopen_or_warn(*argv, "r");
if (!file) {
retval = EXIT_FAILURE;
continue;
}
jump_in:
cut_file(file, delim);
if (NOT_LONE_DASH(*argv))
fclose(file);
} while (*++argv);
if (ENABLE_FEATURE_CLEAN_UP)
free(cut_lists);
fflush_stdout_and_exit(retval);
}
if (ENABLE_FEATURE_CLEAN_UP)
free(cut_lists);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -38,7 +38,7 @@ static void maybe_set_utc(int opt)
putenv((char*)"TZ=UTC0");
}
int date_main(int argc, char **argv);
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int date_main(int argc, char **argv)
{
time_t tm;
+25 -22
View File
@@ -14,6 +14,11 @@
/* This is a NOEXEC applet. Be very careful! */
enum {
ifd = STDIN_FILENO,
ofd = STDOUT_FILENO,
};
static const struct suffix_mult dd_suffixes[] = {
{ "c", 1 },
{ "w", 2 },
@@ -45,19 +50,19 @@ static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
G.out_full, G.out_part);
}
static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
static ssize_t full_write_or_warn(const void *buf, size_t len,
const char *const filename)
{
ssize_t n = full_write(fd, buf, len);
ssize_t n = full_write(ofd, buf, len);
if (n < 0)
bb_perror_msg("writing '%s'", filename);
return n;
}
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
static bool write_and_stats(const void *buf, size_t len, size_t obs,
const char *filename)
{
ssize_t n = full_write_or_warn(fd, buf, len, filename);
ssize_t n = full_write_or_warn(buf, len, filename);
if (n < 0)
return 1;
if (n == obs)
@@ -73,7 +78,7 @@ static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
#define XATOU_SFX xatoul_sfx
#endif
int dd_main(int argc, char **argv);
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc, char **argv)
{
enum {
@@ -105,13 +110,13 @@ int dd_main(int argc, char **argv)
OP_conv_noerror,
#endif
};
int exitcode = EXIT_FAILURE;
size_t ibs = 512, obs = 512;
ssize_t n, w;
char *ibuf, *obuf;
/* And these are all zeroed at once! */
struct {
int flags;
int ifd, ofd;
size_t oc;
off_t count;
off_t seek, skip;
@@ -121,8 +126,6 @@ int dd_main(int argc, char **argv)
#endif
} Z;
#define flags (Z.flags )
#define ifd (Z.ifd )
#define ofd (Z.ofd )
#define oc (Z.oc )
#define count (Z.count )
#define seek (Z.seek )
@@ -133,6 +136,7 @@ int dd_main(int argc, char **argv)
memset(&Z, 0, sizeof(Z));
INIT_G();
//fflush(NULL); - is this needed because of NOEXEC?
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
sigact.sa_handler = dd_output_status;
@@ -227,9 +231,8 @@ int dd_main(int argc, char **argv)
obuf = xmalloc(obs);
}
if (infile != NULL)
ifd = xopen(infile, O_RDONLY);
xmove_fd(xopen(infile, O_RDONLY), ifd);
else {
/* ifd = STDIN_FILENO; - it's zero and it's already there */
infile = bb_msg_standard_input;
}
if (outfile != NULL) {
@@ -238,7 +241,7 @@ int dd_main(int argc, char **argv)
if (!seek && !(flags & FLAG_NOTRUNC))
oflag |= O_TRUNC;
ofd = xopen(outfile, oflag);
xmove_fd(xopen(outfile, oflag), ofd);
if (seek && !(flags & FLAG_NOTRUNC)) {
if (ftruncate(ofd, seek * obs) < 0) {
@@ -250,7 +253,6 @@ int dd_main(int argc, char **argv)
}
}
} else {
ofd = STDOUT_FILENO;
outfile = bb_msg_standard_output;
}
if (skip) {
@@ -276,11 +278,10 @@ int dd_main(int argc, char **argv)
if (n == 0)
break;
if (n < 0) {
if (flags & FLAG_NOERROR) {
n = ibs;
bb_perror_msg("%s", infile);
} else
if (!(flags & FLAG_NOERROR))
goto die_infile;
n = ibs;
bb_simple_perror_msg(infile);
}
if ((size_t)n == ibs)
G.in_full++;
@@ -303,32 +304,34 @@ int dd_main(int argc, char **argv)
tmp += d;
oc += d;
if (oc == obs) {
if (write_and_stats(ofd, obuf, obs, obs, outfile))
if (write_and_stats(obuf, obs, obs, outfile))
goto out_status;
oc = 0;
}
}
} else if (write_and_stats(ofd, ibuf, n, obs, outfile))
} else if (write_and_stats(ibuf, n, obs, outfile))
goto out_status;
}
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
w = full_write_or_warn(ofd, obuf, oc, outfile);
w = full_write_or_warn(obuf, oc, outfile);
if (w < 0) goto out_status;
if (w > 0)
G.out_part++;
}
if (close(ifd) < 0) {
die_infile:
bb_perror_msg_and_die("%s", infile);
bb_simple_perror_msg_and_die(infile);
}
if (close(ofd) < 0) {
die_outfile:
bb_perror_msg_and_die("%s", outfile);
bb_simple_perror_msg_and_die(outfile);
}
exitcode = EXIT_SUCCESS;
out_status:
dd_output_status(0);
return EXIT_SUCCESS;
return exitcode;
}
+34 -10
View File
@@ -29,7 +29,7 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
}
#endif
int df_main(int argc, char **argv);
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int df_main(int argc, char **argv)
{
unsigned long blocks_used;
@@ -45,23 +45,32 @@ int df_main(int argc, char **argv)
/* default display is kilobytes */
const char *disp_units_hdr = "1k-blocks";
enum {
OPT_ALL = (1 << 0),
OPT_INODE = (ENABLE_FEATURE_HUMAN_READABLE ? (1 << 4) : (1 << 2))
* ENABLE_FEATURE_DF_INODE
};
#if ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk";
opt = getopt32(argv, "hmk");
if (opt & 1) {
opt = getopt32(argv, "ahmk" USE_FEATURE_DF_INODE("i"));
if (opt & (1 << 1)) { // -h
df_disp_hr = 0;
disp_units_hdr = " Size";
}
if (opt & 2) {
if (opt & (1 << 2)) { // -m
df_disp_hr = 1024*1024;
disp_units_hdr = "1M-blocks";
}
if (opt & OPT_INODE) {
disp_units_hdr = " Inodes";
}
#else
opt = getopt32(argv, "k");
opt = getopt32(argv, "ak" USE_FEATURE_DF_INODE("i"));
#endif
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
"", disp_units_hdr);
printf("Filesystem %-15sUsed Available Use%% Mounted on\n",
disp_units_hdr);
mount_table = NULL;
argv += optind;
@@ -100,11 +109,20 @@ int df_main(int argc, char **argv)
mount_point = mount_entry->mnt_dir;
if (statfs(mount_point, &s) != 0) {
bb_perror_msg("%s", mount_point);
bb_simple_perror_msg(mount_point);
goto SET_ERROR;
}
if ((s.f_blocks > 0) || !mount_table){
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
if (opt & OPT_INODE) {
s.f_blocks = s.f_files;
s.f_bavail = s.f_bfree = s.f_ffree;
s.f_bsize = 1;
#if ENABLE_FEATURE_HUMAN_READABLE
if (df_disp_hr)
df_disp_hr = 1;
#endif
}
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = 0;
if (blocks_used + s.f_bavail) {
@@ -113,9 +131,14 @@ int df_main(int argc, char **argv)
) / (blocks_used + s.f_bavail);
}
#ifdef WHY_IT_SHOULD_BE_HIDDEN
if (strcmp(device, "rootfs") == 0) {
continue;
} else if (strcmp(device, "/dev/root") == 0) {
}
#endif
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
/* ... and also this is the only user of find_block_device */
if (strcmp(device, "/dev/root") == 0) {
/* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */
device = find_block_device("/");
@@ -123,6 +146,7 @@ int df_main(int argc, char **argv)
goto SET_ERROR;
}
}
#endif
if (printf("\n%-20s" + 1, device) > 20)
printf("\n%-20s", "");
+1 -1
View File
@@ -14,7 +14,7 @@
/* This is a NOFORK applet. Be very careful! */
int dirname_main(int argc, char **argv);
int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dirname_main(int argc, char **argv)
{
if (argc != 2) {
+1 -1
View File
@@ -78,7 +78,7 @@ static int convert(char *fn, int conv_type)
return 0;
}
int dos2unix_main(int argc, char **argv);
int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dos2unix_main(int argc, char **argv)
{
int o, conv_type;
+67 -67
View File
@@ -25,37 +25,34 @@
#include "libbb.h"
struct globals {
#if ENABLE_FEATURE_HUMAN_READABLE
# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned long disp_hr = 1024;
# else
static unsigned long disp_hr = 512;
# endif
#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned disp_k = 1;
unsigned long disp_hr;
#else
static unsigned disp_k; /* bss inits to 0 */
unsigned disp_k;
#endif
static int max_print_depth = INT_MAX;
static nlink_t count_hardlinks = 1;
int max_print_depth;
nlink_t count_hardlinks;
static int status;
static int print_files;
static int slink_depth;
static int du_depth;
static int one_file_system;
static dev_t dir_dev;
bool status;
bool one_file_system;
int print_files;
int slink_depth;
int du_depth;
dev_t dir_dev;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
static void print(long size, const char *const filename)
static void print(unsigned long size, const char *filename)
{
/* TODO - May not want to defer error checking here. */
#if ENABLE_FEATURE_HUMAN_READABLE
printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr),
filename);
#else
if (disp_k) {
if (G.disp_k) {
size++;
size >>= 1;
}
@@ -64,21 +61,21 @@ static void print(long size, const char *const filename)
}
/* tiny recursive du */
static long du(const char *const filename)
static unsigned long du(const char *filename)
{
struct stat statbuf;
long sum;
unsigned long sum;
if (lstat(filename, &statbuf) != 0) {
bb_perror_msg("%s", filename);
status = EXIT_FAILURE;
bb_simple_perror_msg(filename);
G.status = EXIT_FAILURE;
return 0;
}
if (one_file_system) {
if (du_depth == 0) {
dir_dev = statbuf.st_dev;
} else if (dir_dev != statbuf.st_dev) {
if (G.one_file_system) {
if (G.du_depth == 0) {
G.dir_dev = statbuf.st_dev;
} else if (G.dir_dev != statbuf.st_dev) {
return 0;
}
}
@@ -86,20 +83,20 @@ static long du(const char *const filename)
sum = statbuf.st_blocks;
if (S_ISLNK(statbuf.st_mode)) {
if (slink_depth > du_depth) { /* -H or -L */
if (G.slink_depth > G.du_depth) { /* -H or -L */
if (stat(filename, &statbuf) != 0) {
bb_perror_msg("%s", filename);
status = EXIT_FAILURE;
bb_simple_perror_msg(filename);
G.status = EXIT_FAILURE;
return 0;
}
sum = statbuf.st_blocks;
if (slink_depth == 1) {
slink_depth = INT_MAX; /* Convert -H to -L. */
if (G.slink_depth == 1) {
G.slink_depth = INT_MAX; /* Convert -H to -L. */
}
}
}
if (statbuf.st_nlink > count_hardlinks) {
if (statbuf.st_nlink > G.count_hardlinks) {
/* Add files/directories with links only once */
if (is_in_ino_dev_hashtable(&statbuf)) {
return 0;
@@ -114,7 +111,7 @@ static long du(const char *const filename)
dir = warn_opendir(filename);
if (!dir) {
status = EXIT_FAILURE;
G.status = EXIT_FAILURE;
return sum;
}
@@ -128,39 +125,41 @@ static long du(const char *const filename)
newfile = concat_subpath_file(filename, name);
if (newfile == NULL)
continue;
++du_depth;
++G.du_depth;
sum += du(newfile);
--du_depth;
--G.du_depth;
free(newfile);
}
closedir(dir);
} else if (du_depth > print_files) {
} else if (G.du_depth > G.print_files) {
return sum;
}
if (du_depth <= max_print_depth) {
if (G.du_depth <= G.max_print_depth) {
print(sum, filename);
}
return sum;
}
int du_main(int argc, char **argv);
int du_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int du_main(int argc, char **argv)
{
long total;
unsigned long total;
int slink_depth_save;
int print_final_total;
bool print_final_total;
char *smax_print_depth;
unsigned opt;
#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
#if ENABLE_FEATURE_HUMAN_READABLE
disp_hr = 512;
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
G.disp_hr = 512;
#else
disp_k = 0;
#endif
}
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
/* SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
#endif
G.max_print_depth = INT_MAX;
G.count_hardlinks = 1;
/* Note: SUSv3 specifies that -a and -s options cannot be used together
* in strictly conforming applications. However, it also says that some
@@ -171,75 +170,76 @@ int du_main(int argc, char **argv)
#if ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
argv += optind;
if (opt & (1 << 9)) {
/* -h opt */
disp_hr = 0;
G.disp_hr = 0;
}
if (opt & (1 << 10)) {
/* -m opt */
disp_hr = 1024*1024;
G.disp_hr = 1024*1024;
}
if (opt & (1 << 2)) {
/* -k opt */
disp_hr = 1024;
G.disp_hr = 1024;
}
#else
opt_complementary = "H-L:L-H:s-d:d-s";
opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth);
argv += optind;
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & (1 << 2)) {
/* -k opt */
disp_k = 1;
G.disp_k = 1;
}
#endif
#endif
if (opt & (1 << 0)) {
/* -a opt */
print_files = INT_MAX;
G.print_files = INT_MAX;
}
if (opt & (1 << 1)) {
/* -H opt */
slink_depth = 1;
G.slink_depth = 1;
}
if (opt & (1 << 3)) {
/* -L opt */
slink_depth = INT_MAX;
G.slink_depth = INT_MAX;
}
if (opt & (1 << 4)) {
/* -s opt */
max_print_depth = 0;
G.max_print_depth = 0;
}
one_file_system = opt & (1 << 5); /* -x opt */
G.one_file_system = opt & (1 << 5); /* -x opt */
if (opt & (1 << 6)) {
/* -d opt */
max_print_depth = xatoi_u(smax_print_depth);
G.max_print_depth = xatoi_u(smax_print_depth);
}
if (opt & (1 << 7)) {
/* -l opt */
count_hardlinks = MAXINT(nlink_t);
G.count_hardlinks = MAXINT(nlink_t);
}
print_final_total = opt & (1 << 8); /* -c opt */
/* go through remaining args (if any) */
argv += optind;
if (optind >= argc) {
if (!*argv) {
*--argv = (char*)".";
if (slink_depth == 1) {
slink_depth = 0;
if (G.slink_depth == 1) {
G.slink_depth = 0;
}
}
slink_depth_save = slink_depth;
slink_depth_save = G.slink_depth;
total = 0;
do {
total += du(*argv);
slink_depth = slink_depth_save;
G.slink_depth = slink_depth_save;
} while (*++argv);
if (ENABLE_FEATURE_CLEAN_UP)
reset_ino_dev_hashtable();
if (print_final_total) {
if (print_final_total)
print(total, "total");
}
fflush_stdout_and_exit(status);
fflush_stdout_and_exit(G.status);
}
+145 -12
View File
@@ -25,7 +25,13 @@
#include "libbb.h"
int bb_echo(char **argv)
/* This is a NOFORK applet. Be very careful! */
/* argc is unused, but removing it precludes compiler from
* using call -> jump optimization */
int echo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int echo_main(int argc, char **argv)
{
const char *arg;
#if !ENABLE_FEATURE_FANCY_ECHO
@@ -33,6 +39,18 @@ int bb_echo(char **argv)
eflag = '\\',
nflag = 1, /* 1 -- print '\n' */
};
/* We must check that stdout is not closed.
* The reason for this is highly non-obvious.
* echo_main is used from shell. Shell must correctly handle "echo foo"
* if stdout is closed. With stdio, output gets shoveled into
* stdout buffer, and even fflush cannot clear it out. It seems that
* even if libc receives EBADF on write attempts, it feels determined
* to output data no matter what. So it will try later,
* and possibly will clobber future output. Not good. */
if (dup2(1, 1) != 1)
return -1;
arg = *++argv;
if (!arg)
goto newline_ret;
@@ -41,6 +59,10 @@ int bb_echo(char **argv)
char nflag = 1;
char eflag = 0;
/* We must check that stdout is not closed. */
if (dup2(1, 1) != 1)
return -1;
while (1) {
arg = *++argv;
if (!arg)
@@ -100,31 +122,23 @@ int bb_echo(char **argv)
c = bb_process_escape_sequence(&arg);
}
}
putchar(c);
bb_putchar(c);
}
arg = *++argv;
if (!arg)
break;
putchar(' ');
bb_putchar(' ');
}
newline_ret:
if (nflag) {
putchar('\n');
bb_putchar('\n');
}
ret:
return fflush(stdout);
}
/* This is a NOFORK applet. Be very careful! */
int echo_main(int argc, char** argv);
int echo_main(int argc, char** argv)
{
return bb_echo(argv);
}
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -163,3 +177,122 @@ int echo_main(int argc, char** argv)
*
* @(#)echo.c 8.1 (Berkeley) 5/31/93
*/
#ifdef VERSION_WITH_WRITEV
/* We can't use stdio.
* The reason for this is highly non-obvious.
* echo_main is used from shell. Shell must correctly handle "echo foo"
* if stdout is closed. With stdio, output gets shoveled into
* stdout buffer, and even fflush cannot clear it out. It seems that
* even if libc receives EBADF on write attempts, it feels determined
* to output data no matter what. So it will try later,
* and possibly will clobber future output. Not good.
*
* Using writev instead, with 'direct' conversion of argv vector.
*/
int echo_main(int argc, char **argv)
{
struct iovec io[argc];
struct iovec *cur_io = io;
char *arg;
char *p;
#if !ENABLE_FEATURE_FANCY_ECHO
enum {
eflag = '\\',
nflag = 1, /* 1 -- print '\n' */
};
arg = *++argv;
if (!arg)
goto newline_ret;
#else
char nflag = 1;
char eflag = 0;
while (1) {
arg = *++argv;
if (!arg)
goto newline_ret;
if (*arg != '-')
break;
/* If it appears that we are handling options, then make sure
* that all of the options specified are actually valid.
* Otherwise, the string should just be echoed.
*/
p = arg + 1;
if (!*p) /* A single '-', so echo it. */
goto just_echo;
do {
if (!strrchr("neE", *p))
goto just_echo;
} while (*++p);
/* All of the options in this arg are valid, so handle them. */
p = arg + 1;
do {
if (*p == 'n')
nflag = 0;
if (*p == 'e')
eflag = '\\';
} while (*++p);
}
just_echo:
#endif
while (1) {
/* arg is already == *argv and isn't NULL */
int c;
cur_io->iov_base = p = arg;
if (!eflag) {
/* optimization for very common case */
p += strlen(arg);
} else while ((c = *arg++)) {
if (c == eflag) { /* Check for escape seq. */
if (*arg == 'c') {
/* '\c' means cancel newline and
* ignore all subsequent chars. */
cur_io->iov_len = p - (char*)cur_io->iov_base;
cur_io++;
goto ret;
}
#if !ENABLE_FEATURE_FANCY_ECHO
/* SUSv3 specifies that octal escapes must begin with '0'. */
if ( (((unsigned char)*arg) - '1') >= 7)
#endif
{
/* Since SUSv3 mandates a first digit of 0, 4-digit octals
* of the form \0### are accepted. */
if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
arg++;
}
/* bb_process_escape_sequence can handle nul correctly */
c = bb_process_escape_sequence( (void*) &arg);
}
}
*p++ = c;
}
arg = *++argv;
if (arg)
*p++ = ' ';
cur_io->iov_len = p - (char*)cur_io->iov_base;
cur_io++;
if (!arg)
break;
}
newline_ret:
if (nflag) {
cur_io->iov_base = (char*)"\n";
cur_io->iov_len = 1;
cur_io++;
}
ret:
/* TODO: implement and use full_writev? */
return writev(1, io, (cur_io - io)) >= 0;
}
#endif
+3 -3
View File
@@ -41,8 +41,8 @@ static const char env_longopts[] ALIGN1 =
;
#endif
int env_main(int argc, char** argv);
int env_main(int argc, char** argv)
int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int env_main(int argc, char **argv)
{
/* cleanenv was static - why? */
char *cleanenv[1];
@@ -81,7 +81,7 @@ int env_main(int argc, char** argv)
BB_EXECVP(*argv, argv);
/* SUSv3-mandated exit codes. */
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
bb_perror_msg_and_die("%s", *argv);
bb_simple_perror_msg_and_die(*argv);
}
for (ep = environ; *ep; ep++) {
+2 -2
View File
@@ -125,7 +125,7 @@ static void unexpand(FILE *file, unsigned int tab_size, unsigned opt)
}
#endif
int expand_main(int argc, char **argv);
int expand_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int expand_main(int argc, char **argv)
{
/* Default 8 spaces for 1 tab */
@@ -192,7 +192,7 @@ int expand_main(int argc, char **argv)
/* Check and close the file */
/* We do want all of them to execute, thus | instead of || */
if (ferror(file) | fclose_if_not_stdin(file)) {
bb_perror_msg("%s", *argv);
bb_simple_perror_msg(*argv);
exit_status = EXIT_FAILURE;
}
/* If stdin also clear EOF */
+1 -1
View File
@@ -483,7 +483,7 @@ static VALUE *eval(void)
return l;
}
int expr_main(int argc, char **argv);
int expr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int expr_main(int argc, char **argv)
{
VALUE *v;
+1 -1
View File
@@ -14,7 +14,7 @@
/* This is a NOFORK applet. Be very careful! */
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv);
int false_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
{
return EXIT_FAILURE;
+4 -4
View File
@@ -5,7 +5,7 @@
Copyright (C) 91, 1995-2002 Free Software Foundation, Inc.
Modified for busybox based on coreutils v 5.0
Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au>
Copyright (C) 2003 Glenn McGrath
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
@@ -38,7 +38,7 @@ static int adjust_column(int column, char c)
return column;
}
int fold_main(int argc, char **argv);
int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int fold_main(int argc, char **argv)
{
char *line_out = NULL;
@@ -115,7 +115,7 @@ int fold_main(int argc, char **argv)
/* Found a blank. Don't output the part after it. */
logical_end++;
fwrite(line_out, sizeof(char), (size_t) logical_end, stdout);
putchar('\n');
bb_putchar('\n');
/* Move the remainder to the beginning of the next line.
The areas being copied here might overlap. */
memmove(line_out, line_out + logical_end, offset_out - logical_end);
@@ -145,7 +145,7 @@ int fold_main(int argc, char **argv)
}
if (ferror(istream) || fclose_if_not_stdin(istream)) {
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
errs |= EXIT_FAILURE;
}
} while (*++argv);
+2 -2
View File
@@ -31,7 +31,7 @@ static const struct suffix_mult head_suffixes[] = {
static const char header_fmt_str[] ALIGN1 = "\n==> %s <==\n";
int head_main(int argc, char **argv);
int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int head_main(int argc, char **argv)
{
unsigned long count = 10;
@@ -128,7 +128,7 @@ int head_main(int argc, char **argv)
putchar(c);
}
if (fclose_if_not_stdin(fp)) {
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
retval = EXIT_FAILURE;
}
die_if_ferror_stdout();
+1 -1
View File
@@ -13,7 +13,7 @@
/* This is a NOFORK applet. Be very careful! */
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv);
int hostid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
{
if (argc > 1) {
+4 -4
View File
@@ -36,7 +36,7 @@ static int printf_full(unsigned int id, const char *arg, const char prefix)
return status;
}
int id_main(int argc, char **argv);
int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int id_main(int argc, char **argv)
{
struct passwd *p;
@@ -92,7 +92,7 @@ int id_main(int argc, char **argv)
if (getcon(&scontext)) {
bb_error_msg_and_die("can't get process context");
}
printf("%s\n", scontext);
puts(scontext);
}
#endif
/* exit */
@@ -102,7 +102,7 @@ int id_main(int argc, char **argv)
/* Print full info like GNU id */
/* bb_getpwuid(0) doesn't exit on failure (returns NULL) */
status = printf_full(uid, bb_getpwuid(NULL, 0, uid), 'u');
putchar(' ');
bb_putchar(' ');
status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), 'g');
#if ENABLE_SELINUX
@@ -121,6 +121,6 @@ int id_main(int argc, char **argv)
}
#endif
putchar('\n');
bb_putchar('\n');
fflush_stdout_and_exit(status);
}
+70 -54
View File
@@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
* Copyright (C) 2003 by Glenn McGrath
* SELinux support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
@@ -23,6 +23,8 @@ static const char install_longopts[] ALIGN1 =
"group\0" No_argument "g"
"mode\0" No_argument "m"
"owner\0" No_argument "o"
/* autofs build insists of using -b --suffix=.orig */
/* TODO? (short option for --suffix is -S) */
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
"preserve_context\0" No_argument "\xff"
@@ -33,8 +35,6 @@ static const char install_longopts[] ALIGN1 =
#if ENABLE_SELINUX
static bool use_default_selinux_context = 1;
static void setdefaultfilecon(const char *path)
{
struct stat s;
@@ -66,32 +66,38 @@ static void setdefaultfilecon(const char *path)
#endif
int install_main(int argc, char **argv);
int install_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int install_main(int argc, char **argv)
{
struct stat statbuf;
mode_t mode;
uid_t uid;
gid_t gid;
char *arg, *last;
const char *gid_str;
const char *uid_str;
const char *mode_str;
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
int ret = EXIT_SUCCESS, flags, i, isdir;
int flags;
int ret = EXIT_SUCCESS;
int isdir;
#if ENABLE_SELINUX
security_context_t scontext;
bool use_default_selinux_context = 1;
#endif
enum {
OPT_CMD = 0x1,
OPT_DIRECTORY = 0x2,
OPT_PRESERVE_TIME = 0x4,
OPT_STRIP = 0x8,
OPT_GROUP = 0x10,
OPT_MODE = 0x20,
OPT_OWNER = 0x40,
OPT_c = 1 << 0,
OPT_v = 1 << 1,
OPT_b = 1 << 2,
OPT_DIRECTORY = 1 << 3,
OPT_PRESERVE_TIME = 1 << 4,
OPT_STRIP = 1 << 5,
OPT_GROUP = 1 << 6,
OPT_MODE = 1 << 7,
OPT_OWNER = 1 << 8,
#if ENABLE_SELINUX
OPT_SET_SECURITY_CONTEXT = 0x80,
OPT_PRESERVE_SECURITY_CONTEXT = 0x100,
OPT_SET_SECURITY_CONTEXT = 1 << 9,
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 10,
#endif
};
@@ -100,21 +106,24 @@ int install_main(int argc, char **argv)
#endif
opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
/* -c exists for backwards compatibility, it's needed */
flags = getopt32(argv, "cdpsg:m:o:" USE_SELINUX("Z:"),
/* -v is ignored ("print name of each created directory") */
/* -b is ignored ("make a backup of each existing destination file") */
flags = getopt32(argv, "cvb" "dpsg:m:o:" USE_SELINUX("Z:"),
&gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext));
argc -= optind;
argv += optind;
#if ENABLE_SELINUX
if (flags & OPT_PRESERVE_SECURITY_CONTEXT) {
use_default_selinux_context = 0;
copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
if (flags & (OPT_PRESERVE_SECURITY_CONTEXT|OPT_SET_SECURITY_CONTEXT)) {
selinux_or_die();
}
if (flags & OPT_SET_SECURITY_CONTEXT) {
selinux_or_die();
setfscreatecon_or_die(scontext);
use_default_selinux_context = 0;
copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
if (flags & OPT_PRESERVE_SECURITY_CONTEXT) {
copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
}
if (flags & OPT_SET_SECURITY_CONTEXT) {
setfscreatecon_or_die(scontext);
copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
}
}
#endif
@@ -123,58 +132,63 @@ int install_main(int argc, char **argv)
copy_flags |= FILEUTILS_PRESERVE_STATUS;
}
mode = 0666;
if (flags & OPT_MODE) bb_parse_mode(mode_str, &mode);
if (flags & OPT_MODE)
bb_parse_mode(mode_str, &mode);
uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
if (flags & (OPT_OWNER|OPT_GROUP)) umask(0);
if (flags & (OPT_OWNER|OPT_GROUP))
umask(0);
/* Create directories
* don't use bb_make_directory() as it can't change uid or gid
* perhaps bb_make_directory() should be improved.
*/
if (flags & OPT_DIRECTORY) {
for (argv += optind; *argv; argv++) {
char *old_argv_ptr = *argv + 1;
char *argv_ptr;
do {
argv_ptr = strchr(old_argv_ptr, '/');
old_argv_ptr = argv_ptr;
if (argv_ptr) {
*argv_ptr = '\0';
old_argv_ptr++;
}
if (mkdir(*argv, mode | 0111) == -1) {
while ((arg = *argv++) != NULL) {
char *slash = arg;
while (1) {
slash = strchr(slash + 1, '/');
if (slash)
*slash = '\0';
if (mkdir(arg, mode | 0111) == -1) {
if (errno != EEXIST) {
bb_perror_msg("cannot create %s", *argv);
bb_perror_msg("cannot create %s", arg);
ret = EXIT_FAILURE;
break;
}
}
if ((flags & (OPT_OWNER|OPT_GROUP))
&& lchown(*argv, uid, gid) == -1
} /* dir was created, chown? */
else if ((flags & (OPT_OWNER|OPT_GROUP))
&& lchown(arg, uid, gid) == -1
) {
bb_perror_msg("cannot change ownership of %s", *argv);
bb_perror_msg("cannot change ownership of %s", arg);
ret = EXIT_FAILURE;
break;
}
if (argv_ptr) {
*argv_ptr = '/';
}
} while (old_argv_ptr);
if (!slash)
break;
*slash = '/';
}
}
return ret;
}
if (argc < 2)
bb_show_usage();
last = argv[argc - 1];
argv[argc - 1] = NULL;
/* coreutils install resolves link in this case, don't use lstat */
isdir = stat(argv[argc - 1], &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
for (i = optind; i < argc - 1; i++) {
char *dest;
dest = argv[argc - 1];
while ((arg = *argv++) != NULL) {
char *dest = last;
if (isdir)
dest = concat_path_file(argv[argc - 1], basename(argv[i]));
ret |= copy_file(argv[i], dest, copy_flags);
dest = concat_path_file(last, basename(arg));
if (copy_file(arg, dest, copy_flags)) {
/* copy is not made */
ret = EXIT_FAILURE;
goto next;
}
/* Set the file mode */
if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
@@ -202,7 +216,9 @@ int install_main(int argc, char **argv)
ret = EXIT_FAILURE;
}
}
if (ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
next:
if (ENABLE_FEATURE_CLEAN_UP && isdir)
free(dest);
}
return ret;
+1 -1
View File
@@ -6,7 +6,7 @@
/* This is a NOFORK applet. Be very careful! */
int length_main(int argc, char **argv);
int length_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int length_main(int argc, char **argv)
{
if ((argc != 2) || (**(++argv) == '-')) {
+2 -1
View File
@@ -31,7 +31,8 @@ int cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf)
return -1;
}
return 0;
} else if (S_ISDIR(fn_stat->st_mode)) {
}
if (S_ISDIR(fn_stat->st_mode)) {
return 3;
}
return 1;
+6 -6
View File
@@ -22,7 +22,7 @@
#define LN_BACKUP 8
#define LN_SUFFIX 16
int ln_main(int argc, char **argv);
int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ln_main(int argc, char **argv)
{
int status = EXIT_SUCCESS;
@@ -45,7 +45,7 @@ int ln_main(int argc, char **argv)
if (argc == optind + 1) {
*--argv = last;
last = bb_get_last_path_component(xstrdup(last));
last = bb_get_last_path_component_strip(xstrdup(last));
}
do {
@@ -57,14 +57,14 @@ int ln_main(int argc, char **argv)
NULL)
) {
src_name = xstrdup(*argv);
src = concat_path_file(src, bb_get_last_path_component(src_name));
src = concat_path_file(src, bb_get_last_path_component_strip(src_name));
free(src_name);
src_name = src;
}
if (!(flag & LN_SYMLINK) && stat(*argv, &statbuf)) {
// coreutils: "ln dangling_symlink new_hardlink" works
if (lstat(*argv, &statbuf) || !S_ISLNK(statbuf.st_mode)) {
bb_perror_msg("%s", *argv);
bb_simple_perror_msg(*argv);
status = EXIT_FAILURE;
free(src_name);
continue;
@@ -75,7 +75,7 @@ int ln_main(int argc, char **argv)
char *backup;
backup = xasprintf("%s%s", src, suffix);
if (rename(src, backup) < 0 && errno != ENOENT) {
bb_perror_msg("%s", src);
bb_simple_perror_msg(src);
status = EXIT_FAILURE;
free(backup);
continue;
@@ -97,7 +97,7 @@ int ln_main(int argc, char **argv)
}
if (link_func(*argv, src) != 0) {
bb_perror_msg("%s", src);
bb_simple_perror_msg(src);
status = EXIT_FAILURE;
}
+1 -1
View File
@@ -24,7 +24,7 @@
/* This is a NOFORK applet. Be very careful! */
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv);
int logname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv)
{
char buf[128];
+4 -4
View File
@@ -171,7 +171,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
}
#endif
if (stat(fullname, &dstat)) {
bb_perror_msg("%s", fullname);
bb_simple_perror_msg(fullname);
status = EXIT_FAILURE;
return 0;
}
@@ -182,7 +182,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
}
#endif
if (lstat(fullname, &dstat)) {
bb_perror_msg("%s", fullname);
bb_simple_perror_msg(fullname);
status = EXIT_FAILURE;
return 0;
}
@@ -451,7 +451,7 @@ static void showdirs(struct dnode **dn, int ndirs, int first)
for (i = 0; i < ndirs; i++) {
if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
if (!first)
puts("");
bb_putchar('\n');
first = 0;
printf("%s:\n", dn[i]->fullname);
}
@@ -783,7 +783,7 @@ static const unsigned opt_flags[] = {
/* THIS IS A "SAFE" APPLET, main() MAY BE CALLED INTERNALLY FROM SHELL */
/* BE CAREFUL! */
int ls_main(int argc, char **argv);
int ls_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ls_main(int argc, char **argv)
{
struct dnode **dnd;
+1 -1
View File
@@ -77,7 +77,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
return hash_value;
}
int md5_sha1_sum_main(int argc, char **argv);
int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int md5_sha1_sum_main(int argc, char **argv)
{
int return_value = EXIT_SUCCESS;
+1 -1
View File
@@ -34,7 +34,7 @@ static const char mkdir_longopts[] ALIGN1 =
;
#endif
int mkdir_main(int argc, char **argv);
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkdir_main(int argc, char **argv)
{
mode_t mode = (mode_t)(-1);
+2 -2
View File
@@ -13,7 +13,7 @@
#include "libbb.h"
#include "libcoreutils/coreutils.h"
int mkfifo_main(int argc, char **argv);
int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkfifo_main(int argc, char **argv)
{
mode_t mode;
@@ -28,7 +28,7 @@ int mkfifo_main(int argc, char **argv)
do {
if (mkfifo(*argv, mode) < 0) {
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
retval = EXIT_FAILURE;
}
} while (*++argv);
+21 -15
View File
@@ -17,7 +17,7 @@
static const char modes_chars[] ALIGN1 = { 'p', 'c', 'u', 'b', 0, 1, 1, 2 };
static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK };
int mknod_main(int argc, char **argv);
int mknod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mknod_main(int argc, char **argv)
{
mode_t mode;
@@ -28,23 +28,29 @@ int mknod_main(int argc, char **argv)
argv += optind;
argc -= optind;
if ((argc >= 2) && ((name = strchr(modes_chars, argv[1][0])) != NULL)) {
mode |= modes_cubp[(int)(name[4])];
if (argc >= 2) {
name = strchr(modes_chars, argv[1][0]);
if (name != NULL) {
mode |= modes_cubp[(int)(name[4])];
dev = 0;
if ((*name != 'p') && ((argc -= 2) == 2)) {
/* Autodetect what the system supports; these macros should
* optimize out to two constants. */
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
xatoul_range(argv[3], 0, minor(UINT_MAX)));
}
dev = 0;
if (*name != 'p') {
argc -= 2;
if (argc == 2) {
/* Autodetect what the system supports; these macros should
* optimize out to two constants. */
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
xatoul_range(argv[3], 0, minor(UINT_MAX)));
}
}
if (argc == 2) {
name = *argv;
if (mknod(name, mode, dev) == 0) {
return EXIT_SUCCESS;
if (argc == 2) {
name = *argv;
if (mknod(name, mode, dev) == 0) {
return EXIT_SUCCESS;
}
bb_simple_perror_msg_and_die(name);
}
bb_perror_msg_and_die("%s", name);
}
}
bb_show_usage();
+22 -21
View File
@@ -33,7 +33,7 @@ static const char mv_longopts[] ALIGN1 =
static const char fmt[] ALIGN1 =
"cannot overwrite %sdirectory with %sdirectory";
int mv_main(int argc, char **argv);
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mv_main(int argc, char **argv)
{
struct stat dest_stat;
@@ -47,19 +47,18 @@ int mv_main(int argc, char **argv)
#if ENABLE_FEATURE_MV_LONG_OPTIONS
applet_long_options = mv_longopts;
#endif
opt_complementary = "f-i:i-f";
// Need at least two arguments
// -f unsets -i, -i unsets -f
opt_complementary = "-2:f-i:i-f";
flags = getopt32(argv, "fi");
if (optind + 2 > argc) {
bb_show_usage();
}
last = argv[argc - 1];
argc -= optind;
argv += optind;
last = argv[argc - 1];
if (optind + 2 == argc) {
if (argc == 2) {
dest_exists = cp_mv_stat(last, &dest_stat);
if (dest_exists < 0) {
return 1;
return EXIT_FAILURE;
}
if (!(dest_exists & 2)) {
@@ -69,17 +68,17 @@ int mv_main(int argc, char **argv)
}
do {
dest = concat_path_file(last, bb_get_last_path_component(*argv));
dest = concat_path_file(last, bb_get_last_path_component_strip(*argv));
dest_exists = cp_mv_stat(dest, &dest_stat);
if (dest_exists < 0) {
goto RET_1;
}
DO_MOVE:
if (dest_exists && !(flags & OPT_FILEUTILS_FORCE) &&
((access(dest, W_OK) < 0 && isatty(0)) ||
(flags & OPT_FILEUTILS_INTERACTIVE))) {
DO_MOVE:
if (dest_exists && !(flags & OPT_FILEUTILS_FORCE)
&& ((access(dest, W_OK) < 0 && isatty(0))
|| (flags & OPT_FILEUTILS_INTERACTIVE))
) {
if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) {
goto RET_1; /* Ouch! fprintf failed! */
}
@@ -91,8 +90,9 @@ DO_MOVE:
struct stat source_stat;
int source_exists;
if (errno != EXDEV ||
(source_exists = cp_mv_stat(*argv, &source_stat)) < 1) {
if (errno != EXDEV
|| (source_exists = cp_mv_stat(*argv, &source_stat)) < 1
) {
bb_perror_msg("cannot rename '%s'", *argv);
} else {
if (dest_exists) {
@@ -116,15 +116,16 @@ DO_MOVE:
#if ENABLE_SELINUX
copy_flag |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
#endif
if ((copy_file(*argv, dest, copy_flag) >= 0) &&
(remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) {
if ((copy_file(*argv, dest, copy_flag) >= 0)
&& (remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)
) {
goto RET_0;
}
}
RET_1:
RET_1:
status = 1;
}
RET_0:
RET_0:
if (dest != last) {
free((void *) dest);
}
Loaded 100 of 444 files, more files were not shown because too many files have changed in this diff. Show more