Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b7f6928c6 | ||
|
|
a2af67a8c5 | ||
|
|
d0119d15f9 | ||
|
|
8d42f86b14 |
No files matched your search
@@ -231,14 +231,6 @@ 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"
|
||||
@@ -352,25 +344,16 @@ config DEBUG
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
config DEBUG_PESSIMIZE
|
||||
bool "Disable compiler optimizations."
|
||||
default n
|
||||
depends on DEBUG
|
||||
help
|
||||
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.
|
||||
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"
|
||||
@@ -414,14 +397,14 @@ config EFENCE
|
||||
|
||||
endchoice
|
||||
|
||||
config INCLUDE_SUSv2
|
||||
bool "Enable obsolete features removed before SUSv3?"
|
||||
config DEBUG_YANK_SUSv2
|
||||
bool "Disable obsolete features removed before SUSv3?"
|
||||
default y
|
||||
help
|
||||
This option will enable backwards compatibility with SuSv2,
|
||||
This option will disable backwards compatibility with SuSv2,
|
||||
specifically, old-style numeric options ('command -1 <file>')
|
||||
will be supported in head, tail, and fold. (Note: should
|
||||
affect renice too.)
|
||||
will not be supported in head, tail, and fold. (Note: should
|
||||
yank from renice too.)
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -435,30 +418,31 @@ 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 "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.
|
||||
bool
|
||||
prompt "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL
|
||||
help
|
||||
Do not install applets links. Usefull when using the -install feature
|
||||
or a standalone shell for rescue pruposes.
|
||||
|
||||
endchoice
|
||||
|
||||
@@ -493,4 +477,3 @@ 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 CONFIG_PREFIX=/path/from/root install
|
||||
make install # or make 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 CONFIG_PREFIX=. install
|
||||
make PREFIX=. install
|
||||
|
||||
More Information:
|
||||
=================
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 5
|
||||
PATCHLEVEL = 3
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
@@ -71,7 +71,7 @@ endif
|
||||
# In both cases the working directory must be the root of the kernel src.
|
||||
# 1) O=
|
||||
# Use "make O=dir/to/store/output/files/"
|
||||
#
|
||||
#
|
||||
# 2) Set KBUILD_OUTPUT
|
||||
# Set the environment variable KBUILD_OUTPUT to point to the directory
|
||||
# where the output files shall be placed.
|
||||
@@ -145,7 +145,7 @@ export srctree objtree VPATH TOPDIR
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
# first, and if a usermode build is happening, the "ARCH=um" on the command
|
||||
# line overrides the setting of ARCH below. If a native build is happening,
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
@@ -229,7 +229,7 @@ export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
|
||||
# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
|
||||
#
|
||||
# If $(quiet) is empty, the whole command will be printed.
|
||||
# If it is set to "quiet_", only the short version will be printed.
|
||||
# If it is set to "quiet_", only the short version will be printed.
|
||||
# If it is set to "silent_", nothing wil be printed at all, since
|
||||
# the variable $(silent_cmd_cc_o_c) doesn't exist.
|
||||
#
|
||||
@@ -273,8 +273,8 @@ MAKEFLAGS += -rR
|
||||
# Make variables (CC, etc...)
|
||||
|
||||
AS = $(CROSS_COMPILE)as
|
||||
LD = $(CROSS_COMPILE)ld
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
LD = $(CC) -nostdlib
|
||||
CPP = $(CC) -E
|
||||
AR = $(CROSS_COMPILE)ar
|
||||
NM = $(CROSS_COMPILE)nm
|
||||
@@ -299,11 +299,9 @@ AFLAGS_KERNEL =
|
||||
|
||||
# Use LINUXINCLUDE when you must reference the include/ directory.
|
||||
# Needed to be compatible with the O= option
|
||||
CFLAGS := $(CFLAGS)
|
||||
CPPFLAGS := $(CPPFLAGS)
|
||||
AFLAGS := $(AFLAGS)
|
||||
LDFLAGS := $(LDFLAGS)
|
||||
LDLIBS :=
|
||||
CFLAGS :=
|
||||
CPPFLAGS :=
|
||||
AFLAGS :=
|
||||
|
||||
# Read KERNELRELEASE from .kernelrelease (if it exists)
|
||||
KERNELRELEASE = $(shell cat .kernelrelease 2> /dev/null)
|
||||
@@ -315,9 +313,8 @@ export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
|
||||
HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
|
||||
|
||||
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
|
||||
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
|
||||
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
|
||||
@@ -354,7 +351,7 @@ endif
|
||||
# catch them early, and hand them over to scripts/kconfig/Makefile
|
||||
# It is allowed to specify more targets when calling make, including
|
||||
# mixing *config targets and build targets.
|
||||
# For example 'make oldconfig all'.
|
||||
# For example 'make oldconfig all'.
|
||||
# Detect when mixed targets is specified, and make a second invocation
|
||||
# of make so .config is not included in this case either (for *config).
|
||||
|
||||
@@ -432,6 +429,10 @@ libs-y := \
|
||||
coreutils/libcoreutils/ \
|
||||
debianutils/ \
|
||||
e2fsprogs/ \
|
||||
e2fsprogs/blkid/ \
|
||||
e2fsprogs/e2p/ \
|
||||
e2fsprogs/ext2fs/ \
|
||||
e2fsprogs/uuid/ \
|
||||
editors/ \
|
||||
findutils/ \
|
||||
init/ \
|
||||
@@ -445,7 +446,6 @@ libs-y := \
|
||||
networking/udhcp/ \
|
||||
procps/ \
|
||||
runit/ \
|
||||
selinux/ \
|
||||
shell/ \
|
||||
sysklogd/ \
|
||||
util-linux/ \
|
||||
@@ -484,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 overridden in the arch makefile
|
||||
# Defaults busybox but it is usually overriden in the arch makefile
|
||||
all: busybox
|
||||
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
@@ -533,6 +533,7 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
|
||||
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
|
||||
libs-y := $(libs-y1) $(libs-y2)
|
||||
|
||||
|
||||
# Build busybox
|
||||
# ---------------------------------------------------------------------------
|
||||
# busybox is build from the objects selected by $(busybox-init) and
|
||||
@@ -565,14 +566,20 @@ busybox-all := $(core-y) $(libs-y)
|
||||
# Rule to link busybox - also used during CONFIG_KALLSYMS
|
||||
# May be overridden by arch/$(ARCH)/Makefile
|
||||
quiet_cmd_busybox__ ?= LINK $@
|
||||
ifdef CONFIG_STATIC
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
|
||||
-o $@ -Wl,-M \
|
||||
-static \
|
||||
-o $@ \
|
||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group \
|
||||
$(LDLIBS)
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group
|
||||
else
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) -o $@ $(LDFLAGS) \
|
||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group
|
||||
endif
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
|
||||
|
||||
# Link of busybox
|
||||
@@ -628,7 +635,7 @@ endef
|
||||
# First command is ':' to allow us to use + in front of this rule
|
||||
cmd_ksym_ld = $(cmd_busybox__)
|
||||
define rule_ksym_ld
|
||||
:
|
||||
:
|
||||
+$(call cmd,busybox_version)
|
||||
$(call cmd,busybox__)
|
||||
$(Q)echo 'cmd_$@ := $(cmd_busybox__)' > $(@D)/.$(@F).cmd
|
||||
@@ -679,7 +686,7 @@ busybox: busybox_unstripped
|
||||
$(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \
|
||||
busybox_unstripped -o $@
|
||||
|
||||
# The actual objects are generated when descending,
|
||||
# The actual objects are generated when descending,
|
||||
# make sure no implicit rule kicks in
|
||||
$(sort $(busybox-all)): $(busybox-dirs) ;
|
||||
|
||||
@@ -712,7 +719,7 @@ _localver = $(foreach f, $(__localver), $(if $(findstring ~, $(f)),,$(f)))
|
||||
localver = $(subst $(space),, \
|
||||
$(shell cat /dev/null $(_localver)) \
|
||||
$(patsubst "%",%,$(CONFIG_LOCALVERSION)))
|
||||
|
||||
|
||||
# If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called
|
||||
# and if the SCM is know a tag from the SCM is appended.
|
||||
# The appended tag is determinded by the SCM used.
|
||||
@@ -795,14 +802,12 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
|
||||
#bbox# @ln -fsn asm-$(ARCH) $@
|
||||
|
||||
# Split autoconf.h into include/linux/config/*
|
||||
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
|
||||
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs > include/bbconfigopts.h
|
||||
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
|
||||
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
|
||||
#bbox# piggybacked generation of few .h files
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h
|
||||
$(call cmd,split_autoconf)
|
||||
$(call cmd,gen_bbconfigopts)
|
||||
@echo ' SPLIT include/autoconf.h -> include/config/*'
|
||||
@scripts/basic/split-include include/autoconf.h include/config
|
||||
@echo ' GEN include/bbconfigopts.h'
|
||||
@$(srctree)/scripts/mkconfigs >include/bbconfigopts.h
|
||||
@touch $@
|
||||
|
||||
# Generate some files
|
||||
@@ -910,7 +915,7 @@ endif # CONFIG_MODULES
|
||||
|
||||
# Directories & files removed with 'make clean'
|
||||
CLEAN_DIRS += $(MODVERDIR)
|
||||
CLEAN_FILES += busybox* System.map .kernelrelease \
|
||||
CLEAN_FILES += busybox* System.map \
|
||||
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
|
||||
|
||||
# Directories & files removed with 'make mrproper'
|
||||
@@ -1240,7 +1245,7 @@ endif
|
||||
$(build)=$(build-dir) $(@:.ko=.o)
|
||||
$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
|
||||
|
||||
# FIXME Should go into a make.lib or something
|
||||
# FIXME Should go into a make.lib or something
|
||||
# ===========================================================================
|
||||
|
||||
quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
|
||||
|
||||
+2
-2
@@ -38,9 +38,9 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
|
||||
done
|
||||
endif
|
||||
|
||||
check test: busybox busybox.links
|
||||
check test: busybox
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:1=),-v)
|
||||
|
||||
.PHONY: release
|
||||
release: distclean
|
||||
|
||||
+8
-44
@@ -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,50 +15,14 @@ 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
|
||||
|
||||
# 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,)
|
||||
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
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-g)
|
||||
CFLAGS += -g
|
||||
LDFLAGS += -g
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STATIC),y)
|
||||
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 $(CONFIG_PREFIX)'
|
||||
@echo ' install - install busybox into $(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 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").
|
||||
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").
|
||||
|
||||
----------------
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ 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:
|
||||
|
||||
@@ -153,10 +154,6 @@ patch
|
||||
And while we're at it, a new patch filename quoting format is apparently
|
||||
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
|
||||
---
|
||||
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
|
||||
@@ -167,15 +164,7 @@ man
|
||||
---
|
||||
ar
|
||||
Write support?
|
||||
----
|
||||
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:
|
||||
|
||||
|
||||
+4
-5
@@ -10,13 +10,12 @@ obj-y += busybox.o
|
||||
|
||||
# Generated file needs additional love
|
||||
|
||||
applets/applets.o: .config include/usage_compressed.h
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
|
||||
hostprogs-y += usage
|
||||
always := $(hostprogs-y)
|
||||
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: .config $(srctree)/include/usage.h applets/usage
|
||||
$(call cmd,gen_usage_compressed)
|
||||
include/usage_compressed.h: $(srctree)/include/usage.h applets/usage
|
||||
@echo ' GEN include/usage_compressed.h'
|
||||
@$(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
+25
-37
@@ -12,22 +12,17 @@
|
||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#define PROTOTYPES
|
||||
#include "applets.h"
|
||||
#undef PROTOTYPES
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
|
||||
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
|
||||
#warning Static linking against glibc produces buggy executables
|
||||
#warning (glibc does not cope well with ld --gc-sections).
|
||||
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
|
||||
#warning Note that glibc is unsuitable for static linking anyway.
|
||||
#warning If you still want to do it, remove -Wl,--gc-sections
|
||||
#warning from top-level Makefile and remove this warning.
|
||||
#warning Note that glibc is utterly unsuitable for static linking anyway.
|
||||
#endif
|
||||
|
||||
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
|
||||
@@ -49,7 +44,7 @@ static const char usage_messages[] =
|
||||
static struct BB_applet *applet_using;
|
||||
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
|
||||
const unsigned short NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
@@ -111,7 +106,7 @@ static char *get_trimmed_slice(char *s, char *e)
|
||||
}
|
||||
|
||||
|
||||
#define parse_error(x) do { errmsg = x; goto pe_label; } while(0)
|
||||
#define parse_error(x) { err=x; goto pe_label; }
|
||||
|
||||
/* Don't depend on the tools to combine strings. */
|
||||
static const char config_file[] = CONFIG_FILE;
|
||||
@@ -135,7 +130,7 @@ static void parse_config_file(void)
|
||||
struct BB_suid_config *sct;
|
||||
struct BB_applet *applet;
|
||||
FILE *f;
|
||||
const char *errmsg;
|
||||
char *err;
|
||||
char *s;
|
||||
char *e;
|
||||
int i, lc, section;
|
||||
@@ -312,7 +307,7 @@ static void parse_config_file(void)
|
||||
|
||||
pe_label:
|
||||
fprintf(stderr, "Parse error in %s, line %d: %s\n",
|
||||
config_file, lc, errmsg);
|
||||
config_file, lc, err);
|
||||
|
||||
fclose(f);
|
||||
/* Release any allocated memory before returning. */
|
||||
@@ -321,10 +316,11 @@ static void parse_config_file(void)
|
||||
free(sct_head);
|
||||
sct_head = sct;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
#define parse_config_file() ((void)0)
|
||||
#define parse_config_file()
|
||||
#endif /* CONFIG_FEATURE_SUID_CONFIG */
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
@@ -344,26 +340,20 @@ static void check_suid(struct BB_applet *applet)
|
||||
if (sct) {
|
||||
mode_t m = sct->m_mode;
|
||||
|
||||
if (sct->m_uid == ruid)
|
||||
/* same uid */
|
||||
if (sct->m_uid == ruid) /* same uid */
|
||||
m >>= 6;
|
||||
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid))
|
||||
/* same group / in group */
|
||||
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid)) /* same group / in group */
|
||||
m >>= 3;
|
||||
|
||||
if (!(m & S_IXOTH)) /* is x bit not set ? */
|
||||
bb_error_msg_and_die("you have no permission to run this applet!");
|
||||
|
||||
if (sct->m_gid != 0) {
|
||||
/* _both_ have to be set for sgid */
|
||||
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
|
||||
xsetgid(sct->m_gid);
|
||||
} else xsetgid(rgid); /* no sgid -> drop */
|
||||
}
|
||||
if (sct->m_uid != 0) {
|
||||
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
|
||||
else xsetuid(ruid); /* no suid -> drop */
|
||||
}
|
||||
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
|
||||
xsetgid(sct->m_gid);
|
||||
} else xsetgid(rgid); /* no sgid -> drop */
|
||||
|
||||
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
|
||||
else xsetuid(ruid); /* no suid -> drop */
|
||||
} else {
|
||||
/* default: drop all privileges */
|
||||
xsetgid(rgid);
|
||||
@@ -469,6 +459,8 @@ static int applet_name_compare(const void *name, const void *vapplet)
|
||||
return strcmp(name, applet->name);
|
||||
}
|
||||
|
||||
extern const size_t NUM_APPLETS;
|
||||
|
||||
struct BB_applet *find_applet_by_name(const char *name)
|
||||
{
|
||||
return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
|
||||
@@ -477,19 +469,15 @@ struct BB_applet *find_applet_by_name(const char *name)
|
||||
|
||||
void run_applet_by_name(const char *name, int argc, char **argv)
|
||||
{
|
||||
if (ENABLE_FEATURE_SUID_CONFIG)
|
||||
parse_config_file();
|
||||
if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file();
|
||||
|
||||
if (!strncmp(name, "busybox", 7))
|
||||
exit(busybox_main(argc, argv));
|
||||
if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv);
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
applet_using = find_applet_by_name(name);
|
||||
if (applet_using) {
|
||||
applet_name = applet_using->name;
|
||||
if (argc == 2 && !strcmp(argv[1], "--help"))
|
||||
bb_show_usage();
|
||||
if (ENABLE_FEATURE_SUID)
|
||||
check_suid(applet_using);
|
||||
exit(applet_using->main(argc, argv));
|
||||
if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage();
|
||||
if(ENABLE_FEATURE_SUID) check_suid(applet_using);
|
||||
exit((*(applet_using->main))(argc, argv));
|
||||
}
|
||||
}
|
||||
+36
-35
@@ -14,8 +14,8 @@ const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static const char usr_bin [] = "/usr/bin";
|
||||
static const char usr_sbin[] = "/usr/sbin";
|
||||
static const char usr_bin [] ="/usr/bin";
|
||||
static const char usr_sbin[] ="/usr/sbin";
|
||||
|
||||
static const char* const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
@@ -26,25 +26,25 @@ static const char* const install_dir[] = {
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*link_func)(const char *, const char *);
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
link_func lf = link;
|
||||
__link_f Link = link;
|
||||
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
lf = symlink;
|
||||
Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name);
|
||||
rc = lf(busybox, fpc);
|
||||
if (rc != 0 && errno != EEXIST) {
|
||||
install_dir[applets[i].location], applets[i].name);
|
||||
rc = Link(busybox, fpc);
|
||||
if (rc!=0 && errno!=EEXIST) {
|
||||
bb_perror_msg("%s", fpc);
|
||||
}
|
||||
free(fpc);
|
||||
@@ -59,11 +59,10 @@ int main(int argc, char **argv)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
applet_name = argv[0];
|
||||
if (*applet_name == '-')
|
||||
applet_name++;
|
||||
while ((s = strchr(applet_name, '/')))
|
||||
applet_name = s + 1;
|
||||
applet_name=argv[0];
|
||||
if (*applet_name == '-') applet_name++;
|
||||
for (s = applet_name; *s ;)
|
||||
if (*(s++) == '/') applet_name = s;
|
||||
|
||||
/* Set locale for everybody except 'init' */
|
||||
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
|
||||
@@ -73,7 +72,6 @@ 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)
|
||||
{
|
||||
/*
|
||||
@@ -83,41 +81,44 @@ int busybox_main(int argc, char **argv)
|
||||
*/
|
||||
if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2)
|
||||
if (strcmp(argv[2], "-s") == 0)
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
// XXX: FIXME: this is broken. Why not just use argv[0] ?
|
||||
busybox = xmalloc_readlink_or_warn("/proc/self/exe");
|
||||
if (!busybox)
|
||||
return 1;
|
||||
install_links(busybox, use_symbolic_links);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
busybox = xreadlink("/proc/self/exe");
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
return 0;
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Deal with --help. (Also print help when called with no arguments) */
|
||||
|
||||
if (argc == 1 || !strcmp(argv[1], "--help") ) {
|
||||
if (argc > 2) {
|
||||
if (argc==1 || !strcmp(argv[1],"--help") ) {
|
||||
if (argc>2) {
|
||||
applet_name = argv[2];
|
||||
run_applet_by_name(applet_name, 2, argv);
|
||||
} else {
|
||||
const struct BB_applet *a;
|
||||
int col, output_width;
|
||||
|
||||
output_width = 80 - sizeof("start-stop-daemon, ") - 8;
|
||||
if (ENABLE_FEATURE_AUTOWIDTH) {
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= sizeof("start-stop-daemon, ") + 8;
|
||||
}
|
||||
} else output_width = 80 - sizeof("start-stop-daemon, ") - 8;
|
||||
|
||||
printf("%s\n"
|
||||
"Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n"
|
||||
@@ -129,19 +130,19 @@ int busybox_main(int argc, char **argv)
|
||||
"\tlink to busybox for each function they wish to use and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as!\n"
|
||||
"\nCurrently defined functions:\n", bb_msg_full_version);
|
||||
col = 0;
|
||||
for (a = applets; a->name;) {
|
||||
col += printf("%s%s", (col ? ", " : "\t"), a->name);
|
||||
a++;
|
||||
|
||||
col=0;
|
||||
for(a = applets; a->name;) {
|
||||
col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
|
||||
if (col > output_width && a->name) {
|
||||
puts(",");
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
puts("\n");
|
||||
return 0;
|
||||
printf("\n\n");
|
||||
exit(0);
|
||||
}
|
||||
} else run_applet_by_name(argv[1], argc - 1, argv + 1);
|
||||
} else run_applet_by_name(argv[1], argc-1, argv+1);
|
||||
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
#include "../include/autoconf.h"
|
||||
#include "../include/busybox.h"
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
static const char usage_messages[] =
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
|
||||
@@ -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 += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
|
||||
CFLAGS += -march=i386 -mpreferred-stack-boundary=2
|
||||
+1
-1
@@ -131,7 +131,7 @@ config RPM
|
||||
bool "rpm"
|
||||
default n
|
||||
help
|
||||
Mini RPM applet - queries and extracts RPM packages.
|
||||
Mini RPM applet - queries and extracts
|
||||
|
||||
config TAR
|
||||
bool "tar"
|
||||
|
||||
+5
-5
@@ -8,15 +8,15 @@ libs-y += libunarchive/
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_BUNZIP2) += bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += unlzma.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_GUNZIP) += gunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
+1
-2
@@ -38,7 +38,6 @@ 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;
|
||||
@@ -88,7 +87,7 @@ int ar_main(int argc, char **argv)
|
||||
}
|
||||
archive_handle->offset += 7;
|
||||
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS) /* repeat */;
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
/* 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
|
||||
@@ -0,0 +1,66 @@
|
||||
/* 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) && (filename[0] != '-') && (filename[1] != '\0')) {
|
||||
/* 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,7 +26,6 @@
|
||||
#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;
|
||||
|
||||
+253
-188
@@ -34,7 +34,7 @@
|
||||
* 3) all _hash_prime's must be a prime number or chaos is assured, if your looking
|
||||
* for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt
|
||||
* 4) if you go bigger than 15 bits you may get into trouble (untested) as its
|
||||
* sometimes cast to an unsigned, if you go to 16 bit you will overlap
|
||||
* sometimes cast to an unsigned int, if you go to 16 bit you will overlap
|
||||
* int's and chaos is assured, 16381 is the max prime for 14 bit field
|
||||
*/
|
||||
|
||||
@@ -53,16 +53,16 @@
|
||||
* and available file */
|
||||
#define PACKAGE_HASH_PRIME 10007
|
||||
typedef struct edge_s {
|
||||
unsigned operator:3;
|
||||
unsigned type:4;
|
||||
unsigned name:14;
|
||||
unsigned version:14;
|
||||
unsigned int operator:3;
|
||||
unsigned int type:4;
|
||||
unsigned int name:14;
|
||||
unsigned int version:14;
|
||||
} edge_t;
|
||||
|
||||
typedef struct common_node_s {
|
||||
unsigned name:14;
|
||||
unsigned version:14;
|
||||
unsigned num_of_edges:14;
|
||||
unsigned int name:14;
|
||||
unsigned int version:14;
|
||||
unsigned int num_of_edges:14;
|
||||
edge_t **edge;
|
||||
} common_node_t;
|
||||
|
||||
@@ -71,8 +71,8 @@ typedef struct common_node_s {
|
||||
* likely to be installed at any one time, so there is a bit of leeway here */
|
||||
#define STATUS_HASH_PRIME 8191
|
||||
typedef struct status_node_s {
|
||||
unsigned package:14; /* has to fit PACKAGE_HASH_PRIME */
|
||||
unsigned status:14; /* has to fit STATUS_HASH_PRIME */
|
||||
unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */
|
||||
unsigned int status:14; /* has to fit STATUS_HASH_PRIME */
|
||||
} status_node_t;
|
||||
|
||||
/* Were statically declared here, but such a big bss is nommu-unfriendly */
|
||||
@@ -104,14 +104,26 @@ enum operator_e {
|
||||
VER_ANY = 6
|
||||
};
|
||||
|
||||
enum dpkg_opt_e {
|
||||
dpkg_opt_purge = 1,
|
||||
dpkg_opt_remove = 2,
|
||||
dpkg_opt_unpack = 4,
|
||||
dpkg_opt_configure = 8,
|
||||
dpkg_opt_install = 16,
|
||||
dpkg_opt_package_name = 32,
|
||||
dpkg_opt_filename = 64,
|
||||
dpkg_opt_list_installed = 128,
|
||||
dpkg_opt_force_ignore_depends = 256
|
||||
};
|
||||
|
||||
typedef struct deb_file_s {
|
||||
char *control_file;
|
||||
char *filename;
|
||||
unsigned package:14;
|
||||
unsigned int package:14;
|
||||
} deb_file_t;
|
||||
|
||||
|
||||
static void make_hash(const char *key, unsigned *start, unsigned *decrement, const int hash_prime)
|
||||
static void make_hash(const char *key, unsigned int *start, unsigned int *decrement, const int hash_prime)
|
||||
{
|
||||
unsigned long int hash_num = key[0];
|
||||
int len = strlen(key);
|
||||
@@ -126,24 +138,26 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
|
||||
* no effect*/
|
||||
hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
|
||||
}
|
||||
*start = (unsigned) hash_num % hash_prime;
|
||||
*decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
|
||||
*start = (unsigned int) hash_num % hash_prime;
|
||||
*decrement = (unsigned int) 1 + (hash_num % (hash_prime - 1));
|
||||
}
|
||||
|
||||
/* this adds the key to the hash table */
|
||||
static int search_name_hashtable(const char *key)
|
||||
{
|
||||
unsigned probe_address = 0;
|
||||
unsigned probe_decrement = 0;
|
||||
unsigned int probe_address = 0;
|
||||
unsigned int probe_decrement = 0;
|
||||
// char *temp;
|
||||
|
||||
make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
|
||||
while (name_hashtable[probe_address] != NULL) {
|
||||
if (strcmp(name_hashtable[probe_address], key) == 0) {
|
||||
return probe_address;
|
||||
}
|
||||
probe_address -= probe_decrement;
|
||||
if ((int)probe_address < 0) {
|
||||
probe_address += NAME_HASH_PRIME;
|
||||
} else {
|
||||
probe_address -= probe_decrement;
|
||||
if ((int)probe_address < 0) {
|
||||
probe_address += NAME_HASH_PRIME;
|
||||
}
|
||||
}
|
||||
}
|
||||
name_hashtable[probe_address] = xstrdup(key);
|
||||
@@ -153,19 +167,20 @@ static int search_name_hashtable(const char *key)
|
||||
/* this DOESNT add the key to the hashtable
|
||||
* TODO make it consistent with search_name_hashtable
|
||||
*/
|
||||
static unsigned search_status_hashtable(const char *key)
|
||||
static unsigned int search_status_hashtable(const char *key)
|
||||
{
|
||||
unsigned probe_address = 0;
|
||||
unsigned probe_decrement = 0;
|
||||
unsigned int probe_address = 0;
|
||||
unsigned int probe_decrement = 0;
|
||||
|
||||
make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
|
||||
while (status_hashtable[probe_address] != NULL) {
|
||||
if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) {
|
||||
break;
|
||||
}
|
||||
probe_address -= probe_decrement;
|
||||
if ((int)probe_address < 0) {
|
||||
probe_address += STATUS_HASH_PRIME;
|
||||
} else {
|
||||
probe_address -= probe_decrement;
|
||||
if ((int)probe_address < 0) {
|
||||
probe_address += STATUS_HASH_PRIME;
|
||||
}
|
||||
}
|
||||
}
|
||||
return probe_address;
|
||||
@@ -183,6 +198,7 @@ static int version_compare_part(const char *version1, const char *version2)
|
||||
int tmp_int;
|
||||
int ver_num1;
|
||||
int ver_num2;
|
||||
int ret;
|
||||
|
||||
if (version1 == NULL) {
|
||||
version1 = xstrdup("");
|
||||
@@ -205,7 +221,8 @@ static int version_compare_part(const char *version1, const char *version2)
|
||||
free(name1_char);
|
||||
free(name2_char);
|
||||
if (tmp_int != 0) {
|
||||
return tmp_int;
|
||||
ret = tmp_int;
|
||||
goto cleanup_version_compare_part;
|
||||
}
|
||||
|
||||
/* Compare digits */
|
||||
@@ -220,20 +237,24 @@ static int version_compare_part(const char *version1, const char *version2)
|
||||
free(name1_char);
|
||||
free(name2_char);
|
||||
if (ver_num1 < ver_num2) {
|
||||
return -1;
|
||||
ret = -1;
|
||||
goto cleanup_version_compare_part;
|
||||
}
|
||||
if (ver_num1 > ver_num2) {
|
||||
return 1;
|
||||
else if (ver_num1 > ver_num2) {
|
||||
ret = 1;
|
||||
goto cleanup_version_compare_part;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
ret = 0;
|
||||
cleanup_version_compare_part:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* if ver1 < ver2 return -1,
|
||||
* if ver1 = ver2 return 0,
|
||||
* if ver1 > ver2 return 1,
|
||||
*/
|
||||
static int version_compare(const unsigned ver1, const unsigned ver2)
|
||||
static int version_compare(const unsigned int ver1, const unsigned int ver2)
|
||||
{
|
||||
char *ch_ver1 = name_hashtable[ver1];
|
||||
char *ch_ver2 = name_hashtable[ver2];
|
||||
@@ -292,31 +313,46 @@ static int version_compare(const unsigned ver1, const unsigned ver2)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int test_version(const unsigned version1, const unsigned version2, const unsigned operator)
|
||||
static int test_version(const unsigned int version1, const unsigned int version2, const unsigned int operator)
|
||||
{
|
||||
const int version_result = version_compare(version1, version2);
|
||||
switch (operator) {
|
||||
case VER_ANY:
|
||||
return TRUE;
|
||||
case VER_EQUAL:
|
||||
return (version_result == 0);
|
||||
case VER_LESS:
|
||||
return (version_result < 0);
|
||||
case VER_LESS_EQUAL:
|
||||
return (version_result <= 0);
|
||||
case VER_MORE:
|
||||
return (version_result > 0);
|
||||
case VER_MORE_EQUAL:
|
||||
return (version_result >= 0);
|
||||
case VER_ANY:
|
||||
return TRUE;
|
||||
case VER_EQUAL:
|
||||
if (version_result == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case VER_LESS:
|
||||
if (version_result < 0) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case VER_LESS_EQUAL:
|
||||
if (version_result <= 0) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case VER_MORE:
|
||||
if (version_result > 0) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case VER_MORE_EQUAL:
|
||||
if (version_result >= 0) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
|
||||
static int search_package_hashtable(const unsigned int name, const unsigned int version, const unsigned int operator)
|
||||
{
|
||||
unsigned probe_address = 0;
|
||||
unsigned probe_decrement = 0;
|
||||
unsigned int probe_address = 0;
|
||||
unsigned int probe_decrement = 0;
|
||||
|
||||
make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
|
||||
while (package_hashtable[probe_address] != NULL) {
|
||||
@@ -357,8 +393,7 @@ static int search_for_provides(int needle, int start_at) {
|
||||
common_node_t *p;
|
||||
for (i = start_at + 1; i < PACKAGE_HASH_PRIME; i++) {
|
||||
p = package_hashtable[i];
|
||||
if (p == NULL)
|
||||
continue;
|
||||
if (p == NULL) continue;
|
||||
for (j = 0; j < p->num_of_edges; j++)
|
||||
if (p->edge[j]->type == EDGE_PROVIDES && p->edge[j]->name == needle)
|
||||
return i;
|
||||
@@ -386,7 +421,7 @@ static void add_edge_to_node(common_node_t *node, edge_t *edge)
|
||||
* field contains the number of EDGE nodes which follow as part of
|
||||
* this alternative.
|
||||
*/
|
||||
static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned edge_type)
|
||||
static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
|
||||
{
|
||||
char *line = xstrdup(whole_line);
|
||||
char *line2;
|
||||
@@ -405,19 +440,23 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
||||
field += strspn(field, " ");
|
||||
line2 = xstrdup(field);
|
||||
field2 = strtok_r(line2, "|", &line_ptr2);
|
||||
or_edge = NULL;
|
||||
if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS)
|
||||
&& (strcmp(field, field2) != 0)
|
||||
) {
|
||||
or_edge = xmalloc(sizeof(edge_t));
|
||||
if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) &&
|
||||
(strcmp(field, field2) != 0)) {
|
||||
or_edge = (edge_t *)xmalloc(sizeof(edge_t));
|
||||
or_edge->type = edge_type + 1;
|
||||
} else {
|
||||
or_edge = NULL;
|
||||
}
|
||||
|
||||
if (or_edge) {
|
||||
or_edge->name = search_name_hashtable(field);
|
||||
or_edge->version = 0; // tracks the number of altenatives
|
||||
|
||||
add_edge_to_node(parent_node, or_edge);
|
||||
}
|
||||
|
||||
do {
|
||||
edge = xmalloc(sizeof(edge_t));
|
||||
edge = (edge_t *) xmalloc(sizeof(edge_t));
|
||||
edge->type = edge_type;
|
||||
|
||||
/* Skip any extra leading spaces */
|
||||
@@ -431,7 +470,8 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
||||
edge->version = search_name_hashtable("ANY");
|
||||
} else {
|
||||
/* Skip leading ' ' or '(' */
|
||||
version += strspn(field2, " (");
|
||||
version += strspn(field2, " ");
|
||||
version += strspn(version, "(");
|
||||
/* Calculate length of any operator characters */
|
||||
offset_ch = strspn(version, "<=>");
|
||||
/* Determine operator */
|
||||
@@ -476,6 +516,8 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
||||
free(line2);
|
||||
} while ((field = strtok_r(NULL, ",", &line_ptr1)) != NULL);
|
||||
free(line);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void free_package(common_node_t *node)
|
||||
@@ -564,25 +606,27 @@ static int read_package_field(const char *package_buffer, char **field_name, cha
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
*field_name = NULL;
|
||||
if (name_length) {
|
||||
if (name_length == 0) {
|
||||
*field_name = NULL;
|
||||
} else {
|
||||
*field_name = xstrndup(&package_buffer[offset_name_start], name_length);
|
||||
}
|
||||
*field_value = NULL;
|
||||
if (value_length > 0) {
|
||||
*field_value = xstrndup(&package_buffer[offset_value_start], value_length);
|
||||
} else {
|
||||
*field_value = NULL;
|
||||
}
|
||||
return next_offset;
|
||||
}
|
||||
|
||||
static unsigned fill_package_struct(char *control_buffer)
|
||||
static unsigned int fill_package_struct(char *control_buffer)
|
||||
{
|
||||
static const char *const field_names[] = { "Package", "Version",
|
||||
"Pre-Depends", "Depends","Replaces", "Provides",
|
||||
"Conflicts", "Suggests", "Recommends", "Enhances", 0
|
||||
};
|
||||
|
||||
common_node_t *new_node = xzalloc(sizeof(common_node_t));
|
||||
common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
|
||||
char *field_name;
|
||||
char *field_value;
|
||||
int field_start = 0;
|
||||
@@ -602,38 +646,38 @@ static unsigned fill_package_struct(char *control_buffer)
|
||||
|
||||
field_num = index_in_str_array(field_names, field_name);
|
||||
switch (field_num) {
|
||||
case 0: /* Package */
|
||||
new_node->name = search_name_hashtable(field_value);
|
||||
break;
|
||||
case 1: /* Version */
|
||||
new_node->version = search_name_hashtable(field_value);
|
||||
break;
|
||||
case 2: /* Pre-Depends */
|
||||
add_split_dependencies(new_node, field_value, EDGE_PRE_DEPENDS);
|
||||
break;
|
||||
case 3: /* Depends */
|
||||
add_split_dependencies(new_node, field_value, EDGE_DEPENDS);
|
||||
break;
|
||||
case 4: /* Replaces */
|
||||
add_split_dependencies(new_node, field_value, EDGE_REPLACES);
|
||||
break;
|
||||
case 5: /* Provides */
|
||||
add_split_dependencies(new_node, field_value, EDGE_PROVIDES);
|
||||
break;
|
||||
case 6: /* Conflicts */
|
||||
add_split_dependencies(new_node, field_value, EDGE_CONFLICTS);
|
||||
break;
|
||||
case 7: /* Suggests */
|
||||
add_split_dependencies(new_node, field_value, EDGE_SUGGESTS);
|
||||
break;
|
||||
case 8: /* Recommends */
|
||||
add_split_dependencies(new_node, field_value, EDGE_RECOMMENDS);
|
||||
break;
|
||||
case 9: /* Enhances */
|
||||
add_split_dependencies(new_node, field_value, EDGE_ENHANCES);
|
||||
break;
|
||||
case 0: /* Package */
|
||||
new_node->name = search_name_hashtable(field_value);
|
||||
break;
|
||||
case 1: /* Version */
|
||||
new_node->version = search_name_hashtable(field_value);
|
||||
break;
|
||||
case 2: /* Pre-Depends */
|
||||
add_split_dependencies(new_node, field_value, EDGE_PRE_DEPENDS);
|
||||
break;
|
||||
case 3: /* Depends */
|
||||
add_split_dependencies(new_node, field_value, EDGE_DEPENDS);
|
||||
break;
|
||||
case 4: /* Replaces */
|
||||
add_split_dependencies(new_node, field_value, EDGE_REPLACES);
|
||||
break;
|
||||
case 5: /* Provides */
|
||||
add_split_dependencies(new_node, field_value, EDGE_PROVIDES);
|
||||
break;
|
||||
case 6: /* Conflicts */
|
||||
add_split_dependencies(new_node, field_value, EDGE_CONFLICTS);
|
||||
break;
|
||||
case 7: /* Suggests */
|
||||
add_split_dependencies(new_node, field_value, EDGE_SUGGESTS);
|
||||
break;
|
||||
case 8: /* Recommends */
|
||||
add_split_dependencies(new_node, field_value, EDGE_RECOMMENDS);
|
||||
break;
|
||||
case 9: /* Enhances */
|
||||
add_split_dependencies(new_node, field_value, EDGE_ENHANCES);
|
||||
break;
|
||||
}
|
||||
fill_package_struct_cleanup:
|
||||
fill_package_struct_cleanup:
|
||||
free(field_name);
|
||||
free(field_value);
|
||||
}
|
||||
@@ -643,17 +687,20 @@ static unsigned fill_package_struct(char *control_buffer)
|
||||
return -1;
|
||||
}
|
||||
num = search_package_hashtable(new_node->name, new_node->version, VER_EQUAL);
|
||||
free_package(package_hashtable[num]);
|
||||
package_hashtable[num] = new_node;
|
||||
if (package_hashtable[num] == NULL) {
|
||||
package_hashtable[num] = new_node;
|
||||
} else {
|
||||
free_package(new_node);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/* if num = 1, it returns the want status, 2 returns flag, 3 returns status */
|
||||
static unsigned get_status(const unsigned status_node, const int num)
|
||||
static unsigned int get_status(const unsigned int status_node, const int num)
|
||||
{
|
||||
char *status_string = name_hashtable[status_hashtable[status_node]->status];
|
||||
char *state_sub_string;
|
||||
unsigned state_sub_num;
|
||||
unsigned int state_sub_num;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
@@ -671,13 +718,13 @@ static unsigned get_status(const unsigned status_node, const int num)
|
||||
return state_sub_num;
|
||||
}
|
||||
|
||||
static void set_status(const unsigned status_node_num, const char *new_value, const int position)
|
||||
static void set_status(const unsigned int status_node_num, const char *new_value, const int position)
|
||||
{
|
||||
const unsigned new_value_len = strlen(new_value);
|
||||
const unsigned new_value_num = search_name_hashtable(new_value);
|
||||
unsigned want = get_status(status_node_num, 1);
|
||||
unsigned flag = get_status(status_node_num, 2);
|
||||
unsigned status = get_status(status_node_num, 3);
|
||||
const unsigned int new_value_len = strlen(new_value);
|
||||
const unsigned int new_value_num = search_name_hashtable(new_value);
|
||||
unsigned int want = get_status(status_node_num, 1);
|
||||
unsigned int flag = get_status(status_node_num, 2);
|
||||
unsigned int status = get_status(status_node_num, 3);
|
||||
int want_len = strlen(name_hashtable[want]);
|
||||
int flag_len = strlen(name_hashtable[flag]);
|
||||
int status_len = strlen(name_hashtable[status]);
|
||||
@@ -703,6 +750,7 @@ 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) {
|
||||
@@ -736,11 +784,11 @@ static void index_status_file(const char *filename)
|
||||
char *control_buffer;
|
||||
char *status_line;
|
||||
status_node_t *status_node = NULL;
|
||||
unsigned status_num;
|
||||
unsigned int status_num;
|
||||
|
||||
status_file = xfopen(filename, "r");
|
||||
while ((control_buffer = xmalloc_fgets_str(status_file, "\n\n")) != NULL) {
|
||||
const unsigned package_num = fill_package_struct(control_buffer);
|
||||
const unsigned int package_num = fill_package_struct(control_buffer);
|
||||
if (package_num != -1) {
|
||||
status_node = xmalloc(sizeof(status_node_t));
|
||||
/* fill_package_struct doesnt handle the status field */
|
||||
@@ -759,6 +807,7 @@ 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)
|
||||
@@ -775,6 +824,7 @@ 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 */
|
||||
@@ -962,7 +1012,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
/* Create array of package numbers to check against
|
||||
* installed package for conflicts*/
|
||||
while (deb_file[i] != NULL) {
|
||||
const unsigned package_num = deb_file[i]->package;
|
||||
const unsigned int package_num = deb_file[i]->package;
|
||||
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
|
||||
conflicts[conflicts_num] = package_num;
|
||||
conflicts_num++;
|
||||
@@ -975,7 +1025,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
package_hashtable[package_num]->edge[j]->operator);
|
||||
if (package_hashtable[conflicts_package_num] == NULL) {
|
||||
/* create a new package */
|
||||
common_node_t *new_node = xzalloc(sizeof(common_node_t));
|
||||
common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
|
||||
new_node->name = package_hashtable[package_num]->edge[j]->name;
|
||||
new_node->version = package_hashtable[package_num]->edge[j]->version;
|
||||
package_hashtable[conflicts_package_num] = new_node;
|
||||
@@ -1004,7 +1054,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
const edge_t *package_edge = package_node->edge[j];
|
||||
|
||||
if (package_edge->type == EDGE_CONFLICTS) {
|
||||
const unsigned package_num =
|
||||
const unsigned int package_num =
|
||||
search_package_hashtable(package_edge->name,
|
||||
package_edge->version,
|
||||
package_edge->operator);
|
||||
@@ -1063,7 +1113,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
*/
|
||||
for (j = 0; j < package_node->num_of_edges; j++) {
|
||||
const edge_t *package_edge = package_node->edge[j];
|
||||
unsigned package_num;
|
||||
unsigned int package_num;
|
||||
|
||||
if (package_edge->type == EDGE_OR_PRE_DEPENDS ||
|
||||
package_edge->type == EDGE_OR_DEPENDS) { /* start an EDGE_OR_ list */
|
||||
@@ -1296,11 +1346,11 @@ static void list_packages(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void remove_package(const unsigned package_num, int noisy)
|
||||
static void remove_package(const unsigned int package_num, int noisy)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
|
||||
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
|
||||
const unsigned status_num = search_status_hashtable(package_name);
|
||||
const unsigned int status_num = search_status_hashtable(package_name);
|
||||
const int package_name_length = strlen(package_name);
|
||||
char **remove_files;
|
||||
char **exclude_files;
|
||||
@@ -1348,11 +1398,11 @@ static void remove_package(const unsigned package_num, int noisy)
|
||||
set_status(status_num, "config-files", 3);
|
||||
}
|
||||
|
||||
static void purge_package(const unsigned package_num)
|
||||
static void purge_package(const unsigned int package_num)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
|
||||
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
|
||||
const unsigned status_num = search_status_hashtable(package_name);
|
||||
const unsigned int status_num = search_status_hashtable(package_name);
|
||||
char **remove_files;
|
||||
char **exclude_files;
|
||||
char list_name[strlen(package_name) + 25];
|
||||
@@ -1411,14 +1461,16 @@ 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), (char*)"control.tar.gz");
|
||||
llist_add_to(&(ar_handle->accept), "control.tar.gz");
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
|
||||
llist_add_to(&(ar_handle->accept), "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)
|
||||
@@ -1431,14 +1483,16 @@ 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), (char*)"data.tar.gz");
|
||||
llist_add_to(&(ar_handle->accept), "data.tar.gz");
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
|
||||
llist_add_to(&(ar_handle->accept), "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)
|
||||
@@ -1462,13 +1516,14 @@ 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)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
|
||||
const unsigned status_num = search_status_hashtable(package_name);
|
||||
const unsigned status_package_num = status_hashtable[status_num]->package;
|
||||
const unsigned int status_num = search_status_hashtable(package_name);
|
||||
const unsigned int status_package_num = status_hashtable[status_num]->package;
|
||||
char *info_prefix;
|
||||
char *list_filename;
|
||||
archive_handle_t *archive_handle;
|
||||
@@ -1514,7 +1569,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 = (char*)"/"; /* huh? */
|
||||
archive_handle->sub_archive->buffer = "/";
|
||||
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
@@ -1555,95 +1610,105 @@ 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;
|
||||
status_node_t *status_node;
|
||||
char *str_f;
|
||||
int opt;
|
||||
int package_num;
|
||||
int dpkg_opt = 0;
|
||||
int deb_count = 0;
|
||||
int state_status;
|
||||
int status_num;
|
||||
int i;
|
||||
enum {
|
||||
OPT_configure = 0x1,
|
||||
OPT_force_ignore_depends = 0x2,
|
||||
OPT_install = 0x4,
|
||||
OPT_list_installed = 0x8,
|
||||
OPT_purge = 0x10,
|
||||
OPT_remove = 0x20,
|
||||
OPT_unpack = 0x40,
|
||||
};
|
||||
|
||||
opt = getopt32(argc, argv, "CF:ilPru", &str_f);
|
||||
//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) ... // -i
|
||||
//if (opt & OPT_list_installed) ... // -l
|
||||
//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 */
|
||||
if (!opt || (!argc && !(opt && OPT_list_installed)))
|
||||
bb_show_usage();
|
||||
|
||||
name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));
|
||||
package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1));
|
||||
status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1));
|
||||
|
||||
while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) {
|
||||
switch (opt) {
|
||||
case 'C': // equivalent to --configure in official dpkg
|
||||
dpkg_opt |= dpkg_opt_configure;
|
||||
dpkg_opt |= dpkg_opt_package_name;
|
||||
break;
|
||||
case 'F': // equivalent to --force in official dpkg
|
||||
if (strcmp(optarg, "depends") == 0) {
|
||||
dpkg_opt |= dpkg_opt_force_ignore_depends;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
dpkg_opt |= dpkg_opt_install;
|
||||
dpkg_opt |= dpkg_opt_filename;
|
||||
break;
|
||||
case 'l':
|
||||
dpkg_opt |= dpkg_opt_list_installed;
|
||||
break;
|
||||
case 'P':
|
||||
dpkg_opt |= dpkg_opt_purge;
|
||||
dpkg_opt |= dpkg_opt_package_name;
|
||||
break;
|
||||
case 'r':
|
||||
dpkg_opt |= dpkg_opt_remove;
|
||||
dpkg_opt |= dpkg_opt_package_name;
|
||||
break;
|
||||
case 'u': /* Equivalent to --unpack in official dpkg */
|
||||
dpkg_opt |= dpkg_opt_unpack;
|
||||
dpkg_opt |= dpkg_opt_filename;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
/* check for non-option argument if expected */
|
||||
if ((dpkg_opt == 0) || ((argc == optind) && !(dpkg_opt && dpkg_opt_list_installed))) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* puts("(Reading database ... xxxxx files and directories installed.)"); */
|
||||
index_status_file("/var/lib/dpkg/status");
|
||||
|
||||
/* if the list action was given print the installed packages and exit */
|
||||
if (opt & OPT_list_installed) {
|
||||
if (dpkg_opt & dpkg_opt_list_installed) {
|
||||
list_packages();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Read arguments and store relevant info in structs */
|
||||
while (*argv) {
|
||||
while (optind < argc) {
|
||||
/* 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[0]) * (deb_count + 2));
|
||||
deb_file[deb_count] = xzalloc(sizeof(deb_file[0][0]));
|
||||
if (opt & (OPT_install | OPT_unpack)) {
|
||||
/* -i/-u: require filename */
|
||||
deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
|
||||
deb_file[deb_count] = (deb_file_t *) xzalloc(sizeof(deb_file_t));
|
||||
if (dpkg_opt & dpkg_opt_filename) {
|
||||
archive_handle_t *archive_handle;
|
||||
llist_t *control_list = NULL;
|
||||
|
||||
/* Extract the control file */
|
||||
llist_add_to(&control_list, (char*)"./control");
|
||||
archive_handle = init_archive_deb_ar(argv[0]);
|
||||
llist_add_to(&control_list, "./control");
|
||||
archive_handle = init_archive_deb_ar(argv[optind]);
|
||||
init_archive_deb_control(archive_handle);
|
||||
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
||||
if (deb_file[deb_count]->control_file == NULL) {
|
||||
bb_error_msg_and_die("cannot extract control file");
|
||||
}
|
||||
deb_file[deb_count]->filename = xstrdup(argv[0]);
|
||||
deb_file[deb_count]->filename = xstrdup(argv[optind]);
|
||||
package_num = fill_package_struct(deb_file[deb_count]->control_file);
|
||||
|
||||
if (package_num == -1) {
|
||||
bb_error_msg("invalid control file in %s", argv[0]);
|
||||
argv++;
|
||||
bb_error_msg("invalid control file in %s", argv[optind]);
|
||||
optind++;
|
||||
continue;
|
||||
}
|
||||
deb_file[deb_count]->package = (unsigned) package_num;
|
||||
deb_file[deb_count]->package = (unsigned int) package_num;
|
||||
|
||||
/* Add the package to the status hashtable */
|
||||
if (opt & (OPT_unpack | OPT_install)) {
|
||||
if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_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 */
|
||||
if (status_hashtable[status_num] == NULL
|
||||
|| status_hashtable[status_num]->status == 0
|
||||
) {
|
||||
status_node = xmalloc(sizeof(status_node_t));
|
||||
if ((status_hashtable[status_num] == NULL) ||
|
||||
(status_hashtable[status_num]->status == 0)) {
|
||||
status_node = (status_node_t *) xmalloc(sizeof(status_node_t));
|
||||
status_node->package = deb_file[deb_count]->package;
|
||||
/* reinstreq isnt changed to "ok" until the package control info
|
||||
* is written to the status file*/
|
||||
@@ -1654,27 +1719,27 @@ int dpkg_main(int argc, char **argv)
|
||||
set_status(status_num, "reinstreq", 2);
|
||||
}
|
||||
}
|
||||
} else if (opt & (OPT_configure | OPT_purge | OPT_remove)) {
|
||||
/* -C/-p/-r: require package name */
|
||||
}
|
||||
else if (dpkg_opt & dpkg_opt_package_name) {
|
||||
deb_file[deb_count]->package = search_package_hashtable(
|
||||
search_name_hashtable(argv[0]),
|
||||
search_name_hashtable("ANY"), VER_ANY);
|
||||
search_name_hashtable(argv[optind]),
|
||||
search_name_hashtable("ANY"), VER_ANY);
|
||||
if (package_hashtable[deb_file[deb_count]->package] == NULL) {
|
||||
bb_error_msg_and_die("package %s is uninstalled or unknown", argv[0]);
|
||||
bb_error_msg_and_die("package %s is uninstalled or unknown", argv[optind]);
|
||||
}
|
||||
package_num = deb_file[deb_count]->package;
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
|
||||
/* check package status is "installed" */
|
||||
if (opt & OPT_remove) {
|
||||
if (strcmp(name_hashtable[state_status], "not-installed") == 0
|
||||
|| strcmp(name_hashtable[state_status], "config-files") == 0
|
||||
) {
|
||||
if (dpkg_opt & dpkg_opt_remove) {
|
||||
if ((strcmp(name_hashtable[state_status], "not-installed") == 0) ||
|
||||
(strcmp(name_hashtable[state_status], "config-files") == 0)) {
|
||||
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 (dpkg_opt & dpkg_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]);
|
||||
@@ -1683,14 +1748,12 @@ int dpkg_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
deb_count++;
|
||||
argv++;
|
||||
optind++;
|
||||
}
|
||||
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 */
|
||||
if (!(opt & OPT_force_ignore_depends)) {
|
||||
if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) {
|
||||
if (!check_deps(deb_file, 0, deb_count)) {
|
||||
bb_error_msg_and_die("dependency check failed");
|
||||
}
|
||||
@@ -1699,25 +1762,25 @@ int dpkg_main(int argc, char **argv)
|
||||
/* TODO: install or remove packages in the correct dependency order */
|
||||
for (i = 0; i < deb_count; i++) {
|
||||
/* Remove or purge packages */
|
||||
if (opt & OPT_remove) {
|
||||
if (dpkg_opt & dpkg_opt_remove) {
|
||||
remove_package(deb_file[i]->package, 1);
|
||||
}
|
||||
else if (opt & OPT_purge) {
|
||||
else if (dpkg_opt & dpkg_opt_purge) {
|
||||
purge_package(deb_file[i]->package);
|
||||
}
|
||||
else if (opt & OPT_unpack) {
|
||||
else if (dpkg_opt & dpkg_opt_unpack) {
|
||||
unpack_package(deb_file[i]);
|
||||
}
|
||||
else if (opt & OPT_install) {
|
||||
else if (dpkg_opt & dpkg_opt_install) {
|
||||
unpack_package(deb_file[i]);
|
||||
/* package is configured in second pass below */
|
||||
}
|
||||
else if (opt & OPT_configure) {
|
||||
else if (dpkg_opt & dpkg_opt_configure) {
|
||||
configure_package(deb_file[i]);
|
||||
}
|
||||
}
|
||||
/* configure installed packages */
|
||||
if (opt & OPT_install) {
|
||||
if (dpkg_opt & dpkg_opt_install) {
|
||||
for (i = 0; i < deb_count; i++)
|
||||
configure_package(deb_file[i]);
|
||||
}
|
||||
@@ -1738,7 +1801,9 @@ int dpkg_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
|
||||
free_package(package_hashtable[i]);
|
||||
if (package_hashtable[i] != NULL) {
|
||||
free_package(package_hashtable[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < STATUS_HASH_PRIME; i++) {
|
||||
|
||||
+6
-7
@@ -13,14 +13,13 @@
|
||||
#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;
|
||||
const char *extract_dir = NULL;
|
||||
char *extract_dir = NULL;
|
||||
short argcount = 1;
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
@@ -32,13 +31,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), (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, "control.tar.gz");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, "control.tar.bz2");
|
||||
#endif
|
||||
|
||||
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
@@ -61,7 +60,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), (char*)"./control");
|
||||
llist_add_to(&(tar_archive->accept), "./control");
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/* 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 || strcmp(old_path, "-") == 0) {
|
||||
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;
|
||||
}
|
||||
+1528
-1140
File diff suppressed because it is too large.
Load diff
@@ -2,11 +2,12 @@
|
||||
/*
|
||||
* 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_or_die */
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip */
|
||||
|
||||
void check_header_gzip_or_die(int src_fd)
|
||||
void check_header_gzip(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -29,7 +30,7 @@ void check_header_gzip_or_die(int src_fd)
|
||||
|
||||
if (header.formatted.flags & 0x04) {
|
||||
/* bit 2 set: extra field present */
|
||||
unsigned extra_short;
|
||||
unsigned char extra_short;
|
||||
|
||||
extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
|
||||
while (extra_short > 0) {
|
||||
@@ -42,13 +43,13 @@ void check_header_gzip_or_die(int src_fd)
|
||||
/* Discard original name if any */
|
||||
if (header.formatted.flags & 0x08) {
|
||||
/* bit 3 set: original file name present */
|
||||
while (xread_char(src_fd) != 0);
|
||||
while(xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Discard file comment if any */
|
||||
if (header.formatted.flags & 0x10) {
|
||||
/* bit 4 set: file comment present */
|
||||
while (xread_char(src_fd) != 0);
|
||||
while(xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Read the header checksum */
|
||||
@@ -56,4 +57,6 @@ void check_header_gzip_or_die(int src_fd)
|
||||
xread_char(src_fd);
|
||||
xread_char(src_fd);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -14,4 +17,6 @@ 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;
|
||||
}
|
||||
@@ -67,10 +67,10 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
/* Regular file */
|
||||
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
file_header->mode);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((errno != EISDIR) && (res == -1)
|
||||
@@ -110,14 +110,6 @@ 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;
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
void data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned int size = archive_handle->file_header->size;
|
||||
const unsigned int size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->buffer = xzalloc(size + 1);
|
||||
|
||||
xread(archive_handle->src_fd, archive_handle->buffer, size);
|
||||
}
|
||||
@@ -4,10 +4,9 @@
|
||||
*/
|
||||
|
||||
#include "unarchive.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_exact_size(archive_handle->src_fd,
|
||||
STDOUT_FILENO,
|
||||
archive_handle->file_header->size);
|
||||
bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -32,25 +32,25 @@
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Constants for Huffman coding */
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
||||
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
||||
#define SYMBOL_RUNA 0
|
||||
#define SYMBOL_RUNB 1
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
||||
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
||||
#define SYMBOL_RUNA 0
|
||||
#define SYMBOL_RUNB 1
|
||||
|
||||
/* Status return values */
|
||||
#define RETVAL_OK 0
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
#define RETVAL_OK 0
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
|
||||
/* Other housekeeping constants */
|
||||
#define IOBUF_SIZE 4096
|
||||
#define IOBUF_SIZE 4096
|
||||
|
||||
/* This is what we know about each Huffman coding group */
|
||||
struct group_data {
|
||||
@@ -151,7 +151,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Reset longjmp I/O error handling */
|
||||
|
||||
i=setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
if(i) return i;
|
||||
|
||||
/* Read in header signature and CRC, then validate signature.
|
||||
(last block signature means CRC is for whole file, return now) */
|
||||
@@ -166,8 +166,8 @@ static int get_next_block(bunzip_data *bd)
|
||||
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
||||
it didn't actually work. */
|
||||
|
||||
if (get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
|
||||
if ((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
|
||||
if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
|
||||
if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* mapping table: if some byte values are never used (encoding things
|
||||
like ascii text), the compression code removes the gaps to have fewer
|
||||
@@ -180,7 +180,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
for (i=0;i<16;i++) {
|
||||
if(t&(1<<(15-i))) {
|
||||
k=get_bits(bd,16);
|
||||
for (j=0;j<16;j++)
|
||||
for(j=0;j<16;j++)
|
||||
if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j;
|
||||
}
|
||||
}
|
||||
@@ -196,17 +196,17 @@ static int get_next_block(bunzip_data *bd)
|
||||
start of the list.) */
|
||||
|
||||
if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR;
|
||||
for (i=0; i<groupCount; i++) mtfSymbol[i] = i;
|
||||
for (i=0; i<nSelectors; i++) {
|
||||
for(i=0; i<groupCount; i++) mtfSymbol[i] = i;
|
||||
for(i=0; i<nSelectors; i++) {
|
||||
|
||||
/* Get next value */
|
||||
|
||||
for (j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
|
||||
for(j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* Decode MTF to get the next selector */
|
||||
|
||||
uc = mtfSymbol[j];
|
||||
for (;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
||||
for(;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
||||
mtfSymbol[0]=selectors[i]=uc;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
t=get_bits(bd, 5)-1;
|
||||
for (i = 0; i < symCount; i++) {
|
||||
for (;;) {
|
||||
for(;;) {
|
||||
if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
|
||||
return RETVAL_DATA_ERROR;
|
||||
|
||||
@@ -254,7 +254,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Find largest and smallest lengths in this group */
|
||||
|
||||
minLen=maxLen=length[0];
|
||||
for (i = 1; i < symCount; i++) {
|
||||
for(i = 1; i < symCount; i++) {
|
||||
if(length[i] > maxLen) maxLen = length[i];
|
||||
else if(length[i] < minLen) minLen = length[i];
|
||||
}
|
||||
@@ -284,9 +284,9 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
|
||||
|
||||
pp=0;
|
||||
for (i=minLen;i<=maxLen;i++) {
|
||||
for(i=minLen;i<=maxLen;i++) {
|
||||
temp[i]=limit[i]=0;
|
||||
for (t=0;t<symCount;t++)
|
||||
for(t=0;t<symCount;t++)
|
||||
if(length[t]==i) hufGroup->permute[pp++] = t;
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
/* Initialize symbol occurrence counters and symbol Move To Front table */
|
||||
|
||||
for (i=0;i<256;i++) {
|
||||
for(i=0;i<256;i++) {
|
||||
byteCount[i] = 0;
|
||||
mtfSymbol[i]=(unsigned char)i;
|
||||
}
|
||||
@@ -333,7 +333,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Loop through compressed symbols. */
|
||||
|
||||
runPos=dbufCount=selector=0;
|
||||
for (;;) {
|
||||
for(;;) {
|
||||
|
||||
/* fetch next Huffman coding group from list. */
|
||||
|
||||
@@ -372,7 +372,7 @@ got_huff_bits:
|
||||
/* Figure how how many bits are in next symbol and unget extras */
|
||||
|
||||
i=hufGroup->minLen;
|
||||
while (j>limit[i]) ++i;
|
||||
while(j>limit[i]) ++i;
|
||||
bd->inbufBitCount += (hufGroup->maxLen - i);
|
||||
|
||||
/* Huffman decode value to get nextSym (with bounds checking) */
|
||||
@@ -421,7 +421,7 @@ got_huff_bits:
|
||||
|
||||
uc = symToByte[mtfSymbol[0]];
|
||||
byteCount[uc] += t;
|
||||
while (t--) dbuf[dbufCount++]=uc;
|
||||
while(t--) dbuf[dbufCount++]=uc;
|
||||
}
|
||||
|
||||
/* Is this the terminating symbol? */
|
||||
@@ -473,7 +473,7 @@ end_of_huffman_loop:
|
||||
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
|
||||
|
||||
j=0;
|
||||
for (i=0;i<256;i++) {
|
||||
for(i=0;i<256;i++) {
|
||||
k=j+byteCount[i];
|
||||
byteCount[i] = j;
|
||||
j=k;
|
||||
@@ -535,7 +535,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
|
||||
/* Loop outputting bytes */
|
||||
|
||||
for (;;) {
|
||||
for(;;) {
|
||||
|
||||
/* If the output buffer is full, snapshot state and return */
|
||||
|
||||
@@ -682,7 +682,7 @@ uncompressStream(int src_fd, int dst_fd)
|
||||
outbuf=xmalloc(IOBUF_SIZE);
|
||||
i=start_bunzip(&bd,src_fd,0,0);
|
||||
if(!i) {
|
||||
for (;;) {
|
||||
for(;;) {
|
||||
if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break;
|
||||
if(i!=write(dst_fd,outbuf,i)) {
|
||||
i=RETVAL_UNEXPECTED_OUTPUT_EOF;
|
||||
|
||||
@@ -64,6 +64,12 @@
|
||||
#undef MAXSEG_64K
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
/* Block compress mode -C compatible with 2.0 */
|
||||
static int block_mode = BLOCK_MODE;
|
||||
|
||||
/* user settable max # bits/code */
|
||||
static int maxbits = BITS;
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
@@ -103,38 +109,25 @@ uncompress(int fd_in, int fd_out)
|
||||
RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048);
|
||||
unsigned char htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
|
||||
/* Hmm, these were statics - why?! */
|
||||
/* user settable max # bits/code */
|
||||
int maxbits; /* = BITS; */
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
memset(inbuf, 0, IBUFSIZ + 64);
|
||||
memset(outbuf, 0, OBUFSIZ + 2048);
|
||||
|
||||
insize = 0;
|
||||
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(fd_in, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
return -1;
|
||||
}
|
||||
inbuf[0] = xread_char(fd_in);
|
||||
|
||||
maxbits = inbuf[0] & BIT_MASK;
|
||||
block_mode = inbuf[0] & BLOCK_MODE;
|
||||
maxmaxcode = MAXCODE(maxbits);
|
||||
|
||||
if (maxbits > BITS) {
|
||||
bb_error_msg("compressed with %d bits, can only handle "
|
||||
"%d bits", maxbits, BITS);
|
||||
bb_error_msg("compressed with %d bits, can only handle %d bits", maxbits,
|
||||
BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
n_bits = INIT_BITS;
|
||||
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||
bitmask = (1 << INIT_BITS) - 1;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
oldcode = -1;
|
||||
finchar = 0;
|
||||
outpos = 0;
|
||||
@@ -150,14 +143,13 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
do {
|
||||
resetbuf:
|
||||
resetbuf:;
|
||||
{
|
||||
int i;
|
||||
int e;
|
||||
int o;
|
||||
|
||||
o = posbits >> 3;
|
||||
e = insize - o;
|
||||
e = insize - (o = (posbits >> 3));
|
||||
|
||||
for (i = 0; i < e; ++i)
|
||||
inbuf[i] = inbuf[i + o];
|
||||
@@ -168,7 +160,6 @@ uncompress(int fd_in, int fd_out)
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
//error check??
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
@@ -193,8 +184,8 @@ uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
unsigned char *p = &inbuf[posbits >> 3];
|
||||
|
||||
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
}
|
||||
posbits += n_bits;
|
||||
|
||||
@@ -213,9 +204,8 @@ uncompress(int fd_in, int fd_out)
|
||||
((posbits - 1) +
|
||||
((n_bits << 3) -
|
||||
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
||||
n_bits = INIT_BITS;
|
||||
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||
bitmask = (1 << INIT_BITS) - 1;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
@@ -248,15 +238,13 @@ uncompress(int fd_in, int fd_out)
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
finchar = tab_suffixof(code);
|
||||
*--stackp = (unsigned char) finchar;
|
||||
*--stackp = (unsigned char) (finchar = tab_suffixof(code));
|
||||
|
||||
/* And put them out in forward order */
|
||||
{
|
||||
int i;
|
||||
|
||||
i = de_stack - stackp;
|
||||
if (outpos + i >= OBUFSIZ) {
|
||||
if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) {
|
||||
do {
|
||||
if (i > OBUFSIZ - outpos) {
|
||||
i = OBUFSIZ - outpos;
|
||||
@@ -268,14 +256,12 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
write(fd_out, outbuf, outpos);
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
stackp += i;
|
||||
i = de_stack - stackp;
|
||||
} while (i > 0);
|
||||
} while ((i = (de_stack - stackp)) > 0);
|
||||
} else {
|
||||
memcpy(outbuf + outpos, stackp, i);
|
||||
outpos += i;
|
||||
@@ -283,8 +269,7 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
/* Generate the new entry. */
|
||||
code = free_ent;
|
||||
if (code < maxmaxcode) {
|
||||
if ((code = free_ent) < maxmaxcode) {
|
||||
tab_prefixof(code) = (unsigned short) oldcode;
|
||||
tab_suffixof(code) = (unsigned char) finchar;
|
||||
free_ent = code + 1;
|
||||
@@ -297,8 +282,7 @@ uncompress(int fd_in, int fd_out)
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
write(fd_out, outbuf, outpos);
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,23 +22,15 @@
|
||||
typedef struct {
|
||||
int fd;
|
||||
uint8_t *ptr;
|
||||
|
||||
/* Was keeping rc on stack in unlzma and separately allocating buffer,
|
||||
* but with "buffer 'attached to' allocated rc" code is smaller: */
|
||||
/* uint8_t *buffer; */
|
||||
#define RC_BUFFER ((uint8_t*)(rc+1))
|
||||
|
||||
uint8_t *buffer;
|
||||
uint8_t *buffer_end;
|
||||
|
||||
/* Had provisions for variable buffer, but we don't need it here */
|
||||
/* int buffer_size; */
|
||||
#define RC_BUFFER_SIZE 0x10000
|
||||
|
||||
int buffer_size;
|
||||
uint32_t code;
|
||||
uint32_t range;
|
||||
uint32_t bound;
|
||||
} rc_t;
|
||||
|
||||
|
||||
#define RC_TOP_BITS 24
|
||||
#define RC_MOVE_BITS 5
|
||||
#define RC_MODEL_TOTAL_BITS 11
|
||||
@@ -47,24 +39,22 @@ typedef struct {
|
||||
/* Called twice: once at startup and once in rc_normalize() */
|
||||
static void rc_read(rc_t * rc)
|
||||
{
|
||||
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
|
||||
if (buffer_size <= 0)
|
||||
rc->buffer_size = read(rc->fd, rc->buffer, rc->buffer_size);
|
||||
if (rc->buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = RC_BUFFER;
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
rc->ptr = rc->buffer;
|
||||
rc->buffer_end = rc->buffer + rc->buffer_size;
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
static void rc_init(rc_t * rc, int fd, int buffer_size)
|
||||
{
|
||||
int i;
|
||||
rc_t* rc;
|
||||
|
||||
rc = xmalloc(sizeof(rc_t) + RC_BUFFER_SIZE);
|
||||
|
||||
rc->fd = fd;
|
||||
/* rc->buffer_size = buffer_size; */
|
||||
rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
|
||||
rc->buffer = xmalloc(buffer_size);
|
||||
rc->buffer_size = buffer_size;
|
||||
rc->buffer_end = rc->buffer + rc->buffer_size;
|
||||
rc->ptr = rc->buffer_end;
|
||||
|
||||
rc->code = 0;
|
||||
@@ -74,14 +64,13 @@ static rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
rc_read(rc);
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
/* Called once. TODO: bb_maybe_free() */
|
||||
static ATTRIBUTE_ALWAYS_INLINE void rc_free(rc_t * rc)
|
||||
{
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(rc);
|
||||
free(rc->buffer);
|
||||
}
|
||||
|
||||
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
|
||||
@@ -174,58 +163,53 @@ typedef struct {
|
||||
} __attribute__ ((packed)) lzma_header_t;
|
||||
|
||||
|
||||
/* #defines will force compiler to compute/optimize each one with each usage.
|
||||
* Have heart and use enum instead. */
|
||||
enum {
|
||||
LZMA_BASE_SIZE = 1846,
|
||||
LZMA_LIT_SIZE = 768,
|
||||
#define LZMA_BASE_SIZE 1846
|
||||
#define LZMA_LIT_SIZE 768
|
||||
|
||||
LZMA_NUM_POS_BITS_MAX = 4,
|
||||
#define LZMA_NUM_POS_BITS_MAX 4
|
||||
|
||||
LZMA_LEN_NUM_LOW_BITS = 3,
|
||||
LZMA_LEN_NUM_MID_BITS = 3,
|
||||
LZMA_LEN_NUM_HIGH_BITS = 8,
|
||||
#define LZMA_LEN_NUM_LOW_BITS 3
|
||||
#define LZMA_LEN_NUM_MID_BITS 3
|
||||
#define LZMA_LEN_NUM_HIGH_BITS 8
|
||||
|
||||
LZMA_LEN_CHOICE = 0,
|
||||
LZMA_LEN_CHOICE_2 = (LZMA_LEN_CHOICE + 1),
|
||||
LZMA_LEN_LOW = (LZMA_LEN_CHOICE_2 + 1),
|
||||
LZMA_LEN_MID = (LZMA_LEN_LOW \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS))),
|
||||
LZMA_LEN_HIGH = (LZMA_LEN_MID \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS))),
|
||||
LZMA_NUM_LEN_PROBS = (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS)),
|
||||
#define LZMA_LEN_CHOICE 0
|
||||
#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
|
||||
#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
|
||||
#define LZMA_LEN_MID (LZMA_LEN_LOW \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
|
||||
#define LZMA_LEN_HIGH (LZMA_LEN_MID \
|
||||
+(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
|
||||
#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
|
||||
|
||||
LZMA_NUM_STATES = 12,
|
||||
LZMA_NUM_LIT_STATES = 7,
|
||||
#define LZMA_NUM_STATES 12
|
||||
#define LZMA_NUM_LIT_STATES 7
|
||||
|
||||
LZMA_START_POS_MODEL_INDEX = 4,
|
||||
LZMA_END_POS_MODEL_INDEX = 14,
|
||||
LZMA_NUM_FULL_DISTANCES = (1 << (LZMA_END_POS_MODEL_INDEX >> 1)),
|
||||
#define LZMA_START_POS_MODEL_INDEX 4
|
||||
#define LZMA_END_POS_MODEL_INDEX 14
|
||||
#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
|
||||
|
||||
LZMA_NUM_POS_SLOT_BITS = 6,
|
||||
LZMA_NUM_LEN_TO_POS_STATES = 4,
|
||||
#define LZMA_NUM_POS_SLOT_BITS 6
|
||||
#define LZMA_NUM_LEN_TO_POS_STATES 4
|
||||
|
||||
LZMA_NUM_ALIGN_BITS = 4,
|
||||
#define LZMA_NUM_ALIGN_BITS 4
|
||||
|
||||
LZMA_MATCH_MIN_LEN = 2,
|
||||
|
||||
LZMA_IS_MATCH = 0,
|
||||
LZMA_IS_REP = (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
|
||||
LZMA_IS_REP_G0 = (LZMA_IS_REP + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_G1 = (LZMA_IS_REP_G0 + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_G2 = (LZMA_IS_REP_G1 + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_0_LONG = (LZMA_IS_REP_G2 + LZMA_NUM_STATES),
|
||||
LZMA_POS_SLOT = (LZMA_IS_REP_0_LONG \
|
||||
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
|
||||
LZMA_SPEC_POS = (LZMA_POS_SLOT \
|
||||
+ (LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS)),
|
||||
LZMA_ALIGN = (LZMA_SPEC_POS \
|
||||
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX),
|
||||
LZMA_LEN_CODER = (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS)),
|
||||
LZMA_REP_LEN_CODER = (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS),
|
||||
LZMA_LITERAL = (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS),
|
||||
};
|
||||
#define LZMA_MATCH_MIN_LEN 2
|
||||
|
||||
#define LZMA_IS_MATCH 0
|
||||
#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES <<LZMA_NUM_POS_BITS_MAX))
|
||||
#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
|
||||
#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
|
||||
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
|
||||
#define LZMA_SPEC_POS (LZMA_POS_SLOT \
|
||||
+(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
|
||||
#define LZMA_ALIGN (LZMA_SPEC_POS \
|
||||
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
|
||||
#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
|
||||
#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
||||
#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
unlzma(int src_fd, int dst_fd)
|
||||
@@ -241,7 +225,7 @@ unlzma(int src_fd, int dst_fd)
|
||||
uint16_t *prob_lit;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
rc_t rc;
|
||||
int i, mi;
|
||||
uint8_t *buffer;
|
||||
uint8_t previous_byte = 0;
|
||||
@@ -250,7 +234,8 @@ unlzma(int src_fd, int dst_fd)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
xread(src_fd, &header, sizeof(header));
|
||||
if (read(src_fd, &header, sizeof(header)) != sizeof(header))
|
||||
bb_error_msg_and_die("can't read header");
|
||||
|
||||
if (header.pos >= (9 * 5 * 5))
|
||||
bb_error_msg_and_die("bad header");
|
||||
@@ -275,16 +260,16 @@ unlzma(int src_fd, int dst_fd)
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
rc_init(&rc, src_fd, 0x10000);
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
|
||||
prob =
|
||||
p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
mi = 1;
|
||||
rc_update_bit_0(rc, prob);
|
||||
rc_update_bit_0(&rc, prob);
|
||||
prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE
|
||||
* ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
|
||||
+ (previous_byte >> (8 - lc)))));
|
||||
@@ -302,7 +287,7 @@ unlzma(int src_fd, int dst_fd)
|
||||
match_byte <<= 1;
|
||||
bit = match_byte & 0x100;
|
||||
prob_lit = prob + 0x100 + bit + mi;
|
||||
if (rc_get_bit(rc, prob_lit, &mi)) {
|
||||
if (rc_get_bit(&rc, prob_lit, &mi)) {
|
||||
if (!bit)
|
||||
break;
|
||||
} else {
|
||||
@@ -313,7 +298,7 @@ unlzma(int src_fd, int dst_fd)
|
||||
}
|
||||
while (mi < 0x100) {
|
||||
prob_lit = prob + mi;
|
||||
rc_get_bit(rc, prob_lit, &mi);
|
||||
rc_get_bit(&rc, prob_lit, &mi);
|
||||
}
|
||||
previous_byte = (uint8_t) mi;
|
||||
|
||||
@@ -321,8 +306,8 @@ unlzma(int src_fd, int dst_fd)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
if (state < 4)
|
||||
@@ -335,24 +320,24 @@ unlzma(int src_fd, int dst_fd)
|
||||
int offset;
|
||||
uint16_t *prob_len;
|
||||
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
prob = p + LZMA_IS_REP + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
rep3 = rep2;
|
||||
rep2 = rep1;
|
||||
rep1 = rep0;
|
||||
state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
|
||||
prob = p + LZMA_LEN_CODER;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
prob = p + LZMA_IS_REP_G0 + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
prob = (p + LZMA_IS_REP_0_LONG
|
||||
+ (state << LZMA_NUM_POS_BITS_MAX) + pos_state);
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
pos = buffer_pos - rep0;
|
||||
@@ -363,30 +348,30 @@ unlzma(int src_fd, int dst_fd)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
}
|
||||
} else {
|
||||
uint32_t distance;
|
||||
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
prob = p + LZMA_IS_REP_G1 + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
distance = rep1;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
prob = p + LZMA_IS_REP_G2 + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
distance = rep2;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
distance = rep3;
|
||||
rep3 = rep2;
|
||||
}
|
||||
@@ -400,30 +385,30 @@ unlzma(int src_fd, int dst_fd)
|
||||
}
|
||||
|
||||
prob_len = prob + LZMA_LEN_CHOICE;
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
if (rc_is_bit_0(&rc, prob_len)) {
|
||||
rc_update_bit_0(&rc, prob_len);
|
||||
prob_len = (prob + LZMA_LEN_LOW
|
||||
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
|
||||
offset = 0;
|
||||
num_bits = LZMA_LEN_NUM_LOW_BITS;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
rc_update_bit_1(&rc, prob_len);
|
||||
prob_len = prob + LZMA_LEN_CHOICE_2;
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
if (rc_is_bit_0(&rc, prob_len)) {
|
||||
rc_update_bit_0(&rc, prob_len);
|
||||
prob_len = (prob + LZMA_LEN_MID
|
||||
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
|
||||
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
|
||||
num_bits = LZMA_LEN_NUM_MID_BITS;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
rc_update_bit_1(&rc, prob_len);
|
||||
prob_len = prob + LZMA_LEN_HIGH;
|
||||
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
|
||||
+ (1 << LZMA_LEN_NUM_MID_BITS));
|
||||
num_bits = LZMA_LEN_NUM_HIGH_BITS;
|
||||
}
|
||||
}
|
||||
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
|
||||
rc_bit_tree_decode(&rc, prob_len, num_bits, &len);
|
||||
len += offset;
|
||||
|
||||
if (state < 4) {
|
||||
@@ -436,7 +421,7 @@ unlzma(int src_fd, int dst_fd)
|
||||
LZMA_NUM_LEN_TO_POS_STATES ? len :
|
||||
LZMA_NUM_LEN_TO_POS_STATES - 1)
|
||||
<< LZMA_NUM_POS_SLOT_BITS);
|
||||
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
||||
rc_bit_tree_decode(&rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
||||
&pos_slot);
|
||||
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
|
||||
num_bits = (pos_slot >> 1) - 1;
|
||||
@@ -447,7 +432,7 @@ unlzma(int src_fd, int dst_fd)
|
||||
} else {
|
||||
num_bits -= LZMA_NUM_ALIGN_BITS;
|
||||
while (num_bits--)
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(rc);
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(&rc);
|
||||
prob = p + LZMA_ALIGN;
|
||||
rep0 <<= LZMA_NUM_ALIGN_BITS;
|
||||
num_bits = LZMA_NUM_ALIGN_BITS;
|
||||
@@ -455,7 +440,7 @@ unlzma(int src_fd, int dst_fd)
|
||||
i = 1;
|
||||
mi = 1;
|
||||
while (num_bits--) {
|
||||
if (rc_get_bit(rc, prob + mi, &mi))
|
||||
if (rc_get_bit(&rc, prob + mi, &mi))
|
||||
rep0 |= i;
|
||||
i <<= 1;
|
||||
}
|
||||
@@ -476,8 +461,8 @@ unlzma(int src_fd, int dst_fd)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
@@ -485,13 +470,9 @@ unlzma(int src_fd, int dst_fd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
|
||||
bad:
|
||||
rc_free(rc);
|
||||
return -1;
|
||||
}
|
||||
rc_free(rc);
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, buffer_pos);
|
||||
USE_DESKTOP(total_written += buffer_pos;)
|
||||
rc_free(&rc);
|
||||
return USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,13 +5,17 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Reassign the subarchive metadata parser based on the filename extension
|
||||
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
|
||||
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
|
||||
* Reassign the subarchive metadata parser based on the filename extension
|
||||
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
|
||||
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
|
||||
*/
|
||||
char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
{
|
||||
|
||||
@@ -66,9 +66,7 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
unsigned long_offset;
|
||||
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
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
|
||||
@@ -80,22 +78,20 @@ 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 */
|
||||
}
|
||||
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
} else 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
|
||||
@@ -109,8 +105,7 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(typed);
|
||||
if (archive_handle->sub_archive) {
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
|
||||
/* repeat */;
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS);
|
||||
} else {
|
||||
archive_handle->action_data(archive_handle);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
/* Always round up */
|
||||
printf("%d blocks\n", (int) (archive_handle->offset % 512 ?
|
||||
archive_handle->offset / 512 + 1 :
|
||||
archive_handle->offset / 512
|
||||
archive_handle->offset / 512
|
||||
));
|
||||
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
|
||||
hardlinks_t *tmp = saved_hardlinks;
|
||||
|
||||
@@ -69,7 +69,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
char padding[12]; /* 500-512 */
|
||||
} tar;
|
||||
char *cp;
|
||||
int i, sum_u, sum_s, sum;
|
||||
int sum, i;
|
||||
int parse_names;
|
||||
|
||||
if (sizeof(tar) != 512)
|
||||
@@ -110,23 +110,16 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
#endif
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
|
||||
/* 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);
|
||||
/* Do checksum on headers */
|
||||
sum = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148 ; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
sum += ((char*)&tar)[i];
|
||||
}
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
sum += ((char*)&tar)[i];
|
||||
}
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
sum = xstrtoul(tar.chksum, 8);
|
||||
if (sum_u != sum && sum_s != sum) {
|
||||
if (sum != xstrtoul(tar.chksum, 8)) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
@@ -260,7 +253,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
}
|
||||
|
||||
/* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if it's a directory */
|
||||
/* Must be done after mode is set as '/' is used to check if its a directory */
|
||||
cp = last_char_is(file_header->name, '/');
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
|
||||
@@ -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_or_die(archive_handle->src_fd);
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
{
|
||||
if (jump_size)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
|
||||
if (jump_size) {
|
||||
bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
}
|
||||
+122
-170
@@ -10,44 +10,44 @@
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
#define RPM_CHAR_TYPE 1
|
||||
#define RPM_INT8_TYPE 2
|
||||
#define RPM_INT16_TYPE 3
|
||||
#define RPM_INT32_TYPE 4
|
||||
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
|
||||
#define RPM_STRING_TYPE 6
|
||||
#define RPM_BIN_TYPE 7
|
||||
#define RPM_STRING_ARRAY_TYPE 8
|
||||
#define RPM_I18NSTRING_TYPE 9
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
#define RPM_CHAR_TYPE 1
|
||||
#define RPM_INT8_TYPE 2
|
||||
#define RPM_INT16_TYPE 3
|
||||
#define RPM_INT32_TYPE 4
|
||||
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
|
||||
#define RPM_STRING_TYPE 6
|
||||
#define RPM_BIN_TYPE 7
|
||||
#define RPM_STRING_ARRAY_TYPE 8
|
||||
#define RPM_I18NSTRING_TYPE 9
|
||||
|
||||
#define TAG_NAME 1000
|
||||
#define TAG_VERSION 1001
|
||||
#define TAG_RELEASE 1002
|
||||
#define TAG_SUMMARY 1004
|
||||
#define TAG_DESCRIPTION 1005
|
||||
#define TAG_BUILDTIME 1006
|
||||
#define TAG_BUILDHOST 1007
|
||||
#define TAG_SIZE 1009
|
||||
#define TAG_VENDOR 1011
|
||||
#define TAG_LICENSE 1014
|
||||
#define TAG_PACKAGER 1015
|
||||
#define TAG_GROUP 1016
|
||||
#define TAG_URL 1020
|
||||
#define TAG_PREIN 1023
|
||||
#define TAG_POSTIN 1024
|
||||
#define TAG_FILEFLAGS 1037
|
||||
#define TAG_FILEUSERNAME 1039
|
||||
#define TAG_FILEGROUPNAME 1040
|
||||
#define TAG_SOURCERPM 1044
|
||||
#define TAG_PREINPROG 1085
|
||||
#define TAG_POSTINPROG 1086
|
||||
#define TAG_PREFIXS 1098
|
||||
#define TAG_DIRINDEXES 1116
|
||||
#define TAG_BASENAMES 1117
|
||||
#define TAG_DIRNAMES 1118
|
||||
#define RPMFILE_CONFIG (1 << 0)
|
||||
#define RPMFILE_DOC (1 << 1)
|
||||
#define RPMTAG_NAME 1000
|
||||
#define RPMTAG_VERSION 1001
|
||||
#define RPMTAG_RELEASE 1002
|
||||
#define RPMTAG_SUMMARY 1004
|
||||
#define RPMTAG_DESCRIPTION 1005
|
||||
#define RPMTAG_BUILDTIME 1006
|
||||
#define RPMTAG_BUILDHOST 1007
|
||||
#define RPMTAG_SIZE 1009
|
||||
#define RPMTAG_VENDOR 1011
|
||||
#define RPMTAG_LICENSE 1014
|
||||
#define RPMTAG_PACKAGER 1015
|
||||
#define RPMTAG_GROUP 1016
|
||||
#define RPMTAG_URL 1020
|
||||
#define RPMTAG_PREIN 1023
|
||||
#define RPMTAG_POSTIN 1024
|
||||
#define RPMTAG_FILEFLAGS 1037
|
||||
#define RPMTAG_FILEUSERNAME 1039
|
||||
#define RPMTAG_FILEGROUPNAME 1040
|
||||
#define RPMTAG_SOURCERPM 1044
|
||||
#define RPMTAG_PREINPROG 1085
|
||||
#define RPMTAG_POSTINPROG 1086
|
||||
#define RPMTAG_PREFIXS 1098
|
||||
#define RPMTAG_DIRINDEXES 1116
|
||||
#define RPMTAG_BASENAMES 1117
|
||||
#define RPMTAG_DIRNAMES 1118
|
||||
#define RPMFILE_CONFIG (1 << 0)
|
||||
#define RPMFILE_DOC (1 << 1)
|
||||
|
||||
enum rpm_functions_e {
|
||||
rpm_query = 1,
|
||||
@@ -73,40 +73,38 @@ static int tagcount;
|
||||
static void extract_cpio_gz(int fd);
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags);
|
||||
static int bsearch_rpmtag(const void *key, const void *item);
|
||||
static char *rpm_getstr(int tag, int itemindex);
|
||||
static char *rpm_getstring(int tag, int itemindex);
|
||||
static int rpm_getint(int tag, int itemindex);
|
||||
static int rpm_getcount(int tag);
|
||||
static void fileaction_dobackup(char *filename, int fileref);
|
||||
static void fileaction_setowngrp(char *filename, int fileref);
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
|
||||
int rpm_main(int argc, char **argv);
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
const int pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
case 'i': // First arg: Install mode, with q: Information
|
||||
if (!func) func |= rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
case 'q': // First arg: Query mode
|
||||
if (!func) func |= rpm_query;
|
||||
else bb_show_usage();
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
case 'p': // Query a package
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
case 'l': // List files in a package
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
case 'd': // List doc files in a package (implies list)
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
case 'c': // List config files in a package (implies list)
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
@@ -114,73 +112,57 @@ int rpm_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
if (!argc) bb_show_usage();
|
||||
|
||||
while (*argv) {
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, &tagcount);
|
||||
if (!mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
offset = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
/* Mimimum is one page */
|
||||
map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
|
||||
if (optind == argc) bb_show_usage();
|
||||
while (optind < argc) {
|
||||
rpm_fd = xopen(argv[optind], O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
|
||||
offset = lseek(rpm_fd, 0, SEEK_CUR);
|
||||
if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
|
||||
map = mmap(0, offset > getpagesize() ? (offset + offset % getpagesize()) : getpagesize(), PROT_READ, MAP_PRIVATE, rpm_fd, 0); // Mimimum is one page
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio_gz(rpm_fd);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
loop_through_files(RPMTAG_BASENAMES, fileaction_dobackup); /* Backup any config files */
|
||||
extract_cpio_gz(rpm_fd); // Extact the archive
|
||||
loop_through_files(RPMTAG_BASENAMES, fileaction_setowngrp); /* Set the correct file uid/gid's */
|
||||
} else if (func & rpm_query && func & rpm_query_package) {
|
||||
if (!((func & rpm_query_info) || (func & rpm_query_list))) { // If just a straight query, just give package name
|
||||
printf("%s-%s-%s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate;
|
||||
char bdatestring[50];
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_PREFIXS, 0) ? rpm_getstr(TAG_PREFIXS, 0) : "(not relocateable)");
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_VENDOR, 0) ? rpm_getstr(TAG_VENDOR, 0) : "(none)");
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_PREFIXS, 0) ? rpm_getstring(RPMTAG_PREFIXS, 0) : "(not relocateable)");
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_VENDOR, 0) ? rpm_getstring(RPMTAG_VENDOR, 0) : "(none)");
|
||||
bdate_time = rpm_getint(RPMTAG_BUILDTIME, 0);
|
||||
bdate = localtime((time_t *) &bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate);
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), rpm_getstr(TAG_SOURCERPM, 0));
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstr(TAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstring(RPMTAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstring(RPMTAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstring(RPMTAG_GROUP, 0), rpm_getstring(RPMTAG_SOURCERPM, 0));
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(RPMTAG_SIZE, 0), rpm_getstring(RPMTAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstring(RPMTAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstring(RPMTAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstring(RPMTAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
count = rpm_getcount(RPMTAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
flags = rpm_getint(RPMTAG_FILEFLAGS, it);
|
||||
switch ((func & rpm_query_list_doc) + (func & rpm_query_list_config))
|
||||
{
|
||||
case rpm_query_list_doc: if (!(flags & RPMFILE_DOC)) continue; break;
|
||||
case rpm_query_list_config: if (!(flags & RPMFILE_CONFIG)) continue; break;
|
||||
case rpm_query_list_doc + rpm_query_list_config: if (!((flags & RPMFILE_CONFIG) || (flags & RPMFILE_DOC))) continue; break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
printf("%s%s\n", rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, it)), rpm_getstring(RPMTAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mytags);
|
||||
optind++;
|
||||
free (mytags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -203,26 +185,22 @@ 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_or_die(archive_handle->src_fd);
|
||||
xchdir("/"); /* Install RPM's to root */
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
xchdir("/"); // Install RPM's to root
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
/* loop */;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
{
|
||||
/* We should never need mode than 200, and realloc later */
|
||||
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *));
|
||||
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
|
||||
int pass, tagindex = 0;
|
||||
lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
/* 1st pass is the signature headers, 2nd is the main stuff */
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
for (pass = 0; pass < 2; pass++) { /* 1st pass is the signature headers, 2nd is the main stuff */
|
||||
struct {
|
||||
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
|
||||
uint8_t version; /* 1 byte version number */
|
||||
@@ -233,31 +211,24 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
rpm_index *tmpindex;
|
||||
int storepos;
|
||||
|
||||
xread(fd, &header, sizeof(header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0)
|
||||
return NULL; /* Invalid magic */
|
||||
if (header.version != 1)
|
||||
return NULL; /* This program only supports v1 headers */
|
||||
read(fd, &header, sizeof(header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) return NULL; /* Invalid magic */
|
||||
if (header.version != 1) return NULL; /* This program only supports v1 headers */
|
||||
header.size = ntohl(header.size);
|
||||
header.entries = ntohl(header.entries);
|
||||
storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
storepos = lseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
|
||||
while (header.entries--) {
|
||||
tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index));
|
||||
xread(fd, tmpindex, sizeof(rpm_index));
|
||||
tmpindex->tag = ntohl(tmpindex->tag);
|
||||
tmpindex->type = ntohl(tmpindex->type);
|
||||
tmpindex->count = ntohl(tmpindex->count);
|
||||
read(fd, tmpindex, sizeof(rpm_index));
|
||||
tmpindex->tag = ntohl(tmpindex->tag); tmpindex->type = ntohl(tmpindex->type); tmpindex->count = ntohl(tmpindex->count);
|
||||
tmpindex->offset = storepos + ntohl(tmpindex->offset);
|
||||
if (pass==0)
|
||||
tmpindex->tag -= 743;
|
||||
if (pass==0) tmpindex->tag -= 743;
|
||||
}
|
||||
xlseek(fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
/* Skip padding to 8 byte boundary after reading signature headers */
|
||||
if (pass==0)
|
||||
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
|
||||
lseek(fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
if (pass==0) lseek(fd, (8 - (lseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR); /* Skip padding to 8 byte boundary after reading signature headers */
|
||||
}
|
||||
tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
|
||||
tags = realloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
|
||||
*num_tags = tagindex;
|
||||
return tags; /* All done, leave the file at the start of the gzipped cpio archive */
|
||||
}
|
||||
@@ -273,59 +244,42 @@ static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found[0]->count;
|
||||
if (!found) return 0;
|
||||
else return found[0]->count;
|
||||
}
|
||||
|
||||
static char *rpm_getstr(int tag, int itemindex)
|
||||
static char *rpm_getstring(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return NULL;
|
||||
if (!found || itemindex >= found[0]->count) return NULL;
|
||||
if (found[0]->type == RPM_STRING_TYPE || found[0]->type == RPM_I18NSTRING_TYPE || found[0]->type == RPM_STRING_ARRAY_TYPE) {
|
||||
int n;
|
||||
char *tmpstr = (char *) (map + found[0]->offset);
|
||||
for (n=0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
for (n=0; n < itemindex; n++) tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
}
|
||||
return NULL;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
int *tmpint; /* NB: using int8_t* would be easier to code */
|
||||
|
||||
int n, *tmpint;
|
||||
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
|
||||
* it's ok to ignore it because tag won't be used as a pointer */
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
if (!found || itemindex >= found[0]->count) return -1;
|
||||
tmpint = (int *) (map + found[0]->offset);
|
||||
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
/*return ntohl(*tmpint);*/
|
||||
/* int can be != int32_t */
|
||||
return ntohl(*(int32_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT16_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*2);
|
||||
/* ??? read int, and THEN ntohs() it?? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return ntohs(*(int16_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT8_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex);
|
||||
/* ??? why we don't read byte here??? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return *(int8_t*)tmpint;
|
||||
}
|
||||
return -1;
|
||||
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 4);
|
||||
return ntohl(*tmpint);
|
||||
} else if (found[0]->type == RPM_INT16_TYPE) {
|
||||
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 2);
|
||||
return ntohs(*tmpint);
|
||||
} else if (found[0]->type == RPM_INT8_TYPE) {
|
||||
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 1);
|
||||
return ntohs(*tmpint);
|
||||
} else return -1;
|
||||
}
|
||||
|
||||
static void fileaction_dobackup(char *filename, int fileref)
|
||||
@@ -333,11 +287,9 @@ static void fileaction_dobackup(char *filename, int fileref)
|
||||
struct stat oldfile;
|
||||
int stat_res;
|
||||
char *newname;
|
||||
if (rpm_getint(TAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) {
|
||||
/* Only need to backup config files */
|
||||
stat_res = lstat(filename, &oldfile);
|
||||
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) {
|
||||
/* File already exists - really should check MD5's etc to see if different */
|
||||
if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
|
||||
stat_res = lstat (filename, &oldfile);
|
||||
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
|
||||
newname = xasprintf("%s.rpmorig", filename);
|
||||
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
|
||||
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
|
||||
@@ -349,18 +301,18 @@ static void fileaction_dobackup(char *filename, int fileref)
|
||||
static void fileaction_setowngrp(char *filename, int fileref)
|
||||
{
|
||||
int uid, gid;
|
||||
uid = xuname2uid(rpm_getstr(TAG_FILEUSERNAME, fileref));
|
||||
gid = xgroup2gid(rpm_getstr(TAG_FILEGROUPNAME, fileref));
|
||||
uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
|
||||
gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
|
||||
chown(filename, uid, gid);
|
||||
}
|
||||
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
|
||||
{
|
||||
int count = 0;
|
||||
while (rpm_getstr(filetag, count)) {
|
||||
char* filename = xasprintf("%s%s",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, count)),
|
||||
rpm_getstr(TAG_BASENAMES, count));
|
||||
while (rpm_getstring(filetag, count)) {
|
||||
char * filename = xasprintf("%s%s",
|
||||
rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
|
||||
count)), rpm_getstring(RPMTAG_BASENAMES, count));
|
||||
fileaction(filename, count++);
|
||||
free(filename);
|
||||
}
|
||||
|
||||
+1
-2
@@ -49,7 +49,6 @@ 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;
|
||||
@@ -79,7 +78,7 @@ int rpm2cpio_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip_or_die(rpm_fd);
|
||||
check_header_gzip(rpm_fd);
|
||||
if (inflate_gunzip(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
|
||||
+61
-104
@@ -23,10 +23,10 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
#define NAME_SIZE 100
|
||||
#define NAME_SIZE_STR "100"
|
||||
typedef struct TarHeader TarHeader;
|
||||
struct TarHeader { /* byte offset */
|
||||
char name[NAME_SIZE]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
@@ -57,6 +56,7 @@ struct TarHeader { /* byte offset */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
|
||||
};
|
||||
typedef struct TarHeader TarHeader;
|
||||
|
||||
/*
|
||||
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
|
||||
@@ -73,7 +73,6 @@ struct HardLinkInfo {
|
||||
};
|
||||
|
||||
/* Some info to be carried along when creating a new tarball */
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
struct TarBallInfo {
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
for the tarball */
|
||||
@@ -86,6 +85,7 @@ struct TarBallInfo {
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
};
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
|
||||
/* A nice enum with all the possible tar file content types */
|
||||
enum TarFileType {
|
||||
@@ -134,6 +134,7 @@ static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
|
||||
}
|
||||
*hlInfoHeadPtr = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
@@ -172,9 +173,6 @@ 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;
|
||||
|
||||
@@ -275,8 +273,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
tbInfo->hlInfo->name, 0);
|
||||
#endif
|
||||
} else if (S_ISLNK(statbuf->st_mode)) {
|
||||
char *lpath = xmalloc_readlink_or_warn(fileName);
|
||||
if (!lpath)
|
||||
char *lpath = xreadlink(fileName);
|
||||
if (!lpath) /* Already printed err msg inside xreadlink() */
|
||||
return FALSE;
|
||||
header.typeflag = SYMTYPE;
|
||||
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
||||
@@ -350,7 +348,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
{
|
||||
while (excluded_files) {
|
||||
@@ -373,12 +371,12 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
# else
|
||||
#define exclude_file(excluded_files, file) 0
|
||||
#endif
|
||||
# endif
|
||||
|
||||
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
void *userData, int depth ATTRIBUTE_UNUSED)
|
||||
void *userData, int depth)
|
||||
{
|
||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
|
||||
const char *header_name;
|
||||
@@ -454,28 +452,26 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
|
||||
/* If it was a regular file, write out the body */
|
||||
if (inputFileFd >= 0) {
|
||||
size_t readSize;
|
||||
/* Wwrite the file to the archive. */
|
||||
/* We record size into header first, */
|
||||
/* and then write out file. If file shrinks in between, */
|
||||
/* tar will be corrupted. So we don't allow for that. */
|
||||
/* NB: GNU tar 1.16 warns and pads with zeroes */
|
||||
/* or even seeks back and updates header */
|
||||
bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
////off_t readSize;
|
||||
////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
////if (readSize != statbuf->st_size && readSize >= 0) {
|
||||
//// bb_error_msg_and_die("short read from %s, aborting", fileName);
|
||||
////}
|
||||
off_t readSize = 0;
|
||||
|
||||
/* write the file to the archive */
|
||||
readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
/* readSize < 0 means that error was already reported */
|
||||
if (readSize != statbuf->st_size && readSize >= 0) {
|
||||
/* Deadly. We record size into header first, */
|
||||
/* and then write out file. If file shrinks in between, */
|
||||
/* tar will be corrupted. So bail out. */
|
||||
/* NB: GNU tar 1.16 warns and pads with zeroes */
|
||||
/* or even seeks back and updates header */
|
||||
bb_error_msg_and_die("short read from %s, aborting", fileName);
|
||||
}
|
||||
/* Check that file did not grow in between? */
|
||||
/* if (safe_read(inputFileFd, 1) == 1) warn but continue? */
|
||||
|
||||
/* if (safe_read(inputFileFd,1) == 1) warn but continue? */
|
||||
close(inputFileFd);
|
||||
|
||||
/* Pad the file up to the tar block size */
|
||||
/* (a few tricks here in the name of code size) */
|
||||
readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1);
|
||||
readSize = (-(int)readSize) & (TAR_BLOCK_SIZE-1);
|
||||
memset(bb_common_bufsiz1, 0, readSize);
|
||||
xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize);
|
||||
}
|
||||
@@ -506,19 +502,20 @@ 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;
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
|
||||
|
||||
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
|
||||
bb_perror_msg_and_die("pipe");
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__
|
||||
# if __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &include;
|
||||
(void) &errorFlag;
|
||||
(void) &zip_exec;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
gzipPid = vfork();
|
||||
|
||||
@@ -531,7 +528,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 */
|
||||
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
execlp(zip_exec, zip_exec, "-f", NULL);
|
||||
vfork_exec_errno = errno;
|
||||
|
||||
close(gzipStatusPipe[1]);
|
||||
@@ -588,21 +585,16 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
if (gzipPid) {
|
||||
int status;
|
||||
if (waitpid(gzipPid, &status, 0) == -1)
|
||||
bb_perror_msg("waitpid");
|
||||
else if (!WIFEXITED(status) || WEXITSTATUS(status))
|
||||
/* gzip was killed or has exited with nonzero! */
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
return errorFlag;
|
||||
if (gzipPid && waitpid(gzipPid, NULL, 0) == -1)
|
||||
bb_error_msg("waitpid failed");
|
||||
|
||||
return !errorFlag;
|
||||
}
|
||||
#else
|
||||
int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
const unsigned long dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, const int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
#endif /* tar_create */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -630,7 +622,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
return newlist;
|
||||
}
|
||||
#else
|
||||
#define append_file_list_to_list(x) 0
|
||||
#define append_file_list_to_list(x) 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_COMPRESS
|
||||
@@ -655,30 +647,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
#define get_header_tar_Z NULL
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
/* Looks like it isn't needed - tar detects malformed (truncated)
|
||||
* archive if e.g. bunzip2 fails */
|
||||
static int child_error;
|
||||
|
||||
static void handle_SIGCHLD(int status)
|
||||
{
|
||||
/* Actually, 'status' is a signo. We reuse it for other needs */
|
||||
|
||||
/* Wait for any child without blocking */
|
||||
if (waitpid(-1, &status, WNOHANG) < 0)
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
|
||||
/* child exited with 0 */
|
||||
return;
|
||||
/* Cannot happen?
|
||||
if(!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
|
||||
child_error = 1;
|
||||
}
|
||||
#define get_header_tar_Z 0
|
||||
#endif
|
||||
|
||||
enum {
|
||||
@@ -754,7 +723,6 @@ 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;
|
||||
@@ -763,9 +731,7 @@ int tar_main(int argc, char **argv)
|
||||
const char *tar_filename = "-";
|
||||
unsigned opt;
|
||||
int verboseFlag = 0;
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
llist_t *excludes = NULL;
|
||||
#endif
|
||||
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
@@ -778,9 +744,7 @@ int tar_main(int argc, char **argv)
|
||||
"tt:vv:" // count -t,-v
|
||||
"?:" // bail out with usage instead of error return
|
||||
"X::T::" // cumulative lists
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
"\xff::" // cumulative lists for --exclude
|
||||
#endif
|
||||
USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
|
||||
USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
|
||||
SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
|
||||
@@ -795,15 +759,14 @@ int tar_main(int argc, char **argv)
|
||||
USE_FEATURE_TAR_FROM( "T:X:")
|
||||
USE_FEATURE_TAR_GZIP( "z" )
|
||||
USE_FEATURE_TAR_COMPRESS("Z" )
|
||||
, &base_dir // -C dir
|
||||
, &tar_filename // -f filename
|
||||
USE_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
|
||||
USE_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
, &excludes // --exclude
|
||||
#endif
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
,
|
||||
&base_dir, // -C dir
|
||||
&tar_filename, // -f filename
|
||||
USE_FEATURE_TAR_FROM(&(tar_handle->accept),) // T
|
||||
USE_FEATURE_TAR_FROM(&(tar_handle->reject),) // X
|
||||
USE_FEATURE_TAR_FROM(&excludes ,) // --exclude
|
||||
&verboseFlag, // combined count for -t and -v
|
||||
&verboseFlag // combined count for -t and -v
|
||||
);
|
||||
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
@@ -836,19 +799,17 @@ int tar_main(int argc, char **argv)
|
||||
if (opt & OPT_COMPRESS)
|
||||
get_header_ptr = get_header_tar_Z;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *next = excludes->link;
|
||||
excludes->link = tar_handle->reject;
|
||||
tar_handle->reject = excludes;
|
||||
excludes = next;
|
||||
if (ENABLE_FEATURE_TAR_FROM) {
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *temp = excludes->link;
|
||||
excludes->link = tar_handle->reject;
|
||||
tar_handle->reject = excludes;
|
||||
excludes = temp;
|
||||
}
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
}
|
||||
#endif
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
#endif
|
||||
|
||||
/* Check if we are reading from stdin */
|
||||
if (argv[optind] && *argv[optind] == '-') {
|
||||
@@ -866,7 +827,7 @@ int tar_main(int argc, char **argv)
|
||||
llist_add_to(&tar_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
tar_handle->accept = llist_rev(tar_handle->accept);
|
||||
tar_handle->accept = rev_llist(tar_handle->accept);
|
||||
|
||||
if (tar_handle->accept || tar_handle->reject)
|
||||
tar_handle->filter = filter_accept_reject_list;
|
||||
@@ -890,7 +851,7 @@ int tar_main(int argc, char **argv)
|
||||
flags = O_RDONLY;
|
||||
}
|
||||
|
||||
if (LONE_DASH(tar_filename)) {
|
||||
if (tar_filename[0] == '-' && !tar_filename[1]) {
|
||||
tar_handle->src_fd = fileno(tar_stream);
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else {
|
||||
@@ -901,11 +862,6 @@ int tar_main(int argc, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
/* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
signal(SIGCHLD, handle_SIGCHLD);
|
||||
#endif
|
||||
|
||||
/* create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
int zipMode = 0;
|
||||
@@ -913,10 +869,11 @@ int tar_main(int argc, char **argv)
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2)
|
||||
zipMode = 2;
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
|
||||
writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
|
||||
tar_handle->accept,
|
||||
tar_handle->reject, zipMode);
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/* 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 (strcmp(compressed_file, "-") == 0) {
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* 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 && (filename[0] != '-') && (filename[1] != '\0')) {
|
||||
/* 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);
|
||||
}
|
||||
+27
-17
@@ -32,6 +32,9 @@
|
||||
#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
|
||||
#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
|
||||
|
||||
extern unsigned int gunzip_crc;
|
||||
extern unsigned int gunzip_bytes_out;
|
||||
|
||||
typedef union {
|
||||
unsigned char raw[26];
|
||||
struct {
|
||||
@@ -51,9 +54,9 @@ typedef union {
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
|
||||
if (errno != ESPIPE)
|
||||
if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
|
||||
bb_error_msg_and_die("seek failure");
|
||||
bb_copyfd_exact_size(fd, -1, skip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,20 +75,22 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
if (zip_header->formatted.method == 0) {
|
||||
/* Method 0 - stored (not compressed) */
|
||||
off_t size = zip_header->formatted.ucmpsize;
|
||||
if (size)
|
||||
bb_copyfd_exact_size(src_fd, dst_fd, size);
|
||||
if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) {
|
||||
bb_error_msg_and_die("cannot complete extraction");
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
inflate_unzip_result res;
|
||||
/* err = */ inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd);
|
||||
// we should check for -1 error return
|
||||
inflate_init(zip_header->formatted.cmpsize);
|
||||
inflate_unzip(src_fd, dst_fd);
|
||||
inflate_cleanup();
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
|
||||
if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("invalid compressed data--%s error", "crc");
|
||||
return 1;
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != res.bytes_out) {
|
||||
if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
|
||||
bb_error_msg("invalid compressed data--%s error", "length");
|
||||
return 1;
|
||||
}
|
||||
@@ -93,7 +98,6 @@ 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;
|
||||
@@ -110,7 +114,7 @@ int unzip_main(int argc, char **argv)
|
||||
char key_buf[512];
|
||||
struct stat stat_buf;
|
||||
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
while((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
@@ -183,14 +187,15 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Open input file */
|
||||
if (LONE_DASH(src_fn)) {
|
||||
if (strcmp("-", src_fn) == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
/* Cannot use prompt mode since zip data is arriving on STDIN */
|
||||
overwrite = (overwrite == o_prompt) ? o_never : overwrite;
|
||||
|
||||
} else {
|
||||
static const char *const extn[] = {"", ".zip", ".ZIP"};
|
||||
int orig_src_fn_len = strlen(src_fn);
|
||||
for (i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
for(i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
strcpy(src_fn + orig_src_fn_len, extn[i]);
|
||||
src_fd = open(src_fn, O_RDONLY);
|
||||
}
|
||||
@@ -245,8 +250,8 @@ int unzip_main(int argc, char **argv)
|
||||
unzip_skip(src_fd, zip_header.formatted.extra_len);
|
||||
|
||||
if ((verbosity == v_list) && !list_header_done){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
printf(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----\n");
|
||||
list_header_done = 1;
|
||||
}
|
||||
|
||||
@@ -270,8 +275,10 @@ int unzip_main(int argc, char **argv)
|
||||
dst_fn);
|
||||
total_entries++;
|
||||
i = 'n';
|
||||
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
i = -1;
|
||||
|
||||
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
@@ -292,15 +299,17 @@ int unzip_main(int argc, char **argv)
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract file */
|
||||
_check_file:
|
||||
_check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
|
||||
} else { /* File already exists */
|
||||
if (overwrite == o_never) {
|
||||
i = 'n';
|
||||
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
if (overwrite == o_always) {
|
||||
i = 'y';
|
||||
@@ -311,6 +320,7 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
i = key_buf[0];
|
||||
}
|
||||
|
||||
} else { /* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn);
|
||||
}
|
||||
@@ -329,7 +339,7 @@ int unzip_main(int argc, char **argv)
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
if (unzip_extract(&zip_header, src_fd, dst_fd)) {
|
||||
failed = 1;
|
||||
failed = 1;
|
||||
}
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
|
||||
@@ -15,7 +15,6 @@ 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,7 +15,6 @@
|
||||
#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,7 +15,6 @@
|
||||
/* 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,19 +22,18 @@ 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];
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc >= 2 && argv[1][0] == '-')
|
||||
if (argc >= 2 && *argv[1] == '-')
|
||||
bb_show_usage();
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
write(1, "bkeymap", 7);
|
||||
write(1, magic, 7);
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
|
||||
@@ -30,7 +30,6 @@ struct psf_header {
|
||||
|
||||
static void loadnewfont(int fd);
|
||||
|
||||
int loadfont_main(int argc, char **argv);
|
||||
int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
@@ -82,14 +81,14 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
struct unipair *up;
|
||||
int ct = 0, maxct;
|
||||
int glyph;
|
||||
uint16_t unicode;
|
||||
u_short unicode;
|
||||
|
||||
maxct = tailsz; /* more than enough */
|
||||
up = xmalloc(maxct * sizeof(struct unipair));
|
||||
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
|
||||
|
||||
for (glyph = 0; glyph < fontsize; glyph++) {
|
||||
while (tailsz >= 2) {
|
||||
unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
|
||||
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
|
||||
tailsz -= 2;
|
||||
inbuf += 2;
|
||||
if (unicode == PSF_SEPARATOR)
|
||||
|
||||
@@ -25,12 +25,11 @@ 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;
|
||||
int i, j, fd;
|
||||
uint16_t ibuff[NR_KEYS];
|
||||
u_short ibuff[NR_KEYS];
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
char buff[7];
|
||||
|
||||
@@ -47,7 +46,7 @@ int loadkmap_main(int argc, char **argv)
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
xread(0, ibuff, NR_KEYS * sizeof(u_short));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
|
||||
+10
-8
@@ -12,12 +12,12 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int openvt_main(int argc, char **argv);
|
||||
int openvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
char vtname[sizeof(VC_FORMAT) + 2];
|
||||
|
||||
|
||||
if (argc < 3) {
|
||||
bb_show_usage();
|
||||
}
|
||||
@@ -25,18 +25,20 @@ int openvt_main(int argc, char **argv)
|
||||
sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63));
|
||||
|
||||
if (fork() == 0) {
|
||||
/* child */
|
||||
/* leave current vt (controlling tty) */
|
||||
setsid();
|
||||
/* leave current vt */
|
||||
if (setsid() < 0) {
|
||||
bb_perror_msg_and_die("setsid");
|
||||
}
|
||||
close(0); /* so that new vt becomes stdin */
|
||||
|
||||
/* and grab new one */
|
||||
fd = xopen(vtname, O_RDWR);
|
||||
/* Reassign stdin, stdout and sterr */
|
||||
dup2(fd, STDIN_FILENO);
|
||||
|
||||
/* Reassign stdout and sterr */
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
while (fd > 2) close(fd--);
|
||||
|
||||
BB_EXECVP(argv[2], &argv[2]);
|
||||
execvp(argv[2], &argv[2]);
|
||||
_exit(1);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int reset_main(int argc, char **argv);
|
||||
int reset_main(int argc, char **argv)
|
||||
{
|
||||
if (isatty(1)) {
|
||||
|
||||
+9
-41
@@ -9,62 +9,30 @@
|
||||
/* 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 new;
|
||||
struct winsize w = { 0,0,0,0 };
|
||||
struct termios old, new;
|
||||
struct winsize w = {0,0,0,0};
|
||||
int ret;
|
||||
|
||||
/* 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 */
|
||||
tcgetattr(STDOUT_FILENO, &old); /* fiddle echo */
|
||||
new = old;
|
||||
new.c_cflag |= (CLOCAL | CREAD);
|
||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
signal(SIGINT, onintr);
|
||||
signal(SIGQUIT, onintr);
|
||||
signal(SIGTERM, onintr);
|
||||
signal(SIGALRM, onintr);
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
||||
|
||||
tcsetattr(STDOUT_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
|
||||
*/
|
||||
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);
|
||||
|
||||
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);
|
||||
if (ENABLE_FEATURE_RESIZE_PRINT)
|
||||
printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",
|
||||
w.ws_col, w.ws_row);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -18,7 +18,6 @@ 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;
|
||||
@@ -38,7 +37,7 @@ int setconsole_main(int argc, char **argv)
|
||||
device = argv[optind];
|
||||
} else {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
device = DEV_CONSOLE;
|
||||
device = CONSOLE_DEV;
|
||||
}
|
||||
|
||||
if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
* 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"
|
||||
|
||||
@@ -21,8 +24,8 @@ enum {
|
||||
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
|
||||
};
|
||||
|
||||
int setkeycodes_main(int argc, char** argv);
|
||||
int setkeycodes_main(int argc, char** argv)
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int setlogcons_main(int argc, char **argv);
|
||||
int setlogcons_main(int argc, char **argv)
|
||||
extern int setlogcons_main(int argc, char **argv)
|
||||
{
|
||||
struct {
|
||||
char fn;
|
||||
|
||||
@@ -10,8 +10,6 @@ lib-y:=
|
||||
lib-$(CONFIG_BASENAME) += basename.o
|
||||
lib-$(CONFIG_CAL) += cal.o
|
||||
lib-$(CONFIG_CAT) += cat.o
|
||||
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
|
||||
@@ -30,7 +28,6 @@ lib-$(CONFIG_DIRNAME) += dirname.o
|
||||
lib-$(CONFIG_DOS2UNIX) += dos2unix.o
|
||||
lib-$(CONFIG_DU) += du.o
|
||||
lib-$(CONFIG_ECHO) += echo.o
|
||||
lib-$(CONFIG_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_ENV) += env.o
|
||||
lib-$(CONFIG_EXPR) += expr.o
|
||||
lib-$(CONFIG_FALSE) += false.o
|
||||
@@ -68,7 +65,6 @@ lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAIL) += tail.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TEST) += test.o
|
||||
lib-$(CONFIG_ASH) += test.o # used by ash
|
||||
lib-$(CONFIG_TOUCH) += touch.o
|
||||
lib-$(CONFIG_TR) += tr.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int basename_main(int argc, char **argv);
|
||||
int basename_main(int argc, char **argv)
|
||||
{
|
||||
size_t m, n;
|
||||
|
||||
+5
-1
@@ -77,7 +77,6 @@ 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;
|
||||
@@ -88,6 +87,11 @@ int cal_main(int argc, char **argv)
|
||||
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
|
||||
char buf[40];
|
||||
|
||||
// Done in busybox.c, ok to remove?
|
||||
//#ifdef CONFIG_LOCALE_SUPPORT
|
||||
// setlocale(LC_TIME, "");
|
||||
//#endif
|
||||
|
||||
flags = getopt32(argc, argv, "jy");
|
||||
|
||||
julian = flags & 1;
|
||||
|
||||
+10
-12
@@ -11,33 +11,31 @@
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
|
||||
|
||||
#include "busybox.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int bb_cat(char **argv)
|
||||
int cat_main(int argc, char **argv)
|
||||
{
|
||||
static const char *const argv_dash[] = { "-", NULL };
|
||||
FILE *f;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
if (!*argv) argv = (char**) &argv_dash;
|
||||
getopt32(argc, argv, "u");
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
*--argv = "-";
|
||||
}
|
||||
|
||||
do {
|
||||
f = fopen_or_warn_stdin(*argv);
|
||||
if (f) {
|
||||
off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
|
||||
fclose_if_not_stdin(f);
|
||||
if (r >= 0)
|
||||
if (r >= 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
retval = EXIT_FAILURE;
|
||||
} while (*++argv);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int cat_main(int argc, char **argv);
|
||||
int cat_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argc, argv, "u");
|
||||
argv += optind;
|
||||
return bb_cat(argv);
|
||||
}
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int catv_main(int argc, char **argv);
|
||||
int catv_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS, fd;
|
||||
|
||||
+1
-2
@@ -7,13 +7,12 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int chgrp_main(int argc, char **argv);
|
||||
int chgrp_main(int argc, char **argv)
|
||||
{
|
||||
/* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
|
||||
|
||||
+9
-11
@@ -31,7 +31,7 @@
|
||||
* symbolic links encountered during recursive directory traversals.
|
||||
*/
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth)
|
||||
{
|
||||
mode_t newmode;
|
||||
|
||||
@@ -46,8 +46,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
|
||||
}
|
||||
newmode = statbuf->st_mode;
|
||||
|
||||
if (!bb_parse_mode((char *)param, &newmode))
|
||||
bb_error_msg_and_die("invalid mode: %s", (char *)param);
|
||||
if (!bb_parse_mode((char *)junk, &newmode))
|
||||
bb_error_msg_and_die("invalid mode: %s", (char *)junk);
|
||||
|
||||
if (chmod(fileName, newmode) == 0) {
|
||||
if (OPT_VERBOSE
|
||||
@@ -64,7 +64,6 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chmod_main(int argc, char **argv);
|
||||
int chmod_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
@@ -118,12 +117,10 @@ 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 directory.
|
||||
Run it in empty dir. Probably requires bash.
|
||||
|
||||
#!/bin/sh
|
||||
t1="/tmp/busybox chmod"
|
||||
t2="/usr/bin/chmod"
|
||||
create() {
|
||||
function create() {
|
||||
rm -rf $1; mkdir $1
|
||||
(
|
||||
cd $1 || exit 1
|
||||
@@ -136,16 +133,17 @@ create() {
|
||||
ln -s ../up dir/up
|
||||
)
|
||||
}
|
||||
tst() {
|
||||
function 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
|
||||
rm out.diff
|
||||
mv out.diff out1.diff
|
||||
}
|
||||
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
||||
t1="/tmp/busybox chmod"
|
||||
t2="/usr/bin/chmod"
|
||||
create test1; create test2
|
||||
tst "a+w file"
|
||||
tst "a-w dir"
|
||||
|
||||
+42
-111
@@ -7,49 +7,43 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
|
||||
#define BIT_RECURSE 1
|
||||
static uid_t uid = -1;
|
||||
static gid_t gid = -1;
|
||||
|
||||
static int (*chown_func)(const char *, uid_t, gid_t) = chown;
|
||||
|
||||
#define OPT_RECURSE (option_mask32 & 1)
|
||||
#define OPT_NODEREF (option_mask32 & 2)
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 0x08) SKIP_DESKTOP(0))
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
|
||||
#define OPT_QUIET (USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0))
|
||||
/* POSIX options
|
||||
* -L traverse every symbolic link to a directory encountered
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcf"))
|
||||
|
||||
/* TODO:
|
||||
* -H if a command line argument is a symbolic link to a directory, traverse it
|
||||
* -L traverse every symbolic link to a directory encountered
|
||||
* -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 *cf, int depth)
|
||||
void ATTRIBUTE_UNUSED *junk, int depth)
|
||||
{
|
||||
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;
|
||||
// TODO: -H/-L/-P
|
||||
// if (depth ... && S_ISLNK(statbuf->st_mode)) ....
|
||||
|
||||
if (!((chown_fptr)cf)(fileName, u, g)) {
|
||||
if (!chown_func(fileName,
|
||||
(uid == (uid_t)-1) ? statbuf->st_uid : uid,
|
||||
(gid == (gid_t)-1) ? statbuf->st_gid : gid)) {
|
||||
if (OPT_VERBOSE
|
||||
|| (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
|
||||
|| (OPT_CHANGED && (statbuf->st_uid != uid || statbuf->st_gid != gid))
|
||||
) {
|
||||
printf("changed ownership of '%s' to %u:%u\n",
|
||||
fileName, (unsigned)u, (unsigned)g);
|
||||
printf("changed ownership of '%s' to %u:%u\n", fileName, uid, gid);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -58,110 +52,47 @@ 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)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
chown_fptr chown_func;
|
||||
char *groupName;
|
||||
|
||||
opt_complementary = "-2";
|
||||
getopt32(argc, argv, OPT_STR);
|
||||
|
||||
if (OPT_NODEREF) chown_func = lchown;
|
||||
|
||||
argv += optind;
|
||||
|
||||
/* 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;
|
||||
/* First, check if there is a group name here */
|
||||
groupName = strchr(*argv, '.');
|
||||
if (!groupName) {
|
||||
groupName = strchr(*argv, ':');
|
||||
}
|
||||
|
||||
parse_chown_usergroup_or_die(&ugid, argv[0]);
|
||||
/* Check for the username and groupname */
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = get_ug_id(groupName, bb_xgetgrnam);
|
||||
}
|
||||
if (--groupName != *argv)
|
||||
uid = get_ug_id(*argv, bb_xgetpwnam);
|
||||
++argv;
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
argv++;
|
||||
do {
|
||||
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
|
||||
if (!recursive_action(*argv,
|
||||
OPT_RECURSE, // recurse
|
||||
FALSE, // follow links: TODO: -H/-L/-P
|
||||
FALSE, // depth first
|
||||
fileAction, // file action
|
||||
fileAction, // dir action
|
||||
chown_func, // user data
|
||||
0) // depth
|
||||
NULL, // 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"
|
||||
|
||||
*/
|
||||
+1
-2
@@ -11,7 +11,6 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int chroot_main(int argc, char **argv);
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
@@ -33,6 +32,6 @@ int chroot_main(int argc, char **argv)
|
||||
argv[1] = (char *) "-i";
|
||||
}
|
||||
|
||||
BB_EXECVP(*argv, argv);
|
||||
execvp(*argv, argv);
|
||||
bb_perror_msg_and_die("cannot execute %s", *argv);
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int cksum_main(int argc, char **argv);
|
||||
int cksum_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
|
||||
+11
-29
@@ -34,53 +34,39 @@ 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 %"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 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 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;
|
||||
int c1, c2, char_pos = 0, line_pos = 1;
|
||||
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;
|
||||
|
||||
filename1 = *argv;
|
||||
fp1 = cmp_xfopen_input(filename1);
|
||||
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));
|
||||
|
||||
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) { /* Paranoia check... stdin == stdin? */
|
||||
|
||||
if (fp1 == fp2) { /* Paranioa 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 -)'.
|
||||
@@ -93,10 +79,6 @@ 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,7 +108,6 @@ 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,7 +3,6 @@
|
||||
* 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.
|
||||
*/
|
||||
@@ -18,7 +17,6 @@
|
||||
#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;
|
||||
@@ -51,12 +49,6 @@ 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) {
|
||||
|
||||
+6
-8
@@ -162,15 +162,12 @@ 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;
|
||||
|
||||
opt_complementary = "b--bcf:c--bcf:f--bcf";
|
||||
getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok);
|
||||
// argc -= optind;
|
||||
argv += optind;
|
||||
if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
|
||||
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
|
||||
if (option_mask32 & BB_GETOPT_ERROR)
|
||||
@@ -265,21 +262,22 @@ int cut_main(int argc, char **argv)
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
}
|
||||
|
||||
/* argv[0..argc-1] should be names of file to process. If no
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[0] == NULL || LONE_DASH(argv[0])) {
|
||||
if (argv[optind] == NULL
|
||||
|| (argv[optind][0] == '-' && argv[optind][1] == '\0')) {
|
||||
cut_file(stdin);
|
||||
} else {
|
||||
FILE *file;
|
||||
|
||||
do {
|
||||
file = fopen_or_warn(argv[0], "r");
|
||||
for (; optind < argc; optind++) {
|
||||
file = fopen_or_warn(argv[optind], "r");
|
||||
if (file) {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
} while (*++argv);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(cut_lists);
|
||||
|
||||
+10
-6
@@ -32,13 +32,18 @@
|
||||
#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)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
xputenv("TZ=UTC0");
|
||||
}
|
||||
|
||||
int date_main(int argc, char **argv);
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
time_t tm;
|
||||
@@ -207,13 +212,12 @@ format_utc:
|
||||
}
|
||||
} else if (opt & DATE_OPT_RFC2822) {
|
||||
/* Undo busybox.c for date -R */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_TIME, "C");
|
||||
setlocale(LC_TIME, "C");
|
||||
strcpy(date_fmt, "%a, %d %b %Y %H:%M:%S ");
|
||||
i = 22;
|
||||
goto format_utc;
|
||||
} else /* default case */
|
||||
date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
date_fmt = "%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
|
||||
if (*date_fmt == '\0') {
|
||||
@@ -223,7 +227,7 @@ format_utc:
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Generate output string */
|
||||
|
||||
@@ -50,7 +50,6 @@ 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 {
|
||||
|
||||
+1
-2
@@ -33,7 +33,6 @@ 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;
|
||||
@@ -94,7 +93,7 @@ int df_main(int argc, char **argv)
|
||||
mount_entry = find_mount_point(mount_point, bb_path_mtab_file);
|
||||
if (!mount_entry) {
|
||||
bb_error_msg("%s: can't find mount point", mount_point);
|
||||
SET_ERROR:
|
||||
SET_ERROR:
|
||||
status = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
+268
-252
@@ -50,6 +50,8 @@
|
||||
#define D_SKIPPED2 (1<<8)
|
||||
|
||||
/* Command line options */
|
||||
static unsigned long cmd_flags;
|
||||
|
||||
#define FLAG_a (1<<0)
|
||||
#define FLAG_b (1<<1)
|
||||
#define FLAG_d (1<<2)
|
||||
@@ -65,25 +67,13 @@
|
||||
#define FLAG_U (1<<12)
|
||||
#define FLAG_w (1<<13)
|
||||
|
||||
/* 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. */
|
||||
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;)
|
||||
/* XXX: FIXME: the following variables should be static, but gcc currently
|
||||
* creates a much bigger object if we do this. */
|
||||
int context, status;
|
||||
char *start, *label[2];
|
||||
struct stat stb1, stb2;
|
||||
char **dl;
|
||||
static int dl_count = 0;
|
||||
|
||||
struct cand {
|
||||
int x;
|
||||
@@ -91,7 +81,7 @@ struct cand {
|
||||
int pred;
|
||||
};
|
||||
|
||||
static struct line {
|
||||
struct line {
|
||||
int serial;
|
||||
int value;
|
||||
} *file[2];
|
||||
@@ -116,7 +106,7 @@ static int clen;
|
||||
static int len[2];
|
||||
static int pref, suff; /* length of prefix and suffix */
|
||||
static int slen[2];
|
||||
static bool anychange;
|
||||
static int 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 */
|
||||
@@ -126,7 +116,6 @@ static struct context_vec *context_vec_start;
|
||||
static struct context_vec *context_vec_end;
|
||||
static struct context_vec *context_vec_ptr;
|
||||
|
||||
|
||||
static void print_only(const char *path, size_t dirlen, const char *entry)
|
||||
{
|
||||
if (dirlen > 1)
|
||||
@@ -134,12 +123,11 @@ static void print_only(const char *path, size_t dirlen, const char *entry)
|
||||
printf("Only in %.*s: %s\n", (int) dirlen, path, entry);
|
||||
}
|
||||
|
||||
|
||||
static void print_status(int val, char *path1, char *path2, char *entry)
|
||||
{
|
||||
const char * const _entry = entry ? entry : "";
|
||||
char * const _path1 = entry ? concat_path_file(path1, _entry) : path1;
|
||||
char * const _path2 = entry ? concat_path_file(path2, _entry) : path2;
|
||||
const char *const _entry = entry ? entry : "";
|
||||
char *_path1 = entry ? concat_path_file(path1, _entry) : path1;
|
||||
char *_path2 = entry ? concat_path_file(path2, _entry) : path2;
|
||||
|
||||
switch (val) {
|
||||
case D_ONLY:
|
||||
@@ -152,20 +140,20 @@ static void print_status(int val, char *path1, char *path2, char *entry)
|
||||
printf("Binary files %s and %s differ\n", _path1, _path2);
|
||||
break;
|
||||
case D_DIFFER:
|
||||
if (option_mask32 & FLAG_q)
|
||||
if (cmd_flags & FLAG_q)
|
||||
printf("Files %s and %s differ\n", _path1, _path2);
|
||||
break;
|
||||
case D_SAME:
|
||||
if (option_mask32 & FLAG_s)
|
||||
if (cmd_flags & FLAG_s)
|
||||
printf("Files %s and %s are identical\n", _path1, _path2);
|
||||
break;
|
||||
case D_MISMATCH1:
|
||||
printf("File %s is a %s while file %s is a %s\n",
|
||||
_path1, "directory", _path2, "regular file");
|
||||
printf("File %s is a directory while file %s is a regular file\n",
|
||||
_path1, _path2);
|
||||
break;
|
||||
case D_MISMATCH2:
|
||||
printf("File %s is a %s while file %s is a %s\n",
|
||||
_path1, "regular file", _path2, "directory");
|
||||
printf("File %s is a regular file while file %s is a directory\n",
|
||||
_path1, _path2);
|
||||
break;
|
||||
case D_SKIPPED1:
|
||||
printf("File %s is not a regular file or directory and was skipped\n",
|
||||
@@ -181,10 +169,7 @@ static void print_status(int val, char *path1, char *path2, char *entry)
|
||||
free(_path2);
|
||||
}
|
||||
}
|
||||
static void fiddle_sum(int *sum, int t)
|
||||
{
|
||||
*sum = (int)(*sum * 127 + t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578.
|
||||
*/
|
||||
@@ -195,15 +180,24 @@ static int readhash(FILE * f)
|
||||
|
||||
sum = 1;
|
||||
space = 0;
|
||||
if (!(option_mask32 & (FLAG_b | FLAG_w))) {
|
||||
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||
if (t == EOF) {
|
||||
if (i == 0)
|
||||
return 0;
|
||||
break;
|
||||
if (!(cmd_flags & FLAG_b) && !(cmd_flags & FLAG_w)) {
|
||||
if (FLAG_i)
|
||||
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||
if (t == EOF) {
|
||||
if (i == 0)
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
sum = sum * 127 + t;
|
||||
} else
|
||||
for (i = 0; (t = getc(f)) != '\n'; i++) {
|
||||
if (t == EOF) {
|
||||
if (i == 0)
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
sum = sum * 127 + t;
|
||||
}
|
||||
fiddle_sum(&sum, t);
|
||||
}
|
||||
} else {
|
||||
for (i = 0;;) {
|
||||
switch (t = getc(f)) {
|
||||
@@ -215,11 +209,11 @@ static int readhash(FILE * f)
|
||||
space++;
|
||||
continue;
|
||||
default:
|
||||
if (space && !(option_mask32 & FLAG_w)) {
|
||||
if (space && !(cmd_flags & FLAG_w)) {
|
||||
i++;
|
||||
space = 0;
|
||||
}
|
||||
fiddle_sum(&sum, t);
|
||||
sum = sum * 127 + t;
|
||||
i++;
|
||||
continue;
|
||||
case EOF:
|
||||
@@ -240,33 +234,34 @@ static int readhash(FILE * f)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Check to see if the given files differ.
|
||||
* Returns 0 if they are the same, 1 if different, and -1 on error.
|
||||
*/
|
||||
static int files_differ(FILE * f1, FILE * f2, int flags)
|
||||
{
|
||||
char buf1[BUFSIZ], buf2[BUFSIZ];
|
||||
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);
|
||||
i = fread(buf1, 1, sizeof(buf1), f1);
|
||||
j = fread(buf2, 1, sizeof(buf2), f2);
|
||||
if (i != j)
|
||||
return 1;
|
||||
if (i == 0)
|
||||
return (ferror(f1) || ferror(f2));
|
||||
if (memcmp(bb_common_bufsiz1,
|
||||
bb_common_bufsiz1 + BUFSIZ/2, i) != 0)
|
||||
if (i == 0 && j == 0) {
|
||||
if (ferror(f1) || ferror(f2))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(buf1, buf2, i) != 0)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void prepare(int i, FILE * fd, off_t filesize)
|
||||
{
|
||||
struct line *p;
|
||||
@@ -280,8 +275,7 @@ static void prepare(int i, FILE * fd, off_t filesize)
|
||||
sz = 100;
|
||||
|
||||
p = xmalloc((sz + 3) * sizeof(struct line));
|
||||
j = 0;
|
||||
while ((h = readhash(fd))) {
|
||||
for (j = 0; (h = readhash(fd));) {
|
||||
if (j == sz) {
|
||||
sz = sz * 3 / 2;
|
||||
p = xrealloc(p, (sz + 3) * sizeof(struct line));
|
||||
@@ -292,18 +286,15 @@ static void prepare(int i, FILE * fd, off_t filesize)
|
||||
file[i] = p;
|
||||
}
|
||||
|
||||
|
||||
static void prune(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (pref = 0; pref < len[0] && pref < len[1] &&
|
||||
file[0][pref + 1].value == file[1][pref + 1].value; pref++)
|
||||
;
|
||||
file[0][pref + 1].value == file[1][pref + 1].value; pref++);
|
||||
for (suff = 0; suff < len[0] - pref && suff < len[1] - pref &&
|
||||
file[0][len[0] - suff].value == file[1][len[1] - suff].value;
|
||||
suff++)
|
||||
;
|
||||
suff++);
|
||||
for (j = 0; j < 2; j++) {
|
||||
sfile[j] = file[j] + pref;
|
||||
slen[j] = len[j] - pref - suff;
|
||||
@@ -312,7 +303,6 @@ static void prune(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void equiv(struct line *a, int n, struct line *b, int m, int *c)
|
||||
{
|
||||
int i, j;
|
||||
@@ -340,14 +330,13 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c)
|
||||
c[j] = -1;
|
||||
}
|
||||
|
||||
|
||||
static int isqrt(int n)
|
||||
{
|
||||
int y, x;
|
||||
int y, x = 1;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
x = 1;
|
||||
|
||||
do {
|
||||
y = x;
|
||||
x = n / x;
|
||||
@@ -358,7 +347,6 @@ static int isqrt(int n)
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
static int newcand(int x, int y, int pred)
|
||||
{
|
||||
struct cand *q;
|
||||
@@ -407,7 +395,7 @@ static int stone(int *a, int n, int *b, int *c)
|
||||
|
||||
#if ENABLE_FEATURE_DIFF_MINIMAL
|
||||
const unsigned int bound =
|
||||
(option_mask32 & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
|
||||
(cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
|
||||
#else
|
||||
const unsigned int bound = MAX(256, isqrt(n));
|
||||
#endif
|
||||
@@ -445,7 +433,6 @@ static int stone(int *a, int n, int *b, int *c)
|
||||
return k;
|
||||
}
|
||||
|
||||
|
||||
static void unravel(int p)
|
||||
{
|
||||
struct cand *q;
|
||||
@@ -470,7 +457,6 @@ static void unsort(struct line *f, int l, int *b)
|
||||
free(a);
|
||||
}
|
||||
|
||||
|
||||
static int skipline(FILE * f)
|
||||
{
|
||||
int i, c;
|
||||
@@ -507,8 +493,8 @@ static void check(FILE * f1, FILE * f2)
|
||||
ixnew[j] = ctnew += skipline(f2);
|
||||
j++;
|
||||
}
|
||||
if ((option_mask32 & FLAG_b) || (option_mask32 & FLAG_w)
|
||||
|| (option_mask32 & FLAG_i)) {
|
||||
if ((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)
|
||||
|| (cmd_flags & FLAG_i)) {
|
||||
while (1) {
|
||||
c = getc(f1);
|
||||
d = getc(f2);
|
||||
@@ -516,13 +502,13 @@ static void check(FILE * f1, FILE * f2)
|
||||
* GNU diff ignores a missing newline
|
||||
* in one file if bflag || wflag.
|
||||
*/
|
||||
if (((option_mask32 & FLAG_b) || (option_mask32 & FLAG_w)) &&
|
||||
if (((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)) &&
|
||||
((c == EOF && d == '\n') || (c == '\n' && d == EOF))) {
|
||||
break;
|
||||
}
|
||||
ctold++;
|
||||
ctnew++;
|
||||
if ((option_mask32 & FLAG_b) && isspace(c) && isspace(d)) {
|
||||
if ((cmd_flags & FLAG_b) && isspace(c) && isspace(d)) {
|
||||
do {
|
||||
if (c == '\n')
|
||||
break;
|
||||
@@ -533,7 +519,7 @@ static void check(FILE * f1, FILE * f2)
|
||||
break;
|
||||
ctnew++;
|
||||
} while (isspace(d = getc(f2)));
|
||||
} else if (option_mask32 & FLAG_w) {
|
||||
} else if (cmd_flags & FLAG_w) {
|
||||
while (isspace(c) && c != '\n') {
|
||||
c = getc(f1);
|
||||
ctold++;
|
||||
@@ -579,7 +565,6 @@ static void check(FILE * f1, FILE * f2)
|
||||
ixnew[j] = ctnew += skipline(f2);
|
||||
}
|
||||
|
||||
|
||||
/* shellsort CACM #201 */
|
||||
static void sort(struct line *a, int n)
|
||||
{
|
||||
@@ -622,28 +607,27 @@ static void uni_range(int a, int b)
|
||||
printf("%d,0", b);
|
||||
}
|
||||
|
||||
|
||||
static void fetch(long *f, int a, int b, FILE * lb, int ch)
|
||||
static int fetch(long *f, int a, int b, FILE * lb, int ch)
|
||||
{
|
||||
int i, j, c, lastc, col, nc;
|
||||
|
||||
if (a > b)
|
||||
return;
|
||||
return 0;
|
||||
for (i = a; i <= b; i++) {
|
||||
fseek(lb, f[i - 1], SEEK_SET);
|
||||
nc = f[i] - f[i - 1];
|
||||
if (ch != '\0') {
|
||||
putchar(ch);
|
||||
if (option_mask32 & FLAG_T)
|
||||
if (cmd_flags & FLAG_T)
|
||||
putchar('\t');
|
||||
}
|
||||
col = 0;
|
||||
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
|
||||
if ((c = getc(lb)) == EOF) {
|
||||
printf("\n\\ No newline at end of file\n");
|
||||
return;
|
||||
puts("\n\\ No newline at end of file");
|
||||
return 0;
|
||||
}
|
||||
if (c == '\t' && (option_mask32 & FLAG_t)) {
|
||||
if (c == '\t' && (cmd_flags & FLAG_t)) {
|
||||
do {
|
||||
putchar(' ');
|
||||
} while (++col & 7);
|
||||
@@ -653,24 +637,24 @@ static void fetch(long *f, int a, int b, FILE * lb, int ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int asciifile(FILE * f)
|
||||
{
|
||||
#if ENABLE_FEATURE_DIFF_BINARY
|
||||
unsigned char buf[BUFSIZ];
|
||||
int i, cnt;
|
||||
#endif
|
||||
|
||||
if ((option_mask32 & FLAG_a) || f == NULL)
|
||||
if ((cmd_flags & FLAG_a) || f == NULL)
|
||||
return 1;
|
||||
|
||||
#if ENABLE_FEATURE_DIFF_BINARY
|
||||
rewind(f);
|
||||
cnt = fread(bb_common_bufsiz1, 1, BUFSIZ, f);
|
||||
cnt = fread(buf, 1, sizeof(buf), f);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (!isprint(bb_common_bufsiz1[i])
|
||||
&& !isspace(bb_common_bufsiz1[i])) {
|
||||
if (!isprint(buf[i]) && !isspace(buf[i])) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -678,7 +662,6 @@ static int asciifile(FILE * f)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* dump accumulated "unified" diff changes */
|
||||
static void dump_unified_vec(FILE * f1, FILE * f2)
|
||||
{
|
||||
@@ -696,11 +679,12 @@ static void dump_unified_vec(FILE * f1, FILE * f2)
|
||||
lowc = MAX(1, cvp->c - context);
|
||||
upd = MIN(len[1], context_vec_ptr->d + context);
|
||||
|
||||
printf("@@ -");
|
||||
fputs("@@ -", stdout);
|
||||
uni_range(lowa, upb);
|
||||
printf(" +");
|
||||
fputs(" +", stdout);
|
||||
uni_range(lowc, upd);
|
||||
printf(" @@\n");
|
||||
fputs(" @@", stdout);
|
||||
putchar('\n');
|
||||
|
||||
/*
|
||||
* Output changes in "unified" diff format--the old and new lines
|
||||
@@ -740,20 +724,21 @@ static void dump_unified_vec(FILE * f1, FILE * f2)
|
||||
|
||||
static void print_header(const char *file1, const char *file2)
|
||||
{
|
||||
if (label1)
|
||||
printf("--- %s\n", label1);
|
||||
if (label[0] != NULL)
|
||||
printf("%s %s\n", "---", label[0]);
|
||||
else
|
||||
printf("--- %s\t%s", file1, ctime(&stb1.st_mtime));
|
||||
if (label2)
|
||||
printf("+++ %s\n", label2);
|
||||
printf("%s %s\t%s", "---", file1, ctime(&stb1.st_mtime));
|
||||
if (label[1] != NULL)
|
||||
printf("%s %s\n", "+++", label[1]);
|
||||
else
|
||||
printf("+++ %s\t%s", file2, ctime(&stb2.st_mtime));
|
||||
printf("%s %s\t%s", "+++", file2, ctime(&stb2.st_mtime));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Indicate that there is a difference between lines a and b of the from file
|
||||
* to get to lines c to d of the to file. If a is greater than b then there
|
||||
* to get to lines c to d of the to file. If a is greater then b then there
|
||||
* are no lines in the from file involved and this means that there were
|
||||
* lines appended (beginning at b). If c is greater than d then there are
|
||||
* lines missing from the to file.
|
||||
@@ -763,10 +748,10 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
|
||||
{
|
||||
static size_t max_context = 64;
|
||||
|
||||
if ((a > b && c > d) || (option_mask32 & FLAG_q)) {
|
||||
anychange = 1;
|
||||
if (a > b && c > d)
|
||||
return;
|
||||
if (cmd_flags & FLAG_q)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate change records as needed.
|
||||
@@ -776,7 +761,8 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
|
||||
|
||||
max_context <<= 1;
|
||||
context_vec_start = xrealloc(context_vec_start,
|
||||
max_context * sizeof(struct context_vec));
|
||||
max_context *
|
||||
sizeof(struct context_vec));
|
||||
context_vec_end = context_vec_start + max_context;
|
||||
context_vec_ptr = context_vec_start + offset;
|
||||
}
|
||||
@@ -785,6 +771,7 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
|
||||
* Print the context/unidiff header first time through.
|
||||
*/
|
||||
print_header(file1, file2);
|
||||
anychange = 1;
|
||||
} else if (a > context_vec_ptr->b + (2 * context) + 1 &&
|
||||
c > context_vec_ptr->d + (2 * context) + 1) {
|
||||
/*
|
||||
@@ -798,12 +785,14 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
|
||||
context_vec_ptr->b = b;
|
||||
context_vec_ptr->c = c;
|
||||
context_vec_ptr->d = d;
|
||||
anychange = 1;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void output(char *file1, FILE * f1, char *file2, FILE * f2)
|
||||
{
|
||||
|
||||
/* Note that j0 and j1 can't be used as they are defined in math.h.
|
||||
* This also allows the rather amusing variable 'j00'... */
|
||||
int m, i0, i1, j00, j01;
|
||||
@@ -827,79 +816,81 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
|
||||
if (m == 0) {
|
||||
change(file1, f1, file2, f2, 1, 0, 1, len[1]);
|
||||
}
|
||||
if (anychange != 0 && !(option_mask32 & FLAG_q)) {
|
||||
if (anychange != 0) {
|
||||
dump_unified_vec(f1, 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)
|
||||
|
||||
static int diffreg(char *ofile1, char *ofile2, int flags)
|
||||
{
|
||||
char *file1 = ofile1;
|
||||
char *file2 = ofile2;
|
||||
FILE *f1 = stdin, *f2 = stdin;
|
||||
unsigned rval;
|
||||
FILE *f1 = NULL;
|
||||
FILE *f2 = NULL;
|
||||
int rval = D_SAME;
|
||||
int i;
|
||||
|
||||
anychange = 0;
|
||||
@@ -907,30 +898,28 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags)
|
||||
|
||||
if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
|
||||
return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
|
||||
|
||||
rval = D_SAME;
|
||||
|
||||
if (LONE_DASH(file1) && LONE_DASH(file2))
|
||||
if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0)
|
||||
goto closem;
|
||||
|
||||
if (flags & D_EMPTY1)
|
||||
f1 = xfopen(bb_dev_null, "r");
|
||||
else if (NOT_LONE_DASH(file1))
|
||||
f1 = xfopen(file1, "r");
|
||||
else {
|
||||
if (strcmp(file1, "-") == 0)
|
||||
f1 = stdin;
|
||||
else
|
||||
f1 = xfopen(file1, "r");
|
||||
}
|
||||
|
||||
if (flags & D_EMPTY2)
|
||||
f2 = xfopen(bb_dev_null, "r");
|
||||
else if (NOT_LONE_DASH(file2))
|
||||
f2 = xfopen(file2, "r");
|
||||
else {
|
||||
if (strcmp(file2, "-") == 0)
|
||||
f2 = stdin;
|
||||
else
|
||||
f2 = xfopen(file2, "r");
|
||||
}
|
||||
|
||||
/* We can't diff non-seekable stream - we use rewind(), fseek().
|
||||
* This can be fixed (volunteers?).
|
||||
* Meanwhile we should check it here by stat'ing input fds,
|
||||
* but I am lazy and check that in main() instead.
|
||||
* Check in main won't catch "diffing fifos buried in subdirectories"
|
||||
* failure scenario - not very likely in real life... */
|
||||
|
||||
i = files_differ(f1, f2, flags);
|
||||
if (i == 0)
|
||||
if ((i = files_differ(f1, f2, flags)) == 0)
|
||||
goto closem;
|
||||
else if (i != 1) { /* 1 == ok */
|
||||
/* error */
|
||||
@@ -976,14 +965,16 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags)
|
||||
check(f1, f2);
|
||||
output(file1, f1, file2, f2);
|
||||
|
||||
closem:
|
||||
closem:
|
||||
if (anychange) {
|
||||
status |= 1;
|
||||
if (rval == D_SAME)
|
||||
rval = D_DIFFER;
|
||||
}
|
||||
fclose_if_not_stdin(f1);
|
||||
fclose_if_not_stdin(f2);
|
||||
if (f1 != NULL)
|
||||
fclose(f1);
|
||||
if (f2 != NULL)
|
||||
fclose(f2);
|
||||
if (file1 != ofile1)
|
||||
free(file1);
|
||||
if (file2 != ofile2)
|
||||
@@ -991,30 +982,26 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags)
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_DIFF_DIR
|
||||
static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
|
||||
{
|
||||
|
||||
int flags = D_HEADER;
|
||||
int val;
|
||||
|
||||
char *fullpath1 = concat_path_file(dir1, path1);
|
||||
char *fullpath2 = concat_path_file(dir2, path2);
|
||||
char *fullpath1 = xasprintf("%s/%s", dir1, path1);
|
||||
char *fullpath2 = xasprintf("%s/%s", dir2, path2);
|
||||
|
||||
if (stat(fullpath1, &stb1) != 0) {
|
||||
flags |= D_EMPTY1;
|
||||
memset(&stb1, 0, sizeof(stb1));
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(fullpath1);
|
||||
fullpath1 = concat_path_file(dir1, path2);
|
||||
fullpath1 = xasprintf("%s/%s", dir1, path2);
|
||||
}
|
||||
if (stat(fullpath2, &stb2) != 0) {
|
||||
flags |= D_EMPTY2;
|
||||
memset(&stb2, 0, sizeof(stb2));
|
||||
stb2.st_mode = stb1.st_mode;
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(fullpath2);
|
||||
fullpath2 = concat_path_file(dir2, path1);
|
||||
fullpath2 = xasprintf("%s/%s", dir2, path1);
|
||||
}
|
||||
|
||||
if (stb1.st_mode == 0)
|
||||
@@ -1036,51 +1023,63 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_DIFF_DIR
|
||||
static int dir_strcmp(const void *p1, const void *p2)
|
||||
{
|
||||
return strcmp(*(char *const *) p1, *(char *const *) p2);
|
||||
}
|
||||
|
||||
|
||||
/* This function adds a filename to dl, the directory listing. */
|
||||
|
||||
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 (cmd_flags & FLAG_r) {
|
||||
int *pp = (int *) userdata;
|
||||
int path_len = *pp + 1;
|
||||
|
||||
dl[dl_count - 1] = &(dl[dl_count - 1])[path_len];
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* This returns a sorted directory listing. */
|
||||
static char **get_dir(char *path)
|
||||
{
|
||||
dl_count = 0;
|
||||
dl = NULL;
|
||||
|
||||
int i;
|
||||
char **retval;
|
||||
|
||||
/* 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 - '(void*)(strlen(path)+)'.
|
||||
* add_to_dirlist then removes root dir prefix. */
|
||||
* length of the root directory. It can then be removed in
|
||||
* add_to_dirlist. */
|
||||
|
||||
if (option_mask32 & FLAG_r) {
|
||||
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 (cmd_flags & FLAG_r)
|
||||
recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL,
|
||||
(void*)(strlen(path)+1), 0);
|
||||
} else {
|
||||
userdata, 0);
|
||||
else {
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
|
||||
dp = warn_opendir(path);
|
||||
while ((ep = readdir(dp))) {
|
||||
if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.'))
|
||||
if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, ".")))
|
||||
continue;
|
||||
add_to_dirlist(ep->d_name, NULL, (void*)(int)0, 0);
|
||||
add_to_dirlist(ep->d_name, NULL, NULL, 0);
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
@@ -1088,18 +1087,24 @@ static char **get_dir(char *path)
|
||||
/* Sort dl alphabetically. */
|
||||
qsort(dl, dl_count, sizeof(char *), dir_strcmp);
|
||||
|
||||
dl[dl_count] = NULL;
|
||||
return dl;
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
|
||||
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';
|
||||
@@ -1110,7 +1115,11 @@ 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) {
|
||||
@@ -1135,13 +1144,13 @@ static void diffdir(char *p1, char *p2)
|
||||
dirlist1++;
|
||||
dirlist2++;
|
||||
} else if (pos < 0) {
|
||||
if (option_mask32 & FLAG_N)
|
||||
if (cmd_flags & FLAG_N)
|
||||
do_diff(p1, dp1, p2, NULL);
|
||||
else
|
||||
print_only(p1, strlen(p1) + 1, dp1);
|
||||
dirlist1++;
|
||||
} else {
|
||||
if (option_mask32 & FLAG_N)
|
||||
if (cmd_flags & FLAG_N)
|
||||
do_diff(p1, NULL, p2, dp2);
|
||||
else
|
||||
print_only(p2, strlen(p2) + 1, dp2);
|
||||
@@ -1152,76 +1161,83 @@ static void diffdir(char *p1, char *p2)
|
||||
#endif
|
||||
|
||||
|
||||
int diff_main(int argc, char **argv);
|
||||
|
||||
int diff_main(int argc, char **argv)
|
||||
{
|
||||
bool gotstdin = 0;
|
||||
int gotstdin = 0;
|
||||
|
||||
char *U_opt;
|
||||
char *f1, *f2;
|
||||
llist_t *L_arg = NULL;
|
||||
|
||||
/* exactly 2 params; collect multiple -L <label> */
|
||||
opt_complementary = "=2:L::";
|
||||
getopt32(argc, argv, "abdiL:NqrsS:tTU:wu"
|
||||
"p" /* ignored (for compatibility) */,
|
||||
opt_complementary = "L::";
|
||||
cmd_flags = getopt32(argc, argv, "abdiL:NqrsS:tTU:wu",
|
||||
&L_arg, &start, &U_opt);
|
||||
/*argc -= optind;*/
|
||||
argv += optind;
|
||||
while (L_arg) {
|
||||
if (label1 && label2)
|
||||
bb_show_usage();
|
||||
if (!label1)
|
||||
label1 = L_arg->data;
|
||||
else { /* then label2 is NULL */
|
||||
label2 = label1;
|
||||
label1 = L_arg->data;
|
||||
|
||||
if (cmd_flags & FLAG_L) {
|
||||
while (L_arg) {
|
||||
if (label[0] == NULL)
|
||||
label[0] = L_arg->data;
|
||||
else if (label[1] == NULL)
|
||||
label[1] = L_arg->data;
|
||||
else
|
||||
bb_show_usage();
|
||||
|
||||
L_arg = L_arg->link;
|
||||
}
|
||||
|
||||
/* If both label[0] and label[1] were set, they need to be swapped. */
|
||||
if (label[0] && label[1]) {
|
||||
char *tmp;
|
||||
|
||||
tmp = label[1];
|
||||
label[1] = label[0];
|
||||
label[0] = tmp;
|
||||
}
|
||||
/* we leak L_arg here... */
|
||||
L_arg = L_arg->link;
|
||||
}
|
||||
if (option_mask32 & FLAG_U)
|
||||
context = xatoi_u(U_opt);
|
||||
|
||||
context = 3; /* This is the default number of lines of context. */
|
||||
if (cmd_flags & FLAG_U) {
|
||||
context = xatoul_range(U_opt, 1, INT_MAX);
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/*
|
||||
* Do sanity checks, fill in stb1 and stb2 and call the appropriate
|
||||
* driver routine. Both drivers use the contents of stb1 and stb2.
|
||||
*/
|
||||
|
||||
f1 = argv[0];
|
||||
f2 = argv[1];
|
||||
if (LONE_DASH(f1)) {
|
||||
if (argc < 2) {
|
||||
bb_error_msg("missing filename");
|
||||
bb_show_usage();
|
||||
}
|
||||
if (strcmp(argv[0], "-") == 0) {
|
||||
fstat(STDIN_FILENO, &stb1);
|
||||
gotstdin = 1;
|
||||
} else
|
||||
xstat(f1, &stb1);
|
||||
if (LONE_DASH(f2)) {
|
||||
xstat(argv[0], &stb1);
|
||||
if (strcmp(argv[1], "-") == 0) {
|
||||
fstat(STDIN_FILENO, &stb2);
|
||||
gotstdin = 1;
|
||||
} else
|
||||
xstat(f2, &stb2);
|
||||
xstat(argv[1], &stb2);
|
||||
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
|
||||
bb_error_msg_and_die("can't compare - to a directory");
|
||||
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
|
||||
#if ENABLE_FEATURE_DIFF_DIR
|
||||
diffdir(f1, f2);
|
||||
diffdir(argv[0], argv[1]);
|
||||
#else
|
||||
bb_error_msg_and_die("directory comparison not supported");
|
||||
#endif
|
||||
} else {
|
||||
if (S_ISDIR(stb1.st_mode)) {
|
||||
f1 = concat_path_file(f1, f2);
|
||||
xstat(f1, &stb1);
|
||||
argv[0] = concat_path_file(argv[0], argv[1]);
|
||||
xstat(argv[0], &stb1);
|
||||
}
|
||||
if (S_ISDIR(stb2.st_mode)) {
|
||||
f2 = concat_path_file(f2, f1);
|
||||
xstat(f2, &stb2);
|
||||
argv[1] = concat_path_file(argv[1], argv[0]);
|
||||
xstat(argv[1], &stb2);
|
||||
}
|
||||
/* XXX: FIXME: */
|
||||
/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek().
|
||||
* This can be fixed (volunteers?) */
|
||||
if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode))
|
||||
bb_error_msg_and_die("can't diff non-seekable stream");
|
||||
print_status(diffreg(f1, f2, 0), f1, f2, NULL);
|
||||
print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], NULL);
|
||||
}
|
||||
return status;
|
||||
exit(status);
|
||||
}
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int dirname_main(int argc, char **argv);
|
||||
int dirname_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
|
||||
@@ -82,7 +82,6 @@ static int convert(char *fn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char *argv[]);
|
||||
int dos2unix_main(int argc, char *argv[])
|
||||
{
|
||||
int o;
|
||||
|
||||
+37
-34
@@ -25,22 +25,26 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
# ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned long disp_hr = 1024;
|
||||
# else
|
||||
static unsigned long disp_hr = 512;
|
||||
# endif
|
||||
#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned disp_k = 1;
|
||||
#elif defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned int disp_k = 1;
|
||||
#else
|
||||
static unsigned disp_k; /* bss inits to 0 */
|
||||
static unsigned int disp_k; /* bss inits to 0 */
|
||||
#endif
|
||||
|
||||
static int max_print_depth = INT_MAX;
|
||||
static nlink_t count_hardlinks = 1;
|
||||
|
||||
static int status;
|
||||
static int status
|
||||
#if EXIT_SUCCESS == 0
|
||||
= EXIT_SUCCESS
|
||||
#endif
|
||||
;
|
||||
static int print_files;
|
||||
static int slink_depth;
|
||||
static int du_depth;
|
||||
@@ -51,9 +55,9 @@ static dev_t dir_dev;
|
||||
static void print(long size, const char * const filename)
|
||||
{
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
|
||||
filename);
|
||||
filename);
|
||||
#else
|
||||
if (disp_k) {
|
||||
size++;
|
||||
@@ -69,7 +73,7 @@ static long du(const char * const filename)
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
|
||||
if (lstat(filename, &statbuf) != 0) {
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
status = EXIT_FAILURE;
|
||||
return 0;
|
||||
@@ -87,7 +91,7 @@ static long du(const char * const filename)
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
if (slink_depth > du_depth) { /* -H or -L */
|
||||
if (stat(filename, &statbuf) != 0) {
|
||||
if ((stat(filename, &statbuf)) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
status = EXIT_FAILURE;
|
||||
return 0;
|
||||
@@ -101,7 +105,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)) {
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
@@ -126,7 +130,7 @@ static long du(const char * const filename)
|
||||
char *name = entry->d_name;
|
||||
|
||||
newfile = concat_subpath_file(filename, name);
|
||||
if (newfile == NULL)
|
||||
if(newfile == NULL)
|
||||
continue;
|
||||
++du_depth;
|
||||
sum += du(newfile);
|
||||
@@ -143,7 +147,6 @@ 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;
|
||||
@@ -152,9 +155,9 @@ int du_main(int argc, char **argv)
|
||||
char *smax_print_depth;
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K
|
||||
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
disp_hr = 512;
|
||||
#else
|
||||
disp_k = 0;
|
||||
@@ -168,62 +171,62 @@ int du_main(int argc, char **argv)
|
||||
* gnu du exits with an error code in this case. We choose to simply
|
||||
* ignore -a. This is consistent with -s being equivalent to -d 0.
|
||||
*/
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
|
||||
if (opt & (1 << 9)) {
|
||||
if((opt & (1 << 9))) {
|
||||
/* -h opt */
|
||||
disp_hr = 0;
|
||||
}
|
||||
if (opt & (1 << 10)) {
|
||||
if((opt & (1 << 10))) {
|
||||
/* -m opt */
|
||||
disp_hr = 1024*1024;
|
||||
}
|
||||
if (opt & (1 << 2)) {
|
||||
if((opt & (1 << 2))) {
|
||||
/* -k opt */
|
||||
disp_hr = 1024;
|
||||
}
|
||||
#else
|
||||
opt_complementary = "H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
|
||||
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (opt & (1 << 2)) {
|
||||
#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if((opt & (1 << 2))) {
|
||||
/* -k opt */
|
||||
disp_k = 1;
|
||||
disp_k = 1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (opt & (1 << 0)) {
|
||||
if((opt & (1 << 0))) {
|
||||
/* -a opt */
|
||||
print_files = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 1)) {
|
||||
if((opt & (1 << 1))) {
|
||||
/* -H opt */
|
||||
slink_depth = 1;
|
||||
}
|
||||
if (opt & (1 << 3)) {
|
||||
if((opt & (1 << 3))) {
|
||||
/* -L opt */
|
||||
slink_depth = INT_MAX;
|
||||
slink_depth = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 4)) {
|
||||
if((opt & (1 << 4))) {
|
||||
/* -s opt */
|
||||
max_print_depth = 0;
|
||||
}
|
||||
max_print_depth = 0;
|
||||
}
|
||||
one_file_system = opt & (1 << 5); /* -x opt */
|
||||
if (opt & (1 << 6)) {
|
||||
if((opt & (1 << 6))) {
|
||||
/* -d opt */
|
||||
max_print_depth = xatoi_u(smax_print_depth);
|
||||
}
|
||||
if (opt & (1 << 7)) {
|
||||
if((opt & (1 << 7))) {
|
||||
/* -l opt */
|
||||
count_hardlinks = MAXINT(nlink_t);
|
||||
count_hardlinks = INT_MAX;
|
||||
}
|
||||
print_final_total = opt & (1 << 8); /* -c opt */
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
argv += optind;
|
||||
if (optind >= argc) {
|
||||
*--argv = (char*)".";
|
||||
*--argv = ".";
|
||||
if (slink_depth == 1) {
|
||||
slink_depth = 0;
|
||||
}
|
||||
@@ -235,7 +238,7 @@ int du_main(int argc, char **argv)
|
||||
total += du(*argv);
|
||||
slink_depth = slink_depth_save;
|
||||
} while (*++argv);
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
#ifdef CONFIG_FEATURE_CLEAN_UP
|
||||
reset_ino_dev_hashtable();
|
||||
#endif
|
||||
|
||||
|
||||
+2
-3
@@ -29,7 +29,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int bb_echo(char **argv)
|
||||
int bb_echo(int ATTRIBUTE_UNUSED argc, char **argv)
|
||||
{
|
||||
#ifndef CONFIG_FEATURE_FANCY_ECHO
|
||||
#define eflag '\\'
|
||||
@@ -112,10 +112,9 @@ just_echo:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int echo_main(int argc, char** argv);
|
||||
int echo_main(int argc, char** argv)
|
||||
{
|
||||
(void)bb_echo(argv);
|
||||
(void)bb_echo(argc, argv);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
+9
-8
@@ -41,11 +41,10 @@ static const struct option env_long_options[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
int env_main(int argc, char** argv);
|
||||
int env_main(int argc, char** argv)
|
||||
{
|
||||
/* cleanenv was static - why? */
|
||||
char *cleanenv[1];
|
||||
static char *cleanenv[1] = { NULL };
|
||||
|
||||
char **ep;
|
||||
unsigned opt;
|
||||
llist_t *unset_env = NULL;
|
||||
@@ -55,16 +54,18 @@ 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])) {
|
||||
if (*argv && (argv[0][0] == '-') && !argv[0][1]) {
|
||||
opt |= 1;
|
||||
++argv;
|
||||
}
|
||||
if (opt & 1) {
|
||||
cleanenv[0] = NULL;
|
||||
|
||||
if (opt & 1)
|
||||
environ = cleanenv;
|
||||
} else if (opt & 2) {
|
||||
else if (opt & 2) {
|
||||
while (unset_env) {
|
||||
unsetenv(unset_env->data);
|
||||
unset_env = unset_env->link;
|
||||
@@ -79,7 +80,7 @@ int env_main(int argc, char** argv)
|
||||
}
|
||||
|
||||
if (*argv) {
|
||||
BB_EXECVP(*argv, argv);
|
||||
execvp(*argv, argv);
|
||||
/* SUSv3-mandated exit codes. */
|
||||
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
|
||||
bb_perror_msg_and_die("%s", *argv);
|
||||
|
||||
+12
-13
@@ -67,14 +67,13 @@ 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(const char *s);
|
||||
static int nextarg(const char *str);
|
||||
static VALUE *str_value(char *s);
|
||||
static int nextarg(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;
|
||||
@@ -111,7 +110,7 @@ static VALUE *int_value(arith_t i)
|
||||
|
||||
/* Return a VALUE for S. */
|
||||
|
||||
static VALUE *str_value(const char *s)
|
||||
static VALUE *str_value(char *s)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
@@ -136,8 +135,8 @@ static int null(VALUE * v)
|
||||
{
|
||||
if (v->type == integer)
|
||||
return v->u.i == 0;
|
||||
/* string: */
|
||||
return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
|
||||
else /* string: */
|
||||
return v->u.s[0] == '\0' || strcmp(v->u.s, "0") == 0;
|
||||
}
|
||||
|
||||
/* Coerce V to a string value (can't fail). */
|
||||
@@ -173,7 +172,7 @@ static int toarith(VALUE * v)
|
||||
/* Return nonzero if the next token matches STR exactly.
|
||||
STR must not be NULL. */
|
||||
|
||||
static int nextarg(const char *str)
|
||||
static int nextarg(char *str)
|
||||
{
|
||||
if (*args == NULL)
|
||||
return 0;
|
||||
@@ -194,16 +193,16 @@ static int cmp_common(VALUE * l, VALUE * r, int op)
|
||||
cmpval = l->u.i - r->u.i;
|
||||
if (op == '<')
|
||||
return cmpval < 0;
|
||||
if (op == ('L' + 'E'))
|
||||
else if (op == ('L' + 'E'))
|
||||
return cmpval <= 0;
|
||||
if (op == '=')
|
||||
else if (op == '=')
|
||||
return cmpval == 0;
|
||||
if (op == '!')
|
||||
else if (op == '!')
|
||||
return cmpval != 0;
|
||||
if (op == '>')
|
||||
else if (op == '>')
|
||||
return cmpval > 0;
|
||||
/* >= */
|
||||
return cmpval >= 0;
|
||||
else /* >= */
|
||||
return cmpval >= 0;
|
||||
}
|
||||
|
||||
/* The arithmetic operator handling functions. */
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#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
-3
@@ -38,7 +38,6 @@ 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;
|
||||
@@ -46,7 +45,7 @@ int fold_main(int argc, char **argv)
|
||||
int i;
|
||||
int errs = 0;
|
||||
|
||||
if (ENABLE_INCLUDE_SUSv2) {
|
||||
if(!ENABLE_DEBUG_YANK_SUSv2) {
|
||||
/* Turn any numeric options into -w options. */
|
||||
for (i = 1; i < argc; i++) {
|
||||
char const *a = argv[i];
|
||||
@@ -67,7 +66,7 @@ int fold_main(int argc, char **argv)
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
*--argv = (char*)"-";
|
||||
*--argv = "-";
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
+4
-5
@@ -31,7 +31,6 @@ 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;
|
||||
@@ -48,7 +47,7 @@ int head_main(int argc, char **argv)
|
||||
int c;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
/* Allow legacy syntax of an initial numeric option without -n. */
|
||||
if (argc > 1 && argv[1][0] == '-'
|
||||
&& isdigit(argv[1][1])
|
||||
@@ -76,8 +75,8 @@ int head_main(int argc, char **argv)
|
||||
#endif
|
||||
case 'n':
|
||||
p = optarg;
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
GET_COUNT:
|
||||
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
GET_COUNT:
|
||||
#endif
|
||||
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
@@ -93,7 +92,7 @@ int head_main(int argc, char **argv)
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
*--argv = (char*)"-";
|
||||
*--argv = "-";
|
||||
}
|
||||
|
||||
fmt = header_fmt_str + 1;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#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) {
|
||||
|
||||
+24
-43
@@ -10,7 +10,6 @@
|
||||
/* 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"
|
||||
@@ -18,13 +17,14 @@
|
||||
#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,7 +39,6 @@ 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;
|
||||
@@ -47,13 +46,11 @@ 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" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
|
||||
flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z"));
|
||||
opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug";
|
||||
flags = getopt32(argc, argv, "rnug");
|
||||
|
||||
/* This values could be overwritten later */
|
||||
uid = geteuid();
|
||||
@@ -65,39 +62,20 @@ int id_main(int argc, char **argv)
|
||||
|
||||
if (argv[optind]) {
|
||||
p = getpwnam(argv[optind]);
|
||||
/* xuname2uid is needed because it exits on failure */
|
||||
uid = xuname2uid(argv[optind]);
|
||||
/* bb_xgetpwnam is needed because it exits on failure */
|
||||
uid = bb_xgetpwnam(argv[optind]);
|
||||
gid = p->pw_gid;
|
||||
/* in this case PRINT_REAL is the same */
|
||||
}
|
||||
|
||||
if (flags & (JUST_GROUP | JUST_USER USE_SELINUX(| JUST_CONTEXT))) {
|
||||
if (flags & (JUST_GROUP | JUST_USER)) {
|
||||
/* 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 {
|
||||
if (flags & JUST_USER) {
|
||||
printf("%u\n", uid);
|
||||
}
|
||||
if (flags & JUST_GROUP) {
|
||||
printf("%u\n", gid);
|
||||
}
|
||||
printf("%u\n", (flags & JUST_USER) ? uid : 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);
|
||||
}
|
||||
@@ -109,18 +87,21 @@ 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');
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
#ifdef CONFIG_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
security_context_t mysid;
|
||||
const char *context;
|
||||
security_context_t mysid;
|
||||
char context[80];
|
||||
int len = sizeof(context);
|
||||
|
||||
context = "unknown";
|
||||
getcon(&mysid);
|
||||
if (mysid) {
|
||||
context = alloca(strlen(mysid) + 1);
|
||||
strcpy((char*)context, mysid);
|
||||
freecon(mysid);
|
||||
}
|
||||
getcon(&mysid);
|
||||
context[0] = '\0';
|
||||
if (mysid) {
|
||||
len = strlen(mysid)+1;
|
||||
safe_strncpy(context, mysid, len);
|
||||
freecon(mysid);
|
||||
} else {
|
||||
safe_strncpy(context, "unknown", 8);
|
||||
}
|
||||
printf(" context=%s", context);
|
||||
}
|
||||
#endif
|
||||
|
||||
+43
-114
@@ -1,7 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
|
||||
* SELinux support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
@@ -14,123 +13,58 @@
|
||||
#include <libgen.h>
|
||||
#include <getopt.h> /* struct option */
|
||||
|
||||
#define INSTALL_OPT_CMD 1
|
||||
#define INSTALL_OPT_DIRECTORY 2
|
||||
#define INSTALL_OPT_PRESERVE_TIME 4
|
||||
#define INSTALL_OPT_STRIP 8
|
||||
#define INSTALL_OPT_GROUP 16
|
||||
#define INSTALL_OPT_MODE 32
|
||||
#define INSTALL_OPT_OWNER 64
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
static const struct option install_long_options[] = {
|
||||
{ "directory", 0, NULL, 'd' },
|
||||
{ "preserve-timestamps", 0, NULL, 'p' },
|
||||
{ "strip", 0, NULL, 's' },
|
||||
{ "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 }
|
||||
{ "directory", 0, NULL, 'd' },
|
||||
{ "preserve-timestamps", 0, NULL, 'p' },
|
||||
{ "strip", 0, NULL, 's' },
|
||||
{ "group", 0, NULL, 'g' },
|
||||
{ "mode", 0, NULL, 'm' },
|
||||
{ "owner", 0, NULL, 'o' },
|
||||
{ 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;
|
||||
mode_t mode;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
const char *gid_str;
|
||||
const char *uid_str;
|
||||
const char *mode_str;
|
||||
char *gid_str = "-1";
|
||||
char *uid_str = "-1";
|
||||
char *mode_str = "0755";
|
||||
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,
|
||||
OPT_PRESERVE_TIME = 0x4,
|
||||
OPT_STRIP = 0x8,
|
||||
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" 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
|
||||
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); /* 'a' must be 2nd */
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
|
||||
if (flags & OPT_PRESERVE_TIME) {
|
||||
if (flags & INSTALL_OPT_PRESERVE_TIME) {
|
||||
copy_flags |= FILEUTILS_PRESERVE_STATUS;
|
||||
}
|
||||
mode = 0666;
|
||||
if (flags & OPT_MODE) bb_parse_mode(mode_str, &mode);
|
||||
uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
if (flags & (OPT_OWNER|OPT_GROUP)) umask(0);
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
gid = get_ug_id(gid_str, bb_xgetgrnam);
|
||||
uid = get_ug_id(uid_str, bb_xgetpwnam);
|
||||
umask(0);
|
||||
|
||||
/* Create directories
|
||||
* don't use bb_make_directory() as it can't change uid or gid
|
||||
* perhaps bb_make_directory() should be improved.
|
||||
*/
|
||||
if (flags & OPT_DIRECTORY) {
|
||||
if (flags & INSTALL_OPT_DIRECTORY) {
|
||||
for (argv += optind; *argv; argv++) {
|
||||
char *old_argv_ptr = *argv + 1;
|
||||
char *argv_ptr;
|
||||
@@ -141,16 +75,14 @@ int install_main(int argc, char **argv)
|
||||
*argv_ptr = '\0';
|
||||
old_argv_ptr++;
|
||||
}
|
||||
if (mkdir(*argv, mode | 0111) == -1) {
|
||||
if (mkdir(*argv, mode) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
bb_perror_msg("cannot create %s", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((flags & (OPT_OWNER|OPT_GROUP))
|
||||
&& lchown(*argv, uid, gid) == -1
|
||||
) {
|
||||
else if (lchown(*argv, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
@@ -163,39 +95,36 @@ int install_main(int argc, char **argv)
|
||||
return ret;
|
||||
}
|
||||
|
||||
isdir = lstat(argv[argc - 1], &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
|
||||
|
||||
{
|
||||
struct stat statbuf;
|
||||
isdir = lstat(argv[argc - 1], &statbuf)<0
|
||||
? 0 : S_ISDIR(statbuf.st_mode);
|
||||
}
|
||||
for (i = optind; i < argc - 1; i++) {
|
||||
char *dest;
|
||||
|
||||
dest = argv[argc - 1];
|
||||
if (isdir)
|
||||
dest = concat_path_file(argv[argc - 1], basename(argv[i]));
|
||||
if (isdir) dest = concat_path_file(argv[argc - 1], basename(argv[i]));
|
||||
ret |= copy_file(argv[i], dest, copy_flags);
|
||||
|
||||
/* Set the file mode */
|
||||
if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
|
||||
if (chmod(dest, mode) == -1) {
|
||||
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
|
||||
) {
|
||||
if (lchown(dest, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", dest);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
if (flags & OPT_STRIP) {
|
||||
if (BB_EXECLP("strip", "strip", dest, NULL) == -1) {
|
||||
bb_perror_msg("strip");
|
||||
if (flags & INSTALL_OPT_STRIP) {
|
||||
if (execlp("strip", "strip", dest, NULL) == -1) {
|
||||
bb_error_msg("strip failed");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
|
||||
if(ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#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,22 +30,11 @@ mode_t getopt_mk_fifo_nod(int argc, char **argv)
|
||||
{
|
||||
mode_t mode = 0666;
|
||||
char *smode = NULL;
|
||||
#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) {
|
||||
|
||||
getopt32(argc, argv, "m:", &smode);
|
||||
if(smode) {
|
||||
if (bb_parse_mode(smode, &mode))
|
||||
umask(0);
|
||||
}
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 2) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
#endif
|
||||
|
||||
return mode;
|
||||
}
|
||||
+1
-2
@@ -19,7 +19,6 @@
|
||||
#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;
|
||||
@@ -27,7 +26,7 @@ int ln_main(int argc, char **argv)
|
||||
char *last;
|
||||
char *src_name;
|
||||
char *src;
|
||||
char *suffix = (char*)"~";
|
||||
char *suffix = "~";
|
||||
struct stat statbuf;
|
||||
int (*link_func)(const char *, const char *);
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#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
-37
@@ -156,13 +156,13 @@ enum {
|
||||
|
||||
static int status = EXIT_SUCCESS;
|
||||
|
||||
static struct dnode *my_stat(char *fullname, char *name, int force_follow)
|
||||
static struct dnode *my_stat(char *fullname, char *name)
|
||||
{
|
||||
struct stat dstat;
|
||||
struct dnode *cur;
|
||||
USE_SELINUX(security_context_t sid = NULL;)
|
||||
|
||||
if ((all_fmt & FOLLOW_LINKS) || force_follow) {
|
||||
if (all_fmt & FOLLOW_LINKS) {
|
||||
#if ENABLE_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
getfilecon(fullname, &sid);
|
||||
@@ -176,7 +176,7 @@ static struct dnode *my_stat(char *fullname, char *name, int force_follow)
|
||||
} else {
|
||||
#if ENABLE_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
lgetfilecon(fullname, &sid);
|
||||
lgetfilecon(fullname,&sid);
|
||||
}
|
||||
#endif
|
||||
if (lstat(fullname, &dstat)) {
|
||||
@@ -291,7 +291,7 @@ static void dfree(struct dnode **dnp, int nfiles)
|
||||
free(dnp); /* free the array holding the dnode pointers */
|
||||
}
|
||||
#else
|
||||
#define dfree(...) ((void)0)
|
||||
#define dfree(...) do {} while(0)
|
||||
#endif
|
||||
|
||||
static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
|
||||
@@ -375,7 +375,7 @@ static void dnsort(struct dnode **dn, int size)
|
||||
qsort(dn, size, sizeof(*dn), sortcmp);
|
||||
}
|
||||
#else
|
||||
#define dnsort(dn, size) ((void)0)
|
||||
#define dnsort(dn, size) do {} while(0)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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, 0);
|
||||
cur = my_stat(fullname, strrchr(fullname, '/') + 1);
|
||||
if (!cur) {
|
||||
free(fullname);
|
||||
continue;
|
||||
@@ -537,16 +537,13 @@ static struct dnode **list_dir(const char *path)
|
||||
}
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
/* Do time() just once. Saves one syscall per file for "ls -l" */
|
||||
/* Initialized in main() */
|
||||
static time_t current_time_t;
|
||||
#endif
|
||||
|
||||
static int list_single(struct dnode *dn)
|
||||
{
|
||||
int i, column = 0;
|
||||
|
||||
#if ENABLE_FEATURE_LS_USERNAME
|
||||
char scratch[16];
|
||||
#endif
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
char *filetime;
|
||||
time_t ttime, age;
|
||||
@@ -587,9 +584,10 @@ static int list_single(struct dnode *dn)
|
||||
break;
|
||||
case LIST_ID_NAME:
|
||||
#if ENABLE_FEATURE_LS_USERNAME
|
||||
printf("%-8.8s %-8.8s",
|
||||
get_cached_username(dn->dstat.st_uid),
|
||||
get_cached_groupname(dn->dstat.st_gid));
|
||||
bb_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
|
||||
printf("%-8.8s ", scratch);
|
||||
bb_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
|
||||
printf("%-8.8s", scratch);
|
||||
column += 17;
|
||||
break;
|
||||
#endif
|
||||
@@ -617,8 +615,7 @@ static int list_single(struct dnode *dn)
|
||||
break;
|
||||
case LIST_DATE_TIME:
|
||||
if ((all_fmt & LIST_FULLTIME) == 0) {
|
||||
/* current_time_t ~== time(NULL) */
|
||||
age = current_time_t - ttime;
|
||||
age = time(NULL) - ttime;
|
||||
printf("%6.6s ", filetime + 4);
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
|
||||
/* hh:mm if less than 6 months old */
|
||||
@@ -664,7 +661,7 @@ static int list_single(struct dnode *dn)
|
||||
break;
|
||||
case LIST_SYMLINK:
|
||||
if (S_ISLNK(dn->dstat.st_mode)) {
|
||||
char *lpath = xmalloc_readlink_or_warn(dn->fullname);
|
||||
char *lpath = xreadlink(dn->fullname);
|
||||
if (!lpath) break;
|
||||
printf(" -> ");
|
||||
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
|
||||
@@ -716,8 +713,7 @@ 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_SELINUX("Z");
|
||||
USE_FEATURE_AUTOWIDTH("T:w:");
|
||||
|
||||
enum {
|
||||
LIST_MASK_TRIGGER = 0,
|
||||
@@ -769,18 +765,11 @@ 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;
|
||||
@@ -800,10 +789,6 @@ int ls_main(int argc, char **argv)
|
||||
USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;)
|
||||
USE_FEATURE_LS_COLOR(char *color_opt;)
|
||||
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
time(¤t_time_t);
|
||||
#endif
|
||||
|
||||
all_fmt = LIST_SHORT |
|
||||
(ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD));
|
||||
|
||||
@@ -824,7 +809,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)) {
|
||||
@@ -842,9 +827,8 @@ int ls_main(int argc, char **argv)
|
||||
all_fmt &= ~TIME_MASK;
|
||||
if (flags & LIST_CONTEXT)
|
||||
all_fmt |= STYLE_SINGLE;
|
||||
/* huh?? opt cannot be 'l' */
|
||||
//if (LS_DISP_HR && opt == 'l')
|
||||
// all_fmt &= ~LS_DISP_HR;
|
||||
if (LS_DISP_HR && opt == 'l')
|
||||
all_fmt &= ~LS_DISP_HR;
|
||||
all_fmt |= flags;
|
||||
}
|
||||
}
|
||||
@@ -910,8 +894,7 @@ 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++) {
|
||||
/* ls w/o -l follows links on command line */
|
||||
cur = my_stat(av[oi], av[oi], !(all_fmt & STYLE_LONG));
|
||||
cur = my_stat(av[oi], av[oi]);
|
||||
if (!cur)
|
||||
continue;
|
||||
cur->allocated = 0;
|
||||
|
||||
@@ -18,9 +18,11 @@ typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
|
||||
static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
|
||||
unsigned hash_length)
|
||||
{
|
||||
/* xzalloc zero-terminates */
|
||||
char *hex_value = xzalloc((hash_length * 2) + 1);
|
||||
bin2hex(hex_value, (char*)hash_value, hash_length);
|
||||
int len = 0;
|
||||
char *hex_value = xmalloc((hash_length * 2) + 2);
|
||||
while (hash_length--) {
|
||||
len += sprintf(hex_value + len, "%02x", *hash_value++);
|
||||
}
|
||||
return hex_value;
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
|
||||
void (*final)(void*, void*);
|
||||
|
||||
src_fd = STDIN_FILENO;
|
||||
if (NOT_LONE_DASH(filename)) {
|
||||
if (filename[0] != '-' || filename[1]) { /* not "-" */
|
||||
src_fd = open(filename, O_RDONLY);
|
||||
if (src_fd < 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
@@ -78,7 +80,6 @@ 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;
|
||||
@@ -103,7 +104,7 @@ int md5_sha1_sum_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (argc == optind) {
|
||||
argv[argc++] = (char*)"-";
|
||||
argv[argc++] = "-";
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
|
||||
@@ -119,7 +120,7 @@ int md5_sha1_sum_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
pre_computed_stream = stdin;
|
||||
if (NOT_LONE_DASH(file_ptr)) {
|
||||
if (file_ptr[0] != '-' || file_ptr[1]) { /* not "-" */
|
||||
pre_computed_stream = xfopen(file_ptr, "r");
|
||||
}
|
||||
|
||||
|
||||
+1
-17
@@ -16,9 +16,6 @@
|
||||
* 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 */
|
||||
@@ -28,14 +25,10 @@
|
||||
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);
|
||||
@@ -43,14 +36,11 @@ 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" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
|
||||
opt = getopt32(argc, argv, "m:p", &smode);
|
||||
if (opt & 1) {
|
||||
mode = 0777;
|
||||
if (!bb_parse_mode(smode, &mode)) {
|
||||
@@ -59,12 +49,6 @@ 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,7 +16,6 @@
|
||||
#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,7 +17,6 @@
|
||||
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;
|
||||
|
||||
+2
-8
@@ -3,7 +3,6 @@
|
||||
* 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.
|
||||
*/
|
||||
@@ -36,7 +35,6 @@ 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;
|
||||
@@ -45,7 +43,6 @@ 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;
|
||||
@@ -115,11 +112,8 @@ DO_MOVE:
|
||||
goto RET_1;
|
||||
}
|
||||
}
|
||||
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) &&
|
||||
if ((copy_file(*argv, dest,
|
||||
FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) &&
|
||||
(remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) {
|
||||
goto RET_0;
|
||||
}
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@
|
||||
#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;
|
||||
@@ -47,7 +46,7 @@ int nice_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
BB_EXECVP(*argv, argv); /* Now exec the desired program. */
|
||||
execvp(*argv, argv); /* Now exec the desired program. */
|
||||
|
||||
/* The exec failed... */
|
||||
xfunc_error_retval = (errno == ENOENT) ? 127 : 126; /* SUSv3 */
|
||||
|
||||
+12
-19
@@ -12,21 +12,18 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int nohup_main(int argc, char **argv);
|
||||
int nohup_main(int argc, char **argv)
|
||||
{
|
||||
int nullfd;
|
||||
const char *nohupout;
|
||||
char *home = NULL;
|
||||
int temp, nullfd;
|
||||
char *nohupout, *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". */
|
||||
@@ -41,20 +38,16 @@ int nohup_main(int argc, char **argv)
|
||||
}
|
||||
} else dup2(nullfd, STDOUT_FILENO);
|
||||
|
||||
/* If we have a tty on stderr, announce filename and redirect to stdout.
|
||||
/* If we have a tty on strderr, announce filename and redirect to stdout.
|
||||
* Else redirect to /dev/null.
|
||||
*/
|
||||
if (isatty(STDERR_FILENO)) {
|
||||
bb_error_msg("appending to %s", nohupout);
|
||||
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||
} else dup2(nullfd, STDERR_FILENO);
|
||||
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 (nullfd > 2)
|
||||
close(nullfd);
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
|
||||
BB_EXECVP(argv[1], argv+1);
|
||||
if (ENABLE_FEATURE_CLEAN_UP && home)
|
||||
free((char*)nohupout);
|
||||
execvp(argv[1],argv+1);
|
||||
if (00 && ENABLE_FEATURE_CLEAN_UP && home) free(nohupout);
|
||||
bb_perror_msg_and_die("%s", argv[1]);
|
||||
}
|
||||
Loaded 100 of 622 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user