Compare commits
351
Commits
1_4_stable
..
1_5_2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e7ba6979c | ||
|
|
3d90be2efe | ||
|
|
b32502da83 | ||
|
|
568d8c9a5c | ||
|
|
05732281e4 | ||
|
|
4b38e29764 | ||
|
|
58875aefe4 | ||
|
|
d0587ed966 | ||
|
|
cbcff2936e | ||
|
|
1787e22465 | ||
|
|
2a51af2579 | ||
|
|
9a1fa8cf07 | ||
|
|
7c139b4778 | ||
|
|
b8e72fdde1 | ||
|
|
afa37cf508 | ||
|
|
f9234135f8 | ||
|
|
4f93cde77f | ||
|
|
f363065021 | ||
|
|
c86e052b81 | ||
|
|
e84aeb5bcb | ||
|
|
88a2aa98e0 | ||
|
|
97fd6d81b4 | ||
|
|
6111a8f2e7 | ||
|
|
16deb86746 | ||
|
|
3d101dd467 | ||
|
|
be862096c0 | ||
|
|
54e3d1f00d | ||
|
|
f24cdf1554 | ||
|
|
dfce08f281 | ||
|
|
bd852076b9 | ||
|
|
de8a6a01d8 | ||
|
|
41e1dc3f8b | ||
|
|
4b4b619c9c | ||
|
|
1c86a29aea | ||
|
|
83bb98f759 | ||
|
|
8e1a0cc4c9 | ||
|
|
6b343ddbc8 | ||
|
|
081ef799fa | ||
|
|
7a96504d30 | ||
|
|
75acbe322c | ||
|
|
757ed50841 | ||
|
|
4b0bb9e0fd | ||
|
|
486e7ca6b7 | ||
|
|
84a9b8750e | ||
|
|
3ce293b585 | ||
|
|
4efeaee387 | ||
|
|
5e892bae51 | ||
|
|
bff32ce4d5 | ||
|
|
1cc70225e7 | ||
|
|
54d14ca1a2 | ||
|
|
24af7201e9 | ||
|
|
972288e62f | ||
|
|
dd2b2f75ae | ||
|
|
5659407595 | ||
|
|
7f2527e5a7 | ||
|
|
650a0459b8 | ||
|
|
16c7fb7fc5 | ||
|
|
e1e93c1e1c | ||
|
|
6ef06eeed4 | ||
|
|
75ab6af71e | ||
|
|
cfa2b3a209 | ||
|
|
1ce190b7c1 | ||
|
|
9616aff095 | ||
|
|
26a8016da6 | ||
|
|
fe42d17318 | ||
|
|
75605788ff | ||
|
|
07766bb0e7 | ||
|
|
da799e8227 | ||
|
|
e930fe1441 | ||
|
|
fad03bc3bb | ||
|
|
93ebd4f58d | ||
|
|
5df955fce2 | ||
|
|
c9c893d4f5 | ||
|
|
8a164052bf | ||
|
|
d55a36255d | ||
|
|
b5c33b10b9 | ||
|
|
39c651e909 | ||
|
|
b3f09f4a50 | ||
|
|
214aec46bd | ||
|
|
955bccc94f | ||
|
|
1203c9bf2f | ||
|
|
baca175912 | ||
|
|
ecea8f201e | ||
|
|
a4688bf55d | ||
|
|
be644a81e9 | ||
|
|
49622d7846 | ||
|
|
4eb8b936cb | ||
|
|
2b52b2797b | ||
|
|
3aba666514 | ||
|
|
bebbd8c9ba | ||
|
|
f25d57e0b4 | ||
|
|
71bc71a7dc | ||
|
|
339f5eb2e0 | ||
|
|
48e71c188f | ||
|
|
02f0c4c2bf | ||
|
|
f5a157615d | ||
|
|
e11b4a4705 | ||
|
|
12eda0ab97 | ||
|
|
67a32adbca | ||
|
|
a1c631278b | ||
|
|
18d6fc1a50 | ||
|
|
5c1de36702 | ||
|
|
8a91081d9d | ||
|
|
cd27c42552 | ||
|
|
6c939e0cb4 | ||
|
|
36b7e28fa0 | ||
|
|
673d4bbab6 | ||
|
|
7fb8a00341 | ||
|
|
0085f231b2 | ||
|
|
80281fefc0 | ||
|
|
ab9eef21a5 | ||
|
|
8e858e2700 | ||
|
|
41cca2b4f5 | ||
|
|
c115fdbc80 | ||
|
|
9431e564aa | ||
|
|
140644dc1c | ||
|
|
ccd412da09 | ||
|
|
1ccd96fd1f | ||
|
|
d238a477b7 | ||
|
|
ec77ba128a | ||
|
|
1c660b4bd2 | ||
|
|
3af3e5b4b0 | ||
|
|
940494f813 | ||
|
|
29e31ddd81 | ||
|
|
dcbd51dd28 | ||
|
|
19c238bc90 | ||
|
|
2110aa9ece | ||
|
|
4c7e5b6c76 | ||
|
|
5066473d41 | ||
|
|
966bb43766 | ||
|
|
b716754199 | ||
|
|
cce38586ae | ||
|
|
f8ea0f3a66 | ||
|
|
385304d449 | ||
|
|
4222ae440a | ||
|
|
018e085d44 | ||
|
|
629563b5d7 | ||
|
|
5276402f2c | ||
|
|
f98dc4db7a | ||
|
|
0dec6de38b | ||
|
|
cc5715184b | ||
|
|
2de3d9fbee | ||
|
|
a89150733a | ||
|
|
99eb8500c9 | ||
|
|
fc06f2968b | ||
|
|
5651bfc204 | ||
|
|
bc54cffc83 | ||
|
|
4d2183bee1 | ||
|
|
4fe15f3d9e | ||
|
|
a6704933dd | ||
|
|
5c67e3ed90 | ||
|
|
fe1f00a7a7 | ||
|
|
9650f36210 | ||
|
|
aa74445514 | ||
|
|
0c032a49b9 | ||
|
|
7a2ca5e111 | ||
|
|
a624c11d5e | ||
|
|
2da584fc4e | ||
|
|
b012b10dbd | ||
|
|
e5570da2cf | ||
|
|
5cedb75aa7 | ||
|
|
3bf0020a5f | ||
|
|
131ae177a7 | ||
|
|
a0f82e928a | ||
|
|
d0762e3d52 | ||
|
|
54cf511ce1 | ||
|
|
ec27feb045 | ||
|
|
c84520d73d | ||
|
|
d818dcc72a | ||
|
|
7fd00cbff7 | ||
|
|
4998c81891 | ||
|
|
9ab2658836 | ||
|
|
b30418ac19 | ||
|
|
ae30210d90 | ||
|
|
b5368bf437 | ||
|
|
e54b472ffc | ||
|
|
9a1c71a0f2 | ||
|
|
a3055846a4 | ||
|
|
6089c2c31e | ||
|
|
6ca0444420 | ||
|
|
136f42f503 | ||
|
|
ad67a3925c | ||
|
|
c8e9993514 | ||
|
|
9ca26d38c5 | ||
|
|
d244c5eaf8 | ||
|
|
b477e18c1e | ||
|
|
0aa6ba5d44 | ||
|
|
4423e5beef | ||
|
|
c5d9e8ff3d | ||
|
|
0850cdabde | ||
|
|
8c6c6e955b | ||
|
|
710694f0e5 | ||
|
|
d4eda22d0c | ||
|
|
d46d3c292e | ||
|
|
b292264bfd | ||
|
|
1d76f439da | ||
|
|
cc24419e98 | ||
|
|
dc485c9da6 | ||
|
|
f885c543da | ||
|
|
8c0164c373 | ||
|
|
d909d23451 | ||
|
|
7154b99c89 | ||
|
|
01986e9c6f | ||
|
|
cf787cf3a5 | ||
|
|
10b7996c1b | ||
|
|
cbd6e65744 | ||
|
|
e991303406 | ||
|
|
1094452423 | ||
|
|
5870ad9672 | ||
|
|
42823d597a | ||
|
|
45854b5e3f | ||
|
|
9f85de1821 | ||
|
|
e8ce0626d9 | ||
|
|
06af216528 | ||
|
|
c7ba8b9d6c | ||
|
|
6a1829d90c | ||
|
|
a5c5ae03eb | ||
|
|
37c8f36357 | ||
|
|
4c97863109 | ||
|
|
e968fcd562 | ||
|
|
4921b54f37 | ||
|
|
0aa8490693 | ||
|
|
64392905ef | ||
|
|
4f8d27f29a | ||
|
|
493691a4f5 | ||
|
|
7a7e54a190 | ||
|
|
e129f43c83 | ||
|
|
7fca91a3de | ||
|
|
8bb21af72c | ||
|
|
a100707c04 | ||
|
|
731d357295 | ||
|
|
c4d606e367 | ||
|
|
de55b5d014 | ||
|
|
4bb31899e5 | ||
|
|
1e3b068689 | ||
|
|
6b50f73171 | ||
|
|
489f93ebae | ||
|
|
00ccf95bc8 | ||
|
|
71d8abf30c | ||
|
|
bb81c5831a | ||
|
|
c72c1ed932 | ||
|
|
0c886c65de | ||
|
|
15d78fb724 | ||
|
|
34c4e5f0b3 | ||
|
|
54767db8c7 | ||
|
|
27a131e08e | ||
|
|
eb10e17b7b | ||
|
|
9356b5022c | ||
|
|
322661d025 | ||
|
|
89ef65f024 | ||
|
|
ab2aea4447 | ||
|
|
06c0a71d23 | ||
|
|
b6aae0f381 | ||
|
|
a41fdf331a | ||
|
|
e935602ff5 | ||
|
|
86811803e3 | ||
|
|
c562bb7487 | ||
|
|
fe7a9f1277 | ||
|
|
826c85f382 | ||
|
|
dccb1a5343 | ||
|
|
afe488d4bc | ||
|
|
9d938732d0 | ||
|
|
4e1715f4b9 | ||
|
|
2806b2368c | ||
|
|
8ca35d2d65 | ||
|
|
4d9a358ec1 | ||
|
|
6912ea1467 | ||
|
|
eeafc1a057 | ||
|
|
ca549c5e69 | ||
|
|
bde74b617f | ||
|
|
e2473f8c23 | ||
|
|
8c78395120 | ||
|
|
e06bed30cf | ||
|
|
cd75a96f0f | ||
|
|
14813c5943 | ||
|
|
aae82e0d8b | ||
|
|
9dca07d949 | ||
|
|
434ad5456b | ||
|
|
e0eebc1ef3 | ||
|
|
fd94efa41f | ||
|
|
5ff8f3d7fd | ||
|
|
98c0bba09d | ||
|
|
fc7f92253a | ||
|
|
8b942c6639 | ||
|
|
86724af484 | ||
|
|
f98d637ba4 | ||
|
|
5b6195c9bc | ||
|
|
bc5262d3dd | ||
|
|
a1042e94f1 | ||
|
|
30abe97940 | ||
|
|
90ec4dc0c7 | ||
|
|
aeb4bdd582 | ||
|
|
581930cc0d | ||
|
|
b9a279ba94 | ||
|
|
677cb5eea5 | ||
|
|
218f2f4882 | ||
|
|
84d2d493b4 | ||
|
|
7b1c5aacb0 | ||
|
|
0e282c9aed | ||
|
|
11353ae0ab | ||
|
|
a01579d4eb | ||
|
|
6cda89700e | ||
|
|
841ef1308b | ||
|
|
08e7097340 | ||
|
|
71a6a4e723 | ||
|
|
1c747b32c7 | ||
|
|
82f8788acc | ||
|
|
b5bb40f088 | ||
|
|
425997223c | ||
|
|
52848eecca | ||
|
|
769d1e05e6 | ||
|
|
d77f7c3136 | ||
|
|
5de9e9ce0b | ||
|
|
9adc6ced4f | ||
|
|
448f0241e0 | ||
|
|
fdcd7c4237 | ||
|
|
835f575b61 | ||
|
|
620e57b421 | ||
|
|
d0f33b3ce8 | ||
|
|
bb8c7c041c | ||
|
|
703e20235a | ||
|
|
6cd2d2bcba | ||
|
|
35d4da0fb5 | ||
|
|
85629f08bc | ||
|
|
3c99a59915 | ||
|
|
d8760a705c | ||
|
|
95fef7071e | ||
|
|
38f6319421 | ||
|
|
253ce00296 | ||
|
|
b01b4e2a1f | ||
|
|
6258fd3454 | ||
|
|
8e1c71529c | ||
|
|
00cdbd8fc2 | ||
|
|
5592fac308 | ||
|
|
47bdb3ac48 | ||
|
|
82b39e83ab | ||
|
|
7b1f23610f | ||
|
|
2f0c0d0b88 | ||
|
|
b3f3c23f78 | ||
|
|
12f96c1cec | ||
|
|
af45760cca | ||
|
|
d19f4aaa21 | ||
|
|
1118a1de46 | ||
|
|
8b1ae45037 | ||
|
|
b31c252860 | ||
|
|
088a212bf5 | ||
|
|
ca5b35299e | ||
|
|
d58c19479d | ||
|
|
a8e2e1872a | ||
|
|
312735878b | ||
|
|
12a3917e45 |
No files matched your search
@@ -231,6 +231,14 @@ config SELINUX
|
||||
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
config FEATURE_EXEC_PREFER_APPLETS
|
||||
bool "exec prefers applets"
|
||||
default n
|
||||
help
|
||||
This is an experimental option which directs applets about to
|
||||
call 'exec' to try and find an applicable busybox applet before
|
||||
searching the executable path for a binary or symlink to execute.
|
||||
|
||||
config BUSYBOX_EXEC_PATH
|
||||
string "Path to BusyBox executable"
|
||||
default "/proc/self/exe"
|
||||
@@ -344,16 +352,25 @@ config DEBUG
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
config DEBUG_PESSIMIZE
|
||||
bool "Disable compiler optimizations."
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
depends on DEBUG
|
||||
help
|
||||
The compiler's optimization of source code can eliminate and reorder
|
||||
code, resulting in an executable that's hard to understand when
|
||||
stepping through it with a debugger. This switches it off, resulting
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
Selecting this will add -Werror to gcc command line.
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
# Seems to be unused
|
||||
#config DEBUG_PESSIMIZE
|
||||
# bool "Disable compiler optimizations."
|
||||
# default n
|
||||
# depends on DEBUG
|
||||
# help
|
||||
# The compiler's optimization of source code can eliminate and reorder
|
||||
# code, resulting in an executable that's hard to understand when
|
||||
# stepping through it with a debugger. This switches it off, resulting
|
||||
# in a much bigger executable that more closely matches the source
|
||||
# code.
|
||||
|
||||
choice
|
||||
prompt "Additional debugging library"
|
||||
@@ -418,31 +435,30 @@ config INSTALL_NO_USR
|
||||
that you really want this behaviour.
|
||||
|
||||
choice
|
||||
prompt "Applets links"
|
||||
default INSTALL_APPLET_SYMLINKS
|
||||
help
|
||||
Choose how you install applets links.
|
||||
prompt "Applets links"
|
||||
default INSTALL_APPLET_SYMLINKS
|
||||
help
|
||||
Choose how you install applets links.
|
||||
|
||||
config INSTALL_APPLET_SYMLINKS
|
||||
bool "as soft-links"
|
||||
help
|
||||
Install applets as soft-links to the busybox binary. This needs some
|
||||
free inodes on the filesystem, but might help with filesystem
|
||||
generators that can't cope with hard-links.
|
||||
bool "as soft-links"
|
||||
help
|
||||
Install applets as soft-links to the busybox binary. This needs some
|
||||
free inodes on the filesystem, but might help with filesystem
|
||||
generators that can't cope with hard-links.
|
||||
|
||||
config INSTALL_APPLET_HARDLINKS
|
||||
bool "as hard-links"
|
||||
help
|
||||
Install applets as hard-links to the busybox binary. This might count
|
||||
on a filesystem with few inodes.
|
||||
bool "as hard-links"
|
||||
help
|
||||
Install applets as hard-links to the busybox binary. This might count
|
||||
on a filesystem with few inodes.
|
||||
|
||||
config INSTALL_APPLET_DONT
|
||||
bool
|
||||
prompt "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL
|
||||
help
|
||||
Do not install applet links. Useful when using the -install feature
|
||||
or a standalone shell for rescue pruposes.
|
||||
bool "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL || FEATURE_EXEC_PREFER_APPLETS
|
||||
help
|
||||
Do not install applet links. Useful when using the -install feature
|
||||
or a standalone shell for rescue pruposes.
|
||||
|
||||
endchoice
|
||||
|
||||
@@ -477,3 +493,4 @@ source procps/Config.in
|
||||
source shell/Config.in
|
||||
source sysklogd/Config.in
|
||||
source runit/Config.in
|
||||
source selinux/Config.in
|
||||
@@ -5,7 +5,7 @@ The BusyBox build process is similar to the Linux kernel build:
|
||||
|
||||
make menuconfig # This creates a file called ".config"
|
||||
make # This creates the "busybox" executable
|
||||
make install # or make PREFIX=/path/from/root install
|
||||
make install # or make CONFIG_PREFIX=/path/from/root install
|
||||
|
||||
The full list of configuration and install options is available by typing:
|
||||
|
||||
@@ -114,7 +114,7 @@ configuration step, as in:
|
||||
make O=/some/empty/directory allyesconfig
|
||||
cd /some/empty/directory
|
||||
make
|
||||
make PREFIX=. install
|
||||
make CONFIG_PREFIX=. install
|
||||
|
||||
More Information:
|
||||
=================
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 4
|
||||
PATCHLEVEL = 5
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
@@ -299,9 +299,11 @@ AFLAGS_KERNEL =
|
||||
|
||||
# Use LINUXINCLUDE when you must reference the include/ directory.
|
||||
# Needed to be compatible with the O= option
|
||||
CFLAGS :=
|
||||
CPPFLAGS :=
|
||||
AFLAGS :=
|
||||
CFLAGS := $(CFLAGS)
|
||||
CPPFLAGS := $(CPPFLAGS)
|
||||
AFLAGS := $(AFLAGS)
|
||||
LDFLAGS := $(LDFLAGS)
|
||||
LDLIBS :=
|
||||
|
||||
# Read KERNELRELEASE from .kernelrelease (if it exists)
|
||||
KERNELRELEASE = $(shell cat .kernelrelease 2> /dev/null)
|
||||
@@ -315,6 +317,7 @@ export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
|
||||
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
|
||||
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
|
||||
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
|
||||
export FLTFLAGS
|
||||
|
||||
# When compiling out-of-tree modules, put MODVERDIR in the module
|
||||
# tree rather than in the kernel tree. The kernel tree might
|
||||
@@ -442,6 +445,7 @@ libs-y := \
|
||||
networking/udhcp/ \
|
||||
procps/ \
|
||||
runit/ \
|
||||
selinux/ \
|
||||
shell/ \
|
||||
sysklogd/ \
|
||||
util-linux/ \
|
||||
@@ -480,7 +484,7 @@ endif
|
||||
# The all: target is the default when no target is given on the
|
||||
# command line.
|
||||
# This allow a user to issue only 'make' to build a kernel including modules
|
||||
# Defaults busybox but it is usually overriden in the arch makefile
|
||||
# Defaults busybox but it is usually overridden in the arch makefile
|
||||
all: busybox
|
||||
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
@@ -562,9 +566,10 @@ busybox-all := $(core-y) $(libs-y)
|
||||
# May be overridden by arch/$(ARCH)/Makefile
|
||||
quiet_cmd_busybox__ ?= LINK $@
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
|
||||
-o $@ \
|
||||
-o $@ -Wl,-M \
|
||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group \
|
||||
$(LDLIBS)
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
@@ -905,7 +910,7 @@ endif # CONFIG_MODULES
|
||||
|
||||
# Directories & files removed with 'make clean'
|
||||
CLEAN_DIRS += $(MODVERDIR)
|
||||
CLEAN_FILES += busybox* System.map \
|
||||
CLEAN_FILES += busybox* System.map .kernelrelease \
|
||||
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
|
||||
|
||||
# Directories & files removed with 'make mrproper'
|
||||
|
||||
+41
-8
@@ -5,9 +5,9 @@
|
||||
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
|
||||
# -std=gnu99 needed for [U]LLONG_MAX on some systems
|
||||
CPPFLAGS += $(call cc-option,-std=gnu99,)
|
||||
|
||||
CPPFLAGS += \
|
||||
-std=gnu99 \
|
||||
-Iinclude -Ilibbb \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \
|
||||
-include include/autoconf.h \
|
||||
@@ -15,17 +15,50 @@ CPPFLAGS += \
|
||||
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
|
||||
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
|
||||
|
||||
CFLAGS += \
|
||||
-Wall -Wstrict-prototypes -Wshadow -Werror -Wundef \
|
||||
-funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \
|
||||
-Os -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections
|
||||
# flag checks are grouped together to speed the checks up a bit..
|
||||
CFLAGS += $(call cc-option,-Wall -Wshadow -Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef -Wstrict-prototypes,)
|
||||
# If you want to add "-Wmissing-prototypes -Wmissing-declarations" above
|
||||
# (or anything else for that matter) make sure that it is still possible
|
||||
# to build bbox without warnings. Current offender: find.c:alloc_action().
|
||||
# Looks more like gcc bug: gcc will warn on it with or without prototype.
|
||||
# But still, warning-free compile is a must, or else we will drown
|
||||
# in warnings pretty soon.
|
||||
|
||||
ifeq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Werror,)
|
||||
endif
|
||||
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
|
||||
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
|
||||
|
||||
# gcc emits bogus "no prev proto" warning on find.c:alloc_action()
|
||||
ifneq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
endif
|
||||
|
||||
CFLAGS += $(call cc-option,-Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
# -fno-guess-branch-probability: prohibit pseudo-random guessing
|
||||
# of branch probabilities (hopefully makes bloatcheck more stable):
|
||||
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
|
||||
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
|
||||
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
#CFLAGS+=$(call cc-option,-Wconversion,)
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += -g
|
||||
CFLAGS += $(call cc-option,-g)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STATIC),y)
|
||||
LDFLAGS += -static
|
||||
LDLIBS += -static
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
LDLIBS += -lselinux -lsepol
|
||||
endif
|
||||
#LDFLAGS += -nostdlib
|
||||
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
FLTFLAGS += -s 20000
|
||||
+1
-1
@@ -27,7 +27,7 @@ help:
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo
|
||||
@echo 'Installation:'
|
||||
@echo ' install - install busybox into $(PREFIX)'
|
||||
@echo ' install - install busybox into $(CONFIG_PREFIX)'
|
||||
@echo ' uninstall'
|
||||
@echo
|
||||
@echo 'Development:'
|
||||
|
||||
@@ -50,10 +50,10 @@ Using busybox:
|
||||
|
||||
The build automatically generates a file "busybox.links", which is used by
|
||||
'make install' to create symlinks to the BusyBox binary for all compiled in
|
||||
commands. This uses the PREFIX environment variable to specify where to
|
||||
install, and installs hardlinks or symlinks depending on the configuration
|
||||
preferences. (You can also manually run the install script at
|
||||
"applets/install.sh").
|
||||
commands. This uses the CONFIG_PREFIX environment variable to specify
|
||||
where to install, and installs hardlinks or symlinks depending
|
||||
on the configuration preferences. (You can also manually run
|
||||
the install script at "applets/install.sh").
|
||||
|
||||
----------------
|
||||
|
||||
|
||||
@@ -130,7 +130,6 @@ Bernhard Fischer <busybox@busybox.net> suggests to look at these:
|
||||
make bb_common_bufsiz1 configurable, size wise.
|
||||
make pipesize configurable, size wise.
|
||||
Use bb_common_bufsiz1 throughout applets!
|
||||
Add chrt applet. Please CC Bernhard if you suggest a patch.
|
||||
|
||||
As yet unclaimed:
|
||||
|
||||
@@ -154,6 +153,10 @@ 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
|
||||
---
|
||||
ps / top
|
||||
Add support for both RSS and VSIZE rather than just one or the other.
|
||||
Or make it a build option.
|
||||
---
|
||||
man
|
||||
It would be nice to have a man command. Not one that handles troff or
|
||||
anything, just one that can handle preformatted ascii man pages, possibly
|
||||
@@ -169,6 +172,10 @@ 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
|
||||
|
||||
Architectural issues:
|
||||
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ obj-y += busybox.o
|
||||
|
||||
# Generated file needs additional love
|
||||
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
applets/applets.o: .config include/usage_compressed.h
|
||||
|
||||
hostprogs-y += usage
|
||||
always := $(hostprogs-y)
|
||||
@@ -18,5 +18,5 @@ HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
include/usage_compressed.h: $(srctree)/include/usage.h applets/usage
|
||||
include/usage_compressed.h: .config $(srctree)/include/usage.h applets/usage
|
||||
$(call cmd,gen_usage_compressed)
|
||||
+9
-5
@@ -12,8 +12,13 @@
|
||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#define PROTOTYPES
|
||||
#include "applets.h"
|
||||
#undef PROTOTYPES
|
||||
|
||||
|
||||
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
|
||||
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
|
||||
@@ -106,7 +111,7 @@ static char *get_trimmed_slice(char *s, char *e)
|
||||
}
|
||||
|
||||
|
||||
#define parse_error(x) { err=x; goto pe_label; }
|
||||
#define parse_error(x) do { errmsg = x; goto pe_label; } while(0)
|
||||
|
||||
/* Don't depend on the tools to combine strings. */
|
||||
static const char config_file[] = CONFIG_FILE;
|
||||
@@ -130,7 +135,7 @@ static void parse_config_file(void)
|
||||
struct BB_suid_config *sct;
|
||||
struct BB_applet *applet;
|
||||
FILE *f;
|
||||
char *err;
|
||||
const char *errmsg;
|
||||
char *s;
|
||||
char *e;
|
||||
int i, lc, section;
|
||||
@@ -307,7 +312,7 @@ static void parse_config_file(void)
|
||||
|
||||
pe_label:
|
||||
fprintf(stderr, "Parse error in %s, line %d: %s\n",
|
||||
config_file, lc, err);
|
||||
config_file, lc, errmsg);
|
||||
|
||||
fclose(f);
|
||||
/* Release any allocated memory before returning. */
|
||||
@@ -316,7 +321,6 @@ static void parse_config_file(void)
|
||||
free(sct_head);
|
||||
sct_head = sct;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
+2
-1
@@ -73,6 +73,7 @@ int main(int argc, char **argv)
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
int busybox_main(int argc, char **argv);
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
/*
|
||||
@@ -91,7 +92,7 @@ int busybox_main(int argc, char **argv)
|
||||
|
||||
/* link */
|
||||
// XXX: FIXME: this is broken. Why not just use argv[0] ?
|
||||
busybox = xreadlink("/proc/self/exe");
|
||||
busybox = xmalloc_readlink_or_warn("/proc/self/exe");
|
||||
if (!busybox)
|
||||
return 1;
|
||||
install_links(busybox, use_symbolic_links);
|
||||
|
||||
@@ -14,6 +14,6 @@ exec >"$target"
|
||||
|
||||
echo 'static const char packed_usage[] = '
|
||||
"$loc/usage" | bzip2 -1 | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' -e 's/ \(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/'
|
||||
| $SED -e 's/^[^ ]*//' -e 's/ *\(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/'
|
||||
echo ';'
|
||||
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
CFLAGS += -march=i386 -mpreferred-stack-boundary=2
|
||||
CFLAGS += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
|
||||
+5
-5
@@ -8,15 +8,15 @@ libs-y += libunarchive/
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_BUNZIP2) += bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += unlzma.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_GUNZIP) += gunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
@@ -38,6 +38,7 @@ static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv);
|
||||
int ar_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Common code for gunzip-like applets
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
enum {
|
||||
OPT_STDOUT = 0x1,
|
||||
OPT_FORCE = 0x2,
|
||||
/* gunzip only: */
|
||||
OPT_VERBOSE = 0x4,
|
||||
OPT_DECOMPRESS = 0x8,
|
||||
OPT_TEST = 0x10,
|
||||
};
|
||||
|
||||
static
|
||||
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
{
|
||||
int fd = open(filename, flags, mode);
|
||||
if (fd < 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
return 1;
|
||||
}
|
||||
if (fd != to_fd) {
|
||||
if (dup2(fd, to_fd) < 0)
|
||||
bb_perror_msg_and_die("cannot dup");
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbunpack(char **argv,
|
||||
char* (*make_new_name)(char *filename),
|
||||
USE_DESKTOP(long long) int (*unpacker)(void)
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
new_name = NULL;
|
||||
filename = *argv; /* can be NULL - 'streaming' bunzip2 */
|
||||
|
||||
if (filename && LONE_DASH(filename))
|
||||
filename = NULL;
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
err:
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Special cases: test, stdout */
|
||||
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;
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
/* Open dst if we are going to unpack to file */
|
||||
if (filename) {
|
||||
new_name = make_new_name(filename);
|
||||
if (!new_name) {
|
||||
bb_error_msg("%s: unknown suffix - ignored", filename);
|
||||
goto err;
|
||||
}
|
||||
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
|
||||
/* GNU gunzip goes not bail out, but goes to next file */
|
||||
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
stat_buf.st_mode))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
status = unpacker();
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
if (status >= 0) {
|
||||
/* TODO: restore user/group/times here? */
|
||||
/* Delete _compressed_ file */
|
||||
del = filename;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
if (new_name == filename)
|
||||
filename[strlen(filename)] = '.';
|
||||
}
|
||||
if (unlink(del) < 0)
|
||||
bb_perror_msg_and_die("cannot remove %s", 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);
|
||||
}
|
||||
} while (*argv && *++argv);
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
#if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* make_new_name_generic(char *filename, const char *expected_ext)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension + 1, expected_ext) != 0) {
|
||||
/* Mimic GNU gunzip - "real" bunzip2 tries to */
|
||||
/* unpack file anyway, to file.out */
|
||||
return NULL;
|
||||
}
|
||||
*extension = '\0';
|
||||
return filename;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_BUNZIP2
|
||||
|
||||
static
|
||||
char* make_new_name_bunzip2(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "bz2");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_bunzip2(void)
|
||||
{
|
||||
return uncompressStream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int bunzip2_main(int argc, char **argv);
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argc, argv, "cf");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if ENABLE_GUNZIP
|
||||
|
||||
static
|
||||
char* make_new_name_gunzip(char *filename)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
|
||||
if (!extension)
|
||||
return NULL;
|
||||
|
||||
extension++;
|
||||
if (strcmp(extension, "tgz" + 1) == 0
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
|| strcmp(extension, "Z") == 0
|
||||
#endif
|
||||
) {
|
||||
extension[-1] = '\0';
|
||||
} else if(strcmp(extension, "tgz") == 0) {
|
||||
filename = xstrdup(filename);
|
||||
extension = strrchr(filename, '.');
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(STDIN_FILENO) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(STDIN_FILENO);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else if (magic2 == 0x8b) {
|
||||
check_header_gzip_or_die(STDIN_FILENO);
|
||||
status = inflate_gunzip(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
goto bad_magic;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
} else {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
/* status is still == -1 */
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int gunzip_main(int argc, char **argv);
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argc, argv, "cfvdt");
|
||||
argv += optind;
|
||||
/* if called as zcat */
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_gunzip, unpack_gunzip);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Based on bunzip.c from busybox
|
||||
*
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_UNLZMA
|
||||
|
||||
static
|
||||
char* make_new_name_unlzma(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "lzma");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_unlzma(void)
|
||||
{
|
||||
return unlzma(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int unlzma_main(int argc, char **argv);
|
||||
int unlzma_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argc, argv, "c");
|
||||
argv += optind;
|
||||
/* lzmacat? */
|
||||
if (applet_name[4] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_unlzma, unpack_unlzma);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* make_new_name_uncompress(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "Z");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_uncompress(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
|
||||
bb_error_msg("invalid magic");
|
||||
} else {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int uncompress_main(int argc, char **argv);
|
||||
int uncompress_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argc, argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, make_new_name_uncompress, unpack_uncompress);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define BUNZIP2_OPT_STDOUT 1
|
||||
#define BUNZIP2_OPT_FORCE 2
|
||||
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename;
|
||||
unsigned opt;
|
||||
int src_fd, dst_fd;
|
||||
|
||||
opt = getopt32(argc, argv, "cf");
|
||||
|
||||
/* Set input filename and number */
|
||||
filename = argv[optind];
|
||||
if (filename && NOT_LONE_DASH(filename)) {
|
||||
/* Open input file */
|
||||
src_fd = xopen(filename, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
filename = 0;
|
||||
}
|
||||
|
||||
/* if called as bzcat force the stdout flag */
|
||||
if ((opt & BUNZIP2_OPT_STDOUT) || applet_name[2] == 'c')
|
||||
filename = 0;
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
struct stat stat_buf;
|
||||
/* extension = filename+strlen(filename)-4 is buggy:
|
||||
* strlen may be less than 4 */
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension, ".bz2") != 0) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
xstat(filename, &stat_buf);
|
||||
*extension = '\0';
|
||||
dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
} else dst_fd = STDOUT_FILENO;
|
||||
status = uncompressStream(src_fd, dst_fd);
|
||||
if (filename) {
|
||||
if (status >= 0) filename[strlen(filename)] = '.';
|
||||
if (unlink(filename) < 0) {
|
||||
bb_error_msg_and_die("cannot remove %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
|
||||
int cpio_main(int argc, char **argv);
|
||||
int cpio_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
+25
-37
@@ -643,11 +643,8 @@ static unsigned fill_package_struct(char *control_buffer)
|
||||
return -1;
|
||||
}
|
||||
num = search_package_hashtable(new_node->name, new_node->version, VER_EQUAL);
|
||||
if (package_hashtable[num] == NULL) {
|
||||
package_hashtable[num] = new_node;
|
||||
} else {
|
||||
free_package(new_node);
|
||||
}
|
||||
free_package(package_hashtable[num]);
|
||||
package_hashtable[num] = new_node;
|
||||
return num;
|
||||
}
|
||||
|
||||
@@ -706,7 +703,6 @@ static void set_status(const unsigned status_node_num, const char *new_value, co
|
||||
new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
|
||||
status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
|
||||
free(new_status);
|
||||
return;
|
||||
}
|
||||
|
||||
static const char *describe_status(int status_num) {
|
||||
@@ -763,7 +759,6 @@ static void index_status_file(const char *filename)
|
||||
free(control_buffer);
|
||||
}
|
||||
fclose(status_file);
|
||||
return;
|
||||
}
|
||||
|
||||
static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer)
|
||||
@@ -780,7 +775,6 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
|
||||
fprintf(new_status_file, "%s: %s\n", name, value);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* This could do with a cleanup */
|
||||
@@ -1417,16 +1411,14 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
|
||||
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
llist_add_to(&(ar_handle->accept), "control.tar.gz");
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_handle->accept), "control.tar.bz2");
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
@@ -1439,16 +1431,14 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
|
||||
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
llist_add_to(&(ar_handle->accept), "data.tar.gz");
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_handle->accept), "data.tar.bz2");
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept)
|
||||
@@ -1472,7 +1462,6 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
|
||||
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
|
||||
data_extract_all(archive_handle);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void unpack_package(deb_file_t *deb_file)
|
||||
@@ -1525,7 +1514,7 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
init_archive_deb_data(archive_handle);
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = "/";
|
||||
archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */
|
||||
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
@@ -1566,6 +1555,7 @@ static void configure_package(deb_file_t *deb_file)
|
||||
set_status(status_num, "installed", 3);
|
||||
}
|
||||
|
||||
int dpkg_main(int argc, char **argv);
|
||||
int dpkg_main(int argc, char **argv)
|
||||
{
|
||||
deb_file_t **deb_file = NULL;
|
||||
@@ -1585,21 +1575,19 @@ int dpkg_main(int argc, char **argv)
|
||||
OPT_purge = 0x10,
|
||||
OPT_remove = 0x20,
|
||||
OPT_unpack = 0x40,
|
||||
REQ_package_name = 0x8000,
|
||||
REQ_filename = 0x4000,
|
||||
};
|
||||
|
||||
opt = getopt32(argc, argv, "CF:ilPru", &str_f);
|
||||
if (opt & OPT_configure) opt |= REQ_package_name; // -C
|
||||
//if (opt & OPT_configure) ... // -C
|
||||
if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg)
|
||||
if (strcmp(str_f, "depends"))
|
||||
opt &= ~OPT_force_ignore_depends;
|
||||
}
|
||||
if (opt & OPT_install) opt |= REQ_filename; // -i
|
||||
//if (opt & OPT_install) ... // -i
|
||||
//if (opt & OPT_list_installed) ... // -l
|
||||
if (opt & OPT_purge) opt |= REQ_package_name; // -P
|
||||
if (opt & OPT_remove) opt |= REQ_package_name; // -r
|
||||
if (opt & OPT_unpack) opt |= REQ_filename; // -u (--unpack in official dpkg)
|
||||
//if (opt & OPT_purge) ... // -P
|
||||
//if (opt & OPT_remove) ... // -r
|
||||
//if (opt & OPT_unpack) ... // -u (--unpack in official dpkg)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
/* check for non-option argument if expected */
|
||||
@@ -1622,14 +1610,15 @@ int dpkg_main(int argc, char **argv)
|
||||
/* Read arguments and store relevant info in structs */
|
||||
while (*argv) {
|
||||
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
|
||||
deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
|
||||
deb_file[deb_count] = xzalloc(sizeof(deb_file_t));
|
||||
if (opt & REQ_filename) {
|
||||
deb_file = xrealloc(deb_file, sizeof(deb_file[0]) * (deb_count + 2));
|
||||
deb_file[deb_count] = xzalloc(sizeof(deb_file[0][0]));
|
||||
if (opt & (OPT_install | OPT_unpack)) {
|
||||
/* -i/-u: require filename */
|
||||
archive_handle_t *archive_handle;
|
||||
llist_t *control_list = NULL;
|
||||
|
||||
/* Extract the control file */
|
||||
llist_add_to(&control_list, "./control");
|
||||
llist_add_to(&control_list, (char*)"./control");
|
||||
archive_handle = init_archive_deb_ar(argv[0]);
|
||||
init_archive_deb_control(archive_handle);
|
||||
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
||||
@@ -1647,7 +1636,7 @@ int dpkg_main(int argc, char **argv)
|
||||
deb_file[deb_count]->package = (unsigned) package_num;
|
||||
|
||||
/* Add the package to the status hashtable */
|
||||
if (opt & (OPT_unpack|OPT_install)) {
|
||||
if (opt & (OPT_unpack | OPT_install)) {
|
||||
/* Try and find a currently installed version of this package */
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[deb_count]->package]->name]);
|
||||
/* If no previous entry was found initialise a new entry */
|
||||
@@ -1665,8 +1654,8 @@ int dpkg_main(int argc, char **argv)
|
||||
set_status(status_num, "reinstreq", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (opt & REQ_package_name) {
|
||||
} else if (opt & (OPT_configure | OPT_purge | OPT_remove)) {
|
||||
/* -C/-p/-r: require package name */
|
||||
deb_file[deb_count]->package = search_package_hashtable(
|
||||
search_name_hashtable(argv[0]),
|
||||
search_name_hashtable("ANY"), VER_ANY);
|
||||
@@ -1685,8 +1674,7 @@ int dpkg_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("%s is already removed", name_hashtable[package_hashtable[package_num]->name]);
|
||||
}
|
||||
set_status(status_num, "deinstall", 1);
|
||||
}
|
||||
else if (opt & OPT_purge) {
|
||||
} else if (opt & OPT_purge) {
|
||||
/* if package status is "conf-files" then its ok */
|
||||
if (strcmp(name_hashtable[state_status], "not-installed") == 0) {
|
||||
bb_error_msg_and_die("%s is already purged", name_hashtable[package_hashtable[package_num]->name]);
|
||||
@@ -1697,6 +1685,8 @@ int dpkg_main(int argc, char **argv)
|
||||
deb_count++;
|
||||
argv++;
|
||||
}
|
||||
if (!deb_count)
|
||||
bb_error_msg_and_die("no package files specified");
|
||||
deb_file[deb_count] = NULL;
|
||||
|
||||
/* Check that the deb file arguments are installable */
|
||||
@@ -1748,9 +1738,7 @@ int dpkg_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
|
||||
if (package_hashtable[i] != NULL) {
|
||||
free_package(package_hashtable[i]);
|
||||
}
|
||||
free_package(package_hashtable[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < STATUS_HASH_PRIME; i++) {
|
||||
|
||||
+7
-6
@@ -13,13 +13,14 @@
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
int dpkg_deb_main(int argc, char **argv);
|
||||
int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
llist_t *control_tar_llist = NULL;
|
||||
unsigned opt;
|
||||
char *extract_dir = NULL;
|
||||
const char *extract_dir = NULL;
|
||||
short argcount = 1;
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
@@ -31,13 +32,13 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, "control.tar.gz");
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, "control.tar.bz2");
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
||||
#endif
|
||||
|
||||
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
@@ -60,7 +61,7 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
llist_add_to(&(tar_archive->accept), "./control");
|
||||
llist_add_to(&(tar_archive->accept), (char*)"./control");
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define GUNZIP_OPT_STDOUT 1
|
||||
#define GUNZIP_OPT_FORCE 2
|
||||
#define GUNZIP_OPT_TEST 4
|
||||
#define GUNZIP_OPT_DECOMPRESS 8
|
||||
#define GUNZIP_OPT_VERBOSE 0x10
|
||||
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
int exitcode = 0;
|
||||
unsigned opt;
|
||||
|
||||
opt = getopt32(argc, argv, "cftdv");
|
||||
/* if called as zcat */
|
||||
if (strcmp(applet_name, "zcat") == 0) {
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
}
|
||||
|
||||
do {
|
||||
struct stat stat_buf;
|
||||
char *old_path = argv[optind];
|
||||
char *delete_path = NULL;
|
||||
char *new_path = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
optind++;
|
||||
|
||||
if (old_path == NULL || LONE_DASH(old_path)) {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
USE_DESKTOP(opt &= ~GUNZIP_OPT_VERBOSE;)
|
||||
optind = argc; /* we don't handle "gunzip - a.gz b.gz" */
|
||||
} else {
|
||||
src_fd = xopen(old_path, O_RDONLY);
|
||||
/* Get the time stamp on the input file. */
|
||||
fstat(src_fd, &stat_buf);
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && !(opt & GUNZIP_OPT_FORCE)) {
|
||||
bb_error_msg_and_die
|
||||
("compressed data not read from terminal, use -f to force it");
|
||||
}
|
||||
|
||||
/* Set output filename and number */
|
||||
if (opt & GUNZIP_OPT_TEST) {
|
||||
dst_fd = xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
|
||||
} else if (opt & GUNZIP_OPT_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
char *extension;
|
||||
|
||||
new_path = xstrdup(old_path);
|
||||
|
||||
extension = strrchr(new_path, '.');
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
if (extension && (strcmp(extension, ".Z") == 0)) {
|
||||
*extension = '\0';
|
||||
} else
|
||||
#endif
|
||||
if (extension && (strcmp(extension, ".gz") == 0)) {
|
||||
*extension = '\0';
|
||||
} else if (extension && (strcmp(extension, ".tgz") == 0)) {
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
// FIXME: should we die or just skip to next?
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
|
||||
/* Open output file (with correct permissions) */
|
||||
dst_fd = xopen3(new_path, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = old_path;
|
||||
}
|
||||
|
||||
status = -1;
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(src_fd) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(src_fd);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
} else if (magic2 == 0x8b) {
|
||||
check_header_gzip(src_fd); // FIXME: xfunc? _or_die?
|
||||
status = inflate_gunzip(src_fd, dst_fd);
|
||||
} else {
|
||||
bb_error_msg("invalid magic");
|
||||
exitcode = 1;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
exitcode = 1;
|
||||
}
|
||||
else if (ENABLE_DESKTOP && (opt & GUNZIP_OPT_VERBOSE)) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
old_path, (unsigned)(stat_buf.st_size*100 / (status+1)), new_path);
|
||||
}
|
||||
} else {
|
||||
bb_error_msg("invalid magic");
|
||||
exitcode = 1;
|
||||
}
|
||||
if (status < 0 && new_path) {
|
||||
/* Unzip failed, remove new path instead of old path */
|
||||
delete_path = new_path;
|
||||
}
|
||||
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
/* delete_path will be NULL if in test mode or from stdin */
|
||||
if (delete_path && (unlink(delete_path) == -1)) {
|
||||
bb_error_msg("cannot remove %s", delete_path);
|
||||
exitcode = 1;
|
||||
}
|
||||
|
||||
free(new_path);
|
||||
|
||||
} while (optind < argc);
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
+436
-573
File diff suppressed because it is too large.
Load diff
@@ -2,12 +2,11 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip */
|
||||
|
||||
void check_header_gzip(int src_fd)
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip_or_die */
|
||||
|
||||
void check_header_gzip_or_die(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -30,7 +29,7 @@ void check_header_gzip(int src_fd)
|
||||
|
||||
if (header.formatted.flags & 0x04) {
|
||||
/* bit 2 set: extra field present */
|
||||
unsigned char extra_short;
|
||||
unsigned extra_short;
|
||||
|
||||
extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
|
||||
while (extra_short > 0) {
|
||||
@@ -57,6 +56,4 @@ void check_header_gzip(int src_fd)
|
||||
xread_char(src_fd);
|
||||
xread_char(src_fd);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -17,6 +14,4 @@ void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -110,6 +110,14 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
}
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)
|
||||
&& (file_header->mode & S_IFMT) != S_IFLNK
|
||||
) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
|
||||
@@ -455,6 +455,8 @@ static int huft_build(unsigned *b, const unsigned n,
|
||||
* bl, bd: number of bits decoded by tl[] and td[]
|
||||
*/
|
||||
/* called once from inflate_block */
|
||||
|
||||
/* map formerly local static variables to globals */
|
||||
#define ml inflate_codes_ml
|
||||
#define md inflate_codes_md
|
||||
#define bb inflate_codes_bb
|
||||
|
||||
@@ -66,7 +66,9 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
unsigned long_offset;
|
||||
|
||||
if (ar.formatted.name[1] == '/') {
|
||||
/* If the second char is a '/' then this entries data section
|
||||
* stores long filename for multiple entries, they are stored
|
||||
@@ -78,20 +80,22 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
/* This ar entries data section only contained filenames for other records
|
||||
* they are stored in the static ar_long_names for future reference */
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
} else if (ar.formatted.name[1] == ' ') {
|
||||
}
|
||||
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
/* This is the index of symbols in the file for compilers */
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += typed->size;
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
} else {
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
(saved in variable long_name) that conatains the real filename */
|
||||
const unsigned int long_offset = atoi(&ar.formatted.name[1]);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
}
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in variable long_name) that conatains the real filename */
|
||||
long_offset = atoi(&ar.formatted.name[1]);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
#else
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
|
||||
@@ -69,7 +69,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
char padding[12]; /* 500-512 */
|
||||
} tar;
|
||||
char *cp;
|
||||
int sum, i;
|
||||
int i, sum_u, sum_s, sum;
|
||||
int parse_names;
|
||||
|
||||
if (sizeof(tar) != 512)
|
||||
@@ -110,16 +110,23 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
#endif
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
/* Do checksum on headers */
|
||||
sum = ' ' * sizeof(tar.chksum);
|
||||
|
||||
/* Do checksum on headers.
|
||||
* POSIX says that checksum is done on unsigned bytes, but
|
||||
* Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source. */
|
||||
sum_s = sum_u = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148 ; i++) {
|
||||
sum += ((char*)&tar)[i];
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
}
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
sum += ((char*)&tar)[i];
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
}
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
if (sum != xstrtoul(tar.chksum, 8)) {
|
||||
sum = xstrtoul(tar.chksum, 8);
|
||||
if (sum_u != sum && sum_s != sum) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
check_header_gzip_or_die(archive_handle->src_fd);
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
|
||||
+2
-1
@@ -80,6 +80,7 @@ static void fileaction_dobackup(char *filename, int fileref);
|
||||
static void fileaction_setowngrp(char *filename, int fileref);
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
|
||||
int rpm_main(int argc, char **argv);
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
@@ -202,7 +203,7 @@ static void extract_cpio_gz(int fd) {
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
check_header_gzip_or_die(archive_handle->src_fd);
|
||||
xchdir("/"); /* Install RPM's to root */
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
|
||||
+2
-1
@@ -49,6 +49,7 @@ static void skip_header(int rpm_fd)
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv);
|
||||
int rpm2cpio_main(int argc, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
@@ -78,7 +79,7 @@ int rpm2cpio_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip(rpm_fd);
|
||||
check_header_gzip_or_die(rpm_fd);
|
||||
if (inflate_gunzip(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
|
||||
+9
-6
@@ -134,7 +134,6 @@ static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
|
||||
}
|
||||
*hlInfoHeadPtr = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
@@ -173,6 +172,9 @@ static void putOctal(char *cp, int len, off_t value)
|
||||
|
||||
static void chksum_and_xwrite(int fd, struct TarHeader* hp)
|
||||
{
|
||||
/* POSIX says that checksum is done on unsigned bytes
|
||||
* (Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source) */
|
||||
const unsigned char *cp;
|
||||
int chksum, size;
|
||||
|
||||
@@ -273,8 +275,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
tbInfo->hlInfo->name, 0);
|
||||
#endif
|
||||
} else if (S_ISLNK(statbuf->st_mode)) {
|
||||
char *lpath = xreadlink(fileName);
|
||||
if (!lpath) /* Already printed err msg inside xreadlink() */
|
||||
char *lpath = xmalloc_readlink_or_warn(fileName);
|
||||
if (!lpath)
|
||||
return FALSE;
|
||||
header.typeflag = SYMTYPE;
|
||||
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
||||
@@ -504,7 +506,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
int gzipDataPipe[2] = { -1, -1 };
|
||||
int gzipStatusPipe[2] = { -1, -1 };
|
||||
volatile int vfork_exec_errno = 0;
|
||||
char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
|
||||
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
|
||||
bb_perror_msg_and_die("pipe");
|
||||
@@ -529,7 +531,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
close(gzipStatusPipe[0]);
|
||||
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */
|
||||
|
||||
execlp(zip_exec, zip_exec, "-f", NULL);
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
vfork_exec_errno = errno;
|
||||
|
||||
close(gzipStatusPipe[1]);
|
||||
@@ -752,6 +754,7 @@ static const struct option tar_long_options[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
int tar_main(int argc, char **argv);
|
||||
int tar_main(int argc, char **argv)
|
||||
{
|
||||
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
|
||||
@@ -863,7 +866,7 @@ int tar_main(int argc, char **argv)
|
||||
llist_add_to(&tar_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
tar_handle->accept = rev_llist(tar_handle->accept);
|
||||
tar_handle->accept = llist_rev(tar_handle->accept);
|
||||
|
||||
if (tar_handle->accept || tar_handle->reject)
|
||||
tar_handle->filter = filter_accept_reject_list;
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define GUNZIP_TO_STDOUT 1
|
||||
#define GUNZIP_FORCE 2
|
||||
|
||||
int uncompress_main(int argc, char **argv)
|
||||
{
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned long flags;
|
||||
|
||||
flags = getopt32(argc, argv, "cf");
|
||||
|
||||
while (optind < argc) {
|
||||
char *compressed_file = argv[optind++];
|
||||
char *delete_path = NULL;
|
||||
char *uncompressed_file = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
if (LONE_DASH(compressed_file)) {
|
||||
src_fd = STDIN_FILENO;
|
||||
flags |= GUNZIP_TO_STDOUT;
|
||||
} else {
|
||||
src_fd = xopen(compressed_file, O_RDONLY);
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && ((flags & GUNZIP_FORCE) == 0)) {
|
||||
bb_error_msg_and_die
|
||||
("compressed data not read from terminal. Use -f to force it.");
|
||||
}
|
||||
|
||||
/* Set output filename and number */
|
||||
if (flags & GUNZIP_TO_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
struct stat stat_buf;
|
||||
char *extension;
|
||||
|
||||
uncompressed_file = xstrdup(compressed_file);
|
||||
|
||||
extension = strrchr(uncompressed_file, '.');
|
||||
if (!extension || (strcmp(extension, ".Z") != 0)) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
*extension = '\0';
|
||||
|
||||
/* Open output file */
|
||||
xstat(compressed_file, &stat_buf);
|
||||
dst_fd = xopen3(uncompressed_file,
|
||||
O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = compressed_file;
|
||||
}
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if ((xread_char(src_fd) != 0x1f) || (xread_char(src_fd) != 0x9d)) {
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
|
||||
if ((status != EXIT_SUCCESS) && (uncompressed_file)) {
|
||||
/* Unzip failed, remove the uncomressed file instead of compressed file */
|
||||
delete_path = uncompressed_file;
|
||||
}
|
||||
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
/* delete_path will be NULL if in test mode or from stdin */
|
||||
if (delete_path && (unlink(delete_path) == -1)) {
|
||||
bb_error_msg_and_die("cannot remove %s", delete_path);
|
||||
}
|
||||
|
||||
free(uncompressed_file);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Based on bunzip.c from busybox
|
||||
*
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* Why our g[un]zip/bunzip2 are so ugly compared to this beauty? */
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define UNLZMA_OPT_STDOUT 1
|
||||
|
||||
int unlzma_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename;
|
||||
unsigned opt;
|
||||
int src_fd, dst_fd;
|
||||
|
||||
opt = getopt32(argc, argv, "c");
|
||||
|
||||
/* Set input filename and number */
|
||||
filename = argv[optind];
|
||||
if (filename && NOT_LONE_DASH(filename)) {
|
||||
/* Open input file */
|
||||
src_fd = xopen(filename, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
filename = 0;
|
||||
}
|
||||
|
||||
/* if called as lzmacat force the stdout flag */
|
||||
if ((opt & UNLZMA_OPT_STDOUT) || applet_name[4] == 'c')
|
||||
filename = 0;
|
||||
|
||||
if (filename) {
|
||||
struct stat stat_buf;
|
||||
/* bug: char *extension = filename + strlen(filename) - 5; */
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension, ".lzma") != 0) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
xstat(filename, &stat_buf);
|
||||
*extension = '\0';
|
||||
dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
} else
|
||||
dst_fd = STDOUT_FILENO;
|
||||
status = unlzma(src_fd, dst_fd);
|
||||
if (filename) {
|
||||
if (status >= 0) /* if success delete src, else delete dst */
|
||||
filename[strlen(filename)] = '.';
|
||||
if (unlink(filename) < 0) {
|
||||
bb_error_msg_and_die("cannot remove %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
return (status < 0);
|
||||
}
|
||||
@@ -93,6 +93,7 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv);
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
zip_header_t zip_header;
|
||||
|
||||
@@ -15,6 +15,7 @@ enum {
|
||||
VT_WAITACTIVE = 0x5607 /* wait for vt active */
|
||||
};
|
||||
|
||||
int chvt_main(int argc, char **argv);
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
int clear_main(int argc, char **argv);
|
||||
int clear_main(int argc, char **argv)
|
||||
{
|
||||
return printf("\033[H\033[J") != 6;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
/* From <linux/vt.h> */
|
||||
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
|
||||
|
||||
int deallocvt_main(int argc, char *argv[]);
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
/* num = 0 deallocate all unused consoles */
|
||||
|
||||
@@ -22,18 +22,19 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int dumpkmap_main(int argc, char **argv);
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
|
||||
if (argc >= 2 && *argv[1] == '-')
|
||||
if (argc >= 2 && argv[1][0] == '-')
|
||||
bb_show_usage();
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
write(1, magic, 7);
|
||||
write(1, "bkeymap", 7);
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
|
||||
@@ -30,6 +30,7 @@ struct psf_header {
|
||||
|
||||
static void loadnewfont(int fd);
|
||||
|
||||
int loadfont_main(int argc, char **argv);
|
||||
int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@@ -25,6 +25,7 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int loadkmap_main(int argc, char **argv);
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int openvt_main(int argc, char **argv);
|
||||
int openvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
@@ -35,7 +36,7 @@ int openvt_main(int argc, char **argv)
|
||||
dup2(fd, STDERR_FILENO);
|
||||
while (fd > 2) close(fd--);
|
||||
|
||||
execvp(argv[2], &argv[2]);
|
||||
BB_EXECVP(argv[2], &argv[2]);
|
||||
_exit(1);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int reset_main(int argc, char **argv);
|
||||
int reset_main(int argc, char **argv)
|
||||
{
|
||||
if (isatty(1)) {
|
||||
|
||||
+41
-9
@@ -9,30 +9,62 @@
|
||||
/* no options, no getopt */
|
||||
#include "busybox.h"
|
||||
|
||||
#define ESC "\033"
|
||||
|
||||
struct termios old;
|
||||
|
||||
static void
|
||||
onintr(int sig ATTRIBUTE_UNUSED)
|
||||
{
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &old);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int resize_main(int argc, char **argv);
|
||||
int resize_main(int argc, char **argv)
|
||||
{
|
||||
struct termios old, new;
|
||||
struct winsize w = {0,0,0,0};
|
||||
struct termios new;
|
||||
struct winsize w = { 0,0,0,0 };
|
||||
int ret;
|
||||
|
||||
tcgetattr(STDOUT_FILENO, &old); /* fiddle echo */
|
||||
/* We use _stderr_ in order to make resize usable
|
||||
* in shell backticks (those redirect stdout away from tty).
|
||||
* NB: other versions of resize open "/dev/tty"
|
||||
* and operate on it - should we do the same?
|
||||
*/
|
||||
|
||||
tcgetattr(STDERR_FILENO, &old); /* fiddle echo */
|
||||
new = old;
|
||||
new.c_cflag |= (CLOCAL | CREAD);
|
||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &new);
|
||||
signal(SIGINT, onintr);
|
||||
signal(SIGQUIT, onintr);
|
||||
signal(SIGTERM, onintr);
|
||||
signal(SIGALRM, onintr);
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
||||
|
||||
/* save_cursor_pos 7
|
||||
* scroll_whole_screen [r
|
||||
* put_cursor_waaaay_off [$x;$yH
|
||||
* get_cursor_pos [6n
|
||||
* restore_cursor_pos 8
|
||||
*/
|
||||
printf("\0337\033[r\033[999;999H\033[6n");
|
||||
scanf("\033[%hu;%huR", &w.ws_row, &w.ws_col);
|
||||
ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w);
|
||||
printf("\0338");
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &old);
|
||||
fprintf(stderr, ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n");
|
||||
alarm(3); /* Just in case terminal won't answer */
|
||||
scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col);
|
||||
fprintf(stderr, ESC"8");
|
||||
|
||||
/* BTW, other versions of resize recalculate w.ws_xpixel, ws.ws_ypixel
|
||||
* by calculating character cell HxW from old values
|
||||
* (gotten via TIOCGWINSZ) and recomputing *pixel values */
|
||||
ret = ioctl(STDERR_FILENO, TIOCSWINSZ, &w);
|
||||
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &old);
|
||||
|
||||
if (ENABLE_FEATURE_RESIZE_PRINT)
|
||||
printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",
|
||||
w.ws_col, w.ws_row);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -18,6 +18,7 @@ static const struct option setconsole_long_options[] = {
|
||||
|
||||
#define OPT_SETCONS_RESET 1
|
||||
|
||||
int setconsole_main(int argc, char **argv);
|
||||
int setconsole_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long flags;
|
||||
@@ -37,7 +38,7 @@ int setconsole_main(int argc, char **argv)
|
||||
device = argv[optind];
|
||||
} else {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
device = CONSOLE_DEV;
|
||||
device = DEV_CONSOLE;
|
||||
}
|
||||
|
||||
if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
@@ -24,8 +21,8 @@ enum {
|
||||
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
|
||||
};
|
||||
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
int setkeycodes_main(int argc, char** argv);
|
||||
int setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
extern int setlogcons_main(int argc, char **argv)
|
||||
int setlogcons_main(int argc, char **argv);
|
||||
int setlogcons_main(int argc, char **argv)
|
||||
{
|
||||
struct {
|
||||
char fn;
|
||||
|
||||
+2
-1
@@ -10,7 +10,8 @@ lib-y:=
|
||||
lib-$(CONFIG_BASENAME) += basename.o
|
||||
lib-$(CONFIG_CAL) += cal.o
|
||||
lib-$(CONFIG_CAT) += cat.o
|
||||
lib-$(CONFIG_LESS) += cat.o # less uses it if stdout isn't a tty
|
||||
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
|
||||
lib-$(CONFIG_LESS) += cat.o # less too
|
||||
lib-$(CONFIG_CATV) += catv.o
|
||||
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
|
||||
lib-$(CONFIG_CHMOD) += chmod.o
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int basename_main(int argc, char **argv);
|
||||
int basename_main(int argc, char **argv)
|
||||
{
|
||||
size_t m, n;
|
||||
|
||||
@@ -77,6 +77,7 @@ static char *build_row(char *p, int *dp);
|
||||
#define J_WEEK_LEN (WEEK_LEN + 7)
|
||||
#define HEAD_SEP 2 /* spaces between day headings */
|
||||
|
||||
int cal_main(int argc, char **argv);
|
||||
int cal_main(int argc, char **argv)
|
||||
{
|
||||
struct tm *local_time;
|
||||
|
||||
+2
-1
@@ -14,7 +14,7 @@
|
||||
|
||||
int bb_cat(char **argv)
|
||||
{
|
||||
static char *const argv_dash[] = { "-", NULL };
|
||||
static const char *const argv_dash[] = { "-", NULL };
|
||||
FILE *f;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
@@ -34,6 +34,7 @@ int bb_cat(char **argv)
|
||||
return retval;
|
||||
}
|
||||
|
||||
int cat_main(int argc, char **argv);
|
||||
int cat_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argc, argv, "u");
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int catv_main(int argc, char **argv);
|
||||
int catv_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS, fd;
|
||||
|
||||
+2
-4
@@ -7,15 +7,13 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
/* FIXME - move to .h */
|
||||
extern int chown_main(int argc, char **argv);
|
||||
|
||||
int chgrp_main(int argc, char **argv);
|
||||
int chgrp_main(int argc, char **argv)
|
||||
{
|
||||
/* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
|
||||
|
||||
+11
-9
@@ -31,7 +31,7 @@
|
||||
* symbolic links encountered during recursive directory traversals.
|
||||
*/
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
|
||||
{
|
||||
mode_t newmode;
|
||||
|
||||
@@ -46,8 +46,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk, in
|
||||
}
|
||||
newmode = statbuf->st_mode;
|
||||
|
||||
if (!bb_parse_mode((char *)junk, &newmode))
|
||||
bb_error_msg_and_die("invalid mode: %s", (char *)junk);
|
||||
if (!bb_parse_mode((char *)param, &newmode))
|
||||
bb_error_msg_and_die("invalid mode: %s", (char *)param);
|
||||
|
||||
if (chmod(fileName, newmode) == 0) {
|
||||
if (OPT_VERBOSE
|
||||
@@ -64,6 +64,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk, in
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chmod_main(int argc, char **argv);
|
||||
int chmod_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
@@ -117,10 +118,12 @@ int chmod_main(int argc, char **argv)
|
||||
/*
|
||||
Security: chmod is too important and too subtle.
|
||||
This is a test script (busybox chmod versus coreutils).
|
||||
Run it in empty dir. Probably requires bash.
|
||||
Run it in empty directory.
|
||||
|
||||
#!/bin/sh
|
||||
function create() {
|
||||
t1="/tmp/busybox chmod"
|
||||
t2="/usr/bin/chmod"
|
||||
create() {
|
||||
rm -rf $1; mkdir $1
|
||||
(
|
||||
cd $1 || exit 1
|
||||
@@ -133,17 +136,16 @@ function create() {
|
||||
ln -s ../up dir/up
|
||||
)
|
||||
}
|
||||
function tst() {
|
||||
tst() {
|
||||
(cd test1; $t1 $1)
|
||||
(cd test2; $t2 $1)
|
||||
(cd test1; ls -lR) >out1
|
||||
(cd test2; ls -lR) >out2
|
||||
echo "chmod $1" >out.diff
|
||||
if ! diff -u out1 out2 >>out.diff; then exit 1; fi
|
||||
mv out.diff out1.diff
|
||||
rm out.diff
|
||||
}
|
||||
t1="/tmp/busybox chmod"
|
||||
t2="/usr/bin/chmod"
|
||||
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
||||
create test1; create test2
|
||||
tst "a+w file"
|
||||
tst "a-w dir"
|
||||
|
||||
+109
-45
@@ -7,44 +7,49 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
static struct bb_uidgid_t ugid = { -1, -1 };
|
||||
|
||||
static int (*chown_func)(const char *, uid_t, gid_t) = chown;
|
||||
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
|
||||
#define BIT_RECURSE 1
|
||||
#define OPT_RECURSE (option_mask32 & 1)
|
||||
#define OPT_NODEREF (option_mask32 & 2)
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 0x08) SKIP_DESKTOP(0))
|
||||
#define OPT_QUIET (USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0))
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcf"))
|
||||
|
||||
/* TODO:
|
||||
* -H if a command line argument is a symbolic link to a directory, traverse it
|
||||
/* POSIX options
|
||||
* -L traverse every symbolic link to a directory encountered
|
||||
* -H if a command line argument is a symbolic link to a directory, traverse it
|
||||
* -P do not traverse any symbolic links (default)
|
||||
*/
|
||||
* We do not conform to the following:
|
||||
* "Specifying more than one of -H, -L, and -P is not an error.
|
||||
* The last option specified shall determine the behavior of the utility." */
|
||||
/* -L */
|
||||
#define BIT_TRAVERSE 0x20
|
||||
#define OPT_TRAVERSE (USE_DESKTOP(option_mask32 & BIT_TRAVERSE) SKIP_DESKTOP(0))
|
||||
/* -H or -L */
|
||||
#define BIT_TRAVERSE_TOP (0x20|0x40)
|
||||
#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
|
||||
|
||||
typedef int (*chown_fptr)(const char *, uid_t, gid_t);
|
||||
|
||||
static struct bb_uidgid_t ugid = { -1, -1 };
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf,
|
||||
void ATTRIBUTE_UNUSED *junk, int depth)
|
||||
void *cf, int depth)
|
||||
{
|
||||
// TODO: -H/-L/-P
|
||||
// if (depth ... && S_ISLNK(statbuf->st_mode)) ....
|
||||
uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
|
||||
gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
|
||||
|
||||
if (!chown_func(fileName,
|
||||
(ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid,
|
||||
(ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid)
|
||||
) {
|
||||
if (!((chown_fptr)cf)(fileName, u, g)) {
|
||||
if (OPT_VERBOSE
|
||||
|| (OPT_CHANGED && (statbuf->st_uid != ugid.uid || statbuf->st_gid != ugid.gid))
|
||||
|| (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
|
||||
) {
|
||||
printf("changed ownership of '%s' to %u:%u\n",
|
||||
fileName, ugid.uid, ugid.gid);
|
||||
fileName, (unsigned)u, (unsigned)g);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -53,51 +58,110 @@ static int fileAction(const char *fileName, struct stat *statbuf,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chown_main(int argc, char **argv);
|
||||
int chown_main(int argc, char **argv)
|
||||
{
|
||||
char *groupName;
|
||||
int retval = EXIT_SUCCESS;
|
||||
chown_fptr chown_func;
|
||||
|
||||
opt_complementary = "-2";
|
||||
getopt32(argc, argv, OPT_STR);
|
||||
argv += optind;
|
||||
|
||||
if (OPT_NODEREF) chown_func = lchown;
|
||||
|
||||
/* First, check if there is a group name here */
|
||||
groupName = strchr(*argv, '.'); /* deprecated? */
|
||||
if (!groupName)
|
||||
groupName = strchr(*argv, ':');
|
||||
else
|
||||
*groupName = ':'; /* replace '.' with ':' */
|
||||
|
||||
/* First, try parsing "user[:[group]]" */
|
||||
if (!groupName) { /* "user" */
|
||||
ugid.uid = get_ug_id(*argv, xuname2uid);
|
||||
} else if (groupName == *argv) { /* ":group" */
|
||||
ugid.gid = get_ug_id(groupName + 1, xgroup2gid);
|
||||
} else {
|
||||
if (!groupName[1]) /* "user:" */
|
||||
*groupName = '\0';
|
||||
if (!get_uidgid(&ugid, *argv, 1))
|
||||
bb_error_msg_and_die("unknown user/group %s", *argv);
|
||||
/* This matches coreutils behavior (almost - see below) */
|
||||
chown_func = chown;
|
||||
if (OPT_NODEREF
|
||||
/* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
|
||||
USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
|
||||
) {
|
||||
chown_func = lchown;
|
||||
}
|
||||
|
||||
parse_chown_usergroup_or_die(&ugid, argv[0]);
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
argv++;
|
||||
do {
|
||||
if (!recursive_action(*argv,
|
||||
OPT_RECURSE, // recurse
|
||||
FALSE, // follow links: TODO: -H/-L/-P
|
||||
char *arg = *argv;
|
||||
|
||||
if (OPT_TRAVERSE_TOP) {
|
||||
/* resolves symlink (even recursive) */
|
||||
arg = xmalloc_realpath(arg);
|
||||
if (!arg)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!recursive_action(arg,
|
||||
OPT_RECURSE, // recurse
|
||||
OPT_TRAVERSE, // follow links if -L
|
||||
FALSE, // depth first
|
||||
fileAction, // file action
|
||||
fileAction, // dir action
|
||||
NULL, // user data
|
||||
chown_func, // user data
|
||||
0) // depth
|
||||
) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (OPT_TRAVERSE_TOP)
|
||||
free(arg);
|
||||
} while (*++argv);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
Testcase. Run in empty directory.
|
||||
|
||||
#!/bin/sh
|
||||
t1="/tmp/busybox chown"
|
||||
t2="/usr/bin/chown"
|
||||
create() {
|
||||
rm -rf $1; mkdir $1
|
||||
(
|
||||
cd $1 || exit 1
|
||||
mkdir dir dir2
|
||||
>up
|
||||
>file
|
||||
>dir/file
|
||||
>dir2/file
|
||||
ln -s dir linkdir
|
||||
ln -s file linkfile
|
||||
ln -s ../up dir/linkup
|
||||
ln -s ../dir2 dir/linkupdir2
|
||||
)
|
||||
chown -R 0:0 $1
|
||||
}
|
||||
tst() {
|
||||
create test1
|
||||
create test2
|
||||
(cd test1; $t1 $1)
|
||||
(cd test2; $t2 $1)
|
||||
(cd test1; ls -lnR) >out1
|
||||
(cd test2; ls -lnR) >out2
|
||||
echo "chown $1" >out.diff
|
||||
if ! diff -u out1 out2 >>out.diff; then exit 1; fi
|
||||
rm out.diff
|
||||
}
|
||||
tst_for_each() {
|
||||
tst "$1 1:1 file"
|
||||
tst "$1 1:1 dir"
|
||||
tst "$1 1:1 linkdir"
|
||||
tst "$1 1:1 linkfile"
|
||||
}
|
||||
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
||||
# These match coreutils 6.8:
|
||||
tst_for_each ""
|
||||
tst_for_each "-R"
|
||||
tst_for_each "-RP"
|
||||
tst_for_each "-RL"
|
||||
tst_for_each "-RH"
|
||||
tst_for_each "-h"
|
||||
tst_for_each "-hR"
|
||||
tst_for_each "-hRP"
|
||||
# Below: with "chown linkdir" coreutils 6.8 will chown linkdir _target_,
|
||||
# we lchown _the link_. I believe we are "more correct".
|
||||
#tst_for_each "-hRL"
|
||||
#tst_for_each "-hRH"
|
||||
|
||||
*/
|
||||
+2
-1
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int chroot_main(int argc, char **argv);
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
@@ -32,6 +33,6 @@ int chroot_main(int argc, char **argv)
|
||||
argv[1] = (char *) "-i";
|
||||
}
|
||||
|
||||
execvp(*argv, argv);
|
||||
BB_EXECVP(*argv, argv);
|
||||
bb_perror_msg_and_die("cannot execute %s", *argv);
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int cksum_main(int argc, char **argv);
|
||||
int cksum_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
|
||||
+29
-11
@@ -34,39 +34,53 @@ static FILE *cmp_xfopen_input(const char * const filename)
|
||||
}
|
||||
|
||||
static const char fmt_eof[] = "cmp: EOF on %s\n";
|
||||
static const char fmt_differ[] = "%s %s differ: char %d, line %d\n";
|
||||
// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%d %o %o\n"
|
||||
static const char fmt_l_opt[] = "%.0s%.0s%d %3o %3o\n";
|
||||
static const char fmt_differ[] = "%s %s differ: char %"OFF_FMT"d, line %d\n";
|
||||
// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"d %o %o\n"
|
||||
static const char fmt_l_opt[] = "%.0s%.0s%"OFF_FMT"d %3o %3o\n";
|
||||
|
||||
static const char opt_chars[] = "sl";
|
||||
#define CMP_OPT_s (1<<0)
|
||||
#define CMP_OPT_l (1<<1)
|
||||
|
||||
int cmp_main(int argc, char **argv);
|
||||
int cmp_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp1, *fp2, *outfile = stdout;
|
||||
const char *filename1, *filename2 = "-";
|
||||
USE_DESKTOP(off_t skip1 = 0, skip2 = 0;)
|
||||
off_t char_pos = 0;
|
||||
int line_pos = 1; /* Hopefully won't overflow... */
|
||||
const char *fmt;
|
||||
int c1, c2, char_pos = 0, line_pos = 1;
|
||||
int c1, c2;
|
||||
unsigned opt;
|
||||
int retval = 0;
|
||||
|
||||
xfunc_error_retval = 2; /* 1 is returned if files are different. */
|
||||
|
||||
opt_complementary = "?:-1"
|
||||
USE_DESKTOP(":?4")
|
||||
SKIP_DESKTOP(":?2")
|
||||
":l--s:s--l";
|
||||
opt = getopt32(argc, argv, opt_chars);
|
||||
argv += optind;
|
||||
|
||||
if (((opt & (CMP_OPT_s|CMP_OPT_l)) == (CMP_OPT_s|CMP_OPT_l))
|
||||
|| (((unsigned int)(--argc - optind)) > 1))
|
||||
bb_show_usage();
|
||||
|
||||
fp1 = cmp_xfopen_input(filename1 = *(argv += optind));
|
||||
filename1 = *argv;
|
||||
fp1 = cmp_xfopen_input(filename1);
|
||||
|
||||
if (*++argv) {
|
||||
filename2 = *argv;
|
||||
#if ENABLE_DESKTOP
|
||||
if (*++argv) {
|
||||
skip1 = XATOOFF(*argv);
|
||||
if (*++argv) {
|
||||
skip2 = XATOOFF(*argv);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
fp2 = cmp_xfopen_input(filename2);
|
||||
|
||||
if (fp1 == fp2) { /* Paranioa check... stdin == stdin? */
|
||||
fp2 = cmp_xfopen_input(filename2);
|
||||
if (fp1 == fp2) { /* Paranoia check... stdin == stdin? */
|
||||
/* Note that we don't bother reading stdin. Neither does gnu wc.
|
||||
* But perhaps we should, so that other apps down the chain don't
|
||||
* get the input. Consider 'echo hello | (cmp - - && cat -)'.
|
||||
@@ -79,6 +93,10 @@ int cmp_main(int argc, char **argv)
|
||||
else
|
||||
fmt = fmt_differ;
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
while (skip1) { getc(fp1); skip1--; }
|
||||
while (skip2) { getc(fp2); skip2--; }
|
||||
#endif
|
||||
do {
|
||||
c1 = getc(fp1);
|
||||
c2 = getc(fp2);
|
||||
|
||||
@@ -108,6 +108,7 @@ static void cmp_files(char **infiles)
|
||||
fclose(streams[1]);
|
||||
}
|
||||
|
||||
int comm_main(int argc, char **argv);
|
||||
int comm_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Mini cp implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
* SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
*
|
||||
* Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
@@ -17,6 +18,7 @@
|
||||
#include "busybox.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
|
||||
int cp_main(int argc, char **argv);
|
||||
int cp_main(int argc, char **argv)
|
||||
{
|
||||
struct stat source_stat;
|
||||
@@ -49,6 +51,12 @@ int cp_main(int argc, char **argv)
|
||||
if (flags & OPT_H) ... // deref command-line params only
|
||||
*/
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {
|
||||
selinux_or_die();
|
||||
}
|
||||
#endif
|
||||
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
|
||||
|
||||
if (optind + 2 > argc) {
|
||||
|
||||
@@ -162,6 +162,7 @@ static void cut_file(FILE * file)
|
||||
|
||||
static const char _op_on_field[] = " only when operating on fields";
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
char *sopt, *ltok;
|
||||
|
||||
+4
-9
@@ -32,18 +32,13 @@
|
||||
#define DATE_OPT_TIMESPEC 0x20
|
||||
#define DATE_OPT_HINT 0x40
|
||||
|
||||
static void xputenv(char *s)
|
||||
{
|
||||
if (putenv(s) != 0)
|
||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
||||
}
|
||||
|
||||
static void maybe_set_utc(int opt)
|
||||
{
|
||||
if (opt & DATE_OPT_UTC)
|
||||
xputenv("TZ=UTC0");
|
||||
putenv((char*)"TZ=UTC0");
|
||||
}
|
||||
|
||||
int date_main(int argc, char **argv);
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
time_t tm;
|
||||
@@ -218,7 +213,7 @@ format_utc:
|
||||
i = 22;
|
||||
goto format_utc;
|
||||
} else /* default case */
|
||||
date_fmt = "%a %b %e %H:%M:%S %Z %Y";
|
||||
date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
|
||||
if (*date_fmt == '\0') {
|
||||
@@ -228,7 +223,7 @@ format_utc:
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Generate output string */
|
||||
|
||||
@@ -50,6 +50,7 @@ static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
|
||||
#define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
int dd_main(int argc, char **argv);
|
||||
int dd_main(int argc, char **argv)
|
||||
{
|
||||
enum {
|
||||
|
||||
@@ -33,6 +33,7 @@ static long kscale(long b, long bs)
|
||||
}
|
||||
#endif
|
||||
|
||||
int df_main(int argc, char **argv);
|
||||
int df_main(int argc, char **argv)
|
||||
{
|
||||
long blocks_used;
|
||||
|
||||
+96
-113
@@ -65,18 +65,25 @@
|
||||
#define FLAG_U (1<<12)
|
||||
#define FLAG_w (1<<13)
|
||||
|
||||
/* XXX: FIXME: the following variables should be static, but gcc currently
|
||||
/* The following variables should be static, but gcc currently
|
||||
* creates a much bigger object if we do this. [which version of gcc? --vda] */
|
||||
/* 4.x, IIRC also 3.x --bernhard */
|
||||
/* Works for gcc 3.4.3. Sizes without and with "static":
|
||||
# size busybox.t[34]/coreutils/diff.o
|
||||
text data bss dec hex filename
|
||||
6969 8 305 7282 1c72 busybox.t3/coreutils/diff.o
|
||||
6969 8 305 7282 1c72 busybox.t4/coreutils/diff.o
|
||||
--vda
|
||||
*/
|
||||
/* This is the default number of lines of context. */
|
||||
int context = 3;
|
||||
int status;
|
||||
char *start;
|
||||
const char *label1;
|
||||
const char *label2;
|
||||
struct stat stb1, stb2;
|
||||
char **dl;
|
||||
USE_FEATURE_DIFF_DIR(int dl_count;)
|
||||
static int context = 3;
|
||||
static int status;
|
||||
static char *start;
|
||||
static const char *label1;
|
||||
static const char *label2;
|
||||
static struct stat stb1, stb2;
|
||||
USE_FEATURE_DIFF_DIR(static char **dl;)
|
||||
USE_FEATURE_DIFF_DIR(static int dl_count;)
|
||||
|
||||
struct cand {
|
||||
int x;
|
||||
@@ -84,7 +91,7 @@ struct cand {
|
||||
int pred;
|
||||
};
|
||||
|
||||
struct line {
|
||||
static struct line {
|
||||
int serial;
|
||||
int value;
|
||||
} *file[2];
|
||||
@@ -109,7 +116,7 @@ static int clen;
|
||||
static int len[2];
|
||||
static int pref, suff; /* length of prefix and suffix */
|
||||
static int slen[2];
|
||||
static smallint anychange;
|
||||
static bool anychange;
|
||||
static long *ixnew; /* will be overlaid on file[1] */
|
||||
static long *ixold; /* will be overlaid on klist */
|
||||
static struct cand *clist; /* merely a free storage pot for candidates */
|
||||
@@ -188,7 +195,7 @@ static int readhash(FILE * f)
|
||||
|
||||
sum = 1;
|
||||
space = 0;
|
||||
if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
|
||||
if (!(option_mask32 & (FLAG_b | FLAG_w))) {
|
||||
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||
if (t == EOF) {
|
||||
if (i == 0)
|
||||
@@ -241,19 +248,18 @@ static int files_differ(FILE * f1, FILE * f2, int flags)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size ||
|
||||
(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
|
||||
if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size
|
||||
|| (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
while (1) {
|
||||
i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1);
|
||||
j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2);
|
||||
if (i != j)
|
||||
return 1;
|
||||
if (i == 0 && j == 0) {
|
||||
if (ferror(f1) || ferror(f2))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
if (i == 0)
|
||||
return (ferror(f1) || ferror(f2));
|
||||
if (memcmp(bb_common_bufsiz1,
|
||||
bb_common_bufsiz1 + BUFSIZ/2, i) != 0)
|
||||
return 1;
|
||||
@@ -337,11 +343,11 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c)
|
||||
|
||||
static int isqrt(int n)
|
||||
{
|
||||
int y, x = 1;
|
||||
int y, x;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
x = 1;
|
||||
do {
|
||||
y = x;
|
||||
x = n / x;
|
||||
@@ -647,7 +653,6 @@ static void fetch(long *f, int a, int b, FILE * lb, int ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -828,66 +833,66 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
|
||||
}
|
||||
|
||||
/*
|
||||
* The following code uses an algorithm due to Harold Stone,
|
||||
* which finds a pair of longest identical subsequences in
|
||||
* the two files.
|
||||
* The following code uses an algorithm due to Harold Stone,
|
||||
* which finds a pair of longest identical subsequences in
|
||||
* the two files.
|
||||
*
|
||||
* The major goal is to generate the match vector J.
|
||||
* J[i] is the index of the line in file1 corresponding
|
||||
* to line i file0. J[i] = 0 if there is no
|
||||
* such line in file1.
|
||||
* The major goal is to generate the match vector J.
|
||||
* J[i] is the index of the line in file1 corresponding
|
||||
* to line i file0. J[i] = 0 if there is no
|
||||
* such line in file1.
|
||||
*
|
||||
* Lines are hashed so as to work in core. All potential
|
||||
* matches are located by sorting the lines of each file
|
||||
* on the hash (called ``value''). In particular, this
|
||||
* collects the equivalence classes in file1 together.
|
||||
* Subroutine equiv replaces the value of each line in
|
||||
* file0 by the index of the first element of its
|
||||
* matching equivalence in (the reordered) file1.
|
||||
* To save space equiv squeezes file1 into a single
|
||||
* array member in which the equivalence classes
|
||||
* are simply concatenated, except that their first
|
||||
* members are flagged by changing sign.
|
||||
* Lines are hashed so as to work in core. All potential
|
||||
* matches are located by sorting the lines of each file
|
||||
* on the hash (called ``value''). In particular, this
|
||||
* collects the equivalence classes in file1 together.
|
||||
* Subroutine equiv replaces the value of each line in
|
||||
* file0 by the index of the first element of its
|
||||
* matching equivalence in (the reordered) file1.
|
||||
* To save space equiv squeezes file1 into a single
|
||||
* array member in which the equivalence classes
|
||||
* are simply concatenated, except that their first
|
||||
* members are flagged by changing sign.
|
||||
*
|
||||
* Next the indices that point into member are unsorted into
|
||||
* array class according to the original order of file0.
|
||||
* Next the indices that point into member are unsorted into
|
||||
* array class according to the original order of file0.
|
||||
*
|
||||
* The cleverness lies in routine stone. This marches
|
||||
* through the lines of file0, developing a vector klist
|
||||
* of "k-candidates". At step i a k-candidate is a matched
|
||||
* pair of lines x,y (x in file0 y in file1) such that
|
||||
* there is a common subsequence of length k
|
||||
* between the first i lines of file0 and the first y
|
||||
* lines of file1, but there is no such subsequence for
|
||||
* any smaller y. x is the earliest possible mate to y
|
||||
* that occurs in such a subsequence.
|
||||
* The cleverness lies in routine stone. This marches
|
||||
* through the lines of file0, developing a vector klist
|
||||
* of "k-candidates". At step i a k-candidate is a matched
|
||||
* pair of lines x,y (x in file0 y in file1) such that
|
||||
* there is a common subsequence of length k
|
||||
* between the first i lines of file0 and the first y
|
||||
* lines of file1, but there is no such subsequence for
|
||||
* any smaller y. x is the earliest possible mate to y
|
||||
* that occurs in such a subsequence.
|
||||
*
|
||||
* Whenever any of the members of the equivalence class of
|
||||
* lines in file1 matable to a line in file0 has serial number
|
||||
* less than the y of some k-candidate, that k-candidate
|
||||
* with the smallest such y is replaced. The new
|
||||
* k-candidate is chained (via pred) to the current
|
||||
* k-1 candidate so that the actual subsequence can
|
||||
* be recovered. When a member has serial number greater
|
||||
* that the y of all k-candidates, the klist is extended.
|
||||
* At the end, the longest subsequence is pulled out
|
||||
* and placed in the array J by unravel
|
||||
* Whenever any of the members of the equivalence class of
|
||||
* lines in file1 matable to a line in file0 has serial number
|
||||
* less than the y of some k-candidate, that k-candidate
|
||||
* with the smallest such y is replaced. The new
|
||||
* k-candidate is chained (via pred) to the current
|
||||
* k-1 candidate so that the actual subsequence can
|
||||
* be recovered. When a member has serial number greater
|
||||
* that the y of all k-candidates, the klist is extended.
|
||||
* At the end, the longest subsequence is pulled out
|
||||
* and placed in the array J by unravel
|
||||
*
|
||||
* With J in hand, the matches there recorded are
|
||||
* checked against reality to assure that no spurious
|
||||
* matches have crept in due to hashing. If they have,
|
||||
* they are broken, and "jackpot" is recorded--a harmless
|
||||
* matter except that a true match for a spuriously
|
||||
* mated line may now be unnecessarily reported as a change.
|
||||
* With J in hand, the matches there recorded are
|
||||
* checked against reality to assure that no spurious
|
||||
* matches have crept in due to hashing. If they have,
|
||||
* they are broken, and "jackpot" is recorded--a harmless
|
||||
* matter except that a true match for a spuriously
|
||||
* mated line may now be unnecessarily reported as a change.
|
||||
*
|
||||
* Much of the complexity of the program comes simply
|
||||
* from trying to minimize core utilization and
|
||||
* maximize the range of doable problems by dynamically
|
||||
* allocating what is needed and reusing what is not.
|
||||
* The core requirements for problems larger than somewhat
|
||||
* are (in words) 2*length(file0) + length(file1) +
|
||||
* 3*(number of k-candidates installed), typically about
|
||||
* 6n words for files of length n.
|
||||
* Much of the complexity of the program comes simply
|
||||
* from trying to minimize core utilization and
|
||||
* maximize the range of doable problems by dynamically
|
||||
* allocating what is needed and reusing what is not.
|
||||
* The core requirements for problems larger than somewhat
|
||||
* are (in words) 2*length(file0) + length(file1) +
|
||||
* 3*(number of k-candidates installed), typically about
|
||||
* 6n words for files of length n.
|
||||
*/
|
||||
static unsigned diffreg(char * ofile1, char * ofile2, int flags)
|
||||
{
|
||||
@@ -1044,15 +1049,10 @@ static int add_to_dirlist(const char *filename,
|
||||
struct stat ATTRIBUTE_UNUSED * sb, void *userdata,
|
||||
int depth ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* +2: with space for eventual trailing NULL */
|
||||
dl = xrealloc(dl, (dl_count+2) * sizeof(dl[0]));
|
||||
dl[dl_count] = xstrdup(filename + (int)(ptrdiff_t)userdata);
|
||||
dl_count++;
|
||||
dl = xrealloc(dl, dl_count * sizeof(char *));
|
||||
dl[dl_count - 1] = xstrdup(filename);
|
||||
if (option_mask32 & FLAG_r) {
|
||||
int *pp = (int *) userdata;
|
||||
int path_len = *pp + 1;
|
||||
|
||||
dl[dl_count - 1] = &(dl[dl_count - 1])[path_len];
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1060,27 +1060,19 @@ static int add_to_dirlist(const char *filename,
|
||||
/* This returns a sorted directory listing. */
|
||||
static char **get_dir(char *path)
|
||||
{
|
||||
int i;
|
||||
char **retval;
|
||||
dl_count = 0;
|
||||
dl = NULL;
|
||||
|
||||
/* If -r has been set, then the recursive_action function will be
|
||||
* used. Unfortunately, this outputs the root directory along with
|
||||
* the recursed paths, so use void *userdata to specify the string
|
||||
* length of the root directory. It can then be removed in
|
||||
* add_to_dirlist. */
|
||||
* length of the root directory - '(void*)(strlen(path)+)'.
|
||||
* add_to_dirlist then removes root dir prefix. */
|
||||
|
||||
int path_len = strlen(path);
|
||||
void *userdata = &path_len;
|
||||
|
||||
/* Reset dl_count - there's no need to free dl as xrealloc does
|
||||
* the job nicely. */
|
||||
dl_count = 0;
|
||||
|
||||
/* Now fill dl with a listing. */
|
||||
if (option_mask32 & FLAG_r)
|
||||
if (option_mask32 & FLAG_r) {
|
||||
recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL,
|
||||
userdata, 0);
|
||||
else {
|
||||
(void*)(strlen(path)+1), 0);
|
||||
} else {
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
|
||||
@@ -1088,7 +1080,7 @@ static char **get_dir(char *path)
|
||||
while ((ep = readdir(dp))) {
|
||||
if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.'))
|
||||
continue;
|
||||
add_to_dirlist(ep->d_name, NULL, NULL, 0);
|
||||
add_to_dirlist(ep->d_name, NULL, (void*)(int)0, 0);
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
@@ -1096,12 +1088,8 @@ static char **get_dir(char *path)
|
||||
/* Sort dl alphabetically. */
|
||||
qsort(dl, dl_count, sizeof(char *), dir_strcmp);
|
||||
|
||||
/* Copy dl so that we can return it. */
|
||||
retval = xmalloc(dl_count * sizeof(char *));
|
||||
for (i = 0; i < dl_count; i++)
|
||||
retval[i] = xstrdup(dl[i]);
|
||||
|
||||
return retval;
|
||||
dl[dl_count] = NULL;
|
||||
return dl;
|
||||
}
|
||||
|
||||
|
||||
@@ -1109,11 +1097,9 @@ static void diffdir(char *p1, char *p2)
|
||||
{
|
||||
char **dirlist1, **dirlist2;
|
||||
char *dp1, *dp2;
|
||||
int dirlist1_count, dirlist2_count;
|
||||
int pos;
|
||||
|
||||
/* Check for trailing slashes. */
|
||||
|
||||
dp1 = last_char_is(p1, '/');
|
||||
if (dp1 != NULL)
|
||||
*dp1 = '\0';
|
||||
@@ -1124,11 +1110,7 @@ static void diffdir(char *p1, char *p2)
|
||||
/* Get directory listings for p1 and p2. */
|
||||
|
||||
dirlist1 = get_dir(p1);
|
||||
dirlist1_count = dl_count;
|
||||
dirlist1[dirlist1_count] = NULL;
|
||||
dirlist2 = get_dir(p2);
|
||||
dirlist2_count = dl_count;
|
||||
dirlist2[dirlist2_count] = NULL;
|
||||
|
||||
/* If -S was set, find the starting point. */
|
||||
if (start) {
|
||||
@@ -1170,9 +1152,10 @@ static void diffdir(char *p1, char *p2)
|
||||
#endif
|
||||
|
||||
|
||||
int diff_main(int argc, char **argv);
|
||||
int diff_main(int argc, char **argv)
|
||||
{
|
||||
smallint gotstdin = 0;
|
||||
bool gotstdin = 0;
|
||||
char *U_opt;
|
||||
char *f1, *f2;
|
||||
llist_t *L_arg = NULL;
|
||||
@@ -1197,7 +1180,7 @@ int diff_main(int argc, char **argv)
|
||||
L_arg = L_arg->link;
|
||||
}
|
||||
if (option_mask32 & FLAG_U)
|
||||
context = xatou_range(U_opt, 1, INT_MAX);
|
||||
context = xatoi_u(U_opt);
|
||||
|
||||
/*
|
||||
* Do sanity checks, fill in stb1 and stb2 and call the appropriate
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int dirname_main(int argc, char **argv);
|
||||
int dirname_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
|
||||
@@ -82,6 +82,7 @@ static int convert(char *fn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char *argv[]);
|
||||
int dos2unix_main(int argc, char *argv[])
|
||||
{
|
||||
int o;
|
||||
|
||||
+3
-2
@@ -101,7 +101,7 @@ static long du(const char * const filename)
|
||||
|
||||
if (statbuf.st_nlink > count_hardlinks) {
|
||||
/* Add files/directories with links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
if (is_in_ino_dev_hashtable(&statbuf)) {
|
||||
return 0;
|
||||
}
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
@@ -143,6 +143,7 @@ static long du(const char * const filename)
|
||||
return sum;
|
||||
}
|
||||
|
||||
int du_main(int argc, char **argv);
|
||||
int du_main(int argc, char **argv)
|
||||
{
|
||||
long total;
|
||||
@@ -222,7 +223,7 @@ int du_main(int argc, char **argv)
|
||||
/* go through remaining args (if any) */
|
||||
argv += optind;
|
||||
if (optind >= argc) {
|
||||
*--argv = ".";
|
||||
*--argv = (char*)".";
|
||||
if (slink_depth == 1) {
|
||||
slink_depth = 0;
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ just_echo:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int echo_main(int argc, char** argv);
|
||||
int echo_main(int argc, char** argv)
|
||||
{
|
||||
(void)bb_echo(argv);
|
||||
|
||||
+7
-8
@@ -41,10 +41,11 @@ static const struct option env_long_options[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
int env_main(int argc, char** argv);
|
||||
int env_main(int argc, char** argv)
|
||||
{
|
||||
static char *cleanenv[1] = { NULL };
|
||||
|
||||
/* cleanenv was static - why? */
|
||||
char *cleanenv[1];
|
||||
char **ep;
|
||||
unsigned opt;
|
||||
llist_t *unset_env = NULL;
|
||||
@@ -54,18 +55,16 @@ int env_main(int argc, char** argv)
|
||||
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
|
||||
applet_long_options = env_long_options;
|
||||
#endif
|
||||
|
||||
opt = getopt32(argc, argv, "+iu:", &unset_env);
|
||||
|
||||
argv += optind;
|
||||
if (*argv && LONE_DASH(argv[0])) {
|
||||
opt |= 1;
|
||||
++argv;
|
||||
}
|
||||
|
||||
if (opt & 1)
|
||||
if (opt & 1) {
|
||||
cleanenv[0] = NULL;
|
||||
environ = cleanenv;
|
||||
else if (opt & 2) {
|
||||
} else if (opt & 2) {
|
||||
while (unset_env) {
|
||||
unsetenv(unset_env->data);
|
||||
unset_env = unset_env->link;
|
||||
@@ -80,7 +79,7 @@ int env_main(int argc, char** argv)
|
||||
}
|
||||
|
||||
if (*argv) {
|
||||
execvp(*argv, argv);
|
||||
BB_EXECVP(*argv, argv);
|
||||
/* SUSv3-mandated exit codes. */
|
||||
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
|
||||
bb_perror_msg_and_die("%s", *argv);
|
||||
|
||||
+13
-12
@@ -67,13 +67,14 @@ static char **args;
|
||||
static VALUE *docolon(VALUE * sv, VALUE * pv);
|
||||
static VALUE *eval(void);
|
||||
static VALUE *int_value(arith_t i);
|
||||
static VALUE *str_value(char *s);
|
||||
static int nextarg(char *str);
|
||||
static VALUE *str_value(const char *s);
|
||||
static int nextarg(const char *str);
|
||||
static int null(VALUE * v);
|
||||
static int toarith(VALUE * v);
|
||||
static void freev(VALUE * v);
|
||||
static void tostring(VALUE * v);
|
||||
|
||||
int expr_main(int argc, char **argv);
|
||||
int expr_main(int argc, char **argv)
|
||||
{
|
||||
VALUE *v;
|
||||
@@ -110,7 +111,7 @@ static VALUE *int_value(arith_t i)
|
||||
|
||||
/* Return a VALUE for S. */
|
||||
|
||||
static VALUE *str_value(char *s)
|
||||
static VALUE *str_value(const char *s)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
@@ -135,8 +136,8 @@ static int null(VALUE * v)
|
||||
{
|
||||
if (v->type == integer)
|
||||
return v->u.i == 0;
|
||||
else /* string: */
|
||||
return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
|
||||
/* string: */
|
||||
return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
|
||||
}
|
||||
|
||||
/* Coerce V to a string value (can't fail). */
|
||||
@@ -172,7 +173,7 @@ static int toarith(VALUE * v)
|
||||
/* Return nonzero if the next token matches STR exactly.
|
||||
STR must not be NULL. */
|
||||
|
||||
static int nextarg(char *str)
|
||||
static int nextarg(const char *str)
|
||||
{
|
||||
if (*args == NULL)
|
||||
return 0;
|
||||
@@ -193,16 +194,16 @@ static int cmp_common(VALUE * l, VALUE * r, int op)
|
||||
cmpval = l->u.i - r->u.i;
|
||||
if (op == '<')
|
||||
return cmpval < 0;
|
||||
else if (op == ('L' + 'E'))
|
||||
if (op == ('L' + 'E'))
|
||||
return cmpval <= 0;
|
||||
else if (op == '=')
|
||||
if (op == '=')
|
||||
return cmpval == 0;
|
||||
else if (op == '!')
|
||||
if (op == '!')
|
||||
return cmpval != 0;
|
||||
else if (op == '>')
|
||||
if (op == '>')
|
||||
return cmpval > 0;
|
||||
else /* >= */
|
||||
return cmpval >= 0;
|
||||
/* >= */
|
||||
return cmpval >= 0;
|
||||
}
|
||||
|
||||
/* The arithmetic operator handling functions. */
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv);
|
||||
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
|
||||
+2
-1
@@ -38,6 +38,7 @@ static int adjust_column(int column, char c)
|
||||
return column;
|
||||
}
|
||||
|
||||
int fold_main(int argc, char **argv);
|
||||
int fold_main(int argc, char **argv)
|
||||
{
|
||||
char *w_opt;
|
||||
@@ -66,7 +67,7 @@ int fold_main(int argc, char **argv)
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
*--argv = "-";
|
||||
*--argv = (char*)"-";
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
+2
-1
@@ -31,6 +31,7 @@ static const struct suffix_mult head_suffixes[] = {
|
||||
|
||||
static const char header_fmt_str[] = "\n==> %s <==\n";
|
||||
|
||||
int head_main(int argc, char **argv);
|
||||
int head_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long count = 10;
|
||||
@@ -92,7 +93,7 @@ int head_main(int argc, char **argv)
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
*--argv = "-";
|
||||
*--argv = (char*)"-";
|
||||
}
|
||||
|
||||
fmt = header_fmt_str + 1;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv);
|
||||
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
|
||||
+32
-10
@@ -10,6 +10,7 @@
|
||||
/* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */
|
||||
/* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to
|
||||
* be more similar to GNU id.
|
||||
* -Z option support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
@@ -17,14 +18,13 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef CONFIG_SELINUX
|
||||
#include <selinux/selinux.h> /* for is_selinux_enabled() */
|
||||
#endif
|
||||
|
||||
#define PRINT_REAL 1
|
||||
#define NAME_NOT_NUMBER 2
|
||||
#define JUST_USER 4
|
||||
#define JUST_GROUP 8
|
||||
#if ENABLE_SELINUX
|
||||
#define JUST_CONTEXT 16
|
||||
#endif
|
||||
|
||||
static short printf_full(unsigned int id, const char *arg, const char prefix)
|
||||
{
|
||||
@@ -39,6 +39,7 @@ static short printf_full(unsigned int id, const char *arg, const char prefix)
|
||||
return status;
|
||||
}
|
||||
|
||||
int id_main(int argc, char **argv);
|
||||
int id_main(int argc, char **argv)
|
||||
{
|
||||
struct passwd *p;
|
||||
@@ -46,11 +47,13 @@ int id_main(int argc, char **argv)
|
||||
gid_t gid;
|
||||
unsigned long flags;
|
||||
short status;
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
/* Don't allow -n -r -nr -ug -rug -nug -rnug */
|
||||
/* Don't allow more than one username */
|
||||
opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug";
|
||||
flags = getopt32(argc, argv, "rnug");
|
||||
opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
|
||||
flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z"));
|
||||
|
||||
/* This values could be overwritten later */
|
||||
uid = geteuid();
|
||||
@@ -68,14 +71,33 @@ int id_main(int argc, char **argv)
|
||||
/* in this case PRINT_REAL is the same */
|
||||
}
|
||||
|
||||
if (flags & (JUST_GROUP | JUST_USER)) {
|
||||
if (flags & (JUST_GROUP | JUST_USER USE_SELINUX(| JUST_CONTEXT))) {
|
||||
/* JUST_GROUP and JUST_USER are mutually exclusive */
|
||||
if (flags & NAME_NOT_NUMBER) {
|
||||
/* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */
|
||||
puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 ));
|
||||
} else {
|
||||
printf("%u\n", (flags & JUST_USER) ? uid : gid);
|
||||
if (flags & JUST_USER) {
|
||||
printf("%u\n", uid);
|
||||
}
|
||||
if (flags & JUST_GROUP) {
|
||||
printf("%u\n", gid);
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & JUST_CONTEXT) {
|
||||
selinux_or_die();
|
||||
if (argc - optind == 1) {
|
||||
bb_error_msg_and_die("user name can't be passed with -Z");
|
||||
}
|
||||
|
||||
if (getcon(&scontext)) {
|
||||
bb_error_msg_and_die("can't get process context");
|
||||
}
|
||||
printf("%s\n", scontext);
|
||||
}
|
||||
#endif
|
||||
/* exit */
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -87,7 +109,7 @@ int id_main(int argc, char **argv)
|
||||
/* bb_getgrgid doesn't exit on failure here */
|
||||
status |= printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g');
|
||||
|
||||
#ifdef CONFIG_SELINUX
|
||||
#if ENABLE_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
security_context_t mysid;
|
||||
const char *context;
|
||||
|
||||
+72
-7
@@ -1,6 +1,7 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
|
||||
* SELinux support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
@@ -21,10 +22,50 @@ static const struct option install_long_options[] = {
|
||||
{ "group", 0, NULL, 'g' },
|
||||
{ "mode", 0, NULL, 'm' },
|
||||
{ "owner", 0, NULL, 'o' },
|
||||
#if ENABLE_SELINUX
|
||||
{ "context", 1, NULL, 'Z' },
|
||||
{ "preserve_context", 0, NULL, 0xff },
|
||||
{ "preserve-context", 0, NULL, 0xff },
|
||||
#endif
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
static bool use_default_selinux_context = 1;
|
||||
|
||||
static void setdefaultfilecon(const char *path) {
|
||||
struct stat s;
|
||||
security_context_t scontext = NULL;
|
||||
|
||||
if (!is_selinux_enabled()) {
|
||||
return;
|
||||
}
|
||||
if (lstat(path, &s) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchpathcon(path, s.st_mode, &scontext) < 0) {
|
||||
goto out;
|
||||
}
|
||||
if (strcmp(scontext, "<<none>>") == 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (lsetfilecon(path, scontext) < 0) {
|
||||
if (errno != ENOTSUP) {
|
||||
bb_perror_msg("warning: failed to change context of %s to %s", path, scontext);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
freecon(scontext);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int install_main(int argc, char **argv);
|
||||
int install_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
@@ -36,7 +77,9 @@ int install_main(int argc, char **argv)
|
||||
const char *mode_str;
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int ret = EXIT_SUCCESS, flags, i, isdir;
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
enum {
|
||||
OPT_CMD = 0x1,
|
||||
OPT_DIRECTORY = 0x2,
|
||||
@@ -45,14 +88,33 @@ int install_main(int argc, char **argv)
|
||||
OPT_GROUP = 0x10,
|
||||
OPT_MODE = 0x20,
|
||||
OPT_OWNER = 0x40,
|
||||
#if ENABLE_SELINUX
|
||||
OPT_SET_SECURITY_CONTEXT = 0x80,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 0x100,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_long_options;
|
||||
#endif
|
||||
opt_complementary = "?:s--d:d--s";
|
||||
/* -c exists for backwards compatibility, its needed */
|
||||
flags = getopt32(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str);
|
||||
opt_complementary = "?:s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
|
||||
flags = getopt32(argc, argv, "cdpsg:m:o:" USE_SELINUX("Z:"), &gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext));
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & OPT_PRESERVE_SECURITY_CONTEXT) {
|
||||
use_default_selinux_context = 0;
|
||||
copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
|
||||
selinux_or_die();
|
||||
}
|
||||
if (flags & OPT_SET_SECURITY_CONTEXT) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
use_default_selinux_context = 0;
|
||||
copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
|
||||
if (flags & OPT_PRESERVE_TIME) {
|
||||
@@ -116,7 +178,10 @@ int install_main(int argc, char **argv)
|
||||
bb_perror_msg("cannot change permissions of %s", dest);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (use_default_selinux_context)
|
||||
setdefaultfilecon(dest);
|
||||
#endif
|
||||
/* Set the user and group id */
|
||||
if ((flags & (OPT_OWNER|OPT_GROUP))
|
||||
&& lchown(dest, uid, gid) == -1
|
||||
@@ -125,7 +190,7 @@ int install_main(int argc, char **argv)
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
if (flags & OPT_STRIP) {
|
||||
if (execlp("strip", "strip", dest, NULL) == -1) {
|
||||
if (BB_EXECLP("strip", "strip", dest, NULL) == -1) {
|
||||
bb_perror_msg("strip");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int length_main(int argc, char **argv);
|
||||
int length_main(int argc, char **argv)
|
||||
{
|
||||
if ((argc != 2) || (**(++argv) == '-')) {
|
||||
|
||||
@@ -30,11 +30,22 @@ mode_t getopt_mk_fifo_nod(int argc, char **argv)
|
||||
{
|
||||
mode_t mode = 0666;
|
||||
char *smode = NULL;
|
||||
|
||||
getopt32(argc, argv, "m:", &smode);
|
||||
if(smode) {
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
int opt;
|
||||
opt = getopt32(argc, argv, "m:" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
if (bb_parse_mode(smode, &mode))
|
||||
umask(0);
|
||||
}
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 2) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
#endif
|
||||
|
||||
return mode;
|
||||
}
|
||||
+2
-1
@@ -19,6 +19,7 @@
|
||||
#define LN_BACKUP 8
|
||||
#define LN_SUFFIX 16
|
||||
|
||||
int ln_main(int argc, char **argv);
|
||||
int ln_main(int argc, char **argv)
|
||||
{
|
||||
int status = EXIT_SUCCESS;
|
||||
@@ -26,7 +27,7 @@ int ln_main(int argc, char **argv)
|
||||
char *last;
|
||||
char *src_name;
|
||||
char *src;
|
||||
char *suffix = "~";
|
||||
char *suffix = (char*)"~";
|
||||
struct stat statbuf;
|
||||
int (*link_func)(const char *, const char *);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv);
|
||||
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
+20
-12
@@ -156,13 +156,13 @@ enum {
|
||||
|
||||
static int status = EXIT_SUCCESS;
|
||||
|
||||
static struct dnode *my_stat(char *fullname, char *name)
|
||||
static struct dnode *my_stat(char *fullname, char *name, int force_follow)
|
||||
{
|
||||
struct stat dstat;
|
||||
struct dnode *cur;
|
||||
USE_SELINUX(security_context_t sid = NULL;)
|
||||
|
||||
if (all_fmt & FOLLOW_LINKS) {
|
||||
if ((all_fmt & FOLLOW_LINKS) || force_follow) {
|
||||
#if ENABLE_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
getfilecon(fullname, &sid);
|
||||
@@ -176,7 +176,7 @@ static struct dnode *my_stat(char *fullname, char *name)
|
||||
} else {
|
||||
#if ENABLE_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
lgetfilecon(fullname,&sid);
|
||||
lgetfilecon(fullname, &sid);
|
||||
}
|
||||
#endif
|
||||
if (lstat(fullname, &dstat)) {
|
||||
@@ -510,7 +510,7 @@ static struct dnode **list_dir(const char *path)
|
||||
continue;
|
||||
}
|
||||
fullname = concat_path_file(path, entry->d_name);
|
||||
cur = my_stat(fullname, strrchr(fullname, '/') + 1);
|
||||
cur = my_stat(fullname, strrchr(fullname, '/') + 1, 0);
|
||||
if (!cur) {
|
||||
free(fullname);
|
||||
continue;
|
||||
@@ -664,7 +664,7 @@ static int list_single(struct dnode *dn)
|
||||
break;
|
||||
case LIST_SYMLINK:
|
||||
if (S_ISLNK(dn->dstat.st_mode)) {
|
||||
char *lpath = xreadlink(dn->fullname);
|
||||
char *lpath = xmalloc_readlink_or_warn(dn->fullname);
|
||||
if (!lpath) break;
|
||||
printf(" -> ");
|
||||
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
|
||||
@@ -716,7 +716,8 @@ static const char ls_options[] = "Cadil1gnsxAk"
|
||||
USE_FEATURE_LS_RECURSIVE("R")
|
||||
USE_FEATURE_HUMAN_READABLE("h")
|
||||
USE_SELINUX("K")
|
||||
USE_FEATURE_AUTOWIDTH("T:w:");
|
||||
USE_FEATURE_AUTOWIDTH("T:w:")
|
||||
USE_SELINUX("Z");
|
||||
|
||||
enum {
|
||||
LIST_MASK_TRIGGER = 0,
|
||||
@@ -768,11 +769,18 @@ static const unsigned opt_flags[] = {
|
||||
#endif
|
||||
#if ENABLE_FEATURE_AUTOWIDTH
|
||||
0, 0, /* T, w - ignored */
|
||||
#endif
|
||||
#if ENABLE_SELINUX
|
||||
LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT, /* Z */
|
||||
#endif
|
||||
(1U<<31)
|
||||
};
|
||||
|
||||
|
||||
/* THIS IS A "SAFE" APPLET, main() MAY BE CALLED INTERNALLY FROM SHELL */
|
||||
/* BE CAREFUL! */
|
||||
|
||||
int ls_main(int argc, char **argv);
|
||||
int ls_main(int argc, char **argv)
|
||||
{
|
||||
struct dnode **dnd;
|
||||
@@ -792,8 +800,6 @@ int ls_main(int argc, char **argv)
|
||||
USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;)
|
||||
USE_FEATURE_LS_COLOR(char *color_opt;)
|
||||
|
||||
setvbuf(stdout, bb_common_bufsiz1, _IOFBF, BUFSIZ);
|
||||
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
time(¤t_time_t);
|
||||
#endif
|
||||
@@ -818,7 +824,7 @@ int ls_main(int argc, char **argv)
|
||||
if (terminal_width_str)
|
||||
terminal_width = xatou(terminal_width_str);
|
||||
#else
|
||||
opt = getopt32(argc, argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt));
|
||||
opt = getopt32(argc, argv, ls_options USE_FEATURE_LS_COLOR(, &color_opt));
|
||||
#endif
|
||||
for (i = 0; opt_flags[i] != (1U<<31); i++) {
|
||||
if (opt & (1 << i)) {
|
||||
@@ -836,8 +842,9 @@ int ls_main(int argc, char **argv)
|
||||
all_fmt &= ~TIME_MASK;
|
||||
if (flags & LIST_CONTEXT)
|
||||
all_fmt |= STYLE_SINGLE;
|
||||
if (LS_DISP_HR && opt == 'l')
|
||||
all_fmt &= ~LS_DISP_HR;
|
||||
/* huh?? opt cannot be 'l' */
|
||||
//if (LS_DISP_HR && opt == 'l')
|
||||
// all_fmt &= ~LS_DISP_HR;
|
||||
all_fmt |= flags;
|
||||
}
|
||||
}
|
||||
@@ -903,7 +910,8 @@ int ls_main(int argc, char **argv)
|
||||
/* stuff the command line file names into a dnode array */
|
||||
dn = NULL;
|
||||
for (oi = 0; oi < ac; oi++) {
|
||||
cur = my_stat(av[oi], av[oi]);
|
||||
/* ls w/o -l follows links on command line */
|
||||
cur = my_stat(av[oi], av[oi], !(all_fmt & STYLE_LONG));
|
||||
if (!cur)
|
||||
continue;
|
||||
cur->allocated = 0;
|
||||
|
||||
@@ -78,6 +78,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
|
||||
return hash_value;
|
||||
}
|
||||
|
||||
int md5_sha1_sum_main(int argc, char **argv);
|
||||
int md5_sha1_sum_main(int argc, char **argv)
|
||||
{
|
||||
int return_value = EXIT_SUCCESS;
|
||||
@@ -102,7 +103,7 @@ int md5_sha1_sum_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (argc == optind) {
|
||||
argv[argc++] = "-";
|
||||
argv[argc++] = (char*)"-";
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
|
||||
|
||||
+17
-1
@@ -16,6 +16,9 @@
|
||||
* conjunction with -m.
|
||||
*/
|
||||
|
||||
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h> /* struct option */
|
||||
@@ -25,10 +28,14 @@
|
||||
static const struct option mkdir_long_options[] = {
|
||||
{ "mode", 1, NULL, 'm' },
|
||||
{ "parents", 0, NULL, 'p' },
|
||||
#if ENABLE_SELINUX
|
||||
{ "context", 1, NULL, 'Z' },
|
||||
#endif
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
int mkdir_main(int argc, char **argv);
|
||||
int mkdir_main(int argc, char **argv)
|
||||
{
|
||||
mode_t mode = (mode_t)(-1);
|
||||
@@ -36,11 +43,14 @@ int mkdir_main(int argc, char **argv)
|
||||
int flags = 0;
|
||||
unsigned opt;
|
||||
char *smode;
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
||||
applet_long_options = mkdir_long_options;
|
||||
#endif
|
||||
opt = getopt32(argc, argv, "m:p", &smode);
|
||||
opt = getopt32(argc, argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode = 0777;
|
||||
if (!bb_parse_mode(smode, &mode)) {
|
||||
@@ -49,6 +59,12 @@ int mkdir_main(int argc, char **argv)
|
||||
}
|
||||
if (opt & 2)
|
||||
flags |= FILEUTILS_RECUR;
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 4) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (optind == argc) {
|
||||
bb_show_usage();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "busybox.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
|
||||
int mkfifo_main(int argc, char **argv);
|
||||
int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
mode_t mode;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
static const char modes_chars[] = { 'p', 'c', 'u', 'b', 0, 1, 1, 2 };
|
||||
static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK };
|
||||
|
||||
int mknod_main(int argc, char **argv);
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
mode_t mode;
|
||||
|
||||
+8
-2
@@ -3,6 +3,7 @@
|
||||
* Mini mv implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
* SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
@@ -35,6 +36,7 @@ static const struct option mv_long_options[] = {
|
||||
|
||||
static const char fmt[] = "cannot overwrite %sdirectory with %sdirectory";
|
||||
|
||||
int mv_main(int argc, char **argv);
|
||||
int mv_main(int argc, char **argv)
|
||||
{
|
||||
struct stat dest_stat;
|
||||
@@ -43,6 +45,7 @@ int mv_main(int argc, char **argv)
|
||||
unsigned long flags;
|
||||
int dest_exists;
|
||||
int status = 0;
|
||||
int copy_flag = 0;
|
||||
|
||||
#if ENABLE_FEATURE_MV_LONG_OPTIONS
|
||||
applet_long_options = mv_long_options;
|
||||
@@ -112,8 +115,11 @@ DO_MOVE:
|
||||
goto RET_1;
|
||||
}
|
||||
}
|
||||
if ((copy_file(*argv, dest,
|
||||
FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) &&
|
||||
copy_flag = FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS;
|
||||
#if ENABLE_SELINUX
|
||||
copy_flag |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
|
||||
#endif
|
||||
if ((copy_file(*argv, dest, copy_flag) >= 0) &&
|
||||
(remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) {
|
||||
goto RET_0;
|
||||
}
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@
|
||||
#include <sys/resource.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int nice_main(int argc, char **argv);
|
||||
int nice_main(int argc, char **argv)
|
||||
{
|
||||
int old_priority, adjustment;
|
||||
@@ -46,7 +47,7 @@ int nice_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
execvp(*argv, argv); /* Now exec the desired program. */
|
||||
BB_EXECVP(*argv, argv); /* Now exec the desired program. */
|
||||
|
||||
/* The exec failed... */
|
||||
xfunc_error_retval = (errno == ENOENT) ? 127 : 126; /* SUSv3 */
|
||||
|
||||
+19
-12
@@ -12,18 +12,21 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int nohup_main(int argc, char **argv);
|
||||
int nohup_main(int argc, char **argv)
|
||||
{
|
||||
int temp, nullfd;
|
||||
char *nohupout, *home = NULL;
|
||||
int nullfd;
|
||||
const char *nohupout;
|
||||
char *home = NULL;
|
||||
|
||||
xfunc_error_retval = 127;
|
||||
|
||||
if (argc<2) bb_show_usage();
|
||||
if (argc < 2) bb_show_usage();
|
||||
|
||||
nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
|
||||
/* If stdin is a tty, detach from it. */
|
||||
if (isatty(STDIN_FILENO)) dup2(nullfd, STDIN_FILENO);
|
||||
if (isatty(STDIN_FILENO))
|
||||
dup2(nullfd, STDIN_FILENO);
|
||||
|
||||
nohupout = "nohup.out";
|
||||
/* Redirect stdout to nohup.out, either in "." or in "$HOME". */
|
||||
@@ -38,16 +41,20 @@ int nohup_main(int argc, char **argv)
|
||||
}
|
||||
} else dup2(nullfd, STDOUT_FILENO);
|
||||
|
||||
/* If we have a tty on strderr, announce filename and redirect to stdout.
|
||||
/* If we have a tty on stderr, announce filename and redirect to stdout.
|
||||
* Else redirect to /dev/null.
|
||||
*/
|
||||
temp = isatty(STDERR_FILENO);
|
||||
if (temp) bb_error_msg("appending to %s", nohupout);
|
||||
dup2(temp ? STDOUT_FILENO : nullfd, STDERR_FILENO);
|
||||
close(nullfd);
|
||||
signal (SIGHUP, SIG_IGN);
|
||||
if (isatty(STDERR_FILENO)) {
|
||||
bb_error_msg("appending to %s", nohupout);
|
||||
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||
} else dup2(nullfd, STDERR_FILENO);
|
||||
|
||||
execvp(argv[1],argv+1);
|
||||
if (00 && ENABLE_FEATURE_CLEAN_UP && home) free(nohupout);
|
||||
if (nullfd > 2)
|
||||
close(nullfd);
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
|
||||
BB_EXECVP(argv[1], argv+1);
|
||||
if (ENABLE_FEATURE_CLEAN_UP && home)
|
||||
free((char*)nohupout);
|
||||
bb_perror_msg_and_die("%s", argv[1]);
|
||||
}
|
||||
+3
-2
@@ -12,13 +12,13 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "busybox.h"
|
||||
#if ENABLE_DESKTOP
|
||||
/* This one provides -t (busybox's own build script needs it) */
|
||||
#include "od_bloaty.c"
|
||||
#else
|
||||
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#include "dump.h"
|
||||
|
||||
#define isdecdigit(c) isdigit(c)
|
||||
@@ -156,6 +156,7 @@ static const char od_o2si[] = {
|
||||
0xb, 1, 8, 9,
|
||||
};
|
||||
|
||||
int od_main(int argc, char **argv);
|
||||
int od_main(int argc, char **argv)
|
||||
{
|
||||
int ch;
|
||||
|
||||
@@ -542,7 +542,7 @@ check_and_close(void)
|
||||
fmt = SIGNED_DECIMAL;
|
||||
size = INT or LONG; (whichever integral_type_size[4] resolves to)
|
||||
print_function = print_int; (assuming size == INT)
|
||||
fmt_string = "%011d%c";
|
||||
fmt_string = "%011d%c";
|
||||
}
|
||||
S_ORIG is solely for reporting errors. It should be the full format
|
||||
string argument. */
|
||||
@@ -823,7 +823,7 @@ skip(off_t n_skip)
|
||||
n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream);
|
||||
n_skip -= n_bytes_read;
|
||||
if (n_bytes_read != n_bytes_to_read)
|
||||
break; /* EOF on this file or error */
|
||||
break; /* EOF on this file or error */
|
||||
}
|
||||
}
|
||||
if (n_skip == 0)
|
||||
@@ -1207,8 +1207,8 @@ dump_strings(void)
|
||||
check_and_close();
|
||||
}
|
||||
|
||||
int
|
||||
od_main(int argc, char **argv)
|
||||
int od_main(int argc, char **argv);
|
||||
int od_main(int argc, char **argv)
|
||||
{
|
||||
static const struct suffix_mult bkm[] = {
|
||||
{ "b", 512 },
|
||||
@@ -1312,7 +1312,7 @@ od_main(int argc, char **argv)
|
||||
if (opt & OPT_l) decode_format_string("d4");
|
||||
if (opt & OPT_o) decode_format_string("o2");
|
||||
//if (opt & OPT_t)...
|
||||
lst_t = rev_llist(lst_t);
|
||||
lst_t = llist_rev(lst_t);
|
||||
while (lst_t) {
|
||||
decode_format_string(lst_t->data);
|
||||
lst_t = lst_t->link;
|
||||
@@ -1334,7 +1334,7 @@ od_main(int argc, char **argv)
|
||||
/* If the --traditional option is used, there may be from
|
||||
* 0 to 3 remaining command line arguments; handle each case
|
||||
* separately.
|
||||
* od [file] [[+]offset[.][b] [[+]label[.][b]]]
|
||||
* od [file] [[+]offset[.][b] [[+]label[.][b]]]
|
||||
* The offset and pseudo_start have the same syntax.
|
||||
*
|
||||
* FIXME: POSIX 1003.1-2001 with XSI requires support for the
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int printenv_main(int argc, char **argv);
|
||||
int printenv_main(int argc, char **argv)
|
||||
{
|
||||
extern char **environ;
|
||||
|
||||
+115
-123
@@ -40,33 +40,31 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
static int print_formatted(char *format, int argc, char **argv);
|
||||
static void print_direc(char *start, size_t length,
|
||||
int field_width, int precision, char *argument);
|
||||
typedef void (*converter)(const char *arg, void *result);
|
||||
|
||||
typedef void (*converter)(char *arg, void *result);
|
||||
|
||||
static void multiconvert(char *arg, void *result, converter convert)
|
||||
static void multiconvert(const char *arg, void *result, converter convert)
|
||||
{
|
||||
char s[16];
|
||||
char s[sizeof(int)*3 + 2];
|
||||
|
||||
if (*arg == '"' || *arg == '\'') {
|
||||
sprintf(s, "%d", (unsigned char)arg[1]);
|
||||
arg = s;
|
||||
}
|
||||
convert(arg, result);
|
||||
if (errno) /* Huh, looks strange... bug? */
|
||||
/* if there was conversion error, print unconverted string */
|
||||
if (errno)
|
||||
fputs(arg, stderr);
|
||||
}
|
||||
|
||||
static void conv_strtoul(char *arg, void *result)
|
||||
static void conv_strtoul(const char *arg, void *result)
|
||||
{
|
||||
*(unsigned long*)result = bb_strtoul(arg, NULL, 10);
|
||||
*(unsigned long*)result = bb_strtoul(arg, NULL, 0);
|
||||
}
|
||||
static void conv_strtol(char *arg, void *result)
|
||||
static void conv_strtol(const char *arg, void *result)
|
||||
{
|
||||
*(long*)result = bb_strtol(arg, NULL, 10);
|
||||
*(long*)result = bb_strtol(arg, NULL, 0);
|
||||
}
|
||||
static void conv_strtod(char *arg, void *result)
|
||||
static void conv_strtod(const char *arg, void *result)
|
||||
{
|
||||
char *end;
|
||||
/* Well, this one allows leading whitespace... so what */
|
||||
@@ -75,21 +73,21 @@ static void conv_strtod(char *arg, void *result)
|
||||
if (end[0]) errno = ERANGE;
|
||||
}
|
||||
|
||||
static unsigned long my_xstrtoul(char *arg)
|
||||
static unsigned long my_xstrtoul(const char *arg)
|
||||
{
|
||||
unsigned long result;
|
||||
multiconvert(arg, &result, conv_strtoul);
|
||||
return result;
|
||||
}
|
||||
|
||||
static long my_xstrtol(char *arg)
|
||||
static long my_xstrtol(const char *arg)
|
||||
{
|
||||
long result;
|
||||
multiconvert(arg, &result, conv_strtol);
|
||||
return result;
|
||||
}
|
||||
|
||||
static double my_xstrtod(char *arg)
|
||||
static double my_xstrtod(const char *arg)
|
||||
{
|
||||
double result;
|
||||
multiconvert(arg, &result, conv_strtod);
|
||||
@@ -109,31 +107,82 @@ static void print_esc_string(char *str)
|
||||
}
|
||||
}
|
||||
|
||||
int printf_main(int argc, char **argv)
|
||||
static void print_direc(char *start, size_t length, int field_width, int precision,
|
||||
const char *argument)
|
||||
{
|
||||
char *format;
|
||||
int args_used;
|
||||
char *p; /* Null-terminated copy of % directive. */
|
||||
|
||||
if (argc <= 1 || argv[1][0] == '-') {
|
||||
bb_show_usage();
|
||||
p = xmalloc((unsigned) (length + 1));
|
||||
strncpy(p, start, length);
|
||||
p[length] = 0;
|
||||
|
||||
switch (p[length - 1]) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, my_xstrtol(argument));
|
||||
else
|
||||
printf(p, precision, my_xstrtol(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, my_xstrtol(argument));
|
||||
else
|
||||
printf(p, field_width, precision, my_xstrtol(argument));
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, my_xstrtoul(argument));
|
||||
else
|
||||
printf(p, precision, my_xstrtoul(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, my_xstrtoul(argument));
|
||||
else
|
||||
printf(p, field_width, precision, my_xstrtoul(argument));
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, my_xstrtod(argument));
|
||||
else
|
||||
printf(p, precision, my_xstrtod(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, my_xstrtod(argument));
|
||||
else
|
||||
printf(p, field_width, precision, my_xstrtod(argument));
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
printf(p, *argument);
|
||||
break;
|
||||
case 's':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, argument);
|
||||
else
|
||||
printf(p, precision, argument);
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, argument);
|
||||
else
|
||||
printf(p, field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
format = argv[1];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
do {
|
||||
args_used = print_formatted(format, argc, argv);
|
||||
argc -= args_used;
|
||||
argv += args_used;
|
||||
}
|
||||
while (args_used > 0 && argc > 0);
|
||||
|
||||
/* if (argc > 0)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
free(p);
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
@@ -142,12 +191,12 @@ int printf_main(int argc, char **argv)
|
||||
|
||||
static int print_formatted(char *format, int argc, char **argv)
|
||||
{
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
char *f; /* Pointer into 'format'. */
|
||||
char *direc_start; /* Start of % directive. */
|
||||
size_t direc_length; /* Length of % directive. */
|
||||
int field_width; /* Arg to first '*', or -1 if none. */
|
||||
int precision; /* Arg to second '*', or -1 if none. */
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
char *f; /* Pointer into 'format'. */
|
||||
char *direc_start; /* Start of % directive. */
|
||||
size_t direc_length; /* Length of % directive. */
|
||||
int field_width; /* Arg to first '*', or -1 if none. */
|
||||
int precision; /* Arg to second '*', or -1 if none. */
|
||||
|
||||
for (f = format; *f; ++f) {
|
||||
switch (*f) {
|
||||
@@ -180,11 +229,12 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
--argc;
|
||||
} else
|
||||
field_width = 0;
|
||||
} else
|
||||
} else {
|
||||
while (isdigit(*f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
if (*f == '.') {
|
||||
++f;
|
||||
++direc_length;
|
||||
@@ -221,14 +271,12 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
print_direc(direc_start, direc_length, field_width,
|
||||
precision, "");
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
if (*++f == 'c')
|
||||
exit(0);
|
||||
putchar(bb_process_escape_sequence((const char **)&f));
|
||||
f--;
|
||||
break;
|
||||
|
||||
default:
|
||||
putchar(*f);
|
||||
}
|
||||
@@ -237,85 +285,29 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
return save_argc - argc;
|
||||
}
|
||||
|
||||
static void
|
||||
print_direc(char *start, size_t length, int field_width, int precision,
|
||||
char *argument)
|
||||
int printf_main(int argc, char **argv);
|
||||
int printf_main(int argc, char **argv)
|
||||
{
|
||||
char *p; /* Null-terminated copy of % directive. */
|
||||
char *format;
|
||||
int args_used;
|
||||
|
||||
p = xmalloc((unsigned) (length + 1));
|
||||
strncpy(p, start, length);
|
||||
p[length] = 0;
|
||||
|
||||
switch (p[length - 1]) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, my_xstrtol(argument));
|
||||
else
|
||||
printf(p, precision, my_xstrtol(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, my_xstrtol(argument));
|
||||
else
|
||||
printf(p, field_width, precision, my_xstrtol(argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, my_xstrtoul(argument));
|
||||
else
|
||||
printf(p, precision, my_xstrtoul(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, my_xstrtoul(argument));
|
||||
else
|
||||
printf(p, field_width, precision, my_xstrtoul(argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, my_xstrtod(argument));
|
||||
else
|
||||
printf(p, precision, my_xstrtod(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, my_xstrtod(argument));
|
||||
else
|
||||
printf(p, field_width, precision, my_xstrtod(argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf(p, *argument);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, argument);
|
||||
else
|
||||
printf(p, precision, argument);
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, argument);
|
||||
else
|
||||
printf(p, field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
if (argc <= 1 || argv[1][0] == '-') {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
free(p);
|
||||
format = argv[1];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
do {
|
||||
args_used = print_formatted(format, argc, argv);
|
||||
argc -= args_used;
|
||||
argv += args_used;
|
||||
} while (args_used > 0 && argc > 0);
|
||||
|
||||
/* if (argc > 0)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+3
-1
@@ -11,11 +11,13 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int pwd_main(int argc, char **argv);
|
||||
int pwd_main(int argc, char **argv)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
if ((buf = xgetcwd(NULL)) != NULL) {
|
||||
buf = xrealloc_getcwd_or_warn(NULL);
|
||||
if (buf != NULL) {
|
||||
puts(buf);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int realpath_main(int argc, char **argv);
|
||||
int realpath_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int rm_main(int argc, char **argv);
|
||||
int rm_main(int argc, char **argv)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <libgen.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int rmdir_main(int argc, char **argv);
|
||||
int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
int status = EXIT_SUCCESS;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int seq_main(int argc, char **argv);
|
||||
int seq_main(int argc, char **argv)
|
||||
{
|
||||
double last, first, increment, i;
|
||||
|
||||
@@ -33,6 +33,7 @@ static const struct suffix_mult sfx[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
int sleep_main(int argc, char **argv);
|
||||
int sleep_main(int argc, char **argv)
|
||||
{
|
||||
unsigned int duration;
|
||||
|
||||
+11
-4
@@ -271,11 +271,13 @@ static unsigned str2u(char **str)
|
||||
}
|
||||
#endif
|
||||
|
||||
int sort_main(int argc, char **argv);
|
||||
int sort_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp, *outfile = stdout;
|
||||
char *line, **lines = NULL;
|
||||
char *str_ignored, *str_o, *str_k, *str_t;
|
||||
char *str_ignored, *str_o, *str_t;
|
||||
llist_t *lst_k = NULL;
|
||||
int i, flag;
|
||||
int linecount = 0;
|
||||
|
||||
@@ -283,8 +285,9 @@ int sort_main(int argc, char **argv)
|
||||
|
||||
/* Parse command line options */
|
||||
/* -o and -t can be given at most once */
|
||||
opt_complementary = "?:o--o:t--t";
|
||||
getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &str_k, &str_t);
|
||||
opt_complementary = "?:o--o:t--t:" /* -t, -o: maximum one of each */
|
||||
"k::"; /* -k takes list */
|
||||
getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
|
||||
#if ENABLE_FEATURE_SORT_BIG
|
||||
if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w");
|
||||
if (option_mask32 & FLAG_t) {
|
||||
@@ -293,7 +296,8 @@ int sort_main(int argc, char **argv)
|
||||
key_separator = str_t[0];
|
||||
}
|
||||
/* parse sort key */
|
||||
if (option_mask32 & FLAG_k) {
|
||||
lst_k = llist_rev(lst_k);
|
||||
while (lst_k) {
|
||||
enum {
|
||||
FLAG_allowed_for_k =
|
||||
FLAG_n | /* Numeric sort */
|
||||
@@ -307,6 +311,7 @@ int sort_main(int argc, char **argv)
|
||||
0
|
||||
};
|
||||
struct sort_key *key = add_key();
|
||||
char *str_k = lst_k->data;
|
||||
const char *temp2;
|
||||
|
||||
i = 0; /* i==0 before comma, 1 after (-k3,6) */
|
||||
@@ -336,6 +341,8 @@ int sort_main(int argc, char **argv)
|
||||
str_k++;
|
||||
}
|
||||
}
|
||||
/* leaking lst_k... */
|
||||
lst_k = lst_k->link;
|
||||
}
|
||||
#endif
|
||||
/* global b strips leading and trailing spaces */
|
||||
|
||||
+156
-18
@@ -5,6 +5,7 @@
|
||||
* Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation.
|
||||
* Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
|
||||
* Copyright (C) 2006 by Yoshinori Sato <ysato@users.sourceforge.jp>
|
||||
*
|
||||
* Written by Michael Meskes
|
||||
* Taken from coreutils and turned into a busybox applet by Mike Frysinger
|
||||
@@ -17,6 +18,7 @@
|
||||
/* vars to control behavior */
|
||||
#define OPT_TERSE 2
|
||||
#define OPT_DEREFERENCE 4
|
||||
#define OPT_SELINUX 8
|
||||
static long flags;
|
||||
|
||||
static char const *file_type(struct stat const *st)
|
||||
@@ -114,7 +116,8 @@ static char const *human_fstype(long f_type)
|
||||
#ifdef CONFIG_FEATURE_STAT_FORMAT
|
||||
/* print statfs info */
|
||||
static void print_statfs(char *pformat, size_t buf_len, char m,
|
||||
char const *filename, void const *data)
|
||||
char const *filename, void const *data
|
||||
USE_SELINUX(,security_context_t scontext) )
|
||||
{
|
||||
struct statfs const *statfsbuf = data;
|
||||
|
||||
@@ -164,6 +167,14 @@ static void print_statfs(char *pformat, size_t buf_len, char m,
|
||||
strncat(pformat, "jd", buf_len);
|
||||
printf(pformat, (intmax_t) (statfsbuf->f_ffree));
|
||||
break;
|
||||
#if ENABLE_SELINUX
|
||||
case 'C':
|
||||
if (flags & OPT_SELINUX) {
|
||||
strncat(pformat, "s", buf_len);
|
||||
printf(scontext);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
strncat(pformat, "c", buf_len);
|
||||
printf(pformat, m);
|
||||
@@ -173,7 +184,8 @@ static void print_statfs(char *pformat, size_t buf_len, char m,
|
||||
|
||||
/* print stat info */
|
||||
static void print_stat(char *pformat, size_t buf_len, char m,
|
||||
char const *filename, void const *data)
|
||||
char const *filename, void const *data
|
||||
USE_SELINUX(, security_context_t scontext))
|
||||
{
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
struct stat *statbuf = (struct stat *) data;
|
||||
@@ -188,7 +200,7 @@ static void print_stat(char *pformat, size_t buf_len, char m,
|
||||
case 'N':
|
||||
strncat(pformat, "s", buf_len);
|
||||
if (S_ISLNK(statbuf->st_mode)) {
|
||||
char *linkname = xreadlink(filename);
|
||||
char *linkname = xmalloc_readlink_or_warn(filename);
|
||||
if (linkname == NULL) {
|
||||
bb_perror_msg("cannot read symbolic link '%s'", filename);
|
||||
return;
|
||||
@@ -301,6 +313,14 @@ static void print_stat(char *pformat, size_t buf_len, char m,
|
||||
strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len);
|
||||
printf(pformat, (unsigned long int) statbuf->st_ctime);
|
||||
break;
|
||||
#if ENABLE_SELINUX
|
||||
case 'C':
|
||||
if (flags & OPT_SELINUX) {
|
||||
strncat(pformat, "s", buf_len);
|
||||
printf(pformat, scontext);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
strncat(pformat, "c", buf_len);
|
||||
printf(pformat, m);
|
||||
@@ -309,8 +329,9 @@ static void print_stat(char *pformat, size_t buf_len, char m,
|
||||
}
|
||||
|
||||
static void print_it(char const *masterformat, char const *filename,
|
||||
void (*print_func) (char *, size_t, char, char const *, void const *),
|
||||
void const *data)
|
||||
void (*print_func) (char *, size_t, char, char const *, void const *
|
||||
USE_SELINUX(, security_context_t scontext)),
|
||||
void const *data USE_SELINUX(, security_context_t scontext) )
|
||||
{
|
||||
char *b;
|
||||
|
||||
@@ -350,7 +371,7 @@ static void print_it(char const *masterformat, char const *filename,
|
||||
putchar('%');
|
||||
break;
|
||||
default:
|
||||
print_func(dest, n_alloc, *p, filename, data);
|
||||
print_func(dest, n_alloc, *p, filename, data USE_SELINUX(,scontext));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -365,6 +386,16 @@ static int do_statfs(char const *filename, char const *format)
|
||||
{
|
||||
struct statfs statfsbuf;
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext = NULL;
|
||||
if (flags & OPT_SELINUX) {
|
||||
if ((flags & OPT_DEREFERENCE ? lgetfilecon(filename, scontext):
|
||||
getfilecon(filename, scontext))< 0) {
|
||||
bb_perror_msg(filename);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (statfs(filename, &statfsbuf) != 0) {
|
||||
bb_perror_msg("cannot read file system information for '%s'", filename);
|
||||
return 0;
|
||||
@@ -372,6 +403,7 @@ static int do_statfs(char const *filename, char const *format)
|
||||
|
||||
#ifdef CONFIG_FEATURE_STAT_FORMAT
|
||||
if (format == NULL)
|
||||
#ifndef ENABLE_SELINUX
|
||||
format = (flags & OPT_TERSE
|
||||
? "%n %i %l %t %s %b %f %a %c %d\n"
|
||||
: " File: \"%n\"\n"
|
||||
@@ -379,9 +411,27 @@ static int do_statfs(char const *filename, char const *format)
|
||||
"Block size: %-10s\n"
|
||||
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
|
||||
"Inodes: Total: %-10c Free: %d");
|
||||
print_it(format, filename, print_statfs, &statfsbuf);
|
||||
print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext));
|
||||
#else
|
||||
|
||||
format = (flags & OPT_TERSE
|
||||
? (flags & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n":
|
||||
"%n %i %l %t %s %b %f %a %c %d\n")
|
||||
: (flags & OPT_SELINUX ?
|
||||
" File: \"%n\"\n"
|
||||
" ID: %-8i Namelen: %-7l Type: %T\n"
|
||||
"Block size: %-10s\n"
|
||||
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
|
||||
"Inodes: Total: %-10c Free: %d"
|
||||
" S_context: %C\n":
|
||||
" File: \"%n\"\n"
|
||||
" ID: %-8i Namelen: %-7l Type: %T\n"
|
||||
"Block size: %-10s\n"
|
||||
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
|
||||
"Inodes: Total: %-10c Free: %d\n")
|
||||
);
|
||||
print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext));
|
||||
#endif /* SELINUX */
|
||||
#else /* FEATURE_STAT_FORMAT */
|
||||
format = (flags & OPT_TERSE
|
||||
? "%s %llx %lu "
|
||||
: " File: \"%s\"\n"
|
||||
@@ -396,6 +446,7 @@ static int do_statfs(char const *filename, char const *format)
|
||||
else
|
||||
printf("Type: %s\n", human_fstype(statfsbuf.f_type));
|
||||
|
||||
#if !ENABLE_SELINUX
|
||||
format = (flags & OPT_TERSE
|
||||
? "%lu %ld %ld %ld %ld %ld\n"
|
||||
: "Block size: %-10lu\n"
|
||||
@@ -408,8 +459,31 @@ static int do_statfs(char const *filename, char const *format)
|
||||
(intmax_t) (statfsbuf.f_bavail),
|
||||
(intmax_t) (statfsbuf.f_files),
|
||||
(intmax_t) (statfsbuf.f_ffree));
|
||||
#endif
|
||||
#else
|
||||
format = (flags & OPT_TERSE
|
||||
? (flags & OPT_SELINUX ? "%lu %ld %ld %ld %ld %ld %C\n":
|
||||
"%lu %ld %ld %ld %ld %ld\n")
|
||||
: (flags & OPT_SELINUX ?
|
||||
"Block size: %-10lu\n"
|
||||
"Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
|
||||
"Inodes: Total: %-10jd Free: %jd"
|
||||
"S_context: %C\n":
|
||||
"Block size: %-10lu\n"
|
||||
"Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
|
||||
"Inodes: Total: %-10jd Free: %jd\n"));
|
||||
printf(format,
|
||||
(unsigned long int) (statfsbuf.f_bsize),
|
||||
(intmax_t) (statfsbuf.f_blocks),
|
||||
(intmax_t) (statfsbuf.f_bfree),
|
||||
(intmax_t) (statfsbuf.f_bavail),
|
||||
(intmax_t) (statfsbuf.f_files),
|
||||
(intmax_t) (statfsbuf.f_ffree),
|
||||
scontext);
|
||||
|
||||
if (scontext)
|
||||
freecon(scontext);
|
||||
#endif
|
||||
#endif /* FEATURE_STAT_FORMAT */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -417,7 +491,16 @@ static int do_statfs(char const *filename, char const *format)
|
||||
static int do_stat(char const *filename, char const *format)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext = NULL;
|
||||
if (flags & OPT_SELINUX) {
|
||||
if ((flags & OPT_DEREFERENCE ? lgetfilecon(filename, scontext):
|
||||
getfilecon(filename, scontext))< 0) {
|
||||
bb_perror_msg (filename);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if ((flags & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) {
|
||||
bb_perror_msg("cannot stat '%s'", filename);
|
||||
return 0;
|
||||
@@ -425,6 +508,7 @@ static int do_stat(char const *filename, char const *format)
|
||||
|
||||
#ifdef CONFIG_FEATURE_STAT_FORMAT
|
||||
if (format == NULL) {
|
||||
#ifndef ENABLE_SELINUX
|
||||
if (flags & OPT_TERSE) {
|
||||
format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
|
||||
} else {
|
||||
@@ -445,11 +529,49 @@ static int do_stat(char const *filename, char const *format)
|
||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
print_it(format, filename, print_stat, &statbuf);
|
||||
#else
|
||||
if (flags & OPT_TERSE) {
|
||||
format = (flags & OPT_SELINUX ?
|
||||
"%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n":
|
||||
"%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n");
|
||||
} else {
|
||||
if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
|
||||
format = (flags & OPT_SELINUX ?
|
||||
" File: \"%N\"\n"
|
||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
||||
" Device type: %t,%T\n"
|
||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||
" S_Context: %C\n"
|
||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n":
|
||||
" File: \"%N\"\n"
|
||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
|
||||
" Device type: %t,%T\n"
|
||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n");
|
||||
} else {
|
||||
format = (flags & OPT_SELINUX ?
|
||||
" File: \"%N\"\n"
|
||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||
"S_Context: %C\n"
|
||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n":
|
||||
" File: \"%N\"\n"
|
||||
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
|
||||
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
|
||||
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
|
||||
"Access: %x\n" "Modify: %y\n" "Change: %z\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
print_it(format, filename, print_stat, &statbuf USE_SELINUX(, scontext));
|
||||
#else /* FEATURE_STAT_FORMAT */
|
||||
if (flags & OPT_TERSE) {
|
||||
printf("%s %ju %ju %lx %lu %lu %jx %ju %lu %lx %lx %lu %lu %lu %lu\n",
|
||||
printf("%s %ju %ju %lx %lu %lu %jx %ju %lu %lx %lx %lu %lu %lu %lu"
|
||||
SKIP_SELINUX("\n"),
|
||||
filename,
|
||||
(uintmax_t) (statbuf.st_size),
|
||||
(uintmax_t) statbuf.st_blocks,
|
||||
@@ -466,6 +588,12 @@ static int do_stat(char const *filename, char const *format)
|
||||
(unsigned long int) statbuf.st_ctime,
|
||||
(unsigned long int) statbuf.st_blksize
|
||||
);
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & OPT_SELINUX)
|
||||
printf(" %lc\n", *scontext);
|
||||
else
|
||||
putchar('\n');
|
||||
#endif
|
||||
} else {
|
||||
char *linkname = NULL;
|
||||
|
||||
@@ -477,7 +605,7 @@ static int do_stat(char const *filename, char const *format)
|
||||
pw_ent = getpwuid(statbuf.st_uid);
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode))
|
||||
linkname = xreadlink(filename);
|
||||
linkname = xmalloc_readlink_or_warn(filename);
|
||||
if (linkname)
|
||||
printf(" File: \"%s\" -> \"%s\"\n", filename, linkname);
|
||||
else
|
||||
@@ -499,22 +627,26 @@ static int do_stat(char const *filename, char const *format)
|
||||
(unsigned long int) minor(statbuf.st_rdev));
|
||||
else
|
||||
putchar('\n');
|
||||
printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n"
|
||||
"Access: %s\n" "Modify: %s\n" "Change: %s\n",
|
||||
printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n",
|
||||
(unsigned long int) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
|
||||
bb_mode_string(statbuf.st_mode),
|
||||
(unsigned long int) statbuf.st_uid,
|
||||
(pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN",
|
||||
(unsigned long int) statbuf.st_gid,
|
||||
(gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN",
|
||||
(gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN");
|
||||
#if ENABLE_SELINUX
|
||||
printf(" S_Context: %lc\n", *scontext);
|
||||
#endif
|
||||
printf("Access: %s\n" "Modify: %s\n" "Change: %s\n",
|
||||
human_time(statbuf.st_atime),
|
||||
human_time(statbuf.st_mtime),
|
||||
human_time(statbuf.st_ctime));
|
||||
}
|
||||
#endif
|
||||
#endif /* FEATURE_STAT_FORMAT */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int stat_main(int argc, char **argv);
|
||||
int stat_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
@@ -523,6 +655,7 @@ int stat_main(int argc, char **argv)
|
||||
int (*statfunc)(char const *, char const *) = do_stat;
|
||||
|
||||
flags = getopt32(argc, argv, "ftL"
|
||||
USE_SELINUX("Z")
|
||||
USE_FEATURE_STAT_FORMAT("c:", &format)
|
||||
);
|
||||
|
||||
@@ -531,6 +664,11 @@ int stat_main(int argc, char **argv)
|
||||
if (argc == optind) /* files */
|
||||
bb_show_usage();
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & OPT_SELINUX) {
|
||||
selinux_or_die();
|
||||
}
|
||||
#endif /* ENABLE_SELINUX */
|
||||
for (i = optind; i < argc; ++i)
|
||||
ok &= statfunc(argv[i], format);
|
||||
|
||||
|
||||
Loaded 100 of 418 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user