Compare commits
320
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28dd64a0e1 | ||
|
|
5698ff9323 | ||
|
|
d9e0c438e1 | ||
|
|
a2dd4ee0e8 | ||
|
|
7625811d25 | ||
|
|
198b02f7dd | ||
|
|
61be8e46a8 | ||
|
|
e83e1c50f2 | ||
|
|
e85e260e47 | ||
|
|
c9d87bed8e | ||
|
|
80a068d741 | ||
|
|
e9355c4326 | ||
|
|
4967a41ba1 | ||
|
|
4b26f82c78 | ||
|
|
3ac1e0d753 | ||
|
|
9f4f60183b | ||
|
|
22bb81fa85 | ||
|
|
0b3a38b9f5 | ||
|
|
777be10ebe | ||
|
|
6c46eed6e9 | ||
|
|
a14958c69d | ||
|
|
cb1dc1d1d1 | ||
|
|
327f550669 | ||
|
|
9b2a9f0210 | ||
|
|
1a7256ac38 | ||
|
|
72745632a1 | ||
|
|
df0d2cd837 | ||
|
|
deb0769b26 | ||
|
|
259b3c047a | ||
|
|
8bd810bd27 | ||
|
|
d9fc4d8f92 | ||
|
|
195c436f84 | ||
|
|
760fc6debc | ||
|
|
cffe28ef87 | ||
|
|
4d8ad381ab | ||
|
|
924a179cb7 | ||
|
|
26ad256bd0 | ||
|
|
71f6c1aa43 | ||
|
|
bd0e221620 | ||
|
|
2635369a92 | ||
|
|
0545e3b69a | ||
|
|
dd1d8ab506 | ||
|
|
1cbc642bed | ||
|
|
ebfa9b5aa1 | ||
|
|
8b59b2c13e | ||
|
|
6ef7729112 | ||
|
|
9c1c605b1a | ||
|
|
f6beef63c6 | ||
|
|
ac21687309 | ||
|
|
36184a487d | ||
|
|
66620fa626 | ||
|
|
73225b6d6e | ||
|
|
f200f732f4 | ||
|
|
cd0936be36 | ||
|
|
d3092c99ae | ||
|
|
087843a65b | ||
|
|
afa63b2dcd | ||
|
|
5e63776212 | ||
|
|
b1489f97e0 | ||
|
|
140f4e3511 | ||
|
|
1d39e33d46 | ||
|
|
80f8cdf04a | ||
|
|
200c1c46f4 | ||
|
|
b541d1fcbd | ||
|
|
8d3efaf35e | ||
|
|
b21bc80c76 | ||
|
|
18b461925c | ||
|
|
17f4aca556 | ||
|
|
c44539fcd3 | ||
|
|
a82e32d9ce | ||
|
|
9d46a7a9a4 | ||
|
|
af0cdeedc6 | ||
|
|
2d576e2a22 | ||
|
|
af4f0e48ec | ||
|
|
28a209466f | ||
|
|
64938011f3 | ||
|
|
840ef17f63 | ||
|
|
5117eff6f9 | ||
|
|
eba5faec67 | ||
|
|
d074b416f8 | ||
|
|
730e4d8b52 | ||
|
|
7985bc109e | ||
|
|
1d30b3f1f6 | ||
|
|
5906a5c26c | ||
|
|
932e233a49 | ||
|
|
cd256e1c40 | ||
|
|
3eab2b7675 | ||
|
|
054f3eb784 | ||
|
|
a6ed6a3148 | ||
|
|
d7ea34ee71 | ||
|
|
32ed30d96b | ||
|
|
fbe250db76 | ||
|
|
b5352078a7 | ||
|
|
a613aa1b4c | ||
|
|
2a053a2430 | ||
|
|
dc57294485 | ||
|
|
a407cf74cc | ||
|
|
d6ae4fb446 | ||
|
|
deebdf59b5 | ||
|
|
1b9ac21166 | ||
|
|
0ff0b320a2 | ||
|
|
1b57fe108f | ||
|
|
f3114a3bd0 | ||
|
|
90e9cfd218 | ||
|
|
4502bb1f21 | ||
|
|
5b9910f0a4 | ||
|
|
e66a56de23 | ||
|
|
7a18043a96 | ||
|
|
8395bd3f52 | ||
|
|
b941316ae5 | ||
|
|
4b1896cd2c | ||
|
|
ec2bef11a7 | ||
|
|
9f07af6156 | ||
|
|
d2e07bc16c | ||
|
|
73fbe9dc86 | ||
|
|
fc364ba9e3 | ||
|
|
6761d7da83 | ||
|
|
9ae6d79307 | ||
|
|
456687fff1 | ||
|
|
8c7fcbd752 | ||
|
|
a5e6c6cd3b | ||
|
|
543efd7b4b | ||
|
|
aadb485bd0 | ||
|
|
adc30b4cf9 | ||
|
|
985345d002 | ||
|
|
da331d779c | ||
|
|
cc1c9ca6f8 | ||
|
|
9369634167 | ||
|
|
a060a1ad96 | ||
|
|
e418b2e7bb | ||
|
|
15d0a860e9 | ||
|
|
3b45801dc6 | ||
|
|
982e87f2fb | ||
|
|
bfa6ed1bf4 | ||
|
|
79c618c411 | ||
|
|
d0bc708cb5 | ||
|
|
05965cbb75 | ||
|
|
2ead5316b4 | ||
|
|
2641426187 | ||
|
|
fd3ac96c0f | ||
|
|
ffeeb7a96c | ||
|
|
ca54b662e7 | ||
|
|
ad546ec606 | ||
|
|
9078633fee | ||
|
|
7801148a81 | ||
|
|
688a7e3f04 | ||
|
|
c19be75d57 | ||
|
|
b855460adc | ||
|
|
b0e9b72915 | ||
|
|
26cd90c7fd | ||
|
|
1390a010b6 | ||
|
|
5e87e8aebb | ||
|
|
a7ecbed56b | ||
|
|
9b58fe9c0b | ||
|
|
25ce3ee9f3 | ||
|
|
c72b43c2f0 | ||
|
|
0dacb68e1a | ||
|
|
e95738f635 | ||
|
|
d87fcd4888 | ||
|
|
40ab27a225 | ||
|
|
e93d15613e | ||
|
|
d8f6d8c627 | ||
|
|
2301d127a2 | ||
|
|
4f9fc1e5f5 | ||
|
|
6651e42609 | ||
|
|
cd8eece88e | ||
|
|
3e7ecb179b | ||
|
|
ea267d518f | ||
|
|
1bf560e9c3 | ||
|
|
16614e9bab | ||
|
|
e9b3fcc3e4 | ||
|
|
f798ba9717 | ||
|
|
65bdf0b737 | ||
|
|
f86404f773 | ||
|
|
173aa78bcf | ||
|
|
26a7e2ecbf | ||
|
|
59f46676a9 | ||
|
|
4928e9f7d0 | ||
|
|
879f008a8f | ||
|
|
d66eb9042d | ||
|
|
1f5e81f8f8 | ||
|
|
f6205c6ab7 | ||
|
|
fea2588021 | ||
|
|
5a7e3376b7 | ||
|
|
07c5987498 | ||
|
|
5ffdd1d981 | ||
|
|
d99ef636f6 | ||
|
|
b6dc13c2d3 | ||
|
|
9cb1e2f86b | ||
|
|
f958425451 | ||
|
|
ae0cf2a9d7 | ||
|
|
e9581b673c | ||
|
|
b443a3780d | ||
|
|
c133fa66f3 | ||
|
|
6db5f679a2 | ||
|
|
5fc0585c01 | ||
|
|
aa94130f74 | ||
|
|
414db791d0 | ||
|
|
e0a6ab698f | ||
|
|
6782f48ccb | ||
|
|
c3cf1e30a3 | ||
|
|
ff463a885d | ||
|
|
abbc478f1c | ||
|
|
f76fd17d74 | ||
|
|
041baf2720 | ||
|
|
264f37363d | ||
|
|
d96ffda62e | ||
|
|
3beab83e4f | ||
|
|
d35cbad0ef | ||
|
|
2df1c64f38 | ||
|
|
e306c11367 | ||
|
|
2c0508b4fa | ||
|
|
8172d054db | ||
|
|
1d14569a66 | ||
|
|
8f2cb7ab26 | ||
|
|
6c852bfcad | ||
|
|
2c24806bf4 | ||
|
|
ef6747e290 | ||
|
|
80a38ca11c | ||
|
|
85daa67bc2 | ||
|
|
c608731e78 | ||
|
|
a42f530e03 | ||
|
|
e82bfef839 | ||
|
|
4a732220e9 | ||
|
|
236f222cde | ||
|
|
a8ba0a0d0c | ||
|
|
06ad964ae6 | ||
|
|
95e99e5271 | ||
|
|
14285d14a5 | ||
|
|
7c6f2d4207 | ||
|
|
4424dfd69b | ||
|
|
c56d12505b | ||
|
|
091f831424 | ||
|
|
88b532d59a | ||
|
|
4ef1439c59 | ||
|
|
aeb717aa5e | ||
|
|
9e7c002182 | ||
|
|
cb5aa725df | ||
|
|
257a77568a | ||
|
|
4a600f8777 | ||
|
|
45dc96c8a6 | ||
|
|
0d61dcd641 | ||
|
|
af4a07a244 | ||
|
|
7b5d5c1bdb | ||
|
|
e3f5b73ad0 | ||
|
|
b79a0fef99 | ||
|
|
7991d45446 | ||
|
|
1b49c25e0a | ||
|
|
af9e70b8cb | ||
|
|
445e7543e8 | ||
|
|
bca5c556c4 | ||
|
|
9bbf6b98c4 | ||
|
|
93b51819cf | ||
|
|
507f6ea6d2 | ||
|
|
a2d04e0702 | ||
|
|
c09fd27c0a | ||
|
|
2fe5fed2df | ||
|
|
08e28e806d | ||
|
|
920c1baab7 | ||
|
|
fb03663619 | ||
|
|
41655438c6 | ||
|
|
8e96efa323 | ||
|
|
f2d8478e56 | ||
|
|
577235dee8 | ||
|
|
7794c21daf | ||
|
|
216e952fb8 | ||
|
|
47f8558eee | ||
|
|
ed954b6855 | ||
|
|
efd0698f74 | ||
|
|
5d1c599d76 | ||
|
|
de6f148006 | ||
|
|
a14f319805 | ||
|
|
bc0ffc0e97 | ||
|
|
1e43a381b2 | ||
|
|
0496e824a5 | ||
|
|
f59d563399 | ||
|
|
46031da862 | ||
|
|
380c8a0763 | ||
|
|
433757413f | ||
|
|
c3045edec2 | ||
|
|
a1ae2b75a7 | ||
|
|
efb800439f | ||
|
|
aada3126a7 | ||
|
|
b967e42b77 | ||
|
|
18714d8460 | ||
|
|
9056fcecbf | ||
|
|
3a7b2417f9 | ||
|
|
04f296b28a | ||
|
|
e3e321682c | ||
|
|
5bce135e36 | ||
|
|
9fed24c031 | ||
|
|
39b8fb41c5 | ||
|
|
40b97fb31e | ||
|
|
1961aea305 | ||
|
|
3305c008ed | ||
|
|
40c6da433f | ||
|
|
af0255f496 | ||
|
|
8e6a1ea825 | ||
|
|
d4d4f3528e | ||
|
|
2aec773688 | ||
|
|
10f5f9b10d | ||
|
|
cf5731bcbd | ||
|
|
1bd5ca2f53 | ||
|
|
272d85cc85 | ||
|
|
b5fc51198b | ||
|
|
ba76b7a40b | ||
|
|
06af569f44 | ||
|
|
a8816dafc4 | ||
|
|
6e29d07417 | ||
|
|
04ac6e03c3 | ||
|
|
03b614739b | ||
|
|
6be6f3bfec | ||
|
|
17d4436424 | ||
|
|
ee3bc70cea | ||
|
|
243e733001 | ||
|
|
bf99807657 | ||
|
|
9b7ebfe644 | ||
|
|
778794d1dd | ||
|
|
6aab061d2d | ||
|
|
f474dfa681 |
No files matched your search
@@ -161,12 +161,13 @@ config UNICODE_USING_LOCALE
|
||||
Internal implementation is smaller.
|
||||
|
||||
config FEATURE_CHECK_UNICODE_IN_ENV
|
||||
bool "Check $LANG environment variable"
|
||||
bool "Check $LC_ALL, $LC_CTYPE and $LANG environment variables"
|
||||
default n
|
||||
depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE
|
||||
help
|
||||
With this option on, Unicode support is activated
|
||||
only if LANG variable has the value of the form "xxxx.utf8"
|
||||
only if locale-related variables have the value of the form
|
||||
"xxxx.utf8"
|
||||
|
||||
Otherwise, Unicode support will be always enabled and active.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 21
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 22
|
||||
SUBLEVEL = 1
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
+10
-1
@@ -3,7 +3,12 @@
|
||||
# ==========================================================================
|
||||
|
||||
busybox.links: $(srctree)/applets/busybox.mkll $(objtree)/include/autoconf.h include/applets.h
|
||||
$(Q)-$(SHELL) $^ >$@
|
||||
$(Q)-$(SHELL) $^ > $@
|
||||
|
||||
busybox.cfg.suid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autoconf.h include/applets.h
|
||||
$(Q)-SUID="yes" $(SHELL) $^ > $@
|
||||
busybox.cfg.nosuid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autoconf.h include/applets.h
|
||||
$(Q)-SUID="DROP" $(SHELL) $^ > $@
|
||||
|
||||
.PHONY: install
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
|
||||
@@ -68,6 +73,10 @@ release: distclean
|
||||
-name .git \
|
||||
-print \
|
||||
-exec rm -r -f {} \; ; \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \
|
||||
-name .gitignore \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
|
||||
@@ -127,20 +127,6 @@ patch
|
||||
|
||||
And while we're at it, a new patch filename quoting format is apparently
|
||||
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
|
||||
---
|
||||
stty / catv
|
||||
stty's visible() function and catv's guts are identical. Merge them into
|
||||
an appropriate libbb function.
|
||||
---
|
||||
struct suffix_mult
|
||||
Several duplicate users of: grep -r "1024\*1024" * -B2 -A1
|
||||
Merge to a single size_suffixes[] in libbb.
|
||||
Users: head tail od_bloaty hexdump and (partially as it wouldn't hurt) svlogd
|
||||
---
|
||||
tail
|
||||
./busybox tail -f foo.c~ TODO
|
||||
should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
|
||||
fmt+ if another (not the current) file did change
|
||||
|
||||
Architectural issues:
|
||||
|
||||
@@ -233,8 +219,6 @@ Minor stuff:
|
||||
---
|
||||
See grep -r strtod
|
||||
Alot of duplication that wants cleanup.
|
||||
---
|
||||
in_ether duplicated in network/{interface,ifconfig}.c
|
||||
---
|
||||
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
|
||||
---
|
||||
|
||||
@@ -53,7 +53,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int ofs;
|
||||
unsigned MAX_APPLET_NAME_LEN = 1;
|
||||
// unsigned MAX_APPLET_NAME_LEN = 1;
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
@@ -89,8 +89,8 @@ int main(int argc, char **argv)
|
||||
printf("const char applet_names[] ALIGN1 = \"\"\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("\"%s\" \"\\0\"\n", applets[i].name);
|
||||
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
// if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
// MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
}
|
||||
printf(";\n\n");
|
||||
|
||||
@@ -130,8 +130,8 @@ int main(int argc, char **argv)
|
||||
printf("};\n");
|
||||
#endif
|
||||
//printf("#endif /* SKIP_definitions */\n");
|
||||
printf("\n");
|
||||
printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
// printf("\n");
|
||||
// printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
|
||||
if (argv[2]) {
|
||||
char line_old[80];
|
||||
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
# Make list of configuration variables regarding suid handling
|
||||
|
||||
# input $1: full path to autoconf.h
|
||||
# input $2: full path to applets.h
|
||||
# input $3: full path to .config
|
||||
# output (stdout): list of CONFIG_ that do or may require suid
|
||||
|
||||
# If the environment variable SUID is not set or set to DROP,
|
||||
# lists all config options that do not require suid permissions.
|
||||
# Otherwise, lists all config options for applets that DO or MAY require
|
||||
# suid permissions.
|
||||
|
||||
# Maintainer: Bernhard Reutner-Fischer
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
CONFIG_H=${1:-include/autoconf.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
DOT_CONFIG=${3:-.config}
|
||||
|
||||
case ${SUID:-DROP} in
|
||||
[dD][rR][oO][pP]) USE="DROP" ;;
|
||||
*) USE="suid" ;;
|
||||
esac
|
||||
|
||||
$HOSTCC -E -DMAKE_SUID -include $CONFIG_H $APPLETS_H |
|
||||
awk -v USE=${USE} '
|
||||
/^SUID[ \t]/{
|
||||
if (USE == "DROP") {
|
||||
if ($2 != "BB_SUID_DROP") next
|
||||
} else {
|
||||
if ($2 == "BB_SUID_DROP") next
|
||||
}
|
||||
cfg = $NF
|
||||
gsub("\"", "", cfg)
|
||||
cfg = substr(cfg, 8)
|
||||
s[i++] = "CONFIG_" cfg
|
||||
s[i++] = "CONFIG_FEATURE_" cfg "_.*"
|
||||
}
|
||||
END{
|
||||
while (getline < ARGV[2]) {
|
||||
for (j in s) {
|
||||
if ($0 ~ "^" s[j] "=y$") {
|
||||
sub(/=.*/, "")
|
||||
print
|
||||
if (s[j] !~ /\*$/) delete s[j] # can drop this applet now
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
' - $DOT_CONFIG
|
||||
|
||||
@@ -10,20 +10,20 @@ test "$SED" || SED=sed
|
||||
test "$DD" || DD=dd
|
||||
|
||||
# Some people were bitten by their system lacking a (proper) od
|
||||
od -v -t x1 </dev/null >/dev/null
|
||||
od -v -b </dev/null >/dev/null
|
||||
if test $? != 0; then
|
||||
echo 'od tool is not installed or cannot accept "-v -t x1" options'
|
||||
echo 'od tool is not installed or cannot accept "-v -b" options'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec >"$target.$$"
|
||||
|
||||
echo '#define UNPACKED_USAGE "" \'
|
||||
"$loc/usage" | od -v -t x1 \
|
||||
"$loc/usage" | od -v -b \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(..\)/\\x\1/g' \
|
||||
-e 's/\(...\)/\\\1/g' \
|
||||
-e 's/^/"/' \
|
||||
-e 's/$/" \\/'
|
||||
echo ''
|
||||
@@ -39,11 +39,11 @@ echo '#define PACKED_USAGE \'
|
||||
## -e '/^$/d' \
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## -e 's/$/ \\/'
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(..\)/0x\1,/g' \
|
||||
-e 's/\(...\)/0\1,/g' \
|
||||
-e 's/$/ \\/'
|
||||
echo ''
|
||||
|
||||
|
||||
+1
-349
@@ -5,8 +5,6 @@
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
INSERT
|
||||
|
||||
config FEATURE_SEAMLESS_XZ
|
||||
bool "Make tar, rpm, modprobe etc understand .xz data"
|
||||
default y
|
||||
@@ -37,352 +35,6 @@ config FEATURE_SEAMLESS_Z
|
||||
help
|
||||
Make tar, rpm, modprobe etc understand .Z data.
|
||||
|
||||
config AR
|
||||
bool "ar"
|
||||
default n # needs to be improved to be able to replace binutils ar
|
||||
help
|
||||
ar is an archival utility program used to create, modify, and
|
||||
extract contents from archives. An archive is a single file holding
|
||||
a collection of other files in a structure that makes it possible to
|
||||
retrieve the original individual files (called archive members).
|
||||
The original files' contents, mode (permissions), timestamp, owner,
|
||||
and group are preserved in the archive, and can be restored on
|
||||
extraction.
|
||||
|
||||
The stored filename is limited to 15 characters. (for more information
|
||||
see long filename support).
|
||||
ar has 60 bytes of overheads for every stored file.
|
||||
|
||||
This implementation of ar can extract archives, it cannot create or
|
||||
modify them.
|
||||
On an x86 system, the ar applet adds about 1K.
|
||||
|
||||
Unless you have a specific application which requires ar, you should
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_AR_LONG_FILENAMES
|
||||
bool "Support for long filenames (not needed for debs)"
|
||||
default y
|
||||
depends on AR
|
||||
help
|
||||
By default the ar format can only store the first 15 characters
|
||||
of the filename, this option removes that limitation.
|
||||
It supports the GNU ar long filename method which moves multiple long
|
||||
filenames into a the data section of a new ar entry.
|
||||
|
||||
config FEATURE_AR_CREATE
|
||||
bool "Support archive creation"
|
||||
default y
|
||||
depends on AR
|
||||
help
|
||||
This enables archive creation (-c and -r) with busybox ar.
|
||||
|
||||
config BUNZIP2
|
||||
bool "bunzip2"
|
||||
default y
|
||||
help
|
||||
bunzip2 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 bunzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config BZIP2
|
||||
bool "bzip2"
|
||||
default y
|
||||
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 y
|
||||
help
|
||||
cpio is an archival utility program used to create, modify, and
|
||||
extract contents from archives.
|
||||
cpio has 110 bytes of overheads for every stored file.
|
||||
|
||||
This implementation of cpio can extract cpio archives created in the
|
||||
"newc" or "crc" format, it cannot create or modify them.
|
||||
|
||||
Unless you have a specific application which requires cpio, you
|
||||
should probably say N here.
|
||||
|
||||
config FEATURE_CPIO_O
|
||||
bool "Support for archive creation"
|
||||
default y
|
||||
depends on CPIO
|
||||
help
|
||||
This implementation of cpio can create cpio archives in the "newc"
|
||||
format only.
|
||||
|
||||
config FEATURE_CPIO_P
|
||||
bool "Support for passthrough mode"
|
||||
default y
|
||||
depends on FEATURE_CPIO_O
|
||||
help
|
||||
Passthrough mode. Rarely used.
|
||||
|
||||
config DPKG
|
||||
bool "dpkg"
|
||||
default n
|
||||
select FEATURE_SEAMLESS_GZ
|
||||
help
|
||||
dpkg is a medium-level tool to install, build, remove and manage
|
||||
Debian packages.
|
||||
|
||||
This implementation of dpkg has a number of limitations,
|
||||
you should use the official dpkg if possible.
|
||||
|
||||
config DPKG_DEB
|
||||
bool "dpkg_deb"
|
||||
default n
|
||||
select FEATURE_SEAMLESS_GZ
|
||||
help
|
||||
dpkg-deb unpacks and provides information about Debian archives.
|
||||
|
||||
This implementation of dpkg-deb cannot pack archives.
|
||||
|
||||
Unless you have a specific application which requires dpkg-deb,
|
||||
say N here.
|
||||
|
||||
config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool "Extract only (-x)"
|
||||
default n
|
||||
depends on DPKG_DEB
|
||||
help
|
||||
This reduces dpkg-deb to the equivalent of
|
||||
"ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
|
||||
of the extra dpkg-deb, ar or tar options are needed, they are linked
|
||||
to internally.
|
||||
|
||||
config GUNZIP
|
||||
bool "gunzip"
|
||||
default y
|
||||
help
|
||||
gunzip is used to decompress archives created by gzip.
|
||||
You can use the `-t' option to test the integrity of
|
||||
an archive, without decompressing it.
|
||||
|
||||
config GZIP
|
||||
bool "gzip"
|
||||
default y
|
||||
help
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config FEATURE_GZIP_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default y
|
||||
depends on GZIP && LONG_OPTS
|
||||
help
|
||||
Enable use of long options, increases size by about 106 Bytes
|
||||
|
||||
config GZIP_FAST
|
||||
int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
|
||||
default 0
|
||||
range 0 2
|
||||
depends on GZIP
|
||||
help
|
||||
Enable big memory options for gzip.
|
||||
0: small buffers, small hash-tables
|
||||
1: larger buffers, larger hash-tables
|
||||
2: larger buffers, largest hash-tables
|
||||
Larger models may give slightly better compression
|
||||
|
||||
config LZOP
|
||||
bool "lzop"
|
||||
default y
|
||||
help
|
||||
Lzop compression/decompresion.
|
||||
|
||||
config LZOP_COMPR_HIGH
|
||||
bool "lzop compression levels 7,8,9 (not very useful)"
|
||||
default n
|
||||
depends on LZOP
|
||||
help
|
||||
High levels (7,8,9) of lzop compression. These levels
|
||||
are actually slower than gzip at equivalent compression ratios
|
||||
and take up 3.2K of code.
|
||||
|
||||
config RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
default y
|
||||
help
|
||||
Converts a RPM file into a CPIO archive.
|
||||
|
||||
config RPM
|
||||
bool "rpm"
|
||||
default y
|
||||
help
|
||||
Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
config TAR
|
||||
bool "tar"
|
||||
default y
|
||||
help
|
||||
tar is an archiving program. It's commonly used with gzip to
|
||||
create compressed archives. It's probably the most widely used
|
||||
UNIX archive program.
|
||||
|
||||
config FEATURE_TAR_CREATE
|
||||
bool "Enable archive creation"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to create
|
||||
tar archives using the `-c' option.
|
||||
|
||||
config FEATURE_TAR_AUTODETECT
|
||||
bool "Autodetect compressed tarballs"
|
||||
default y
|
||||
depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
|
||||
help
|
||||
With this option tar can automatically detect compressed
|
||||
tarballs. Currently it works only on files (not pipes etc).
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
bool "Support for old tar header format"
|
||||
default y
|
||||
depends on TAR || DPKG
|
||||
help
|
||||
This option is required to unpack archives created in
|
||||
the old GNU format; help to kill this old format by
|
||||
repacking your ancient archives with the new format.
|
||||
|
||||
config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
|
||||
default y
|
||||
depends on TAR || DPKG
|
||||
help
|
||||
This option is required to unpack archives created by some old
|
||||
version of Sun's tar (it was calculating checksum using signed
|
||||
arithmetic). It is said to be fixed in newer Sun tar, but "old"
|
||||
tarballs still exist.
|
||||
|
||||
config FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool "Support for GNU tar extensions (long filenames)"
|
||||
default y
|
||||
depends on TAR || DPKG
|
||||
help
|
||||
With this option busybox supports GNU long filenames and
|
||||
linknames.
|
||||
|
||||
config FEATURE_TAR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default y
|
||||
depends on TAR && LONG_OPTS
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config FEATURE_TAR_TO_COMMAND
|
||||
bool "Support for writing to an external program"
|
||||
default y
|
||||
depends on TAR && FEATURE_TAR_LONG_OPTIONS
|
||||
help
|
||||
If you enable this option you'll be able to instruct tar to send
|
||||
the contents of each extracted file to the standard input of an
|
||||
external program.
|
||||
|
||||
config FEATURE_TAR_UNAME_GNAME
|
||||
bool "Enable use of user and group names"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
Enables use of user and group names in tar. This affects contents
|
||||
listings (-t) and preserving permissions when unpacking (-p).
|
||||
+200 bytes.
|
||||
|
||||
config FEATURE_TAR_NOPRESERVE_TIME
|
||||
bool "Enable -m (do not preserve time) option"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
With this option busybox supports GNU tar -m
|
||||
(do not preserve time) option.
|
||||
|
||||
config FEATURE_TAR_SELINUX
|
||||
bool "Support for extracting SELinux labels"
|
||||
default n
|
||||
depends on TAR && SELINUX
|
||||
help
|
||||
With this option busybox supports restoring SELinux labels
|
||||
when extracting files from tar archives.
|
||||
|
||||
config UNCOMPRESS
|
||||
bool "uncompress"
|
||||
default n
|
||||
help
|
||||
uncompress is used to decompress archives created by compress.
|
||||
Not much used anymore, replaced by gzip/gunzip.
|
||||
|
||||
config UNLZMA
|
||||
bool "unlzma"
|
||||
default y
|
||||
help
|
||||
unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
compression algorithm, and range coding. Compression
|
||||
is generally considerably better than that achieved by the bzip2
|
||||
compressors.
|
||||
|
||||
The BusyBox unlzma applet is limited to decompression only.
|
||||
On an x86 system, this applet adds about 4K.
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimize unlzma for speed"
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
This option reduces decompression time by about 25% at the cost of
|
||||
a 1K bigger binary.
|
||||
|
||||
config LZMA
|
||||
bool "Provide lzma alias which supports only unpacking"
|
||||
default y
|
||||
depends on UNLZMA
|
||||
help
|
||||
Enable this option if you want commands like "lzma -d" to work.
|
||||
IOW: you'll get lzma applet, but it will always require -d option.
|
||||
|
||||
config UNXZ
|
||||
bool "unxz"
|
||||
default y
|
||||
help
|
||||
unxz is a unlzma successor.
|
||||
|
||||
config XZ
|
||||
bool "Provide xz alias which supports only unpacking"
|
||||
default y
|
||||
depends on UNXZ
|
||||
help
|
||||
Enable this option if you want commands like "xz -d" to work.
|
||||
IOW: you'll get xz applet, but it will always require -d option.
|
||||
|
||||
config UNZIP
|
||||
bool "unzip"
|
||||
default y
|
||||
help
|
||||
unzip will list or extract files from a ZIP archive,
|
||||
commonly found on DOS/WIN systems. The default behavior
|
||||
(with no options) is to extract the archive into the
|
||||
current directory. Use the `-d' option to extract to a
|
||||
directory of your choice.
|
||||
INSERT
|
||||
|
||||
endmenu
|
||||
@@ -9,22 +9,3 @@ libs-y += libarchive/
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
|
||||
|
||||
lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
@@ -17,6 +17,49 @@
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
|
||||
//config:config AR
|
||||
//config: bool "ar"
|
||||
//config: default n # needs to be improved to be able to replace binutils ar
|
||||
//config: help
|
||||
//config: ar is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives. An archive is a single file holding
|
||||
//config: a collection of other files in a structure that makes it possible to
|
||||
//config: retrieve the original individual files (called archive members).
|
||||
//config: The original files' contents, mode (permissions), timestamp, owner,
|
||||
//config: and group are preserved in the archive, and can be restored on
|
||||
//config: extraction.
|
||||
//config:
|
||||
//config: The stored filename is limited to 15 characters. (for more information
|
||||
//config: see long filename support).
|
||||
//config: ar has 60 bytes of overheads for every stored file.
|
||||
//config:
|
||||
//config: This implementation of ar can extract archives, it cannot create or
|
||||
//config: modify them.
|
||||
//config: On an x86 system, the ar applet adds about 1K.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires ar, you should
|
||||
//config: probably say N here.
|
||||
//config:
|
||||
//config:config FEATURE_AR_LONG_FILENAMES
|
||||
//config: bool "Support for long filenames (not needed for debs)"
|
||||
//config: default y
|
||||
//config: depends on AR
|
||||
//config: help
|
||||
//config: By default the ar format can only store the first 15 characters
|
||||
//config: of the filename, this option removes that limitation.
|
||||
//config: It supports the GNU ar long filename method which moves multiple long
|
||||
//config: filenames into a the data section of a new ar entry.
|
||||
//config:
|
||||
//config:config FEATURE_AR_CREATE
|
||||
//config: bool "Support archive creation"
|
||||
//config: default y
|
||||
//config: depends on AR
|
||||
//config: help
|
||||
//config: This enables archive creation (-c and -r) with busybox ar.
|
||||
|
||||
//applet:IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_AR) += ar.o
|
||||
|
||||
//usage:#define ar_trivial_usage
|
||||
//usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
|
||||
//usage:#define ar_full_usage "\n\n"
|
||||
|
||||
+165
-44
@@ -7,13 +7,19 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
/* lzop_main() uses bbunpack(), need this: */
|
||||
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
|
||||
|
||||
/* Note: must be kept in sync with archival/lzop.c */
|
||||
enum {
|
||||
OPT_STDOUT = 1 << 0,
|
||||
OPT_FORCE = 1 << 1,
|
||||
/* only some decompressors: */
|
||||
OPT_VERBOSE = 1 << 2,
|
||||
OPT_DECOMPRESS = 1 << 3,
|
||||
OPT_TEST = 1 << 4,
|
||||
OPT_QUIET = 1 << 3,
|
||||
OPT_DECOMPRESS = 1 << 4,
|
||||
OPT_TEST = 1 << 5,
|
||||
SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION,
|
||||
};
|
||||
|
||||
static
|
||||
@@ -39,7 +45,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
IF_DESKTOP(long long) int status;
|
||||
IF_DESKTOP(long long) int status = 0;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
transformer_aux_data_t aux;
|
||||
@@ -54,13 +60,27 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
bb_simple_perror_msg(filename);
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
err_name:
|
||||
bb_simple_perror_msg(filename);
|
||||
err:
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
} else {
|
||||
/* "clever zcat" with FILE */
|
||||
int fd = open_zipped(filename);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
}
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
} else
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -68,7 +88,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
|
||||
if (option_mask32 & OPT_TEST)
|
||||
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
|
||||
goto err;
|
||||
xfunc_die();
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
@@ -93,23 +113,32 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
|
||||
if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = 1;
|
||||
status = unpacker(&aux);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = 1;
|
||||
status = unpacker(&aux);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
} else {
|
||||
if (bb_copyfd_eof(STDIN_FILENO, STDOUT_FILENO) < 0)
|
||||
/* Disk full, tty closed, etc. No point in continuing */
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
if (!(option_mask32 & OPT_STDOUT))
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
|
||||
if (status >= 0) {
|
||||
unsigned new_name_len;
|
||||
|
||||
/* TODO: restore other things? */
|
||||
if (aux.mtime != 0) {
|
||||
struct timeval times[2];
|
||||
@@ -123,22 +152,29 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
utimes(new_name, times); /* ignoring errors */
|
||||
}
|
||||
|
||||
/* Delete _compressed_ file */
|
||||
if (ENABLE_DESKTOP)
|
||||
new_name_len = strlen(new_name);
|
||||
/* Restore source filename (unless tgz -> tar case) */
|
||||
if (new_name == filename) {
|
||||
new_name_len = strlen(filename);
|
||||
filename[new_name_len] = '.';
|
||||
}
|
||||
/* Extreme bloat for gunzip compat */
|
||||
/* Some users do want this info... */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) {
|
||||
unsigned percent = status
|
||||
? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
|
||||
: 0;
|
||||
fprintf(stderr, "%s: %u%% - replaced with %.*s\n",
|
||||
filename,
|
||||
100u - percent,
|
||||
new_name_len, new_name
|
||||
);
|
||||
}
|
||||
/* Delete _source_ file */
|
||||
del = filename;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
if (new_name == filename)
|
||||
filename[strlen(filename)] = '.';
|
||||
}
|
||||
xunlink(del);
|
||||
|
||||
#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
|
||||
/* Extreme bloat for gunzip compat */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
free_name:
|
||||
if (new_name != filename)
|
||||
free(new_name);
|
||||
@@ -172,7 +208,6 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//usage:#define uncompress_trivial_usage
|
||||
//usage: "[-cf] [FILE]..."
|
||||
//usage:#define uncompress_full_usage "\n\n"
|
||||
@@ -180,6 +215,15 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Overwrite"
|
||||
|
||||
//config:config UNCOMPRESS
|
||||
//config: bool "uncompress"
|
||||
//config: default n
|
||||
//config: help
|
||||
//config: uncompress is used to decompress archives created by compress.
|
||||
//config: Not much used anymore, replaced by gzip/gunzip.
|
||||
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
#if ENABLE_UNCOMPRESS
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
|
||||
@@ -220,11 +264,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
//usage:#define gunzip_trivial_usage
|
||||
//usage: "[-cft] [FILE]..."
|
||||
//usage:#define gunzip_full_usage "\n\n"
|
||||
@@ -241,10 +281,22 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar\n"
|
||||
//usage:
|
||||
//usage:#define zcat_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define zcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config GUNZIP
|
||||
//config: bool "gunzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: gunzip is used to decompress archives created by gzip.
|
||||
//config: You can use the `-t' option to test the integrity of
|
||||
//config: an archive, without decompressing it.
|
||||
|
||||
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
|
||||
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
#if ENABLE_GUNZIP
|
||||
static
|
||||
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
|
||||
@@ -292,11 +344,15 @@ IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
|
||||
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdtn");
|
||||
getopt32(argv, "cfvqdtn");
|
||||
argv += optind;
|
||||
/* if called as zcat */
|
||||
|
||||
/* If called as zcat...
|
||||
* Normally, "zcat" is just "gunzip -c".
|
||||
* But if seamless magic is enabled, then we are much more clever.
|
||||
*/
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
@@ -316,11 +372,27 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage:#define bzcat_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define bzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config BUNZIP2
|
||||
//config: bool "bunzip2"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: bunzip2 is a compression utility using the Burrows-Wheeler block
|
||||
//config: sorting text compression algorithm, and Huffman coding. Compression
|
||||
//config: is generally considerably better than that achieved by more
|
||||
//config: conventional LZ77/LZ78-based compressors, and approaches the
|
||||
//config: performance of the PPM family of statistical compressors.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires bunzip2, you
|
||||
//config: should probably say N here.
|
||||
|
||||
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
#if ENABLE_BUNZIP2
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
||||
@@ -330,7 +402,7 @@ IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdt");
|
||||
getopt32(argv, "cfvqdt");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
@@ -348,7 +420,6 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//usage:#define unlzma_trivial_usage
|
||||
//usage: "[-cf] [FILE]..."
|
||||
//usage:#define unlzma_full_usage "\n\n"
|
||||
@@ -365,7 +436,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -f Force"
|
||||
//usage:
|
||||
//usage:#define lzcat_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define lzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
//usage:
|
||||
@@ -385,10 +456,42 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -f Force"
|
||||
//usage:
|
||||
//usage:#define xzcat_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define xzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config UNLZMA
|
||||
//config: bool "unlzma"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
//config: compression algorithm, and range coding. Compression
|
||||
//config: is generally considerably better than that achieved by the bzip2
|
||||
//config: compressors.
|
||||
//config:
|
||||
//config: The BusyBox unlzma applet is limited to decompression only.
|
||||
//config: On an x86 system, this applet adds about 4K.
|
||||
//config:
|
||||
//config:config FEATURE_LZMA_FAST
|
||||
//config: bool "Optimize unlzma for speed"
|
||||
//config: default n
|
||||
//config: depends on UNLZMA
|
||||
//config: help
|
||||
//config: This option reduces decompression time by about 25% at the cost of
|
||||
//config: a 1K bigger binary.
|
||||
//config:
|
||||
//config:config LZMA
|
||||
//config: bool "Provide lzma alias which supports only unpacking"
|
||||
//config: default y
|
||||
//config: depends on UNLZMA
|
||||
//config: help
|
||||
//config: Enable this option if you want commands like "lzma -d" to work.
|
||||
//config: IOW: you'll get lzma applet, but it will always require -d option.
|
||||
|
||||
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
|
||||
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
|
||||
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
#if ENABLE_UNLZMA
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
||||
@@ -398,7 +501,7 @@ IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfvdt");
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfvqdt");
|
||||
# if ENABLE_LZMA
|
||||
/* lzma without -d or -t? */
|
||||
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
@@ -414,6 +517,24 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
|
||||
//config:config UNXZ
|
||||
//config: bool "unxz"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unxz is a unlzma successor.
|
||||
//config:
|
||||
//config:config XZ
|
||||
//config: bool "Provide xz alias which supports only unpacking"
|
||||
//config: default y
|
||||
//config: depends on UNXZ
|
||||
//config: help
|
||||
//config: Enable this option if you want commands like "xz -d" to work.
|
||||
//config: IOW: you'll get xz applet, but it will always require -d option.
|
||||
|
||||
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
|
||||
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
|
||||
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
#if ENABLE_UNXZ
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
||||
@@ -423,7 +544,7 @@ IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_XZ(int opts =) getopt32(argv, "cfvdt");
|
||||
IF_XZ(int opts =) getopt32(argv, "cfvqdt");
|
||||
# if ENABLE_XZ
|
||||
/* xz without -d or -t? */
|
||||
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
|
||||
@@ -7,6 +7,22 @@
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
|
||||
//config:config BZIP2
|
||||
//config: bool "bzip2"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
//config: sorting text compression algorithm, and Huffman coding. Compression
|
||||
//config: is generally considerably better than that achieved by more
|
||||
//config: conventional LZ77/LZ78-based compressors, and approaches the
|
||||
//config: performance of the PPM family of statistical compressors.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires bzip2, you
|
||||
//config: should probably say N here.
|
||||
|
||||
//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
|
||||
|
||||
//usage:#define bzip2_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define bzip2_full_usage "\n\n"
|
||||
|
||||
+32
-1
@@ -9,11 +9,42 @@
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
//config:config CPIO
|
||||
//config: bool "cpio"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cpio is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives.
|
||||
//config: cpio has 110 bytes of overheads for every stored file.
|
||||
//config:
|
||||
//config: This implementation of cpio can extract cpio archives created in the
|
||||
//config: "newc" or "crc" format, it cannot create or modify them.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires cpio, you
|
||||
//config: should probably say N here.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_O
|
||||
//config: bool "Support for archive creation"
|
||||
//config: default y
|
||||
//config: depends on CPIO
|
||||
//config: help
|
||||
//config: This implementation of cpio can create cpio archives in the "newc"
|
||||
//config: format only.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_P
|
||||
//config: bool "Support for passthrough mode"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O
|
||||
//config: help
|
||||
//config: Passthrough mode. Rarely used.
|
||||
|
||||
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
|
||||
|
||||
//usage:#define cpio_trivial_usage
|
||||
//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
|
||||
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
|
||||
|
||||
+14
-2
@@ -14,7 +14,6 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* known difference between busybox dpkg and the official dpkg that i don't
|
||||
* consider important, its worth keeping a note of differences anyway, just to
|
||||
@@ -25,9 +24,22 @@
|
||||
*
|
||||
* bugs that need to be fixed
|
||||
* - (unknown, please let me know when you find any)
|
||||
*
|
||||
*/
|
||||
|
||||
//config:config DPKG
|
||||
//config: bool "dpkg"
|
||||
//config: default n
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg is a medium-level tool to install, build, remove and manage
|
||||
//config: Debian packages.
|
||||
//config:
|
||||
//config: This implementation of dpkg has a number of limitations,
|
||||
//config: you should use the official dpkg if possible.
|
||||
|
||||
//applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_DPKG) += dpkg.o
|
||||
|
||||
//usage:#define dpkg_trivial_usage
|
||||
//usage: "[-ilCPru] [-F OPT] PACKAGE"
|
||||
//usage:#define dpkg_full_usage "\n\n"
|
||||
|
||||
+26
-1
@@ -5,8 +5,33 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg_deb"
|
||||
//config: default n
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg-deb unpacks and provides information about Debian archives.
|
||||
//config:
|
||||
//config: This implementation of dpkg-deb cannot pack archives.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires dpkg-deb,
|
||||
//config: say N here.
|
||||
//config:
|
||||
//config:config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
//config: bool "Extract only (-x)"
|
||||
//config: default n
|
||||
//config: depends on DPKG_DEB
|
||||
//config: help
|
||||
//config: This reduces dpkg-deb to the equivalent of
|
||||
//config: "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
|
||||
//config: of the extra dpkg-deb, ar or tar options are needed, they are linked
|
||||
//config: to internally.
|
||||
|
||||
//applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
|
||||
//kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
|
||||
//usage:#define dpkg_deb_trivial_usage
|
||||
//usage: "[-cefxX] FILE [argument"
|
||||
//usage: "[-cefxX] FILE [argument]"
|
||||
//usage:#define dpkg_deb_full_usage "\n\n"
|
||||
//usage: "Perform actions on Debian packages (.debs)\n"
|
||||
//usage: "\n -c List contents of filesystem tree"
|
||||
|
||||
+29
-2
@@ -15,7 +15,6 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* big objects in bss:
|
||||
* 00000020 b bl_count
|
||||
* 00000074 b base_length
|
||||
@@ -31,7 +30,6 @@
|
||||
* 00000480 b static_ltree
|
||||
* 000008f4 b dyn_ltree
|
||||
*/
|
||||
|
||||
/* TODO: full support for -v for DESKTOP
|
||||
* "/usr/bin/gzip -v a bogus aa" should say:
|
||||
a: 85.1% -- replaced with a.gz
|
||||
@@ -39,6 +37,35 @@ gzip: bogus: No such file or directory
|
||||
aa: 85.1% -- replaced with aa.gz
|
||||
*/
|
||||
|
||||
//config:config GZIP
|
||||
//config: bool "gzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: gzip is used to compress files.
|
||||
//config: It's probably the most widely used UNIX compression program.
|
||||
//config:
|
||||
//config:config FEATURE_GZIP_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on GZIP && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable use of long options, increases size by about 106 Bytes
|
||||
//config:
|
||||
//config:config GZIP_FAST
|
||||
//config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
|
||||
//config: default 0
|
||||
//config: range 0 2
|
||||
//config: depends on GZIP
|
||||
//config: help
|
||||
//config: Enable big memory options for gzip.
|
||||
//config: 0: small buffers, small hash-tables
|
||||
//config: 1: larger buffers, larger hash-tables
|
||||
//config: 2: larger buffers, largest hash-tables
|
||||
//config: Larger models may give slightly better compression
|
||||
|
||||
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
|
||||
|
||||
//usage:#define gzip_trivial_usage
|
||||
//usage: "[-cfd] [FILE]..."
|
||||
//usage:#define gzip_full_usage "\n\n"
|
||||
|
||||
@@ -38,31 +38,45 @@ DPKG_FILES:= \
|
||||
|
||||
INSERT
|
||||
|
||||
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_UNXZ) += decompress_unxz.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += decompress_gunzip.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
|
||||
lib-$(CONFIG_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_LZOP) += open_transformer.o
|
||||
lib-$(CONFIG_MAN) += open_transformer.o
|
||||
lib-$(CONFIG_SETFONT) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_2_4_MODULES) += open_transformer.o
|
||||
lib-$(CONFIG_MODINFO) += open_transformer.o
|
||||
lib-$(CONFIG_INSMOD) += open_transformer.o
|
||||
lib-$(CONFIG_DEPMOD) += open_transformer.o
|
||||
lib-$(CONFIG_RMMOD) += open_transformer.o
|
||||
lib-$(CONFIG_LSMOD) += open_transformer.o
|
||||
lib-$(CONFIG_MODPROBE) += open_transformer.o
|
||||
lib-$(CONFIG_MODPROBE_SMALL) += open_transformer.o
|
||||
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o
|
||||
|
||||
ifneq ($(lib-y),)
|
||||
lib-y += $(COMMON_FILES)
|
||||
|
||||
@@ -249,7 +249,7 @@ void generateMTFValues(EState* s)
|
||||
static NOINLINE
|
||||
void sendMTFValues(EState* s)
|
||||
{
|
||||
int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||
int32_t v, t, i, j, gs, ge, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups;
|
||||
|
||||
@@ -345,7 +345,6 @@ void sendMTFValues(EState* s)
|
||||
}
|
||||
#endif
|
||||
nSelectors = 0;
|
||||
totc = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
/*--- Set group start & end marks. --*/
|
||||
@@ -411,7 +410,6 @@ void sendMTFValues(EState* s)
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
totc += bc;
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
@@ -501,14 +499,14 @@ void sendMTFValues(EState* s)
|
||||
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);
|
||||
((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4])
|
||||
| *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8])
|
||||
| *(bb__aliased_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);
|
||||
((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,15 +106,28 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
char *dst_name;
|
||||
int flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
dst_fd = xopen3(file_header->name,
|
||||
dst_name = file_header->name;
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
|
||||
/* rpm-style temp file name */
|
||||
dst_name = xasprintf("%s;%x", dst_name, (int)getpid());
|
||||
#endif
|
||||
dst_fd = xopen3(dst_name,
|
||||
flags,
|
||||
file_header->mode
|
||||
);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) {
|
||||
xrename(dst_name, file_header->name);
|
||||
free(dst_name);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
|
||||
@@ -103,7 +103,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
|
||||
archive_handle->tar__to_command_shell,
|
||||
"-c",
|
||||
archive_handle->tar__to_command,
|
||||
NULL);
|
||||
(char *)0);
|
||||
bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell);
|
||||
}
|
||||
close(p[0]);
|
||||
|
||||
@@ -42,6 +42,12 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if 0
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
#else
|
||||
# define dbg(...) ((void)0)
|
||||
#endif
|
||||
|
||||
/* Constants for Huffman coding */
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
@@ -52,13 +58,13 @@
|
||||
|
||||
/* Status return values */
|
||||
#define RETVAL_OK 0
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_SHORT_WRITE (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
#define RETVAL_LAST_BLOCK (dbg("%d", __LINE__), -1)
|
||||
#define RETVAL_NOT_BZIP_DATA (dbg("%d", __LINE__), -2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (dbg("%d", __LINE__), -3)
|
||||
#define RETVAL_SHORT_WRITE (dbg("%d", __LINE__), -4)
|
||||
#define RETVAL_DATA_ERROR (dbg("%d", __LINE__), -5)
|
||||
#define RETVAL_OUT_OF_MEMORY (dbg("%d", __LINE__), -6)
|
||||
#define RETVAL_OBSOLETE_INPUT (dbg("%d", __LINE__), -7)
|
||||
|
||||
/* Other housekeeping constants */
|
||||
#define IOBUF_SIZE 4096
|
||||
@@ -440,7 +446,11 @@ static int get_next_block(bunzip_data *bd)
|
||||
literal used is the one at the head of the mtfSymbol array.) */
|
||||
if (runPos != 0) {
|
||||
uint8_t tmp_byte;
|
||||
if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
if (dbufCount + runCnt > dbufSize) {
|
||||
dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR",
|
||||
dbufCount, runCnt, dbufCount + runCnt, dbufSize);
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
tmp_byte = symToByte[mtfSymbol[0]];
|
||||
byteCount[tmp_byte] += runCnt;
|
||||
while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte;
|
||||
@@ -808,7 +818,6 @@ static char *const bunzip_errors[] = {
|
||||
/* Dumb little test thing, decompress stdin to stdout */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
|
||||
int i = unpack_bz2_stream(0, 1);
|
||||
|
||||
@@ -336,7 +336,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
}
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
for (j = 1; (c[j] == 0) && (j <= BMAX); j++)
|
||||
for (j = 1; (j <= BMAX) && (c[j] == 0); j++)
|
||||
continue;
|
||||
k = j; /* minimum code length */
|
||||
for (i = BMAX; (c[i] == 0) && i; i--)
|
||||
|
||||
@@ -45,16 +45,16 @@ typedef struct {
|
||||
#define RC_MODEL_TOTAL_BITS 11
|
||||
|
||||
|
||||
/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
|
||||
static size_inline void rc_read(rc_t *rc)
|
||||
/* Called once in rc_do_normalize() */
|
||||
static void rc_read(rc_t *rc)
|
||||
{
|
||||
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
|
||||
//TODO: return -1 instead
|
||||
//This will make unlzma delete broken unpacked file on unpack errors
|
||||
if (buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = RC_BUFFER;
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
rc->ptr = RC_BUFFER;
|
||||
}
|
||||
|
||||
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
|
||||
@@ -65,6 +65,12 @@ static void rc_do_normalize(rc_t *rc)
|
||||
rc->range <<= 8;
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
@@ -78,15 +84,9 @@ static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
/* rc->ptr = rc->buffer_end; */
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
if (rc->ptr >= rc->buffer_end)
|
||||
rc_read(rc);
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
#else
|
||||
rc_do_normalize(rc);
|
||||
#endif
|
||||
}
|
||||
rc->range = 0xFFFFFFFF;
|
||||
rc->range = 0xffffffff;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -96,13 +96,6 @@ static ALWAYS_INLINE void rc_free(rc_t *rc)
|
||||
free(rc);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* rc_is_bit_1 is called 9 times */
|
||||
static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
|
||||
{
|
||||
@@ -120,7 +113,7 @@ static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
|
||||
}
|
||||
|
||||
/* Called 4 times in unlzma loop */
|
||||
static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
|
||||
static ALWAYS_INLINE int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
|
||||
{
|
||||
int ret = rc_is_bit_1(rc, p);
|
||||
*symbol = *symbol * 2 + ret;
|
||||
|
||||
@@ -30,8 +30,8 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
/* We use arch-optimized unaligned accessors */
|
||||
#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
|
||||
#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
|
||||
#define put_unaligned_le32(val, buf) move_to_unaligned16(buf, SWAP_LE32(val))
|
||||
#define put_unaligned_be32(val, buf) move_to_unaligned16(buf, SWAP_BE32(val))
|
||||
#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
|
||||
#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
|
||||
|
||||
#include "unxz/xz_dec_bcj.c"
|
||||
#include "unxz/xz_dec_lzma2.c"
|
||||
@@ -40,6 +40,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
enum xz_ret xz_result;
|
||||
struct xz_buf iobuf;
|
||||
struct xz_dec *state;
|
||||
unsigned char *membuf;
|
||||
@@ -63,9 +64,8 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
/* Limit memory usage to about 64 MiB. */
|
||||
state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
|
||||
|
||||
xz_result = X_OK;
|
||||
while (1) {
|
||||
enum xz_ret r;
|
||||
|
||||
if (iobuf.in_pos == iobuf.in_size) {
|
||||
int rd = safe_read(src_fd, membuf, BUFSIZ);
|
||||
if (rd < 0) {
|
||||
@@ -73,28 +73,57 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
if (rd == 0 && xz_result == XZ_STREAM_END)
|
||||
break;
|
||||
iobuf.in_size = rd;
|
||||
iobuf.in_pos = 0;
|
||||
}
|
||||
if (xz_result == XZ_STREAM_END) {
|
||||
/*
|
||||
* Try to start decoding next concatenated stream.
|
||||
* Stream padding must always be a multiple of four
|
||||
* bytes to preserve four-byte alignment. To keep the
|
||||
* code slightly smaller, we aren't as strict here as
|
||||
* the .xz spec requires. We just skip all zero-bytes
|
||||
* without checking the alignment and thus can accept
|
||||
* files that aren't valid, e.g. the XZ utils test
|
||||
* files bad-0pad-empty.xz and bad-0catpad-empty.xz.
|
||||
*/
|
||||
do {
|
||||
if (membuf[iobuf.in_pos] != 0) {
|
||||
xz_dec_reset(state);
|
||||
goto do_run;
|
||||
}
|
||||
iobuf.in_pos++;
|
||||
} while (iobuf.in_pos < iobuf.in_size);
|
||||
}
|
||||
do_run:
|
||||
// bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
|
||||
r = xz_dec_run(state, &iobuf);
|
||||
xz_result = xz_dec_run(state, &iobuf);
|
||||
// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, r);
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
|
||||
if (iobuf.out_pos) {
|
||||
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
|
||||
IF_DESKTOP(total += iobuf.out_pos;)
|
||||
iobuf.out_pos = 0;
|
||||
}
|
||||
if (r == XZ_STREAM_END) {
|
||||
break;
|
||||
if (xz_result == XZ_STREAM_END) {
|
||||
/*
|
||||
* Can just "break;" here, if not for concatenated
|
||||
* .xz streams.
|
||||
* Checking for padding may require buffer
|
||||
* replenishment. Can't do it here.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
if (r != XZ_OK && r != XZ_UNSUPPORTED_CHECK) {
|
||||
if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
xz_dec_end(state);
|
||||
free(membuf);
|
||||
|
||||
|
||||
@@ -8,11 +8,19 @@
|
||||
#include "bb_archive.h"
|
||||
#include "ar.h"
|
||||
|
||||
static unsigned read_num(const char *str, int base)
|
||||
/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
|
||||
static unsigned read_num(char *str, int base, int len)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* ar fields are fixed length text strings (padded with spaces).
|
||||
* Ensure bb_strtou doesn't read past the field in case the full
|
||||
* width is used. */
|
||||
str[len] = 0;
|
||||
|
||||
/* This code works because
|
||||
* on misformatted numbers bb_strtou returns all-ones */
|
||||
int err = bb_strtou(str, NULL, base);
|
||||
err = bb_strtou(str, NULL, base);
|
||||
if (err == -1)
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
return err;
|
||||
@@ -51,11 +59,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
/* FIXME: more thorough routine would be in order here
|
||||
* (we have something like that in tar)
|
||||
* but for now we are lax. */
|
||||
ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */
|
||||
typed->size = size = read_num(ar.formatted.size, 10);
|
||||
/*
|
||||
* Note that the fields MUST be read in reverse order as
|
||||
* read_num() clobbers the next byte after the field!
|
||||
* Order is: name, date, uid, gid, mode, size, magic.
|
||||
*/
|
||||
typed->size = size = read_num(ar.formatted.size, 10,
|
||||
sizeof(ar.formatted.size));
|
||||
|
||||
/* special filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
@@ -87,10 +97,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
* long filename pseudo file. Thus we decode the rest
|
||||
* after dealing with long filename pseudo file.
|
||||
*/
|
||||
typed->mode = read_num(ar.formatted.mode, 8);
|
||||
typed->mtime = read_num(ar.formatted.date, 10);
|
||||
typed->uid = read_num(ar.formatted.uid, 10);
|
||||
typed->gid = read_num(ar.formatted.gid, 10);
|
||||
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
|
||||
typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
|
||||
typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
|
||||
typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));
|
||||
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
@@ -98,7 +108,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in ar_long_names) that conatains the real filename */
|
||||
long_offset = read_num(&ar.formatted.name[1], 10);
|
||||
long_offset = read_num(&ar.formatted.name[1], 10,
|
||||
sizeof(ar.formatted.name) - 1);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
|
||||
@@ -198,13 +198,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* the message and we don't check whether we indeed
|
||||
* saw zero block directly before this. */
|
||||
if (i == 0) {
|
||||
xfunc_error_retval = 0;
|
||||
short_read:
|
||||
bb_error_msg_and_die("short read");
|
||||
bb_error_msg("short read");
|
||||
/* this merely signals end of archive, not exit(1): */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (i != 512) {
|
||||
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
|
||||
goto short_read;
|
||||
bb_error_msg_and_die("short read");
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -221,10 +221,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
*/
|
||||
while (full_read(archive_handle->src_fd, &tar, 512) == 512)
|
||||
continue;
|
||||
return EXIT_FAILURE;
|
||||
return EXIT_FAILURE; /* "end of archive" */
|
||||
}
|
||||
archive_handle->tar__end = 1;
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS; /* "decoded one header" */
|
||||
}
|
||||
archive_handle->tar__end = 0;
|
||||
|
||||
@@ -471,5 +471,5 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
free(file_header->tar__uname);
|
||||
free(file_header->tar__gname);
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS; /* "decoded one header" */
|
||||
}
|
||||
@@ -76,11 +76,13 @@
|
||||
# define TEST_IP (ip < ip_end)
|
||||
# define NEED_IP(x) \
|
||||
if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
|
||||
# define TEST_IV(x) if ((x) > (unsigned)0 - (511)) goto input_overrun
|
||||
|
||||
# undef TEST_OP /* don't need both of the tests here */
|
||||
# define TEST_OP 1
|
||||
# define NEED_OP(x) \
|
||||
if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
|
||||
# define TEST_OV(x) if ((x) > (unsigned)0 - (511)) goto output_overrun
|
||||
|
||||
#define HAVE_ANY_OP 1
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ typedef struct {
|
||||
( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) )
|
||||
|
||||
#if defined(LZO_UNALIGNED_OK_2)
|
||||
# define HEAD2(b,p) (* (uint16_t *) &(b[p]))
|
||||
# define HEAD2(b,p) (* (bb__aliased_uint16_t *) &(b[p]))
|
||||
#else
|
||||
# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8))
|
||||
#endif
|
||||
@@ -466,7 +466,6 @@ static int find_match(lzo1x_999_t *c, lzo_swd_p s,
|
||||
}
|
||||
|
||||
s->m_len = 1;
|
||||
s->m_len = 1;
|
||||
#ifdef SWD_BEST_OFF
|
||||
if (s->use_best_off)
|
||||
memset(s->best_pos, 0, sizeof(s->best_pos));
|
||||
|
||||
@@ -92,6 +92,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 15 + *ip++;
|
||||
}
|
||||
/* copy literals */
|
||||
@@ -224,6 +225,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 31 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
@@ -265,6 +267,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 7 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
|
||||
@@ -34,6 +34,7 @@ void check_errors_in_children(int signo)
|
||||
if (!signo) {
|
||||
/* block waiting for any child */
|
||||
if (wait(&status) < 0)
|
||||
//FIXME: check EINTR?
|
||||
return; /* probably there are no children */
|
||||
goto check_status;
|
||||
}
|
||||
@@ -41,14 +42,18 @@ void check_errors_in_children(int signo)
|
||||
/* Wait for any child without blocking */
|
||||
for (;;) {
|
||||
if (wait_any_nohang(&status) < 0)
|
||||
//FIXME: check EINTR?
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
check_status:
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||
/*if (WIFEXITED(status) && WEXITSTATUS(status) == 0)*/
|
||||
/* On Linux, the above can be checked simply as: */
|
||||
if (status == 0)
|
||||
/* this child exited with 0 */
|
||||
continue;
|
||||
/* Cannot happen?
|
||||
if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */
|
||||
/* Cannot happen:
|
||||
if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???;
|
||||
*/
|
||||
bb_got_signal = 1;
|
||||
}
|
||||
}
|
||||
@@ -74,16 +79,17 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
// FIXME: error check?
|
||||
#if BB_MMU
|
||||
{
|
||||
IF_DESKTOP(long long) int r;
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = check_signature;
|
||||
transformer(&aux, fd, fd_pipe.wr);
|
||||
r = transformer(&aux, fd, fd_pipe.wr);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe.wr); /* send EOF */
|
||||
close(fd);
|
||||
}
|
||||
/* must be _exit! bug was actually seen here */
|
||||
_exit(EXIT_SUCCESS);
|
||||
_exit(/*error if:*/ r < 0);
|
||||
}
|
||||
#else
|
||||
{
|
||||
@@ -176,27 +182,26 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname)
|
||||
{
|
||||
char *sfx;
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
sfx = strrchr(fname, '.');
|
||||
if (sfx) {
|
||||
sfx++;
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
|
||||
/* .lzma has no header/signature, just trust it */
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
|
||||
else
|
||||
if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
|
||||
) {
|
||||
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
if ((ENABLE_FEATURE_SEAMLESS_GZ)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_XZ)
|
||||
) {
|
||||
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ XZ Embedded
|
||||
|
||||
XZ Embedded was written for use in the Linux kernel, but the code can
|
||||
be easily used in other environments too, including regular userspace
|
||||
applications.
|
||||
applications. See userspace/xzminidec.c for an example program.
|
||||
|
||||
This README contains information that is useful only when the copy
|
||||
of XZ Embedded isn't part of the Linux kernel tree. You should also
|
||||
@@ -55,7 +55,7 @@ Compiler requirements
|
||||
code is modified not to support large files, which needs some more
|
||||
care than just using 32-bit integer instead of 64-bit).
|
||||
|
||||
If you use GCC, try to use a recent version. For example, on x86,
|
||||
If you use GCC, try to use a recent version. For example, on x86-32,
|
||||
xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when
|
||||
compiled with GCC 4.3.3.
|
||||
|
||||
@@ -93,7 +93,7 @@ BCJ filter support
|
||||
them always #defined doesn't hurt either.
|
||||
|
||||
#define Instruction set BCJ filter endianness
|
||||
XZ_DEC_X86 x86 or x86-64 Little endian only
|
||||
XZ_DEC_X86 x86-32 or x86-64 Little endian only
|
||||
XZ_DEC_POWERPC PowerPC Big endian only
|
||||
XZ_DEC_IA64 Itanium (IA-64) Big or little endian
|
||||
XZ_DEC_ARM ARM Little endian only
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In Linux, this is used to make extern functions static when needed. */
|
||||
#ifndef XZ_EXTERN
|
||||
# define XZ_EXTERN extern
|
||||
@@ -70,7 +74,7 @@ enum xz_mode {
|
||||
* @XZ_UNSUPPORTED_CHECK: Integrity check type is not supported. Decoding
|
||||
* is still possible in multi-call mode by simply
|
||||
* calling xz_dec_run() again.
|
||||
* NOTE: This return value is used only if
|
||||
* Note that this return value is used only if
|
||||
* XZ_DEC_ANY_CHECK was defined at build time,
|
||||
* which is not used in the kernel. Unsupported
|
||||
* check types return XZ_OPTIONS_ERROR if
|
||||
@@ -105,7 +109,7 @@ enum xz_mode {
|
||||
* stream that is truncated or otherwise corrupt.
|
||||
*
|
||||
* In single-call mode, XZ_BUF_ERROR is returned only when the output buffer
|
||||
* is too small, or the compressed input is corrupt in a way that makes the
|
||||
* is too small or the compressed input is corrupt in a way that makes the
|
||||
* decoder produce more output than the caller expected. When it is
|
||||
* (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR
|
||||
* is used instead of XZ_BUF_ERROR.
|
||||
@@ -207,8 +211,8 @@ XZ_EXTERN struct xz_dec * XZ_FUNC xz_dec_init(
|
||||
* The possible return values depend on build options and operation mode.
|
||||
* See enum xz_ret for details.
|
||||
*
|
||||
* NOTE: If an error occurs in single-call mode (return value is not
|
||||
* XZ_STREAM_END), b->in_pos and b->out_pos are not modified, and the
|
||||
* Note that if an error occurs in single-call mode (return value is not
|
||||
* XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the
|
||||
* contents of the output buffer from b->out[b->out_pos] onward are
|
||||
* undefined. This is true even after XZ_BUF_ERROR, because with some filter
|
||||
* chains, there may be a second pass over the output buffer, and this pass
|
||||
@@ -268,4 +272,9 @@ XZ_EXTERN void XZ_FUNC xz_crc32_init(void);
|
||||
XZ_EXTERN uint32_t XZ_FUNC xz_crc32(
|
||||
const uint8_t *buf, size_t size, uint32_t crc);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -77,10 +77,13 @@ struct xz_dec_bcj {
|
||||
|
||||
#ifdef XZ_DEC_X86
|
||||
/*
|
||||
* This is macro used to test the most significant byte of a memory address
|
||||
* This is used to test the most significant byte of a memory address
|
||||
* in an x86 instruction.
|
||||
*/
|
||||
#define bcj_x86_test_msbyte(b) ((b) == 0x00 || (b) == 0xFF)
|
||||
static inline int bcj_x86_test_msbyte(uint8_t b)
|
||||
{
|
||||
return b == 0x00 || b == 0xFF;
|
||||
}
|
||||
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_x86(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
@@ -443,8 +446,12 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||
* next filter in the chain. Apply the BCJ filter on the new data
|
||||
* in the output buffer. If everything cannot be filtered, copy it
|
||||
* to temp and rewind the output buffer position accordingly.
|
||||
*
|
||||
* This needs to be always run when temp.size == 0 to handle a special
|
||||
* case where the output buffer is full and the next filter has no
|
||||
* more output coming but hasn't returned XZ_STREAM_END yet.
|
||||
*/
|
||||
if (s->temp.size < b->out_size - b->out_pos) {
|
||||
if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
|
||||
out_start = b->out_pos;
|
||||
memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
|
||||
b->out_pos += s->temp.size;
|
||||
@@ -467,16 +474,25 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||
s->temp.size = b->out_pos - out_start;
|
||||
b->out_pos -= s->temp.size;
|
||||
memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
|
||||
|
||||
/*
|
||||
* If there wasn't enough input to the next filter to fill
|
||||
* the output buffer with unfiltered data, there's no point
|
||||
* to try decoding more data to temp.
|
||||
*/
|
||||
if (b->out_pos + s->temp.size < b->out_size)
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have unfiltered data in temp, try to fill by decoding more
|
||||
* data from the next filter. Apply the BCJ filter on temp. Then we
|
||||
* hopefully can fill the actual output buffer by copying filtered
|
||||
* data from temp. A mix of filtered and unfiltered data may be left
|
||||
* in temp; it will be taken care on the next call to this function.
|
||||
* We have unfiltered data in temp. If the output buffer isn't full
|
||||
* yet, try to fill the temp buffer by decoding more data from the
|
||||
* next filter. Apply the BCJ filter on temp. Then we hopefully can
|
||||
* fill the actual output buffer by copying filtered data from temp.
|
||||
* A mix of filtered and unfiltered data may be left in temp; it will
|
||||
* be taken care on the next call to this function.
|
||||
*/
|
||||
if (s->temp.size > 0) {
|
||||
if (b->out_pos < b->out_size) {
|
||||
/* Make b->out{,_pos,_size} temporarily point to s->temp. */
|
||||
s->out = b->out;
|
||||
s->out_pos = b->out_pos;
|
||||
|
||||
@@ -407,7 +407,6 @@ static void XZ_FUNC dict_uncompressed(
|
||||
|
||||
b->out_pos += copy_size;
|
||||
b->in_pos += copy_size;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -972,6 +971,9 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
*/
|
||||
tmp = b->in[b->in_pos++];
|
||||
|
||||
if (tmp == 0x00)
|
||||
return XZ_STREAM_END;
|
||||
|
||||
if (tmp >= 0xE0 || tmp == 0x01) {
|
||||
s->lzma2.need_props = true;
|
||||
s->lzma2.need_dict_reset = false;
|
||||
@@ -1004,9 +1006,6 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
lzma_reset(s);
|
||||
}
|
||||
} else {
|
||||
if (tmp == 0x00)
|
||||
return XZ_STREAM_END;
|
||||
|
||||
if (tmp > 0x02)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
|
||||
@@ -25,15 +25,20 @@
|
||||
|
||||
#define STREAM_HEADER_SIZE 12
|
||||
|
||||
#define HEADER_MAGIC "\3757zXZ\0"
|
||||
#define HEADER_MAGIC "\3757zXZ"
|
||||
#define HEADER_MAGIC_SIZE 6
|
||||
|
||||
#define FOOTER_MAGIC "YZ"
|
||||
#define FOOTER_MAGIC_SIZE 2
|
||||
|
||||
/*
|
||||
* Variable-length integer can hold a 63-bit unsigned integer, or a special
|
||||
* value to indicate that the value is unknown.
|
||||
* Variable-length integer can hold a 63-bit unsigned integer or a special
|
||||
* value indicating that the value is unknown.
|
||||
*
|
||||
* Experimental: vli_type can be defined to uint32_t to save a few bytes
|
||||
* in code size (no effect on speed). Doing so limits the uncompressed and
|
||||
* compressed size of the file to less than 256 MiB and may also weaken
|
||||
* error detection slightly.
|
||||
*/
|
||||
typedef uint64_t vli_type;
|
||||
|
||||
|
||||
+37
-15
@@ -25,6 +25,26 @@
|
||||
"Minimalized" for busybox by Alain Knaff
|
||||
*/
|
||||
|
||||
//config:config LZOP
|
||||
//config: bool "lzop"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Lzop compression/decompresion.
|
||||
//config:
|
||||
//config:config LZOP_COMPR_HIGH
|
||||
//config: bool "lzop compression levels 7,8,9 (not very useful)"
|
||||
//config: default n
|
||||
//config: depends on LZOP
|
||||
//config: help
|
||||
//config: High levels (7,8,9) of lzop compression. These levels
|
||||
//config: are actually slower than gzip at equivalent compression ratios
|
||||
//config: and take up 3.2K of code.
|
||||
|
||||
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
|
||||
//applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
|
||||
//kbuild:lib-$(CONFIG_LZOP) += lzop.o
|
||||
|
||||
//usage:#define lzop_trivial_usage
|
||||
//usage: "[-cfvd123456789CF] [FILE]..."
|
||||
//usage:#define lzop_full_usage "\n\n"
|
||||
@@ -436,25 +456,27 @@ struct globals {
|
||||
//#define LZOP_VERSION_STRING "1.01"
|
||||
//#define LZOP_VERSION_DATE "Apr 27th 2003"
|
||||
|
||||
#define OPTION_STRING "cfvdt123456789CF"
|
||||
#define OPTION_STRING "cfvqdt123456789CF"
|
||||
|
||||
/* Note: must be kept in sync with archival/bbunzip.c */
|
||||
enum {
|
||||
OPT_STDOUT = (1 << 0),
|
||||
OPT_FORCE = (1 << 1),
|
||||
OPT_VERBOSE = (1 << 2),
|
||||
OPT_DECOMPRESS = (1 << 3),
|
||||
OPT_TEST = (1 << 4),
|
||||
OPT_1 = (1 << 5),
|
||||
OPT_2 = (1 << 6),
|
||||
OPT_3 = (1 << 7),
|
||||
OPT_4 = (1 << 8),
|
||||
OPT_5 = (1 << 9),
|
||||
OPT_6 = (1 << 10),
|
||||
OPT_789 = (7 << 11),
|
||||
OPT_7 = (1 << 11),
|
||||
OPT_8 = (1 << 12),
|
||||
OPT_C = (1 << 14),
|
||||
OPT_F = (1 << 15),
|
||||
OPT_QUIET = (1 << 3),
|
||||
OPT_DECOMPRESS = (1 << 4),
|
||||
OPT_TEST = (1 << 5),
|
||||
OPT_1 = (1 << 6),
|
||||
OPT_2 = (1 << 7),
|
||||
OPT_3 = (1 << 8),
|
||||
OPT_4 = (1 << 9),
|
||||
OPT_5 = (1 << 10),
|
||||
OPT_6 = (1 << 11),
|
||||
OPT_789 = (7 << 12),
|
||||
OPT_7 = (1 << 13),
|
||||
OPT_8 = (1 << 14),
|
||||
OPT_C = (1 << 15),
|
||||
OPT_F = (1 << 16),
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -1093,7 +1115,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[4] == 'c')
|
||||
option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
|
||||
/* unlzop? */
|
||||
if (applet_name[0] == 'u')
|
||||
if (applet_name[4] == 'o')
|
||||
option_mask32 |= OPT_DECOMPRESS;
|
||||
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
|
||||
+162
-152
@@ -7,6 +7,15 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config RPM
|
||||
//config: bool "rpm"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
//applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_RPM) += rpm.o
|
||||
|
||||
//usage:#define rpm_trivial_usage
|
||||
//usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
|
||||
//usage:#define rpm_full_usage "\n\n"
|
||||
@@ -14,10 +23,10 @@
|
||||
//usage: "\nCommands:"
|
||||
//usage: "\n -i Install package"
|
||||
//usage: "\n -qp Query package"
|
||||
//usage: "\n -i Show information"
|
||||
//usage: "\n -l List contents"
|
||||
//usage: "\n -d List documents"
|
||||
//usage: "\n -c List config files"
|
||||
//usage: "\n -qpi Show information"
|
||||
//usage: "\n -qpl List contents"
|
||||
//usage: "\n -qpd List documents"
|
||||
//usage: "\n -qpc List config files"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
@@ -79,136 +88,13 @@ typedef struct {
|
||||
uint32_t count; /* 4 byte count */
|
||||
} rpm_index;
|
||||
|
||||
static void *map;
|
||||
static rpm_index **mytags;
|
||||
static int tagcount;
|
||||
|
||||
static void extract_cpio(int fd, const char *source_rpm);
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags);
|
||||
static int bsearch_rpmtag(const void *key, const void *item);
|
||||
static char *rpm_getstr(int tag, int itemindex);
|
||||
static int rpm_getint(int tag, int itemindex);
|
||||
static int rpm_getcount(int tag);
|
||||
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) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
const int pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
if (!argv[0]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
const char *source_rpm;
|
||||
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, &tagcount);
|
||||
if (!mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
offset = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
/* Mimimum is one page */
|
||||
map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
|
||||
source_rpm = rpm_getstr(TAG_SOURCERPM, 0);
|
||||
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio(rpm_fd, source_rpm);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate_ptm;
|
||||
char bdatestring[50];
|
||||
const char *p;
|
||||
|
||||
p = rpm_getstr(TAG_PREFIXS, 0);
|
||||
if (!p) p = "(not relocateable)";
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), p);
|
||||
p = rpm_getstr(TAG_VENDOR, 0);
|
||||
if (!p) p = "(none)";
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), p);
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), source_rpm);
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstr(TAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mytags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
struct globals {
|
||||
void *map;
|
||||
rpm_index **mytags;
|
||||
int tagcount;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
|
||||
static void extract_cpio(int fd, const char *source_rpm)
|
||||
{
|
||||
@@ -231,8 +117,8 @@ static void extract_cpio(int fd, const char *source_rpm)
|
||||
/* compat: overwrite existing files.
|
||||
* try "rpm -i foo.src.rpm" few times in a row -
|
||||
* standard rpm will not complain.
|
||||
* (TODO? real rpm creates "file;1234" and then renames it) */
|
||||
| ARCHIVE_UNLINK_OLD;
|
||||
*/
|
||||
| ARCHIVE_REPLACE_VIA_RENAME;
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
@@ -294,7 +180,7 @@ static int bsearch_rpmtag(const void *key, const void *item)
|
||||
static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found[0]->count;
|
||||
@@ -303,7 +189,7 @@ static int rpm_getcount(int tag)
|
||||
static char *rpm_getstr(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return NULL;
|
||||
if (found[0]->type == RPM_STRING_TYPE
|
||||
@@ -311,7 +197,7 @@ static char *rpm_getstr(int tag, int itemindex)
|
||||
|| found[0]->type == RPM_STRING_ARRAY_TYPE
|
||||
) {
|
||||
int n;
|
||||
char *tmpstr = (char *) map + found[0]->offset;
|
||||
char *tmpstr = (char *) G.map + found[0]->offset;
|
||||
for (n = 0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
@@ -322,32 +208,25 @@ static char *rpm_getstr(int tag, int itemindex)
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
int *tmpint; /* NB: using int8_t* would be easier to code */
|
||||
char *tmpint;
|
||||
|
||||
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
|
||||
* it's ok to ignore it because tag won't be used as a pointer */
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
tmpint = (int *) ((char *) map + found[0]->offset);
|
||||
|
||||
tmpint = (char *) G.map + found[0]->offset;
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
/*return ntohl(*tmpint);*/
|
||||
/* int can be != int32_t */
|
||||
tmpint += itemindex*4;
|
||||
return ntohl(*(int32_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT16_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*2);
|
||||
/* ??? read int, and THEN ntohs() it?? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
tmpint += itemindex*2;
|
||||
return ntohs(*(int16_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT8_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex);
|
||||
/* ??? why we don't read byte here??? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
tmpint += itemindex;
|
||||
return *(int8_t*)tmpint;
|
||||
}
|
||||
return -1;
|
||||
@@ -392,3 +271,134 @@ static void loop_through_files(int filetag, void (*fileaction)(char *filename, i
|
||||
free(filename);
|
||||
}
|
||||
}
|
||||
|
||||
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt, func = 0;
|
||||
const unsigned pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
if (!argv[0]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
int rpm_fd;
|
||||
unsigned mapsize;
|
||||
const char *source_rpm;
|
||||
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
G.mytags = rpm_gettags(rpm_fd, &G.tagcount);
|
||||
if (!G.mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
mapsize = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
mapsize = (mapsize + pagesize) & -(int)pagesize;
|
||||
/* Some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
||||
G.map = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
//FIXME: error check?
|
||||
|
||||
source_rpm = rpm_getstr(TAG_SOURCERPM, 0);
|
||||
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio(rpm_fd, source_rpm);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate_ptm;
|
||||
char bdatestring[50];
|
||||
const char *p;
|
||||
|
||||
printf("%-12s: %s\n", "Name" , rpm_getstr(TAG_NAME, 0));
|
||||
/* TODO compat: add "Epoch" here */
|
||||
printf("%-12s: %s\n", "Version" , rpm_getstr(TAG_VERSION, 0));
|
||||
printf("%-12s: %s\n", "Release" , rpm_getstr(TAG_RELEASE, 0));
|
||||
/* add "Architecture" */
|
||||
printf("%-12s: %s\n", "Install Date", "(not installed)");
|
||||
printf("%-12s: %s\n", "Group" , rpm_getstr(TAG_GROUP, 0));
|
||||
printf("%-12s: %d\n", "Size" , rpm_getint(TAG_SIZE, 0));
|
||||
printf("%-12s: %s\n", "License" , rpm_getstr(TAG_LICENSE, 0));
|
||||
/* add "Signature" */
|
||||
printf("%-12s: %s\n", "Source RPM" , source_rpm ? source_rpm : "(none)");
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
printf("%-12s: %s\n", "Build Date" , bdatestring);
|
||||
printf("%-12s: %s\n", "Build Host" , rpm_getstr(TAG_BUILDHOST, 0));
|
||||
p = rpm_getstr(TAG_PREFIXS, 0);
|
||||
printf("%-12s: %s\n", "Relocations" , p ? p : "(not relocatable)");
|
||||
/* add "Packager" */
|
||||
p = rpm_getstr(TAG_VENDOR, 0);
|
||||
printf("%-12s: %s\n", "Vendor" , p ? p : "(none)");
|
||||
printf("%-12s: %s\n", "URL" , rpm_getstr(TAG_URL, 0));
|
||||
printf("%-12s: %s\n", "Summary" , rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
munmap(G.map, mapsize);
|
||||
free(G.mytags);
|
||||
close(rpm_fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -7,6 +7,15 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config RPM2CPIO
|
||||
//config: bool "rpm2cpio"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Converts a RPM file into a CPIO archive.
|
||||
|
||||
//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
|
||||
//usage:#define rpm2cpio_trivial_usage
|
||||
//usage: "package.rpm"
|
||||
//usage:#define rpm2cpio_full_usage "\n\n"
|
||||
|
||||
+115
-8
@@ -22,7 +22,6 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* TODO: security with -C DESTDIR option can be enhanced.
|
||||
* Consider tar file created via:
|
||||
* $ tar cvf bug.tar anything.txt
|
||||
@@ -42,6 +41,109 @@
|
||||
* This doesn't feel right, and IIRC GNU tar doesn't do that.
|
||||
*/
|
||||
|
||||
//config:config TAR
|
||||
//config: bool "tar"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: tar is an archiving program. It's commonly used with gzip to
|
||||
//config: create compressed archives. It's probably the most widely used
|
||||
//config: UNIX archive program.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_CREATE
|
||||
//config: bool "Enable archive creation"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: If you enable this option you'll be able to create
|
||||
//config: tar archives using the `-c' option.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_AUTODETECT
|
||||
//config: bool "Autodetect compressed tarballs"
|
||||
//config: default y
|
||||
//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
|
||||
//config: help
|
||||
//config: With this option tar can automatically detect compressed
|
||||
//config: tarballs. Currently it works only on files (not pipes etc).
|
||||
//config:
|
||||
//config:config FEATURE_TAR_FROM
|
||||
//config: bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: If you enable this option you'll be able to specify
|
||||
//config: a list of files to include or exclude from an archive.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
//config: bool "Support for old tar header format"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
//config: This option is required to unpack archives created in
|
||||
//config: the old GNU format; help to kill this old format by
|
||||
//config: repacking your ancient archives with the new format.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
//config: bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
//config: This option is required to unpack archives created by some old
|
||||
//config: version of Sun's tar (it was calculating checksum using signed
|
||||
//config: arithmetic). It is said to be fixed in newer Sun tar, but "old"
|
||||
//config: tarballs still exist.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_GNU_EXTENSIONS
|
||||
//config: bool "Support for GNU tar extensions (long filenames)"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
//config: With this option busybox supports GNU long filenames and
|
||||
//config: linknames.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on TAR && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable use of long options, increases size by about 400 Bytes
|
||||
//config:
|
||||
//config:config FEATURE_TAR_TO_COMMAND
|
||||
//config: bool "Support for writing to an external program"
|
||||
//config: default y
|
||||
//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
|
||||
//config: help
|
||||
//config: If you enable this option you'll be able to instruct tar to send
|
||||
//config: the contents of each extracted file to the standard input of an
|
||||
//config: external program.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_UNAME_GNAME
|
||||
//config: bool "Enable use of user and group names"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: Enables use of user and group names in tar. This affects contents
|
||||
//config: listings (-t) and preserving permissions when unpacking (-p).
|
||||
//config: +200 bytes.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_NOPRESERVE_TIME
|
||||
//config: bool "Enable -m (do not preserve time) option"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: With this option busybox supports GNU tar -m
|
||||
//config: (do not preserve time) option.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_SELINUX
|
||||
//config: bool "Support for extracting SELinux labels"
|
||||
//config: default n
|
||||
//config: depends on TAR && SELINUX
|
||||
//config: help
|
||||
//config: With this option busybox supports restoring SELinux labels
|
||||
//config: when extracting files from tar archives.
|
||||
|
||||
//applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_TAR) += tar.o
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
@@ -567,7 +669,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0);
|
||||
vfork_exec_errno = errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -679,14 +781,12 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
char *cp = last_char_is(line, '/');
|
||||
if (cp > line)
|
||||
*cp = '\0';
|
||||
llist_add_to(&newlist, line);
|
||||
llist_add_to_end(&newlist, line);
|
||||
}
|
||||
fclose(src_stream);
|
||||
}
|
||||
return newlist;
|
||||
}
|
||||
#else
|
||||
# define append_file_list_to_list(x) 0
|
||||
#endif
|
||||
|
||||
//usage:#define tar_trivial_usage
|
||||
@@ -1096,8 +1196,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
/*tar_handle->offset = 0; - already is */
|
||||
}
|
||||
|
||||
/* Zero processed headers (== empty file) is not a valid tarball.
|
||||
* We (ab)use bb_got_signal as exitcode here,
|
||||
* because check_errors_in_children() uses _it_ as error indicator.
|
||||
*/
|
||||
bb_got_signal = EXIT_FAILURE;
|
||||
|
||||
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
@@ -1113,8 +1219,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
close(tar_handle->src_fd);
|
||||
|
||||
if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
|
||||
/* Set bb_got_signal to 1 if a child died with !0 exitcode */
|
||||
check_errors_in_children(0);
|
||||
return bb_got_signal;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
return bb_got_signal;
|
||||
}
|
||||
+73
-29
@@ -9,16 +9,27 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* For reference see
|
||||
* http://www.pkware.com/company/standards/appnote/
|
||||
* http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
|
||||
*/
|
||||
|
||||
/* TODO
|
||||
*
|
||||
* TODO
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
|
||||
//config:config UNZIP
|
||||
//config: bool "unzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
//config: commonly found on DOS/WIN systems. The default behavior
|
||||
//config: (with no options) is to extract the archive into the
|
||||
//config: current directory. Use the `-d' option to extract to a
|
||||
//config: directory of your choice.
|
||||
|
||||
//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
//usage:#define unzip_trivial_usage
|
||||
//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
|
||||
//usage:#define unzip_full_usage "\n\n"
|
||||
@@ -163,7 +174,17 @@ enum { zip_fd = 3 };
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
|
||||
#define PEEK_FROM_END 16384
|
||||
/* Seen in the wild:
|
||||
* Self-extracting PRO2K3XP_32.exe contains 19078464 byte zip archive,
|
||||
* where CDE was nearly 48 kbytes before EOF.
|
||||
* (Surprisingly, it also apparently has *another* CDE structure
|
||||
* closer to the end, with bogus cdf_offset).
|
||||
* To make extraction work, bumped PEEK_FROM_END from 16k to 64k.
|
||||
*/
|
||||
#define PEEK_FROM_END (64*1024)
|
||||
|
||||
/* This value means that we failed to find CDF */
|
||||
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
|
||||
|
||||
/* NB: does not preserve file position! */
|
||||
static uint32_t find_cdf_offset(void)
|
||||
@@ -180,6 +201,7 @@ static uint32_t find_cdf_offset(void)
|
||||
xlseek(zip_fd, end, SEEK_SET);
|
||||
full_read(zip_fd, buf, PEEK_FROM_END);
|
||||
|
||||
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
|
||||
p = buf;
|
||||
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
|
||||
if (*p != 'P') {
|
||||
@@ -195,11 +217,17 @@ static uint32_t find_cdf_offset(void)
|
||||
/* we found CDE! */
|
||||
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde_header);
|
||||
free(buf);
|
||||
return cde_header.formatted.cdf_offset;
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
* where cdf_offset points past EOF - ??
|
||||
* Ignore such CDEs:
|
||||
*/
|
||||
if (cde_header.formatted.cdf_offset < end + (p - buf))
|
||||
break;
|
||||
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
|
||||
}
|
||||
//free(buf);
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
free(buf);
|
||||
return cde_header.formatted.cdf_offset;
|
||||
};
|
||||
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
@@ -211,13 +239,15 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
if (!cdf_offset)
|
||||
cdf_offset = find_cdf_offset();
|
||||
|
||||
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDF(*cdf_ptr);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf_ptr->formatted.file_name_length
|
||||
+ cdf_ptr->formatted.extra_field_length
|
||||
+ cdf_ptr->formatted.file_comment_length;
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDF(*cdf_ptr);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf_ptr->formatted.file_name_length
|
||||
+ cdf_ptr->formatted.extra_field_length
|
||||
+ cdf_ptr->formatted.file_comment_length;
|
||||
}
|
||||
|
||||
xlseek(zip_fd, org, SEEK_SET);
|
||||
return cdf_offset;
|
||||
@@ -226,8 +256,9 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
|
||||
static void unzip_skip(off_t skip)
|
||||
{
|
||||
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
|
||||
bb_copyfd_exact_size(zip_fd, -1, skip);
|
||||
if (skip != 0)
|
||||
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
|
||||
bb_copyfd_exact_size(zip_fd, -1, skip);
|
||||
}
|
||||
|
||||
static void unzip_create_leading_dirs(const char *fn)
|
||||
@@ -267,6 +298,14 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
}
|
||||
}
|
||||
|
||||
static void my_fgets80(char *buf80)
|
||||
{
|
||||
fflush_all();
|
||||
if (!fgets(buf80, 80, stdin)) {
|
||||
bb_perror_msg_and_die("can't read standard input");
|
||||
}
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
@@ -291,7 +330,7 @@ int unzip_main(int argc, char **argv)
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
int i, opt;
|
||||
char key_buf[80];
|
||||
char key_buf[80]; /* must match size used by my_fgets80 */
|
||||
struct stat stat_buf;
|
||||
|
||||
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
|
||||
@@ -520,21 +559,31 @@ int unzip_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
|
||||
}
|
||||
|
||||
{
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
cdf_header_t cdf_header;
|
||||
cdf_offset = read_next_cdf(cdf_offset, &cdf_header);
|
||||
/*
|
||||
* Note: cdf_offset can become BAD_CDF_OFFSET after the above call.
|
||||
*/
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) {
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory. See unzip_doc.txt */
|
||||
* only from Central Directory. See unzip_doc.txt
|
||||
*/
|
||||
zip_header.formatted.crc32 = cdf_header.formatted.crc32;
|
||||
zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize;
|
||||
zip_header.formatted.ucmpsize = cdf_header.formatted.ucmpsize;
|
||||
}
|
||||
if ((cdf_header.formatted.version_made_by >> 8) == 3) {
|
||||
/* this archive is created on Unix */
|
||||
/* This archive is created on Unix */
|
||||
dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16);
|
||||
}
|
||||
}
|
||||
if (cdf_offset == BAD_CDF_OFFSET
|
||||
&& (zip_header.formatted.zip_flags & SWAP_LE16(0x0008))
|
||||
) {
|
||||
/* If it's a streaming zip, we _require_ CDF */
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Read filename */
|
||||
@@ -624,10 +673,7 @@ int unzip_main(int argc, char **argv)
|
||||
i = 'y';
|
||||
} else {
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
fflush_all();
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("can't read input");
|
||||
}
|
||||
my_fgets80(key_buf);
|
||||
i = key_buf[0];
|
||||
}
|
||||
} else { /* File is not regular file */
|
||||
@@ -668,9 +714,7 @@ int unzip_main(int argc, char **argv)
|
||||
case 'r':
|
||||
/* Prompt for new name */
|
||||
printf("new name: ");
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("can't read input");
|
||||
}
|
||||
my_fgets80(key_buf);
|
||||
free(dst_fn);
|
||||
dst_fn = xstrdup(key_buf);
|
||||
chomp(dst_fn);
|
||||
|
||||
+23
-14
@@ -36,47 +36,56 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
||||
#define flags bb_common_bufsiz1
|
||||
|
||||
/* When user accidentally runs "dumpkmap FILE"
|
||||
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
|
||||
* Let's prevent it: */
|
||||
* Let's prevent it:
|
||||
*/
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
/* bb_warn_ignoring_args(argv[1]);*/
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
|
||||
#if 0
|
||||
write(STDOUT_FILENO, "bkeymap", 7);
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
memset(flags, 0x00, MAX_NR_KEYMAPS);
|
||||
* [0-2] [4-6] [8-10] [12]
|
||||
*/
|
||||
/*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */
|
||||
memset(flags, 0x01, 13);
|
||||
flags[3] = flags[7] = flags[11] = 0;
|
||||
|
||||
/* dump flags */
|
||||
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
#define flags7 flags
|
||||
#else
|
||||
/* Same effect */
|
||||
/* 0 1 2 3 4 5 6 7 8 9 a b c=12 */
|
||||
memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1",
|
||||
/* Can use sizeof, or sizeof-1. sizeof is even, using that */
|
||||
/****/ sizeof("bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1")
|
||||
);
|
||||
write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS);
|
||||
#define flags7 (flags + 7)
|
||||
#endif
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
for (i = 0; i < 13; i++) {
|
||||
if (flags7[i]) {
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (!ioctl_or_perror(fd, KDGKBENT, &ke,
|
||||
"ioctl failed with %s, %s, %p",
|
||||
(char *)&ke.kb_index,
|
||||
(char *)&ke.kb_table,
|
||||
&ke.kb_value)
|
||||
"ioctl(KDGKBENT{%d,%d}) failed",
|
||||
j, i)
|
||||
) {
|
||||
write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
|
||||
write(STDOUT_FILENO, &ke.kb_value, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd);
|
||||
RELEASE_CONFIG_BUFFER(flags);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -48,6 +48,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
/* bb_warn_ignoring_args(argv[1]); */
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
/* or maybe:
|
||||
opt = getopt32(argv, "C:", &tty_name);
|
||||
@@ -61,14 +62,24 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
}
|
||||
if (flags[i] != 1)
|
||||
continue;
|
||||
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
/*
|
||||
* Note: table[idx:0] can contain special value
|
||||
* K_ALLOCATED (marks allocated tables in kernel).
|
||||
* dumpkmap saves the value as-is; but attempts
|
||||
* to load it here fail, since it isn't a valid
|
||||
* key value: it is K(KT_SPEC,126) == 2<<8 + 126,
|
||||
* whereas last valid KT_SPEC is
|
||||
* K_BARENUMLOCK == K(KT_SPEC,19).
|
||||
* So far we just ignore these errors:
|
||||
*/
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ lib-$(CONFIG_EXPAND) += expand.o
|
||||
lib-$(CONFIG_FALSE) += false.o
|
||||
lib-$(CONFIG_FOLD) += fold.o
|
||||
lib-$(CONFIG_FSYNC) += fsync.o
|
||||
lib-$(CONFIG_HEAD) += head.o
|
||||
lib-$(CONFIG_INSTALL) += install.o
|
||||
#lib-$(CONFIG_LENGTH) += length.o
|
||||
lib-$(CONFIG_LN) += ln.o
|
||||
@@ -71,7 +70,6 @@ lib-$(CONFIG_STTY) += stty.o
|
||||
lib-$(CONFIG_SUM) += sum.o
|
||||
lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAC) += tac.o
|
||||
lib-$(CONFIG_TAIL) += tail.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
lib-$(CONFIG_TTY) += tty.o
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
|
||||
char lineout[30];
|
||||
|
||||
day_array(month, year, dp);
|
||||
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
|
||||
len = sprintf(lineout, "%s %u", month_names[month - 1], year);
|
||||
printf("%*s%s\n%s\n",
|
||||
((7*julian + WEEK_LEN) - len) / 2, "",
|
||||
lineout, day_headings);
|
||||
|
||||
+20
-23
@@ -25,14 +25,23 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
unsigned flags;
|
||||
|
||||
flags = getopt32(argv, "etv");
|
||||
unsigned opts;
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
flags ^= CATV_OPT_v;
|
||||
typedef char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
|
||||
opts = getopt32(argv, "etv");
|
||||
argv += optind;
|
||||
#if 0 /* These consts match, we can just pass "opts" to visible() */
|
||||
if (opts & CATV_OPT_e)
|
||||
flags |= VISIBLE_ENDLINE;
|
||||
if (opts & CATV_OPT_t)
|
||||
flags |= VISIBLE_SHOW_TABS;
|
||||
#endif
|
||||
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
if (!argv[0])
|
||||
@@ -50,29 +59,17 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
res = read(fd, read_buf, COMMON_BUFSIZE);
|
||||
if (res < 0)
|
||||
retval = EXIT_FAILURE;
|
||||
if (res < 1)
|
||||
if (res <= 0)
|
||||
break;
|
||||
for (i = 0; i < res; i++) {
|
||||
unsigned char c = read_buf[i];
|
||||
|
||||
if (c > 126 && (flags & CATV_OPT_v)) {
|
||||
if (c == 127) {
|
||||
printf("^?");
|
||||
continue;
|
||||
}
|
||||
printf("M-");
|
||||
c -= 128;
|
||||
if (opts & CATV_OPT_v) {
|
||||
putchar(c);
|
||||
} else {
|
||||
char buf[sizeof("M-^c")];
|
||||
visible(c, buf, opts);
|
||||
fputs(buf, stdout);
|
||||
}
|
||||
if (c < 32) {
|
||||
if (c == 10) {
|
||||
if (flags & CATV_OPT_e)
|
||||
bb_putchar('$');
|
||||
} else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
|
||||
printf("^%c", c+'@');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
bb_putchar(c);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP && fd)
|
||||
|
||||
+76
-35
@@ -30,10 +30,10 @@
|
||||
//usage: "\n conv=noerror Continue after read errors"
|
||||
//usage: "\n conv=sync Pad blocks with zeros"
|
||||
//usage: "\n conv=fsync Physically write data out before finishing"
|
||||
//usage: "\n conv=swab Swap every pair of bytes"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nNumbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),"
|
||||
//usage: "\nMD (x1000000), M (x1048576), GD (x1000000000) or G (x1073741824)"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kD (1000), k (1024), MD, M, GD, G"
|
||||
//usage:
|
||||
//usage:#define dd_example_usage
|
||||
//usage: "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n"
|
||||
@@ -151,13 +151,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = 1 << 0,
|
||||
FLAG_SYNC = 1 << 1,
|
||||
FLAG_NOERROR = 1 << 2,
|
||||
FLAG_FSYNC = 1 << 3,
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = 1 << 4,
|
||||
FLAG_COUNT = 1 << 5,
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
};
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"
|
||||
@@ -167,7 +168,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static const char conv_words[] ALIGN1 =
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0";
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
|
||||
#endif
|
||||
enum {
|
||||
OP_bs = 0,
|
||||
@@ -185,11 +186,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
OP_conv_sync,
|
||||
OP_conv_noerror,
|
||||
OP_conv_fsync,
|
||||
OP_conv_swab,
|
||||
/* Unimplemented conv=XXX: */
|
||||
//nocreat do not create the output file
|
||||
//excl fail if the output file already exists
|
||||
//fdatasync physically write output file data before finishing
|
||||
//swab swap every pair of input bytes
|
||||
//lcase change upper case to lower case
|
||||
//ucase change lower case to upper case
|
||||
//block pad newline-terminated records with spaces to cbs-size
|
||||
@@ -197,22 +198,33 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
//ascii from EBCDIC to ASCII
|
||||
//ebcdic from ASCII to EBCDIC
|
||||
//ibm from ASCII to alternate EBCDIC
|
||||
/* Partially implemented: */
|
||||
//swab swap every pair of input bytes: will abort on non-even reads
|
||||
#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! */
|
||||
smallint exitcode = EXIT_FAILURE;
|
||||
int i;
|
||||
size_t ibs = 512;
|
||||
char *ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
size_t obs = 512;
|
||||
char *obuf;
|
||||
#else
|
||||
# define obs ibs
|
||||
# define obuf ibuf
|
||||
#endif
|
||||
/* These are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
size_t oc;
|
||||
ssize_t prev_read_size; /* for detecting swab failure */
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define oc (Z.oc )
|
||||
#define prev_read_size (Z.prev_read_size)
|
||||
#define count (Z.count )
|
||||
#define seek (Z.seek )
|
||||
#define skip (Z.skip )
|
||||
@@ -223,10 +235,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
//fflush_all(); - is this needed because of NOEXEC?
|
||||
|
||||
for (n = 1; argv[n]; n++) {
|
||||
for (i = 1; argv[i]; i++) {
|
||||
int what;
|
||||
char *val;
|
||||
char *arg = argv[n];
|
||||
char *arg = argv[i];
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
/* "dd --". NB: coreutils 6.9 will complain if they see
|
||||
@@ -255,6 +267,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
while (1) {
|
||||
int n;
|
||||
/* find ',', replace them with NUL so we can use val for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on val being non-null, else strchr would fault.
|
||||
@@ -262,20 +275,21 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
arg = strchr(val, ',');
|
||||
if (arg)
|
||||
*arg = '\0';
|
||||
what = index_in_strings(conv_words, val);
|
||||
if (what < 0)
|
||||
n = index_in_strings(conv_words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
|
||||
flags |= (1 << what);
|
||||
flags |= (1 << n);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
/* *arg = ','; - to preserve ps listing? */
|
||||
val = arg + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
continue; /* we trashed 'what', can't fall through */
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
obs = ibs;
|
||||
/*continue;*/
|
||||
}
|
||||
/* These can be large: */
|
||||
@@ -300,14 +314,17 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
outfile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
} /* end of "for (argv[n])" */
|
||||
} /* end of "for (argv[i])" */
|
||||
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
ibuf = obuf = xmalloc(ibs);
|
||||
ibuf = xmalloc(ibs);
|
||||
obuf = ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (ibs != obs) {
|
||||
flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
@@ -316,12 +333,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.begin_time_us = monotonic_us();
|
||||
#endif
|
||||
|
||||
if (infile != NULL)
|
||||
if (infile) {
|
||||
xmove_fd(xopen(infile, O_RDONLY), ifd);
|
||||
else {
|
||||
} else {
|
||||
infile = bb_msg_standard_input;
|
||||
}
|
||||
if (outfile != NULL) {
|
||||
if (outfile) {
|
||||
int oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
@@ -346,13 +363,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (skip) {
|
||||
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
|
||||
while (skip-- > 0) {
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
do {
|
||||
ssize_t n = safe_read(ifd, ibuf, ibs);
|
||||
if (n < 0)
|
||||
goto die_infile;
|
||||
if (n == 0)
|
||||
break;
|
||||
}
|
||||
} while (--skip != 0);
|
||||
}
|
||||
}
|
||||
if (seek) {
|
||||
@@ -361,6 +378,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
ssize_t n;
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
break;
|
||||
@@ -375,6 +394,27 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if (flags & FLAG_SWAB) {
|
||||
uint16_t *p16;
|
||||
ssize_t n2;
|
||||
|
||||
/* Our code allows only last read to be odd-sized */
|
||||
if (prev_read_size & 1)
|
||||
bb_error_msg_and_die("can't swab %lu byte buffer",
|
||||
(unsigned long)prev_read_size);
|
||||
prev_read_size = n;
|
||||
|
||||
/* If n is odd, last byte is not swapped:
|
||||
* echo -n "qwe" | dd conv=swab
|
||||
* prints "wqe".
|
||||
*/
|
||||
p16 = (void*) ibuf;
|
||||
n2 = (n >> 1);
|
||||
while (--n2 >= 0) {
|
||||
*p16 = bswap_16(*p16);
|
||||
p16++;
|
||||
}
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
else {
|
||||
@@ -401,8 +441,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
oc = 0;
|
||||
}
|
||||
}
|
||||
} else if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
} else {
|
||||
if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
}
|
||||
|
||||
if (flags & FLAG_FSYNC) {
|
||||
if (fsync(ofd) < 0)
|
||||
@@ -411,9 +453,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
|
||||
w = full_write_or_warn(obuf, oc, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w > 0) G.out_part++;
|
||||
if (write_and_stats(obuf, oc, obs, outfile))
|
||||
goto out_status;
|
||||
}
|
||||
if (close(ifd) < 0) {
|
||||
die_infile:
|
||||
|
||||
+3
-10
@@ -78,11 +78,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
unsigned len;
|
||||
*ptr = '\0';
|
||||
# if ENABLE_UNICODE_SUPPORT
|
||||
{
|
||||
uni_stat_t uni_stat;
|
||||
printable_string(&uni_stat, ptr_strbeg);
|
||||
len = uni_stat.unicode_width;
|
||||
}
|
||||
len = unicode_strwidth(ptr_strbeg);
|
||||
# else
|
||||
len = ptr - ptr_strbeg;
|
||||
# endif
|
||||
@@ -138,12 +134,9 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
printf("%*s%.*s", len, "", n, ptr);
|
||||
# if ENABLE_UNICODE_SUPPORT
|
||||
{
|
||||
char c;
|
||||
uni_stat_t uni_stat;
|
||||
c = ptr[n];
|
||||
char c = ptr[n];
|
||||
ptr[n] = '\0';
|
||||
printable_string(&uni_stat, ptr);
|
||||
len = uni_stat.unicode_width;
|
||||
len = unicode_strwidth(ptr);
|
||||
ptr[n] = c;
|
||||
}
|
||||
# else
|
||||
|
||||
+130
-27
@@ -11,6 +11,8 @@
|
||||
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
|
||||
|
||||
//kbuild:lib-$(CONFIG_HEAD) += head.o
|
||||
|
||||
//usage:#define head_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define head_full_usage "\n\n"
|
||||
@@ -18,7 +20,8 @@
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -n N[kbm] Print first N lines"
|
||||
//usage: IF_FEATURE_FANCY_HEAD(
|
||||
//usage: "\n -c N[kbm] Print first N bytes"
|
||||
//usage: "\n -n -N[kbm] Print all except N last lines"
|
||||
//usage: "\n -c [-]N[kbm] Print first N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: )
|
||||
@@ -34,6 +37,110 @@
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
# define print_first_N(fp,count,bytes) print_first_N(fp,count)
|
||||
#endif
|
||||
static void
|
||||
print_first_N(FILE *fp, unsigned long count, bool count_bytes)
|
||||
{
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
const int count_bytes = 0;
|
||||
#endif
|
||||
while (count) {
|
||||
int c = getc(fp);
|
||||
if (c == EOF)
|
||||
break;
|
||||
if (count_bytes || (c == '\n'))
|
||||
--count;
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
static void
|
||||
print_except_N_last_bytes(FILE *fp, unsigned count)
|
||||
{
|
||||
unsigned char *circle = xmalloc(++count);
|
||||
unsigned head = 0;
|
||||
for(;;) {
|
||||
int c;
|
||||
c = getc(fp);
|
||||
if (c == EOF)
|
||||
goto ret;
|
||||
circle[head++] = c;
|
||||
if (head == count)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
int c;
|
||||
if (head == count)
|
||||
head = 0;
|
||||
putchar(circle[head]);
|
||||
c = getc(fp);
|
||||
if (c == EOF)
|
||||
goto ret;
|
||||
circle[head] = c;
|
||||
head++;
|
||||
}
|
||||
ret:
|
||||
free(circle);
|
||||
}
|
||||
|
||||
static void
|
||||
print_except_N_last_lines(FILE *fp, unsigned count)
|
||||
{
|
||||
char **circle = xzalloc((++count) * sizeof(circle[0]));
|
||||
unsigned head = 0;
|
||||
for(;;) {
|
||||
char *c;
|
||||
c = xmalloc_fgets(fp);
|
||||
if (!c)
|
||||
goto ret;
|
||||
circle[head++] = c;
|
||||
if (head == count)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
char *c;
|
||||
if (head == count)
|
||||
head = 0;
|
||||
fputs(circle[head], stdout);
|
||||
c = xmalloc_fgets(fp);
|
||||
if (!c)
|
||||
goto ret;
|
||||
free(circle[head]);
|
||||
circle[head++] = c;
|
||||
}
|
||||
ret:
|
||||
head = 0;
|
||||
for(;;) {
|
||||
free(circle[head++]);
|
||||
if (head == count)
|
||||
break;
|
||||
}
|
||||
free(circle);
|
||||
}
|
||||
#else
|
||||
/* Must never be called */
|
||||
void print_except_N_last_bytes(FILE *fp, unsigned count);
|
||||
void print_except_N_last_lines(FILE *fp, unsigned count);
|
||||
#endif
|
||||
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
# define eat_num(negative_N,p) eat_num(p)
|
||||
#endif
|
||||
static unsigned long
|
||||
eat_num(bool *negative_N, const char *p)
|
||||
{
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
if (*p == '-') {
|
||||
*negative_N = 1;
|
||||
p++;
|
||||
}
|
||||
#endif
|
||||
return xatoul_sfx(p, bkm_suffixes);
|
||||
}
|
||||
|
||||
static const char head_opts[] ALIGN1 =
|
||||
"n:"
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
@@ -41,29 +148,25 @@ static const char head_opts[] ALIGN1 =
|
||||
#endif
|
||||
;
|
||||
|
||||
static const struct suffix_mult head_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
#define header_fmt_str "\n==> %s <==\n"
|
||||
|
||||
int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int head_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long count = 10;
|
||||
unsigned long i;
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
int count_bytes = 0;
|
||||
int header_threshhold = 1;
|
||||
bool count_bytes = 0;
|
||||
bool negative_N = 0;
|
||||
#else
|
||||
# define header_threshhold 1
|
||||
# define count_bytes 0
|
||||
# define negative_N 0
|
||||
#endif
|
||||
FILE *fp;
|
||||
const char *fmt;
|
||||
char *p;
|
||||
int opt;
|
||||
int c;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
@@ -73,7 +176,7 @@ int head_main(int argc, char **argv)
|
||||
) {
|
||||
--argc;
|
||||
++argv;
|
||||
p = (*argv) + 1;
|
||||
p = argv[0] + 1;
|
||||
goto GET_COUNT;
|
||||
}
|
||||
#endif
|
||||
@@ -97,7 +200,7 @@ int head_main(int argc, char **argv)
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
GET_COUNT:
|
||||
#endif
|
||||
count = xatoul_sfx(p, head_suffixes);
|
||||
count = eat_num(&negative_N, p);
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
@@ -110,19 +213,17 @@ int head_main(int argc, char **argv)
|
||||
*--argv = (char*)"-";
|
||||
|
||||
fmt = header_fmt_str + 1;
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
if (argc <= header_threshhold) {
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
header_threshhold = 0;
|
||||
}
|
||||
#else
|
||||
if (argc <= 1) {
|
||||
fmt += 11; /* "" */
|
||||
}
|
||||
/* Now define some things here to avoid #ifdefs in the code below.
|
||||
* These should optimize out of the if conditions below. */
|
||||
#define header_threshhold 1
|
||||
#define count_bytes 0
|
||||
#endif
|
||||
}
|
||||
if (negative_N) {
|
||||
if (count >= INT_MAX / sizeof(char*))
|
||||
bb_error_msg("count is too big: %lu", count);
|
||||
}
|
||||
|
||||
do {
|
||||
fp = fopen_or_warn_stdin(*argv);
|
||||
@@ -133,18 +234,20 @@ int head_main(int argc, char **argv)
|
||||
if (header_threshhold) {
|
||||
printf(fmt, *argv);
|
||||
}
|
||||
i = count;
|
||||
while (i && ((c = getc(fp)) != EOF)) {
|
||||
if (count_bytes || (c == '\n')) {
|
||||
--i;
|
||||
if (negative_N) {
|
||||
if (count_bytes) {
|
||||
print_except_N_last_bytes(fp, count);
|
||||
} else {
|
||||
print_except_N_last_lines(fp, count);
|
||||
}
|
||||
putchar(c);
|
||||
} else {
|
||||
print_first_N(fp, count, count_bytes);
|
||||
}
|
||||
die_if_ferror_stdout();
|
||||
if (fclose_if_not_stdin(fp)) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
die_if_ferror_stdout();
|
||||
} else {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@ int hostid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
printf("%08lx\n", gethostid());
|
||||
/* POSIX says gethostid returns a "32-bit identifier" */
|
||||
printf("%08x\n", (unsigned)(uint32_t)gethostid());
|
||||
|
||||
return fflush_all();
|
||||
}
|
||||
+1
-3
@@ -64,12 +64,10 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#if !ENABLE_USE_BB_PWD_GRP
|
||||
#if defined(__UCLIBC_MAJOR__) && (__UCLIBC_MAJOR__ == 0)
|
||||
#if (__UCLIBC_MINOR__ < 9) || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 30)
|
||||
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 30)
|
||||
#error "Sorry, you need at least uClibc version 0.9.30 for id applet to build"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum {
|
||||
PRINT_REAL = (1 << 0),
|
||||
|
||||
@@ -151,7 +151,9 @@ static uint8_t *hash_file(const char *filename)
|
||||
update(&context, in_buf, count);
|
||||
}
|
||||
hash_value = NULL;
|
||||
if (count == 0) {
|
||||
if (count < 0)
|
||||
bb_perror_msg("can't read '%s'", filename);
|
||||
else /* count == 0 */ {
|
||||
final(&context, in_buf);
|
||||
hash_value = hash_bin_to_hex(in_buf, hash_len);
|
||||
}
|
||||
|
||||
@@ -1166,12 +1166,6 @@ parse_old_offset(const char *s, off_t *offset)
|
||||
int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
static const struct suffix_mult bkm[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
};
|
||||
#if ENABLE_LONG_OPTS
|
||||
static const char od_longopts[] ALIGN1 =
|
||||
"skip-bytes\0" Required_argument "j"
|
||||
@@ -1230,7 +1224,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
address_pad_len_char = doxn_address_pad_len_char[pos];
|
||||
}
|
||||
if (opt & OPT_N) {
|
||||
max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm);
|
||||
max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes);
|
||||
}
|
||||
if (opt & OPT_a) decode_format_string("a");
|
||||
if (opt & OPT_b) decode_format_string("oC");
|
||||
@@ -1239,7 +1233,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_f) decode_format_string("fF");
|
||||
if (opt & OPT_h) decode_format_string("x2");
|
||||
if (opt & OPT_i) decode_format_string("d2");
|
||||
if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm);
|
||||
if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes);
|
||||
if (opt & OPT_l) decode_format_string("d4");
|
||||
if (opt & OPT_o) decode_format_string("o2");
|
||||
while (lst_t) {
|
||||
@@ -1248,7 +1242,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_x) decode_format_string("x2");
|
||||
if (opt & OPT_s) decode_format_string("d2");
|
||||
if (opt & OPT_S) {
|
||||
string_min = xstrtou_sfx(str_S, 0, bkm);
|
||||
string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
|
||||
}
|
||||
|
||||
// Bloat:
|
||||
|
||||
@@ -39,7 +39,10 @@
|
||||
* -q, --quiet, -s, --silent suppress most error messages
|
||||
* -v, --verbose report error messages
|
||||
*
|
||||
* bbox supports: -f -n -v (fully), -q -s (accepts but ignores)
|
||||
* bbox supports: -f (partially) -n -v (fully), -q -s (accepts but ignores)
|
||||
* Note: we export the -f flag, but our -f behaves like coreutils' -e.
|
||||
* Unfortunately, there isn't a C lib function we can leverage to get this
|
||||
* behavior which means we'd have to implement the full stack ourselves :(.
|
||||
*/
|
||||
|
||||
int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
|
||||
+6
-5
@@ -23,17 +23,15 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static const struct suffix_mult split_suffices[] = {
|
||||
#if ENABLE_FEATURE_SPLIT_FANCY
|
||||
static const struct suffix_mult split_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
#endif
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
#if ENABLE_FEATURE_SPLIT_FANCY
|
||||
{ "g", 1024*1024*1024 },
|
||||
#endif
|
||||
{ "", 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Increment the suffix part of the filename.
|
||||
* Returns NULL if we are out of filenames.
|
||||
@@ -86,7 +84,10 @@ int split_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & SPLIT_OPT_l)
|
||||
cnt = XATOOFF(count_p);
|
||||
if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF
|
||||
cnt = xatoull_sfx(count_p, split_suffices);
|
||||
cnt = xatoull_sfx(count_p,
|
||||
IF_FEATURE_SPLIT_FANCY(split_suffixes)
|
||||
IF_NOT_FEATURE_SPLIT_FANCY(km_suffixes)
|
||||
);
|
||||
sfx = "x";
|
||||
|
||||
argv += optind;
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ static const char *human_time(time_t t)
|
||||
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
|
||||
#define buf bb_common_bufsiz1
|
||||
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
|
||||
strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
|
||||
return buf;
|
||||
#undef buf
|
||||
}
|
||||
|
||||
+42
-63
@@ -246,10 +246,21 @@ enum speed_setting {
|
||||
|
||||
/* Which member(s) of 'struct termios' a mode uses */
|
||||
enum {
|
||||
/* Do NOT change the order or values, as mode_type_flag()
|
||||
* depends on them */
|
||||
control, input, output, local, combination
|
||||
};
|
||||
static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode)
|
||||
{
|
||||
static const uint8_t tcflag_offsets[] ALIGN1 = {
|
||||
offsetof(struct termios, c_cflag), /* control */
|
||||
offsetof(struct termios, c_iflag), /* input */
|
||||
offsetof(struct termios, c_oflag), /* output */
|
||||
offsetof(struct termios, c_lflag) /* local */
|
||||
};
|
||||
if (type <= local) {
|
||||
return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Flags for 'struct mode_info' */
|
||||
#define SANE_SET 1 /* Set in 'sane' mode */
|
||||
@@ -770,51 +781,6 @@ struct globals {
|
||||
G.max_col = 80; \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Return a string that is the printable representation of character CH */
|
||||
/* Adapted from 'cat' by Torbjorn Granlund */
|
||||
static const char *visible(unsigned ch)
|
||||
{
|
||||
char *bpout = G.buf;
|
||||
|
||||
if (ch == _POSIX_VDISABLE)
|
||||
return "<undef>";
|
||||
|
||||
if (ch >= 128) {
|
||||
ch -= 128;
|
||||
*bpout++ = 'M';
|
||||
*bpout++ = '-';
|
||||
}
|
||||
|
||||
if (ch < 32) {
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch + 64;
|
||||
} else if (ch < 127) {
|
||||
*bpout++ = ch;
|
||||
} else {
|
||||
*bpout++ = '^';
|
||||
*bpout++ = '?';
|
||||
}
|
||||
|
||||
*bpout = '\0';
|
||||
return G.buf;
|
||||
}
|
||||
|
||||
static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
|
||||
{
|
||||
static const uint8_t tcflag_offsets[] ALIGN1 = {
|
||||
offsetof(struct termios, c_cflag), /* control */
|
||||
offsetof(struct termios, c_iflag), /* input */
|
||||
offsetof(struct termios, c_oflag), /* output */
|
||||
offsetof(struct termios, c_lflag) /* local */
|
||||
};
|
||||
|
||||
if (type <= local) {
|
||||
return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void set_speed_or_die(enum speed_setting type, const char *arg,
|
||||
struct termios *mode)
|
||||
{
|
||||
@@ -1042,6 +1008,7 @@ static void do_display(const struct termios *mode, int all)
|
||||
#endif
|
||||
|
||||
for (i = 0; i != CIDX_min; ++i) {
|
||||
char ch;
|
||||
/* If swtch is the same as susp, don't print both */
|
||||
#if VSWTCH == VSUSP
|
||||
if (i == CIDX_swtch)
|
||||
@@ -1055,8 +1022,12 @@ static void do_display(const struct termios *mode, int all)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
wrapf("%s = %s;", nth_string(control_name, i),
|
||||
visible(mode->c_cc[control_info[i].offset]));
|
||||
ch = mode->c_cc[control_info[i].offset];
|
||||
if (ch == _POSIX_VDISABLE)
|
||||
strcpy(G.buf, "<undef>");
|
||||
else
|
||||
visible(ch, G.buf, 0);
|
||||
wrapf("%s = %s;", nth_string(control_name, i), G.buf);
|
||||
}
|
||||
#if VEOF == VMIN
|
||||
if ((mode->c_lflag & ICANON) == 0)
|
||||
@@ -1072,7 +1043,7 @@ static void do_display(const struct termios *mode, int all)
|
||||
prev_type = mode_info[i].type;
|
||||
}
|
||||
|
||||
bitsp = mode_type_flag(mode_info[i].type, mode);
|
||||
bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
|
||||
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
|
||||
if ((*bitsp & mask) == mode_info[i].bits) {
|
||||
if (all || (mode_info[i].flags & SANE_UNSET))
|
||||
@@ -1091,7 +1062,6 @@ static void do_display(const struct termios *mode, int all)
|
||||
static void sane_mode(struct termios *mode)
|
||||
{
|
||||
int i;
|
||||
tcflag_t *bitsp;
|
||||
|
||||
for (i = 0; i < NUM_control_info; ++i) {
|
||||
#if VMIN == VEOF
|
||||
@@ -1102,14 +1072,17 @@ static void sane_mode(struct termios *mode)
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_mode_info; ++i) {
|
||||
tcflag_t val;
|
||||
tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
|
||||
|
||||
if (!bitsp)
|
||||
continue;
|
||||
val = *bitsp & ~((unsigned long)mode_info[i].mask);
|
||||
if (mode_info[i].flags & SANE_SET) {
|
||||
bitsp = mode_type_flag(mode_info[i].type, mode);
|
||||
*bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask))
|
||||
| mode_info[i].bits;
|
||||
} else if (mode_info[i].flags & SANE_UNSET) {
|
||||
bitsp = mode_type_flag(mode_info[i].type, mode);
|
||||
*bitsp = *bitsp & ~((unsigned long)mode_info[i].mask)
|
||||
& ~mode_info[i].bits;
|
||||
*bitsp = val | mode_info[i].bits;
|
||||
} else
|
||||
if (mode_info[i].flags & SANE_UNSET) {
|
||||
*bitsp = val & ~mode_info[i].bits;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1119,17 +1092,18 @@ static void set_mode(const struct mode_info *info, int reversed,
|
||||
{
|
||||
tcflag_t *bitsp;
|
||||
|
||||
bitsp = mode_type_flag(info->type, mode);
|
||||
bitsp = get_ptr_to_tcflag(info->type, mode);
|
||||
|
||||
if (bitsp) {
|
||||
tcflag_t val = *bitsp & ~info->mask;
|
||||
if (reversed)
|
||||
*bitsp = *bitsp & ~info->mask & ~info->bits;
|
||||
*bitsp = val & ~info->bits;
|
||||
else
|
||||
*bitsp = (*bitsp & ~info->mask) | info->bits;
|
||||
*bitsp = val | info->bits;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Combination mode */
|
||||
/* !bitsp - it's a "combination" mode */
|
||||
if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) {
|
||||
if (reversed)
|
||||
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
||||
@@ -1534,7 +1508,12 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
|
||||
perror_on_device_and_die("%s");
|
||||
|
||||
if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
|
||||
#if CIBAUD
|
||||
/*
|
||||
* I think the below chunk is not necessary on Linux.
|
||||
* If you are deleting it, also delete STTY_speed_was_set bit -
|
||||
* it is only ever checked here.
|
||||
*/
|
||||
#if 0 /* was "if CIBAUD" */
|
||||
/* SunOS 4.1.3 (at least) has the problem that after this sequence,
|
||||
tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
|
||||
sometimes (m1 != m2). The only difference is in the four bits
|
||||
|
||||
+2
-2
@@ -70,9 +70,9 @@ static unsigned sum_file(const char *file, unsigned type)
|
||||
if (type >= SUM_SYSV) {
|
||||
r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
|
||||
s = (r & 0xffff) + (r >> 16);
|
||||
printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file);
|
||||
printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file);
|
||||
} else
|
||||
printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
|
||||
printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
|
||||
return 1;
|
||||
#undef buf
|
||||
}
|
||||
|
||||
+22
-22
@@ -24,6 +24,8 @@
|
||||
* 7) lseek attempted when count==0 even if arg was +0 (from top)
|
||||
*/
|
||||
|
||||
//kbuild:lib-$(CONFIG_TAIL) += tail.o
|
||||
|
||||
//usage:#define tail_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define tail_full_usage "\n\n"
|
||||
@@ -34,14 +36,13 @@
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: )
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -c N[kbm] Print last N bytes"
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage: "\nIf N starts with a '+', output begins with the Nth item from the start"
|
||||
//usage: "\nof each file, not from the end."
|
||||
//usage: )
|
||||
//usage:
|
||||
//usage:#define tail_example_usage
|
||||
@@ -50,13 +51,6 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static const struct suffix_mult tail_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
bool from_top;
|
||||
bool exitcode;
|
||||
@@ -73,15 +67,6 @@ static void tail_xprint_header(const char *fmt, const char *filename)
|
||||
static ssize_t tail_read(int fd, char *buf, size_t count)
|
||||
{
|
||||
ssize_t r;
|
||||
off_t current;
|
||||
struct stat sbuf;
|
||||
|
||||
/* /proc files report zero st_size, don't lseek them. */
|
||||
if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {
|
||||
current = lseek(fd, 0, SEEK_CUR);
|
||||
if (sbuf.st_size < current)
|
||||
xlseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
r = full_read(fd, buf, count);
|
||||
if (r < 0) {
|
||||
@@ -102,7 +87,7 @@ static unsigned eat_num(const char *p)
|
||||
p++;
|
||||
G.from_top = 1;
|
||||
}
|
||||
return xatou_sfx(p, tail_suffixes);
|
||||
return xatou_sfx(p, bkm_suffixes);
|
||||
}
|
||||
|
||||
int tail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -120,6 +105,7 @@ int tail_main(int argc, char **argv)
|
||||
|
||||
int *fds;
|
||||
const char *fmt;
|
||||
int prev_fd;
|
||||
|
||||
INIT_G();
|
||||
|
||||
@@ -324,6 +310,7 @@ int tail_main(int argc, char **argv)
|
||||
xwrite(STDOUT_FILENO, tailbuf, taillen);
|
||||
}
|
||||
} while (++i < nfiles);
|
||||
prev_fd = fds[i-1];
|
||||
|
||||
tailbuf = xrealloc(tailbuf, BUFSIZ);
|
||||
|
||||
@@ -367,10 +354,23 @@ int tail_main(int argc, char **argv)
|
||||
if (nfiles > header_threshhold) {
|
||||
fmt = header_fmt_str;
|
||||
}
|
||||
while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) {
|
||||
if (fmt) {
|
||||
for (;;) {
|
||||
/* tail -f keeps following files even if they are truncated */
|
||||
struct stat sbuf;
|
||||
/* /proc files report zero st_size, don't lseek them */
|
||||
if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {
|
||||
off_t current = lseek(fd, 0, SEEK_CUR);
|
||||
if (sbuf.st_size < current)
|
||||
xlseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
nread = tail_read(fd, tailbuf, BUFSIZ);
|
||||
if (nread <= 0)
|
||||
break;
|
||||
if (fmt && (fd != prev_fd)) {
|
||||
tail_xprint_header(fmt, filename);
|
||||
fmt = NULL;
|
||||
prev_fd = fd;
|
||||
}
|
||||
xwrite(STDOUT_FILENO, tailbuf, nread);
|
||||
}
|
||||
|
||||
+35
-4
@@ -26,6 +26,14 @@
|
||||
//config: touch is used to create or change the access and/or
|
||||
//config: modification timestamp of specified files.
|
||||
//config:
|
||||
//config:config FEATURE_TOUCH_NODEREF
|
||||
//config: bool "Add support for -h"
|
||||
//config: default y
|
||||
//config: depends on TOUCH
|
||||
//config: help
|
||||
//config: Enable touch to have the -h option.
|
||||
//config: This requires libc support for lutimes() function.
|
||||
//config:
|
||||
//config:config FEATURE_TOUCH_SUSV3
|
||||
//config: bool "Add support for SUSV3 features (-d -t -r)"
|
||||
//config: default y
|
||||
@@ -42,6 +50,9 @@
|
||||
//usage:#define touch_full_usage "\n\n"
|
||||
//usage: "Update the last-modified date on the given FILE[s]\n"
|
||||
//usage: "\n -c Don't create files"
|
||||
//usage: IF_FEATURE_TOUCH_NODEREF(
|
||||
//usage: "\n -h Don't follow links"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_TOUCH_SUSV3(
|
||||
//usage: "\n -d DT Date/time to use"
|
||||
//usage: "\n -t DT Date/time to use"
|
||||
@@ -65,6 +76,7 @@
|
||||
* parse STRING and use it instead of current time
|
||||
* -f (ignored, BSD compat)
|
||||
* -m change only the modification time
|
||||
* -h, --no-dereference
|
||||
* -r, --reference=FILE
|
||||
* use this file's times instead of current time
|
||||
* -t STAMP
|
||||
@@ -79,6 +91,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
int fd;
|
||||
int status = EXIT_SUCCESS;
|
||||
int opts;
|
||||
enum {
|
||||
OPT_c = (1 << 0),
|
||||
OPT_r = (1 << 1) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_d = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_t = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_h = (1 << 4) * ENABLE_FEATURE_TOUCH_NODEREF,
|
||||
};
|
||||
#if ENABLE_FEATURE_TOUCH_SUSV3
|
||||
# if ENABLE_LONG_OPTS
|
||||
static const char touch_longopts[] ALIGN1 =
|
||||
@@ -86,6 +105,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
"no-create\0" No_argument "c"
|
||||
"reference\0" Required_argument "r"
|
||||
"date\0" Required_argument "d"
|
||||
IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
|
||||
;
|
||||
# endif
|
||||
char *reference_file = NULL;
|
||||
@@ -105,13 +125,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
* accepted data format differs a bit between -d and -t.
|
||||
* We accept the same formats for both */
|
||||
opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:")
|
||||
IF_FEATURE_TOUCH_NODEREF("h")
|
||||
/*ignored:*/ "fma"
|
||||
IF_FEATURE_TOUCH_SUSV3(, &reference_file)
|
||||
IF_FEATURE_TOUCH_SUSV3(, &date_str)
|
||||
IF_FEATURE_TOUCH_SUSV3(, &date_str)
|
||||
);
|
||||
|
||||
opts &= 1; /* only -c bit is left */
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
bb_show_usage();
|
||||
@@ -121,6 +141,10 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct stat stbuf;
|
||||
xstat(reference_file, &stbuf);
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
|
||||
/* Can use .st_mtim.tv_nsec
|
||||
* (or is it .st_mtimensec?? see date.c)
|
||||
* to set microseconds too.
|
||||
*/
|
||||
}
|
||||
|
||||
if (date_str) {
|
||||
@@ -141,9 +165,16 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
do {
|
||||
if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) {
|
||||
if (errno == ENOENT) { /* no such file */
|
||||
if (opts) { /* creation is disabled, so ignore */
|
||||
int result;
|
||||
result = (
|
||||
#if ENABLE_FEATURE_TOUCH_NODEREF
|
||||
(opts & OPT_h) ? lutimes :
|
||||
#endif
|
||||
utimes)(*argv, (reference_file || date_str) ? timebuf : NULL);
|
||||
if (result != 0) {
|
||||
if (errno == ENOENT) { /* no such file? */
|
||||
if (opts & OPT_c) {
|
||||
/* Creation is disabled, so ignore */
|
||||
continue;
|
||||
}
|
||||
/* Try to create the file */
|
||||
|
||||
+29
-29
@@ -21,24 +21,24 @@
|
||||
* taken from debian-utils. I've only removed the long options and the
|
||||
* report mode. As the original run-parts support only long options, I've
|
||||
* broken compatibility because the BusyBox policy doesn't allow them.
|
||||
* The supported options are:
|
||||
* -t test. Print the name of the files to be executed, without
|
||||
* execute them.
|
||||
* -a ARG argument. Pass ARG as an argument the program executed. It can
|
||||
* be repeated to pass multiple arguments.
|
||||
* -u MASK umask. Set the umask of the program executed to MASK.
|
||||
*/
|
||||
|
||||
//usage:#define run_parts_trivial_usage
|
||||
//usage: "[-t"IF_FEATURE_RUN_PARTS_FANCY("l")"] [-a ARG]... [-u MASK] DIRECTORY"
|
||||
//usage: "[-a ARG]... [-u UMASK] "
|
||||
//usage: IF_FEATURE_RUN_PARTS_LONG_OPTIONS("[--reverse] [--test] [--exit-on-error] "IF_FEATURE_RUN_PARTS_FANCY("[--list] "))
|
||||
//usage: "DIRECTORY"
|
||||
//usage:#define run_parts_full_usage "\n\n"
|
||||
//usage: "Run a bunch of scripts in DIRECTORY\n"
|
||||
//usage: "\n -t Dry run"
|
||||
//usage: "\n -a ARG Pass ARG as argument to scripts"
|
||||
//usage: "\n -u UMASK Set UMASK before running scripts"
|
||||
//usage: IF_FEATURE_RUN_PARTS_LONG_OPTIONS(
|
||||
//usage: "\n --reverse Reverse execution order"
|
||||
//usage: "\n --test Dry run"
|
||||
//usage: "\n --exit-on-error Exit if a script exits with non-zero"
|
||||
//usage: IF_FEATURE_RUN_PARTS_FANCY(
|
||||
//usage: "\n -l Print names of matching files even if they are not executable"
|
||||
//usage: "\n --list Print names of matching files even if they are not executable"
|
||||
//usage: )
|
||||
//usage: )
|
||||
//usage: "\n -a ARG Pass ARG as argument to programs"
|
||||
//usage: "\n -u MASK Set umask to MASK before running programs"
|
||||
//usage:
|
||||
//usage:#define run_parts_example_usage
|
||||
//usage: "$ run-parts -a start /etc/init.d\n"
|
||||
@@ -59,7 +59,7 @@
|
||||
struct globals {
|
||||
char **names;
|
||||
int cur;
|
||||
char *cmd[1];
|
||||
char *cmd[2 /* using 1 provokes compiler warning */];
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define names (G.names)
|
||||
@@ -70,19 +70,15 @@ struct globals {
|
||||
enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 };
|
||||
|
||||
enum {
|
||||
OPT_r = (1 << 0),
|
||||
OPT_a = (1 << 1),
|
||||
OPT_u = (1 << 2),
|
||||
OPT_t = (1 << 3),
|
||||
OPT_l = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_FANCY,
|
||||
OPT_a = (1 << 0),
|
||||
OPT_u = (1 << 1),
|
||||
OPT_r = (1 << 2) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS,
|
||||
OPT_t = (1 << 3) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS,
|
||||
OPT_e = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS,
|
||||
OPT_l = (1 << 5) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
|
||||
* ENABLE_FEATURE_RUN_PARTS_FANCY,
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_RUN_PARTS_FANCY
|
||||
#define list_mode (option_mask32 & OPT_l)
|
||||
#else
|
||||
#define list_mode 0
|
||||
#endif
|
||||
|
||||
/* Is this a valid filename (upper/lower alpha, digits,
|
||||
* underscores, and hyphens only?)
|
||||
*/
|
||||
@@ -110,7 +106,7 @@ static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUS
|
||||
if (depth == 2
|
||||
&& ( !(statbuf->st_mode & (S_IFREG | S_IFLNK))
|
||||
|| invalid_name(file)
|
||||
|| (!list_mode && access(file, X_OK) != 0))
|
||||
|| (!(option_mask32 & OPT_l) && access(file, X_OK) != 0))
|
||||
) {
|
||||
return SKIP;
|
||||
}
|
||||
@@ -126,11 +122,12 @@ static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUS
|
||||
static const char runparts_longopts[] ALIGN1 =
|
||||
"arg\0" Required_argument "a"
|
||||
"umask\0" Required_argument "u"
|
||||
"test\0" No_argument "t"
|
||||
#if ENABLE_FEATURE_RUN_PARTS_FANCY
|
||||
"list\0" No_argument "l"
|
||||
"reverse\0" No_argument "r"
|
||||
//TODO: "verbose\0" No_argument "v"
|
||||
"reverse\0" No_argument "\xf0"
|
||||
"test\0" No_argument "\xf1"
|
||||
"exit-on-error\0" No_argument "\xf2"
|
||||
#if ENABLE_FEATURE_RUN_PARTS_FANCY
|
||||
"list\0" No_argument "\xf3"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
@@ -150,7 +147,7 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* We require exactly one argument: the directory name */
|
||||
opt_complementary = "=1:a::";
|
||||
getopt32(argv, "ra:u:t"IF_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p);
|
||||
getopt32(argv, "a:u:", &arg_list, &umask_p);
|
||||
|
||||
umask(xstrtou_range(umask_p, 8, 0, 07777));
|
||||
|
||||
@@ -193,6 +190,9 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_perror_msg("can't execute '%s'", name);
|
||||
else /* ret > 0 */
|
||||
bb_error_msg("%s exited with code %d", name, ret & 0xff);
|
||||
|
||||
if (option_mask32 & OPT_e)
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
@@ -138,13 +138,6 @@ less readable, use #defines:
|
||||
#define sector (G.sector)
|
||||
|
||||
|
||||
Word of caution
|
||||
|
||||
If applet doesn't use much of global data, converting it to use
|
||||
one of above methods is not worth the resulting code obfuscation.
|
||||
If you have less than ~300 bytes of global data - don't bother.
|
||||
|
||||
|
||||
Finding non-shared duplicated strings
|
||||
|
||||
strings busybox | sort | uniq -c | sort -nr
|
||||
@@ -224,6 +217,14 @@ Result (non-static busybox built against glibc):
|
||||
|
||||
Keeping code small
|
||||
|
||||
Use scripts/bloat-o-meter to check whether introduced changes
|
||||
didn't generate unnecessary bloat. This script needs unstripped binaries
|
||||
to generate a detailed report. To automate this, just use
|
||||
"make bloatcheck". It requires busybox_old binary to be present,
|
||||
use "make baseline" to generate it from unmodified source, or
|
||||
copy busybox_unstripped to busybox_old before modifying sources
|
||||
and rebuilding.
|
||||
|
||||
Set CONFIG_EXTRA_CFLAGS="-fno-inline-functions-called-once",
|
||||
produce "make bloatcheck", see the biggest auto-inlined functions.
|
||||
Now, set CONFIG_EXTRA_CFLAGS back to "", but add NOINLINE
|
||||
|
||||
+2
-2
@@ -51,9 +51,9 @@ device nodes if your system needs something more than the default root/root
|
||||
660 permissions.
|
||||
|
||||
The file has the format:
|
||||
[-]<device regex> <uid>:<gid> <permissions>
|
||||
[-][envmatch]<device regex> <uid>:<gid> <permissions>
|
||||
or
|
||||
@<maj[,min1[-min2]]> <uid>:<gid> <permissions>
|
||||
[envmatch]@<maj[,min1[-min2]]> <uid>:<gid> <permissions>
|
||||
or
|
||||
$envvar=<regex> <uid>:<gid> <permissions>
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
Some less-widely known details of TCP connections.
|
||||
|
||||
Properly closing the connection.
|
||||
|
||||
After this code sequence:
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
connect(sock, &remote, sizeof(remote));
|
||||
write(sock, buffer, 1000000);
|
||||
|
||||
a large block of data is only buffered by kernel, it can't be sent all at once.
|
||||
What will happen if we close the socket?
|
||||
|
||||
"A host MAY implement a 'half-duplex' TCP close sequence, so that
|
||||
an application that has called close() cannot continue to read
|
||||
data from the connection. If such a host issues a close() call
|
||||
while received data is still pending in TCP, or if new data is
|
||||
received after close() is called, its TCP SHOULD send a RST
|
||||
to show that data was lost."
|
||||
|
||||
IOW: if we just close(sock) now, kernel can reset the TCP connection
|
||||
(send RST packet).
|
||||
|
||||
This is problematic for two reasons: it discards some not-yet sent
|
||||
data, and it may be reported as error, not EOF, on peer's side.
|
||||
|
||||
What can be done about it?
|
||||
|
||||
Solution #1: block until sending is done:
|
||||
|
||||
/* When enabled, a close(2) or shutdown(2) will not return until
|
||||
* all queued messages for the socket have been successfully sent
|
||||
* or the linger timeout has been reached.
|
||||
*/
|
||||
struct linger {
|
||||
int l_onoff; /* linger active */
|
||||
int l_linger; /* how many seconds to linger for */
|
||||
} linger;
|
||||
linger.l_onoff = 1;
|
||||
linger.l_linger = SOME_NUM;
|
||||
setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
|
||||
close(sock);
|
||||
|
||||
Solution #2: tell kernel that you are done sending.
|
||||
This makes kernel send FIN after all data is written:
|
||||
|
||||
shutdown(sock, SHUT_WR);
|
||||
close(sock);
|
||||
|
||||
However, experiments on Linux 3.9.4 show that kernel can return from
|
||||
shutdown() and from close() before all data is sent,
|
||||
and if peer sends any data to us after this, kernel still responds with
|
||||
RST before all our data is sent.
|
||||
|
||||
In practice the protocol in use often does not allow peer to send
|
||||
such data to us, in which case this solution is acceptable.
|
||||
|
||||
Solution #3: if you know that peer is going to close its end after it sees
|
||||
our FIN (as EOF), it might be a good idea to perform a read after shutdown().
|
||||
When read finishes with 0-sized result, we conclude that peer received all
|
||||
the data, saw EOF, and closed its end.
|
||||
|
||||
However, this incurs small performance penalty (we run for a longer time)
|
||||
and requires safeguards (nonblocking reads, timeouts etc) against
|
||||
malicious peers which don't close the connection.
|
||||
|
||||
Solutions #1 and #2 can be combined:
|
||||
|
||||
/* ...set up struct linger... then: */
|
||||
setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
|
||||
shutdown(sock, SHUT_WR);
|
||||
/* At this point, kernel sent FIN packet, not RST, to the peer, */
|
||||
/* even if there is buffered read data from the peer. */
|
||||
close(sock);
|
||||
|
||||
Defeating Nagle.
|
||||
|
||||
Method #1: manually control whether partial sends are allowed:
|
||||
|
||||
This prevents partially filled packets being sent:
|
||||
|
||||
int state = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
|
||||
|
||||
and this forces last, partially filled packet (if any) to be sent:
|
||||
|
||||
int state = 0;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
|
||||
|
||||
Method #2: make any write to immediately send data, even if it's partial:
|
||||
|
||||
int state = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &state, sizeof(state));
|
||||
@@ -179,8 +179,4 @@ extern int blkid_set_tag(blkid_dev dev, const char *name,
|
||||
extern blkid_dev blkid_new_dev(void);
|
||||
extern void blkid_free_dev(blkid_dev dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -115,7 +115,7 @@ int main(int argc, char** argv)
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_probe_all(cache) < 0))
|
||||
if ((ret = blkid_probe_all(cache)) < 0)
|
||||
fprintf(stderr, "error probing devices\n");
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
@@ -153,7 +153,7 @@ extern int optind;
|
||||
void usage(char *prog)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog);
|
||||
fprintf(stderr, "\tList all devices and exit\n", prog);
|
||||
fprintf(stderr, "\tList all devices and exit\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %d\n",
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ void blkid_read_cache(blkid_cache cache)
|
||||
continue;
|
||||
end = strlen(buf) - 1;
|
||||
/* Continue reading next line if it ends with a backslash */
|
||||
while (buf[end] == '\\' && end < sizeof(buf) - 2 &&
|
||||
while (end < sizeof(buf) - 2 && buf[end] == '\\' &&
|
||||
fgets(buf + end, sizeof(buf) - end, file)) {
|
||||
end = strlen(buf) - 1;
|
||||
lineno++;
|
||||
|
||||
@@ -356,7 +356,7 @@ void usage(char *prog)
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask] device "
|
||||
"[type value]\n",
|
||||
prog);
|
||||
fprintf(stderr, "\tList all tags for a device and exit\n", prog);
|
||||
fprintf(stderr, "\tList all tags for a device and exit\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ int main(int argc, char **argv)
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %d\n",
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
@@ -407,7 +407,7 @@ int main(int argc, char **argv)
|
||||
|
||||
dev = blkid_get_dev(cache, devname, flags);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "%s: cannot find device in blkid cache\n");
|
||||
fprintf(stderr, "%s: cannot find device in blkid cache\n", devname);
|
||||
exit(1);
|
||||
}
|
||||
if (search_type) {
|
||||
|
||||
@@ -1050,7 +1050,7 @@ static errcode_t ea_refcount_create(int size, ext2_refcount_t *ret)
|
||||
refcount->size = size;
|
||||
bytes = (size_t) (size * sizeof(struct ea_refcount_el));
|
||||
#ifdef DEBUG
|
||||
printf("Refcount allocated %d entries, %d bytes.\n",
|
||||
printf("Refcount allocated %d entries, %lu bytes.\n",
|
||||
refcount->size, bytes);
|
||||
#endif
|
||||
retval = ext2fs_get_mem(bytes, &refcount->list);
|
||||
@@ -3424,7 +3424,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
|
||||
continue;
|
||||
}
|
||||
if ((inode->i_links_count || inode->i_blocks ||
|
||||
inode->i_blocks || inode->i_block[0]) &&
|
||||
inode->i_block[0]) &&
|
||||
fix_problem(ctx, PR_1_JOURNAL_INODE_NOT_CLEAR,
|
||||
&pctx)) {
|
||||
memset(inode, 0, inode_size);
|
||||
@@ -12195,11 +12195,7 @@ static void swap_filesys(e2fsck_t ctx)
|
||||
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
|
||||
const char *description)
|
||||
{
|
||||
void *ret;
|
||||
char buf[256];
|
||||
|
||||
ret = xzalloc(size);
|
||||
return ret;
|
||||
return xzalloc(size);
|
||||
}
|
||||
|
||||
static char *string_copy(const char *str, int len)
|
||||
|
||||
@@ -83,7 +83,7 @@ static int calc_reserved_gdt_blocks(ext2_filsys fs)
|
||||
if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
|
||||
rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);
|
||||
#ifdef RES_GDT_DEBUG
|
||||
printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %lu\n",
|
||||
printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %u\n",
|
||||
max_blocks, rsv_groups, rsv_gdb);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -544,7 +544,7 @@ static errcode_t unix_read_blk(io_channel channel, unsigned long block,
|
||||
/* If it's in the cache, use it! */
|
||||
if ((cache = find_cached_block(data, block, &reuse[0]))) {
|
||||
#ifdef DEBUG
|
||||
printf("Using cached block %d\n", block);
|
||||
printf("Using cached block %lu\n", block);
|
||||
#endif
|
||||
memcpy(cp, cache->buf, channel->block_size);
|
||||
count--;
|
||||
@@ -560,7 +560,7 @@ static errcode_t unix_read_blk(io_channel channel, unsigned long block,
|
||||
if (find_cached_block(data, block+i, &reuse[i]))
|
||||
break;
|
||||
#ifdef DEBUG
|
||||
printf("Reading %d blocks starting at %d\n", i, block);
|
||||
printf("Reading %d blocks starting at %lu\n", i, block);
|
||||
#endif
|
||||
if ((retval = raw_read_blk(channel, data, block, i, cp)))
|
||||
return retval;
|
||||
|
||||
@@ -1239,7 +1239,6 @@ static void PRS(int argc, char **argv)
|
||||
progress_fd = 0;
|
||||
else {
|
||||
goto next_arg;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -239,7 +239,7 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
|
||||
errcode_t retval;
|
||||
char buf[1024];
|
||||
|
||||
sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
|
||||
sprintf(buf, "badblocks -b %u %s%s%s %d", fs->blocksize,
|
||||
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
|
||||
fs->device_name, fs->super->s_blocks_count);
|
||||
mke2fs_verbose("Running command: %s\n", buf);
|
||||
@@ -385,7 +385,7 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num,
|
||||
struct progress_struct *progress,
|
||||
blk_t *ret_blk, int *ret_count)
|
||||
{
|
||||
int j, count, next_update, next_update_incr;
|
||||
int j, count, next_update;
|
||||
static char *buf;
|
||||
errcode_t retval;
|
||||
|
||||
@@ -403,9 +403,7 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num,
|
||||
}
|
||||
/* OK, do the write loop */
|
||||
next_update = 0;
|
||||
next_update_incr = num / 100;
|
||||
if (next_update_incr < 1)
|
||||
next_update_incr = 1;
|
||||
|
||||
for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
|
||||
count = num - j;
|
||||
if (count > STRIDE_LENGTH)
|
||||
|
||||
@@ -607,7 +607,7 @@ int tune2fs_main(int argc, char **argv)
|
||||
if (e_flag) {
|
||||
sb->s_errors = errors;
|
||||
ext2fs_mark_super_dirty(fs);
|
||||
printf("Setting error behavior to %d\n", errors);
|
||||
printf("Setting error behavior to %u\n", errors);
|
||||
}
|
||||
if (g_flag) {
|
||||
sb->s_def_resgid = resgid;
|
||||
|
||||
@@ -117,7 +117,7 @@ void parse_journal_opts(char **journal_device, int *journal_flags,
|
||||
}
|
||||
if (strcmp(token, "device") == 0) {
|
||||
*journal_device = blkid_get_devname(NULL, arg, NULL);
|
||||
if (!journal_device) {
|
||||
if (!*journal_device) {
|
||||
journal_usage++;
|
||||
continue;
|
||||
}
|
||||
@@ -239,7 +239,7 @@ void make_journal_blocks(ext2_filsys fs, int journal_size, int journal_flags, in
|
||||
return;
|
||||
}
|
||||
if (!quiet)
|
||||
printf("Creating journal (%ld blocks): ", journal_blocks);
|
||||
printf("Creating journal (%lu blocks): ", journal_blocks);
|
||||
fflush(stdout);
|
||||
retval = ext2fs_add_journal_inode(fs, journal_blocks,
|
||||
journal_flags);
|
||||
|
||||
@@ -7,66 +7,6 @@ menu "Editors"
|
||||
|
||||
INSERT
|
||||
|
||||
config AWK
|
||||
bool "awk"
|
||||
default y
|
||||
help
|
||||
Awk is used as a pattern scanning and processing language. This is
|
||||
the BusyBox implementation of that programming language.
|
||||
|
||||
config FEATURE_AWK_LIBM
|
||||
bool "Enable math functions (requires libm)"
|
||||
default y
|
||||
depends on AWK
|
||||
help
|
||||
Enable math functions of the Awk programming language.
|
||||
NOTE: This will require libm to be present for linking.
|
||||
|
||||
config CMP
|
||||
bool "cmp"
|
||||
default y
|
||||
help
|
||||
cmp is used to compare two files and returns the result
|
||||
to standard output.
|
||||
|
||||
config DIFF
|
||||
bool "diff"
|
||||
default y
|
||||
help
|
||||
diff compares two files or directories and outputs the
|
||||
differences between them in a form that can be given to
|
||||
the patch command.
|
||||
|
||||
config FEATURE_DIFF_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default y
|
||||
depends on DIFF && LONG_OPTS
|
||||
help
|
||||
Enable use of long options.
|
||||
|
||||
config FEATURE_DIFF_DIR
|
||||
bool "Enable directory support"
|
||||
default y
|
||||
depends on DIFF
|
||||
help
|
||||
This option enables support for directory and subdirectory
|
||||
comparison.
|
||||
|
||||
config ED
|
||||
bool "ed"
|
||||
default y
|
||||
help
|
||||
The original 1970's Unix text editor, from the days of teletypes.
|
||||
Small, simple, evil. Part of SUSv3. If you're not already using
|
||||
this, you don't need it.
|
||||
|
||||
config SED
|
||||
bool "sed"
|
||||
default y
|
||||
help
|
||||
sed is used to perform text transformations on a file
|
||||
or input from a pipeline.
|
||||
|
||||
config FEATURE_ALLOW_EXEC
|
||||
bool "Allow vi and awk to execute shell commands"
|
||||
default y
|
||||
|
||||
@@ -7,8 +7,3 @@
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
lib-$(CONFIG_AWK) += awk.o
|
||||
lib-$(CONFIG_CMP) += cmp.o
|
||||
lib-$(CONFIG_DIFF) += diff.o
|
||||
lib-$(CONFIG_ED) += ed.o
|
||||
lib-$(CONFIG_SED) += sed.o
|
||||
+102
-34
@@ -7,12 +7,45 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config AWK
|
||||
//config: bool "awk"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Awk is used as a pattern scanning and processing language. This is
|
||||
//config: the BusyBox implementation of that programming language.
|
||||
//config:
|
||||
//config:config FEATURE_AWK_LIBM
|
||||
//config: bool "Enable math functions (requires libm)"
|
||||
//config: default y
|
||||
//config: depends on AWK
|
||||
//config: help
|
||||
//config: Enable math functions of the Awk programming language.
|
||||
//config: NOTE: This will require libm to be present for linking.
|
||||
//config:
|
||||
//config:config FEATURE_AWK_GNU_EXTENSIONS
|
||||
//config: bool "Enable a few GNU extensions"
|
||||
//config: default y
|
||||
//config: depends on AWK
|
||||
//config: help
|
||||
//config: Enable a few features from gawk:
|
||||
//config: * command line option -e AWK_PROGRAM
|
||||
//config: * simultaneous use of -f and -e on the command line.
|
||||
//config: This enables the use of awk library files.
|
||||
//config: Ex: awk -f mylib.awk -e '{print myfunction($1);}' ...
|
||||
|
||||
//applet:IF_AWK(APPLET_NOEXEC(awk, awk, BB_DIR_USR_BIN, BB_SUID_DROP, awk))
|
||||
|
||||
//kbuild:lib-$(CONFIG_AWK) += awk.o
|
||||
|
||||
//usage:#define awk_trivial_usage
|
||||
//usage: "[OPTIONS] [AWK_PROGRAM] [FILE]..."
|
||||
//usage:#define awk_full_usage "\n\n"
|
||||
//usage: " -v VAR=VAL Set variable"
|
||||
//usage: "\n -F SEP Use SEP as field separator"
|
||||
//usage: "\n -f FILE Read program from FILE"
|
||||
//usage: IF_FEATURE_AWK_GNU_EXTENSIONS(
|
||||
//usage: "\n -e AWK_PROGRAM"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
#include "xregex.h"
|
||||
@@ -38,6 +71,25 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define OPTSTR_AWK \
|
||||
"F:v:f:" \
|
||||
IF_FEATURE_AWK_GNU_EXTENSIONS("e:") \
|
||||
"W:"
|
||||
#define OPTCOMPLSTR_AWK \
|
||||
"v::f::" \
|
||||
IF_FEATURE_AWK_GNU_EXTENSIONS("e::")
|
||||
enum {
|
||||
OPTBIT_F, /* define field separator */
|
||||
OPTBIT_v, /* define variable */
|
||||
OPTBIT_f, /* pull in awk program from file */
|
||||
IF_FEATURE_AWK_GNU_EXTENSIONS(OPTBIT_e,) /* -e AWK_PROGRAM */
|
||||
OPTBIT_W, /* -W ignored */
|
||||
OPT_F = 1 << OPTBIT_F,
|
||||
OPT_v = 1 << OPTBIT_v,
|
||||
OPT_f = 1 << OPTBIT_f,
|
||||
OPT_e = IF_FEATURE_AWK_GNU_EXTENSIONS((1 << OPTBIT_e)) + 0,
|
||||
OPT_W = 1 << OPTBIT_W
|
||||
};
|
||||
|
||||
#define MAXVARFMT 240
|
||||
#define MINNVBLOCK 64
|
||||
@@ -190,7 +242,7 @@ typedef struct tsplitter_s {
|
||||
|
||||
/* combined token classes */
|
||||
#define TC_BINOP (TC_BINOPX | TC_COMMA | TC_PIPE | TC_IN)
|
||||
#define TC_UNARYOP (TC_UOPPRE | TC_UOPPOST)
|
||||
//#define TC_UNARYOP (TC_UOPPRE | TC_UOPPOST)
|
||||
#define TC_OPERAND (TC_VARIABLE | TC_ARRAY | TC_FUNCTION \
|
||||
| TC_BUILTIN | TC_GETLINE | TC_SEQSTART | TC_STRING | TC_NUMBER)
|
||||
|
||||
@@ -2015,8 +2067,8 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i
|
||||
char c;
|
||||
const char *s = format;
|
||||
|
||||
if (int_as_int && n == (int)n) {
|
||||
r = snprintf(b, size, "%d", (int)n);
|
||||
if (int_as_int && n == (long long)n) {
|
||||
r = snprintf(b, size, "%lld", (long long)n);
|
||||
} else {
|
||||
do { c = *s; } while (c && *++s);
|
||||
if (strchr("diouxX", c)) {
|
||||
@@ -2661,7 +2713,8 @@ static var *evaluate(node *op, var *res)
|
||||
var *vbeg, *v;
|
||||
const char *sv_progname;
|
||||
|
||||
if (!op->r.f->body.first)
|
||||
/* The body might be empty, still has to eval the args */
|
||||
if (!op->r.n->info && !op->r.f->body.first)
|
||||
syntax_error(EMSG_UNDEF_FUNC);
|
||||
|
||||
vbeg = v = nvalloc(op->r.f->nargs + 1);
|
||||
@@ -2732,7 +2785,7 @@ static var *evaluate(node *op, var *res)
|
||||
|
||||
switch (opn) {
|
||||
case F_in:
|
||||
R_d = (int)L_d;
|
||||
R_d = (long long)L_d;
|
||||
break;
|
||||
|
||||
case F_rn:
|
||||
@@ -2783,8 +2836,16 @@ static var *evaluate(node *op, var *res)
|
||||
break;
|
||||
|
||||
case F_le:
|
||||
if (!op1)
|
||||
debug_printf_eval("length: L.s:'%s'\n", L.s);
|
||||
if (!op1) {
|
||||
L.s = getvar_s(intvar[F0]);
|
||||
debug_printf_eval("length: L.s='%s'\n", L.s);
|
||||
}
|
||||
else if (L.v->type & VF_ARRAY) {
|
||||
R_d = L.v->x.array->nel;
|
||||
debug_printf_eval("length: array_len:%d\n", L.v->x.array->nel);
|
||||
break;
|
||||
}
|
||||
R_d = strlen(L.s);
|
||||
break;
|
||||
|
||||
@@ -2930,7 +2991,7 @@ static var *evaluate(node *op, var *res)
|
||||
case '%':
|
||||
if (R_d == 0)
|
||||
syntax_error(EMSG_DIV_BY_ZERO);
|
||||
L_d -= (int)(L_d / R_d) * R_d;
|
||||
L_d -= (long long)(L_d / R_d) * R_d;
|
||||
break;
|
||||
}
|
||||
debug_printf_eval("BINARY/REPLACE result:%f\n", L_d);
|
||||
@@ -3078,6 +3139,9 @@ int awk_main(int argc, char **argv)
|
||||
char *opt_F;
|
||||
llist_t *list_v = NULL;
|
||||
llist_t *list_f = NULL;
|
||||
#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
|
||||
llist_t *list_e = NULL;
|
||||
#endif
|
||||
int i, j;
|
||||
var *v;
|
||||
var tv;
|
||||
@@ -3136,47 +3200,51 @@ int awk_main(int argc, char **argv)
|
||||
*s1 = '=';
|
||||
}
|
||||
}
|
||||
opt_complementary = "v::f::"; /* -v and -f can occur multiple times */
|
||||
opt = getopt32(argv, "F:v:f:W:", &opt_F, &list_v, &list_f, NULL);
|
||||
opt_complementary = OPTCOMPLSTR_AWK;
|
||||
opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL);
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
if (opt & 0x1) { /* -F */
|
||||
if (opt & OPT_W)
|
||||
bb_error_msg("warning: option -W is ignored");
|
||||
if (opt & OPT_F) {
|
||||
unescape_string_in_place(opt_F);
|
||||
setvar_s(intvar[FS], opt_F);
|
||||
}
|
||||
while (list_v) { /* -v */
|
||||
while (list_v) {
|
||||
if (!is_assignment(llist_pop(&list_v)))
|
||||
bb_show_usage();
|
||||
}
|
||||
if (list_f) { /* -f */
|
||||
do {
|
||||
char *s = NULL;
|
||||
FILE *from_file;
|
||||
while (list_f) {
|
||||
char *s = NULL;
|
||||
FILE *from_file;
|
||||
|
||||
g_progname = llist_pop(&list_f);
|
||||
from_file = xfopen_stdin(g_progname);
|
||||
/* one byte is reserved for some trick in next_token */
|
||||
for (i = j = 1; j > 0; i += j) {
|
||||
s = xrealloc(s, i + 4096);
|
||||
j = fread(s + i, 1, 4094, from_file);
|
||||
}
|
||||
s[i] = '\0';
|
||||
fclose(from_file);
|
||||
parse_program(s + 1);
|
||||
free(s);
|
||||
} while (list_f);
|
||||
argc++;
|
||||
} else { // no -f: take program from 1st parameter
|
||||
if (!argc)
|
||||
g_progname = llist_pop(&list_f);
|
||||
from_file = xfopen_stdin(g_progname);
|
||||
/* one byte is reserved for some trick in next_token */
|
||||
for (i = j = 1; j > 0; i += j) {
|
||||
s = xrealloc(s, i + 4096);
|
||||
j = fread(s + i, 1, 4094, from_file);
|
||||
}
|
||||
s[i] = '\0';
|
||||
fclose(from_file);
|
||||
parse_program(s + 1);
|
||||
free(s);
|
||||
}
|
||||
g_progname = "cmd. line";
|
||||
#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
|
||||
while (list_e) {
|
||||
parse_program(llist_pop(&list_e));
|
||||
}
|
||||
#endif
|
||||
if (!(opt & (OPT_f | OPT_e))) {
|
||||
if (!*argv)
|
||||
bb_show_usage();
|
||||
g_progname = "cmd. line";
|
||||
parse_program(*argv++);
|
||||
argc--;
|
||||
}
|
||||
if (opt & 0x8) // -W
|
||||
bb_error_msg("warning: option -W is ignored");
|
||||
|
||||
/* fill in ARGV array */
|
||||
setvar_i(intvar[ARGC], argc);
|
||||
setvar_i(intvar[ARGC], argc + 1);
|
||||
setari_u(intvar[ARGV], 0, "awk");
|
||||
i = 0;
|
||||
while (*argv)
|
||||
|
||||
@@ -10,6 +10,17 @@
|
||||
/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */
|
||||
|
||||
//config:config CMP
|
||||
//config: bool "cmp"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cmp is used to compare two files and returns the result
|
||||
//config: to standard output.
|
||||
|
||||
//kbuild:lib-$(CONFIG_CMP) += cmp.o
|
||||
|
||||
//applet:IF_CMP(APPLET(cmp, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define cmp_trivial_usage
|
||||
//usage: "[-l] [-s] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]"
|
||||
//usage:#define cmp_full_usage "\n\n"
|
||||
|
||||
@@ -76,6 +76,33 @@
|
||||
* 6n words for files of length n.
|
||||
*/
|
||||
|
||||
//config:config DIFF
|
||||
//config: bool "diff"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: diff compares two files or directories and outputs the
|
||||
//config: differences between them in a form that can be given to
|
||||
//config: the patch command.
|
||||
//config:
|
||||
//config:config FEATURE_DIFF_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on DIFF && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable use of long options.
|
||||
//config:
|
||||
//config:config FEATURE_DIFF_DIR
|
||||
//config: bool "Enable directory support"
|
||||
//config: default y
|
||||
//config: depends on DIFF
|
||||
//config: help
|
||||
//config: This option enables support for directory and subdirectory
|
||||
//config: comparison.
|
||||
|
||||
//kbuild:lib-$(CONFIG_DIFF) += diff.o
|
||||
|
||||
//applet:IF_DIFF(APPLET(diff, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define diff_trivial_usage
|
||||
//usage: "[-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
|
||||
//usage:#define diff_full_usage "\n\n"
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
* The "ed" built-in command (much simplified)
|
||||
*/
|
||||
|
||||
//config:config ED
|
||||
//config: bool "ed"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: The original 1970's Unix text editor, from the days of teletypes.
|
||||
//config: Small, simple, evil. Part of SUSv3. If you're not already using
|
||||
//config: this, you don't need it.
|
||||
|
||||
//kbuild:lib-$(CONFIG_ED) += ed.o
|
||||
|
||||
//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define ed_trivial_usage ""
|
||||
//usage:#define ed_full_usage ""
|
||||
|
||||
|
||||
@@ -188,8 +188,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned src_last_line = 1;
|
||||
unsigned dst_last_line = 1;
|
||||
|
||||
if ((sscanf(patch_line, "@@ -%d,%d +%d,%d", &src_beg_line, &src_last_line, &dst_beg_line, &dst_last_line) < 3)
|
||||
&& (sscanf(patch_line, "@@ -%d +%d,%d", &src_beg_line, &dst_beg_line, &dst_last_line) < 2)
|
||||
if ((sscanf(patch_line, "@@ -%u,%u +%u,%u", &src_beg_line, &src_last_line, &dst_beg_line, &dst_last_line) < 3)
|
||||
&& (sscanf(patch_line, "@@ -%u +%u,%u", &src_beg_line, &dst_beg_line, &dst_last_line) < 2)
|
||||
) {
|
||||
/* No more hunks for this file */
|
||||
break;
|
||||
|
||||
+154
-144
@@ -23,9 +23,6 @@
|
||||
* resulting sed_cmd_t structures are appended to a linked list
|
||||
* (G.sed_cmd_head/G.sed_cmd_tail).
|
||||
*
|
||||
* add_input_file() adds a FILE* to the list of input files. We need to
|
||||
* know all input sources ahead of time to find the last line for the $ match.
|
||||
*
|
||||
* process_files() does actual sedding, reading data lines from each input FILE*
|
||||
* (which could be stdin) and applying the sed command list (sed_cmd_head) to
|
||||
* each of the resulting lines.
|
||||
@@ -58,16 +55,27 @@
|
||||
* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
|
||||
*/
|
||||
|
||||
//config:config SED
|
||||
//config: bool "sed"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: sed is used to perform text transformations on a file
|
||||
//config: or input from a pipeline.
|
||||
|
||||
//kbuild:lib-$(CONFIG_SED) += sed.o
|
||||
|
||||
//applet:IF_SED(APPLET(sed, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define sed_trivial_usage
|
||||
//usage: "[-inr] [-f FILE]... [-e CMD]... [FILE]...\n"
|
||||
//usage: "or: sed [-inr] CMD [FILE]..."
|
||||
//usage: "[-inrE] [-f FILE]... [-e CMD]... [FILE]...\n"
|
||||
//usage: "or: sed [-inrE] CMD [FILE]..."
|
||||
//usage:#define sed_full_usage "\n\n"
|
||||
//usage: " -e CMD Add CMD to sed commands to be executed"
|
||||
//usage: "\n -f FILE Add FILE contents to sed commands to be executed"
|
||||
//usage: "\n -i[SFX] Edit files in-place (otherwise sends to stdout)"
|
||||
//usage: "\n Optionally back files up, appending SFX"
|
||||
//usage: "\n -n Suppress automatic printing of pattern space"
|
||||
//usage: "\n -r Use extended regex syntax"
|
||||
//usage: "\n -r,-E Use extended regex syntax"
|
||||
//usage: "\n"
|
||||
//usage: "\nIf no -e or -f, the first non-option argument is the sed command string."
|
||||
//usage: "\nRemaining arguments are input files (stdin if none)."
|
||||
@@ -124,12 +132,15 @@ static const char semicolon_whitespace[] ALIGN1 = "; \n\r\t\v";
|
||||
struct globals {
|
||||
/* options */
|
||||
int be_quiet, regex_type;
|
||||
|
||||
FILE *nonstdout;
|
||||
char *outname, *hold_space;
|
||||
smallint exitcode;
|
||||
|
||||
/* List of input files */
|
||||
int input_file_count, current_input_file;
|
||||
FILE **input_file_list;
|
||||
/* list of input files */
|
||||
int current_input_file, last_input_file;
|
||||
char **input_file_list;
|
||||
FILE *current_fp;
|
||||
|
||||
regmatch_t regmatch[10];
|
||||
regex_t *previous_regex_ptr;
|
||||
@@ -137,7 +148,7 @@ struct globals {
|
||||
/* linked list of sed commands */
|
||||
sed_cmd_t *sed_cmd_head, **sed_cmd_tail;
|
||||
|
||||
/* Linked list of append lines */
|
||||
/* linked list of append lines */
|
||||
llist_t *append_head;
|
||||
|
||||
char *add_cmd_line;
|
||||
@@ -189,8 +200,8 @@ static void sed_free_and_close_stuff(void)
|
||||
|
||||
free(G.hold_space);
|
||||
|
||||
while (G.current_input_file < G.input_file_count)
|
||||
fclose(G.input_file_list[G.current_input_file++]);
|
||||
if (G.current_fp)
|
||||
fclose(G.current_fp);
|
||||
}
|
||||
#else
|
||||
void sed_free_and_close_stuff(void);
|
||||
@@ -330,7 +341,7 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
|
||||
next = index_of_next_unescaped_regexp_delim(delimiter, ++pos);
|
||||
temp = copy_parsing_escapes(pos, next);
|
||||
*regex = xzalloc(sizeof(regex_t));
|
||||
xregcomp(*regex, temp, G.regex_type|REG_NEWLINE);
|
||||
xregcomp(*regex, temp, G.regex_type);
|
||||
free(temp);
|
||||
/* Move position to next character after last delimiter */
|
||||
pos += (next+1);
|
||||
@@ -370,7 +381,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
|
||||
|
||||
/*
|
||||
* A substitution command should look something like this:
|
||||
* s/match/replace/ #gIpw
|
||||
* s/match/replace/ #giIpw
|
||||
* || | |||
|
||||
* mandatory optional
|
||||
*/
|
||||
@@ -418,6 +429,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
|
||||
break;
|
||||
}
|
||||
/* Ignore case (gnu exension) */
|
||||
case 'i':
|
||||
case 'I':
|
||||
cflags |= REG_ICASE;
|
||||
break;
|
||||
@@ -649,6 +661,12 @@ static void add_cmd(const char *cmdstr)
|
||||
sed_cmd->cmd = *cmdstr++;
|
||||
cmdstr = parse_cmd_args(sed_cmd, cmdstr);
|
||||
|
||||
/* cmdstr now points past args.
|
||||
* GNU sed requires a separator, if there are more commands,
|
||||
* else it complains "char N: extra characters after command".
|
||||
* Example: "sed 'p;d'". We also allow "sed 'pd'".
|
||||
*/
|
||||
|
||||
/* Add the command to the command array */
|
||||
*G.sed_cmd_tail = sed_cmd;
|
||||
G.sed_cmd_tail = &sed_cmd->next;
|
||||
@@ -842,81 +860,7 @@ static sed_cmd_t *branch_to(char *label)
|
||||
|
||||
static void append(char *s)
|
||||
{
|
||||
llist_add_to_end(&G.append_head, xstrdup(s));
|
||||
}
|
||||
|
||||
static void flush_append(void)
|
||||
{
|
||||
char *data;
|
||||
|
||||
/* Output appended lines. */
|
||||
while ((data = (char *)llist_pop(&G.append_head))) {
|
||||
fprintf(G.nonstdout, "%s\n", data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
static void add_input_file(FILE *file)
|
||||
{
|
||||
G.input_file_list = xrealloc_vector(G.input_file_list, 2, G.input_file_count);
|
||||
G.input_file_list[G.input_file_count++] = file;
|
||||
}
|
||||
|
||||
/* Get next line of input from G.input_file_list, flushing append buffer and
|
||||
* noting if we ran out of files without a newline on the last line we read.
|
||||
*/
|
||||
enum {
|
||||
NO_EOL_CHAR = 1,
|
||||
LAST_IS_NUL = 2,
|
||||
};
|
||||
static char *get_next_line(char *gets_char)
|
||||
{
|
||||
char *temp = NULL;
|
||||
int len;
|
||||
char gc;
|
||||
|
||||
flush_append();
|
||||
|
||||
/* will be returned if last line in the file
|
||||
* doesn't end with either '\n' or '\0' */
|
||||
gc = NO_EOL_CHAR;
|
||||
while (G.current_input_file < G.input_file_count) {
|
||||
FILE *fp = G.input_file_list[G.current_input_file];
|
||||
/* Read line up to a newline or NUL byte, inclusive,
|
||||
* return malloc'ed char[]. length of the chunk read
|
||||
* is stored in len. NULL if EOF/error */
|
||||
temp = bb_get_chunk_from_file(fp, &len);
|
||||
if (temp) {
|
||||
/* len > 0 here, it's ok to do temp[len-1] */
|
||||
char c = temp[len-1];
|
||||
if (c == '\n' || c == '\0') {
|
||||
temp[len-1] = '\0';
|
||||
gc = c;
|
||||
if (c == '\0') {
|
||||
int ch = fgetc(fp);
|
||||
if (ch != EOF)
|
||||
ungetc(ch, fp);
|
||||
else
|
||||
gc = LAST_IS_NUL;
|
||||
}
|
||||
}
|
||||
/* else we put NO_EOL_CHAR into *gets_char */
|
||||
break;
|
||||
|
||||
/* NB: I had the idea of peeking next file(s) and returning
|
||||
* NO_EOL_CHAR only if it is the *last* non-empty
|
||||
* input file. But there is a case where this won't work:
|
||||
* file1: "a woo\nb woo"
|
||||
* file2: "c no\nd no"
|
||||
* sed -ne 's/woo/bang/p' input1 input2 => "a bang\nb bang"
|
||||
* (note: *no* newline after "b bang"!) */
|
||||
}
|
||||
/* Close this file and advance to next one */
|
||||
fclose(fp);
|
||||
G.current_input_file++;
|
||||
}
|
||||
*gets_char = gc;
|
||||
return temp;
|
||||
llist_add_to_end(&G.append_head, s);
|
||||
}
|
||||
|
||||
/* Output line of text. */
|
||||
@@ -933,6 +877,10 @@ static char *get_next_line(char *gets_char)
|
||||
* bbox:
|
||||
* 00000000 74 68 7a 6e 67 79 61 67 61 7a 6e |thzngyagazn|
|
||||
*/
|
||||
enum {
|
||||
NO_EOL_CHAR = 1,
|
||||
LAST_IS_NUL = 2,
|
||||
};
|
||||
static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char last_gets_char)
|
||||
{
|
||||
char lpc = *last_puts_char;
|
||||
@@ -967,6 +915,82 @@ static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char l
|
||||
*last_puts_char = lpc;
|
||||
}
|
||||
|
||||
static void flush_append(char *last_puts_char, char last_gets_char)
|
||||
{
|
||||
char *data;
|
||||
|
||||
/* Output appended lines. */
|
||||
while ((data = (char *)llist_pop(&G.append_head))) {
|
||||
puts_maybe_newline(data, G.nonstdout, last_puts_char, last_gets_char);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get next line of input from G.input_file_list, flushing append buffer and
|
||||
* noting if we ran out of files without a newline on the last line we read.
|
||||
*/
|
||||
static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets_char)
|
||||
{
|
||||
char *temp = NULL;
|
||||
int len;
|
||||
char gc;
|
||||
|
||||
flush_append(last_puts_char, last_gets_char);
|
||||
|
||||
/* will be returned if last line in the file
|
||||
* doesn't end with either '\n' or '\0' */
|
||||
gc = NO_EOL_CHAR;
|
||||
for (; G.current_input_file <= G.last_input_file; G.current_input_file++) {
|
||||
FILE *fp = G.current_fp;
|
||||
if (!fp) {
|
||||
const char *path = G.input_file_list[G.current_input_file];
|
||||
fp = stdin;
|
||||
if (path != bb_msg_standard_input) {
|
||||
fp = fopen_or_warn(path, "r");
|
||||
if (!fp) {
|
||||
G.exitcode = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
G.current_fp = fp;
|
||||
}
|
||||
/* Read line up to a newline or NUL byte, inclusive,
|
||||
* return malloc'ed char[]. length of the chunk read
|
||||
* is stored in len. NULL if EOF/error */
|
||||
temp = bb_get_chunk_from_file(fp, &len);
|
||||
if (temp) {
|
||||
/* len > 0 here, it's ok to do temp[len-1] */
|
||||
char c = temp[len-1];
|
||||
if (c == '\n' || c == '\0') {
|
||||
temp[len-1] = '\0';
|
||||
gc = c;
|
||||
if (c == '\0') {
|
||||
int ch = fgetc(fp);
|
||||
if (ch != EOF)
|
||||
ungetc(ch, fp);
|
||||
else
|
||||
gc = LAST_IS_NUL;
|
||||
}
|
||||
}
|
||||
/* else we put NO_EOL_CHAR into *gets_char */
|
||||
break;
|
||||
|
||||
/* NB: I had the idea of peeking next file(s) and returning
|
||||
* NO_EOL_CHAR only if it is the *last* non-empty
|
||||
* input file. But there is a case where this won't work:
|
||||
* file1: "a woo\nb woo"
|
||||
* file2: "c no\nd no"
|
||||
* sed -ne 's/woo/bang/p' input1 input2 => "a bang\nb bang"
|
||||
* (note: *no* newline after "b bang"!) */
|
||||
}
|
||||
/* Close this file and advance to next one */
|
||||
fclose_if_not_stdin(fp);
|
||||
G.current_fp = NULL;
|
||||
}
|
||||
*gets_char = gc;
|
||||
return temp;
|
||||
}
|
||||
|
||||
#define sed_puts(s, n) (puts_maybe_newline(s, G.nonstdout, &last_puts_char, n))
|
||||
|
||||
static int beg_match(sed_cmd_t *sed_cmd, const char *pattern_space)
|
||||
@@ -989,7 +1013,7 @@ static void process_files(void)
|
||||
int substituted;
|
||||
|
||||
/* Prime the pump */
|
||||
next_line = get_next_line(&next_gets_char);
|
||||
next_line = get_next_line(&next_gets_char, &last_puts_char, '\n' /*last_gets_char*/);
|
||||
|
||||
/* Go through every line in each file */
|
||||
again:
|
||||
@@ -1003,7 +1027,7 @@ static void process_files(void)
|
||||
|
||||
/* Read one line in advance so we can act on the last line,
|
||||
* the '$' address */
|
||||
next_line = get_next_line(&next_gets_char);
|
||||
next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
|
||||
linenum++;
|
||||
|
||||
/* For every line, go through all the commands */
|
||||
@@ -1175,7 +1199,7 @@ static void process_files(void)
|
||||
|
||||
/* Append line to linked list to be printed later */
|
||||
case 'a':
|
||||
append(sed_cmd->string);
|
||||
append(xstrdup(sed_cmd->string));
|
||||
break;
|
||||
|
||||
/* Insert text before this line */
|
||||
@@ -1197,11 +1221,10 @@ static void process_files(void)
|
||||
rfile = fopen_for_read(sed_cmd->string);
|
||||
if (rfile) {
|
||||
char *line;
|
||||
|
||||
while ((line = xmalloc_fgetline(rfile))
|
||||
!= NULL)
|
||||
append(line);
|
||||
xprint_and_close_file(rfile);
|
||||
fclose(rfile);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1222,7 +1245,7 @@ static void process_files(void)
|
||||
free(pattern_space);
|
||||
pattern_space = next_line;
|
||||
last_gets_char = next_gets_char;
|
||||
next_line = get_next_line(&next_gets_char);
|
||||
next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
|
||||
substituted = 0;
|
||||
linenum++;
|
||||
break;
|
||||
@@ -1258,7 +1281,7 @@ static void process_files(void)
|
||||
pattern_space[len] = '\n';
|
||||
strcpy(pattern_space + len+1, next_line);
|
||||
last_gets_char = next_gets_char;
|
||||
next_line = get_next_line(&next_gets_char);
|
||||
next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
|
||||
linenum++;
|
||||
break;
|
||||
}
|
||||
@@ -1362,7 +1385,7 @@ static void process_files(void)
|
||||
|
||||
/* Delete and such jump here. */
|
||||
discard_line:
|
||||
flush_append();
|
||||
flush_append(&last_puts_char, last_gets_char);
|
||||
free(pattern_space);
|
||||
|
||||
goto again;
|
||||
@@ -1371,7 +1394,7 @@ static void process_files(void)
|
||||
/* It is possible to have a command line argument with embedded
|
||||
* newlines. This counts as multiple command lines.
|
||||
* However, newline can be escaped: 's/e/z\<newline>z/'
|
||||
* We check for this.
|
||||
* add_cmd() handles this.
|
||||
*/
|
||||
|
||||
static void add_cmd_block(char *cmdstr)
|
||||
@@ -1381,22 +1404,8 @@ static void add_cmd_block(char *cmdstr)
|
||||
cmdstr = sv = xstrdup(cmdstr);
|
||||
do {
|
||||
eol = strchr(cmdstr, '\n');
|
||||
next:
|
||||
if (eol) {
|
||||
/* Count preceding slashes */
|
||||
int slashes = 0;
|
||||
char *sl = eol;
|
||||
|
||||
while (sl != cmdstr && *--sl == '\\')
|
||||
slashes++;
|
||||
/* Odd number of preceding slashes - newline is escaped */
|
||||
if (slashes & 1) {
|
||||
overlapping_strcpy(eol - 1, eol);
|
||||
eol = strchr(eol, '\n');
|
||||
goto next;
|
||||
}
|
||||
if (eol)
|
||||
*eol = '\0';
|
||||
}
|
||||
add_cmd(cmdstr);
|
||||
cmdstr = eol + 1;
|
||||
} while (eol);
|
||||
@@ -1421,8 +1430,6 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
"file\0" Required_argument "f";
|
||||
#endif
|
||||
|
||||
int status = EXIT_SUCCESS;
|
||||
|
||||
INIT_G();
|
||||
|
||||
/* destroy command strings on exit */
|
||||
@@ -1443,15 +1450,21 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_LONG_OPTS(applet_long_options = sed_longopts);
|
||||
|
||||
/* -i must be first, to match OPT_in_place definition */
|
||||
opt = getopt32(argv, "i::rne:f:", &opt_i, &opt_e, &opt_f,
|
||||
/* -E is a synonym of -r:
|
||||
* GNU sed 4.2.1 mentions it in neither --help
|
||||
* nor manpage, but does recognize it.
|
||||
*/
|
||||
opt = getopt32(argv, "i::rEne:f:", &opt_i, &opt_e, &opt_f,
|
||||
&G.be_quiet); /* counter for -n */
|
||||
//argc -= optind;
|
||||
argv += optind;
|
||||
if (opt & OPT_in_place) { // -i
|
||||
atexit(cleanup_outname);
|
||||
}
|
||||
if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r
|
||||
//if (opt & 0x4) G.be_quiet++; // -n
|
||||
if (opt & (2|4))
|
||||
G.regex_type |= REG_EXTENDED; // -r or -E
|
||||
//if (opt & 8)
|
||||
// G.be_quiet++; // -n (implemented with a counter instead)
|
||||
while (opt_e) { // -e
|
||||
add_cmd_block(llist_pop(&opt_e));
|
||||
}
|
||||
@@ -1466,7 +1479,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
fclose(cmdfile);
|
||||
}
|
||||
/* if we didn't get a pattern from -e or -f, use argv[0] */
|
||||
if (!(opt & 0x18)) {
|
||||
if (!(opt & 0x30)) {
|
||||
if (!*argv)
|
||||
bb_show_usage();
|
||||
add_cmd_block(*argv++);
|
||||
@@ -1480,42 +1493,38 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* 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) {
|
||||
G.input_file_list = argv;
|
||||
if (!argv[0]) {
|
||||
if (opt & OPT_in_place)
|
||||
bb_error_msg_and_die(bb_msg_requires_arg, "-i");
|
||||
add_input_file(stdin);
|
||||
argv[0] = (char*)bb_msg_standard_input;
|
||||
/* G.last_input_file = 0; - already is */
|
||||
} else {
|
||||
int i;
|
||||
goto start;
|
||||
|
||||
for (i = 0; argv[i]; i++) {
|
||||
for (; *argv; argv++) {
|
||||
struct stat statbuf;
|
||||
int nonstdoutfd;
|
||||
FILE *file;
|
||||
sed_cmd_t *sed_cmd;
|
||||
|
||||
if (LONE_DASH(argv[i]) && !(opt & OPT_in_place)) {
|
||||
add_input_file(stdin);
|
||||
process_files();
|
||||
continue;
|
||||
}
|
||||
file = fopen_or_warn(argv[i], "r");
|
||||
if (!file) {
|
||||
status = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
add_input_file(file);
|
||||
G.last_input_file++;
|
||||
start:
|
||||
if (!(opt & OPT_in_place)) {
|
||||
if (LONE_DASH(*argv)) {
|
||||
*argv = (char*)bb_msg_standard_input;
|
||||
process_files();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* -i: process each FILE separately: */
|
||||
|
||||
G.outname = xasprintf("%sXXXXXX", argv[i]);
|
||||
G.outname = xasprintf("%sXXXXXX", *argv);
|
||||
nonstdoutfd = xmkstemp(G.outname);
|
||||
G.nonstdout = xfdopen_for_write(nonstdoutfd);
|
||||
|
||||
/* Set permissions/owner of output file */
|
||||
fstat(fileno(file), &statbuf);
|
||||
stat(*argv, &statbuf);
|
||||
/* chmod'ing AFTER chown would preserve suid/sgid bits,
|
||||
* but GNU sed 4.2.1 does not preserve them either */
|
||||
fchmod(nonstdoutfd, statbuf.st_mode);
|
||||
@@ -1526,12 +1535,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.nonstdout = stdout;
|
||||
|
||||
if (opt_i) {
|
||||
char *backupname = xasprintf("%s%s", argv[i], opt_i);
|
||||
xrename(argv[i], backupname);
|
||||
char *backupname = xasprintf("%s%s", *argv, opt_i);
|
||||
xrename(*argv, backupname);
|
||||
free(backupname);
|
||||
}
|
||||
/* else unlink(argv[i]); - rename below does this */
|
||||
xrename(G.outname, argv[i]); //TODO: rollback backup on error?
|
||||
/* else unlink(*argv); - rename below does this */
|
||||
xrename(G.outname, *argv); //TODO: rollback backup on error?
|
||||
free(G.outname);
|
||||
G.outname = NULL;
|
||||
|
||||
@@ -1541,12 +1550,13 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
}
|
||||
/* Here, to handle "sed 'cmds' nonexistent_file" case we did:
|
||||
* if (G.current_input_file >= G.input_file_count)
|
||||
* return status;
|
||||
* if (G.current_input_file[G.current_input_file] == NULL)
|
||||
* return G.exitcode;
|
||||
* but it's not needed since process_files() works correctly
|
||||
* in this case too. */
|
||||
}
|
||||
|
||||
process_files();
|
||||
|
||||
return status;
|
||||
return G.exitcode;
|
||||
}
|
||||
+48
-54
@@ -478,6 +478,7 @@ static void flash(int); // flash the terminal screen
|
||||
static void show_status_line(void); // put a message on the bottom line
|
||||
static void status_line(const char *, ...); // print to status buf
|
||||
static void status_line_bold(const char *, ...);
|
||||
static void status_line_bold_errno(const char *fn);
|
||||
static void not_implemented(const char *); // display "Not implemented" message
|
||||
static int format_edit_status(void); // format file status on status line
|
||||
static void redraw(int); // force a full screen refresh
|
||||
@@ -1049,7 +1050,7 @@ static void colon(char *buf)
|
||||
#endif
|
||||
// how many lines in text[]?
|
||||
li = count_lines(text, end - 1);
|
||||
status_line("\"%s\"%s"
|
||||
status_line("'%s'%s"
|
||||
IF_FEATURE_VI_READONLY("%s")
|
||||
" %dL, %dC", current_filename,
|
||||
(file_size(fn) < 0 ? " [New file]" : ""),
|
||||
@@ -1165,7 +1166,7 @@ static void colon(char *buf)
|
||||
goto ret; // nothing was inserted
|
||||
// how many lines in text[]?
|
||||
li = count_lines(q, q + ch - 1);
|
||||
status_line("\"%s\""
|
||||
status_line("'%s'"
|
||||
IF_FEATURE_VI_READONLY("%s")
|
||||
" %dL, %dC", fn,
|
||||
IF_FEATURE_VI_READONLY((readonly_mode ? " [Readonly]" : ""),)
|
||||
@@ -1298,7 +1299,7 @@ static void colon(char *buf)
|
||||
}
|
||||
#if ENABLE_FEATURE_VI_READONLY
|
||||
if (readonly_mode && !useforce) {
|
||||
status_line_bold("\"%s\" File is read only", fn);
|
||||
status_line_bold("'%s' is read only", fn);
|
||||
goto ret;
|
||||
}
|
||||
#endif
|
||||
@@ -1321,9 +1322,9 @@ static void colon(char *buf)
|
||||
}
|
||||
if (l < 0) {
|
||||
if (l == -1)
|
||||
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
||||
status_line_bold_errno(fn);
|
||||
} else {
|
||||
status_line("\"%s\" %dL, %dC", fn, li, l);
|
||||
status_line("'%s' %dL, %dC", fn, li, l);
|
||||
if (q == text && r == end - 1 && l == ch) {
|
||||
file_modified = 0;
|
||||
last_file_modified = -1;
|
||||
@@ -1706,65 +1707,53 @@ static char *new_screen(int ro, int co)
|
||||
// search for pattern starting at p
|
||||
static char *char_search(char *p, const char *pat, int dir, int range)
|
||||
{
|
||||
char *q;
|
||||
struct re_pattern_buffer preg;
|
||||
const char *err;
|
||||
char *q;
|
||||
int i;
|
||||
int size;
|
||||
|
||||
re_syntax_options = RE_SYNTAX_POSIX_EXTENDED;
|
||||
preg.translate = 0;
|
||||
preg.fastmap = 0;
|
||||
preg.buffer = 0;
|
||||
preg.allocated = 0;
|
||||
if (ignorecase)
|
||||
re_syntax_options = RE_SYNTAX_POSIX_EXTENDED | RE_ICASE;
|
||||
|
||||
memset(&preg, 0, sizeof(preg));
|
||||
err = re_compile_pattern(pat, strlen(pat), &preg);
|
||||
if (err != NULL) {
|
||||
status_line_bold("bad search pattern '%s': %s", pat, err);
|
||||
return p;
|
||||
}
|
||||
|
||||
// assume a LIMITED forward search
|
||||
q = next_line(p);
|
||||
q = end_line(q);
|
||||
q = end - 1;
|
||||
if (dir == BACK) {
|
||||
q = prev_line(p);
|
||||
if (dir == BACK)
|
||||
q = text;
|
||||
}
|
||||
// count the number of chars to search over, forward or backward
|
||||
size = q - p;
|
||||
if (size < 0)
|
||||
size = p - q;
|
||||
// RANGE could be negative if we are searching backwards
|
||||
range = q - p;
|
||||
|
||||
q = (char *)re_compile_pattern(pat, strlen(pat), (struct re_pattern_buffer *)&preg);
|
||||
if (q != 0) {
|
||||
// The pattern was not compiled
|
||||
status_line_bold("bad search pattern: \"%s\": %s", pat, q);
|
||||
i = 0; // return p if pattern not compiled
|
||||
goto cs1;
|
||||
}
|
||||
|
||||
q = p;
|
||||
size = range;
|
||||
if (range < 0) {
|
||||
size = -size;
|
||||
q = p - size;
|
||||
if (q < text)
|
||||
q = text;
|
||||
}
|
||||
// search for the compiled pattern, preg, in p[]
|
||||
// range < 0- search backward
|
||||
// range > 0- search forward
|
||||
// range < 0: search backward
|
||||
// range > 0: search forward
|
||||
// 0 < start < size
|
||||
// re_search() < 0 not found or error
|
||||
// re_search() > 0 index of found pattern
|
||||
// struct pattern char int int int struct reg
|
||||
// re_search (*pattern_buffer, *string, size, start, range, *regs)
|
||||
i = re_search(&preg, q, size, 0, range, 0);
|
||||
if (i == -1) {
|
||||
p = 0;
|
||||
i = 0; // return NULL if pattern not found
|
||||
}
|
||||
cs1:
|
||||
if (dir == FORWARD) {
|
||||
// re_search() < 0: not found or error
|
||||
// re_search() >= 0: index of found pattern
|
||||
// struct pattern char int int int struct reg
|
||||
// re_search(*pattern_buffer, *string, size, start, range, *regs)
|
||||
i = re_search(&preg, q, size, /*start:*/ 0, range, /*struct re_registers*:*/ NULL);
|
||||
regfree(&preg);
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
if (dir == FORWARD)
|
||||
p = p + i;
|
||||
} else {
|
||||
else
|
||||
p = p - i;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -1789,7 +1778,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
|
||||
|
||||
len = strlen(pat);
|
||||
if (dir == FORWARD) {
|
||||
stop = end - 1; // assume range is p - end-1
|
||||
stop = end - 1; // assume range is p..end-1
|
||||
if (range == LIMITED)
|
||||
stop = next_line(p); // range is to next line
|
||||
for (start = p; start < stop; start++) {
|
||||
@@ -1798,7 +1787,7 @@ static char *char_search(char *p, const char *pat, int dir, int range)
|
||||
}
|
||||
}
|
||||
} else if (dir == BACK) {
|
||||
stop = text; // assume range is text - p
|
||||
stop = text; // assume range is text..p
|
||||
if (range == LIMITED)
|
||||
stop = prev_line(p); // range is to prev line
|
||||
for (start = p - len; start >= stop; start--) {
|
||||
@@ -2503,12 +2492,12 @@ static int file_insert(const char *fn, char *p, int update_ro_status)
|
||||
|
||||
/* Validate file */
|
||||
if (stat(fn, &statbuf) < 0) {
|
||||
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
||||
status_line_bold_errno(fn);
|
||||
goto fi0;
|
||||
}
|
||||
if (!S_ISREG(statbuf.st_mode)) {
|
||||
// This is not a regular file
|
||||
status_line_bold("\"%s\" Not a regular file", fn);
|
||||
status_line_bold("'%s' is not a regular file", fn);
|
||||
goto fi0;
|
||||
}
|
||||
if (p < text || p > end) {
|
||||
@@ -2519,19 +2508,19 @@ static int file_insert(const char *fn, char *p, int update_ro_status)
|
||||
// read file to buffer
|
||||
fd = open(fn, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
||||
status_line_bold_errno(fn);
|
||||
goto fi0;
|
||||
}
|
||||
size = statbuf.st_size;
|
||||
size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX);
|
||||
p += text_hole_make(p, size);
|
||||
cnt = safe_read(fd, p, size);
|
||||
if (cnt < 0) {
|
||||
status_line_bold("\"%s\" %s", fn, strerror(errno));
|
||||
status_line_bold_errno(fn);
|
||||
p = text_hole_delete(p, p + size - 1); // un-do buffer insert
|
||||
} else if (cnt < size) {
|
||||
// There was a partial read, shrink unused space text[]
|
||||
p = text_hole_delete(p + cnt, p + (size - cnt) - 1); // un-do buffer insert
|
||||
status_line_bold("can't read all of file \"%s\"", fn);
|
||||
p = text_hole_delete(p + cnt, p + size - 1); // un-do buffer insert
|
||||
status_line_bold("can't read '%s'", fn);
|
||||
}
|
||||
if (cnt >= size)
|
||||
file_modified++;
|
||||
@@ -2717,6 +2706,11 @@ static void status_line_bold(const char *format, ...)
|
||||
have_status_msg = 1 + sizeof(ESC_BOLD_TEXT) + sizeof(ESC_NORM_TEXT) - 2;
|
||||
}
|
||||
|
||||
static void status_line_bold_errno(const char *fn)
|
||||
{
|
||||
status_line_bold("'%s' %s", fn, strerror(errno));
|
||||
}
|
||||
|
||||
// format status buffer
|
||||
static void status_line(const char *format, ...)
|
||||
{
|
||||
@@ -3469,7 +3463,7 @@ static void do_cmd(int c)
|
||||
} else {
|
||||
file_modified = 0;
|
||||
last_file_modified = -1;
|
||||
status_line("\"%s\" %dL, %dC", current_filename, count_lines(text, end - 1), cnt);
|
||||
status_line("'%s' %dL, %dC", current_filename, count_lines(text, end - 1), cnt);
|
||||
if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n'
|
||||
|| p[0] == 'X' || p[1] == 'Q' || p[1] == 'N'
|
||||
) {
|
||||
@@ -3667,7 +3661,7 @@ static void do_cmd(int c)
|
||||
}
|
||||
if (file_modified) {
|
||||
if (ENABLE_FEATURE_VI_READONLY && readonly_mode) {
|
||||
status_line_bold("\"%s\" File is read only", current_filename);
|
||||
status_line_bold("'%s' is read only", current_filename);
|
||||
break;
|
||||
}
|
||||
cnt = file_write(current_filename, text, end - 1);
|
||||
|
||||
+1
-7
@@ -15,10 +15,7 @@
|
||||
# the specified process to run on. The contents of this field are
|
||||
# appended to "/dev/" and used as-is. There is no need for this field to
|
||||
# be unique, although if it isn't you may have strange results. If this
|
||||
# field is left blank, it is completely ignored. Also note that if
|
||||
# BusyBox detects that a serial console is in use, then all entries
|
||||
# containing non-empty id fields will be ignored. BusyBox init does
|
||||
# nothing with utmp. We don't need no stinkin' utmp.
|
||||
# field is left blank, then the init's stdin/out will be used.
|
||||
#
|
||||
# <runlevels>: The runlevels field is completely ignored.
|
||||
#
|
||||
@@ -43,9 +40,6 @@
|
||||
# ::shutdown:/sbin/swapoff -a
|
||||
# ::shutdown:/bin/umount -a -r
|
||||
# ::restart:/sbin/init
|
||||
#
|
||||
# if it detects that /dev/console is _not_ a serial console, it will
|
||||
# also run:
|
||||
# tty2::askfirst:/bin/sh
|
||||
# tty3::askfirst:/bin/sh
|
||||
# tty4::askfirst:/bin/sh
|
||||
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Seconds to try to reread partition table
|
||||
cnt=60
|
||||
|
||||
exec </dev/null
|
||||
exec >"/tmp/${0##*/}.$$.out"
|
||||
exec 2>&1
|
||||
|
||||
(
|
||||
echo "Running: $0"
|
||||
echo "Env:"
|
||||
env | sort
|
||||
|
||||
while sleep 1; test $cnt != 0; do
|
||||
echo "Trying to reread partition table on $DEVNAME ($cnt)"
|
||||
: $((cnt--))
|
||||
# If device node doesn't exist, it means the device was removed.
|
||||
# Stop trying.
|
||||
test -e "$DEVNAME" || { echo "$DEVNAME doesn't exist, aborting"; exit 1; }
|
||||
#echo "$DEVNAME exists"
|
||||
if blockdev --rereadpt "$DEVNAME"; then
|
||||
echo "blockdev --rereadpt succeeded"
|
||||
exit 0
|
||||
fi
|
||||
echo "blockdev --rereadpt failed, exit code: $?"
|
||||
done
|
||||
echo "Timed out"
|
||||
) &
|
||||
+34
-3
@@ -7,9 +7,9 @@
|
||||
# instead of the default 0:0 660.
|
||||
#
|
||||
# Syntax:
|
||||
# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
||||
# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
||||
# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
||||
# [-][ENVVAR=regex;]...devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
||||
# [-][ENVVAR=regex;]...@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
||||
# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
||||
#
|
||||
# [-]: do not stop on this match, continue reading mdev.conf
|
||||
# =: move, >: move and create a symlink
|
||||
@@ -53,6 +53,7 @@ sr[0-9]* root:cdrom 660 @ln -sf $MDEV cdrom
|
||||
fd[0-9]* root:floppy 660
|
||||
|
||||
# net devices
|
||||
SUBSYSTEM=net;.* root:root 600 @nameif
|
||||
tun[0-9]* root:root 600 =net/
|
||||
tap[0-9]* root:root 600 =net/
|
||||
|
||||
@@ -111,3 +112,33 @@ usbdev[0-9].[0-9]_.* root:root 660
|
||||
# zaptel devices
|
||||
zap(.*) root:dialout 660 =zap/%1
|
||||
dahdi!(.*) root:dialout 660 =dahdi/%1
|
||||
|
||||
# HTC Android
|
||||
# Attaching it via USB cable causes a flurry of activity:
|
||||
#
|
||||
# mdev[1271]: 48.639459 ACTION:add SUBSYSTEM:usb DEVNAME:bus/usb/001/009 DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5
|
||||
# mdev[1271]: mknod bus/usb/001/009 (189,8) 20660 0:0
|
||||
# mdev[1272]: 48.642354 ACTION:add SUBSYSTEM:usb DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0
|
||||
# mdev[1272]: running: modprobe "$MODALIAS"
|
||||
# mdev[1273]: 48.650078 ACTION:add SUBSYSTEM:scsi DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11
|
||||
# mdev[1274]: 48.651297 ACTION:add SUBSYSTEM:scsi_host DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11/scsi_host/host11
|
||||
# mdev[1275]: 49.649422 ACTION:add SUBSYSTEM:scsi DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11/target11:0:0
|
||||
# mdev[1276]: 49.650703 ACTION:add SUBSYSTEM:scsi DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11/target11:0:0/11:0:0:0
|
||||
# mdev[1276]: running: modprobe "$MODALIAS"
|
||||
# modprobe: module scsi:t-0x00 not found in modules.dep
|
||||
# mdev[1277]: 49.658002 ACTION:add SUBSYSTEM:scsi_disk DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11/target11:0:0/11:0:0:0/scsi_disk/11:0:0:0
|
||||
# mdev[1278]: 49.659244 ACTION:add SUBSYSTEM:scsi_device DEVNAME:(null) DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11/target11:0:0/11:0:0:0/scsi_device/11:0:0:
|
||||
# mdev[1279]: 49.660535 ACTION:add SUBSYSTEM:bsg DEVNAME:bsg/11:0:0:0 DEVPATH:/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host11/target11:0:0/11:0:0:0/bsg/11:0:0:0
|
||||
# mdev[1279]: mknod bsg/11:0:0:0 (253,1) 20660 0:0
|
||||
# mdev[1280]: 49.663516 ACTION:add SUBSYSTEM:bdi DEVNAME:(null) DEVPATH:/devices/virtual/bdi/8:16
|
||||
# mdev[1281]: 49.664748 ACTION:add SUBSYSTEM:block DEVNAME:sdb DEVPATH:/block/sdb
|
||||
# mdev[1281]: mknod sdb (8,16) 60660 0:0
|
||||
# mdev[1282]: 49.677597 ACTION:change SUBSYSTEM:block DEVNAME:sdb DEVPATH:/block/sdb
|
||||
# mdev[1283]: 50.692936 ACTION:change SUBSYSTEM:block DEVNAME:sdb DEVPATH:/block/sdb
|
||||
#
|
||||
# We are hooking to the last events. To avoid having two scripts running,
|
||||
# we check for DISK_MEDIA_CHANGE=1 (prev to last event has it,
|
||||
# and it's the _only_ difference in env for these two events as of kernel 3.7.7)
|
||||
# Unfortunately, there is no event for "user pressed [Turn USB storage] btn"!
|
||||
# Script merely backgrounds and tries to rescan partition table for 1 minute:
|
||||
ACTION=change;SUBSYSTEM=block;DISK_MEDIA_CHANGE=1;.* 0:0 660 */etc/mdev.conf.change_blockdev.sh
|
||||
@@ -29,18 +29,23 @@ case "$1" in
|
||||
metric=0
|
||||
for i in $router ; do
|
||||
echo "Adding router $i"
|
||||
route add default gw $i dev $interface metric $((metric++))
|
||||
route add default gw $i dev $interface metric $metric
|
||||
: $(( metric += 1 ))
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Recreating $RESOLV_CONF"
|
||||
echo -n > $RESOLV_CONF-$$
|
||||
[ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$
|
||||
# If the file is a symlink somewhere (like /etc/resolv.conf
|
||||
# pointing to /run/resolv.conf), make sure things work.
|
||||
realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
|
||||
tmpfile="$realconf-$$"
|
||||
> "$tmpfile"
|
||||
[ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
|
||||
for i in $dns ; do
|
||||
echo " Adding DNS server $i"
|
||||
echo "nameserver $i" >> $RESOLV_CONF-$$
|
||||
echo "nameserver $i" >> "$tmpfile"
|
||||
done
|
||||
mv $RESOLV_CONF-$$ $RESOLV_CONF
|
||||
mv "$tmpfile" "$realconf"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
+78
-11
@@ -231,12 +231,13 @@
|
||||
//kbuild:lib-$(CONFIG_FIND) += find.o
|
||||
|
||||
//usage:#define find_trivial_usage
|
||||
//usage: "[PATH]... [OPTIONS] [ACTIONS]"
|
||||
//usage: "[-HL] [PATH]... [OPTIONS] [ACTIONS]"
|
||||
//usage:#define find_full_usage "\n\n"
|
||||
//usage: "Search for files and perform actions on them.\n"
|
||||
//usage: "First failed action stops processing of current file.\n"
|
||||
//usage: "Defaults: PATH is current directory, action is '-print'\n"
|
||||
//usage: "\n -follow Follow symlinks"
|
||||
//usage: "\n -L,-follow Follow symlinks"
|
||||
//usage: "\n -H ...on command line only"
|
||||
//usage: IF_FEATURE_FIND_XDEV(
|
||||
//usage: "\n -xdev Don't descend directories on other filesystems"
|
||||
//usage: )
|
||||
@@ -814,6 +815,31 @@ static const char* plus_minus_num(const char* str)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Say no to GCCism */
|
||||
#define USE_NESTED_FUNCTION 0
|
||||
|
||||
#if !USE_NESTED_FUNCTION
|
||||
struct pp_locals {
|
||||
action*** appp;
|
||||
unsigned cur_group;
|
||||
unsigned cur_action;
|
||||
IF_FEATURE_FIND_NOT( bool invert_flag; )
|
||||
};
|
||||
static action* alloc_action(struct pp_locals *ppl, int sizeof_struct, action_fp f)
|
||||
{
|
||||
action *ap = xzalloc(sizeof_struct);
|
||||
action **app;
|
||||
action ***group = &ppl->appp[ppl->cur_group];
|
||||
*group = app = xrealloc(*group, (ppl->cur_action+2) * sizeof(ppl->appp[0][0]));
|
||||
app[ppl->cur_action++] = ap;
|
||||
app[ppl->cur_action] = NULL;
|
||||
ap->f = f;
|
||||
IF_FEATURE_FIND_NOT( ap->invert = ppl->invert_flag; )
|
||||
IF_FEATURE_FIND_NOT( ppl->invert_flag = 0; )
|
||||
return ap;
|
||||
}
|
||||
#endif
|
||||
|
||||
static action*** parse_params(char **argv)
|
||||
{
|
||||
enum {
|
||||
@@ -900,10 +926,18 @@ static action*** parse_params(char **argv)
|
||||
IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0")
|
||||
;
|
||||
|
||||
#if !USE_NESTED_FUNCTION
|
||||
struct pp_locals ppl;
|
||||
#define appp (ppl.appp )
|
||||
#define cur_group (ppl.cur_group )
|
||||
#define cur_action (ppl.cur_action )
|
||||
#define invert_flag (ppl.invert_flag)
|
||||
#define ALLOC_ACTION(name) (action_##name*)alloc_action(&ppl, sizeof(action_##name), (action_fp) func_##name)
|
||||
#else
|
||||
action*** appp;
|
||||
unsigned cur_group = 0;
|
||||
unsigned cur_action = 0;
|
||||
IF_FEATURE_FIND_NOT( bool invert_flag = 0; )
|
||||
unsigned cur_group;
|
||||
unsigned cur_action;
|
||||
IF_FEATURE_FIND_NOT( bool invert_flag; )
|
||||
|
||||
/* This is the only place in busybox where we use nested function.
|
||||
* So far more standard alternatives were bigger. */
|
||||
@@ -912,7 +946,7 @@ static action*** parse_params(char **argv)
|
||||
action* alloc_action(int sizeof_struct, action_fp f)
|
||||
{
|
||||
action *ap;
|
||||
appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp));
|
||||
appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(appp[0][0]));
|
||||
appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct);
|
||||
appp[cur_group][cur_action] = NULL;
|
||||
ap->f = f;
|
||||
@@ -920,9 +954,12 @@ static action*** parse_params(char **argv)
|
||||
IF_FEATURE_FIND_NOT( invert_flag = 0; )
|
||||
return ap;
|
||||
}
|
||||
|
||||
#define ALLOC_ACTION(name) (action_##name*)alloc_action(sizeof(action_##name), (action_fp) func_##name)
|
||||
#endif
|
||||
|
||||
cur_group = 0;
|
||||
cur_action = 0;
|
||||
IF_FEATURE_FIND_NOT( invert_flag = 0; )
|
||||
appp = xzalloc(2 * sizeof(appp[0])); /* appp[0],[1] == NULL */
|
||||
|
||||
while (*argv) {
|
||||
@@ -948,8 +985,8 @@ static action*** parse_params(char **argv)
|
||||
*/
|
||||
/* Options */
|
||||
if (parm == OPT_FOLLOW) {
|
||||
dbg("follow enabled: %d", __LINE__);
|
||||
G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
|
||||
dbg("follow enabled: %d", __LINE__);
|
||||
G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
|
||||
}
|
||||
#if ENABLE_FEATURE_FIND_XDEV
|
||||
else if (parm == OPT_XDEV) {
|
||||
@@ -987,7 +1024,7 @@ static action*** parse_params(char **argv)
|
||||
dbg("%d", __LINE__);
|
||||
/* start new OR group */
|
||||
cur_group++;
|
||||
appp = xrealloc(appp, (cur_group+2) * sizeof(*appp));
|
||||
appp = xrealloc(appp, (cur_group+2) * sizeof(appp[0]));
|
||||
/*appp[cur_group] = NULL; - already NULL */
|
||||
appp[cur_group+1] = NULL;
|
||||
cur_action = 0;
|
||||
@@ -1245,16 +1282,46 @@ static action*** parse_params(char **argv)
|
||||
dbg("exiting %s", __func__);
|
||||
return appp;
|
||||
#undef ALLOC_ACTION
|
||||
#undef appp
|
||||
#undef cur_action
|
||||
#undef invert_flag
|
||||
}
|
||||
|
||||
int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int find_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int i, firstopt, status = EXIT_SUCCESS;
|
||||
char **past_HLP, *saved;
|
||||
|
||||
INIT_G();
|
||||
|
||||
argv++;
|
||||
/* "find -type f" + getopt("+HLP") => disaster.
|
||||
* Need to avoid getopt running into a non-HLP option.
|
||||
* Do this by temporarily storing NULL there:
|
||||
*/
|
||||
past_HLP = argv;
|
||||
for (;;) {
|
||||
saved = *++past_HLP;
|
||||
if (!saved)
|
||||
break;
|
||||
if (saved[0] != '-')
|
||||
break;
|
||||
if (!saved[1])
|
||||
break; /* it is "-" */
|
||||
if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
|
||||
break;
|
||||
}
|
||||
*past_HLP = NULL;
|
||||
/* "+": stop on first non-option */
|
||||
i = getopt32(argv, "+HLP");
|
||||
if (i & (1<<0))
|
||||
G.recurse_flags |= ACTION_FOLLOWLINKS_L0 | ACTION_DANGLING_OK;
|
||||
if (i & (1<<1))
|
||||
G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
|
||||
/* -P is default and is ignored */
|
||||
argv = past_HLP; /* same result as "argv += optind;" */
|
||||
*past_HLP = saved;
|
||||
|
||||
for (firstopt = 0; argv[firstopt]; firstopt++) {
|
||||
if (argv[firstopt][0] == '-')
|
||||
break;
|
||||
|
||||
+38
-10
@@ -373,6 +373,11 @@ static int grep_file(FILE *file)
|
||||
opt_f_not_found: ;
|
||||
}
|
||||
} else {
|
||||
#if ENABLE_EXTRA_COMPAT
|
||||
unsigned start_pos;
|
||||
#endif
|
||||
char *match_at;
|
||||
|
||||
if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
|
||||
gl->flg_mem_alocated_compiled |= COMPILED;
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
@@ -387,33 +392,56 @@ static int grep_file(FILE *file)
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
gl->matched_range.rm_so = 0;
|
||||
gl->matched_range.rm_eo = 0;
|
||||
#else
|
||||
start_pos = 0;
|
||||
#endif
|
||||
match_at = line;
|
||||
opt_w_again:
|
||||
//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
|
||||
if (
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
regexec(&gl->compiled_regex, line, 1, &gl->matched_range, 0) == 0
|
||||
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
|
||||
#else
|
||||
re_search(&gl->compiled_regex, line, line_len,
|
||||
/*start:*/ 0, /*range:*/ line_len,
|
||||
re_search(&gl->compiled_regex, match_at, line_len,
|
||||
start_pos, /*range:*/ line_len,
|
||||
&gl->matched_range) >= 0
|
||||
#endif
|
||||
) {
|
||||
if (option_mask32 & OPT_x) {
|
||||
found = (gl->matched_range.rm_so == 0
|
||||
&& line[gl->matched_range.rm_eo] == '\0');
|
||||
&& match_at[gl->matched_range.rm_eo] == '\0');
|
||||
} else
|
||||
if (!(option_mask32 & OPT_w)) {
|
||||
found = 1;
|
||||
} else {
|
||||
char c = ' ';
|
||||
if (gl->matched_range.rm_so)
|
||||
c = line[gl->matched_range.rm_so - 1];
|
||||
c = match_at[gl->matched_range.rm_so - 1];
|
||||
if (!isalnum(c) && c != '_') {
|
||||
c = line[gl->matched_range.rm_eo];
|
||||
if (!c || (!isalnum(c) && c != '_'))
|
||||
c = match_at[gl->matched_range.rm_eo];
|
||||
if (!c || (!isalnum(c) && c != '_')) {
|
||||
found = 1;
|
||||
} else {
|
||||
/*
|
||||
* Why check gl->matched_range.rm_eo?
|
||||
* Zero-length match makes -w skip the line:
|
||||
* "echo foo | grep ^" prints "foo",
|
||||
* "echo foo | grep -w ^" prints nothing.
|
||||
* Without such check, we can loop forever.
|
||||
*/
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
if (gl->matched_range.rm_eo != 0) {
|
||||
match_at += gl->matched_range.rm_eo;
|
||||
goto opt_w_again;
|
||||
}
|
||||
#else
|
||||
if (gl->matched_range.rm_eo > start_pos) {
|
||||
start_pos = gl->matched_range.rm_eo;
|
||||
goto opt_w_again;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
//BUG: "echo foop foo | grep -w foo" should match, but doesn't:
|
||||
//we bail out on first "mismatch" because it's not a word.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -710,7 +738,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_F;
|
||||
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
if (!(option_mask32 & (OPT_o | OPT_w)))
|
||||
if (!(option_mask32 & (OPT_o | OPT_w | OPT_x)))
|
||||
reflags = REG_NOSUB;
|
||||
#endif
|
||||
|
||||
|
||||
+9
-32
@@ -52,6 +52,12 @@ s - suid type:
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) LINK l name
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) LINK l name
|
||||
|
||||
#elif defined(MAKE_SUID)
|
||||
# define APPLET(name,l,s) SUID s l name
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) SUID s l name
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) SUID s l name
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) SUID s l name
|
||||
|
||||
#else
|
||||
static struct bb_applet applets[] = { /* name, main, location, need_suid */
|
||||
# define APPLET(name,l,s) { #name, #name, l, s },
|
||||
@@ -73,16 +79,13 @@ IF_ACPID(APPLET(acpid, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_AWK(APPLET_NOEXEC(awk, awk, BB_DIR_USR_BIN, BB_SUID_DROP, awk))
|
||||
IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename))
|
||||
IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_BEEP(APPLET(beep, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_BLKID(APPLET(blkid, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_BRCTL(APPLET(brctl, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CAL(APPLET(cal, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat))
|
||||
IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP))
|
||||
@@ -99,10 +102,8 @@ IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
|
||||
IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CMP(APPLET(cmp, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
|
||||
IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_CROND(APPLET(crond, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
/* Needs to be run by root or be suid root - needs to change /var/spool/cron* files: */
|
||||
IF_CRONTAB(APPLET(crontab, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
|
||||
@@ -117,21 +118,17 @@ IF_DEVFSD(APPLET(devfsd, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_DEVMEM(APPLET(devmem, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_DHCPRELAY(APPLET(dhcprelay, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_DIFF(APPLET(diff, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_DIRNAME(APPLET_NOFORK(dirname, dirname, BB_DIR_USR_BIN, BB_SUID_DROP, dirname))
|
||||
IF_DMESG(APPLET(dmesg, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_DNSD(APPLET(dnsd, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_HOSTNAME(APPLET_ODDNAME(dnsdomainname, hostname, BB_DIR_BIN, BB_SUID_DROP, dnsdomainname))
|
||||
IF_DOS2UNIX(APPLET_NOEXEC(dos2unix, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, dos2unix))
|
||||
IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
|
||||
IF_DU(APPLET(du, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_DUMPKMAP(APPLET(dumpkmap, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_DUMPLEASES(APPLET(dumpleases, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//IF_E2FSCK(APPLET(e2fsck, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//IF_E2LABEL(APPLET_ODDNAME(e2label, tune2fs, BB_DIR_SBIN, BB_SUID_DROP, e2label))
|
||||
IF_ECHO(APPLET_NOFORK(echo, echo, BB_DIR_BIN, BB_SUID_DROP, echo))
|
||||
IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_EJECT(APPLET(eject, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
|
||||
IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir))
|
||||
@@ -170,8 +167,6 @@ IF_GETENFORCE(APPLET(getenforce, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_GETOPT(APPLET(getopt, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_HD(APPLET_NOEXEC(hd, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hd))
|
||||
IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head))
|
||||
@@ -230,13 +225,9 @@ IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls))
|
||||
IF_LSATTR(APPLET(lsattr, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_LSPCI(APPLET(lspci, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_LSUSB(APPLET(lsusb, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
|
||||
IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
|
||||
IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
|
||||
IF_MAKEDEVS(APPLET(makedevs, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_MAKEMIME(APPLET(makemime, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_MAN(APPLET(man, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_MATCHPATHCON(APPLET(matchpathcon, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_MD5SUM(APPLET_NOEXEC(md5sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, md5sum))
|
||||
IF_MICROCOM(APPLET(microcom, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
@@ -297,12 +288,9 @@ IF_RENICE(APPLET(renice, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, BB_DIR_SBIN, BB_SUID_DROP, restorecon))
|
||||
IF_RFKILL(APPLET(rfkill, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
|
||||
IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir))
|
||||
IF_ROUTE(APPLET(route, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts))
|
||||
IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
@@ -312,7 +300,6 @@ IF_RUNSVDIR(APPLET(runsvdir, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_RX(APPLET(rx, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_SCRIPT(APPLET(script, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_SED(APPLET(sed, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_SELINUXENABLED(APPLET(selinuxenabled, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_SENDMAIL(APPLET(sendmail, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
|
||||
@@ -356,7 +343,6 @@ IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac))
|
||||
IF_TAIL(APPLET(tail, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
/* IF_TC(APPLET(tc, BB_DIR_SBIN, BB_SUID_DROP)) */
|
||||
IF_TCPSVD(APPLET_ODDNAME(tcpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, tcpsvd))
|
||||
@@ -385,14 +371,9 @@ IF_UDHCPD(APPLET(udhcpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
IF_UDPSVD(APPLET_ODDNAME(udpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, udpsvd))
|
||||
IF_UMOUNT(APPLET(umount, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_UNEXPAND(APPLET_ODDNAME(unexpand, expand, BB_DIR_USR_BIN, BB_SUID_DROP, unexpand))
|
||||
IF_UNIQ(APPLET(uniq, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_UNIX2DOS(APPLET_NOEXEC(unix2dos, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, unix2dos))
|
||||
IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
|
||||
IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_UPTIME(APPLET(uptime, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep))
|
||||
IF_UUDECODE(APPLET(uudecode, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
@@ -401,21 +382,17 @@ IF_VCONFIG(APPLET(vconfig, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
/* Needs to be run by root or be suid root - needs to change uid and gid: */
|
||||
IF_VLOCK(APPLET(vlock, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
|
||||
IF_VOLNAME(APPLET(volname, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
/* Needs to be run by root or be suid root - needs to write to /dev/TTY: */
|
||||
IF_WALL(APPLET(wall, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
|
||||
IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP))
|
||||
IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_WGET(APPLET(wget, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami))
|
||||
IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
|
||||
IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
|
||||
IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
|
||||
IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
|
||||
IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
|
||||
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE)
|
||||
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE) \
|
||||
&& !defined(MAKE_LINKS) && !defined(MAKE_SUID)
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -122,6 +122,9 @@ typedef struct archive_handle_t {
|
||||
#define ARCHIVE_NUMERIC_OWNER (1 << 7)
|
||||
#define ARCHIVE_O_TRUNC (1 << 8)
|
||||
#define ARCHIVE_REMEMBER_NAMES (1 << 9)
|
||||
#if ENABLE_RPM
|
||||
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 10)
|
||||
#endif
|
||||
|
||||
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
|
||||
@@ -442,7 +442,7 @@ struct ext2_super_block {
|
||||
uint32_t s_reserved[162]; /* Padding to the end of the block */
|
||||
};
|
||||
struct BUG_ext2_super_block {
|
||||
char bug[sizeof(struct ext2_super_block) == 1024 ? 1 : -1];
|
||||
char bug[sizeof(struct ext2_super_block) == 1024 ? 1 : -1];
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
+40
-19
@@ -32,12 +32,12 @@
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
/* There are two incompatible basename's, let not use them! */
|
||||
/* There are two incompatible basename's, let's not use them! */
|
||||
/* See the dirname/basename man page for details */
|
||||
#include <libgen.h> /* dirname,basename */
|
||||
#undef basename
|
||||
#define basename dont_use_basename
|
||||
#include <sys/poll.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -386,6 +386,7 @@ char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
|
||||
const char *bb_basename(const char *name) FAST_FUNC;
|
||||
/* NB: can violate const-ness (similarly to strchr) */
|
||||
char *last_char_is(const char *s, int c) FAST_FUNC;
|
||||
const char* endofname(const char *name) FAST_FUNC;
|
||||
|
||||
void ndelay_on(int fd) FAST_FUNC;
|
||||
void ndelay_off(int fd) FAST_FUNC;
|
||||
@@ -460,6 +461,8 @@ void record_signo(int signo); /* not FAST_FUNC! */
|
||||
|
||||
void xsetgid(gid_t gid) FAST_FUNC;
|
||||
void xsetuid(uid_t uid) FAST_FUNC;
|
||||
void xsetegid(gid_t egid) FAST_FUNC;
|
||||
void xseteuid(uid_t euid) FAST_FUNC;
|
||||
void xchdir(const char *path) FAST_FUNC;
|
||||
void xchroot(const char *path) FAST_FUNC;
|
||||
void xsetenv(const char *key, const char *value) FAST_FUNC;
|
||||
@@ -468,11 +471,12 @@ void bb_unsetenv_and_free(char *key) FAST_FUNC;
|
||||
void xunlink(const char *pathname) FAST_FUNC;
|
||||
void xstat(const char *pathname, struct stat *buf) FAST_FUNC;
|
||||
void xfstat(int fd, struct stat *buf, const char *errmsg) FAST_FUNC;
|
||||
int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC;
|
||||
int open_or_warn(const char *pathname, int flags) FAST_FUNC;
|
||||
int xopen3(const char *pathname, int flags, int mode) FAST_FUNC;
|
||||
int xopen(const char *pathname, int flags) FAST_FUNC;
|
||||
int xopen_nonblocking(const char *pathname) FAST_FUNC;
|
||||
int xopen3(const char *pathname, int flags, int mode) FAST_FUNC;
|
||||
int open_or_warn(const char *pathname, int flags) FAST_FUNC;
|
||||
int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC;
|
||||
int xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) FAST_FUNC;
|
||||
int open_or_warn_stdin(const char *pathname) FAST_FUNC;
|
||||
int xopen_stdin(const char *pathname) FAST_FUNC;
|
||||
void xrename(const char *oldpath, const char *newpath) FAST_FUNC;
|
||||
@@ -482,9 +486,9 @@ int xmkstemp(char *template) FAST_FUNC;
|
||||
off_t fdlength(int fd) FAST_FUNC;
|
||||
|
||||
uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
|
||||
const char *override,
|
||||
unsigned override_units,
|
||||
int extend);
|
||||
const char *override,
|
||||
unsigned override_units,
|
||||
int extend);
|
||||
|
||||
void xpipe(int filedes[2]) FAST_FUNC;
|
||||
/* In this form code with pipes is much more readable */
|
||||
@@ -522,7 +526,8 @@ struct BUG_too_small {
|
||||
|
||||
void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC;
|
||||
time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC;
|
||||
|
||||
char *strftime_HHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
|
||||
char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
|
||||
|
||||
int xsocket(int domain, int type, int protocol) FAST_FUNC;
|
||||
void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
|
||||
@@ -676,6 +681,13 @@ const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str);
|
||||
* else it is printed as-is (except for ch = 0x9b) */
|
||||
enum { PRINTABLE_META = 0x100 };
|
||||
void fputc_printable(int ch, FILE *file) FAST_FUNC;
|
||||
/* Return a string that is the printable representation of character ch.
|
||||
* Buffer must hold at least four characters. */
|
||||
enum {
|
||||
VISIBLE_ENDLINE = 1 << 0,
|
||||
VISIBLE_SHOW_TABS = 1 << 1,
|
||||
};
|
||||
void visible(unsigned ch, char *buf, int flags) FAST_FUNC;
|
||||
|
||||
/* dmalloc will redefine these to it's own implementation. It is safe
|
||||
* to have the prototypes here unconditionally. */
|
||||
@@ -806,8 +818,8 @@ char *itoa(int n) FAST_FUNC;
|
||||
char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC;
|
||||
char *itoa_to_buf(int n, char *buf, unsigned buflen) FAST_FUNC;
|
||||
/* Intelligent formatters of bignums */
|
||||
void smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC;
|
||||
void smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC;
|
||||
char *smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC;
|
||||
char *smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC;
|
||||
/* If block_size == 0, display size without fractional part,
|
||||
* else display (size * block_size) with one decimal digit.
|
||||
* If display_unit == 0, show value no bigger than 1024 with suffix (K,M,G...),
|
||||
@@ -830,6 +842,9 @@ struct suffix_mult {
|
||||
char suffix[4];
|
||||
unsigned mult;
|
||||
};
|
||||
extern const struct suffix_mult bkm_suffixes[];
|
||||
#define km_suffixes (bkm_suffixes + 1)
|
||||
|
||||
#include "xatonum.h"
|
||||
/* Specialized: */
|
||||
|
||||
@@ -1107,9 +1122,6 @@ void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC;
|
||||
|
||||
|
||||
/* Networking */
|
||||
int create_icmp_socket(void) FAST_FUNC;
|
||||
int create_icmp6_socket(void) FAST_FUNC;
|
||||
/* interface.c */
|
||||
/* This structure defines protocol families and their handlers. */
|
||||
struct aftype {
|
||||
const char *name;
|
||||
@@ -1138,6 +1150,7 @@ struct hwtype {
|
||||
};
|
||||
extern smallint interface_opt_a;
|
||||
int display_interfaces(char *ifname) FAST_FUNC;
|
||||
int in_ether(const char *bufp, struct sockaddr *sap) FAST_FUNC;
|
||||
#if ENABLE_FEATURE_HWIB
|
||||
int in_ib(const char *bufp, struct sockaddr *sap) FAST_FUNC;
|
||||
#else
|
||||
@@ -1287,8 +1300,10 @@ int sd_listen_fds(void);
|
||||
#define SETUP_ENV_CLEARENV (1 << 1)
|
||||
#define SETUP_ENV_TO_TMP (1 << 2)
|
||||
#define SETUP_ENV_NO_CHDIR (1 << 4)
|
||||
extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
|
||||
extern int correct_password(const struct passwd *pw) FAST_FUNC;
|
||||
void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
|
||||
void nuke_str(char *str) FAST_FUNC;
|
||||
int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
|
||||
int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
|
||||
/* Returns a malloced string */
|
||||
#if !ENABLE_USE_BB_CRYPT
|
||||
#define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt)
|
||||
@@ -1434,7 +1449,7 @@ void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC;
|
||||
/* It's NOT just ENABLEd or disabled. It's a number: */
|
||||
# if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0
|
||||
# define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0)
|
||||
unsigned size_from_HISTFILESIZE(const char *hp);
|
||||
unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC;
|
||||
# else
|
||||
# define MAX_HISTORY 0
|
||||
# endif
|
||||
@@ -1476,6 +1491,7 @@ line_input_t *new_line_input_t(int flags) FAST_FUNC;
|
||||
* >0 length of input string, including terminating '\n'
|
||||
*/
|
||||
int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC;
|
||||
void show_history(const line_input_t *st) FAST_FUNC;
|
||||
# if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
|
||||
void save_history(line_input_t *st);
|
||||
# endif
|
||||
@@ -1759,6 +1775,11 @@ extern struct globals *const ptr_to_globals;
|
||||
(*(struct globals**)&ptr_to_globals) = (void*)(x); \
|
||||
barrier(); \
|
||||
} while (0)
|
||||
#define FREE_PTR_TO_GLOBALS() do { \
|
||||
if (ENABLE_FEATURE_CLEAN_UP) { \
|
||||
free(ptr_to_globals); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
|
||||
* use bb_default_login_shell and following defines.
|
||||
@@ -1800,7 +1821,7 @@ extern const char bb_default_login_shell[] ALIGN1;
|
||||
# define VC_4 "/dev/vc/4"
|
||||
# define VC_5 "/dev/vc/5"
|
||||
# define VC_FORMAT "/dev/vc/%d"
|
||||
# define LOOP_FORMAT "/dev/loop/%d"
|
||||
# define LOOP_FORMAT "/dev/loop/%u"
|
||||
# define LOOP_NAMESIZE (sizeof("/dev/loop/") + sizeof(int)*3 + 1)
|
||||
# define LOOP_NAME "/dev/loop/"
|
||||
# define FB_0 "/dev/fb/0"
|
||||
@@ -1813,7 +1834,7 @@ extern const char bb_default_login_shell[] ALIGN1;
|
||||
# define VC_4 "/dev/tty4"
|
||||
# define VC_5 "/dev/tty5"
|
||||
# define VC_FORMAT "/dev/tty%d"
|
||||
# define LOOP_FORMAT "/dev/loop%d"
|
||||
# define LOOP_FORMAT "/dev/loop%u"
|
||||
# define LOOP_NAMESIZE (sizeof("/dev/loop") + sizeof(int)*3 + 1)
|
||||
# define LOOP_NAME "/dev/loop"
|
||||
# define FB_0 "/dev/fb0"
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
/*
|
||||
static void die_at(int line)
|
||||
{
|
||||
bb_error_msg_and_die("internal error at %d", line);
|
||||
bb_error_msg_and_die("internal error at %d", line);
|
||||
}
|
||||
#define assert(v) if (!(v)) die_at(__LINE__)
|
||||
*/
|
||||
|
||||
+14
-11
@@ -208,6 +208,7 @@ typedef int bb__aliased_int FIX_ALIASING;
|
||||
typedef long bb__aliased_long FIX_ALIASING;
|
||||
typedef uint16_t bb__aliased_uint16_t FIX_ALIASING;
|
||||
typedef uint32_t bb__aliased_uint32_t FIX_ALIASING;
|
||||
typedef uint64_t bb__aliased_uint64_t FIX_ALIASING;
|
||||
|
||||
/* NB: unaligned parameter should be a pointer, aligned one -
|
||||
* a lvalue. This makes it more likely to not swap them by mistake
|
||||
@@ -228,7 +229,7 @@ typedef uint32_t bb__aliased_uint32_t FIX_ALIASING;
|
||||
# define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
|
||||
# define move_to_unaligned16(u16p, v) do { \
|
||||
uint16_t __t = (v); \
|
||||
memcpy((u16p), &__t, 4); \
|
||||
memcpy((u16p), &__t, 2); \
|
||||
} while (0)
|
||||
# define move_to_unaligned32(u32p, v) do { \
|
||||
uint32_t __t = (v); \
|
||||
@@ -263,6 +264,12 @@ typedef unsigned smalluint;
|
||||
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
|
||||
#ifdef __UCLIBC__
|
||||
# define UCLIBC_VERSION KERNEL_VERSION(__UCLIBC_MAJOR__, __UCLIBC_MINOR__, __UCLIBC_SUBLEVEL__)
|
||||
#else
|
||||
# define UCLIBC_VERSION 0
|
||||
#endif
|
||||
|
||||
|
||||
/* ---- Miscellaneous --------------------------------------- */
|
||||
|
||||
@@ -305,8 +312,9 @@ typedef unsigned smalluint;
|
||||
* for a mmu-less system.
|
||||
*/
|
||||
#if ENABLE_NOMMU || \
|
||||
(defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
|
||||
__UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__)
|
||||
(defined __UCLIBC__ && \
|
||||
UCLIBC_VERSION > KERNEL_VERSION(0, 9, 28) && \
|
||||
!defined __ARCH_USE_MMU__)
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
@@ -373,13 +381,8 @@ typedef unsigned smalluint;
|
||||
#define HAVE_NET_ETHERNET_H 1
|
||||
#define HAVE_SYS_STATFS_H 1
|
||||
|
||||
#if defined(__UCLIBC_MAJOR__)
|
||||
# if __UCLIBC_MAJOR__ == 0 \
|
||||
&& ( __UCLIBC_MINOR__ < 9 \
|
||||
|| (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 32) \
|
||||
)
|
||||
# undef HAVE_STRVERSCMP
|
||||
# endif
|
||||
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
|
||||
# undef HAVE_STRVERSCMP
|
||||
#endif
|
||||
|
||||
#if defined(__dietlibc__)
|
||||
@@ -431,7 +434,7 @@ typedef unsigned smalluint;
|
||||
# undef HAVE_UNLOCKED_LINE_OPS
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__)
|
||||
# undef HAVE_STRCHRNUL
|
||||
#endif
|
||||
|
||||
|
||||
@@ -60,6 +60,12 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !ENABLE_TAR && !ENABLE_WERROR
|
||||
# warning Note: bootchartd requires tar command, but you did not select it.
|
||||
#elif !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_WERROR
|
||||
# warning Note: bootchartd requires tar -z support, but you did not select it.
|
||||
#endif
|
||||
|
||||
#define BC_VERSION_STR "0.8"
|
||||
|
||||
/* For debugging, set to 0:
|
||||
|
||||
+61
-46
@@ -9,11 +9,6 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc))
|
||||
|
||||
//kbuild:lib-$(CONFIG_INIT) += init.o
|
||||
|
||||
//config:config INIT
|
||||
//config: bool "init"
|
||||
//config: default y
|
||||
@@ -108,6 +103,11 @@
|
||||
//config: Note that on Linux, init attempts to detect serial terminal and
|
||||
//config: sets TERM to "vt102" if one is found.
|
||||
|
||||
//applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc))
|
||||
|
||||
//kbuild:lib-$(CONFIG_INIT) += init.o
|
||||
|
||||
#define DEBUG_SEGV_HANDLER 0
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -140,12 +140,11 @@
|
||||
* not fully functional init by switching it on! */
|
||||
#define DEBUG_INIT 0
|
||||
|
||||
#define COMMAND_SIZE 256
|
||||
#define CONSOLE_NAME_SIZE 32
|
||||
|
||||
/* Default sysinit script. */
|
||||
#ifndef INIT_SCRIPT
|
||||
#define INIT_SCRIPT "/etc/init.d/rcS"
|
||||
# define INIT_SCRIPT "/etc/init.d/rcS"
|
||||
#endif
|
||||
|
||||
/* Each type of actions can appear many times. They will be
|
||||
@@ -195,7 +194,7 @@ struct init_action {
|
||||
pid_t pid;
|
||||
uint8_t action_type;
|
||||
char terminal[CONSOLE_NAME_SIZE];
|
||||
char command[COMMAND_SIZE];
|
||||
char command[1];
|
||||
};
|
||||
|
||||
static struct init_action *init_action_list = NULL;
|
||||
@@ -223,8 +222,8 @@ static void message(int where, const char *fmt, ...)
|
||||
msg[0] = '\r';
|
||||
va_start(arguments, fmt);
|
||||
l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
|
||||
if (l > sizeof(msg) - 1)
|
||||
l = sizeof(msg) - 1;
|
||||
if (l > sizeof(msg) - 2)
|
||||
l = sizeof(msg) - 2;
|
||||
va_end(arguments);
|
||||
|
||||
#if ENABLE_FEATURE_INIT_SYSLOG
|
||||
@@ -398,7 +397,7 @@ static void reset_sighandlers_and_unblock_sigs(void)
|
||||
}
|
||||
|
||||
/* Wrapper around exec:
|
||||
* Takes string (max COMMAND_SIZE chars).
|
||||
* Takes string.
|
||||
* If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'.
|
||||
* Otherwise splits words on whitespace, deals with leading dash,
|
||||
* and uses plain exec().
|
||||
@@ -406,10 +405,15 @@ static void reset_sighandlers_and_unblock_sigs(void)
|
||||
*/
|
||||
static void init_exec(const char *command)
|
||||
{
|
||||
char *cmd[COMMAND_SIZE / 2];
|
||||
char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
|
||||
int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
|
||||
/* +8 allows to write VLA sizes below more efficiently: */
|
||||
unsigned command_size = strlen(command) + 8;
|
||||
/* strlen(command) + strlen("exec ")+1: */
|
||||
char buf[command_size];
|
||||
/* strlen(command) / 2 + 4: */
|
||||
char *cmd[command_size / 2];
|
||||
int dash;
|
||||
|
||||
dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
|
||||
command += dash;
|
||||
|
||||
/* See if any special /bin/sh requiring characters are present */
|
||||
@@ -626,21 +630,21 @@ static void new_init_action(uint8_t action_type, const char *command, const char
|
||||
nextp = &a->next;
|
||||
}
|
||||
|
||||
a = xzalloc(sizeof(*a));
|
||||
a = xzalloc(sizeof(*a) + strlen(command));
|
||||
|
||||
/* Append to the end of the list */
|
||||
append:
|
||||
*nextp = a;
|
||||
a->action_type = action_type;
|
||||
safe_strncpy(a->command, command, sizeof(a->command));
|
||||
strcpy(a->command, command);
|
||||
safe_strncpy(a->terminal, cons, sizeof(a->terminal));
|
||||
dbg_message(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
|
||||
dbg_message(L_LOG | L_CONSOLE, "command='%s' action=%x tty='%s'\n",
|
||||
a->command, a->action_type, a->terminal);
|
||||
}
|
||||
|
||||
/* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
|
||||
* then parse_inittab() simply adds in some default
|
||||
* actions(i.e., runs INIT_SCRIPT and then starts a pair
|
||||
* actions (i.e., runs INIT_SCRIPT and then starts a pair
|
||||
* of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB
|
||||
* _is_ defined, but /etc/inittab is missing, this
|
||||
* results in the same set of default behaviors.
|
||||
@@ -655,23 +659,22 @@ static void parse_inittab(void)
|
||||
#endif
|
||||
{
|
||||
/* No inittab file - set up some default behavior */
|
||||
/* Reboot on Ctrl-Alt-Del */
|
||||
new_init_action(CTRLALTDEL, "reboot", "");
|
||||
/* Umount all filesystems on halt/reboot */
|
||||
new_init_action(SHUTDOWN, "umount -a -r", "");
|
||||
/* Swapoff on halt/reboot */
|
||||
if (ENABLE_SWAPONOFF)
|
||||
new_init_action(SHUTDOWN, "swapoff -a", "");
|
||||
/* Prepare to restart init when a QUIT is received */
|
||||
new_init_action(RESTART, "init", "");
|
||||
/* Sysinit */
|
||||
new_init_action(SYSINIT, INIT_SCRIPT, "");
|
||||
/* Askfirst shell on tty1-4 */
|
||||
new_init_action(ASKFIRST, bb_default_login_shell, "");
|
||||
//TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
|
||||
new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
|
||||
new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
|
||||
new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
|
||||
/* sysinit */
|
||||
new_init_action(SYSINIT, INIT_SCRIPT, "");
|
||||
/* Reboot on Ctrl-Alt-Del */
|
||||
new_init_action(CTRLALTDEL, "reboot", "");
|
||||
/* Umount all filesystems on halt/reboot */
|
||||
new_init_action(SHUTDOWN, "umount -a -r", "");
|
||||
/* Swapoff on halt/reboot */
|
||||
new_init_action(SHUTDOWN, "swapoff -a", "");
|
||||
/* Restart init when a QUIT is received */
|
||||
new_init_action(RESTART, "init", "");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -786,7 +789,7 @@ static void run_shutdown_and_kill_processes(void)
|
||||
* and only one will be remembered and acted upon.
|
||||
*/
|
||||
|
||||
/* The SIGUSR[12]/SIGTERM handler */
|
||||
/* The SIGPWR/SIGUSR[12]/SIGTERM handler */
|
||||
static void halt_reboot_pwoff(int sig) NORETURN;
|
||||
static void halt_reboot_pwoff(int sig)
|
||||
{
|
||||
@@ -931,10 +934,17 @@ static void reload_inittab(void)
|
||||
|
||||
/* Remove stale entries and SYSINIT entries.
|
||||
* We never rerun SYSINIT entries anyway,
|
||||
* removing them too saves a few bytes */
|
||||
* removing them too saves a few bytes
|
||||
*/
|
||||
nextp = &init_action_list;
|
||||
while ((a = *nextp) != NULL) {
|
||||
if ((a->action_type & ~SYSINIT) == 0) {
|
||||
/*
|
||||
* Why pid == 0 check?
|
||||
* Process can be removed from inittab and added *later*.
|
||||
* If we delete its entry but process still runs,
|
||||
* duplicate is spawned when the entry is re-added.
|
||||
*/
|
||||
if ((a->action_type & ~SYSINIT) == 0 && a->pid == 0) {
|
||||
*nextp = a->next;
|
||||
free(a);
|
||||
} else {
|
||||
@@ -1058,10 +1068,13 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* It's 2013, does anyone really still depend on this? */
|
||||
/* If you do, consider adding swapon to sysinot actions then! */
|
||||
/* struct sysinfo is linux-specific */
|
||||
#ifdef __linux__
|
||||
# ifdef __linux__
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
if (ENABLE_SWAPONOFF) {
|
||||
/*if (ENABLE_SWAPONOFF) - WRONG: we may have non-bbox swapon*/ {
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) == 0
|
||||
@@ -1075,6 +1088,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
run_actions(SYSINIT); /* wait and removing */
|
||||
}
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
@@ -1089,8 +1103,8 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
|
||||
* then parse_inittab() simply adds in some default
|
||||
* actions(i.e., INIT_SCRIPT and a pair
|
||||
* of "askfirst" shells */
|
||||
* actions (i.e., INIT_SCRIPT and a pair
|
||||
* of "askfirst" shells) */
|
||||
parse_inittab();
|
||||
}
|
||||
|
||||
@@ -1114,13 +1128,14 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
strncpy(argv[0], "init", strlen(argv[0]));
|
||||
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
|
||||
while (*++argv)
|
||||
memset(*argv, 0, strlen(*argv));
|
||||
nuke_str(*argv);
|
||||
|
||||
/* Set up signal handlers */
|
||||
if (!DEBUG_INIT) {
|
||||
struct sigaction sa;
|
||||
|
||||
bb_signals(0
|
||||
+ (1 << SIGPWR) /* halt */
|
||||
+ (1 << SIGUSR1) /* halt */
|
||||
+ (1 << SIGTERM) /* reboot */
|
||||
+ (1 << SIGUSR2) /* poweroff */
|
||||
@@ -1216,7 +1231,14 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage:#define init_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define init_full_usage "\n\n"
|
||||
//usage: "Init is the parent of all processes"
|
||||
//usage: "Init is the first process started during boot. It never exits."
|
||||
//usage: IF_FEATURE_USE_INITTAB(
|
||||
//usage: "\n""It (re)spawns children according to /etc/inittab."
|
||||
//usage: )
|
||||
//usage: IF_NOT_FEATURE_USE_INITTAB(
|
||||
//usage: "\n""This version of init doesn't use /etc/inittab,"
|
||||
//usage: "\n""has fixed set of processed to run."
|
||||
//usage: )
|
||||
//usage:
|
||||
//usage:#define init_notes_usage
|
||||
//usage: "This version of init is designed to be run only by the kernel.\n"
|
||||
@@ -1234,9 +1256,6 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: " ::shutdown:/sbin/swapoff -a\n"
|
||||
//usage: " ::shutdown:/bin/umount -a -r\n"
|
||||
//usage: " ::restart:/sbin/init\n"
|
||||
//usage: "\n"
|
||||
//usage: "if it detects that /dev/console is _not_ a serial console, it will also run:\n"
|
||||
//usage: "\n"
|
||||
//usage: " tty2::askfirst:/bin/sh\n"
|
||||
//usage: " tty3::askfirst:/bin/sh\n"
|
||||
//usage: " tty4::askfirst:/bin/sh\n"
|
||||
@@ -1252,11 +1271,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: " the specified process to run on. The contents of this field are\n"
|
||||
//usage: " appended to \"/dev/\" and used as-is. There is no need for this field to\n"
|
||||
//usage: " be unique, although if it isn't you may have strange results. If this\n"
|
||||
//usage: " field is left blank, the controlling tty is set to the console. Also\n"
|
||||
//usage: " note that if BusyBox detects that a serial console is in use, then only\n"
|
||||
//usage: " entries whose controlling tty is either the serial console or /dev/null\n"
|
||||
//usage: " will be run. BusyBox init does nothing with utmp. We don't need no\n"
|
||||
//usage: " stinkin' utmp.\n"
|
||||
//usage: " field is left blank, then the init's stdin/out will be used.\n"
|
||||
//usage: "\n"
|
||||
//usage: " <runlevels>:\n"
|
||||
//usage: "\n"
|
||||
|
||||
+1
-3
@@ -27,8 +27,6 @@ lib-y += concat_subpath_file.o
|
||||
lib-y += copy_file.o
|
||||
lib-y += copyfd.o
|
||||
lib-y += crc32.o
|
||||
lib-y += create_icmp6_socket.o
|
||||
lib-y += create_icmp_socket.o
|
||||
lib-y += default_error_retval.o
|
||||
lib-y += device_open.o
|
||||
lib-y += dump.o
|
||||
@@ -146,7 +144,7 @@ lib-$(CONFIG_DELUSER) += update_passwd.o
|
||||
lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o obscure.o
|
||||
lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o
|
||||
lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
|
||||
lib-$(CONFIG_SULOGIN) += pw_encrypt.o
|
||||
lib-$(CONFIG_SULOGIN) += pw_encrypt.o correct_password.o
|
||||
lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o
|
||||
lib-$(CONFIG_SU) += pw_encrypt.o correct_password.o
|
||||
lib-$(CONFIG_LOGIN) += pw_encrypt.o correct_password.o
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@
|
||||
#include "busybox.h"
|
||||
|
||||
#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|
||||
|| defined(__APPLE__) \
|
||||
|| defined(__APPLE__) \
|
||||
)
|
||||
# include <malloc.h> /* for mallopt */
|
||||
#endif
|
||||
@@ -750,7 +750,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
|
||||
//TODO: just compare applet_no with APPLET_NO_test
|
||||
if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) {
|
||||
/* If you want "foo --help" to return 0: */
|
||||
/*xfunc_error_retval = 0;*/
|
||||
xfunc_error_retval = 0;
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
Loaded 100 of 281 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user