Compare commits
39
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f8880d233 | ||
|
|
d905e44d47 | ||
|
|
5eda15566a | ||
|
|
c5907cc380 | ||
|
|
88c0e01caf | ||
|
|
2f49047deb | ||
|
|
2a5044cc46 | ||
|
|
3f762e4025 | ||
|
|
e78e45e801 | ||
|
|
7a95dd6f82 | ||
|
|
e76da05b75 | ||
|
|
ab76d3acfd | ||
|
|
258685a2e5 | ||
|
|
d3986eb7ec | ||
|
|
9e78a1772d | ||
|
|
f7c7dde158 | ||
|
|
830c040f6f | ||
|
|
045dedad91 | ||
|
|
b309ec71c8 | ||
|
|
866bad310f | ||
|
|
5e1f2d429d | ||
|
|
0be69b1693 | ||
|
|
c7cba1ae3b | ||
|
|
be3dae145f | ||
|
|
6022fc8723 | ||
|
|
fc455b2101 | ||
|
|
365a345e92 | ||
|
|
d5138f44fe | ||
|
|
9344d8aa10 | ||
|
|
44dbd4bc65 | ||
|
|
25b8652b4f | ||
|
|
091a3e510e | ||
|
|
ffaa3deeeb | ||
|
|
5f07779aca | ||
|
|
ab6399a4c6 | ||
|
|
ca17c937c2 | ||
|
|
d62df011a0 | ||
|
|
164a716f96 | ||
|
|
8c59a0bf0e |
No files matched your search
@@ -1,7 +0,0 @@
|
||||
busybox
|
||||
busybox.links
|
||||
_install
|
||||
.config
|
||||
.menuconfig.log
|
||||
.config.cmd
|
||||
.config.old
|
||||
@@ -2,18 +2,20 @@ List of the authors of code contained in BusyBox.
|
||||
|
||||
If you have code in BusyBox, you should be listed here. If you should be
|
||||
listed, or the description of what you have done needs more detail, or is
|
||||
incorect, _please_ let me know.
|
||||
incorrect, _please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
Emanuele Aina <emanuele.aina@tiscali.it>
|
||||
run-parts
|
||||
run-parts
|
||||
|
||||
Erik Andersen <andersen@codepoet.org>, <andersen@codepoet.org>
|
||||
Erik Andersen <andersen@codepoet.org>
|
||||
Tons of new stuff, major rewrite of most of the
|
||||
core apps, tons of new apps as noted in header files.
|
||||
Lots of tedious effort writing these boring docs that
|
||||
nobody is going to actually read.
|
||||
|
||||
Laurence Anderson <l.d.anderson@warwick.ac.uk>
|
||||
rpm2cpio, unzip, get_header_cpio, read_gz interface, rpm
|
||||
@@ -21,24 +23,27 @@ Laurence Anderson <l.d.anderson@warwick.ac.uk>
|
||||
Jeff Angielski <jeff@theptrgroup.com>
|
||||
ftpput, ftpget
|
||||
|
||||
Jim Bauer <jfbauer@nfr.com>
|
||||
modprobe shell dependency
|
||||
|
||||
Edward Betts <edward@debian.org>
|
||||
expr, hostid, logname, tty, wc, whoami, yes
|
||||
|
||||
expr, hostid, logname, whoami
|
||||
|
||||
John Beppu <beppu@codepoet.org>
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
du, nslookup, sort
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
|
||||
Randolph Chung <tausq@debian.org>
|
||||
fbset, ping, hostname, and mkfifo
|
||||
fbset, ping, hostname
|
||||
|
||||
Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
Jordan Crouse <jordan@cosmicpenguin.net>
|
||||
ipcalc
|
||||
ipcalc
|
||||
|
||||
Magnus Damm <damm@opensource.se>
|
||||
tftp client
|
||||
@@ -54,6 +59,10 @@ Gennady Feldman <gfeldman@gena01.com>
|
||||
Sysklogd (single threaded syslogd, IPC Circular buffer support,
|
||||
logread), various fixes.
|
||||
|
||||
Robert Griebl <sandman@handhelds.org>
|
||||
modprobe, hwclock, suid/sgid handling, tinylogin integration
|
||||
many bugfixes and enhancements
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
|
||||
@@ -63,14 +72,31 @@ Daniel Jacobowitz <dan@debian.org>
|
||||
Matt Kraai <kraai@alumni.cmu.edu>
|
||||
documentation, bugfixes, test suite
|
||||
|
||||
Rob Landley <rob@landley.net>
|
||||
sed (major rewrite in 2003, and I now maintain the thing).
|
||||
bunzip2 (complete from-scratch rewrite, then mjn3 optimized the result.)
|
||||
I've patched lots of other applets, but don't maintain 'em.
|
||||
|
||||
Stephan Linz <linz@li-pro.net>
|
||||
ipcalc, Red Hat equivalence
|
||||
ipcalc, Red Hat equivalence
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
John Lombardo <john@deltanet.com>
|
||||
tr
|
||||
|
||||
Glenn McGrath <bug1@optushome.com.au>
|
||||
ar, dpkg, dpkg-deb
|
||||
Glenn McGrath <bug1@iinet.net.au>
|
||||
Common unarchiving code and unarchiving applets, ifupdown, ftpgetput,
|
||||
nameif, sed, patch, fold, install, uudecode.
|
||||
Various bugfixes, review and apply numerous patches.
|
||||
|
||||
Manuel Novoa III <mjn3@codepoet.org>
|
||||
cat, head, mkfifo, mknod, rmdir, sleep, tee, tty, uniq, usleep, wc, yes,
|
||||
mesg, vconfig, make_directory, parse_mode, dirname, mode_string,
|
||||
get_last_path_component, simplify_path, and a number trivial libbb routines
|
||||
|
||||
also bug fixes, partial rewrites, and size optimizations in
|
||||
ash, basename, cal, cmp, cp, df, du, echo, env, ln, logname, md5sum, mkdir,
|
||||
mv, realpath, rm, sort, tail, touch, uname, watch, arith, human_readable,
|
||||
interface, dutmp, ifconfig, route
|
||||
|
||||
Vladimir Oleynik <dzo@simtreas.ru>
|
||||
cmdedit; xargs(current), httpd(current);
|
||||
@@ -79,7 +105,7 @@ Vladimir Oleynik <dzo@simtreas.ru>
|
||||
and irreconcilable critic of everything not perfect.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox in 1995, 1996. Some of his code can
|
||||
Original author of BusyBox in 1995, 1996. Some of his code can
|
||||
still be found hiding here and there...
|
||||
|
||||
Tim Riker <Tim@Rikers.org>
|
||||
@@ -109,3 +135,7 @@ Charles P. Wright <cpwright@villagenet.com>
|
||||
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
Tito Ragusa <farmatito@tiscali.it>
|
||||
devfsd and size optimizations in strings, openvt, chvt, deallocvt, hdparm and fdformat.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
1) Run 'make config' or 'make menuconfig' and select the
|
||||
1) Run 'make config' or 'make menuconfig' and select the
|
||||
functionality that you wish to enable.
|
||||
|
||||
2) Run 'make dep'
|
||||
|
||||
3) Check the Makefile for any Makefile setting you wish
|
||||
to adjust for your system (things like like setting
|
||||
3) Check the Makefile for any Makefile setting you wish
|
||||
to adjust for your system (things like like setting
|
||||
your cross compiler, adjusting optimizations, etc)
|
||||
|
||||
4) Run 'make'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -23,59 +23,149 @@
|
||||
noconfig_targets := menuconfig config oldconfig randconfig \
|
||||
defconfig allyesconfig allnoconfig clean distclean \
|
||||
release tags
|
||||
TOPDIR=./
|
||||
include Rules.mak
|
||||
|
||||
ifndef TOPDIR
|
||||
TOPDIR=$(CURDIR)/
|
||||
endif
|
||||
ifndef top_srcdir
|
||||
top_srcdir=$(CURDIR)
|
||||
endif
|
||||
ifndef top_builddir
|
||||
top_builddir=$(CURDIR)
|
||||
endif
|
||||
|
||||
export srctree=$(top_srcdir)
|
||||
vpath %/Config.in $(srctree)
|
||||
|
||||
include $(top_builddir)/Rules.mak
|
||||
|
||||
DIRS:=applets archival archival/libunarchive coreutils console-tools \
|
||||
debianutils editors findutils init miscutils modutils networking \
|
||||
networking/libiproute networking/udhcp procps loginutils shell \
|
||||
sysklogd util-linux libpwdgrp coreutils/libcoreutils libbb
|
||||
|
||||
SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
|
||||
|
||||
ifeq ($(strip $(CONFIG_SELINUX)),y)
|
||||
CFLAGS += -I/usr/include/selinux
|
||||
LIBRARIES += -lsecure
|
||||
LIBRARIES += -lselinux
|
||||
endif
|
||||
|
||||
CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
|
||||
CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
|
||||
|
||||
ALL_DIRS:= $(DIRS) scripts/config
|
||||
ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
|
||||
|
||||
ifeq ($(KBUILD_SRC),)
|
||||
|
||||
ifdef O
|
||||
ifeq ("$(origin O)", "command line")
|
||||
KBUILD_OUTPUT := $(O)
|
||||
endif
|
||||
endif
|
||||
|
||||
# That's our default target when none is given on the command line
|
||||
.PHONY: _all
|
||||
_all:
|
||||
|
||||
ifneq ($(KBUILD_OUTPUT),)
|
||||
# Invoke a second make in the output directory, passing relevant variables
|
||||
# check that the output directory actually exists
|
||||
saved-output := $(KBUILD_OUTPUT)
|
||||
KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
|
||||
$(if $(wildcard $(KBUILD_OUTPUT)),, \
|
||||
$(error output directory "$(saved-output)" does not exist))
|
||||
|
||||
.PHONY: $(MAKECMDGOALS)
|
||||
|
||||
$(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
|
||||
$(MAKE) -C $(KBUILD_OUTPUT) \
|
||||
top_srcdir=$(CURDIR) \
|
||||
top_builddir=$(KBUILD_OUTPUT) \
|
||||
TOPDIR=$(KBUILD_OUTPUT) \
|
||||
KBUILD_SRC=$(CURDIR) \
|
||||
-f $(CURDIR)/Makefile $@
|
||||
|
||||
$(KBUILD_OUTPUT)/Rules.mak:
|
||||
@echo > $@
|
||||
@echo top_srcdir=$(CURDIR) >> $@
|
||||
@echo top_builddir=$(KBUILD_OUTPUT) >> $@
|
||||
@echo include $(top_srcdir)/Rules.mak >> $@
|
||||
|
||||
$(KBUILD_OUTPUT)/Makefile:
|
||||
@echo > $@
|
||||
@echo top_srcdir=$(CURDIR) >> $@
|
||||
@echo top_builddir=$(KBUILD_OUTPUT) >> $@
|
||||
@echo KBUILD_SRC='$$(top_srcdir)' >> $@
|
||||
@echo include '$$(KBUILD_SRC)'/Makefile >> $@
|
||||
|
||||
# Leave processing to above invocation of make
|
||||
skip-makefile := 1
|
||||
endif # ifneq ($(KBUILD_OUTPUT),)
|
||||
endif # ifeq ($(KBUILD_SRC),)
|
||||
|
||||
ifeq ($(skip-makefile),)
|
||||
|
||||
_all: all
|
||||
|
||||
ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
|
||||
|
||||
all: busybox busybox.links doc
|
||||
|
||||
# In this section, we need .config
|
||||
-include .config.cmd
|
||||
include $(patsubst %,%/Makefile.in, $(DIRS))
|
||||
all_tree: $(ALL_MAKEFILES)
|
||||
|
||||
busybox: .depend include/config.h $(libraries-y)
|
||||
$(CC) $(LDFLAGS) -o $@ $(libraries-y) $(LIBRARIES)
|
||||
$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
|
||||
d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
|
||||
|
||||
# In this section, we need .config
|
||||
-include $(top_builddir)/.config.cmd
|
||||
include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
busybox: $(ALL_MAKEFILES) .depend include/config.h $(libraries-y)
|
||||
$(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
|
||||
$(STRIPCMD) $@
|
||||
|
||||
busybox.links: applets/busybox.mkll include/config.h
|
||||
busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
|
||||
- $(SHELL) $^ >$@
|
||||
|
||||
install: applets/install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX)
|
||||
ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
|
||||
@echo
|
||||
@echo
|
||||
@echo --------------------------------------------------
|
||||
@echo You will probably need to make your busybox binary
|
||||
@echo setuid root to ensure all configured applets will
|
||||
@echo work properly.
|
||||
@echo --------------------------------------------------
|
||||
@echo
|
||||
endif
|
||||
|
||||
uninstall: busybox busybox.links
|
||||
for i in `cat busybox.links` ; do rm -f $$PREFIX$$i; done
|
||||
uninstall: busybox.links
|
||||
rm -f $(PREFIX)/bin/busybox
|
||||
for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
|
||||
|
||||
install-hardlinks: applets/install.sh busybox busybox.links
|
||||
install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX) --hardlinks
|
||||
|
||||
check: busybox
|
||||
bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
|
||||
$(top_srcdir)/testsuite/runtest
|
||||
|
||||
# Documentation Targets
|
||||
doc: olddoc
|
||||
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
# Old Docs...
|
||||
olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
docs/busybox.pod : docs/busybox_header.pod include/usage.h docs/busybox_footer.pod
|
||||
- ( cat docs/busybox_header.pod; \
|
||||
docs/autodocifier.pl include/usage.h; \
|
||||
cat docs/busybox_footer.pod ) > docs/busybox.pod
|
||||
docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
|
||||
-mkdir -p docs
|
||||
- ( cat $(top_srcdir)/docs/busybox_header.pod; \
|
||||
$(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
|
||||
cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
$(SECHO)
|
||||
$(SECHO) BusyBox Documentation
|
||||
$(SECHO)
|
||||
-mkdir -p docs
|
||||
-pod2text $< > $@
|
||||
|
||||
@@ -87,7 +177,7 @@ docs/BusyBox.1: docs/busybox.pod
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
- mkdir -p docs
|
||||
-@ rm -f docs/BusyBox.html
|
||||
-@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
|
||||
-@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
|
||||
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
-@ mkdir -p docs/busybox.net
|
||||
@@ -95,69 +185,37 @@ docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
docs/busybox.net/BusyBox.html
|
||||
-@ rm -f pod2htm*
|
||||
|
||||
|
||||
# New docs based on DOCBOOK SGML
|
||||
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
|
||||
|
||||
docs/busybox.txt: docs/busybox.sgml
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b txt busybox.sgml)
|
||||
|
||||
docs/busybox.dvi: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b dvi busybox.sgml)
|
||||
|
||||
docs/busybox.ps: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b ps busybox.sgml)
|
||||
|
||||
docs/busybox.pdf: docs/busybox.ps
|
||||
- mkdir -p docs
|
||||
(cd docs; ps2pdf busybox.ps)
|
||||
|
||||
docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs/busybox.net; sgmltools -b html ../busybox.sgml)
|
||||
|
||||
# The nifty new buildsystem stuff
|
||||
scripts/mkdep: scripts/mkdep.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
|
||||
scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
|
||||
|
||||
scripts/split-include: scripts/split-include.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
|
||||
scripts/split-include: $(top_srcdir)/scripts/split-include.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
|
||||
|
||||
.depend: scripts/mkdep
|
||||
.depend: scripts/mkdep include/config.h
|
||||
rm -f .depend .hdepend;
|
||||
mkdir -p include/config;
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
|
||||
scripts/mkdep -I include -- \
|
||||
`find . -name \*.c -print` >> .depend;
|
||||
`find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
|
||||
scripts/mkdep -I include -- \
|
||||
`find . -name \*.h -print` >> .hdepend;
|
||||
$(MAKE) $(patsubst %,_sfdep_%,$(DIRS)) _FASTDEP_ALL_SUB_DIRS="$(DIRS)" ;
|
||||
`find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
|
||||
|
||||
depend dep: include/config.h .depend
|
||||
depend dep: .depend
|
||||
|
||||
include/config/MARKER: depend scripts/split-include
|
||||
scripts/split-include include/config.h include/config
|
||||
@ touch include/config/MARKER
|
||||
|
||||
include/config.h: .config
|
||||
@if [ ! -x ./scripts/config/conf ] ; then \
|
||||
make -C scripts/config conf; \
|
||||
@if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
|
||||
$(MAKE) -C scripts/config conf; \
|
||||
fi;
|
||||
@./scripts/config/conf -o sysdeps/$(TARGET_OS)/Config.in
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
@$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
|
||||
|
||||
finished2:
|
||||
@echo
|
||||
@echo Finished installing...
|
||||
@echo
|
||||
$(SECHO)
|
||||
$(SECHO) Finished installing...
|
||||
$(SECHO)
|
||||
|
||||
else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
|
||||
|
||||
@@ -166,56 +224,56 @@ all: menuconfig
|
||||
# configuration
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
scripts/config/conf:
|
||||
make -C scripts/config conf
|
||||
$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
|
||||
d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
|
||||
|
||||
scripts/config/conf: scripts/config/Makefile Rules.mak
|
||||
$(MAKE) -C scripts/config conf
|
||||
-@if [ ! -f .config ] ; then \
|
||||
cp sysdeps/$(TARGET_OS)/defconfig .config; \
|
||||
cp $(CONFIG_DEFCONFIG) .config; \
|
||||
fi
|
||||
scripts/config/mconf:
|
||||
make -C scripts/config ncurses conf mconf
|
||||
|
||||
scripts/config/mconf: scripts/config/Makefile Rules.mak
|
||||
$(MAKE) -C scripts/config ncurses conf mconf
|
||||
-@if [ ! -f .config ] ; then \
|
||||
cp sysdeps/$(TARGET_OS)/defconfig .config; \
|
||||
cp $(CONFIG_DEFCONFIG) .config; \
|
||||
fi
|
||||
|
||||
menuconfig: scripts/config/mconf
|
||||
@./scripts/config/mconf sysdeps/$(TARGET_OS)/Config.in
|
||||
@./scripts/config/mconf $(CONFIG_CONFIG_IN)
|
||||
|
||||
config: scripts/config/conf
|
||||
@./scripts/config/conf sysdeps/$(TARGET_OS)/Config.in
|
||||
@./scripts/config/conf $(CONFIG_CONFIG_IN)
|
||||
|
||||
oldconfig: scripts/config/conf
|
||||
@./scripts/config/conf -o sysdeps/$(TARGET_OS)/Config.in
|
||||
@./scripts/config/conf -o $(CONFIG_CONFIG_IN)
|
||||
|
||||
randconfig: scripts/config/conf
|
||||
@./scripts/config/conf -r sysdeps/$(TARGET_OS)/Config.in
|
||||
@./scripts/config/conf -r $(CONFIG_CONFIG_IN)
|
||||
|
||||
allyesconfig: scripts/config/conf
|
||||
@./scripts/config/conf -y sysdeps/$(TARGET_OS)/Config.in
|
||||
@./scripts/config/conf -y $(CONFIG_CONFIG_IN)
|
||||
sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
|
||||
sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
|
||||
sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
|
||||
sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
|
||||
@./scripts/config/conf -o $(CONFIG_CONFIG_IN)
|
||||
|
||||
allnoconfig: scripts/config/conf
|
||||
@./scripts/config/conf -n sysdeps/$(TARGET_OS)/Config.in
|
||||
@./scripts/config/conf -n $(CONFIG_CONFIG_IN)
|
||||
|
||||
defconfig: scripts/config/conf
|
||||
@./scripts/config/conf -d sysdeps/$(TARGET_OS)/Config.in
|
||||
|
||||
test tests: busybox
|
||||
# Note that 'tests' is depricated. Use 'make check' instead
|
||||
# To use the nice new testsuite....
|
||||
cd tests && ./tester.sh
|
||||
|
||||
check: busybox
|
||||
cd testsuite && ./runtest
|
||||
@./scripts/config/conf -d $(CONFIG_CONFIG_IN)
|
||||
|
||||
clean:
|
||||
- $(MAKE) -C tests clean
|
||||
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
|
||||
docs/busybox.net/BusyBox.html
|
||||
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pdf docs/busybox.pod docs/busybox.net/busybox.html \
|
||||
docs/busybox _install pod2htm* *.gdb *.elf *~ core
|
||||
- rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
|
||||
- rm -f .*config.log
|
||||
- find . -name .\*.flags -exec rm -f {} \;
|
||||
- rm -f docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pod docs/busybox.net/busybox.html \
|
||||
docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
|
||||
docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
|
||||
docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
|
||||
.config.old .hdepend busybox
|
||||
- rm -rf _install
|
||||
- find . -name .\*.flags -exec rm -f {} \;
|
||||
- find . -name \*.o -exec rm -f {} \;
|
||||
- find . -name \*.a -exec rm -f {} \;
|
||||
|
||||
@@ -227,21 +285,21 @@ distclean: clean
|
||||
- $(MAKE) -C scripts/config clean
|
||||
|
||||
release: distclean #doc
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
cp -a busybox busybox-$(VERSION); \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type d \
|
||||
-name CVS \
|
||||
-print \
|
||||
-exec rm -rf {} \; ; \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
\
|
||||
tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
|
||||
cd ..; \
|
||||
rm -rf $(PROG)-$(VERSION); \
|
||||
cp -a busybox $(PROG)-$(VERSION); \
|
||||
\
|
||||
find $(PROG)-$(VERSION)/ -type d \
|
||||
-name .svn \
|
||||
-print \
|
||||
-exec rm -rf {} \; ; \
|
||||
\
|
||||
find $(PROG)-$(VERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
\
|
||||
tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
|
||||
|
||||
tags:
|
||||
ctags -R .
|
||||
@@ -249,7 +307,7 @@ tags:
|
||||
|
||||
endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
|
||||
|
||||
endif # ifeq ($(skip-makefile),)
|
||||
|
||||
.PHONY: dummy subdirs release distclean clean config oldconfig \
|
||||
menuconfig tags check test tests depend
|
||||
|
||||
|
||||
menuconfig tags check test depend buildtree
|
||||
@@ -1,159 +1,196 @@
|
||||
Please see the LICENSE file for details on copying and usage.
|
||||
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for most of the utilities
|
||||
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
|
||||
tar, etc. BusyBox provides a fairly complete POSIX environment for any small or
|
||||
embedded system. The utilities in BusyBox generally have fewer options than
|
||||
their full featured GNU cousins; however, the options that are included provide
|
||||
the expected functionality and behave very much like their GNU counterparts.
|
||||
|
||||
BusyBox was originally written to support the Debian Rescue/Install disks, but
|
||||
it also makes an excellent environment for any small or embedded system.
|
||||
What is busybox:
|
||||
|
||||
BusyBox has been written with size-optimization and limited resources in mind.
|
||||
It is also extremely modular so you can easily include or exclude commands (or
|
||||
features) at compile time. This makes it easy to customize your embedded
|
||||
systems. To create a working system, just add /dev, /etc, and a kernel.
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for most of the
|
||||
utilities you usually find in bzip2, coreutils, file, findutils, gawk, grep,
|
||||
inetutils, modutils, net-tools, procps, sed, shadow, sysklogd, sysvinit, tar,
|
||||
util-linux, and vim. The utilities in BusyBox often have fewer options than
|
||||
their full-featured cousins; however, the options that are included provide
|
||||
the expected functionality and behave very much like their larger
|
||||
counterparts.
|
||||
|
||||
As of version 0.20 there is now a version number. : ) Also as of version 0.20,
|
||||
BusyBox is now modularized to easily allow you to build only the components you
|
||||
need, thereby reducing binary size. Run 'make config' or 'make menuconfig'
|
||||
for select the functionality that you wish to enable.
|
||||
BusyBox has been written with size-optimization and limited resources in
|
||||
mind, both to produce small binaries and to reduce run-time memory usage.
|
||||
Busybox is also extremely modular so you can easily include or exclude
|
||||
commands (or features) at compile time. This makes it easy to customize
|
||||
embedded systems; to create a working system, just add /dev, /etc, and a
|
||||
Linux kernel. Busybox (usually together with uClibc) has also been used as
|
||||
a component of "thin client" desktop systems, live-CD distributions, rescue
|
||||
disks, installers, and so on.
|
||||
|
||||
After the build is complete, a busybox.links file is generated. This is
|
||||
used by 'make install' to create symlinks to the busybox binary for all
|
||||
compiled in functions. By default, 'make install' will place the symlink
|
||||
forest into `pwd`/_install unless you have defined the PREFIX environment
|
||||
variable (i.e., 'make PREFIX=/tmp/foo install')
|
||||
|
||||
If you wish to install hardlinks, rather than symlinks, you can use
|
||||
'make install-hardlinks' instead.
|
||||
|
||||
----------------
|
||||
|
||||
Supported architectures:
|
||||
|
||||
Busybox in general will build on any architecture supported by gcc. It has
|
||||
a few specialized features added for __sparc__ and __alpha__. insmod
|
||||
functionality is currently limited to x86, ARM, SH3/4, powerpc, m68k,
|
||||
MIPS, and v850e.
|
||||
|
||||
Supported libcs:
|
||||
|
||||
glibc-2.0.x, glibc-2.1.x, glibc-2.2.x, glibc-2.3.x, uClibc. People
|
||||
are looking at newlib and diet-libc, but consider them unsupported,
|
||||
untested, or worse. Linux-libc5 is no longer supported -- you
|
||||
should probably use uClibc instead if you want a small C library.
|
||||
|
||||
Supported kernels:
|
||||
|
||||
Full functionality requires Linux 2.2.x or better. A large fraction of the
|
||||
code should run on just about anything. While the current code is fairly
|
||||
Linux specific, it should be fairly easy to port the majority of the code
|
||||
to, say, FreeBSD or Solaris, or MacOsX, or even Windows (if you are into that
|
||||
sortof thing).
|
||||
BusyBox provides a fairly complete POSIX environment for any small system,
|
||||
both embedded environments and more full featured systems concerned about
|
||||
space. Busybox is slowly working towards implementing the full Single Unix
|
||||
Specification V3 (http://www.opengroup.org/onlinepubs/009695399/), but isn't
|
||||
there yet (and for size reasons will probably support at most UTF-8 for
|
||||
internationalization). We are also interested in passing the Linux Test
|
||||
Project (http://ltp.sourceforge.net).
|
||||
|
||||
----------------
|
||||
|
||||
Shells:
|
||||
Using busybox:
|
||||
|
||||
lash is the very smallest shell (adds just 10k) and it is quite usable as
|
||||
a command prompt, but it is not suitable for any but the most trivial
|
||||
scripting (such as an initrd that calls insmod a few times) since it does
|
||||
not understand Bourne shell grammer. It does handle pipes, redirects, and
|
||||
job control though. Adding in command editing makes it a very nice
|
||||
lightweight command prompt.
|
||||
BusyBox is extremely configurable. This allows you to include only the
|
||||
components and options you need, thereby reducing binary size. Run 'make
|
||||
config' or 'make menuconfig' to select the functionality that you wish to
|
||||
enable.
|
||||
|
||||
hush is also quite small (just 18k) and it has very complete Bourne shell
|
||||
grammer. It handles if/then/else/fi just fine, but doesn't handle loops
|
||||
like for/do/done or case/esac and such. It also currently has a problem
|
||||
with job control. Using hush is not yet recommended.
|
||||
The behavior of busybox is determined by the name it's called under: as
|
||||
"cp" it behaves like cp, as "sed" it behaves like sed, and so on. Called
|
||||
as "busybox" it takes the second argument as the name of the applet to
|
||||
run (I.E. "./busybox ls -l /proc").
|
||||
|
||||
msh: The minix shell (adds just 30k) is quite complete and handles things
|
||||
like for/do/done, case/esac and all the things you expect a Bourne shell to
|
||||
do. It is not always pedantically correct about Bourne shell grammer (try
|
||||
running the shell testscript "tests/sh.testcases" on it and compare vs bash)
|
||||
but for most things it works quite well. It also uses only vfork, so it can
|
||||
be used on uClinux systems. This was only recently added, so there is still
|
||||
room to shrink it further...
|
||||
The "standalone shell" mode is an easy way to try out busybox; this is a
|
||||
command shell that calls the builtin applets without needing them to be
|
||||
installed in the path. (Note that this requires /proc to be mounted, if
|
||||
testing from a boot floppy or in a chroot environment.)
|
||||
|
||||
ash: This adds about 60k in the default configuration and is the most
|
||||
complete and most pedantically correct shell included with busybox. This
|
||||
shell was also recently added, and several people (mainly Vladimir and Erik)
|
||||
have been working on it. There are a number of configurable things at the
|
||||
top of ash.c as well, so check those out if you want to tweak things.
|
||||
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. Use the PREFIX environment variable to specify where to install
|
||||
the busybox binary and symlink forest. (i.e., 'make PREFIX=/tmp/foo install',
|
||||
or 'make PREFIX=/tmp/foo install-hardlinks' if you prefer hard links.)
|
||||
|
||||
----------------
|
||||
|
||||
Getting help:
|
||||
Downloading the current source code:
|
||||
|
||||
When you find you need help, you can check out the BusyBox mailing list
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
Source for the latest released version, as well as daily snapshots, can always
|
||||
be downloaded from
|
||||
|
||||
----------------
|
||||
|
||||
Bugs:
|
||||
|
||||
If you find bugs, please submit a detailed bug report to the busybox mailing
|
||||
list at busybox@busybox.net. A well-written bug report should include a
|
||||
transcript of a shell session that demonstrates the bad behavior and enables
|
||||
anyone else to duplicate the bug on their own machine. The following is such
|
||||
an example:
|
||||
|
||||
To: busybox@busybox.net
|
||||
From: diligent@testing.linux.org
|
||||
Subject: /bin/date doesn't work
|
||||
|
||||
Package: busybox
|
||||
Version: 1.00
|
||||
|
||||
When I execute Busybox 'date' it produces unexpected results.
|
||||
With GNU date I get the following output:
|
||||
|
||||
$ date
|
||||
Wed Mar 21 14:19:41 MST 2001
|
||||
|
||||
But when I use BusyBox date I get this instead:
|
||||
|
||||
$ date
|
||||
llegal instruction
|
||||
|
||||
I am using Debian unstable, kernel version 2.4.19-rmk1 on an Netwinder,
|
||||
and the latest uClibc from CVS. Thanks for the wonderful program!
|
||||
|
||||
-Diligent
|
||||
|
||||
Note the careful description and use of examples showing not only what BusyBox
|
||||
does, but also a counter example showing what an equivalent GNU app does. Bug
|
||||
reports lacking such detail may never be fixed... Thanks for understanding.
|
||||
|
||||
----------------
|
||||
|
||||
FTP:
|
||||
|
||||
Source for the latest released version, as well as daily snapshots, can always
|
||||
be downloaded from
|
||||
http://busybox.net/downloads/
|
||||
|
||||
----------------
|
||||
You can browse the up to the minute source code and change history online
|
||||
at:
|
||||
|
||||
CVS:
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_00_stable/busybox/
|
||||
|
||||
BusyBox now has its own publicly browsable CVS tree at:
|
||||
http://busybox.net/cgi-bin/cvsweb/busybox/
|
||||
Anonymous SVN access is available. For instructions, check out:
|
||||
|
||||
Anonymous CVS access is available. For instructions, check out:
|
||||
http://busybox.net/cvs_anon.html
|
||||
http://busybox.net/subversion.html
|
||||
|
||||
For those that are actively contributing there is even CVS write access:
|
||||
http://busybox.net/cvs_write.html
|
||||
For those that are actively contributing and would like to check files in,
|
||||
see:
|
||||
|
||||
http://busybox.net/developer.html
|
||||
|
||||
The developers also have a bug and patch tracking system
|
||||
(http://bugs.busybox.net) although posting a bug/patch to the mailing list
|
||||
is generally a faster way of getting it fixed, and the complete archive of
|
||||
what happened is the subversion changelog.
|
||||
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@codepoet.org>
|
||||
<andersen@codepoet.org>
|
||||
getting help:
|
||||
|
||||
when you find you need help, you can check out the busybox mailing list
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
|
||||
----------------
|
||||
|
||||
bugs:
|
||||
|
||||
if you find bugs, please submit a detailed bug report to the busybox mailing
|
||||
list at busybox@busybox.net. a well-written bug report should include a
|
||||
transcript of a shell session that demonstrates the bad behavior and enables
|
||||
anyone else to duplicate the bug on their own machine. the following is such
|
||||
an example:
|
||||
|
||||
to: busybox@mail.busybox.net
|
||||
from: diligent@testing.linux.org
|
||||
subject: /bin/date doesn't work
|
||||
|
||||
package: busybox
|
||||
version: 1.00
|
||||
|
||||
when i execute busybox 'date' it produces unexpected results.
|
||||
with gnu date i get the following output:
|
||||
|
||||
$ date
|
||||
fri oct 8 14:19:41 mdt 2004
|
||||
|
||||
but when i use busybox date i get this instead:
|
||||
|
||||
$ date
|
||||
illegal instruction
|
||||
|
||||
i am using debian unstable, kernel version 2.4.25-vrs2 on a netwinder,
|
||||
and the latest uclibc from cvs. thanks for the wonderful program!
|
||||
|
||||
-diligent
|
||||
|
||||
note the careful description and use of examples showing not only what
|
||||
busybox does, but also a counter example showing what an equivalent app
|
||||
does (or pointing to the text of a relevant standard). Bug reports lacking
|
||||
such detail may never be fixed... Thanks for understanding.
|
||||
|
||||
----------------
|
||||
|
||||
Portability:
|
||||
|
||||
Busybox is developed and tested on Linux 2.4 and 2.6 kernels, linked
|
||||
against uClibc (0.9.27 or greater) and glibc (2.2 or greater). In such
|
||||
an environment, the full set of busybox features should work (and if
|
||||
anything doesn't we want to know about it so we can fix it). Note that
|
||||
the 2.6 kernel can be trimmed down considerably with the aid of Matt
|
||||
Mackall's -tiny work (http://www.selenic.com/tiny-about/).
|
||||
|
||||
Since busybox consists of a large number of more or less independent
|
||||
applets, portability is a question of which features work where. Some
|
||||
busybox applets (such as cat and rm) are highly portable and likely to work
|
||||
just about anywhere, while others (such as insmod and losetup) are only
|
||||
likely to work under fairly recent Linux kernels with recent C libraries.
|
||||
|
||||
Earlier versions of Linux and glibc may or may not work, for any given
|
||||
configuration. Linux 2.2 or earlier should mostly work, but this is no
|
||||
longer regularly tested and inherently won't support certain features (such
|
||||
as long files and --bind mounts). The same is true for glibc 2.0 and 2.1,
|
||||
expect a higher testing and debugging burden using such old infrastructure.
|
||||
(The busybox developers are not very interested in supporting these older
|
||||
versions, but can probably be talked into accepting small patches to fix
|
||||
simple problems.)
|
||||
|
||||
Some environments are not recommended. Early versions of uClibc were buggy
|
||||
and missing many features: upgrade. Linking against libc5 or dietlibc is
|
||||
not supported and not interesting to the busybox developers. (The first is
|
||||
obsolete and has no known size or feature advantages over uClibc, the second
|
||||
has known bugs that its developers have actively refused to fix.) Ancient
|
||||
Linux kernels (2.0.x and earlier) are similarly uninteresting.
|
||||
|
||||
In theory it's possible to use Busybox under other operating systems (such as
|
||||
MacOS X, Solaris, Cygwin, or the BSD Fork Du Jour). This generally involves
|
||||
a different kernel and a different C library at the same time. While it
|
||||
should be possible to port the majority of the code to work in one of
|
||||
these environments, don't be suprised if it doesn't work out of the box. If
|
||||
you're into that sort of thing, start small (selecting just a few applets)
|
||||
and work your way up.
|
||||
|
||||
Shaun Jackman has recently (2005) ported busybox to a combination of newlib
|
||||
and libgloss, and some of his patches have been integrated. This platform
|
||||
may join glibc/uclibc and Linux as a supported combination with the 1.1
|
||||
release, but is not supported in 1.0.
|
||||
|
||||
Supported hardware:
|
||||
|
||||
BusyBox in general will build on any architecture supported by gcc. We
|
||||
support both 32 and 64 bit platforms, and both big and little endian
|
||||
systems.
|
||||
|
||||
Under 2.4 Linux kernels, kernel module loading was implemented in a
|
||||
platform-specific manner. Busybox's insmod utility has been reported to
|
||||
work under ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC, S390,
|
||||
SH3/4/5, Sparc, v850e, and x86_64. Anything else probably won't work.
|
||||
|
||||
The module loading mechanism for the 2.6 kernel is much more generic, and
|
||||
we believe 2.6.x kernel module loading support should work on all
|
||||
architectures supported by the kernel.
|
||||
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to the busybox
|
||||
maintainer:
|
||||
Erik Andersen
|
||||
<andersen@codepoet.org>
|
||||
@@ -1,6 +1,6 @@
|
||||
# Rules.make for busybox
|
||||
#
|
||||
# Copyright (C) 2001-2003 Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,9 +17,14 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# Pull in the user's busybox configuration
|
||||
ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
|
||||
-include $(top_builddir)/.config
|
||||
endif
|
||||
|
||||
#--------------------------------------------------------
|
||||
PROG := busybox
|
||||
VERSION := 1.00-pre2
|
||||
VERSION := 1.01
|
||||
BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
|
||||
|
||||
@@ -35,7 +40,6 @@ BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
# by asking the CC compiler what arch it compiles things for, so unless
|
||||
# your compiler is broken, you should not need to specify TARGET_ARCH
|
||||
CROSS =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
|
||||
#CROSS =/usr/i386-linux-uclibc/bin/i386-uclibc-
|
||||
CC = $(CROSS)gcc
|
||||
AR = $(CROSS)ar
|
||||
AS = $(CROSS)as
|
||||
@@ -43,7 +47,7 @@ LD = $(CROSS)ld
|
||||
NM = $(CROSS)nm
|
||||
STRIP = $(CROSS)strip
|
||||
CPP = $(CC) -E
|
||||
MAKEFILES = $(TOPDIR).config
|
||||
# MAKEFILES = $(top_builddir)/.config
|
||||
|
||||
# What OS are you compiling busybox for? This allows you to include
|
||||
# OS specific things, syscall overrides, etc.
|
||||
@@ -53,14 +57,14 @@ TARGET_OS=linux
|
||||
HOSTCC = gcc
|
||||
HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
|
||||
|
||||
# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
|
||||
# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
|
||||
LC_ALL:= C
|
||||
|
||||
# If you want to add some simple compiler switches (like -march=i686),
|
||||
# especially from the command line, use this instead of CFLAGS directly.
|
||||
# For optimization overrides, it's better still to set OPTIMIZATION.
|
||||
CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
|
||||
|
||||
|
||||
# If you have a "pristine" source directory, point BB_SRC_DIR to it.
|
||||
# Experimental and incomplete; tell the mailing list
|
||||
# <busybox@busybox.net> if you do or don't like it so far.
|
||||
@@ -81,13 +85,13 @@ BB_SRC_DIR=
|
||||
#GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
|
||||
WARNINGS=-Wall -Wstrict-prototypes -Wshadow
|
||||
CFLAGS=-I$(TOPDIR)include
|
||||
ARFLAGS=-r
|
||||
CFLAGS=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
|
||||
ARFLAGS=cru
|
||||
|
||||
#--------------------------------------------------------
|
||||
export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
|
||||
ifeq ($(strip $(TARGET_ARCH)),)
|
||||
TARGET_ARCH=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
|
||||
TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
|
||||
-e 's/i.86/i386/' \
|
||||
-e 's/sparc.*/sparc/' \
|
||||
-e 's/arm.*/arm/g' \
|
||||
@@ -101,23 +105,26 @@ TARGET_ARCH=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
|
||||
)
|
||||
endif
|
||||
|
||||
# Pull in the user's uClibc configuration
|
||||
ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
|
||||
-include $(TOPDIR).config
|
||||
endif
|
||||
|
||||
# A nifty macro to make testing gcc features easier
|
||||
check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
|
||||
then echo "$(1)"; else echo "$(2)"; fi)
|
||||
|
||||
# Setup some shortcuts so that silent mode is silent like it should be
|
||||
ifeq ($(subst s,,$(MAKEFLAGS)),$(MAKEFLAGS))
|
||||
export MAKE_IS_SILENT=n
|
||||
SECHO=@echo
|
||||
else
|
||||
export MAKE_IS_SILENT=y
|
||||
SECHO=-@false
|
||||
endif
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Arch specific compiler optimization stuff should go here.
|
||||
# Unless you want to override the defaults, do not set anything
|
||||
# for OPTIMIZATION...
|
||||
|
||||
# use '-Os' optimization if available, else use -O2
|
||||
OPTIMIZATION=
|
||||
OPTIMIZATION=${call check_gcc,-Os,-O2}
|
||||
OPTIMIZATION:=${call check_gcc,-Os,-O2}
|
||||
|
||||
# Some nice architecture specific optimizations
|
||||
ifeq ($(strip $(TARGET_ARCH)),arm)
|
||||
@@ -138,7 +145,7 @@ OPTIMIZATIONS=$(OPTIMIZATION) -fomit-frame-pointer
|
||||
# by itself, instead of following it by the same half-dozen overrides
|
||||
# every time. The stuff below, on the other hand, is probably less
|
||||
# prone to casual user adjustment.
|
||||
#
|
||||
#
|
||||
|
||||
ifeq ($(strip $(CONFIG_LFS)),y)
|
||||
# For large file summit support
|
||||
@@ -159,8 +166,8 @@ ifeq ($(strip $(CONFIG_DEBUG)),y)
|
||||
STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
|
||||
else
|
||||
CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
|
||||
LDFLAGS += -s -Wl,-warn-common
|
||||
STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment
|
||||
LDFLAGS += -Wl,-warn-common
|
||||
STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
|
||||
endif
|
||||
ifeq ($(strip $(CONFIG_STATIC)),y)
|
||||
LDFLAGS += --static
|
||||
@@ -190,23 +197,4 @@ endif
|
||||
# have a chance of winning.
|
||||
CFLAGS += $(CFLAGS_EXTRA)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
ifdef _FASTDEP_ALL_SUB_DIRS
|
||||
fastdep: dummy
|
||||
$(TOPDIR)scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
|
||||
ifdef ALL_SUB_DIRS
|
||||
$(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
|
||||
endif
|
||||
|
||||
$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
|
||||
$(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
|
||||
endif
|
||||
|
||||
.PHONY: dummy
|
||||
|
||||
|
||||
|
||||
.EXPORT_ALL_VARIABLES:
|
||||
|
||||
@@ -1,49 +1,11 @@
|
||||
TODO list for busybox in no particular order. Just because something
|
||||
is listed here doesn't mean that it is going to be added to busybox,
|
||||
or that doing so is even a good idea. It just means that we _might_ get
|
||||
around to it some time. If you have any good ideas, please send them
|
||||
on in...
|
||||
Busybox TODO
|
||||
|
||||
-Erik
|
||||
Stuff that needs to be done
|
||||
|
||||
-----------
|
||||
----
|
||||
tr - missing SuS3 features in busybox 1.0pre10
|
||||
|
||||
Possible apps to include some time:
|
||||
|
||||
* group/commonize strings, remove dups (for i18n, l10n)
|
||||
|
||||
-----------
|
||||
|
||||
With sysvinit, reboot, poweroff and halt all used a named pipe,
|
||||
/dev/initctl, to communicate with the init process. Busybox
|
||||
currently uses signals to communicate with init. This makes
|
||||
busybox incompatible with sysvinit. We should probably use
|
||||
a named pipe as well so we can be compatible.
|
||||
|
||||
-----------------------
|
||||
|
||||
Run the following:
|
||||
|
||||
rm -f busybox && make LDFLAGS+=-nostdlib 2>&1 | \
|
||||
sed -ne 's/.*undefined reference to `\(.*\)..*/\1/gp' | sort | uniq
|
||||
|
||||
reveals the list of all external (i.e., libc) things that BusyBox depends on.
|
||||
It would be a very nice thing to reduce this list to an absolute minimum, to
|
||||
reduce the footprint of busybox, especially when staticly linking with
|
||||
libraries such as uClibc.
|
||||
|
||||
-----------------------
|
||||
|
||||
Compile with debugging on, run 'nm --size-sort ./busybox'
|
||||
and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
xargs could use a -l option
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
libbb/unzip.c and archival/gzip.c have common constant static arrays and
|
||||
code for initializing the CRC array. Both use CRC-32 and could use
|
||||
common code for CRC calculation. Within archival/gzip.c, the CRC
|
||||
array should be malloc-ed as it is in libbb/unzip.c .
|
||||
tr doesnt support [:blank:], [:digit:] or other predefined classes, [=equiv=]
|
||||
support is also missing.
|
||||
----
|
||||
|
||||
+8
-6
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,13 +17,15 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR:= ../
|
||||
top_srcdir=..
|
||||
top_builddir=..
|
||||
srcdir=$(top_srcdir)/applets
|
||||
APPLETS_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
-include $(top_builddir).depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
+9
-8
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,18 +19,19 @@
|
||||
|
||||
APPLETS_AR:=applets.a
|
||||
ifndef $(APPLETS_DIR)
|
||||
APPLETS_DIR:=$(TOPDIR)applets/
|
||||
APPLETS_DIR:=$(top_builddir)/applets/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/applets
|
||||
|
||||
APPLET_SRC:=applets.c busybox.c usage.c
|
||||
APPLET_SRC:=applets.c busybox.c
|
||||
APPLET_OBJ:= $(patsubst %.c,$(APPLETS_DIR)%.o, $(APPLET_SRC))
|
||||
|
||||
|
||||
|
||||
libraries-y+=$(APPLETS_DIR)$(APPLETS_AR)
|
||||
|
||||
$(APPLET_OBJ): $(TOPDIR).config
|
||||
|
||||
$(APPLETS_DIR)$(APPLETS_AR): $(APPLET_OBJ)
|
||||
$(AR) -ro $@ $(APPLET_OBJ)
|
||||
$(AR) $(ARFLAGS) $@ $(APPLET_OBJ)
|
||||
|
||||
$(APPLET_OBJ): $(top_builddir)/.config
|
||||
$(APPLET_OBJ): $(APPLETS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+243
-185
@@ -29,14 +29,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
const char usage_messages[] =
|
||||
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
|
||||
#include "applets.h"
|
||||
|
||||
;
|
||||
|
||||
#undef MAKE_USAGE
|
||||
#undef APPLET
|
||||
#undef APPLET_NOUSAGE
|
||||
#undef PROTOTYPES
|
||||
#include "applets.h"
|
||||
|
||||
struct BB_applet *applet_using;
|
||||
|
||||
static struct BB_applet *applet_using;
|
||||
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
|
||||
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
@@ -53,9 +65,7 @@ static void check_suid (struct BB_applet *app);
|
||||
#include "pwd_.h"
|
||||
#include "grp_.h"
|
||||
|
||||
static int parse_config_file (void);
|
||||
|
||||
static int config_ok;
|
||||
static void parse_config_file (void);
|
||||
|
||||
#define CONFIG_FILE "/etc/busybox.conf"
|
||||
|
||||
@@ -72,6 +82,7 @@ struct BB_suid_config
|
||||
};
|
||||
|
||||
static struct BB_suid_config *suid_config;
|
||||
static int suid_cfg_readable;
|
||||
|
||||
#endif /* CONFIG_FEATURE_SUID_CONFIG */
|
||||
|
||||
@@ -127,7 +138,7 @@ run_applet_by_name (const char *name, int argc, char **argv)
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if (recurse_level == 0)
|
||||
config_ok = parse_config_file ();
|
||||
parse_config_file ();
|
||||
#endif
|
||||
|
||||
recurse_level++;
|
||||
@@ -193,7 +204,7 @@ check_suid (struct BB_applet *applet)
|
||||
uid_t rgid = getgid ();
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if (config_ok) {
|
||||
if (suid_cfg_readable) {
|
||||
struct BB_suid_config *sct;
|
||||
|
||||
for (sct = suid_config; sct; sct = sct->m_next) {
|
||||
@@ -253,191 +264,238 @@ check_suid (struct BB_applet *applet)
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
/* This should probably be a libbb routine. In that case,
|
||||
* I'd probably rename it to something like bb_trimmed_slice.
|
||||
*/
|
||||
static char *get_trimmed_slice(char *s, char *e)
|
||||
{
|
||||
/* First, consider the value at e to be nul and back up until we
|
||||
* reach a non-space char. Set the char after that (possibly at
|
||||
* the original e) to nul. */
|
||||
while (e-- > s) {
|
||||
if (!isspace(*e)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
e[1] = 0;
|
||||
|
||||
/* Next, advance past all leading space and return a ptr to the
|
||||
* first non-space char; possibly the terminating nul. */
|
||||
return (char *) bb_skip_whitespace(s);
|
||||
}
|
||||
|
||||
|
||||
#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;
|
||||
|
||||
int
|
||||
parse_config_file (void)
|
||||
/* There are 4 chars + 1 nul for each of user/group/other. */
|
||||
static const char mode_chars[] = "Ssx-\0Ssx-\0Ttx-";
|
||||
|
||||
/* We don't supply a value for the nul, so an index adjustment is
|
||||
* necessary below. Also, we use unsigned short here to save some
|
||||
* space even though these are really mode_t values. */
|
||||
static const unsigned short mode_mask[] = {
|
||||
/* SST sst xxx --- */
|
||||
S_ISUID, S_ISUID|S_IXUSR, S_IXUSR, 0, /* user */
|
||||
S_ISGID, S_ISGID|S_IXGRP, S_IXGRP, 0, /* group */
|
||||
0, S_IXOTH, S_IXOTH, 0 /* other */
|
||||
};
|
||||
|
||||
static void parse_config_file(void)
|
||||
{
|
||||
struct stat st;
|
||||
char *err = 0;
|
||||
FILE *f = 0;
|
||||
int lc = 0;
|
||||
struct BB_suid_config *sct_head;
|
||||
struct BB_suid_config *sct;
|
||||
struct BB_applet *applet;
|
||||
FILE *f;
|
||||
char *err;
|
||||
char *s;
|
||||
char *e;
|
||||
int i, lc, section;
|
||||
char buffer[256];
|
||||
struct stat st;
|
||||
|
||||
suid_config = 0;
|
||||
assert(!suid_config); /* Should be set to NULL by bss init. */
|
||||
|
||||
/* is there a config file ? */
|
||||
if (stat (CONFIG_FILE, &st) == 0) {
|
||||
/* is it owned by root with no write perm. for group and others ? */
|
||||
if (S_ISREG (st.st_mode) && (st.st_uid == 0)
|
||||
&& (!(st.st_mode & (S_IWGRP | S_IWOTH)))) {
|
||||
/* that's ok .. then try to open it */
|
||||
f = fopen (CONFIG_FILE, "r");
|
||||
|
||||
if (f) {
|
||||
char buffer[256];
|
||||
int section = 0;
|
||||
|
||||
while (fgets (buffer, sizeof (buffer) - 1, f)) {
|
||||
char c = buffer[0];
|
||||
char *p;
|
||||
|
||||
lc++;
|
||||
|
||||
p = strchr (buffer, '#');
|
||||
if (p)
|
||||
*p = 0;
|
||||
p = buffer + bb_strlen (buffer);
|
||||
while ((p > buffer) && isspace (*--p))
|
||||
*p = 0;
|
||||
|
||||
if (p == buffer)
|
||||
continue;
|
||||
|
||||
if (c == '[') {
|
||||
p = strchr (buffer, ']');
|
||||
|
||||
if (!p || (p == (buffer + 1))) /* no matching ] or empty [] */
|
||||
parse_error ("malformed section header");
|
||||
|
||||
*p = 0;
|
||||
|
||||
if (strcasecmp (buffer + 1, "SUID") == 0)
|
||||
section = 1;
|
||||
else
|
||||
section = -1; /* unknown section - just skip */
|
||||
} else if (section) {
|
||||
switch (section) {
|
||||
case 1:{ /* SUID */
|
||||
int l;
|
||||
struct BB_applet *applet;
|
||||
|
||||
p = strchr (buffer, '='); /* <key>[::space::]*=[::space::]*<value> */
|
||||
|
||||
if (!p || (p == (buffer + 1))) /* no = or key is empty */
|
||||
parse_error ("malformed keyword");
|
||||
|
||||
l = p - buffer;
|
||||
while (isspace (buffer[--l])) {
|
||||
/* skip whitespace */
|
||||
}
|
||||
|
||||
buffer[l + 1] = 0;
|
||||
|
||||
if ((applet = find_applet_by_name (buffer))) {
|
||||
struct BB_suid_config *sct =
|
||||
xmalloc (sizeof (struct BB_suid_config));
|
||||
|
||||
sct->m_applet = applet;
|
||||
sct->m_next = suid_config;
|
||||
suid_config = sct;
|
||||
|
||||
while (isspace (*++p)) {
|
||||
/* skip whitespace */
|
||||
}
|
||||
|
||||
sct->m_mode = 0;
|
||||
|
||||
switch (*p++) {
|
||||
case 'S':
|
||||
sct->m_mode |= S_ISUID;
|
||||
break;
|
||||
case 's':
|
||||
sct->m_mode |= S_ISUID;
|
||||
/* no break */
|
||||
case 'x':
|
||||
sct->m_mode |= S_IXUSR;
|
||||
break;
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
parse_error ("invalid user mode");
|
||||
}
|
||||
|
||||
switch (*p++) {
|
||||
case 's':
|
||||
sct->m_mode |= S_ISGID;
|
||||
/* no break */
|
||||
case 'x':
|
||||
sct->m_mode |= S_IXGRP;
|
||||
break;
|
||||
case 'S':
|
||||
break;
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
parse_error ("invalid group mode");
|
||||
}
|
||||
|
||||
switch (*p) {
|
||||
case 't':
|
||||
case 'x':
|
||||
sct->m_mode |= S_IXOTH;
|
||||
break;
|
||||
case 'T':
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
parse_error ("invalid other mode");
|
||||
}
|
||||
|
||||
while (isspace (*++p)) {
|
||||
/* skip whitespace */
|
||||
}
|
||||
|
||||
if (isdigit (*p)) {
|
||||
sct->m_uid = strtol (p, &p, 10);
|
||||
if (*p++ != '.')
|
||||
parse_error ("parsing <uid>.<gid>");
|
||||
} else {
|
||||
struct passwd *pwd;
|
||||
char *p2 = strchr (p, '.');
|
||||
|
||||
if (!p2)
|
||||
parse_error ("parsing <uid>.<gid>");
|
||||
|
||||
*p2 = 0;
|
||||
pwd = getpwnam (p);
|
||||
|
||||
if (!pwd)
|
||||
parse_error ("invalid user name");
|
||||
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
p = p2 + 1;
|
||||
}
|
||||
if (isdigit (*p))
|
||||
sct->m_gid = strtol (p, &p, 10);
|
||||
else {
|
||||
struct group *grp = getgrnam (p);
|
||||
|
||||
if (!grp)
|
||||
parse_error ("invalid group name");
|
||||
|
||||
sct->m_gid = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: /* unknown - skip */
|
||||
break;
|
||||
}
|
||||
} else
|
||||
parse_error ("keyword not within section");
|
||||
}
|
||||
fclose (f);
|
||||
return 1;
|
||||
}
|
||||
if ((stat(config_file, &st) != 0) /* No config file? */
|
||||
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|
||||
|| (st.st_uid != 0) /* Not owned by root? */
|
||||
|| (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */
|
||||
|| !(f = fopen(config_file, "r")) /* Can not open? */
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return 0; /* no config file or not readable (not an error) */
|
||||
|
||||
pe_label:
|
||||
fprintf (stderr, "Parse error in %s, line %d: %s\n", CONFIG_FILE, lc, err);
|
||||
suid_cfg_readable = 1;
|
||||
sct_head = NULL;
|
||||
section = lc = 0;
|
||||
|
||||
if (f)
|
||||
fclose (f);
|
||||
return 0;
|
||||
do {
|
||||
s = buffer;
|
||||
|
||||
if (!fgets(s, sizeof(buffer), f)) { /* Are we done? */
|
||||
if (ferror(f)) { /* Make sure it wasn't a read error. */
|
||||
parse_error("reading");
|
||||
}
|
||||
fclose(f);
|
||||
suid_config = sct_head; /* Success, so set the pointer. */
|
||||
return;
|
||||
}
|
||||
|
||||
lc++; /* Got a (partial) line. */
|
||||
|
||||
/* If a line is too long for our buffer, we consider it an error.
|
||||
* The following test does mistreat one corner case though.
|
||||
* If the final line of the file does not end with a newline and
|
||||
* yet exactly fills the buffer, it will be treated as too long
|
||||
* even though there isn't really a problem. But it isn't really
|
||||
* worth adding code to deal with such an unlikely situation, and
|
||||
* we do err on the side of caution. Besides, the line would be
|
||||
* too long if it did end with a newline. */
|
||||
if (!strchr(s, '\n') && !feof(f)) {
|
||||
parse_error("line too long");
|
||||
}
|
||||
|
||||
/* Trim leading and trailing whitespace, ignoring comments, and
|
||||
* check if the resulting string is empty. */
|
||||
if (!*(s = get_trimmed_slice(s, strchrnul(s, '#')))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check for a section header. */
|
||||
|
||||
if (*s == '[') {
|
||||
/* Unlike the old code, we ignore leading and trailing
|
||||
* whitespace for the section name. We also require that
|
||||
* there are no stray characters after the closing bracket. */
|
||||
if (!(e = strchr(s, ']')) /* Missing right bracket? */
|
||||
|| e[1] /* Trailing characters? */
|
||||
|| !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */
|
||||
) {
|
||||
parse_error("section header");
|
||||
}
|
||||
/* Right now we only have one section so just check it.
|
||||
* If more sections are added in the future, please don't
|
||||
* resort to cascading ifs with multiple strcasecmp calls.
|
||||
* That kind of bloated code is all too common. A loop
|
||||
* and a string table would be a better choice unless the
|
||||
* number of sections is very small. */
|
||||
if (strcasecmp(s, "SUID") == 0) {
|
||||
section = 1;
|
||||
continue;
|
||||
}
|
||||
section = -1; /* Unknown section so set to skip. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process sections. */
|
||||
|
||||
if (section == 1) { /* SUID */
|
||||
/* Since we trimmed leading and trailing space above, we're
|
||||
* now looking for strings of the form
|
||||
* <key>[::space::]*=[::space::]*<value>
|
||||
* where both key and value could contain inner whitespace. */
|
||||
|
||||
/* First get the key (an applet name in our case). */
|
||||
if (!!(e = strchr(s, '='))) {
|
||||
s = get_trimmed_slice(s, e);
|
||||
}
|
||||
if (!e || !*s) { /* Missing '=' or empty key. */
|
||||
parse_error("keyword");
|
||||
}
|
||||
|
||||
/* Ok, we have an applet name. Process the rhs if this
|
||||
* applet is currently built in and ignore it otherwise.
|
||||
* Note: This can hide config file bugs which only pop
|
||||
* up when the busybox configuration is changed. */
|
||||
if ((applet = find_applet_by_name(s))) {
|
||||
/* Note: We currently don't check for duplicates!
|
||||
* The last config line for each applet will be the
|
||||
* one used since we insert at the head of the list.
|
||||
* I suppose this could be considered a feature. */
|
||||
sct = xmalloc(sizeof(struct BB_suid_config));
|
||||
sct->m_applet = applet;
|
||||
sct->m_mode = 0;
|
||||
sct->m_next = sct_head;
|
||||
sct_head = sct;
|
||||
|
||||
/* Get the specified mode. */
|
||||
|
||||
e = (char *) bb_skip_whitespace(e+1);
|
||||
|
||||
for (i=0 ; i < 3 ; i++) {
|
||||
const char *q;
|
||||
if (!*(q = strchrnul(mode_chars + 5*i, *e++))) {
|
||||
parse_error("mode");
|
||||
}
|
||||
/* Adjust by -i to account for nul. */
|
||||
sct->m_mode |= mode_mask[(q - mode_chars) - i];
|
||||
}
|
||||
|
||||
/* Now get the the user/group info. */
|
||||
|
||||
s = (char *) bb_skip_whitespace(e);
|
||||
|
||||
/* Note: We require whitespace between the mode and the
|
||||
* user/group info. */
|
||||
if ((s == e) || !(e = strchr(s, '.'))) {
|
||||
parse_error("<uid>.<gid>");
|
||||
}
|
||||
*e++ = 0;
|
||||
|
||||
/* We can't use get_ug_id here since it would exit()
|
||||
* if a uid or gid was not found. Oh well... */
|
||||
{
|
||||
char *e2;
|
||||
|
||||
sct->m_uid = strtoul(s, &e2, 10);
|
||||
if (*e2 || (s == e2)) {
|
||||
struct passwd *pwd;
|
||||
if (!(pwd = getpwnam(s))) {
|
||||
parse_error("user");
|
||||
}
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
}
|
||||
|
||||
sct->m_gid = strtoul(e, &e2, 10);
|
||||
if (*e2 || (e == e2)) {
|
||||
struct group *grp;
|
||||
if (!(grp = getgrnam(e))) {
|
||||
parse_error("group");
|
||||
}
|
||||
sct->m_gid = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Unknown sections are ignored. */
|
||||
|
||||
/* Encountering configuration lines prior to seeing a
|
||||
* section header is treated as an error. This is how
|
||||
* the old code worked, but it may not be desirable.
|
||||
* We may want to simply ignore such lines in case they
|
||||
* are used in some future version of busybox. */
|
||||
if (!section) {
|
||||
parse_error("keyword outside section");
|
||||
}
|
||||
|
||||
} while (1);
|
||||
|
||||
pe_label:
|
||||
fprintf(stderr, "Parse error in %s, line %d: %s\n",
|
||||
config_file, lc, err);
|
||||
|
||||
fclose(f);
|
||||
/* Release any allocated memory before returning. */
|
||||
while (sct_head) {
|
||||
sct = sct_head->m_next;
|
||||
free(sct_head);
|
||||
sct_head = sct;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -446,9 +504,9 @@ pe_label:
|
||||
|
||||
/* END CODE */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+32
-23
@@ -13,7 +13,7 @@ int been_there_done_that = 0; /* Also used in applets.c */
|
||||
const char *bb_applet_name;
|
||||
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
@@ -32,7 +32,7 @@ static const char* const install_dir[] = {
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Where in the filesystem is this busybox?
|
||||
* [return]
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
@@ -52,7 +52,7 @@ static void install_links(const char *busybox, int use_symbolic_links)
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
if (use_symbolic_links)
|
||||
Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
|
||||
bb_applet_name = s;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
#ifdef CONFIG_INIT
|
||||
if(getpid()!=1) /* Do not set locale for `init' */
|
||||
#endif
|
||||
@@ -100,9 +100,9 @@ int busybox_main(int argc, char **argv)
|
||||
{
|
||||
int col = 0, len, i;
|
||||
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
@@ -113,8 +113,8 @@ int busybox_main(int argc, char **argv)
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,33 +135,42 @@ int busybox_main(int argc, char **argv)
|
||||
/* If we've already been here once, exit now */
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct BB_applet *a = applets;
|
||||
int output_width = 60;
|
||||
|
||||
fprintf(stderr, "%s\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n"
|
||||
"\nCurrently defined functions:\n", bb_msg_full_version);
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= 20;
|
||||
#endif
|
||||
|
||||
printf("%s\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as!\n"
|
||||
"\nCurrently defined functions:\n", bb_msg_full_version);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > 60 && a->name != 0) {
|
||||
fprintf(stderr, ",\n");
|
||||
printf("%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > output_width && a->name != 0) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
printf("\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Flag that we've been here already */
|
||||
been_there_done_that = 1;
|
||||
|
||||
|
||||
/* Move the command line down a notch */
|
||||
/* Preserve pointers so setproctitle() works consistently */
|
||||
len = argv[argc] + strlen(argv[argc]) - argv[1];
|
||||
memmove(argv[0], argv[1], len);
|
||||
memset(argv[0] + len, 0, argv[1] - argv[0]);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "busybox.h"
|
||||
|
||||
const char usage_messages[] =
|
||||
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
|
||||
#include "applets.h"
|
||||
|
||||
;
|
||||
+68
-46
@@ -16,13 +16,14 @@ config CONFIG_AR
|
||||
The original files' contents, mode (permissions), timestamp, owner,
|
||||
and group are preserved in the archive, and can be restored on
|
||||
extraction.
|
||||
|
||||
The stored filename is limited to 15 characters. (for more information
|
||||
see long filename support).
|
||||
ar has 60 bytes of overheads for every stored file.
|
||||
|
||||
This implementation of ar can extract archives, it cannot create or
|
||||
modify them.
|
||||
On an x86 system, the ar applet adds about XXX bytes.
|
||||
On an x86 system, the ar applet adds about 1K.
|
||||
|
||||
Unless you have a specific application which requires ar, you should
|
||||
probably say N here.
|
||||
@@ -41,15 +42,15 @@ config CONFIG_BUNZIP2
|
||||
bool "bunzip2"
|
||||
default n
|
||||
help
|
||||
bunzip2 is an compression utility using the Burrows-Wheeler block
|
||||
bunzip2 is a compression utility using the Burrows-Wheeler block
|
||||
sorting text compression algorithm, and Huffman coding. Compression
|
||||
is generally considerably better than that achieved by more
|
||||
conventional LZ77/LZ78-based compressors, and approaches the
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
The BusyBox bunzip2 applet is limited to de-compression only.
|
||||
On an x86 system, this applet adds about XXX bytes.
|
||||
|
||||
On an x86 system, this applet adds about 11K.
|
||||
|
||||
Unless you have a specific application which requires bunzip2, you
|
||||
should probably say N here.
|
||||
|
||||
@@ -62,7 +63,7 @@ config CONFIG_CPIO
|
||||
cpio has 110 bytes of overheads for every stored file.
|
||||
|
||||
This implementation of cpio can extract cpio archives created in the
|
||||
"newc" or "crc" format, it cannot create or modify them.
|
||||
"newc" or "crc" format, it cannot create or modify them.
|
||||
|
||||
Unless you have a specific application which requires cpio, you should
|
||||
probably say N here.
|
||||
@@ -72,7 +73,7 @@ config CONFIG_DPKG
|
||||
default n
|
||||
help
|
||||
dpkg is a medium-level tool to install, build, remove and manage Debian packages.
|
||||
|
||||
|
||||
This implementation of dpkg has a number of limitations, you should use the
|
||||
official dpkg if possible.
|
||||
|
||||
@@ -81,9 +82,9 @@ config CONFIG_DPKG_DEB
|
||||
default n
|
||||
help
|
||||
dpkg-deb packs, unpacks and provides information about Debian archives.
|
||||
|
||||
|
||||
This implementation of dpkg-deb cannot pack archives.
|
||||
|
||||
|
||||
Unless you have a specific application which requires dpkg-deb, you should
|
||||
probably say N here.
|
||||
|
||||
@@ -92,30 +93,10 @@ config CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
default n
|
||||
depends on CONFIG_DPKG_DEB
|
||||
help
|
||||
This reduced dpkg-deb to the equivalent of "ar -p <deb> data.tar.gz | tar -zx".
|
||||
However it saves space as none of the extra dpkg-deb, ar or tar options are
|
||||
This reduces dpkg-deb to the equivalent of "ar -p <deb> data.tar.gz | tar -zx".
|
||||
However it saves space as none of the extra dpkg-deb, ar or tar options are
|
||||
needed, they are linked to internally.
|
||||
|
||||
config CONFIG_FEATURE_DEB_TAR_GZ
|
||||
bool " gzip debian packages (normal)"
|
||||
default y if CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
help
|
||||
This is the default compression method inside the debian ar file.
|
||||
|
||||
If you want compatability with standard .deb's you should say yes here.
|
||||
|
||||
config CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
bool " bzip2 debian packages"
|
||||
default n
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
help
|
||||
This allows dpkg and dpkg-deb to extract deb's that are compressed internally
|
||||
with bzip2 instead of gzip.
|
||||
|
||||
You only want this is your are creating your own custom debian packages that
|
||||
use an internal control.tar.bz2 or data.tar.bz2.
|
||||
|
||||
config CONFIG_GUNZIP
|
||||
bool "gunzip"
|
||||
default n
|
||||
@@ -129,7 +110,7 @@ config CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
default n
|
||||
depends on CONFIG_GUNZIP
|
||||
help
|
||||
If you want gunzip to have the ability to decompress
|
||||
Enable if you want gunzip to have the ability to decompress
|
||||
archives created by the program compress (not much
|
||||
used anymore).
|
||||
|
||||
@@ -138,7 +119,7 @@ config CONFIG_GZIP
|
||||
default n
|
||||
help
|
||||
gzip is used to compress files.
|
||||
It's probably the most used UNIX compression program.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config CONFIG_RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
@@ -150,14 +131,14 @@ config CONFIG_RPM
|
||||
bool "rpm"
|
||||
default n
|
||||
help
|
||||
Mini RPM applet - querys and extracts
|
||||
Mini RPM applet - queries and extracts
|
||||
|
||||
config CONFIG_TAR
|
||||
bool "tar"
|
||||
default n
|
||||
help
|
||||
tar is an archiving program. It's commonly used with gzip to
|
||||
create compressed archives. It's probably the most used
|
||||
create compressed archives. It's probably the most widely used
|
||||
UNIX archive program.
|
||||
|
||||
config CONFIG_FEATURE_TAR_CREATE
|
||||
@@ -176,13 +157,13 @@ config CONFIG_FEATURE_TAR_BZIP2
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with bzip2.
|
||||
|
||||
config CONFIG_FEATURE_TAR_EXCLUDE
|
||||
bool " Enable -X and --exclude options (exclude files)"
|
||||
config CONFIG_FEATURE_TAR_FROM
|
||||
bool " Enable -X (exclude from) and -T (include from) options)"
|
||||
default n
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to exclude from an archive.
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config CONFIG_FEATURE_TAR_GZIP
|
||||
bool " Enable -z option"
|
||||
@@ -192,13 +173,21 @@ config CONFIG_FEATURE_TAR_GZIP
|
||||
If you enable this option tar will be able to call gzip,
|
||||
when creating or extracting tar gziped archives.
|
||||
|
||||
config CONFIG_FEATURE_TAR_COMPRESS
|
||||
bool " Enable -Z option"
|
||||
default n
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
If you enable this option tar will be able to call uncompress,
|
||||
when extracting .tar.Z archives.
|
||||
|
||||
config CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
bool " Enable support for old tar header format"
|
||||
default N
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
This option is required to unpack archives created with
|
||||
in the old GNU format, help to kill this old format by
|
||||
This option is required to unpack archives created in
|
||||
the old GNU format; help to kill this old format by
|
||||
repacking your ancient archives with the new format.
|
||||
|
||||
config CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
@@ -206,15 +195,15 @@ config CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
default y
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
With this option busybox supports GNU long filenames and
|
||||
With this option busybox supports GNU long filenames and
|
||||
linknames.
|
||||
|
||||
config CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
bool " Enable tape drive support"
|
||||
config CONFIG_FEATURE_TAR_LONG_OPTIONS
|
||||
bool " Enable long options"
|
||||
default n
|
||||
depends on CONFIG_TAR || CONFIG_CPIO
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
I dont think this is needed anymore.
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config CONFIG_UNCOMPRESS
|
||||
bool "uncompress"
|
||||
@@ -233,4 +222,37 @@ config CONFIG_UNZIP
|
||||
current directory. Use the `-d' option to extract to a
|
||||
directory of your choice.
|
||||
|
||||
comment "Common options for cpio and tar"
|
||||
depends on CONFIG_CPIO || CONFIG_TAR
|
||||
|
||||
config CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
bool " Enable tape drive support"
|
||||
default n
|
||||
depends on CONFIG_CPIO || CONFIG_TAR
|
||||
help
|
||||
I don't think this is needed anymore.
|
||||
|
||||
comment "Common options for dpkg and dpkg_deb"
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
|
||||
config CONFIG_FEATURE_DEB_TAR_GZ
|
||||
bool " gzip debian packages (normal)"
|
||||
default y if CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
help
|
||||
This is the default compression method inside the debian ar file.
|
||||
|
||||
If you want compatibility with standard .deb's you should say yes here.
|
||||
|
||||
config CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
bool " bzip2 debian packages"
|
||||
default n
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
help
|
||||
This allows dpkg and dpkg-deb to extract deb's that are compressed internally
|
||||
with bzip2 instead of gzip.
|
||||
|
||||
You only want this if you are creating your own custom debian packages that
|
||||
use an internal control.tar.bz2 or data.tar.bz2.
|
||||
|
||||
endmenu
|
||||
+8
-6
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,13 +17,15 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR:= ../
|
||||
top_srcdir=..
|
||||
top_builddir=..
|
||||
ARCHIVAL_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
srcdir=$(top_srcdir)/archival
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
ARCHIVAL_AR:=archival.a
|
||||
ifndef $(ARCHIVAL_DIR)
|
||||
ARCHIVAL_DIR:=$(TOPDIR)archival/
|
||||
ARCHIVAL_DIR:=$(top_builddir)/archival/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/archival
|
||||
|
||||
ARCHIVAL-y:=
|
||||
ARCHIVAL-$(CONFIG_APT_GET) +=
|
||||
@@ -40,5 +41,8 @@ ARCHIVAL-$(CONFIG_UNZIP) += unzip.o
|
||||
libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR)
|
||||
|
||||
$(ARCHIVAL_DIR)$(ARCHIVAL_AR): $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
$(AR) $(ARFLAGS) $@ $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
|
||||
$(ARCHIVAL_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+44
-73
@@ -1,10 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@optushome.com.au> 1 June 2000
|
||||
*
|
||||
* Written by Glenn McGrath <bug1@iinet.net.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -21,20 +21,20 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* There is no signle standard to adhere to so ar may not portable
|
||||
* There is no single standard to adhere to so ar may not portable
|
||||
* between different systems
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
@@ -50,87 +50,59 @@ static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
printf("%s %d/%d%7d %s %s\n", &mode[1], file_header->uid, file_header->gid, (int) file_header->size, &mtime[4], file_header->name);
|
||||
}
|
||||
|
||||
#if !defined CONFIG_TAR && !defined CONFIG_DPKG_DEB && !defined CONFIG_CPIO
|
||||
/* This is simpler than data_extract_all */
|
||||
static void data_extract_regular_file(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header;
|
||||
int dst_fd;
|
||||
|
||||
file_header = archive_handle->file_header;
|
||||
dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT);
|
||||
archive_copy_file(archive_handle, dst_fd);
|
||||
close(dst_fd);
|
||||
|
||||
chmod(file_header->name, file_header->mode);
|
||||
chown(file_header->name, file_header->uid, file_header->gid);
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#define AR_CTX_PRINT 0x01
|
||||
#define AR_CTX_LIST 0x02
|
||||
#define AR_CTX_EXTRACT 0x04
|
||||
#define AR_OPT_PRESERVE_DATE 0x08
|
||||
#define AR_OPT_VERBOSE 0x10
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
int opt;
|
||||
|
||||
#if !defined CONFIG_DPKG_DEB && !defined CONFIG_DPKG
|
||||
unsigned long opt;
|
||||
char *msg_unsupported_err = "Archive %s not supported. Install binutils 'ar'.";
|
||||
char magic[8];
|
||||
#endif
|
||||
|
||||
archive_handle = init_handle();
|
||||
|
||||
while ((opt = getopt(argc, argv, "covtpxX")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p': /* print */
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
break;
|
||||
case 't': /* list contents */
|
||||
archive_handle->action_header = header_list;
|
||||
break;
|
||||
case 'X':
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
case 'x': /* extract */
|
||||
#if defined CONFIG_TAR || defined CONFIG_DPKG_DEB || defined CONFIG_CPIO
|
||||
archive_handle->action_data = data_extract_all;
|
||||
#else
|
||||
archive_handle->action_data = data_extract_regular_file;
|
||||
#endif
|
||||
break;
|
||||
/* Modifiers */
|
||||
case 'o': /* preserve original dates */
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
/* check the src filename was specified */
|
||||
if (optind == argc) {
|
||||
bb_opt_complementaly = "p~tx:t~px:x~pt";
|
||||
opt = bb_getopt_ulflags(argc, argv, "ptxovcr");
|
||||
|
||||
if ((opt & BB_GETOPT_ERROR) || (opt == 0) || (optind == argc)) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & AR_CTX_LIST) {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & AR_CTX_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
if (opt & AR_OPT_VERBOSE) {
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
}
|
||||
if (opt & AR_OPT_CREATE) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "creation");
|
||||
}
|
||||
if (opt & AR_OPT_INSERT) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
/* TODO: This is the same as in tar, seperate function ? */
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind++]);
|
||||
}
|
||||
|
||||
#if defined CONFIG_DPKG_DEB || defined CONFIG_DPKG
|
||||
unpack_ar_archive(archive_handle);
|
||||
#else
|
||||
archive_xread_all(archive_handle, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
bb_error_msg_and_die("Invalid ar magic");
|
||||
@@ -138,7 +110,6 @@ extern int ar_main(int argc, char **argv)
|
||||
archive_handle->offset += 7;
|
||||
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+36
-48
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@optushome.com.au>
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -27,76 +27,64 @@
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define BUNZIP2_OPT_STDOUT 1
|
||||
#define BUNZIP2_OPT_FORCE 2
|
||||
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
const int bunzip_to_stdout = 1;
|
||||
const int bunzip_force = 2;
|
||||
int flags = 0;
|
||||
int opt = 0;
|
||||
char *compressed_name;
|
||||
/* Note: Ignore the warning about save_name being used uninitialized.
|
||||
* That is not the case, but gcc has trouble working that out... */
|
||||
char *save_name;
|
||||
unsigned long opt;
|
||||
int status;
|
||||
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
char *save_name = NULL;
|
||||
char *delete_name = NULL;
|
||||
|
||||
/* if called as bzcat */
|
||||
if (strcmp(bb_applet_name, "bzcat") == 0)
|
||||
flags |= bunzip_to_stdout;
|
||||
opt = bb_getopt_ulflags(argc, argv, "cf");
|
||||
|
||||
while ((opt = getopt(argc, argv, "cfh")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
flags |= bunzip_to_stdout;
|
||||
break;
|
||||
case 'f':
|
||||
flags |= bunzip_force;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
bb_show_usage(); /* exit's inside usage */
|
||||
}
|
||||
/* if called as bzcat force the stdout flag */
|
||||
if (bb_applet_name[2] == 'c') {
|
||||
opt |= BUNZIP2_OPT_STDOUT;
|
||||
}
|
||||
|
||||
/* Set input filename and number */
|
||||
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
|
||||
flags |= bunzip_to_stdout;
|
||||
src_fd = fileno(stdin);
|
||||
} else {
|
||||
compressed_name = argv[optind];
|
||||
if ((compressed_name) && (compressed_name[0] != '-') && (compressed_name[1] != '\0')) {
|
||||
/* Open input file */
|
||||
src_fd = bb_xopen(argv[optind], O_RDONLY);
|
||||
|
||||
save_name = bb_xstrdup(argv[optind]);
|
||||
if (strcmp(save_name + strlen(save_name) - 4, ".bz2") != 0)
|
||||
bb_error_msg_and_die("Invalid extension");
|
||||
save_name[strlen(save_name) - 4] = '\0';
|
||||
src_fd = bb_xopen(compressed_name, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= BUNZIP2_OPT_STDOUT;
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && (flags & bunzip_force) == 0) {
|
||||
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 (flags & bunzip_to_stdout) {
|
||||
dst_fd = fileno(stdout);
|
||||
if (opt & BUNZIP2_OPT_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
int len = strlen(compressed_name) - 4;
|
||||
if (strcmp(compressed_name + len, ".bz2") != 0) {
|
||||
bb_error_msg_and_die("Invalid extension");
|
||||
}
|
||||
save_name = bb_xstrndup(compressed_name, len);
|
||||
dst_fd = bb_xopen(save_name, O_WRONLY | O_CREAT);
|
||||
}
|
||||
|
||||
if (uncompressStream(src_fd, dst_fd)) {
|
||||
if (!(flags & bunzip_to_stdout)) {
|
||||
delete_name = argv[optind];
|
||||
}
|
||||
status = EXIT_SUCCESS;
|
||||
} else {
|
||||
if (!(flags & bunzip_to_stdout)) {
|
||||
status = uncompressStream(src_fd, dst_fd);
|
||||
if(!(opt & BUNZIP2_OPT_STDOUT)) {
|
||||
char *delete_name;
|
||||
if (status) {
|
||||
delete_name = save_name;
|
||||
} else {
|
||||
delete_name = compressed_name;
|
||||
}
|
||||
if (unlink(delete_name) < 0) {
|
||||
bb_error_msg_and_die("Couldn't remove %s", delete_name);
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ((delete_name) && (unlink(delete_name) < 0)) {
|
||||
bb_error_msg_and_die("Couldn't remove %s", delete_name);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
+46
-31
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini cpio implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -31,44 +31,60 @@
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define CPIO_OPT_EXTRACT 0x01
|
||||
#define CPIO_OPT_TEST 0x02
|
||||
#define CPIO_OPT_UNCONDITIONAL 0x04
|
||||
#define CPIO_OPT_VERBOSE 0x08
|
||||
#define CPIO_OPT_FILE 0x10
|
||||
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
|
||||
extern int cpio_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
int opt;
|
||||
char *cpio_filename = NULL;
|
||||
unsigned long opt;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = fileno(stdin);
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->action_header = header_list;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* extract */
|
||||
archive_handle->action_data = data_extract_all;
|
||||
break;
|
||||
case 'd': /* create _leading_ directories */
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
break;
|
||||
case 'm': /* preserve modification time */
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
break;
|
||||
case 'v': /* verbosly list files */
|
||||
archive_handle->action_header = header_verbose_list;
|
||||
break;
|
||||
case 'u': /* unconditional */
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
break;
|
||||
case 't': /* list files */
|
||||
archive_handle->action_header = header_list;
|
||||
break;
|
||||
case 'F':
|
||||
archive_handle->src_fd = bb_xopen(optarg, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
opt = bb_getopt_ulflags(argc, argv, "ituvF:dm", &cpio_filename);
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (opt & CPIO_OPT_TEST) {
|
||||
/* if both extract and test option are given, ignore extract option */
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
opt &= ~CPIO_OPT_EXTRACT;
|
||||
}
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & CPIO_OPT_UNCONDITIONAL) {
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
}
|
||||
if (opt & CPIO_OPT_VERBOSE) {
|
||||
if (archive_handle->action_header == header_list) {
|
||||
archive_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (cpio_filename) { /* CPIO_OPT_FILE */
|
||||
archive_handle->src_fd = bb_xopen(cpio_filename, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
}
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
@@ -81,4 +97,3 @@ extern int cpio_main(int argc, char **argv)
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
+323
-141
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Mini dpkg implementation for busybox.
|
||||
* This is not meant as a replacemnt for dpkg
|
||||
* This is not meant as a replacement for dpkg
|
||||
*
|
||||
* Written By Glenn McGrath with the help of others
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
*
|
||||
*
|
||||
* Started life as a busybox implementation of udpkg
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -23,15 +23,12 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Known difference between busybox dpkg and the official dpkg that i dont
|
||||
* Known difference between busybox dpkg and the official dpkg that i don't
|
||||
* consider important, its worth keeping a note of differences anyway, just to
|
||||
* make it easier to maintain.
|
||||
* - The first value for the Confflile: field isnt placed on a new line.
|
||||
* - The <package>.control file is extracted and kept in the info dir.
|
||||
* - When installing a package the Status: field is placed at the end of the
|
||||
* section, rather than just after the Package: field.
|
||||
* - Packages with previously unknown status are inserted at the begining of
|
||||
* the status file
|
||||
*
|
||||
* Bugs that need to be fixed
|
||||
* - (unknown, please let me know when you find any)
|
||||
@@ -57,7 +54,7 @@
|
||||
* int's and chaos is assured, 16381 is the max prime for 14 bit field
|
||||
*/
|
||||
|
||||
/* NAME_HASH_PRIME, Stores package names and versions,
|
||||
/* NAME_HASH_PRIME, Stores package names and versions,
|
||||
* I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME,
|
||||
* as there a lot of duplicate version numbers */
|
||||
#define NAME_HASH_PRIME 16381
|
||||
@@ -89,7 +86,7 @@ common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1];
|
||||
|
||||
/* Currently it doesnt store packages that have state-status of not-installed
|
||||
* So it only really has to be the size of the maximum number of packages
|
||||
* likely to be installed at any one time, so there is a bit of leaway here */
|
||||
* 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 int package:14; /* has to fit PACKAGE_HASH_PRIME */
|
||||
@@ -97,7 +94,7 @@ typedef struct status_node_s {
|
||||
} status_node_t;
|
||||
status_node_t *status_hashtable[STATUS_HASH_PRIME + 1];
|
||||
|
||||
/* Even numbers are for 'extras', like ored dependecies or null */
|
||||
/* Even numbers are for 'extras', like ored dependencies or null */
|
||||
enum edge_type_e {
|
||||
EDGE_NULL = 0,
|
||||
EDGE_PRE_DEPENDS = 1,
|
||||
@@ -151,9 +148,9 @@ void make_hash(const char *key, unsigned int *start, unsigned int *decrement, co
|
||||
for(i = 1; i < len; i++) {
|
||||
/* shifts the ascii based value and adds it to previous value
|
||||
* shift amount is mod 24 because long int is 32 bit and data
|
||||
* to be shifted is 8, dont want to shift data to where it has
|
||||
* to be shifted is 8, don't want to shift data to where it has
|
||||
* no effect*/
|
||||
hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
|
||||
hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
|
||||
}
|
||||
*start = (unsigned int) hash_num % hash_prime;
|
||||
*decrement = (unsigned int) 1 + (hash_num % (hash_prime - 1));
|
||||
@@ -392,8 +389,54 @@ int search_package_hashtable(const unsigned int name, const unsigned int version
|
||||
return(probe_address);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function searches through the entire package_hashtable looking
|
||||
* for a package which provides "needle". It returns the index into
|
||||
* the package_hashtable for the providing package.
|
||||
*
|
||||
* needle is the index into name_hashtable of the package we are
|
||||
* looking for.
|
||||
*
|
||||
* start_at is the index in the package_hashtable to start looking
|
||||
* at. If start_at is -1 then start at the beginning. This is to allow
|
||||
* for repeated searches since more than one package might provide
|
||||
* needle.
|
||||
*
|
||||
* FIXME: I don't think this is very efficient, but I thought I'd keep
|
||||
* it simple for now until it proves to be a problem.
|
||||
*/
|
||||
int search_for_provides(int needle, int start_at) {
|
||||
int i, j;
|
||||
common_node_t *p;
|
||||
for (i = start_at + 1; i < PACKAGE_HASH_PRIME; i++) {
|
||||
p = package_hashtable[i];
|
||||
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;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an edge to a node
|
||||
*/
|
||||
void add_edge_to_node(common_node_t *node, edge_t *edge)
|
||||
{
|
||||
node->num_of_edges++;
|
||||
node->edge = xrealloc(node->edge, sizeof(edge_t) * (node->num_of_edges + 1));
|
||||
node->edge[node->num_of_edges - 1] = edge;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create one new node and one new edge for every dependency.
|
||||
*
|
||||
* Dependencies which contain multiple alternatives are represented as
|
||||
* an EDGE_OR_PRE_DEPENDS or EDGE_OR_DEPENDS node, followed by a
|
||||
* number of EDGE_PRE_DEPENDS or EDGE_DEPENDS nodes. The name field of
|
||||
* the OR edge contains the full dependency string while the version
|
||||
* field contains the number of EDGE nodes which follow as part of
|
||||
* this alternative.
|
||||
*/
|
||||
void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
|
||||
{
|
||||
@@ -405,25 +448,33 @@ void add_split_dependencies(common_node_t *parent_node, const char *whole_line,
|
||||
char *field2;
|
||||
char *version;
|
||||
edge_t *edge;
|
||||
edge_t *or_edge;
|
||||
int offset_ch;
|
||||
int type;
|
||||
|
||||
field = strtok_r(line, ",", &line_ptr1);
|
||||
do {
|
||||
/* skip leading spaces */
|
||||
field += strspn(field, " ");
|
||||
line2 = bb_xstrdup(field);
|
||||
field2 = strtok_r(line2, "|", &line_ptr2);
|
||||
if ((edge_type == EDGE_DEPENDS) && (strcmp(field, field2) != 0)) {
|
||||
type = EDGE_OR_DEPENDS;
|
||||
}
|
||||
else if ((edge_type == EDGE_PRE_DEPENDS) && (strcmp(field, field2) != 0)) {
|
||||
type = EDGE_OR_PRE_DEPENDS;
|
||||
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 {
|
||||
type = edge_type;
|
||||
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 = (edge_t *) xmalloc(sizeof(edge_t));
|
||||
edge->type = type;
|
||||
edge->type = edge_type;
|
||||
|
||||
/* Skip any extra leading spaces */
|
||||
field2 += strspn(field2, " ");
|
||||
@@ -438,7 +489,7 @@ void add_split_dependencies(common_node_t *parent_node, const char *whole_line,
|
||||
/* Skip leading ' ' or '(' */
|
||||
version += strspn(field2, " ");
|
||||
version += strspn(version, "(");
|
||||
/* Calculate length of any operator charactors */
|
||||
/* Calculate length of any operator characters */
|
||||
offset_ch = strspn(version, "<=>");
|
||||
/* Determine operator */
|
||||
if (offset_ch > 0) {
|
||||
@@ -473,11 +524,11 @@ void add_split_dependencies(common_node_t *parent_node, const char *whole_line,
|
||||
/* Get the dependency name */
|
||||
field2[strcspn(field2, " (")] = '\0';
|
||||
edge->name = search_name_hashtable(field2);
|
||||
|
||||
/* link the new edge to the current node */
|
||||
parent_node->num_of_edges++;
|
||||
parent_node->edge = xrealloc(parent_node->edge, sizeof(edge_t) * (parent_node->num_of_edges + 1));
|
||||
parent_node->edge[parent_node->num_of_edges - 1] = edge;
|
||||
|
||||
if ( or_edge )
|
||||
or_edge->version++;
|
||||
|
||||
add_edge_to_node(parent_node, edge);
|
||||
} while ((field2 = strtok_r(NULL, "|", &line_ptr2)) != NULL);
|
||||
free(line2);
|
||||
} while ((field = strtok_r(NULL, ",", &line_ptr1)) != NULL);
|
||||
@@ -493,7 +544,8 @@ void free_package(common_node_t *node)
|
||||
for (i = 0; i < node->num_of_edges; i++) {
|
||||
free(node->edge[i]);
|
||||
}
|
||||
free(node->edge);
|
||||
if ( node->edge )
|
||||
free(node->edge);
|
||||
free(node);
|
||||
}
|
||||
}
|
||||
@@ -520,7 +572,7 @@ unsigned int fill_package_struct(char *control_buffer)
|
||||
goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */
|
||||
}
|
||||
|
||||
field_num = compare_string_array(field_names, field_name);
|
||||
field_num = compare_string_array(field_names, field_name);
|
||||
switch(field_num) {
|
||||
case 0: /* Package */
|
||||
new_node->name = search_name_hashtable(field_value);
|
||||
@@ -584,7 +636,7 @@ unsigned int get_status(const unsigned int status_node, const int num)
|
||||
for (i = 1; i < num; i++) {
|
||||
/* skip past a word */
|
||||
status_string += strcspn(status_string, " ");
|
||||
/* skip past the seperating spaces */
|
||||
/* skip past the separating spaces */
|
||||
status_string += strspn(status_string, " ");
|
||||
}
|
||||
len = strcspn(status_string, " \n\0");
|
||||
@@ -630,6 +682,31 @@ void set_status(const unsigned int status_node_num, const char *new_value, const
|
||||
return;
|
||||
}
|
||||
|
||||
const char *describe_status(int status_num) {
|
||||
int status_want, status_state ;
|
||||
if ( status_hashtable[status_num] == NULL || status_hashtable[status_num]->status == 0 )
|
||||
return "is not installed or flagged to be installed\n";
|
||||
|
||||
status_want = get_status(status_num, 1);
|
||||
status_state = get_status(status_num, 3);
|
||||
|
||||
if ( status_state == search_name_hashtable("installed") ) {
|
||||
if ( status_want == search_name_hashtable("install") )
|
||||
return "is installed";
|
||||
if ( status_want == search_name_hashtable("deinstall") )
|
||||
return "is marked to be removed";
|
||||
if ( status_want == search_name_hashtable("purge") )
|
||||
return "is marked to be purged";
|
||||
}
|
||||
if ( status_want == search_name_hashtable("unknown") )
|
||||
return "is in an indeterminate state";
|
||||
if ( status_want == search_name_hashtable("install") )
|
||||
return "is marked to be installed";
|
||||
|
||||
return "is not installed or flagged to be installed";
|
||||
}
|
||||
|
||||
|
||||
void index_status_file(const char *filename)
|
||||
{
|
||||
FILE *status_file;
|
||||
@@ -662,7 +739,7 @@ void index_status_file(const char *filename)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#if 0 /* this code is no longer used */
|
||||
char *get_depends_field(common_node_t *package, const int depends_type)
|
||||
{
|
||||
char *depends = NULL;
|
||||
@@ -733,6 +810,7 @@ char *get_depends_field(common_node_t *package, const int depends_type)
|
||||
}
|
||||
return(depends);
|
||||
}
|
||||
#endif
|
||||
|
||||
void write_buffer_no_status(FILE *new_status_file, const char *control_buffer)
|
||||
{
|
||||
@@ -877,13 +955,13 @@ void write_status_file(deb_file_t **deb_file)
|
||||
fclose(new_status_file);
|
||||
|
||||
|
||||
/* Create a seperate backfile to dpkg */
|
||||
/* Create a separate backfile to dpkg */
|
||||
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
|
||||
struct stat stat_buf;
|
||||
struct stat stat_buf;
|
||||
if (stat("/var/lib/dpkg/status", &stat_buf) == 0) {
|
||||
bb_error_msg_and_die("Couldnt create backup status file");
|
||||
}
|
||||
/* Its ok if renaming the status file fails becasue status
|
||||
/* Its ok if renaming the status file fails because status
|
||||
* file doesnt exist, maybe we are starting from scratch */
|
||||
bb_error_msg("No status file found, creating new one");
|
||||
}
|
||||
@@ -893,13 +971,34 @@ void write_status_file(deb_file_t **deb_file)
|
||||
}
|
||||
}
|
||||
|
||||
/* This function returns TRUE if the given package can satisfy a
|
||||
* dependency of type depend_type.
|
||||
*
|
||||
* A pre-depends is satisfied only if a package is already installed,
|
||||
* which a regular depends can be satisfied by a package which we want
|
||||
* to install.
|
||||
*/
|
||||
int package_satisfies_dependency(int package, int depend_type)
|
||||
{
|
||||
int status_num = search_status_hashtable(name_hashtable[package_hashtable[package]->name]);
|
||||
|
||||
/* status could be unknown if package is a pure virtual
|
||||
* provides which cannot satisfy any dependency by itself.
|
||||
*/
|
||||
if ( status_hashtable[status_num] == NULL )
|
||||
return 0;
|
||||
|
||||
switch (depend_type) {
|
||||
case EDGE_PRE_DEPENDS: return get_status(status_num, 3) == search_name_hashtable("installed");
|
||||
case EDGE_DEPENDS: return get_status(status_num, 1) == search_name_hashtable("install");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
{
|
||||
int *conflicts = NULL;
|
||||
int conflicts_num = 0;
|
||||
int state_status;
|
||||
int state_flag;
|
||||
int state_want;
|
||||
int i = deb_start;
|
||||
int j;
|
||||
|
||||
@@ -955,21 +1054,17 @@ 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];
|
||||
const unsigned int package_num =
|
||||
search_package_hashtable(package_edge->name,
|
||||
package_edge->version, package_edge->operator);
|
||||
|
||||
if (package_edge->type == EDGE_CONFLICTS) {
|
||||
const unsigned int package_num =
|
||||
search_package_hashtable(package_edge->name,
|
||||
package_edge->version,
|
||||
package_edge->operator);
|
||||
int result = 0;
|
||||
if (package_hashtable[package_num] != NULL) {
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_flag = get_status(status_num, 1);
|
||||
|
||||
result = (state_status == search_name_hashtable("installed")) ||
|
||||
(state_flag == search_name_hashtable("want-install"));
|
||||
|
||||
if (result) {
|
||||
if (get_status(status_num, 1) == search_name_hashtable("install")) {
|
||||
result = test_version(package_hashtable[deb_file[i]->package]->version,
|
||||
package_edge->version, package_edge->operator);
|
||||
}
|
||||
@@ -983,70 +1078,127 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Check dependendcies */
|
||||
i = 0;
|
||||
while (deb_file[i] != NULL) {
|
||||
const common_node_t *package_node = package_hashtable[deb_file[i]->package];
|
||||
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
|
||||
int status_num = 0;
|
||||
int number_of_alternatives = 0;
|
||||
const edge_t * root_of_alternatives = NULL;
|
||||
const common_node_t *package_node = package_hashtable[i];
|
||||
|
||||
status_num = search_status_hashtable(name_hashtable[package_node->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
/* If the package node does not exist then this
|
||||
* package is a virtual one. In which case there are
|
||||
* no dependencies to check.
|
||||
*/
|
||||
if ( package_node == NULL ) continue;
|
||||
|
||||
if (state_status == search_name_hashtable("installed")) {
|
||||
i++;
|
||||
status_num = search_status_hashtable(name_hashtable[package_node->name]);
|
||||
|
||||
/* If there is no status then this package is a
|
||||
* virtual one provided by something else. In which
|
||||
* case there are no dependencies to check.
|
||||
*/
|
||||
if ( status_hashtable[status_num] == NULL ) continue;
|
||||
|
||||
/* If we don't want this package installed then we may
|
||||
* as well ignore it's dependencies.
|
||||
*/
|
||||
if (get_status(status_num, 1) != search_name_hashtable("install")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; j < package_hashtable[deb_file[i]->package]->num_of_edges; j++) {
|
||||
#if 0
|
||||
/* This might be needed so we don't complain about
|
||||
* things which are broken but unrelated to the
|
||||
* packages that are currently being installed
|
||||
*/
|
||||
if (state_status == search_name_hashtable("installed"))
|
||||
continue;
|
||||
#endif
|
||||
|
||||
/* This code is tested only for EDGE_DEPENDS, since I
|
||||
* have no suitable pre-depends available. There is no
|
||||
* reason that it shouldn't work though :-)
|
||||
*/
|
||||
for (j = 0; j < package_node->num_of_edges; j++) {
|
||||
const edge_t *package_edge = package_node->edge[j];
|
||||
unsigned int package_num;
|
||||
|
||||
if ( package_edge->type == EDGE_OR_PRE_DEPENDS ||
|
||||
package_edge->type == EDGE_OR_DEPENDS ) { /* start an EDGE_OR_ list */
|
||||
number_of_alternatives = package_edge->version;
|
||||
root_of_alternatives = package_edge;
|
||||
continue;
|
||||
} else if ( number_of_alternatives == 0 ) { /* not in the middle of an EDGE_OR_ list */
|
||||
number_of_alternatives = 1;
|
||||
root_of_alternatives = NULL;
|
||||
}
|
||||
|
||||
package_num = search_package_hashtable(package_edge->name, package_edge->version, package_edge->operator);
|
||||
|
||||
switch (package_edge->type) {
|
||||
case(EDGE_PRE_DEPENDS):
|
||||
case(EDGE_OR_PRE_DEPENDS): {
|
||||
int result=1;
|
||||
/* It must be already installed */
|
||||
/* NOTE: This is untested, nothing apropriate in my status file */
|
||||
if (package_hashtable[package_num] != NULL) {
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
result = (state_status != search_name_hashtable("installed"));
|
||||
}
|
||||
if (package_edge->type == EDGE_PRE_DEPENDS ||
|
||||
package_edge->type == EDGE_DEPENDS ) {
|
||||
int result=1;
|
||||
status_num = 0;
|
||||
|
||||
if (result) {
|
||||
bb_error_msg_and_die("Package %s pre-depends on %s, but it is not installed",
|
||||
name_hashtable[package_node->name],
|
||||
name_hashtable[package_edge->name]);
|
||||
/* If we are inside an alternative then check
|
||||
* this edge is the right type.
|
||||
*
|
||||
* EDGE_DEPENDS == OR_DEPENDS -1
|
||||
* EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1
|
||||
*/
|
||||
if ( root_of_alternatives && package_edge->type != root_of_alternatives->type - 1)
|
||||
bb_error_msg_and_die("Fatal error. Package dependencies corrupt: %d != %d - 1 \n",
|
||||
package_edge->type, root_of_alternatives->type);
|
||||
|
||||
if (package_hashtable[package_num] != NULL)
|
||||
result = !package_satisfies_dependency(package_num, package_edge->type);
|
||||
|
||||
if (result) { /* check for other package which provide what we are looking for */
|
||||
int provider = -1;
|
||||
|
||||
while ( (provider = search_for_provides(package_edge->name, provider) ) > -1 ) {
|
||||
if ( package_hashtable[provider] == NULL ) {
|
||||
printf("Have a provider but no package information for it\n");
|
||||
continue;
|
||||
}
|
||||
result = !package_satisfies_dependency(provider, package_edge->type);
|
||||
|
||||
if ( result == 0 )
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(EDGE_DEPENDS):
|
||||
case(EDGE_OR_DEPENDS): {
|
||||
int result=1;
|
||||
if (package_hashtable[package_num] != NULL) {
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
result=(state_status != search_name_hashtable("installed")) && (state_want != search_name_hashtable("want-install"));
|
||||
}
|
||||
/* It must be already installed, or to be installed */
|
||||
if (result) {
|
||||
bb_error_msg_and_die("Package %s depends on %s, but it is not installed, or flaged to be installed",
|
||||
|
||||
/* It must be already installed, or to be installed */
|
||||
number_of_alternatives--;
|
||||
if (result && number_of_alternatives == 0) {
|
||||
if ( root_of_alternatives )
|
||||
bb_error_msg_and_die(
|
||||
"Package %s %sdepends on %s, "
|
||||
"which cannot be satisfied",
|
||||
name_hashtable[package_node->name],
|
||||
name_hashtable[package_edge->name]);
|
||||
}
|
||||
break;
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[root_of_alternatives->name]);
|
||||
else
|
||||
bb_error_msg_and_die(
|
||||
"Package %s %sdepends on %s, which %s\n",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[package_edge->name],
|
||||
describe_status(status_num));
|
||||
} else if ( result == 0 && number_of_alternatives ) {
|
||||
/* we've found a package which
|
||||
* satisfies the dependency,
|
||||
* so skip over the rest of
|
||||
* the alternatives.
|
||||
*/
|
||||
j += number_of_alternatives;
|
||||
number_of_alternatives = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
free(conflicts);
|
||||
return(TRUE);
|
||||
@@ -1059,7 +1211,7 @@ char **create_list(const char *filename)
|
||||
char *line = NULL;
|
||||
int count = 0;
|
||||
|
||||
/* dont use [xw]fopen here, handle error ourself */
|
||||
/* don't use [xw]fopen here, handle error ourself */
|
||||
list_stream = fopen(filename, "r");
|
||||
if (list_stream == NULL) {
|
||||
return(NULL);
|
||||
@@ -1138,28 +1290,29 @@ int run_package_script(const char *package_name, const char *script_type)
|
||||
return(result);
|
||||
}
|
||||
|
||||
const char *all_control_files[] = {"preinst", "postinst", "prerm", "postrm",
|
||||
"list", "md5sums", "shlibs", "conffiles", "config", "templates", NULL };
|
||||
|
||||
char **all_control_list(const char *package_name)
|
||||
{
|
||||
const char *extensions[11] = {"preinst", "postinst", "prerm", "postrm",
|
||||
"list", "md5sums", "shlibs", "conffiles", "config", "templates", NULL };
|
||||
unsigned short i = 0;
|
||||
char **remove_files;
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = malloc(sizeof(char *) * 11);
|
||||
while (extensions[i]) {
|
||||
remove_files[i] = xmalloc(strlen(package_name) + strlen(extensions[i]) + 21);
|
||||
sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, extensions[i]);
|
||||
remove_files = malloc(sizeof(all_control_files));
|
||||
while (all_control_files[i]) {
|
||||
remove_files[i] = xmalloc(strlen(package_name) + strlen(all_control_files[i]) + 21);
|
||||
sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
|
||||
i++;
|
||||
}
|
||||
remove_files[10] = NULL;
|
||||
remove_files[sizeof(all_control_files)/sizeof(char*) - 1] = NULL;
|
||||
|
||||
return(remove_files);
|
||||
}
|
||||
|
||||
void free_array(char **array)
|
||||
{
|
||||
|
||||
|
||||
if (array) {
|
||||
unsigned short i = 0;
|
||||
while (array[i]) {
|
||||
@@ -1172,15 +1325,15 @@ void free_array(char **array)
|
||||
|
||||
/* This function lists information on the installed packages. It loops through
|
||||
* the status_hashtable to retrieve the info. This results in smaller code than
|
||||
* scanning the status file. The resulting list, however, is unsorted.
|
||||
* scanning the status file. The resulting list, however, is unsorted.
|
||||
*/
|
||||
void list_packages(void)
|
||||
static void list_packages(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf(" Name Version\n");
|
||||
printf("+++-==============-==============\n");
|
||||
|
||||
|
||||
/* go through status hash, dereference package hash and finally strings */
|
||||
for (i=0; i<STATUS_HASH_PRIME+1; i++) {
|
||||
|
||||
@@ -1189,31 +1342,32 @@ void list_packages(void)
|
||||
const char *name_str; /* package name */
|
||||
const char *vers_str; /* version */
|
||||
char s1, s2; /* status abbreviations */
|
||||
int spccnt; /* space count */
|
||||
int spccnt; /* space count */
|
||||
int j;
|
||||
|
||||
|
||||
stat_str = name_hashtable[status_hashtable[i]->status];
|
||||
name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name];
|
||||
vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version];
|
||||
|
||||
|
||||
/* get abbreviation for status field 1 */
|
||||
s1 = stat_str[0] == 'i' ? 'i' : 'r';
|
||||
|
||||
|
||||
/* get abbreviation for status field 2 */
|
||||
for (j=0, spccnt=0; stat_str[j] && spccnt<2; j++) {
|
||||
if (stat_str[j] == ' ') spccnt++;
|
||||
}
|
||||
s2 = stat_str[j];
|
||||
|
||||
|
||||
/* print out the line formatted like Debian dpkg */
|
||||
printf("%c%c %-14s %s\n", s1, s2, name_str, vers_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove_package(const unsigned int package_num)
|
||||
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 int status_num = search_status_hashtable(package_name);
|
||||
const int package_name_length = strlen(package_name);
|
||||
char **remove_files;
|
||||
@@ -1222,7 +1376,8 @@ void remove_package(const unsigned int package_num)
|
||||
char conffile_name[package_name_length + 30];
|
||||
int return_value;
|
||||
|
||||
printf("Removing %s ...\n", package_name);
|
||||
if ( noisy )
|
||||
printf("Removing %s (%s) ...\n", package_name, package_version);
|
||||
|
||||
/* run prerm script */
|
||||
return_value = run_package_script(package_name, "prerm");
|
||||
@@ -1230,7 +1385,7 @@ void remove_package(const unsigned int package_num)
|
||||
bb_error_msg_and_die("script failed, prerm failure");
|
||||
}
|
||||
|
||||
/* Create a list of files to remove, and a seperate list of those to keep */
|
||||
/* Create a list of files to remove, and a separate list of those to keep */
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
|
||||
remove_files = create_list(list_name);
|
||||
|
||||
@@ -1260,18 +1415,20 @@ void remove_package(const unsigned int package_num)
|
||||
rename(conffile_name, list_name);
|
||||
|
||||
/* Change package status */
|
||||
set_status(status_num, "deinstall", 1);
|
||||
set_status(status_num, "config-files", 3);
|
||||
}
|
||||
|
||||
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 int status_num = search_status_hashtable(package_name);
|
||||
char **remove_files;
|
||||
char **exclude_files;
|
||||
char list_name[strlen(package_name) + 25];
|
||||
|
||||
printf("Purging %s (%s) ...\n", package_name, package_version);
|
||||
|
||||
/* run prerm script */
|
||||
if (run_package_script(package_name, "prerm") != 0) {
|
||||
bb_error_msg_and_die("script failed, prerm failure");
|
||||
@@ -1300,7 +1457,6 @@ void purge_package(const unsigned int package_num)
|
||||
}
|
||||
|
||||
/* Change package status */
|
||||
set_status(status_num, "purge", 1);
|
||||
set_status(status_num, "not-installed", 3);
|
||||
}
|
||||
|
||||
@@ -1308,12 +1464,12 @@ static archive_handle_t *init_archive_deb_ar(const char *filename)
|
||||
{
|
||||
archive_handle_t *ar_handle;
|
||||
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_handle = init_handle();
|
||||
ar_handle->filter = filter_accept_list_reassign;
|
||||
ar_handle->src_fd = bb_xopen(filename, O_RDONLY);
|
||||
|
||||
return(ar_handle);
|
||||
return(ar_handle);
|
||||
}
|
||||
|
||||
static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
@@ -1322,10 +1478,9 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
tar_handle = init_handle();
|
||||
tar_handle->filter = filter_accept_list;
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We dont care about data.tar.* or debian-binary, just control.tar.* */
|
||||
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
ar_handle->accept = llist_add_to(NULL, "control.tar.gz");
|
||||
#endif
|
||||
@@ -1336,7 +1491,7 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
@@ -1345,27 +1500,27 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
tar_handle = init_handle();
|
||||
tar_handle->filter = filter_accept_all;
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We dont care about data.tar.* or debian-binary, just control.tar.* */
|
||||
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
tar_handle->accept = llist_add_to(NULL, "data.tar.gz");
|
||||
ar_handle->accept = llist_add_to(NULL, "data.tar.gz");
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
tar_handle->accept = llist_add_to(ar_handle->accept, "data.tar.bz2");
|
||||
ar_handle->accept = 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;
|
||||
return;
|
||||
}
|
||||
|
||||
static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *accept)
|
||||
static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept)
|
||||
{
|
||||
ar_handle->sub_archive->action_data = data_extract_to_buffer;
|
||||
ar_handle->sub_archive->accept = accept;
|
||||
ar_handle->sub_archive->accept = myaccept;
|
||||
ar_handle->sub_archive->filter = filter_accept_list;
|
||||
|
||||
unpack_ar_archive(ar_handle);
|
||||
close(ar_handle->src_fd);
|
||||
@@ -1395,6 +1550,8 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
char *info_prefix;
|
||||
archive_handle_t *archive_handle;
|
||||
FILE *out_stream;
|
||||
llist_t *accept_list = NULL;
|
||||
int i = 0;
|
||||
|
||||
/* If existing version, remove it first */
|
||||
if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) {
|
||||
@@ -1402,7 +1559,7 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
printf("Preparing to replace %s %s (using %s) ...\n", package_name,
|
||||
name_hashtable[package_hashtable[status_package_num]->version],
|
||||
deb_file->filename);
|
||||
remove_package(status_package_num);
|
||||
remove_package(status_package_num, 0);
|
||||
} else {
|
||||
printf("Unpacking %s (from %s) ...\n", package_name, deb_file->filename);
|
||||
}
|
||||
@@ -1412,29 +1569,42 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name);
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
init_archive_deb_control(archive_handle);
|
||||
|
||||
while(all_control_files[i]) {
|
||||
char *c = (char *) xmalloc(3 + bb_strlen(all_control_files[i]));
|
||||
sprintf(c, "./%s", all_control_files[i]);
|
||||
accept_list= llist_add_to(accept_list, c);
|
||||
i++;
|
||||
}
|
||||
archive_handle->sub_archive->accept = accept_list;
|
||||
archive_handle->sub_archive->filter = filter_accept_list;
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = info_prefix;
|
||||
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Run the preinst prior to extracting */
|
||||
if (run_package_script(package_name, "preinst") != 0) {
|
||||
/* when preinst returns exit code != 0 then quit installation process */
|
||||
bb_error_msg_and_die("subprocess pre-installation script returned error.");
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract data.tar.gz to the root directory */
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
init_archive_deb_data(archive_handle);
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = "/";
|
||||
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Create the list file */
|
||||
strcat(info_prefix, "list");
|
||||
out_stream = bb_xfopen(info_prefix, "w");
|
||||
while (archive_handle->passed) {
|
||||
/* blindly skip over the leading '.' */
|
||||
fputs(archive_handle->passed->data + 1, out_stream);
|
||||
out_stream = bb_xfopen(info_prefix, "w");
|
||||
while (archive_handle->sub_archive->passed) {
|
||||
/* the leading . has been stripped by data_extract_all_prefix already */
|
||||
fputs(archive_handle->sub_archive->passed->data, out_stream);
|
||||
fputc('\n', out_stream);
|
||||
archive_handle->passed = archive_handle->passed->link;
|
||||
archive_handle->sub_archive->passed = archive_handle->sub_archive->passed->link;
|
||||
}
|
||||
fclose(out_stream);
|
||||
|
||||
@@ -1451,7 +1621,7 @@ void configure_package(deb_file_t *deb_file)
|
||||
const char *package_version = name_hashtable[package_hashtable[deb_file->package]->version];
|
||||
const int status_num = search_status_hashtable(package_name);
|
||||
|
||||
printf("Setting up %s (%s)\n", package_name, package_version);
|
||||
printf("Setting up %s (%s) ...\n", package_name, package_version);
|
||||
|
||||
/* Run the postinst script */
|
||||
if (run_package_script(package_name, "postinst") != 0) {
|
||||
@@ -1484,7 +1654,8 @@ int dpkg_main(int argc, char **argv)
|
||||
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;
|
||||
@@ -1521,7 +1692,7 @@ int dpkg_main(int argc, char **argv)
|
||||
list_packages();
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* Read arguments and store relevant info in structs */
|
||||
while (optind < argc) {
|
||||
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
|
||||
@@ -1544,25 +1715,27 @@ int dpkg_main(int argc, char **argv)
|
||||
|
||||
if (package_num == -1) {
|
||||
bb_error_msg("Invalid control file in %s", argv[optind]);
|
||||
optind++;
|
||||
continue;
|
||||
}
|
||||
deb_file[deb_count]->package = (unsigned int) package_num;
|
||||
|
||||
/* Add the package to the status hashtable */
|
||||
if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_opt_install)) {
|
||||
status_node = (status_node_t *) xmalloc(sizeof(status_node_t));
|
||||
status_node->package = deb_file[deb_count]->package;
|
||||
/* 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 = (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*/
|
||||
status_node->status = search_name_hashtable("want-install reinstreq not-installed");
|
||||
status_node->status = search_name_hashtable("install reinstreq not-installed");
|
||||
status_hashtable[status_num] = status_node;
|
||||
} else {
|
||||
status_hashtable[status_num]->status = search_name_hashtable("want-install reinstreq not-installed");
|
||||
set_status(status_num, "install", 1);
|
||||
set_status(status_num, "reinstreq", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1575,20 +1748,24 @@ int dpkg_main(int argc, char **argv)
|
||||
if (package_hashtable[deb_file[deb_count]->package] == NULL) {
|
||||
bb_error_msg_and_die("Package %s is uninstalled or unknown\n", argv[optind]);
|
||||
}
|
||||
state_status = get_status(search_status_hashtable(name_hashtable[package_hashtable[deb_file[deb_count]->package]->name]), 3);
|
||||
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 (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[deb_file[deb_count]->package]->name]);
|
||||
bb_error_msg_and_die("%s is already removed.", name_hashtable[package_hashtable[package_num]->name]);
|
||||
}
|
||||
set_status(status_num, "deinstall", 1);
|
||||
}
|
||||
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[deb_file[deb_count]->package]->name]);
|
||||
bb_error_msg_and_die("%s is already purged.", name_hashtable[package_hashtable[package_num]->name]);
|
||||
}
|
||||
set_status(status_num, "purge", 1);
|
||||
}
|
||||
}
|
||||
deb_count++;
|
||||
@@ -1597,17 +1774,17 @@ int dpkg_main(int argc, char **argv)
|
||||
deb_file[deb_count] = NULL;
|
||||
|
||||
/* Check that the deb file arguments are installable */
|
||||
/* TODO: check dependencies before removing */
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: install or remove packages in the correct dependency order */
|
||||
for (i = 0; i < deb_count; i++) {
|
||||
/* Remove or purge packages */
|
||||
if (dpkg_opt & dpkg_opt_remove) {
|
||||
remove_package(deb_file[i]->package);
|
||||
remove_package(deb_file[i]->package, 1);
|
||||
}
|
||||
else if (dpkg_opt & dpkg_opt_purge) {
|
||||
purge_package(deb_file[i]->package);
|
||||
@@ -1617,12 +1794,17 @@ int dpkg_main(int argc, char **argv)
|
||||
}
|
||||
else if (dpkg_opt & dpkg_opt_install) {
|
||||
unpack_package(deb_file[i]);
|
||||
configure_package(deb_file[i]);
|
||||
/* package is configured in second pass below */
|
||||
}
|
||||
else if (dpkg_opt & dpkg_opt_configure) {
|
||||
configure_package(deb_file[i]);
|
||||
}
|
||||
}
|
||||
/* configure installed packages */
|
||||
if (dpkg_opt & dpkg_opt_install) {
|
||||
for (i = 0; i < deb_count; i++)
|
||||
configure_package(deb_file[i]);
|
||||
}
|
||||
|
||||
write_status_file(deb_file);
|
||||
|
||||
|
||||
+50
-45
@@ -12,81 +12,83 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
#define DPKG_DEB_OPT_CONTROL 2
|
||||
#define DPKG_DEB_OPT_FIELD 4
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
extern int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
int opt = 0;
|
||||
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
llist_t *control_tar_llist = NULL;
|
||||
#endif
|
||||
|
||||
unsigned long opt;
|
||||
char *extract_dir = NULL;
|
||||
short argcount = 1;
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
tar_archive = init_handle();
|
||||
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_archive = init_handle();
|
||||
ar_archive->sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
ar_archive->accept = llist_add_to(NULL, "data.tar.gz");
|
||||
# ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
control_tar_llist = llist_add_to(NULL, "control.tar.gz");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2");
|
||||
# ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
while ((opt = getopt(argc, argv, "cefXx")) != -1) {
|
||||
#else
|
||||
while ((opt = getopt(argc, argv, "x")) != -1) {
|
||||
#endif
|
||||
switch (opt) {
|
||||
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
case 'c':
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
break;
|
||||
case 'e':
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->action_data = data_extract_all;
|
||||
break;
|
||||
case 'f':
|
||||
/* Print the entire control file
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->accept = llist_add_to(NULL, "./control");;
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
break;
|
||||
case 'X':
|
||||
tar_archive->action_header = header_list;
|
||||
#endif
|
||||
case 'x':
|
||||
tar_archive->action_data = data_extract_all;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
bb_opt_complementaly = "c~efXx:e~cfXx:f~ceXx:X~cefx:x~cefX";
|
||||
opt = bb_getopt_ulflags(argc, argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_CONTROL) {
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->action_data = data_extract_all;
|
||||
if (optind + 1 == argc) {
|
||||
extract_dir = "./DEBIAN";
|
||||
} else {
|
||||
argcount++;
|
||||
}
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_FIELD) {
|
||||
/* Print the entire control file
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->accept = llist_add_to(NULL, "./control");;
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_EXTRACT) {
|
||||
tar_archive->action_header = header_list;
|
||||
}
|
||||
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
|
||||
tar_archive->action_data = data_extract_all;
|
||||
argcount = 2;
|
||||
}
|
||||
|
||||
if (optind + 2 < argc) {
|
||||
if ((optind + argcount != argc) || (opt & BB_GETOPT_ERROR)) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
@@ -94,9 +96,13 @@ extern int dpkg_deb_main(int argc, char **argv)
|
||||
|
||||
/* Workout where to extract the files */
|
||||
/* 2nd argument is a dir name */
|
||||
mkdir(argv[optind], 0777);
|
||||
chdir(argv[optind]);
|
||||
|
||||
if (argv[optind]) {
|
||||
extract_dir = argv[optind];
|
||||
}
|
||||
if (extract_dir) {
|
||||
mkdir(extract_dir, 0777);
|
||||
chdir(extract_dir);
|
||||
}
|
||||
unpack_ar_archive(ar_archive);
|
||||
|
||||
/* Cleanup */
|
||||
@@ -104,4 +110,3 @@ extern int dpkg_deb_main(int argc, char **argv)
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
+20
-38
@@ -12,8 +12,8 @@
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@optushome.com.au>
|
||||
*
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -71,37 +71,20 @@ static char *license_msg[] = {
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
const char gunzip_to_stdout = 1;
|
||||
const char gunzip_force = 2;
|
||||
const char gunzip_test = 4;
|
||||
#define GUNZIP_OPT_STDOUT 1
|
||||
#define GUNZIP_OPT_FORCE 2
|
||||
#define GUNZIP_OPT_TEST 4
|
||||
#define GUNZIP_OPT_DECOMPRESS 8
|
||||
|
||||
extern int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
char status = EXIT_SUCCESS;
|
||||
char flags = 0;
|
||||
int opt;
|
||||
unsigned long opt;
|
||||
|
||||
opt = bb_getopt_ulflags(argc, argv, "cftd");
|
||||
/* if called as zcat */
|
||||
if (strcmp(bb_applet_name, "zcat") == 0) {
|
||||
flags |= gunzip_to_stdout;
|
||||
}
|
||||
|
||||
while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
flags |= gunzip_to_stdout;
|
||||
break;
|
||||
case 'f':
|
||||
flags |= gunzip_force;
|
||||
break;
|
||||
case 't':
|
||||
flags |= gunzip_test;
|
||||
break;
|
||||
case 'd': /* Used to convert gzip to gunzip. */
|
||||
break;
|
||||
default:
|
||||
bb_show_usage(); /* exit's inside usage */
|
||||
}
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -115,8 +98,8 @@ extern int gunzip_main(int argc, char **argv)
|
||||
optind++;
|
||||
|
||||
if (old_path == NULL || strcmp(old_path, "-") == 0) {
|
||||
src_fd = fileno(stdin);
|
||||
flags |= gunzip_to_stdout;
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
} else {
|
||||
src_fd = bb_xopen(old_path, O_RDONLY);
|
||||
|
||||
@@ -127,16 +110,16 @@ extern int gunzip_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && ((flags & gunzip_force) == 0)) {
|
||||
if (isatty(src_fd) && ((opt & GUNZIP_OPT_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_test) {
|
||||
if (opt & GUNZIP_OPT_TEST) {
|
||||
dst_fd = bb_xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */
|
||||
} else if (flags & gunzip_to_stdout) {
|
||||
dst_fd = fileno(stdout);
|
||||
} else if (opt & GUNZIP_OPT_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
char *extension;
|
||||
|
||||
@@ -170,20 +153,19 @@ extern int gunzip_main(int argc, char **argv)
|
||||
/* do the decompression, and cleanup */
|
||||
if (bb_xread_char(src_fd) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
|
||||
magic2 = bb_xread_char(src_fd);
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
if (magic2 == 0x9d) {
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
} else
|
||||
} else
|
||||
#endif
|
||||
if (magic2 == 0x8b) {
|
||||
check_header_gzip(src_fd);
|
||||
status = inflate(src_fd, dst_fd);
|
||||
status = inflate_gunzip(src_fd, dst_fd);
|
||||
if (status != 0) {
|
||||
bb_error_msg_and_die("Error inflating");
|
||||
}
|
||||
check_trailer_gzip(src_fd);
|
||||
} else {
|
||||
bb_error_msg_and_die("Invalid magic");
|
||||
}
|
||||
@@ -196,10 +178,10 @@ extern int gunzip_main(int argc, char **argv)
|
||||
delete_path = new_path;
|
||||
}
|
||||
|
||||
if (dst_fd != fileno(stdout)) {
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != fileno(stdin)) {
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
|
||||
+19
-41
@@ -9,8 +9,8 @@
|
||||
* only standard in to standard out with -9 compression. It also requires
|
||||
* the zcat module for some important functions."
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support
|
||||
* files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* 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.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
@@ -51,12 +51,6 @@
|
||||
#include <time.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef unsigned long ulg;
|
||||
@@ -214,9 +208,6 @@ typedef int file_t; /* Do not use stdio */
|
||||
static int zip(int in, int out);
|
||||
static int file_read(char *buf, unsigned size);
|
||||
|
||||
/* from gzip.c */
|
||||
static RETSIGTYPE abort_gzip(void);
|
||||
|
||||
/* from deflate.c */
|
||||
static void lm_init(ush * flags);
|
||||
static ulg deflate(void);
|
||||
@@ -305,8 +296,6 @@ DECLARE(ush, d_buf, DIST_BUFSIZE);
|
||||
DECLARE(uch, window, 2L * WSIZE);
|
||||
DECLARE(ush, tab_prefix, 1L << BITS);
|
||||
|
||||
static int crc_table_empty = 1;
|
||||
|
||||
static int foreground; /* set if program run in foreground */
|
||||
static int method = DEFLATED; /* compression method */
|
||||
static int exit_code = OK; /* program exit code */
|
||||
@@ -337,7 +326,7 @@ static void put_short(ush w)
|
||||
/* ========================================================================
|
||||
* Signal and error handler.
|
||||
*/
|
||||
static void abort_gzip()
|
||||
static void abort_gzip(int ignored)
|
||||
{
|
||||
exit(ERROR);
|
||||
}
|
||||
@@ -352,13 +341,6 @@ static void clear_bufs(void)
|
||||
bytes_in = 0L;
|
||||
}
|
||||
|
||||
static void write_bb_error_msg(void)
|
||||
{
|
||||
fputc('\n', stderr);
|
||||
bb_perror_nomsg();
|
||||
abort_gzip();
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Does the same as write(), but also handles partial pipe writes and checks
|
||||
* for error return.
|
||||
@@ -368,9 +350,7 @@ static void write_buf(int fd, void *buf, unsigned cnt)
|
||||
unsigned n;
|
||||
|
||||
while ((n = write(fd, buf, cnt)) != cnt) {
|
||||
if (n == (unsigned) (-1)) {
|
||||
write_bb_error_msg();
|
||||
}
|
||||
if (n == (unsigned) (-1)) bb_error_msg_and_die("can't write");
|
||||
cnt -= n;
|
||||
buf = (void *) ((char *) buf + n);
|
||||
}
|
||||
@@ -387,14 +367,13 @@ static ulg updcrc(uch * s, unsigned n)
|
||||
register ulg c; /* temporary variable */
|
||||
static unsigned long crc_32_tab[256];
|
||||
|
||||
if (crc_table_empty) {
|
||||
if (crc_32_tab[1] == 0x00000000L) {
|
||||
unsigned long csr; /* crc shift register */
|
||||
const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */
|
||||
int i; /* counter for all possible eight bit values */
|
||||
int k; /* byte being shifted into crc apparatus */
|
||||
|
||||
/* Compute table of CRC's. */
|
||||
crc_32_tab[0] = 0x00000000L;
|
||||
for (i = 1; i < 256; i++) {
|
||||
csr = i;
|
||||
/* The idea to initialize the register with the byte instead of
|
||||
@@ -562,7 +541,7 @@ static unsigned bi_reverse(unsigned code, int len)
|
||||
/* ===========================================================================
|
||||
* Write out any remaining bits in an incomplete byte.
|
||||
*/
|
||||
static void bi_windup()
|
||||
static void bi_windup(void)
|
||||
{
|
||||
if (bi_valid > 8) {
|
||||
put_short(bi_buf);
|
||||
@@ -635,7 +614,7 @@ static void copy_block(char *buf, unsigned len, int header)
|
||||
* However the F&G algorithm may be faster for some highly redundant
|
||||
* files if the parameter max_chain_length (described below) is too large.
|
||||
*
|
||||
* ACKNOWLEDGEMENTS
|
||||
* ACKNOWLEDGMENTS
|
||||
*
|
||||
* The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
|
||||
* I found it in 'freeze' written by Leonid Broukhis.
|
||||
@@ -849,7 +828,7 @@ static void lm_init(ush * flags)
|
||||
register unsigned j;
|
||||
|
||||
/* Initialize the hash table. */
|
||||
memzero((char *) head, HASH_SIZE * sizeof(*head));
|
||||
memset(head, 0, HASH_SIZE * sizeof(*head));
|
||||
/* prev will be initialized on the fly */
|
||||
|
||||
*flags |= SLOW;
|
||||
@@ -999,7 +978,7 @@ static void check_match(IPos start, IPos match, int length)
|
||||
* file reads are performed for at least two bytes (required for the
|
||||
* translate_eol option).
|
||||
*/
|
||||
static void fill_window()
|
||||
static void fill_window(void)
|
||||
{
|
||||
register unsigned n, m;
|
||||
unsigned more =
|
||||
@@ -1063,7 +1042,7 @@ static void fill_window()
|
||||
* evaluation for matches: a match is finally adopted only if there is
|
||||
* no better match at the next window position.
|
||||
*/
|
||||
static ulg deflate()
|
||||
static ulg deflate(void)
|
||||
{
|
||||
IPos hash_head; /* head of hash chain */
|
||||
IPos prev_match; /* previous match */
|
||||
@@ -1191,8 +1170,6 @@ static ulg deflate()
|
||||
|
||||
typedef struct dirent dir_type;
|
||||
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
/* ======================================================================== */
|
||||
int gzip_main(int argc, char **argv)
|
||||
{
|
||||
@@ -1238,16 +1215,16 @@ int gzip_main(int argc, char **argv)
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
(void) signal(SIGINT, (sig_type) abort_gzip);
|
||||
(void) signal(SIGINT, abort_gzip);
|
||||
}
|
||||
#ifdef SIGTERM
|
||||
if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
|
||||
(void) signal(SIGTERM, (sig_type) abort_gzip);
|
||||
(void) signal(SIGTERM, abort_gzip);
|
||||
}
|
||||
#endif
|
||||
#ifdef SIGHUP
|
||||
if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
|
||||
(void) signal(SIGHUP, (sig_type) abort_gzip);
|
||||
(void) signal(SIGHUP, abort_gzip);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1274,6 +1251,7 @@ int gzip_main(int argc, char **argv)
|
||||
for (i = optind; i < argc; i++) {
|
||||
char *path = NULL;
|
||||
|
||||
clear_bufs();
|
||||
if (strcmp(argv[i], "-") == 0) {
|
||||
time_stamp = 0;
|
||||
ifile_size = -1L;
|
||||
@@ -1752,7 +1730,7 @@ static void ct_init(ush * attr, int *methodp)
|
||||
/* ===========================================================================
|
||||
* Initialize a new block.
|
||||
*/
|
||||
static void init_block()
|
||||
static void init_block(void)
|
||||
{
|
||||
int n; /* iterates over tree elements */
|
||||
|
||||
@@ -2165,7 +2143,7 @@ static void send_tree(ct_data * tree, int max_code)
|
||||
* Construct the Huffman tree for the bit lengths and return the index in
|
||||
* bl_order of the last bit length code to send.
|
||||
*/
|
||||
static const int build_bl_tree()
|
||||
static int build_bl_tree(void)
|
||||
{
|
||||
int max_blindex; /* index of last bit length code of non zero freq */
|
||||
|
||||
@@ -2428,7 +2406,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
|
||||
* IN assertion: the fields freq of dyn_ltree are set and the total of all
|
||||
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
|
||||
*/
|
||||
static void set_file_type()
|
||||
static void set_file_type(void)
|
||||
{
|
||||
int n = 0;
|
||||
unsigned ascii_freq = 0;
|
||||
@@ -2541,7 +2519,7 @@ static int file_read(char *buf, unsigned size)
|
||||
* Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
|
||||
* (used for the compressed data only)
|
||||
*/
|
||||
static void flush_outbuf()
|
||||
static void flush_outbuf(void)
|
||||
{
|
||||
if (outcnt == 0)
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,13 +17,15 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR:= ../../
|
||||
top_srcdir=../..
|
||||
top_builddir=../..
|
||||
srcdir=$(top_srcdir)/archival/libunarchive
|
||||
LIBUNARCHIVE_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
LIBUNARCHIVE_AR:=libunarchive.a
|
||||
ifndef $(LIBUNARCHIVE_DIR)
|
||||
LIBUNARCHIVE_DIR:=$(TOPDIR)archival/libunarchive/
|
||||
LIBUNARCHIVE_DIR:=$(top_builddir)/archival/libunarchive/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/archvial/libunarchive
|
||||
|
||||
LIBUNARCHIVE-y:= \
|
||||
\
|
||||
@@ -31,49 +32,53 @@ LIBUNARCHIVE-y:= \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
filter_accept_list_reassign.o \
|
||||
filter_accept_reject_list.o \
|
||||
\
|
||||
get_header_ar.o \
|
||||
get_header_cpio.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_bz2.o \
|
||||
get_header_tar_gz.o \
|
||||
\
|
||||
header_skip.o \
|
||||
header_list.o \
|
||||
header_verbose_list.o \
|
||||
\
|
||||
archive_xread.o \
|
||||
archive_xread_all.o \
|
||||
archive_xread_all_eof.o \
|
||||
archive_xread_char.o \
|
||||
\
|
||||
seek_by_char.o \
|
||||
seek_by_jump.o \
|
||||
\
|
||||
archive_copy_file.o \
|
||||
\
|
||||
check_header_gzip.o \
|
||||
data_align.o \
|
||||
decompress_bunzip2.o \
|
||||
find_list_entry.o \
|
||||
init_handle.o \
|
||||
uncompress.o \
|
||||
unpack_ar_archive.o \
|
||||
unzip.o
|
||||
open_transformer.o \
|
||||
init_handle.o
|
||||
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG) +=
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) +=
|
||||
LIBUNARCHIVE-$(CONFIG_AR) +=
|
||||
LIBUNARCHIVE-$(CONFIG_CPIO) +=
|
||||
LIBUNARCHIVE-$(CONFIG_GUNZIP) +=
|
||||
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) +=
|
||||
LIBUNARCHIVE-$(CONFIG_TAR) +=
|
||||
LIBUNARCHIVE-$(CONFIG_UNZIP) +=
|
||||
GUNZIP_FILES:= check_header_gzip.o decompress_unzip.o
|
||||
DPKG_FILES:= \
|
||||
get_header_ar.o \
|
||||
unpack_ar_archive.o \
|
||||
get_header_tar.o \
|
||||
filter_accept_list_reassign.o
|
||||
|
||||
LIBUNARCHIVE-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
LIBUNARCHIVE-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
LIBUNARCHIVE-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
LIBUNARCHIVE-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
LIBUNARCHIVE-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
|
||||
|
||||
libraries-y+=$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR)
|
||||
|
||||
$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR): $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
$(AR) $(ARFLAGS) $@ $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
|
||||
$(LIBUNARCHIVA_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void archive_copy_file(const archive_handle_t *archive_handle, const int dst_fd)
|
||||
{
|
||||
char buffer[512];
|
||||
off_t chunksize = archive_handle->file_header->size;
|
||||
|
||||
while (chunksize != 0) {
|
||||
size_t size;
|
||||
if (chunksize > 512) {
|
||||
size = 512;
|
||||
} else {
|
||||
size = chunksize;
|
||||
}
|
||||
// archive_xread_all(archive_handle, buffer, size);
|
||||
size = archive_xread(archive_handle, buffer, size);
|
||||
|
||||
if (write(dst_fd, buffer, size) != size) {
|
||||
bb_error_msg_and_die ("Short write");
|
||||
}
|
||||
chunksize -= size;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf,
|
||||
{
|
||||
ssize_t size;
|
||||
|
||||
size = archive_xread(archive_handle, buf, count);
|
||||
size = bb_full_read(archive_handle->src_fd, buf, count);
|
||||
if (size != count) {
|
||||
bb_error_msg_and_die("Short read");
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned
|
||||
{
|
||||
ssize_t size;
|
||||
|
||||
size = archive_xread(archive_handle, buf, count);
|
||||
size = bb_full_read(archive_handle->src_fd, buf, count);
|
||||
if ((size != 0) && (size != count)) {
|
||||
bb_perror_msg_and_die("Short read, read %d of %d", size, count);
|
||||
bb_perror_msg_and_die("Short read, read %ld of %ld", (long)size, (long)count);
|
||||
}
|
||||
return(size);
|
||||
}
|
||||
@@ -27,7 +27,6 @@ extern void data_align(archive_handle_t *archive_handle, const unsigned short bo
|
||||
const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
|
||||
archive_handle->offset += skip_amount;
|
||||
|
||||
return;
|
||||
|
||||
@@ -35,62 +35,86 @@ extern void data_extract_all(archive_handle_t *archive_handle)
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *name = bb_xstrdup(file_header->name);
|
||||
bb_make_directory (dirname(name), 0777, FILEUTILS_RECUR);
|
||||
bb_make_directory (dirname(name), -1, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
}
|
||||
|
||||
/* Create the filesystem entry */
|
||||
switch(file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
#ifdef CONFIG_CPIO
|
||||
if (file_header->link_name && file_header->size == 0) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Couldnt create hard link");
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* Regular file */
|
||||
unlink(file_header->name);
|
||||
dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
|
||||
archive_copy_file(archive_handle, dst_fd);
|
||||
close(dst_fd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
unlink(file_header->name);
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("extract_archive: %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
unlink(file_header->name);
|
||||
res = symlink(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
unlink(file_header->name);
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_error_msg_and_die("Unrecognised file type");
|
||||
}
|
||||
|
||||
chmod(file_header->name, file_header->mode);
|
||||
chown(file_header->name, file_header->uid, file_header->gid);
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
/* Remove the existing entry if it exists */
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR) && (unlink(file_header->name) == -1) && (errno != ENOENT)) {
|
||||
bb_perror_msg_and_die("Couldnt remove old file");
|
||||
}
|
||||
}
|
||||
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("Couldnt stat old file");
|
||||
}
|
||||
}
|
||||
else if (statbuf.st_mtime <= file_header->mtime) {
|
||||
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_error_msg("%s not created: newer or same age file exists", file_header->name);
|
||||
}
|
||||
data_skip(archive_handle);
|
||||
return;
|
||||
}
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("Couldnt remove old file %s", file_header->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately
|
||||
* We identified hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Couldnt create hard link");
|
||||
}
|
||||
} else {
|
||||
/* Create the filesystem entry */
|
||||
switch(file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
|
||||
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) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("extract_archive: %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
res = symlink(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_error_msg_and_die("Unrecognised file type");
|
||||
}
|
||||
}
|
||||
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
|
||||
#include "unarchive.h"
|
||||
#include <unistd.h>
|
||||
|
||||
extern void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_copy_file(archive_handle, fileno(stdout));
|
||||
bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,11 +1,9 @@
|
||||
#include "config.h"
|
||||
#include "libbb.h"
|
||||
|
||||
#if defined CONFIG_UNCOMPRESS || defined CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
|
||||
/* uncompress for busybox -- (c) 2002 Robert Griebl
|
||||
*
|
||||
* based on the original compress42.c source
|
||||
* based on the original compress42.c source
|
||||
* (see disclaimer below)
|
||||
*/
|
||||
|
||||
@@ -32,7 +30,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Defailt input buffer size */
|
||||
/* Default input buffer size */
|
||||
#define IBUFSIZ 2048
|
||||
|
||||
/* Default output buffer size */
|
||||
@@ -166,7 +164,7 @@ extern int uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
if (insize < (int) sizeof(inbuf) - IBUFSIZ) {
|
||||
rsize = read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
@@ -293,6 +291,3 @@ extern int uncompress(int fd_in, int fd_out)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -12,10 +12,15 @@
|
||||
* command line handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@optushome.com.au>
|
||||
*
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* read_gz interface + associated hacking by Laurence Anderson
|
||||
*
|
||||
* Fixed huft_build() so decoding end-of-block code does not grab more bits
|
||||
* than necessary (this is required by unzip applet), added inflate_cleanup()
|
||||
* to free leaked bytebuffer memory (used in unzip.c), and some minor style
|
||||
* guide cleanups by Ed Clark
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -103,7 +108,7 @@ static unsigned int gunzip_bb; /* bit buffer */
|
||||
static unsigned char gunzip_bk; /* bits in bit buffer */
|
||||
|
||||
/* These control the size of the bytebuffer */
|
||||
#define BYTEBUFFER_MAX 0x8000
|
||||
static unsigned int bytebuffer_max = 0x8000;
|
||||
static unsigned char *bytebuffer = NULL;
|
||||
static unsigned int bytebuffer_offset = 0;
|
||||
static unsigned int bytebuffer_size = 0;
|
||||
@@ -116,26 +121,26 @@ static const unsigned short mask_bits[] = {
|
||||
/* Copy lengths for literal codes 257..285 */
|
||||
static const unsigned short cplens[] = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
|
||||
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
};
|
||||
|
||||
/* note: see note #13 above about the 258 in this list. */
|
||||
/* Extra bits for literal codes 257..285 */
|
||||
static const unsigned char cplext[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
|
||||
5, 5, 5, 0, 99, 99
|
||||
5, 5, 5, 0, 99, 99
|
||||
}; /* 99==invalid */
|
||||
|
||||
/* Copy offsets for distance codes 0..29 */
|
||||
static const unsigned short cpdist[] = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513,
|
||||
769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
|
||||
769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
|
||||
};
|
||||
|
||||
/* Extra bits for distance codes */
|
||||
static const unsigned char cpdext[] = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
|
||||
11, 11, 12, 12, 13, 13
|
||||
11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
@@ -144,21 +149,19 @@ static const unsigned char border[] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
};
|
||||
|
||||
static void fill_bytebuffer(void)
|
||||
{
|
||||
if (bytebuffer_offset >= bytebuffer_size) {
|
||||
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
|
||||
* to the front of the bytebuffer, leave 4 bytes free at end of tail
|
||||
* so we can easily top up buffer in check_trailer_gzip() */
|
||||
bytebuffer_size = 4 + bb_xread(gunzip_src_fd, &bytebuffer[4], BYTEBUFFER_MAX - 8);
|
||||
bytebuffer_offset = 4;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current, const unsigned int required)
|
||||
{
|
||||
while (*current < required) {
|
||||
fill_bytebuffer();
|
||||
if (bytebuffer_offset >= bytebuffer_size) {
|
||||
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
|
||||
* to the front of the bytebuffer, leave 4 bytes free at end of tail
|
||||
* so we can easily top up buffer in check_trailer_gzip() */
|
||||
if (!(bytebuffer_size = bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8))) {
|
||||
bb_error_msg_and_die("unexpected end of file");
|
||||
}
|
||||
bytebuffer_size += 4;
|
||||
bytebuffer_offset = 4;
|
||||
}
|
||||
bitbuffer |= ((unsigned int) bytebuffer[bytebuffer_offset]) << *current;
|
||||
bytebuffer_offset++;
|
||||
*current += 8;
|
||||
@@ -173,7 +176,7 @@ static void make_gunzip_crc_table(void)
|
||||
|
||||
/* initial shift register value */
|
||||
gunzip_crc = 0xffffffffL;
|
||||
gunzip_crc_table = (unsigned int *) malloc(256 * sizeof(unsigned int));
|
||||
gunzip_crc_table = (unsigned int *) xmalloc(256 * sizeof(unsigned int));
|
||||
|
||||
/* Compute and print table of CRC's, five per line */
|
||||
for (i = 0; i < 256; i++) {
|
||||
@@ -189,8 +192,8 @@ static void make_gunzip_crc_table(void)
|
||||
table_entry = (table_entry >> 1) ^ poly;
|
||||
} else {
|
||||
table_entry >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gunzip_crc_table[i] = table_entry;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +201,7 @@ static void make_gunzip_crc_table(void)
|
||||
/*
|
||||
* Free the malloc'ed tables built by huft_build(), which makes a linked
|
||||
* list of the tables it made, with the links in a dummy first entry of
|
||||
* each table.
|
||||
* each table.
|
||||
* t: table to free
|
||||
*/
|
||||
static int huft_free(huft_t * t)
|
||||
@@ -230,70 +233,59 @@ static int huft_free(huft_t * t)
|
||||
* t: result: starting table
|
||||
* m: maximum lookup bits, returns actual
|
||||
*/
|
||||
static int huft_build(unsigned int *b, const unsigned int n,
|
||||
const unsigned int s, const unsigned short *d,
|
||||
const unsigned char *e, huft_t ** t, int *m)
|
||||
int huft_build(unsigned int *b, const unsigned int n,
|
||||
const unsigned int s, const unsigned short *d,
|
||||
const unsigned char *e, huft_t ** t, int *m)
|
||||
{
|
||||
unsigned a; /* counter for codes of length k */
|
||||
unsigned a; /* counter for codes of length k */
|
||||
unsigned c[BMAX + 1]; /* bit length count table */
|
||||
unsigned f; /* i repeats in table every f entries */
|
||||
int g; /* maximum code length */
|
||||
int h; /* table level */
|
||||
unsigned eob_len; /* length of end-of-block code (value 256) */
|
||||
unsigned f; /* i repeats in table every f entries */
|
||||
int g; /* maximum code length */
|
||||
int h; /* table level */
|
||||
register unsigned i; /* counter, current code */
|
||||
register unsigned j; /* counter */
|
||||
register int k; /* number of bits in current code */
|
||||
int l; /* bits per table (returned in m) */
|
||||
register int k; /* number of bits in current code */
|
||||
register unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
register huft_t *q; /* points to current table */
|
||||
huft_t r; /* table entry for structure assignment */
|
||||
huft_t *u[BMAX]; /* table stack */
|
||||
unsigned v[N_MAX]; /* values in order of bit length */
|
||||
register int w; /* bits before this table == (l * h) */
|
||||
register huft_t *q; /* points to current table */
|
||||
huft_t r; /* table entry for structure assignment */
|
||||
huft_t *u[BMAX]; /* table stack */
|
||||
unsigned v[N_MAX]; /* values in order of bit length */
|
||||
int ws[BMAX+1]; /* bits decoded stack */
|
||||
register int w; /* bits decoded */
|
||||
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
|
||||
unsigned *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
unsigned z; /* number of entries in current table */
|
||||
unsigned *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
unsigned z; /* number of entries in current table */
|
||||
|
||||
/* Length of EOB code, if any */
|
||||
eob_len = n > 256 ? b[256] : BMAX;
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset((void *) (c), 0, sizeof(c));
|
||||
memset((void *)c, 0, sizeof(c));
|
||||
p = b;
|
||||
i = n;
|
||||
do {
|
||||
c[*p]++; /* assume all entries <= BMAX */
|
||||
p++; /* Can't combine with above line (Solaris bug) */
|
||||
c[*p]++; /* assume all entries <= BMAX */
|
||||
p++; /* Can't combine with above line (Solaris bug) */
|
||||
} while (--i);
|
||||
if (c[0] == n) { /* null input--all zero length codes */
|
||||
if (c[0] == n) { /* null input--all zero length codes */
|
||||
*t = (huft_t *) NULL;
|
||||
*m = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
l = *m;
|
||||
for (j = 1; j <= BMAX; j++) {
|
||||
if (c[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
k = j; /* minimum code length */
|
||||
if ((unsigned) l < j) {
|
||||
l = j;
|
||||
}
|
||||
for (i = BMAX; i; i--) {
|
||||
if (c[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
g = i; /* maximum code length */
|
||||
if ((unsigned) l > i) {
|
||||
l = i;
|
||||
}
|
||||
*m = l;
|
||||
for (j = 1; (c[j] == 0) && (j <= BMAX); j++);
|
||||
k = j; /* minimum code length */
|
||||
for (i = BMAX; (c[i] == 0) && i; i--);
|
||||
g = i; /* maximum code length */
|
||||
*m = (*m < j) ? j : ((*m > i) ? i : *m);
|
||||
|
||||
/* Adjust last length count to fill out codes, if needed */
|
||||
for (y = 1 << j; j < i; j++, y <<= 1) {
|
||||
if ((y -= c[j]) < 0) {
|
||||
return 2; /* bad input: more codes than bits */
|
||||
return 2; /* bad input: more codes than bits */
|
||||
}
|
||||
}
|
||||
if ((y -= c[i]) < 0) {
|
||||
@@ -305,7 +297,7 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
x[1] = j = 0;
|
||||
p = c + 1;
|
||||
xp = x + 2;
|
||||
while (--i) { /* note that i == g from above */
|
||||
while (--i) { /* note that i == g from above */
|
||||
*xp++ = (j += *p++);
|
||||
}
|
||||
|
||||
@@ -319,13 +311,13 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
} while (++i < n);
|
||||
|
||||
/* Generate the Huffman codes and for each, make the table entries */
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
h = -1; /* no tables yet--level -1 */
|
||||
w = -l; /* bits decoded == (l * h) */
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
h = -1; /* no tables yet--level -1 */
|
||||
w = ws[0] = 0; /* bits decoded */
|
||||
u[0] = (huft_t *) NULL; /* just to keep compilers happy */
|
||||
q = (huft_t *) NULL; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
|
||||
/* go through the bit lengths (k already is bits in shortest code) */
|
||||
for (; k <= g; k++) {
|
||||
@@ -333,52 +325,52 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
while (a--) {
|
||||
/* here i is the Huffman code of length k bits for value *p */
|
||||
/* make tables up to required level */
|
||||
while (k > w + l) {
|
||||
h++;
|
||||
w += l; /* previous table always l bits */
|
||||
while (k > ws[h + 1]) {
|
||||
w = ws[++h];
|
||||
|
||||
/* compute minimum size table less than or equal to l bits */
|
||||
z = (z = g - w) > (unsigned) l ? l : z; /* upper limit on table size */
|
||||
if ((f = 1 << (j = k - w)) > a + 1) { /* try a k-w bit table *//* too few codes for k-w bit table */
|
||||
f -= a + 1; /* deduct codes from patterns left */
|
||||
/* compute minimum size table less than or equal to *m bits */
|
||||
z = (z = g - w) > *m ? *m : z; /* upper limit on table size */
|
||||
if ((f = 1 << (j = k - w)) > a + 1) { /* try a k-w bit table */
|
||||
/* too few codes for k-w bit table */
|
||||
f -= a + 1; /* deduct codes from patterns left */
|
||||
xp = c + k;
|
||||
while (++j < z) { /* try smaller tables up to z bits */
|
||||
while (++j < z) { /* try smaller tables up to z bits */
|
||||
if ((f <<= 1) <= *++xp) {
|
||||
break; /* enough codes to use up j bits */
|
||||
break; /* enough codes to use up j bits */
|
||||
}
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
}
|
||||
}
|
||||
j = (w + j > eob_len && w < eob_len) ? eob_len - w : j; /* make EOB code end at table */
|
||||
z = 1 << j; /* table entries for j-bit table */
|
||||
ws[h+1] = w + j; /* set bits decoded in stack */
|
||||
|
||||
/* allocate and link in new table */
|
||||
q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t));
|
||||
|
||||
*t = q + 1; /* link to list for huft_free() */
|
||||
*(t = &(q->v.t)) = NULL;
|
||||
u[h] = ++q; /* table starts after link */
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h) {
|
||||
x[h] = i; /* save pattern for backing up */
|
||||
r.b = (unsigned char) l; /* bits to dump before this table */
|
||||
r.e = (unsigned char) (16 + j); /* bits in this table */
|
||||
r.v.t = q; /* pointer to this table */
|
||||
j = i >> (w - l); /* (get around Turbo C bug) */
|
||||
u[h - 1][j] = r; /* connect to last table */
|
||||
x[h] = i; /* save pattern for backing up */
|
||||
r.b = (unsigned char) (w - ws[h - 1]); /* bits to dump before this table */
|
||||
r.e = (unsigned char) (16 + j); /* bits in this table */
|
||||
r.v.t = q; /* pointer to this table */
|
||||
j = (i & ((1 << w) - 1)) >> ws[h - 1];
|
||||
u[h - 1][j] = r; /* connect to last table */
|
||||
}
|
||||
}
|
||||
|
||||
/* set up table entry in r */
|
||||
r.b = (unsigned char) (k - w);
|
||||
if (p >= v + n) {
|
||||
r.e = 99; /* out of values--invalid code */
|
||||
r.e = 99; /* out of values--invalid code */
|
||||
} else if (*p < s) {
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */
|
||||
r.v.n = (unsigned short) (*p); /* simple code is just the value */
|
||||
p++; /* one compiler does not like *p++ */
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
|
||||
} else {
|
||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
||||
r.v.n = d[*p++ - s];
|
||||
}
|
||||
|
||||
@@ -396,11 +388,14 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
|
||||
/* backup over finished tables */
|
||||
while ((i & ((1 << w) - 1)) != x[h]) {
|
||||
h--; /* don't need to update q */
|
||||
w -= l;
|
||||
w = ws[--h];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* return actual size of base table */
|
||||
*m = ws[1];
|
||||
|
||||
/* Return true (1) if we were given an incomplete table */
|
||||
return y != 0 && g != 1;
|
||||
}
|
||||
@@ -440,9 +435,9 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned int my_b
|
||||
md = mask_bits[bd];
|
||||
return 0; // Don't actually do anything the first time
|
||||
}
|
||||
|
||||
|
||||
if (resumeCopy) goto do_copy;
|
||||
|
||||
|
||||
while (1) { /* do until end of block */
|
||||
b = fill_bitbuffer(b, &k, bl);
|
||||
if ((e = (t = tl + ((unsigned) b & ml))->e) > 16)
|
||||
@@ -538,7 +533,7 @@ do_copy: do {
|
||||
/* free the decoding tables, return */
|
||||
huft_free(tl);
|
||||
huft_free(td);
|
||||
|
||||
|
||||
/* done */
|
||||
return 0;
|
||||
}
|
||||
@@ -553,7 +548,7 @@ static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
||||
w = gunzip_outbuf_count; /* initialize gunzip_window position */
|
||||
return 0; // Don't do anything first time
|
||||
}
|
||||
|
||||
|
||||
/* read and output the compressed data */
|
||||
while (n--) {
|
||||
b_stored = fill_bitbuffer(b_stored, &k_stored, 8);
|
||||
@@ -644,7 +639,7 @@ static int inflate_block(int *e)
|
||||
inflate_stored(n, b_stored, k_stored, 1); // Setup inflate_stored
|
||||
return -1;
|
||||
}
|
||||
case 1: /* Inflate fixed
|
||||
case 1: /* Inflate fixed
|
||||
* decompress an inflated type 1 (fixed Huffman codes) block. We should
|
||||
* either replace this with a custom decoder, or at least precompute the
|
||||
* Huffman tables.
|
||||
@@ -687,9 +682,9 @@ static int inflate_block(int *e)
|
||||
|
||||
/* decompress until an end-of-block code */
|
||||
inflate_codes(tl, td, bl, bd, 1); // Setup inflate_codes
|
||||
|
||||
|
||||
/* huft_free code moved into inflate_codes */
|
||||
|
||||
|
||||
return -2;
|
||||
}
|
||||
case 2: /* Inflate dynamic */
|
||||
@@ -841,7 +836,7 @@ static int inflate_block(int *e)
|
||||
inflate_codes(tl, td, bl, bd, 1); // Setup inflate_codes
|
||||
|
||||
/* huft_free code moved into inflate_codes */
|
||||
|
||||
|
||||
return -2;
|
||||
}
|
||||
default:
|
||||
@@ -861,24 +856,26 @@ static void calculate_gunzip_crc(void)
|
||||
|
||||
static int inflate_get_next_window(void)
|
||||
{
|
||||
static int needAnotherBlock = 1;
|
||||
static int method = -1; // Method == -1 for stored, -2 for codes
|
||||
static int e = 0;
|
||||
|
||||
static int needAnotherBlock = 1;
|
||||
|
||||
gunzip_outbuf_count = 0;
|
||||
|
||||
while(1) {
|
||||
int ret;
|
||||
|
||||
|
||||
if (needAnotherBlock) {
|
||||
if(e) {
|
||||
calculate_gunzip_crc();
|
||||
e = 0;
|
||||
needAnotherBlock = 1;
|
||||
return 0;
|
||||
} // Last block
|
||||
method = inflate_block(&e);
|
||||
needAnotherBlock = 0;
|
||||
}
|
||||
|
||||
|
||||
switch (method) {
|
||||
case -1: ret = inflate_stored(0,0,0,0);
|
||||
break;
|
||||
@@ -895,54 +892,30 @@ static int inflate_get_next_window(void)
|
||||
/* Doesnt get here */
|
||||
}
|
||||
|
||||
/*
|
||||
* User functions
|
||||
*
|
||||
* read_gz, GZ_gzReadOpen, GZ_gzReadClose, inflate
|
||||
*/
|
||||
|
||||
extern ssize_t read_gz(int fd, void *buf, size_t count)
|
||||
/* Initialise bytebuffer, be careful not to overfill the buffer */
|
||||
extern void inflate_init(unsigned int bufsize)
|
||||
{
|
||||
static int morebytes = 0, finished = 0;
|
||||
|
||||
if (morebytes) {
|
||||
int bytesRead = morebytes > count ? count : morebytes;
|
||||
memcpy(buf, gunzip_window + (gunzip_outbuf_count - morebytes), bytesRead);
|
||||
morebytes -= bytesRead;
|
||||
return bytesRead;
|
||||
} else if (finished) {
|
||||
return 0;
|
||||
} else if (count >= 0x8000) { // We can decompress direcly to the buffer, 32k at a time
|
||||
// Could decompress to larger buffer, but it must be a power of 2, and calculating that is probably more expensive than the benefit
|
||||
unsigned char *old_gunzip_window = gunzip_window; // Save old window
|
||||
gunzip_window = buf;
|
||||
if (inflate_get_next_window() == 0) finished = 1;
|
||||
gunzip_window = old_gunzip_window; // Restore old window
|
||||
return gunzip_outbuf_count;
|
||||
} else { // Oh well, need to split up the gunzip_window
|
||||
int bytesRead;
|
||||
if (inflate_get_next_window() == 0) finished = 1;
|
||||
morebytes = gunzip_outbuf_count;
|
||||
bytesRead = morebytes > count ? count : morebytes;
|
||||
memcpy(buf, gunzip_window, bytesRead);
|
||||
morebytes -= bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
/* Set the bytebuffer size, default is same as gunzip_wsize */
|
||||
bytebuffer_max = bufsize + 8;
|
||||
bytebuffer_offset = 4;
|
||||
bytebuffer_size = 0;
|
||||
}
|
||||
|
||||
extern void GZ_gzReadOpen(int fd, void *unused, int nUnused)
|
||||
extern void inflate_cleanup(void)
|
||||
{
|
||||
free(bytebuffer);
|
||||
}
|
||||
|
||||
extern int inflate_unzip(int in, int out)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
typedef void (*sig_type) (int);
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
gunzip_window = xmalloc(gunzip_wsize);
|
||||
gunzip_outbuf_count = 0;
|
||||
gunzip_bytes_out = 0;
|
||||
gunzip_src_fd = fd;
|
||||
|
||||
/* Input buffer */
|
||||
bytebuffer = xmalloc(BYTEBUFFER_MAX);
|
||||
gunzip_src_fd = in;
|
||||
|
||||
/* initialize gunzip_window, bit buffer */
|
||||
gunzip_bk = 0;
|
||||
@@ -950,10 +923,20 @@ extern void GZ_gzReadOpen(int fd, void *unused, int nUnused)
|
||||
|
||||
/* Create the crc table */
|
||||
make_gunzip_crc_table();
|
||||
}
|
||||
|
||||
extern void GZ_gzReadClose(void)
|
||||
{
|
||||
/* Allocate space for buffer */
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
|
||||
while(1) {
|
||||
int ret = inflate_get_next_window();
|
||||
nwrote = bb_full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == -1) {
|
||||
bb_perror_msg("write");
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0) break;
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
free(gunzip_window);
|
||||
free(gunzip_crc_table);
|
||||
@@ -967,57 +950,20 @@ extern void GZ_gzReadClose(void)
|
||||
gunzip_bb >>= 8;
|
||||
gunzip_bk -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/*extern int inflate(int in, int out) // Useful for testing read_gz
|
||||
{
|
||||
char buf[8192];
|
||||
ssize_t nread, nwrote;
|
||||
|
||||
GZ_gzReadOpen(in, 0, 0);
|
||||
while(1) { // Robbed from bb_copyfd.c
|
||||
nread = read_gz(in, buf, sizeof(buf));
|
||||
if (nread == 0) break; // no data to write
|
||||
else if (nread == -1) {
|
||||
bb_perror_msg("read");
|
||||
return -1;
|
||||
}
|
||||
nwrote = bb_full_write(out, buf, nread);
|
||||
if (nwrote == -1) {
|
||||
bb_perror_msg("write");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
GZ_gzReadClose();
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
extern int inflate(int in, int out)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
GZ_gzReadOpen(in, 0, 0);
|
||||
while(1) {
|
||||
int ret = inflate_get_next_window();
|
||||
nwrote = bb_full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == -1) {
|
||||
bb_perror_msg("write");
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0) break;
|
||||
}
|
||||
GZ_gzReadClose();
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void check_trailer_gzip(int src_fd)
|
||||
extern int inflate_gunzip(int in, int out)
|
||||
{
|
||||
unsigned int stored_crc = 0;
|
||||
unsigned char count;
|
||||
unsigned int count;
|
||||
|
||||
inflate_unzip(in, out);
|
||||
|
||||
/* top up the input buffer with the rest of the trailer */
|
||||
count = bytebuffer_size - bytebuffer_offset;
|
||||
if (count < 8) {
|
||||
bb_xread_all(src_fd, &bytebuffer[bytebuffer_size], 8 - count);
|
||||
bb_xread_all(in, &bytebuffer[bytebuffer_size], 8 - count);
|
||||
bytebuffer_size += 8 - count;
|
||||
}
|
||||
for (count = 0; count != 4; count++) {
|
||||
@@ -1027,14 +973,15 @@ extern void check_trailer_gzip(int src_fd)
|
||||
|
||||
/* Validate decompression - crc */
|
||||
if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
bb_error_msg("crc error");
|
||||
}
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (gunzip_bytes_out !=
|
||||
(bytebuffer[bytebuffer_offset] | (bytebuffer[bytebuffer_offset+1] << 8) |
|
||||
(bytebuffer[bytebuffer_offset+2] << 16) | (bytebuffer[bytebuffer_offset+3] << 24))) {
|
||||
bb_error_msg_and_die("Incorrect length, but crc is correct");
|
||||
bb_error_msg("Incorrect length");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
/*
|
||||
* 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
|
||||
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
|
||||
*/
|
||||
extern char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
{
|
||||
@@ -40,16 +40,13 @@ extern char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
if (strcmp(name_ptr, ".gz") == 0) {
|
||||
archive_handle->sub_archive->read = read;
|
||||
archive_handle->action_data_subarchive = get_header_tar_gz;
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
if (strcmp(name_ptr, ".bz2") == 0) {
|
||||
archive_handle->sub_archive->read = read_bz2;
|
||||
BZ2_bzReadOpen(archive_handle->src_fd, NULL, 0);
|
||||
archive_handle->action_data_subarchive = get_header_tar;
|
||||
archive_handle->action_data_subarchive = get_header_tar_bz2;
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -45,9 +45,11 @@ extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
||||
/* End Of File */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Some ar entries have a trailing '\n' after the previous data entry */
|
||||
/* ar header starts on an even byte (2 byte aligned)
|
||||
* '\n' is used for padding
|
||||
*/
|
||||
if (ar.raw[0] == '\n') {
|
||||
/* fix up the header, we started reading 1 byte too early */
|
||||
memmove(ar.raw, &ar.raw[1], 59);
|
||||
@@ -55,7 +57,7 @@ extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset++;
|
||||
}
|
||||
archive_handle->offset += 60;
|
||||
|
||||
|
||||
/* align the headers based on the header magic */
|
||||
if ((ar.formated.magic[0] != '`') || (ar.formated.magic[1] != '\n')) {
|
||||
bb_error_msg_and_die("Invalid ar header");
|
||||
@@ -84,6 +86,7 @@ extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
} else if (ar.formated.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
|
||||
@@ -112,11 +115,12 @@ extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
archive_handle->action_data(archive_handle);
|
||||
}
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
archive_handle->offset += typed->size + 1;
|
||||
archive_handle->offset += typed->size;
|
||||
/* Set the file pointer to the correct spot, we may have been reading a compressed file */
|
||||
lseek(archive_handle->src_fd, archive_handle->offset, SEEK_SET);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysmacros.h> /* major() and minor() */
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -36,8 +37,7 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
int namesize;
|
||||
char dummy[16];
|
||||
int major, minor, nlink, inode;
|
||||
char extract_flag;
|
||||
|
||||
|
||||
if (pending_hardlinks) { /* Deal with any pending hardlinks */
|
||||
hardlinks_t *tmp;
|
||||
hardlinks_t *oldtmp;
|
||||
@@ -71,24 +71,14 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (strncmp(&cpio_header[0], "07070", 5) != 0) {
|
||||
printf("cpio header is %x-%x-%x-%x-%x\n",
|
||||
cpio_header[0],
|
||||
cpio_header[1],
|
||||
cpio_header[2],
|
||||
cpio_header[3],
|
||||
cpio_header[4]);
|
||||
bb_error_msg_and_die("Unsupported cpio format");
|
||||
}
|
||||
|
||||
if ((cpio_header[5] != '1') && (cpio_header[5] != '2')) {
|
||||
if ((strncmp(&cpio_header[0], "07070", 5) != 0) || ((cpio_header[5] != '1') && (cpio_header[5] != '2'))) {
|
||||
bb_error_msg_and_die("Unsupported cpio format, use newc or crc");
|
||||
}
|
||||
|
||||
{
|
||||
unsigned long tmpsize;
|
||||
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
|
||||
dummy, &inode, (unsigned int*)&file_header->mode,
|
||||
dummy, &inode, (unsigned int*)&file_header->mode,
|
||||
(unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid,
|
||||
&nlink, &file_header->mtime, &tmpsize,
|
||||
dummy, &major, &minor, &namesize, dummy);
|
||||
@@ -128,6 +118,8 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
file_header->link_name[file_header->size] = '\0';
|
||||
archive_handle->offset += file_header->size;
|
||||
file_header->size = 0; /* Stop possible seeks in future */
|
||||
} else {
|
||||
file_header->link_name = NULL;
|
||||
}
|
||||
if (nlink > 1 && !S_ISDIR(file_header->mode)) {
|
||||
if (file_header->size == 0) { /* Put file on a linked list for later */
|
||||
@@ -152,38 +144,18 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
}
|
||||
}
|
||||
}
|
||||
file_header->device = (major << 8) | minor;
|
||||
file_header->device = makedev(major, minor);
|
||||
|
||||
extract_flag = FALSE;
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
struct stat statbuf;
|
||||
|
||||
extract_flag = TRUE;
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (lstat (file_header->name, &statbuf) == 0) {
|
||||
if ((archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) || (statbuf.st_mtime < file_header->mtime)) {
|
||||
/* Remove file if flag set or its older than the file to be extracted */
|
||||
if (unlink(file_header->name) == -1) {
|
||||
bb_perror_msg_and_die("Couldnt remove old file");
|
||||
}
|
||||
} else {
|
||||
if (! archive_handle->flags & ARCHIVE_EXTRACT_QUIET) {
|
||||
bb_error_msg("%s not created: newer or same age file exists", file_header->name);
|
||||
}
|
||||
extract_flag = FALSE;
|
||||
}
|
||||
}
|
||||
archive_handle->action_header(file_header);
|
||||
}
|
||||
|
||||
archive_handle->action_header(file_header);
|
||||
if (extract_flag) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_name);
|
||||
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* FIXME:
|
||||
* In privileged mode if uname and gname map to a uid and gid then use the
|
||||
* mapped value instead of the uid/gid values in tar header
|
||||
*
|
||||
* References:
|
||||
* GNU tar and star man pages,
|
||||
* Opengroup's ustar interchange format,
|
||||
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -29,6 +38,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
union {
|
||||
/* ustar header, Posix 1003.1 */
|
||||
unsigned char raw[512];
|
||||
struct {
|
||||
char name[100]; /* 0-99 */
|
||||
@@ -52,12 +62,12 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
} tar;
|
||||
long sum = 0;
|
||||
long i;
|
||||
char *tmp;
|
||||
static int end = 0;
|
||||
|
||||
/* Align header */
|
||||
data_align(archive_handle, 512);
|
||||
|
||||
if (archive_xread(archive_handle, tar.raw, 512) != 512) {
|
||||
if (bb_full_read(archive_handle->src_fd, tar.raw, 512) != 512) {
|
||||
/* Assume end of file */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
@@ -65,8 +75,17 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.formated.name[0] == 0) {
|
||||
if (end) {
|
||||
/* This is the second consecutive empty header! End of archive!
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
*/
|
||||
while (bb_full_read(archive_handle->src_fd, tar.raw, 512) == 512);
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
end = 1;
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
end = 0;
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar
|
||||
* 0's are for the old tar format
|
||||
@@ -105,31 +124,40 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
} else {
|
||||
file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name);
|
||||
}
|
||||
tmp = last_char_is(archive_handle->file_header->name, '/');
|
||||
if (tmp) {
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
file_header->mode = strtol(tar.formated.mode, NULL, 8);
|
||||
file_header->uid = strtol(tar.formated.uid, NULL, 8);
|
||||
file_header->gid = strtol(tar.formated.gid, NULL, 8);
|
||||
file_header->size = strtol(tar.formated.size, NULL, 8);
|
||||
file_header->mtime = strtol(tar.formated.mtime, NULL, 8);
|
||||
file_header->link_name = (tar.formated.linkname[0] != '\0') ?
|
||||
file_header->link_name = (tar.formated.linkname[0] != '\0') ?
|
||||
bb_xstrdup(tar.formated.linkname) : NULL;
|
||||
file_header->device = (dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) +
|
||||
strtol(tar.formated.devminor, NULL, 8));
|
||||
file_header->device = makedev(strtol(tar.formated.devmajor, NULL, 8),
|
||||
strtol(tar.formated.devminor, NULL, 8));
|
||||
|
||||
#if defined CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY || defined CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* Fix mode, used by the old format */
|
||||
/* Set bits 0-11 of the files mode */
|
||||
file_header->mode = 07777 & strtol(tar.formated.mode, NULL, 8);
|
||||
|
||||
/* Set bits 12-15 of the files mode */
|
||||
switch (tar.formated.typeflag) {
|
||||
# ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
case 0:
|
||||
case '0':
|
||||
/* busybox identifies hard links as being regular files with 0 size and a link name */
|
||||
case '1':
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case '1':
|
||||
bb_error_msg("WARNING: Converting hard link to symlink");
|
||||
case 'x':
|
||||
case 'g':
|
||||
bb_error_msg_and_die("pax is not tar");
|
||||
break;
|
||||
case '7':
|
||||
/* Reserved for high performance files, treat as normal file */
|
||||
case 0:
|
||||
case '0':
|
||||
#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
if (last_char_is(file_header->name, '/')) {
|
||||
file_header->mode |= S_IFDIR;
|
||||
} else
|
||||
#endif
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case '2':
|
||||
file_header->mode |= S_IFLNK;
|
||||
break;
|
||||
@@ -145,8 +173,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
break;
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
case 'L': {
|
||||
longname = xmalloc(file_header->size + 1);
|
||||
archive_xread_all(archive_handle, longname, file_header->size);
|
||||
@@ -164,25 +191,35 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->name = linkname;
|
||||
return(get_header_tar(archive_handle));
|
||||
}
|
||||
case 'D':
|
||||
case 'M':
|
||||
case 'N':
|
||||
case 'S':
|
||||
case 'V':
|
||||
case 'D': /* GNU dump dir */
|
||||
case 'M': /* Continuation of multi volume archive*/
|
||||
case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'S': /* Sparse file */
|
||||
case 'V': /* Volume header */
|
||||
bb_error_msg("Ignoring GNU extension type %c", tar.formated.typeflag);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
bb_error_msg("Unknown typeflag: 0x%x", tar.formated.typeflag);
|
||||
}
|
||||
{ /* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if its a directory */
|
||||
char *tmp = last_char_is(file_header->name, '/');
|
||||
if (tmp) {
|
||||
*tmp = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
|
||||
archive_handle->action_data(archive_handle);
|
||||
archive_handle->passed = llist_add_to(archive_handle->passed, archive_handle->file_header->name);
|
||||
archive_handle->passed = llist_add_to(archive_handle->passed, file_header->name);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_name);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -25,18 +26,13 @@
|
||||
|
||||
extern char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
{
|
||||
BZ2_bzReadOpen(archive_handle->src_fd, NULL, 0);
|
||||
|
||||
archive_handle->read = read_bz2;
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
/* Cleanup */
|
||||
BZ2_bzReadClose();
|
||||
|
||||
/* Can only do one tar.bz2 per archive */
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ extern char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned char magic[2];
|
||||
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
|
||||
archive_xread_all(archive_handle, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("Invalid gzip magic");
|
||||
@@ -30,20 +33,10 @@ extern char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
|
||||
GZ_gzReadOpen(archive_handle->src_fd, 0, 0);
|
||||
|
||||
archive_handle->read = read_gz;
|
||||
archive_handle->seek = seek_by_char;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
/* Cleanup */
|
||||
GZ_gzReadClose();
|
||||
|
||||
check_trailer_gzip(archive_handle->src_fd);
|
||||
|
||||
/* Can only do one tar.bz2 per archive */
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ archive_handle_t *init_handle(void)
|
||||
archive_handle->action_header = header_skip;
|
||||
archive_handle->action_data = data_skip;
|
||||
archive_handle->filter = filter_accept_all;
|
||||
archive_handle->read = bb_full_read;
|
||||
archive_handle->seek = seek_by_jump;
|
||||
|
||||
return(archive_handle);
|
||||
|
||||
@@ -14,20 +14,38 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
extern ssize_t archive_xread(const archive_handle_t *archive_handle, unsigned char *buf, const size_t count)
|
||||
/* transformer(), more than meets the eye */
|
||||
extern int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd))
|
||||
{
|
||||
ssize_t size;
|
||||
int fd_pipe[2];
|
||||
int pid;
|
||||
|
||||
size = archive_handle->read(archive_handle->src_fd, buf, count);
|
||||
if (size < 0) {
|
||||
bb_perror_msg_and_die("Read error");
|
||||
if (pipe(fd_pipe) != 0) {
|
||||
bb_perror_msg_and_die("Can't create pipe");
|
||||
}
|
||||
|
||||
return(size);
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
bb_perror_msg_and_die("Fork failed");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
/* child process */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
||||
transformer(src_fd, fd_pipe[1]);
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(src_fd);
|
||||
exit(0);
|
||||
/* notreached */
|
||||
}
|
||||
|
||||
/* parent process */
|
||||
close(fd_pipe[1]); /* Don't want to write to the child */
|
||||
|
||||
return(fd_pipe[0]);
|
||||
}
|
||||
@@ -14,12 +14,19 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "unarchive.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount)
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* If we are reading through a pipe(), or from stdin then we cant lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*
|
||||
* TODO: rename to seek_by_read
|
||||
*/
|
||||
extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < amount; i++) {
|
||||
archive_xread_char(archive_handle);
|
||||
if (jump_size) {
|
||||
bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
#include "config.h"
|
||||
#include "libbb.h"
|
||||
|
||||
#if defined CONFIG_UNCOMPRESS || defined CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
|
||||
/* uncompress for busybox -- (c) 2002 Robert Griebl
|
||||
*
|
||||
* based on the original compress42.c source
|
||||
* (see disclaimer below)
|
||||
*/
|
||||
|
||||
|
||||
/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
|
||||
*
|
||||
* Authors:
|
||||
* Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
|
||||
* Jim McKie (decvax!mcvax!jim)
|
||||
* Steve Davies (decvax!vax135!petsd!peora!srd)
|
||||
* Ken Turkowski (decvax!decwrl!turtlevax!ken)
|
||||
* James A. Woods (decvax!ihnp4!ames!jaw)
|
||||
* Joe Orost (decvax!vax135!petsd!joe)
|
||||
* Dave Mack (csu@alembic.acs.com)
|
||||
* Peter Jannesen, Network Communication Systems
|
||||
* (peter@ncs.nl)
|
||||
*
|
||||
* marc@suse.de : a small security fix for a buffer overflow
|
||||
*
|
||||
* [... History snipped ...]
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Defailt input buffer size */
|
||||
#define IBUFSIZ 2048
|
||||
|
||||
/* Default output buffer size */
|
||||
#define OBUFSIZ 2048
|
||||
|
||||
/* Defines for third byte of header */
|
||||
#define MAGIC_1 (char_type)'\037' /* First byte of compressed file */
|
||||
#define MAGIC_2 (char_type)'\235' /* Second byte of compressed file */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
|
||||
|
||||
/* machine variants which require cc -Dmachine: pdp11, z8000, DOS */
|
||||
#define FAST
|
||||
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1)
|
||||
#define HPRIME 9941
|
||||
#define BITS 16
|
||||
#undef MAXSEG_64K
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
/* Block compress mode -C compatible with 2.0 */
|
||||
int block_mode = BLOCK_MODE;
|
||||
|
||||
/* user settable max # bits/code */
|
||||
int maxbits = BITS;
|
||||
|
||||
/* Exitcode of compress (-1 no file compressed) */
|
||||
int exit_code = -1;
|
||||
|
||||
/* Input buffer */
|
||||
unsigned char inbuf[IBUFSIZ + 64];
|
||||
|
||||
/* Output buffer */
|
||||
unsigned char outbuf[OBUFSIZ + 2048];
|
||||
|
||||
|
||||
long int htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((unsigned char *)(htab))[i]
|
||||
#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
|
||||
#define clear_htab() memset(htab, -1, sizeof(htab))
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256);
|
||||
|
||||
|
||||
/*
|
||||
* Decompress stdin to stdout. This routine adapts to the codes in the
|
||||
* file building the "string" table on-the-fly; requiring no table to
|
||||
* be stored in the compressed file. The tables used herein are shared
|
||||
* with those of the compress() routine. See the definitions above.
|
||||
*/
|
||||
|
||||
extern int uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
unsigned char *stackp;
|
||||
long int code;
|
||||
int finchar;
|
||||
long int oldcode;
|
||||
long int incode;
|
||||
int inbits;
|
||||
int posbits;
|
||||
int outpos;
|
||||
int insize;
|
||||
int bitmask;
|
||||
long int free_ent;
|
||||
long int maxcode;
|
||||
long int maxmaxcode;
|
||||
int n_bits;
|
||||
int rsize = 0;
|
||||
|
||||
insize = 0;
|
||||
|
||||
inbuf[0] = bb_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);
|
||||
return -1;
|
||||
}
|
||||
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
oldcode = -1;
|
||||
finchar = 0;
|
||||
outpos = 0;
|
||||
posbits = 0 << 3;
|
||||
|
||||
free_ent = ((block_mode) ? FIRST : 256);
|
||||
|
||||
/* As above, initialize the first 256 entries in the table. */
|
||||
clear_tab_prefixof();
|
||||
|
||||
for (code = 255; code >= 0; --code) {
|
||||
tab_suffixof(code) = (unsigned char) code;
|
||||
}
|
||||
|
||||
do {
|
||||
resetbuf:;
|
||||
{
|
||||
int i;
|
||||
int e;
|
||||
int o;
|
||||
|
||||
e = insize - (o = (posbits >> 3));
|
||||
|
||||
for (i = 0; i < e; ++i)
|
||||
inbuf[i] = inbuf[i + o];
|
||||
|
||||
insize = e;
|
||||
posbits = 0;
|
||||
}
|
||||
|
||||
if (insize < (int) sizeof(inbuf) - IBUFSIZ) {
|
||||
rsize = read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
inbits = ((rsize > 0) ? (insize - insize % n_bits) << 3 :
|
||||
(insize << 3) - (n_bits - 1));
|
||||
|
||||
while (inbits > posbits) {
|
||||
if (free_ent > maxcode) {
|
||||
posbits =
|
||||
((posbits - 1) +
|
||||
((n_bits << 3) -
|
||||
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
||||
++n_bits;
|
||||
if (n_bits == maxbits) {
|
||||
maxcode = maxmaxcode;
|
||||
} else {
|
||||
maxcode = MAXCODE(n_bits) - 1;
|
||||
}
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
goto resetbuf;
|
||||
}
|
||||
{
|
||||
unsigned char *p = &inbuf[posbits >> 3];
|
||||
|
||||
code =
|
||||
((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
}
|
||||
posbits += n_bits;
|
||||
|
||||
|
||||
if (oldcode == -1) {
|
||||
outbuf[outpos++] = (unsigned char) (finchar =
|
||||
(int) (oldcode = code));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code == CLEAR && block_mode) {
|
||||
clear_tab_prefixof();
|
||||
free_ent = FIRST - 1;
|
||||
posbits =
|
||||
((posbits - 1) +
|
||||
((n_bits << 3) -
|
||||
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
incode = code;
|
||||
stackp = de_stack;
|
||||
|
||||
/* Special case for KwKwK string. */
|
||||
if (code >= free_ent) {
|
||||
if (code > free_ent) {
|
||||
unsigned char *p;
|
||||
|
||||
posbits -= n_bits;
|
||||
p = &inbuf[posbits >> 3];
|
||||
|
||||
bb_error_msg
|
||||
("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)",
|
||||
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
|
||||
(posbits & 07));
|
||||
bb_error_msg("uncompress: corrupt input");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*--stackp = (unsigned char) finchar;
|
||||
code = oldcode;
|
||||
}
|
||||
|
||||
/* Generate output characters in reverse order */
|
||||
while ((long int) code >= (long int) 256) {
|
||||
*--stackp = tab_suffixof(code);
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
*--stackp = (unsigned char) (finchar = tab_suffixof(code));
|
||||
|
||||
/* And put them out in forward order */
|
||||
{
|
||||
int i;
|
||||
|
||||
if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) {
|
||||
do {
|
||||
if (i > OBUFSIZ - outpos) {
|
||||
i = OBUFSIZ - outpos;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
memcpy(outbuf + outpos, stackp, i);
|
||||
outpos += i;
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
write(fd_out, outbuf, outpos);
|
||||
outpos = 0;
|
||||
}
|
||||
stackp += i;
|
||||
} while ((i = (de_stack - stackp)) > 0);
|
||||
} else {
|
||||
memcpy(outbuf + outpos, stackp, i);
|
||||
outpos += i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate the new entry. */
|
||||
if ((code = free_ent) < maxmaxcode) {
|
||||
tab_prefixof(code) = (unsigned short) oldcode;
|
||||
tab_suffixof(code) = (unsigned char) finchar;
|
||||
free_ent = code + 1;
|
||||
}
|
||||
|
||||
/* Remember previous code. */
|
||||
oldcode = incode;
|
||||
}
|
||||
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
write(fd_out, outbuf, outpos);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
+12
-15
@@ -82,10 +82,10 @@ enum rpm_functions_e {
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
u_int32_t tag; /* 4 byte tag */
|
||||
u_int32_t type; /* 4 byte type */
|
||||
u_int32_t offset; /* 4 byte offset */
|
||||
u_int32_t count; /* 4 byte count */
|
||||
uint32_t tag; /* 4 byte tag */
|
||||
uint32_t type; /* 4 byte type */
|
||||
uint32_t offset; /* 4 byte offset */
|
||||
uint32_t count; /* 4 byte count */
|
||||
} rpm_index;
|
||||
|
||||
static void *map;
|
||||
@@ -197,7 +197,6 @@ void extract_cpio_gz(int fd) {
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->read = read_gz;
|
||||
archive_handle->seek = seek_by_char;
|
||||
//archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
@@ -205,19 +204,17 @@ void extract_cpio_gz(int fd) {
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
archive_handle->src_fd = fd;
|
||||
archive_handle->offset = 0;
|
||||
|
||||
|
||||
bb_xread_all(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("Invalid gzip magic");
|
||||
}
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
chdir("/"); // Install RPM's to root
|
||||
|
||||
GZ_gzReadOpen(archive_handle->src_fd, 0, 0);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
GZ_gzReadClose();
|
||||
|
||||
check_trailer_gzip(archive_handle->src_fd);
|
||||
}
|
||||
|
||||
|
||||
@@ -230,10 +227,10 @@ rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
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 */
|
||||
u_int8_t version; /* 1 byte version number */
|
||||
u_int32_t reserved; /* 4 bytes reserved */
|
||||
u_int32_t entries; /* Number of entries in header (4 bytes) */
|
||||
u_int32_t size; /* Size of store (4 bytes) */
|
||||
uint8_t version; /* 1 byte version number */
|
||||
uint32_t reserved; /* 4 bytes reserved */
|
||||
uint32_t entries; /* Number of entries in header (4 bytes) */
|
||||
uint32_t size; /* Size of store (4 bytes) */
|
||||
} header;
|
||||
rpm_index *tmpindex;
|
||||
int storepos;
|
||||
|
||||
+12
-13
@@ -31,21 +31,21 @@
|
||||
|
||||
struct rpm_lead {
|
||||
unsigned char magic[4];
|
||||
u_int8_t major, minor;
|
||||
u_int16_t type;
|
||||
u_int16_t archnum;
|
||||
uint8_t major, minor;
|
||||
uint16_t type;
|
||||
uint16_t archnum;
|
||||
char name[66];
|
||||
u_int16_t osnum;
|
||||
u_int16_t signature_type;
|
||||
uint16_t osnum;
|
||||
uint16_t signature_type;
|
||||
char reserved[16];
|
||||
};
|
||||
|
||||
struct rpm_header {
|
||||
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
|
||||
u_int8_t version; /* 1 byte version number */
|
||||
u_int32_t reserved; /* 4 bytes reserved */
|
||||
u_int32_t entries; /* Number of entries in header (4 bytes) */
|
||||
u_int32_t size; /* Size of store (4 bytes) */
|
||||
uint8_t version; /* 1 byte version number */
|
||||
uint32_t reserved; /* 4 bytes reserved */
|
||||
uint32_t entries; /* Number of entries in header (4 bytes) */
|
||||
uint32_t size; /* Size of store (4 bytes) */
|
||||
};
|
||||
|
||||
void skip_header(int rpm_fd)
|
||||
@@ -73,7 +73,7 @@ extern int rpm2cpio_main(int argc, char **argv)
|
||||
unsigned char magic[2];
|
||||
|
||||
if (argc == 1) {
|
||||
rpm_fd = fileno(stdin);
|
||||
rpm_fd = STDIN_FILENO;
|
||||
} else {
|
||||
rpm_fd = bb_xopen(argv[1], O_RDONLY);
|
||||
}
|
||||
@@ -89,17 +89,16 @@ extern int rpm2cpio_main(int argc, char **argv)
|
||||
|
||||
/* Skip the main header */
|
||||
skip_header(rpm_fd);
|
||||
|
||||
|
||||
bb_xread_all(rpm_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("Invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip(rpm_fd);
|
||||
if (inflate(rpm_fd, fileno(stdout)) != 0) {
|
||||
if (inflate_gunzip(rpm_fd, STDOUT_FILENO) != 0) {
|
||||
bb_error_msg("Error inflating");
|
||||
}
|
||||
check_trailer_gzip(rpm_fd);
|
||||
|
||||
close(rpm_fd);
|
||||
|
||||
|
||||
+254
-133
@@ -1,15 +1,15 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini tar implementation for busybox
|
||||
* Mini tar implementation for busybox
|
||||
*
|
||||
* Modifed to use common extraction code used by ar, cpio, dpkg-deb, dpkg
|
||||
* Glenn McGrath <bug1@optushome.com.au>
|
||||
* Modified to use common extraction code used by ar, cpio, dpkg-deb, dpkg
|
||||
* Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* Note, that as of BusyBox-0.43, tar has been completely rewritten from the
|
||||
* ground up. It still has remnents of the old code lying about, but it is
|
||||
* ground up. It still has remnants of the old code lying about, but it is
|
||||
* very different now (i.e., cleaner, less global variables, etc.)
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* Based in part in the tar implementation in sash
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysmacros.h> /* major() and minor() */
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
@@ -58,11 +59,6 @@
|
||||
# define TAR_MAGIC "ustar" /* ustar and a null */
|
||||
# define TAR_VERSION " " /* Be compatable with GNU tar format */
|
||||
|
||||
# ifndef MAJOR
|
||||
# define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
# define MINOR(dev) ((dev)&0xff)
|
||||
# endif
|
||||
|
||||
static const int TAR_BLOCK_SIZE = 512;
|
||||
static const int TAR_MAGIC_LEN = 6;
|
||||
static const int TAR_VERSION_LEN = 2;
|
||||
@@ -111,7 +107,7 @@ struct TarBallInfo {
|
||||
for the tarball */
|
||||
struct stat statBuf; /* Stat info for the tarball, letting
|
||||
us know the inode and device that the
|
||||
tarball lives, so we can avoid trying
|
||||
tarball lives, so we can avoid trying
|
||||
to include the tarball into itself */
|
||||
int verboseFlag; /* Whether to print extra stuff or not */
|
||||
const llist_t *excludeList; /* List of files to not include */
|
||||
@@ -238,9 +234,9 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
TAR_MAGIC_LEN + TAR_VERSION_LEN);
|
||||
|
||||
/* Enter the user and group names (default to root if it fails) */
|
||||
if (my_getpwuid(header.uname, statbuf->st_uid) == NULL)
|
||||
if (my_getpwuid(header.uname, statbuf->st_uid, sizeof(header.uname)) == NULL)
|
||||
strcpy(header.uname, "root");
|
||||
if (my_getgrgid(header.gname, statbuf->st_gid) == NULL)
|
||||
if (my_getgrgid(header.gname, statbuf->st_gid, sizeof(header.gname)) == NULL)
|
||||
strcpy(header.gname, "root");
|
||||
|
||||
if (tbInfo->hlInfo) {
|
||||
@@ -262,15 +258,15 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
} else if (S_ISCHR(statbuf->st_mode)) {
|
||||
header.typeflag = CHRTYPE;
|
||||
putOctal(header.devmajor, sizeof(header.devmajor),
|
||||
MAJOR(statbuf->st_rdev));
|
||||
major(statbuf->st_rdev));
|
||||
putOctal(header.devminor, sizeof(header.devminor),
|
||||
MINOR(statbuf->st_rdev));
|
||||
minor(statbuf->st_rdev));
|
||||
} else if (S_ISBLK(statbuf->st_mode)) {
|
||||
header.typeflag = BLKTYPE;
|
||||
putOctal(header.devmajor, sizeof(header.devmajor),
|
||||
MAJOR(statbuf->st_rdev));
|
||||
major(statbuf->st_rdev));
|
||||
putOctal(header.devminor, sizeof(header.devminor),
|
||||
MINOR(statbuf->st_rdev));
|
||||
minor(statbuf->st_rdev));
|
||||
} else if (S_ISFIFO(statbuf->st_mode)) {
|
||||
header.typeflag = FIFOTYPE;
|
||||
} else if (S_ISREG(statbuf->st_mode)) {
|
||||
@@ -308,21 +304,18 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
if (tbInfo->verboseFlag) {
|
||||
FILE *vbFd = stdout;
|
||||
|
||||
if (tbInfo->verboseFlag == 2) /* If the archive goes to stdout, verbose to stderr */
|
||||
if (tbInfo->tarFd == STDOUT_FILENO) /* If the archive goes to stdout, verbose to stderr */
|
||||
vbFd = stderr;
|
||||
|
||||
fprintf(vbFd, "%s\n", header.name);
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
# if defined CONFIG_FEATURE_TAR_EXCLUDE
|
||||
# ifdef CONFIG_FEATURE_TAR_FROM
|
||||
static inline int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
{
|
||||
if (excluded_files == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (excluded_files) {
|
||||
if (excluded_files->data[0] == '/') {
|
||||
if (fnmatch(excluded_files->data, file,
|
||||
@@ -343,7 +336,7 @@ static inline int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
void *userData)
|
||||
@@ -399,11 +392,11 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
if (header_name[0] == '\0')
|
||||
return TRUE;
|
||||
|
||||
# if defined CONFIG_FEATURE_TAR_EXCLUDE
|
||||
# ifdef CONFIG_FEATURE_TAR_FROM
|
||||
if (exclude_file(tbInfo->excludeList, header_name)) {
|
||||
return SKIP;
|
||||
}
|
||||
# endif /* CONFIG_FEATURE_TAR_EXCLUDE */
|
||||
# endif /* CONFIG_FEATURE_TAR_FROM */
|
||||
|
||||
if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
|
||||
return (FALSE);
|
||||
@@ -413,8 +406,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
if ((tbInfo->hlInfo == NULL)
|
||||
&& (S_ISREG(statbuf->st_mode))) {
|
||||
int inputFileFd;
|
||||
char buffer[BUFSIZ];
|
||||
ssize_t size = 0, readSize = 0;
|
||||
ssize_t readSize = 0;
|
||||
|
||||
/* open the file we want to archive, and make sure all is well */
|
||||
if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
|
||||
@@ -423,18 +415,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
}
|
||||
|
||||
/* write the file to the archive */
|
||||
while ((size = bb_full_read(inputFileFd, buffer, sizeof(buffer))) > 0) {
|
||||
if (bb_full_write(tbInfo->tarFd, buffer, size) != size) {
|
||||
/* Output file seems to have a problem */
|
||||
bb_error_msg(bb_msg_io_error, fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
readSize += size;
|
||||
}
|
||||
if (size == -1) {
|
||||
bb_error_msg(bb_msg_io_error, fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd);
|
||||
|
||||
/* Pad the file up to the tar block size */
|
||||
for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++) {
|
||||
write(tbInfo->tarFd, "\0", 1);
|
||||
@@ -445,8 +427,9 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static inline int writeTarFile(const char *tarName, const int verboseFlag,
|
||||
const llist_t *include, const llist_t *exclude, const int gzip)
|
||||
static inline int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
const unsigned long dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, const int gzip)
|
||||
{
|
||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
int gzipDataPipe[2] = { -1, -1 };
|
||||
@@ -461,31 +444,14 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
|
||||
|
||||
tbInfo.hlInfoHead = NULL;
|
||||
|
||||
/* Make sure there is at least one file to tar up. */
|
||||
if (include == NULL) {
|
||||
bb_error_msg_and_die("Cowardly refusing to create an empty archive");
|
||||
}
|
||||
|
||||
/* Open the tar file for writing. */
|
||||
if (tarName == NULL || (tarName[0] == '-' && tarName[1] == '\0')) {
|
||||
tbInfo.tarFd = fileno(stdout);
|
||||
tbInfo.verboseFlag = verboseFlag ? 2 : 0;
|
||||
} else {
|
||||
unlink(tarName);
|
||||
tbInfo.tarFd = open(tarName, O_WRONLY | O_CREAT | O_EXCL, 0644);
|
||||
tbInfo.verboseFlag = verboseFlag ? 1 : 0;
|
||||
}
|
||||
|
||||
if (tbInfo.tarFd < 0) {
|
||||
bb_perror_msg("%s: Cannot open", tarName);
|
||||
freeHardLinkInfo(&tbInfo.hlInfoHead);
|
||||
return (FALSE);
|
||||
}
|
||||
fchmod(tar_fd, 0644);
|
||||
tbInfo.tarFd = tar_fd;
|
||||
tbInfo.verboseFlag = verboseFlag;
|
||||
|
||||
/* Store the stat info for the tarball's file, so
|
||||
* can avoid including the tarball into itself.... */
|
||||
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
|
||||
bb_error_msg_and_die(bb_msg_io_error, tarName);
|
||||
bb_perror_msg_and_die("Couldnt stat tar file");
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
if (gzip) {
|
||||
@@ -500,20 +466,23 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
|
||||
(void) &include;
|
||||
(void) &errorFlag;
|
||||
# endif
|
||||
|
||||
|
||||
gzipPid = vfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
dup2(gzipDataPipe[0], 0);
|
||||
close(gzipDataPipe[1]);
|
||||
|
||||
if (tbInfo.tarFd != 1);
|
||||
dup2(tbInfo.tarFd, 1);
|
||||
if (tbInfo.tarFd != 1)
|
||||
dup2(tbInfo.tarFd, 1);
|
||||
|
||||
close(gzipStatusPipe[0]);
|
||||
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */
|
||||
|
||||
execl("/bin/gzip", "gzip", "-f", 0);
|
||||
if (gzip == 1)
|
||||
execlp("gzip", "gzip", "-f", 0);
|
||||
else
|
||||
execlp("bzip2", "bzip2", "-f", 0);
|
||||
vfork_exec_errno = errno;
|
||||
|
||||
close(gzipStatusPipe[1]);
|
||||
@@ -547,7 +516,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
|
||||
|
||||
/* Read the directory/files and iterate over them one at a time */
|
||||
while (include) {
|
||||
if (!recursive_action(include->data, TRUE, FALSE, FALSE,
|
||||
if (!recursive_action(include->data, TRUE, dereferenceFlag, FALSE,
|
||||
writeFileToTarball, writeFileToTarball,
|
||||
(void *) &tbInfo)) {
|
||||
errorFlag = TRUE;
|
||||
@@ -572,7 +541,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
|
||||
freeHardLinkInfo(&tbInfo.hlInfoHead);
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
if (gzip && gzipPid) {
|
||||
if (gzipPid) {
|
||||
if (waitpid(gzipPid, NULL, 0) == -1)
|
||||
printf("Couldnt wait ?");
|
||||
}
|
||||
@@ -582,7 +551,7 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
|
||||
}
|
||||
#endif /* tar_create */
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_EXCLUDE
|
||||
#ifdef CONFIG_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
{
|
||||
FILE *src_stream;
|
||||
@@ -605,29 +574,127 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_COMPRESS
|
||||
static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
|
||||
static const char tar_options[]="ctxjT:X:C:f:Opvz";
|
||||
#define CTX_CREATE 1
|
||||
#define CTX_TEST 2
|
||||
#define CTX_EXTRACT 4
|
||||
#define TAR_OPT_BZIP2 8
|
||||
#define TAR_OPT_INCLUDE 16
|
||||
#define TAR_OPT_EXCLUDE 32
|
||||
#define TAR_OPT_BASEDIR 64
|
||||
#define TAR_OPT_ARNAME 128
|
||||
#define TAR_OPT_2STDOUT 256
|
||||
#define TAR_OPT_P 512
|
||||
#define TAR_OPT_VERBOSE 1024
|
||||
#define TAR_OPT_GZIP 2048
|
||||
/* do the decompression, and cleanup */
|
||||
if ((bb_xread_char(archive_handle->src_fd) != 0x1f) || (bb_xread_char(archive_handle->src_fd) != 0x9d)) {
|
||||
bb_error_msg_and_die("Invalid magic");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CTX_TEST (1 << 0)
|
||||
#define CTX_EXTRACT (1 << 1)
|
||||
#define TAR_OPT_BASEDIR (1 << 2)
|
||||
#define TAR_OPT_TARNAME (1 << 3)
|
||||
#define TAR_OPT_2STDOUT (1 << 4)
|
||||
#define TAR_OPT_P (1 << 5)
|
||||
#define TAR_OPT_VERBOSE (1 << 6)
|
||||
#define TAR_OPT_KEEP_OLD (1 << 7)
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_CREATE
|
||||
# define CTX_CREATE (1 << 8)
|
||||
# define TAR_OPT_DEREFERNCE (1 << 9)
|
||||
# define TAR_OPT_STR_CREATE "ch"
|
||||
# define TAR_OPT_FLAG_CREATE 2
|
||||
#else
|
||||
//# define CTX_CREATE 0
|
||||
# define TAR_OPT_STR_CREATE ""
|
||||
# define TAR_OPT_FLAG_CREATE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_BZIP2
|
||||
# define TAR_OPT_BZIP2 (1 << (8 + TAR_OPT_FLAG_CREATE))
|
||||
# define TAR_OPT_STR_BZIP2 "j"
|
||||
# define TAR_OPT_FLAG_BZIP2 1
|
||||
#else
|
||||
# define TAR_OPT_STR_BZIP2 ""
|
||||
# define TAR_OPT_FLAG_BZIP2 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_FROM
|
||||
# define TAR_OPT_INCLUDE_FROM (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2))
|
||||
# define TAR_OPT_EXCLUDE_FROM (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + 1))
|
||||
# define TAR_OPT_STR_FROM "T:X:"
|
||||
# define TAR_OPT_FLAG_FROM 2
|
||||
#else
|
||||
# define TAR_OPT_STR_FROM ""
|
||||
# define TAR_OPT_FLAG_FROM 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
# define TAR_OPT_GZIP (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + TAR_OPT_FLAG_FROM))
|
||||
# define TAR_OPT_STR_GZIP "z"
|
||||
# define TAR_OPT_FLAG_GZIP 1
|
||||
#else
|
||||
# define TAR_OPT_STR_GZIP ""
|
||||
# define TAR_OPT_FLAG_GZIP 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_COMPRESS
|
||||
# define TAR_OPT_UNCOMPRESS (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + TAR_OPT_FLAG_FROM + TAR_OPT_FLAG_GZIP))
|
||||
# define TAR_OPT_STR_COMPRESS "Z"
|
||||
#else
|
||||
# define TAR_OPT_STR_COMPRESS ""
|
||||
#endif
|
||||
|
||||
static const char tar_options[]="txC:f:Opvk" \
|
||||
TAR_OPT_STR_CREATE \
|
||||
TAR_OPT_STR_BZIP2 \
|
||||
TAR_OPT_STR_FROM \
|
||||
TAR_OPT_STR_GZIP \
|
||||
TAR_OPT_STR_COMPRESS;
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS
|
||||
static const struct option tar_long_options[] = {
|
||||
{ "list", 0, NULL, 't' },
|
||||
{ "extract", 0, NULL, 'x' },
|
||||
{ "directory", 1, NULL, 'C' },
|
||||
{ "file", 1, NULL, 'f' },
|
||||
{ "to-stdout", 0, NULL, 'O' },
|
||||
{ "same-permissions", 0, NULL, 'p' },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "keep-old", 0, NULL, 'k' },
|
||||
# ifdef CONFIG_FEATURE_TAR_CREATE
|
||||
{ "create", 0, NULL, 'c' },
|
||||
{ "dereference", 0, NULL, 'h' },
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_TAR_BZIP2
|
||||
{ "bzip2", 0, NULL, 'j' },
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_TAR_FROM
|
||||
{ "files-from", 1, NULL, 'T' },
|
||||
{ "exclude-from", 1, NULL, 'X' },
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
{ "gzip", 0, NULL, 'z' },
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_TAR_COMPRESS
|
||||
{ "compress", 0, NULL, 'Z' },
|
||||
# endif
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
int tar_main(int argc, char **argv)
|
||||
{
|
||||
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
|
||||
archive_handle_t *tar_handle;
|
||||
int opt;
|
||||
char *base_dir = NULL;
|
||||
const char *tar_filename = "-";
|
||||
unsigned char ctx_flag = 0;
|
||||
unsigned long opt;
|
||||
unsigned long ctx_flag = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
bb_show_usage();
|
||||
@@ -643,59 +710,87 @@ int tar_main(int argc, char **argv)
|
||||
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE;
|
||||
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
|
||||
bb_opt_complementaly = "c~tx:t~cx:x~ct:X*:T*";
|
||||
#ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS
|
||||
bb_applet_long_options = tar_long_options;
|
||||
#endif
|
||||
|
||||
bb_opt_complementaly = "c~tx:t~cx:x~ct:X*";
|
||||
opt = bb_getopt_ulflags(argc, argv, tar_options,
|
||||
NULL, /* T: arg is ignored by default
|
||||
a list is an include list */
|
||||
&(tar_handle->reject),
|
||||
&base_dir, /* Change to dir <optarg> */
|
||||
&tar_filename); /* archive filename */
|
||||
&tar_filename /* archive filename */
|
||||
#ifdef CONFIG_FEATURE_TAR_FROM
|
||||
, &(tar_handle->accept),
|
||||
&(tar_handle->reject)
|
||||
#endif
|
||||
);
|
||||
|
||||
/* Check one and only one context option was given */
|
||||
if(opt & 0x80000000UL)
|
||||
if(opt & BB_GETOPT_ERROR) {
|
||||
bb_show_usage();
|
||||
}
|
||||
#ifdef CONFIG_FEATURE_TAR_CREATE
|
||||
ctx_flag = opt & (CTX_CREATE | CTX_TEST | CTX_EXTRACT);
|
||||
#else
|
||||
ctx_flag = opt & (CTX_TEST | CTX_EXTRACT);
|
||||
#endif
|
||||
if (ctx_flag == 0) {
|
||||
bb_show_usage();
|
||||
}
|
||||
if(ctx_flag & CTX_TEST) {
|
||||
if ((tar_handle->action_header == header_list) ||
|
||||
(tar_handle->action_header == header_verbose_list)) {
|
||||
tar_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
tar_handle->action_header = header_list;
|
||||
}
|
||||
if ((tar_handle->action_header == header_list) ||
|
||||
(tar_handle->action_header == header_verbose_list)) {
|
||||
tar_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
tar_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if(ctx_flag & CTX_EXTRACT) {
|
||||
if (tar_handle->action_data != data_extract_to_stdout)
|
||||
tar_handle->action_data = data_extract_all;
|
||||
}
|
||||
tar_handle->action_data = data_extract_all;
|
||||
}
|
||||
if(opt & TAR_OPT_2STDOUT) {
|
||||
/* To stdout */
|
||||
tar_handle->action_data = data_extract_to_stdout;
|
||||
tar_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if(opt & TAR_OPT_VERBOSE) {
|
||||
if ((tar_handle->action_header == header_list) ||
|
||||
(tar_handle->action_header == header_verbose_list))
|
||||
{
|
||||
tar_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
tar_handle->action_header = header_list;
|
||||
}
|
||||
if ((tar_handle->action_header == header_list) ||
|
||||
(tar_handle->action_header == header_verbose_list))
|
||||
{
|
||||
tar_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
tar_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (opt & TAR_OPT_KEEP_OLD) {
|
||||
tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
if(opt & TAR_OPT_GZIP) {
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_TAR_BZIP2
|
||||
if(opt & TAR_OPT_BZIP2) {
|
||||
get_header_ptr = get_header_tar_bz2;
|
||||
get_header_ptr = get_header_tar_bz2;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_TAR_EXCLUDE
|
||||
if(opt & TAR_OPT_EXCLUDE) {
|
||||
#ifdef CONFIG_FEATURE_TAR_COMPRESS
|
||||
if(opt & TAR_OPT_UNCOMPRESS) {
|
||||
get_header_ptr = get_header_tar_Z;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_TAR_FROM
|
||||
if(opt & TAR_OPT_EXCLUDE_FROM) {
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
}
|
||||
if(opt & TAR_OPT_INCLUDE_FROM) {
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Check if we are reading from stdin */
|
||||
if ((argv[optind]) && (*argv[optind] == '-')) {
|
||||
/* Default is to read from stdin, so just skip to next arg */
|
||||
@@ -703,8 +798,12 @@ int tar_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Setup an array of filenames to work with */
|
||||
/* TODO: This is the same as in ar, seperate function ? */
|
||||
/* TODO: This is the same as in ar, separate function ? */
|
||||
while (optind < argc) {
|
||||
char *filename_ptr = last_char_is(argv[optind], '/');
|
||||
if (filename_ptr) {
|
||||
*filename_ptr = '\0';
|
||||
}
|
||||
tar_handle->accept = llist_add_to(tar_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
@@ -713,43 +812,65 @@ int tar_main(int argc, char **argv)
|
||||
tar_handle->filter = filter_accept_reject_list;
|
||||
}
|
||||
|
||||
/* Open the tar file */
|
||||
{
|
||||
FILE *tar_stream;
|
||||
int flags;
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_CREATE
|
||||
if (opt & CTX_CREATE) {
|
||||
/* Make sure there is at least one file to tar up. */
|
||||
if (tar_handle->accept == NULL) {
|
||||
bb_error_msg_and_die("Cowardly refusing to create an empty archive");
|
||||
}
|
||||
tar_stream = stdout;
|
||||
flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
unlink(tar_filename);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
tar_stream = stdin;
|
||||
flags = O_RDONLY;
|
||||
}
|
||||
|
||||
if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
|
||||
tar_handle->src_fd = fileno(tar_stream);
|
||||
tar_handle->seek = seek_by_char;
|
||||
} else {
|
||||
tar_handle->src_fd = bb_xopen(tar_filename, flags);
|
||||
}
|
||||
}
|
||||
|
||||
if ((base_dir) && (chdir(base_dir))) {
|
||||
bb_perror_msg_and_die("Couldnt chdir to %s", base_dir);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_CREATE
|
||||
/* create an archive */
|
||||
if (ctx_flag == CTX_CREATE) {
|
||||
if (opt & CTX_CREATE) {
|
||||
int verboseFlag = FALSE;
|
||||
int gzipFlag = FALSE;
|
||||
int zipMode = 0;
|
||||
|
||||
# ifdef CONFIG_FEATURE_TAR_GZIP
|
||||
if (get_header_ptr == get_header_tar_gz) {
|
||||
gzipFlag = TRUE;
|
||||
zipMode = 1;
|
||||
}
|
||||
# endif /* CONFIG_FEATURE_TAR_GZIP */
|
||||
# ifdef CONFIG_FEATURE_TAR_BZIP2
|
||||
if (get_header_ptr == get_header_tar_bz2) {
|
||||
bb_error_msg_and_die("Creating bzip2 compressed archives is not currently supported.");
|
||||
zipMode = 2;
|
||||
}
|
||||
# endif /* CONFIG_FEATURE_TAR_BZIP2 */
|
||||
|
||||
if ((tar_handle->action_header == header_list) ||
|
||||
if ((tar_handle->action_header == header_list) ||
|
||||
(tar_handle->action_header == header_verbose_list)) {
|
||||
verboseFlag = TRUE;
|
||||
}
|
||||
writeTarFile(tar_filename, verboseFlag, tar_handle->accept,
|
||||
tar_handle->reject, gzipFlag);
|
||||
} else
|
||||
writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERNCE, tar_handle->accept,
|
||||
tar_handle->reject, zipMode);
|
||||
} else
|
||||
#endif /* CONFIG_FEATURE_TAR_CREATE */
|
||||
{
|
||||
if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
|
||||
tar_handle->src_fd = fileno(stdin);
|
||||
tar_handle->seek = seek_by_char;
|
||||
} else {
|
||||
tar_handle->src_fd = bb_xopen(tar_filename, O_RDONLY);
|
||||
}
|
||||
|
||||
if ((base_dir) && (chdir(base_dir))) {
|
||||
bb_perror_msg_and_die("Couldnt chdir");
|
||||
}
|
||||
|
||||
while (get_header_ptr(tar_handle) == EXIT_SUCCESS);
|
||||
|
||||
/* Ckeck that every file that should have been extracted was */
|
||||
@@ -764,7 +885,7 @@ int tar_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_CLEAN_UP
|
||||
if (tar_handle->src_fd != fileno(stdin)) {
|
||||
if (tar_handle->src_fd != STDIN_FILENO) {
|
||||
close(tar_handle->src_fd);
|
||||
}
|
||||
#endif /* CONFIG_FEATURE_CLEAN_UP */
|
||||
|
||||
@@ -46,7 +46,7 @@ extern int uncompress_main(int argc, char **argv)
|
||||
int dst_fd;
|
||||
|
||||
if (strcmp(compressed_file, "-") == 0) {
|
||||
src_fd = fileno(stdin);
|
||||
src_fd = STDIN_FILENO;
|
||||
flags |= GUNZIP_TO_STDOUT;
|
||||
} else {
|
||||
src_fd = bb_xopen(compressed_file, O_RDONLY);
|
||||
@@ -60,7 +60,7 @@ extern int uncompress_main(int argc, char **argv)
|
||||
|
||||
/* Set output filename and number */
|
||||
if (flags & GUNZIP_TO_STDOUT) {
|
||||
dst_fd = fileno(stdout);
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
struct stat stat_buf;
|
||||
char *extension;
|
||||
@@ -96,10 +96,10 @@ extern int uncompress_main(int argc, char **argv)
|
||||
delete_path = uncompressed_file;
|
||||
}
|
||||
|
||||
if (dst_fd != fileno(stdout)) {
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != fileno(stdin)) {
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
|
||||
+9
-7
@@ -20,7 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* For reference to format see http://www.pkware.com/support/appnote.html */
|
||||
/* For reference see
|
||||
* http://www.pkware.com/products/enterprise/white_papers/appnote.txt
|
||||
* http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
|
||||
*/
|
||||
|
||||
/* TODO Endian issues, exclude, should we accept input from stdin ? */
|
||||
|
||||
@@ -135,7 +138,7 @@ extern int unzip_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (*argv[optind] == '-') {
|
||||
archive_handle->src_fd = fileno(stdin);
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_char;
|
||||
} else {
|
||||
archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
|
||||
@@ -199,7 +202,8 @@ extern int unzip_main(int argc, char **argv)
|
||||
archive_handle->action_data(archive_handle);
|
||||
} else {
|
||||
dst_fd = bb_xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
|
||||
inflate(archive_handle->src_fd, dst_fd);
|
||||
inflate_init(zip_header.formated.cmpsize);
|
||||
inflate_unzip(archive_handle->src_fd, dst_fd);
|
||||
close(dst_fd);
|
||||
chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
|
||||
|
||||
@@ -227,10 +231,8 @@ extern int unzip_main(int argc, char **argv)
|
||||
/* Data descriptor section */
|
||||
if (zip_header.formated.flags & 4) {
|
||||
/* skip over duplicate crc, compressed size and uncompressed size */
|
||||
unsigned short i;
|
||||
for (i = 0; i != 12; i++) {
|
||||
archive_xread_char(archive_handle);
|
||||
}
|
||||
unsigned char data_description[12];
|
||||
archive_xread_all(archive_handle, data_description, 12);
|
||||
archive_handle->offset += 12;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,6 @@ config CONFIG_DUMPKMAP
|
||||
This program dumps the kernel's keyboard translation table to
|
||||
stdout, in binary format. You can then use loadkmap to load it.
|
||||
|
||||
config CONFIG_LOADACM
|
||||
bool "loadacm"
|
||||
default n
|
||||
help
|
||||
This program loads an acm from standard input.
|
||||
|
||||
config CONFIG_LOADFONT
|
||||
bool "loadfont"
|
||||
default n
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,13 +17,15 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR:= ../
|
||||
top_srcdir=..
|
||||
top_builddir=..
|
||||
srcdir=$(top_srcdir)/console/tools
|
||||
CONSOLETOOLS_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
CONSOLETOOLS_AR:=console-tools.a
|
||||
ifndef $(CONSOLETOOLS_DIR)
|
||||
CONSOLETOOLS_DIR:=$(TOPDIR)console-tools/
|
||||
CONSOLETOOLS_DIR:=$(top_builddir)/console-tools/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/console-tools
|
||||
|
||||
CONSOLETOOLS_DIR-y:=
|
||||
CONSOLETOOLS_DIR-$(CONFIG_CHVT) += chvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_CLEAR) += clear.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADACM) += loadacm.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADFONT) += loadfont.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP) += loadkmap.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_OPENVT) += openvt.o
|
||||
@@ -37,5 +37,8 @@ CONSOLETOOLS_DIR-$(CONFIG_SETKEYCODES) += setkeycodes.o
|
||||
libraries-y+=$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR)
|
||||
|
||||
$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR): $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
$(AR) $(ARFLAGS) $@ $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
|
||||
$(CONSOLETOOLS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+25
-7
@@ -1,11 +1,25 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* chvt.c - aeb - 940227 - Change virtual terminal
|
||||
* Mini chvt implementation for busybox
|
||||
*
|
||||
* busyboxed by Erik Andersen
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
/* no options, no getopt */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -22,14 +36,18 @@ int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-'))
|
||||
if (argc != 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
fd = get_console_fd();
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num))
|
||||
num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
|
||||
if (ioctl(fd, VT_ACTIVATE, num)) {
|
||||
bb_perror_msg_and_die("VT_ACTIVATE");
|
||||
if (ioctl(fd, VT_WAITACTIVE, num))
|
||||
}
|
||||
if (ioctl(fd, VT_WAITACTIVE, num)) {
|
||||
bb_perror_msg_and_die("VT_WAITACTIVE");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -20,6 +20,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
+34
-24
@@ -1,8 +1,27 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
* Disallocate virtual terminal(s)
|
||||
*
|
||||
* Copyright (C) 2003 by Tito Ragusa <farmatito@tiscali.it>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -15,32 +34,23 @@ static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
int fd, num=0;
|
||||
/* num = 0 deallocate all unused consoles */
|
||||
int num = 0;
|
||||
|
||||
if (argc > 2)
|
||||
bb_show_usage();
|
||||
|
||||
fd = get_console_fd();
|
||||
|
||||
/* num=0 deallocate all unused consoles */
|
||||
if (argc == 1)
|
||||
goto disallocate_all;
|
||||
|
||||
num=bb_xgetlarg(argv[1], 10, 0, INT_MAX);
|
||||
|
||||
switch(num)
|
||||
switch(argc)
|
||||
{
|
||||
case 0:
|
||||
bb_error_msg("0: illegal VT number");
|
||||
break;
|
||||
case 2:
|
||||
if((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0)
|
||||
bb_error_msg_and_die("0: illegal VT number");
|
||||
/* Falltrough */
|
||||
case 1:
|
||||
bb_error_msg("VT 1 cannot be deallocated");
|
||||
break;
|
||||
default:
|
||||
disallocate_all:
|
||||
if (ioctl(fd, VT_DISALLOCATE, num))
|
||||
bb_perror_msg_and_die("VT_DISALLOCATE");
|
||||
return EXIT_SUCCESS;
|
||||
bb_show_usage();
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (ioctl( get_console_fd(), VT_DISALLOCATE, num )) {
|
||||
bb_perror_msg_and_die("VT_DISALLOCATE");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+19
-30
@@ -35,11 +35,11 @@ struct kbentry {
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
static const int KDGKBENT = 0x4B46; /* gets one entry in translation table */
|
||||
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
static const int NR_KEYS = 128;
|
||||
static const int MAX_NR_KEYMAPS = 256;
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
@@ -47,32 +47,21 @@ int dumpkmap_main(int argc, char **argv)
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
if (argc >= 2 && *argv[1] == '-')
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
fd = open(CURRENT_VC, O_RDWR);
|
||||
if (fd < 0) {
|
||||
bb_perror_msg("Error opening " CURRENT_VC);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fd = bb_xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
write(1, magic, 7);
|
||||
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0;
|
||||
flags[0]=1;
|
||||
flags[1]=1;
|
||||
flags[2]=1;
|
||||
flags[4]=1;
|
||||
flags[5]=1;
|
||||
flags[6]=1;
|
||||
flags[8]=1;
|
||||
flags[9]=1;
|
||||
flags[10]=1;
|
||||
flags[12]=1;
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
memset(flags, 0x00, MAX_NR_KEYMAPS);
|
||||
memset(flags, 0x01, 13);
|
||||
flags[3] = flags[7] = flags[11] = 0;
|
||||
|
||||
/* dump flags */
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1);
|
||||
write(1, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
@@ -80,13 +69,13 @@ int dumpkmap_main(int argc, char **argv)
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
|
||||
bb_error_msg("ioctl returned: %m, %s, %s, %xqq", (char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
}
|
||||
else {
|
||||
write(1,(void*)&ke.kb_value,2);
|
||||
}
|
||||
|
||||
bb_perror_msg("ioctl failed with %s, %s, %p",
|
||||
(char *)&ke.kb_index,
|
||||
(char *)&ke.kb_table,
|
||||
&ke.kb_value);
|
||||
} else {
|
||||
write(1, (void*)&ke.kb_value, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,357 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Derived from
|
||||
* mapscrn.c - version 0.92
|
||||
*
|
||||
* Was taken from console-tools and adapted by
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/kd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
static int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
|
||||
static int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
|
||||
static unicode utf8_to_ucs2(char *buf);
|
||||
static int screen_map_load(int fd, FILE * fp);
|
||||
|
||||
int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
fd = open(CURRENT_VC, O_RDWR);
|
||||
if (fd < 0) {
|
||||
bb_perror_msg_and_die("Error opening " CURRENT_VC);
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin)) {
|
||||
bb_perror_msg_and_die("Error loading acm");
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int screen_map_load(int fd, FILE * fp)
|
||||
{
|
||||
struct stat stbuf;
|
||||
unicode wbuf[E_TABSZ];
|
||||
unsigned char buf[E_TABSZ];
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fileno(fp), &stbuf))
|
||||
bb_perror_msg_and_die("Cannot stat map file");
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
if (!
|
||||
(parse_failed =
|
||||
(-1 == uni_screen_map_read_ascii(fp, wbuf, &is_unicode)))
|
||||
|| (S_ISREG(stbuf.st_mode) && (stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) { /* test for binary UTF map by size */
|
||||
if (parse_failed) {
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
bb_error_msg_and_die("16bit screen-map MUST be a regular file.");
|
||||
else
|
||||
bb_perror_msg_and_die("fseek failed reading binary 16bit screen-map");
|
||||
}
|
||||
|
||||
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
|
||||
bb_perror_msg_and_die("Cannot read [new] map from file");
|
||||
#if 0
|
||||
else
|
||||
bb_error_msg("Input screen-map is binary.");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
|
||||
/* same if it was binary, ie. if parse_failed */
|
||||
if (parse_failed || is_unicode) {
|
||||
if (ioctl(fd, PIO_UNISCRNMAP, wbuf))
|
||||
bb_perror_msg_and_die("PIO_UNISCRNMAP ioctl");
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* rewind... */
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
bb_error_msg("Assuming 8bit screen-map - MUST be a regular file."),
|
||||
exit(1);
|
||||
else
|
||||
bb_perror_msg_and_die("fseek failed assuming 8bit screen-map");
|
||||
}
|
||||
|
||||
/* ... and try an old 8-bit screen-map */
|
||||
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp, buf))) ||
|
||||
(S_ISREG(stbuf.st_mode) && (stbuf.st_size == E_TABSZ))) { /* test for binary old 8-bit map by size */
|
||||
if (parse_failed) {
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
bb_error_msg_and_die("fseek() returned ESPIPE !");
|
||||
else
|
||||
bb_perror_msg_and_die("fseek for binary 8bit screen-map");
|
||||
}
|
||||
|
||||
if (fread(buf, E_TABSZ, 1, fp) != 1)
|
||||
bb_perror_msg_and_die("Cannot read [old] map from file");
|
||||
#if 0
|
||||
else
|
||||
bb_error_msg("Input screen-map is binary.");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ioctl(fd, PIO_SCRNMAP, buf))
|
||||
bb_perror_msg_and_die("PIO_SCRNMAP ioctl");
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
bb_error_msg("Error parsing symbolic map");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - reads `fp' as a 16-bit ASCII SFM file.
|
||||
* - returns -1 on error.
|
||||
* - returns it in `unicode' in an E_TABSZ-elements array.
|
||||
* - sets `*is_unicode' flagiff there were any non-8-bit
|
||||
* (ie. real 16-bit) mapping.
|
||||
*
|
||||
* FIXME: ignores everything after second word
|
||||
*/
|
||||
static int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
|
||||
{
|
||||
char buffer[256]; /* line buffer reading file */
|
||||
char *p, *q; /* 1st + 2nd words in line */
|
||||
int in, on; /* the same, as numbers */
|
||||
int tmp_is_unicode; /* tmp for is_unicode calculation */
|
||||
int i; /* loop index - result holder */
|
||||
int ret_code = 0; /* return code */
|
||||
sigset_t acmsigset, old_sigset;
|
||||
|
||||
assert(is_unicode);
|
||||
|
||||
*is_unicode = 0;
|
||||
|
||||
/* first 128 codes defaults to ASCII */
|
||||
for (i = 0; i < 128; i++)
|
||||
buf[i] = i;
|
||||
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
|
||||
for (; i < E_TABSZ; i++)
|
||||
buf[i] = 0xfffd;
|
||||
|
||||
/* block SIGCHLD */
|
||||
sigemptyset(&acmsigset);
|
||||
sigaddset(&acmsigset, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &acmsigset, &old_sigset);
|
||||
|
||||
do {
|
||||
if (NULL == fgets(buffer, sizeof(buffer), fp)) {
|
||||
if (feof(fp))
|
||||
break;
|
||||
else
|
||||
bb_perror_msg_and_die("uni_screen_map_read_ascii() can't read line");
|
||||
}
|
||||
|
||||
/* get "charset-relative charcode", stripping leading spaces */
|
||||
p = strtok(buffer, " \t\n");
|
||||
|
||||
/* skip empty lines and comments */
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
/* get unicode mapping */
|
||||
q = strtok(NULL, " \t\n");
|
||||
if (q) {
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255) {
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
on = ctoi(q, &tmp_is_unicode);
|
||||
if (in < 0 && on > 65535) {
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
*is_unicode |= tmp_is_unicode;
|
||||
buf[in] = on;
|
||||
} else {
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1); /* terminated by break on feof() */
|
||||
|
||||
/* restore sig mask */
|
||||
sigprocmask(SIG_SETMASK, &old_sigset, NULL);
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
|
||||
static int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
|
||||
{
|
||||
char buffer[256];
|
||||
int in, on;
|
||||
char *p, *q;
|
||||
|
||||
for (in = 0; in < 256; in++)
|
||||
buf[in] = in;
|
||||
|
||||
while (fgets(buffer, sizeof(buffer) - 1, fp)) {
|
||||
p = strtok(buffer, " \t\n");
|
||||
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
q = strtok(NULL, " \t\n#");
|
||||
if (q) {
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255)
|
||||
return -1;
|
||||
|
||||
on = ctoi(q, NULL);
|
||||
if (in < 0 && on > 255)
|
||||
return -1;
|
||||
|
||||
buf[in] = on;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - converts a string into an int.
|
||||
* - supports dec and hex bytes, hex UCS2, single-quoted byte and UTF8 chars.
|
||||
* - returns the converted value
|
||||
* - if `is_unicode != NULL', use it to tell whether it was unicode
|
||||
*
|
||||
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
|
||||
*/
|
||||
static long int ctoi(unsigned char *s, int *is_unicode)
|
||||
{
|
||||
int i;
|
||||
size_t ls;
|
||||
|
||||
ls = strlen(s);
|
||||
if (is_unicode)
|
||||
*is_unicode = 0;
|
||||
|
||||
/* hex-specified UCS2 */
|
||||
if ((strncmp(s, "U+", 2) == 0) &&
|
||||
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2)) {
|
||||
sscanf(s + 2, "%x", &i);
|
||||
if (is_unicode)
|
||||
*is_unicode = 1;
|
||||
}
|
||||
|
||||
/* hex-specified byte */
|
||||
else if ((ls <= 4) && (strncmp(s, "0x", 2) == 0) &&
|
||||
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2))
|
||||
sscanf(s + 2, "%x", &i);
|
||||
|
||||
/* oct-specified number (byte) */
|
||||
else if ((*s == '0') && (strspn(s, "01234567") == ls))
|
||||
sscanf(s, "%o", &i);
|
||||
|
||||
/* dec-specified number (byte) */
|
||||
else if (strspn(s, "0123456789") == ls)
|
||||
sscanf(s, "%d", &i);
|
||||
|
||||
/* single-byte quoted char */
|
||||
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
|
||||
i = s[1];
|
||||
|
||||
/* multi-byte UTF8 quoted char */
|
||||
else if ((s[0] == '\'') && (s[ls - 1] == '\'')) {
|
||||
s[ls - 1] = 0; /* ensure we'll not "parse UTF too far" */
|
||||
i = utf8_to_ucs2(s + 1);
|
||||
if (is_unicode)
|
||||
*is_unicode = 1;
|
||||
} else
|
||||
return (-1);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
static unicode utf8_to_ucs2(char *buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char = 0;
|
||||
unicode tc = 0;
|
||||
unsigned char c;
|
||||
|
||||
do {
|
||||
c = *buf;
|
||||
buf++;
|
||||
|
||||
/* if byte should be part of multi-byte sequence */
|
||||
if (c & 0x80) {
|
||||
/* if we have already started to parse a UTF8 sequence */
|
||||
if (utf_count > 0 && (c & 0xc0) == 0x80) {
|
||||
utf_char = (utf_char << 6) | (c & 0x3f);
|
||||
utf_count--;
|
||||
if (utf_count == 0)
|
||||
tc = utf_char;
|
||||
else
|
||||
continue;
|
||||
} else { /* Possibly 1st char of a UTF8 sequence */
|
||||
|
||||
if ((c & 0xe0) == 0xc0) {
|
||||
utf_count = 1;
|
||||
utf_char = (c & 0x1f);
|
||||
} else if ((c & 0xf0) == 0xe0) {
|
||||
utf_count = 2;
|
||||
utf_char = (c & 0x0f);
|
||||
} else if ((c & 0xf8) == 0xf0) {
|
||||
utf_count = 3;
|
||||
utf_char = (c & 0x07);
|
||||
} else if ((c & 0xfc) == 0xf8) {
|
||||
utf_count = 4;
|
||||
utf_char = (c & 0x03);
|
||||
} else if ((c & 0xfe) == 0xfc) {
|
||||
utf_count = 5;
|
||||
utf_char = (c & 0x01);
|
||||
} else
|
||||
utf_count = 0;
|
||||
continue;
|
||||
}
|
||||
} else { /* not part of multi-byte sequence - treat as ASCII
|
||||
* this makes incomplete sequences to be ignored
|
||||
*/
|
||||
tc = c;
|
||||
utf_count = 0;
|
||||
}
|
||||
}
|
||||
while (utf_count);
|
||||
|
||||
return tc;
|
||||
}
|
||||
@@ -46,9 +46,7 @@ extern int loadfont_main(int argc, char **argv)
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
|
||||
fd = open(CURRENT_VC, O_RDWR);
|
||||
if (fd < 0)
|
||||
bb_perror_msg_and_die("Error opening " CURRENT_VC);
|
||||
fd = bb_xopen(CURRENT_VC, O_RDWR);
|
||||
loadnewfont(fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
+14
-21
@@ -37,43 +37,35 @@ struct kbentry {
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
static const int KDSKBENT = 0x4B47; /* sets one entry in translation table */
|
||||
/* sets one entry in translation table */
|
||||
#define KDSKBENT 0x4B47
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
static const int NR_KEYS = 128;
|
||||
static const int MAX_NR_KEYMAPS = 256;
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
u_short *ibuff;
|
||||
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
||||
char flags[MAX_NR_KEYMAPS], buff[7];
|
||||
int i, j, fd;
|
||||
u_short ibuff[NR_KEYS];
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
char buff[7];
|
||||
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
|
||||
fd = open(CURRENT_VC, O_RDWR);
|
||||
if (fd < 0)
|
||||
bb_perror_msg_and_die("Error opening " CURRENT_VC);
|
||||
fd = bb_xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
read(0, buff, 7);
|
||||
if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
|
||||
if ((bb_full_read(0, buff, 7) != 7) || (strncmp(buff, BINARY_KEYMAP_MAGIC, 7) != 0))
|
||||
bb_error_msg_and_die("This is not a valid binary keymap.");
|
||||
|
||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS))
|
||||
if (bb_full_read(0, flags, MAX_NR_KEYMAPS) != MAX_NR_KEYMAPS)
|
||||
bb_perror_msg_and_die("Error reading keymap flags");
|
||||
|
||||
ibuff = (u_short *) xmalloc(ibuffsz);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
pos = 0;
|
||||
while (pos < ibuffsz) {
|
||||
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0)
|
||||
bb_perror_msg_and_die("Error reading keymap");
|
||||
pos += readsz;
|
||||
}
|
||||
bb_full_read(0, ibuff, NR_KEYS * sizeof(u_short));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
@@ -82,7 +74,8 @@ int loadkmap_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Don't bother to close files. Exit does that
|
||||
|
||||
/* Don't bother to close files. Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
+6
-19
@@ -32,34 +32,22 @@
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#define VTNAME "/dev/tty%d"
|
||||
|
||||
int openvt_main(int argc, char **argv)
|
||||
{
|
||||
int pid;
|
||||
int fd;
|
||||
int vtno;
|
||||
char vtname[sizeof VTNAME + 2];
|
||||
char vtname[sizeof VC_FORMAT + 2];
|
||||
|
||||
|
||||
if (argc < 3)
|
||||
bb_show_usage();
|
||||
|
||||
if (!isdigit(argv[1][0]))
|
||||
bb_show_usage();
|
||||
|
||||
vtno = (int) atol(argv[1]);
|
||||
|
||||
/* if (vtno <= 0 || vtno > 63) */
|
||||
if (vtno <= 0 || vtno > 12)
|
||||
bb_error_msg_and_die("Illegal vt number (%d)", vtno);
|
||||
|
||||
sprintf(vtname, VTNAME, vtno);
|
||||
/* check for Illegal vt number: < 1 or > 12 */
|
||||
sprintf(vtname, VC_FORMAT,(int)bb_xgetlarg(argv[1], 10, 1, 12));
|
||||
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
|
||||
if((pid = fork()) == 0) {
|
||||
if(fork() == 0) {
|
||||
/* leave current vt */
|
||||
|
||||
#ifdef ESIX_5_3_2_D
|
||||
@@ -68,13 +56,12 @@ int openvt_main(int argc, char **argv)
|
||||
if (setsid() < 0) {
|
||||
#endif
|
||||
|
||||
bb_perror_msg_and_die("Unable to set new session");
|
||||
bb_perror_msg_and_die("Unable to set new session");
|
||||
}
|
||||
close(0); /* so that new vt becomes stdin */
|
||||
|
||||
/* and grab new one */
|
||||
if ((fd = open(vtname, O_RDWR)) == -1)
|
||||
bb_perror_msg_and_die("could not open %s", vtname);
|
||||
fd = bb_xopen(vtname, O_RDWR);
|
||||
|
||||
/* Reassign stdout and sterr */
|
||||
close(1);
|
||||
|
||||
+15
-3
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini reset implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
* Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -21,13 +21,25 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int reset_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[?25h\033c\033[J");
|
||||
return EXIT_SUCCESS;
|
||||
if (isatty(0) || isatty(0) || isatty(0)) {
|
||||
/* See 'man 4 console_codes' for details:
|
||||
* "ESC c" -- Reset
|
||||
* "ESC ( K" -- Select user mapping
|
||||
* "ESC [ J" -- Erase display
|
||||
* "ESC [ 0 m" -- Reset all Graphics Rendition display attributes
|
||||
* "ESC [ ? 25 h" -- Make cursor visible.
|
||||
*/
|
||||
printf("\033c\033(K\033[J\033[0m\033[?25h");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ struct kbkeycode {
|
||||
};
|
||||
static const int KDSETKEYCODE = 0x4B4D; /* write kernel keycode table entry */
|
||||
|
||||
extern int
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
char *ep;
|
||||
@@ -45,7 +45,7 @@ setkeycodes_main(int argc, char** argv)
|
||||
if (argc % 2 != 1 || argc < 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
|
||||
fd = get_console_fd();
|
||||
|
||||
while (argc > 2) {
|
||||
|
||||
+48
-37
@@ -10,14 +10,14 @@ config CONFIG_BASENAME
|
||||
default n
|
||||
help
|
||||
basename is used to strip the directory and suffix from filenames,
|
||||
leaving just the filename itself. Enable this option if you wish
|
||||
leaving just the filename itself. Enable this option if you wish
|
||||
to enable the 'basename' utility.
|
||||
|
||||
config CONFIG_CAL
|
||||
bool "cal"
|
||||
default n
|
||||
help
|
||||
cal is used to display a montly calender.
|
||||
cal is used to display a monthly calender.
|
||||
|
||||
config CONFIG_CAT
|
||||
bool "cat"
|
||||
@@ -30,7 +30,7 @@ config CONFIG_CHGRP
|
||||
bool "chgrp"
|
||||
default n
|
||||
help
|
||||
chgrp is used to change the group owership of files.
|
||||
chgrp is used to change the group ownership of files.
|
||||
|
||||
config CONFIG_CHMOD
|
||||
bool "chmod"
|
||||
@@ -42,7 +42,7 @@ config CONFIG_CHOWN
|
||||
bool "chown"
|
||||
default n
|
||||
help
|
||||
chown is used too change the user and/or group ownership
|
||||
chown is used to change the user and/or group ownership
|
||||
of files.
|
||||
|
||||
config CONFIG_CHROOT
|
||||
@@ -101,7 +101,7 @@ config CONFIG_DD
|
||||
help
|
||||
dd copies a file (from standard input to standard output,
|
||||
by default) using specific input and output blocksizes,
|
||||
while optionally performing conversions on it.
|
||||
while optionally performing conversions on it.
|
||||
|
||||
config CONFIG_DF
|
||||
bool "df"
|
||||
@@ -114,14 +114,14 @@ config CONFIG_DIRNAME
|
||||
bool "dirname"
|
||||
default n
|
||||
help
|
||||
dirname is used to strip a non directory suffix from
|
||||
dirname is used to strip a non-directory suffix from
|
||||
a file name.
|
||||
|
||||
config CONFIG_DOS2UNIX
|
||||
bool "dos2unix/unix2dos"
|
||||
default n
|
||||
help
|
||||
dos2unix is uses to convert a text file from DOS format to
|
||||
dos2unix is used to convert a text file from DOS format to
|
||||
UNIX format, and vice versa.
|
||||
|
||||
config CONFIG_UNIX2DOS
|
||||
@@ -144,7 +144,7 @@ config CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
|
||||
Use a blocksize of (1K) instead of the default 512b.
|
||||
|
||||
config CONFIG_ECHO
|
||||
bool "echo (basic SUSv3 version taking no options"
|
||||
bool "echo (basic SUSv3 version taking no options)"
|
||||
default n
|
||||
help
|
||||
echo is used to print a specified string to stdout.
|
||||
@@ -154,14 +154,14 @@ config CONFIG_FEATURE_FANCY_ECHO
|
||||
default y
|
||||
depends on CONFIG_ECHO
|
||||
help
|
||||
This adds options (-n and -e) to echo.
|
||||
This adds options (-n and -e) to echo.
|
||||
|
||||
config CONFIG_ENV
|
||||
bool "env"
|
||||
default n
|
||||
help
|
||||
env is used to set an environment variable and run
|
||||
a command, without options it displays the current
|
||||
a command; without options it displays the current
|
||||
environment.
|
||||
|
||||
config CONFIG_EXPR
|
||||
@@ -218,6 +218,12 @@ config CONFIG_ID
|
||||
help
|
||||
id displays the current user and group ID names.
|
||||
|
||||
config CONFIG_INSTALL
|
||||
bool "install"
|
||||
default n
|
||||
help
|
||||
Copy files and set attributes.
|
||||
|
||||
config CONFIG_LENGTH
|
||||
bool "length"
|
||||
default n
|
||||
@@ -347,7 +353,7 @@ config CONFIG_REALPATH
|
||||
default n
|
||||
help
|
||||
Return the canonicalized absolute pathname.
|
||||
This isnt provided by GNU shellutils, but where else does it belong.
|
||||
This isn't provided by GNU shellutils, but where else does it belong.
|
||||
|
||||
config CONFIG_RM
|
||||
bool "rm"
|
||||
@@ -361,19 +367,18 @@ config CONFIG_RMDIR
|
||||
help
|
||||
rmdir is used to remove empty directories.
|
||||
|
||||
config CONFIG_SEQ
|
||||
bool "seq"
|
||||
default n
|
||||
help
|
||||
print a sequence of numbers
|
||||
|
||||
config CONFIG_SHA1SUM
|
||||
bool "sha1sum"
|
||||
default n
|
||||
help
|
||||
Compute and check SHA1 message digest
|
||||
|
||||
config CONFIG_FEATURE_SHA1SUM_CHECK
|
||||
bool " Enale -c and -w options"
|
||||
default n
|
||||
help
|
||||
Enabling the -c and -w options allow files to be checked
|
||||
against pre-calculated hash values.
|
||||
|
||||
config CONFIG_SLEEP
|
||||
bool "sleep (single integer arg with no suffix)"
|
||||
default n
|
||||
@@ -393,22 +398,6 @@ config CONFIG_SORT
|
||||
help
|
||||
sort is used to sort lines of text in specified files.
|
||||
|
||||
config CONFIG_FEATURE_SORT_REVERSE
|
||||
bool " Enable reverse sort"
|
||||
default y
|
||||
depends on CONFIG_SORT
|
||||
help
|
||||
Enable the `-r' option that allows sort to sort lines of
|
||||
text in reverse.
|
||||
|
||||
config CONFIG_FEATURE_SORT_UNIQUE
|
||||
bool " Enable unique sort"
|
||||
default y
|
||||
depends on CONFIG_SORT
|
||||
help
|
||||
Enable the `-u' option that allows sort to only sort lines
|
||||
that are uniq.
|
||||
|
||||
config CONFIG_STTY
|
||||
bool "stty"
|
||||
default n
|
||||
@@ -429,11 +418,12 @@ config CONFIG_TAIL
|
||||
from files.
|
||||
|
||||
config CONFIG_FEATURE_FANCY_TAIL
|
||||
bool " Enable extra tail options (-c, -q, -s, and -v)"
|
||||
bool " Enable extra tail options (-q, -s, and -v)"
|
||||
default y
|
||||
depends on CONFIG_TAIL
|
||||
help
|
||||
Enable tail options (-c, -q, -s, and -v).
|
||||
The options (-q, -s, and -v) are provided by GNU tail, but
|
||||
are not specific in the SUSv3 standard.
|
||||
|
||||
config CONFIG_TEE
|
||||
bool "tee"
|
||||
@@ -462,9 +452,16 @@ if !CONFIG_ASH && !CONFIG_HUSH && !CONFIG_LASH && !CONFIG_MSH
|
||||
help
|
||||
test is used to check file types and compare values,
|
||||
returning an appropriate exit code. The shells (ash
|
||||
and bash have test builtin).
|
||||
and bash) have test builtin.
|
||||
endif
|
||||
|
||||
config CONFIG_FEATURE_TEST_64
|
||||
bool " Extend test to 64 bit"
|
||||
default n
|
||||
depends on CONFIG_TEST
|
||||
help
|
||||
Enable 64-bit support in test.
|
||||
|
||||
config CONFIG_TOUCH
|
||||
bool "touch"
|
||||
default n
|
||||
@@ -548,6 +545,7 @@ config CONFIG_WC
|
||||
config CONFIG_WHO
|
||||
bool "who"
|
||||
default n
|
||||
select CONFIG_FEATURE_UTMP
|
||||
help
|
||||
who is used to show who is logged on.
|
||||
|
||||
@@ -599,4 +597,17 @@ config CONFIG_FEATURE_HUMAN_READABLE
|
||||
help
|
||||
Allow df, du, and ls to have human readable output.
|
||||
|
||||
comment "Common options for md5sum, sha1sum"
|
||||
depends on CONFIG_MD5SUM || CONFIG_SHA1SUM
|
||||
|
||||
config CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
|
||||
bool " Enable -c, -s and -w options"
|
||||
default n
|
||||
depends on CONFIG_MD5SUM || CONFIG_SHA1SUM
|
||||
help
|
||||
Enabling the -c options allows files to be checked
|
||||
against pre-calculated hash values.
|
||||
|
||||
-s and -w are useful options when verifying checksums.
|
||||
|
||||
endmenu
|
||||
+8
-6
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,13 +17,15 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR:= ../
|
||||
top_srcdir=..
|
||||
top_builddir=..
|
||||
srcdir=$(top_srcdir)/coreutils
|
||||
SHELLUTILS_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
+67
-61
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,74 +19,80 @@
|
||||
|
||||
COREUTILS_AR:=coreutils.a
|
||||
ifndef $(COREUTILS_DIR)
|
||||
COREUTILS_DIR:=$(TOPDIR)coreutils/
|
||||
COREUTILS_DIR:=$(top_builddir)/coreutils/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/coreutils
|
||||
|
||||
COREUTILS-y:=
|
||||
COREUTILS-$(CONFIG_BASENAME) += basename.o
|
||||
COREUTILS-$(CONFIG_CAL) += cal.o
|
||||
COREUTILS-$(CONFIG_CAT) += cat.o
|
||||
COREUTILS-$(CONFIG_CHGRP) += chgrp.o
|
||||
COREUTILS-$(CONFIG_CHMOD) += chmod.o
|
||||
COREUTILS-$(CONFIG_CHOWN) += chown.o
|
||||
COREUTILS-$(CONFIG_CHROOT) += chroot.o
|
||||
COREUTILS-$(CONFIG_CMP) += cmp.o
|
||||
COREUTILS-$(CONFIG_CP) += cp.o
|
||||
COREUTILS-$(CONFIG_CUT) += cut.o
|
||||
COREUTILS-$(CONFIG_DATE) += date.o
|
||||
COREUTILS-$(CONFIG_DD) += dd.o
|
||||
COREUTILS-$(CONFIG_DF) += df.o
|
||||
COREUTILS-$(CONFIG_DIRNAME) += dirname.o
|
||||
COREUTILS-$(CONFIG_BASENAME) += basename.o
|
||||
COREUTILS-$(CONFIG_CAL) += cal.o
|
||||
COREUTILS-$(CONFIG_CAT) += cat.o
|
||||
COREUTILS-$(CONFIG_CHGRP) += chgrp.o
|
||||
COREUTILS-$(CONFIG_CHMOD) += chmod.o
|
||||
COREUTILS-$(CONFIG_CHOWN) += chown.o
|
||||
COREUTILS-$(CONFIG_CHROOT) += chroot.o
|
||||
COREUTILS-$(CONFIG_CMP) += cmp.o
|
||||
COREUTILS-$(CONFIG_CP) += cp.o
|
||||
COREUTILS-$(CONFIG_CUT) += cut.o
|
||||
COREUTILS-$(CONFIG_DATE) += date.o
|
||||
COREUTILS-$(CONFIG_DD) += dd.o
|
||||
COREUTILS-$(CONFIG_DF) += df.o
|
||||
COREUTILS-$(CONFIG_DIRNAME) += dirname.o
|
||||
COREUTILS-$(CONFIG_DOS2UNIX) += dos2unix.o
|
||||
COREUTILS-$(CONFIG_DU) += du.o
|
||||
COREUTILS-$(CONFIG_ECHO) += echo.o
|
||||
COREUTILS-$(CONFIG_ENV) += env.o
|
||||
COREUTILS-$(CONFIG_EXPR) += expr.o
|
||||
COREUTILS-$(CONFIG_FALSE) += false.o
|
||||
COREUTILS-$(CONFIG_FOLD) += fold.o
|
||||
COREUTILS-$(CONFIG_HEAD) += head.o
|
||||
COREUTILS-$(CONFIG_HOSTID) += hostid.o
|
||||
COREUTILS-$(CONFIG_ID) += id.o
|
||||
COREUTILS-$(CONFIG_LENGTH) += length.o
|
||||
COREUTILS-$(CONFIG_LN) += ln.o
|
||||
COREUTILS-$(CONFIG_LOGNAME) += logname.o
|
||||
COREUTILS-$(CONFIG_LS) += ls.o
|
||||
COREUTILS-$(CONFIG_MD5SUM) += md5sum.o
|
||||
COREUTILS-$(CONFIG_MKDIR) += mkdir.o
|
||||
COREUTILS-$(CONFIG_MKFIFO) += mkfifo.o
|
||||
COREUTILS-$(CONFIG_MKNOD) += mknod.o
|
||||
COREUTILS-$(CONFIG_MV) += mv.o
|
||||
COREUTILS-$(CONFIG_OD) += od.o
|
||||
COREUTILS-$(CONFIG_PRINTF) += printf.o
|
||||
COREUTILS-$(CONFIG_PWD) += pwd.o
|
||||
COREUTILS-$(CONFIG_REALPATH) += realpath.o
|
||||
COREUTILS-$(CONFIG_RM) += rm.o
|
||||
COREUTILS-$(CONFIG_RMDIR) += rmdir.o
|
||||
COREUTILS-$(CONFIG_SHA1SUM) += sha1sum.o
|
||||
COREUTILS-$(CONFIG_SLEEP) += sleep.o
|
||||
COREUTILS-$(CONFIG_SORT) += sort.o
|
||||
COREUTILS-$(CONFIG_STTY) += stty.o
|
||||
COREUTILS-$(CONFIG_SYNC) += sync.o
|
||||
COREUTILS-$(CONFIG_TAIL) += tail.o
|
||||
COREUTILS-$(CONFIG_TEE) += tee.o
|
||||
COREUTILS-$(CONFIG_TEST) += test.o
|
||||
COREUTILS-$(CONFIG_TOUCH) += touch.o
|
||||
COREUTILS-$(CONFIG_TR) += tr.o
|
||||
COREUTILS-$(CONFIG_TRUE) += true.o
|
||||
COREUTILS-$(CONFIG_TTY) += tty.o
|
||||
COREUTILS-$(CONFIG_UNAME) += uname.o
|
||||
COREUTILS-$(CONFIG_UNIQ) += uniq.o
|
||||
COREUTILS-$(CONFIG_USLEEP) += usleep.o
|
||||
COREUTILS-$(CONFIG_DU) += du.o
|
||||
COREUTILS-$(CONFIG_ECHO) += echo.o
|
||||
COREUTILS-$(CONFIG_ENV) += env.o
|
||||
COREUTILS-$(CONFIG_EXPR) += expr.o
|
||||
COREUTILS-$(CONFIG_FALSE) += false.o
|
||||
COREUTILS-$(CONFIG_FOLD) += fold.o
|
||||
COREUTILS-$(CONFIG_HEAD) += head.o
|
||||
COREUTILS-$(CONFIG_HOSTID) += hostid.o
|
||||
COREUTILS-$(CONFIG_ID) += id.o
|
||||
COREUTILS-$(CONFIG_INSTALL) += install.o
|
||||
COREUTILS-$(CONFIG_LENGTH) += length.o
|
||||
COREUTILS-$(CONFIG_LN) += ln.o
|
||||
COREUTILS-$(CONFIG_LOGNAME) += logname.o
|
||||
COREUTILS-$(CONFIG_LS) += ls.o
|
||||
COREUTILS-$(CONFIG_MD5SUM) += md5_sha1_sum.o
|
||||
COREUTILS-$(CONFIG_MKDIR) += mkdir.o
|
||||
COREUTILS-$(CONFIG_MKFIFO) += mkfifo.o
|
||||
COREUTILS-$(CONFIG_MKNOD) += mknod.o
|
||||
COREUTILS-$(CONFIG_MV) += mv.o
|
||||
COREUTILS-$(CONFIG_OD) += od.o
|
||||
COREUTILS-$(CONFIG_PRINTF) += printf.o
|
||||
COREUTILS-$(CONFIG_PWD) += pwd.o
|
||||
COREUTILS-$(CONFIG_REALPATH) += realpath.o
|
||||
COREUTILS-$(CONFIG_RM) += rm.o
|
||||
COREUTILS-$(CONFIG_RMDIR) += rmdir.o
|
||||
COREUTILS-$(CONFIG_SEQ) += seq.o
|
||||
COREUTILS-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
|
||||
COREUTILS-$(CONFIG_SLEEP) += sleep.o
|
||||
COREUTILS-$(CONFIG_SORT) += sort.o
|
||||
COREUTILS-$(CONFIG_STTY) += stty.o
|
||||
COREUTILS-$(CONFIG_SYNC) += sync.o
|
||||
COREUTILS-$(CONFIG_TAIL) += tail.o
|
||||
COREUTILS-$(CONFIG_TEE) += tee.o
|
||||
COREUTILS-$(CONFIG_TEST) += test.o
|
||||
COREUTILS-$(CONFIG_TOUCH) += touch.o
|
||||
COREUTILS-$(CONFIG_TR) += tr.o
|
||||
COREUTILS-$(CONFIG_TRUE) += true.o
|
||||
COREUTILS-$(CONFIG_TTY) += tty.o
|
||||
COREUTILS-$(CONFIG_UNAME) += uname.o
|
||||
COREUTILS-$(CONFIG_UNIQ) += uniq.o
|
||||
COREUTILS-$(CONFIG_USLEEP) += usleep.o
|
||||
COREUTILS-$(CONFIG_UUDECODE) += uudecode.o
|
||||
COREUTILS-$(CONFIG_UUENCODE) += uuencode.o
|
||||
COREUTILS-$(CONFIG_WATCH) += watch.o
|
||||
COREUTILS-$(CONFIG_WC) += wc.o
|
||||
COREUTILS-$(CONFIG_WHO) += who.o
|
||||
COREUTILS-$(CONFIG_WHOAMI) += whoami.o
|
||||
COREUTILS-$(CONFIG_YES) += yes.o
|
||||
COREUTILS-$(CONFIG_WATCH) += watch.o
|
||||
COREUTILS-$(CONFIG_WC) += wc.o
|
||||
COREUTILS-$(CONFIG_WHO) += who.o
|
||||
COREUTILS-$(CONFIG_WHOAMI) += whoami.o
|
||||
COREUTILS-$(CONFIG_YES) += yes.o
|
||||
|
||||
libraries-y+=$(COREUTILS_DIR)$(COREUTILS_AR)
|
||||
|
||||
$(COREUTILS_DIR)$(COREUTILS_AR): $(patsubst %,$(COREUTILS_DIR)%, $(COREUTILS-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(COREUTILS_DIR)%, $(COREUTILS-y))
|
||||
$(AR) $(ARFLAGS) $@ $(patsubst %,$(COREUTILS_DIR)%, $(COREUTILS-y))
|
||||
|
||||
$(COREUTILS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+5
-18
@@ -1,19 +1,6 @@
|
||||
/* NOTE:
|
||||
*
|
||||
* Apparently, all "Steven J. Merrifield" did was grab the util-linux cal applet,
|
||||
* spend maybe 5 minutes integrating it into busybox, slapped a copyright on it,
|
||||
* and submitted it. I certainly saw no evidence of any attempt at size reduction.
|
||||
* Not only do I consider his copyright below meaningless, I also consider his
|
||||
* actions shameful.
|
||||
*
|
||||
* Manuel Novoa III (mjn3@codepoet.org)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calendar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Steven J. Merrifield <steve@labyrinth.net.au>
|
||||
*
|
||||
* See original copyright at the end of this file
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -78,7 +65,7 @@ static const char sep1752[] = {
|
||||
|
||||
static int julian;
|
||||
|
||||
/* leap year -- account for gregorian reformation in 1752 */
|
||||
/* leap year -- account for Gregorian reformation in 1752 */
|
||||
#define leap_year(yr) \
|
||||
((yr) <= 1752 ? !((yr) % 4) : \
|
||||
(!((yr) % 4) && ((yr) % 100)) || !((yr) % 400))
|
||||
@@ -174,7 +161,7 @@ int cal_main(int argc, char **argv)
|
||||
int row, len, days[MAXDAYS];
|
||||
int *dp = days;
|
||||
char lineout[30];
|
||||
|
||||
|
||||
day_array(month, year, dp);
|
||||
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
|
||||
bb_printf("%*s%s\n%s\n",
|
||||
@@ -189,7 +176,7 @@ int cal_main(int argc, char **argv)
|
||||
int row, which_cal, week_len, days[12][MAXDAYS];
|
||||
int *dp;
|
||||
char lineout[80];
|
||||
|
||||
|
||||
sprintf(lineout, "%d", year);
|
||||
center(lineout,
|
||||
(WEEK_LEN * 3 + HEAD_SEP * 2)
|
||||
@@ -330,14 +317,14 @@ static void blank_string(char *buf, size_t buflen)
|
||||
static char *build_row(char *p, int *dp)
|
||||
{
|
||||
int col, val, day;
|
||||
|
||||
|
||||
memset(p, ' ', (julian + DAY_LEN) * 7);
|
||||
|
||||
col = 0;
|
||||
do {
|
||||
if ((day = *dp++) != SPACE) {
|
||||
if (julian) {
|
||||
*++p;
|
||||
++p;
|
||||
if (day >= 100) {
|
||||
*p = '0';
|
||||
p[-1] = (day / 100) + '0';
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ extern int cat_main(int argc, char **argv)
|
||||
|
||||
do {
|
||||
if ((f = bb_wfopen_input(*argv)) != NULL) {
|
||||
int r = bb_copyfd(fileno(f), STDOUT_FILENO, 0);
|
||||
int r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
|
||||
bb_fclose_nonstdin(f);
|
||||
if (r >= 0) {
|
||||
continue;
|
||||
|
||||
+3
-7
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini chgrp implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -48,7 +48,6 @@ int chgrp_main(int argc, char **argv)
|
||||
long gid;
|
||||
int recursiveFlag;
|
||||
int retval = EXIT_SUCCESS;
|
||||
char *p;
|
||||
|
||||
recursiveFlag = bb_getopt_ulflags(argc, argv, "R");
|
||||
|
||||
@@ -59,15 +58,12 @@ int chgrp_main(int argc, char **argv)
|
||||
argv += optind;
|
||||
|
||||
/* Find the selected group */
|
||||
gid = strtoul(*argv, &p, 10); /* maybe it's already numeric */
|
||||
if (*p || (p == *argv)) { /* trailing chars or nonnumeric */
|
||||
gid = my_getgrnam(*argv);
|
||||
}
|
||||
gid = get_ug_id(*argv, my_getgrnam);
|
||||
++argv;
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
do {
|
||||
if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
|
||||
if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, &gid)) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini chmod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
|
||||
* to correctly parse '-rwxgoa'
|
||||
|
||||
+4
-16
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini chown implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -43,6 +43,7 @@ static int (*chown_func)(const char *, uid_t, gid_t) = chown;
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
||||
chmod(fileName, statbuf->st_mode);
|
||||
return (TRUE);
|
||||
}
|
||||
bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
|
||||
@@ -52,19 +53,6 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
#define FLAG_R 1
|
||||
#define FLAG_h 2
|
||||
|
||||
static unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *))
|
||||
{
|
||||
unsigned long r;
|
||||
char *p;
|
||||
|
||||
r = strtoul(s, &p, 10);
|
||||
if (*p || (s == p)) {
|
||||
r = my_getxxnam(s);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int chown_main(int argc, char **argv)
|
||||
{
|
||||
int flags;
|
||||
@@ -96,10 +84,10 @@ int chown_main(int argc, char **argv)
|
||||
uid = get_ug_id(*argv, my_getpwnam);
|
||||
|
||||
++argv;
|
||||
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
do {
|
||||
if (! recursive_action (*argv, (flags & FLAG_R), FALSE, FALSE,
|
||||
if (! recursive_action (*argv, (flags & FLAG_R), FALSE, FALSE,
|
||||
fileAction, fileAction, NULL)) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -43,7 +43,7 @@ int chroot_main(int argc, char **argv)
|
||||
if (argc == 2) {
|
||||
argv -= 2;
|
||||
if (!(*argv = getenv("SHELL"))) {
|
||||
*argv = (char *) "/bin/sh";
|
||||
*argv = (char *) DEFAULT_SHELL;
|
||||
}
|
||||
argv[1] = (char *) "-i";
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
*
|
||||
* Original version majorly reworked for SUSv3 compliance, bug fixes, and
|
||||
* size optimizations. Changes include:
|
||||
* 1) Now correctly distingusishes between errors and actual file differences.
|
||||
* 1) Now correctly distinguishes between errors and actual file differences.
|
||||
* 2) Proper handling of '-' args.
|
||||
* 3) Actual error checking of i/o.
|
||||
* 4) Accept SUSv3 -l option. Note that we use the slightly nicer gnu format
|
||||
|
||||
+14
-1
@@ -41,7 +41,8 @@
|
||||
#include "busybox.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
|
||||
static const char cp_opts[] = "pdRfia"; /* WARNING!! ORDER IS IMPORTANT!! */
|
||||
/* WARNING!! ORDER IS IMPORTANT!! */
|
||||
static const char cp_opts[] = "pdRfiarP";
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
@@ -66,6 +67,18 @@ extern int cp_main(int argc, char **argv)
|
||||
if (flags & 32) {
|
||||
flags |= (FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR | FILEUTILS_DEREFERENCE);
|
||||
}
|
||||
if (flags & 64) {
|
||||
/* Make -r a synonym for -R,
|
||||
* -r was marked as obsolete in SUSv3, but is included for compatability
|
||||
*/
|
||||
flags |= FILEUTILS_RECUR;
|
||||
}
|
||||
if (flags & 128) {
|
||||
/* Make -P a synonym for -d,
|
||||
* -d is the GNU option while -P is the POSIX 2003 option
|
||||
*/
|
||||
flags |= FILEUTILS_DEREFERENCE;
|
||||
}
|
||||
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
|
||||
|
||||
|
||||
+8
-8
@@ -3,7 +3,7 @@
|
||||
* cut.c - minimalist version of cut
|
||||
*
|
||||
* Copyright (C) 1999,2000,2001 by Lineo, inc.
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@codepoet.org>
|
||||
* Written by Mark Whitley <markw@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -69,8 +69,8 @@ static int cmpfunc(const void *a, const void *b)
|
||||
|
||||
/*
|
||||
* parse_lists() - parses a list and puts values into startpos and endpos.
|
||||
* valid list formats: N, N-, N-M, -M
|
||||
* more than one list can be seperated by commas
|
||||
* valid list formats: N, N-, N-M, -M
|
||||
* more than one list can be separated by commas
|
||||
*/
|
||||
static void parse_lists(char *lists)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ static void parse_lists(char *lists)
|
||||
char *junk;
|
||||
int s = 0, e = 0;
|
||||
|
||||
/* take apart the lists, one by one (they are seperated with commas */
|
||||
/* take apart the lists, one by one (they are separated with commas */
|
||||
while ((ltok = strsep(&lists, ",")) != NULL) {
|
||||
|
||||
/* it's actually legal to pass an empty list */
|
||||
@@ -96,7 +96,7 @@ static void parse_lists(char *lists)
|
||||
s = strtoul(ntok, &junk, 10);
|
||||
if(*junk != '\0' || s < 0)
|
||||
bb_error_msg_and_die("invalid byte or field list");
|
||||
|
||||
|
||||
/* account for the fact that arrays are zero based, while the user
|
||||
* expects the first char on the line to be char # 1 */
|
||||
if (s != 0)
|
||||
@@ -125,7 +125,7 @@ static void parse_lists(char *lists)
|
||||
/* if there's something left to tokenize, the user past an invalid list */
|
||||
if (ltok)
|
||||
bb_error_msg_and_die("invalid byte or field list");
|
||||
|
||||
|
||||
/* add the new list */
|
||||
cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
|
||||
cut_lists[nlists-1].startpos = s;
|
||||
@@ -227,7 +227,7 @@ static void cut_file_by_lines(const char *line, unsigned int linenum)
|
||||
{
|
||||
static int c = 0;
|
||||
static int l = -1;
|
||||
|
||||
|
||||
/* I can't initialize this above cuz the "initializer isn't
|
||||
* constant" *sigh* */
|
||||
if (l == -1)
|
||||
@@ -300,7 +300,7 @@ extern int cut_main(int argc, char **argv)
|
||||
part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS);
|
||||
if(part == 0)
|
||||
bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
|
||||
if(opt & 0x80000000UL)
|
||||
if(opt & BB_GETOPT_ERROR)
|
||||
bb_error_msg_and_die("only one type of list may be specified");
|
||||
parse_lists(sopt);
|
||||
if((opt & (OPT_DELIM_FLGS))) {
|
||||
|
||||
+64
-45
@@ -3,7 +3,7 @@
|
||||
* Mini date implementation for busybox
|
||||
*
|
||||
* by Matthew Grant <grantma@anathoth.gen.nz>
|
||||
*
|
||||
*
|
||||
* iso-format handling added by Robert Griebl <griebl@gmx.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
all the GNU strftime stuff (its in libc, lets use it),
|
||||
setting time using UTC and displaying int, as well as
|
||||
an RFC 822 complient date output for shell scripting
|
||||
@@ -42,11 +42,12 @@
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
much as possible, missed out a lot of bounds checking */
|
||||
|
||||
/* Default input handling to save suprising some people */
|
||||
/* Default input handling to save surprising some people */
|
||||
|
||||
static struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
int nr;
|
||||
char *cp;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d", &(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday), &(tm_time->tm_hour), &(tm_time->tm_min),
|
||||
@@ -56,6 +57,14 @@ static struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, t_string);
|
||||
}
|
||||
|
||||
cp = strchr(t_string, '.');
|
||||
if (cp) {
|
||||
nr = sscanf(cp + 1, "%2d", &(tm_time->tm_sec));
|
||||
if (nr != 1) {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, t_string);
|
||||
}
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time->tm_year >= 1900) {
|
||||
tm_time->tm_year -= 1900;
|
||||
@@ -114,19 +123,26 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
return (tm_time);
|
||||
}
|
||||
|
||||
#define DATE_OPT_RFC2822 0x01
|
||||
#define DATE_OPT_SET 0x02
|
||||
#define DATE_OPT_UTC 0x04
|
||||
#define DATE_OPT_DATE 0x08
|
||||
#define DATE_OPT_REFERENCE 0x10
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
# define DATE_OPT_TIMESPEC 0x20
|
||||
#endif
|
||||
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int set_time;
|
||||
int rfc822;
|
||||
int utc;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
unsigned long opt;
|
||||
struct tm tm_time;
|
||||
char *filename = NULL;
|
||||
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
int ifmt = 0;
|
||||
@@ -137,43 +153,41 @@ int date_main(int argc, char **argv)
|
||||
# define GETOPT_ISOFMT
|
||||
#endif
|
||||
bb_opt_complementaly = "d~ds:s~ds";
|
||||
opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT,
|
||||
&date_str, &date_str
|
||||
opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT,
|
||||
&date_str, &date_str, &filename
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
, &isofmt_arg
|
||||
#endif
|
||||
);
|
||||
rfc822 = opt & 1;
|
||||
set_time = opt & 2;
|
||||
utc = opt & 4;
|
||||
if(utc) {
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
||||
set_time = opt & DATE_OPT_SET;
|
||||
utc = opt & DATE_OPT_UTC;
|
||||
if ((utc) && (putenv("TZ=UTC0") != 0)) {
|
||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
||||
}
|
||||
use_arg = opt & 8;
|
||||
if(opt & 0x80000000UL)
|
||||
bb_show_usage();
|
||||
use_arg = opt & DATE_OPT_DATE;
|
||||
if(opt & BB_GETOPT_ERROR)
|
||||
bb_show_usage();
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
if(opt & 16) {
|
||||
if (!isofmt_arg)
|
||||
ifmt = 1;
|
||||
else {
|
||||
if(opt & DATE_OPT_TIMESPEC) {
|
||||
if (!isofmt_arg) {
|
||||
ifmt = 1;
|
||||
} else {
|
||||
int ifmt_len = bb_strlen(isofmt_arg);
|
||||
|
||||
if ((ifmt_len <= 4)
|
||||
if ((ifmt_len <= 4)
|
||||
&& (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
|
||||
ifmt = 1;
|
||||
} else if ((ifmt_len <= 5)
|
||||
&& (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
|
||||
ifmt = 2;
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
|
||||
ifmt = 3;
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
|
||||
ifmt = 4;
|
||||
}
|
||||
ifmt = 1;
|
||||
} else if ((ifmt_len <= 5)
|
||||
&& (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
|
||||
ifmt = 2;
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
|
||||
ifmt = 3;
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
|
||||
ifmt = 4;
|
||||
}
|
||||
}
|
||||
if (!ifmt) {
|
||||
bb_show_usage();
|
||||
}
|
||||
@@ -190,18 +204,20 @@ int date_main(int argc, char **argv)
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
if(filename) {
|
||||
struct stat statbuf;
|
||||
if(stat(filename,&statbuf))
|
||||
bb_perror_msg_and_die("File '%s' not found.\n",filename);
|
||||
tm=statbuf.st_mtime;
|
||||
} else time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
if (date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (date_str != NULL) {
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
@@ -245,10 +261,10 @@ int date_main(int argc, char **argv)
|
||||
case 0:
|
||||
default:
|
||||
#endif
|
||||
date_fmt =
|
||||
(rfc822
|
||||
? (utc ? "%a, %e %b %Y %H:%M:%S GMT" :
|
||||
"%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y");
|
||||
date_fmt = (opt & DATE_OPT_RFC2822 ?
|
||||
(utc ? "%a, %d %b %Y %H:%M:%S GMT" :
|
||||
"%a, %d %b %Y %H:%M:%S %z") :
|
||||
"%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
break;
|
||||
@@ -266,10 +282,13 @@ int date_main(int argc, char **argv)
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
puts(t_buff);
|
||||
{
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
RESERVE_CONFIG_BUFFER(t_buff, 201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
puts(t_buff);
|
||||
RELEASE_CONFIG_BUFFER(t_buff);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+4
-4
@@ -57,7 +57,7 @@ int dd_main(int argc, char **argv)
|
||||
off_t skip = 0;
|
||||
int sync_flag = FALSE;
|
||||
int noerror = FALSE;
|
||||
int trunc = TRUE;
|
||||
int trunc_flag = TRUE;
|
||||
int oflag;
|
||||
int ifd;
|
||||
int ofd;
|
||||
@@ -83,7 +83,7 @@ int dd_main(int argc, char **argv)
|
||||
buf = argv[i]+5;
|
||||
while (1) {
|
||||
if (strncmp("notrunc", buf, 7) == 0) {
|
||||
trunc = FALSE;
|
||||
trunc_flag = FALSE;
|
||||
buf += 7;
|
||||
} else if (strncmp("sync", buf, 4) == 0) {
|
||||
sync_flag = TRUE;
|
||||
@@ -115,7 +115,7 @@ int dd_main(int argc, char **argv)
|
||||
if (outfile != NULL) {
|
||||
oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && trunc) {
|
||||
if (!seek && trunc_flag) {
|
||||
oflag |= O_TRUNC;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ int dd_main(int argc, char **argv)
|
||||
bb_perror_msg_and_die("%s", outfile);
|
||||
}
|
||||
|
||||
if (seek && trunc) {
|
||||
if (seek && trunc_flag) {
|
||||
if (ftruncate(ofd, seek * bs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
|
||||
+9
-9
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -27,7 +27,7 @@
|
||||
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
||||
*
|
||||
* Size reduction. Removed floating point dependency. Added error checking
|
||||
* on output. Output stats on 0-sized filesystems if specificly listed on
|
||||
* on output. Output stats on 0-sized filesystems if specifically listed on
|
||||
* the command line. Properly round *-blocks, Used, and Available quantities.
|
||||
*/
|
||||
|
||||
@@ -51,7 +51,7 @@ extern int df_main(int argc, char **argv)
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
unsigned long df_disp_hr = KILOBYTE;
|
||||
unsigned long df_disp_hr = KILOBYTE;
|
||||
#endif
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned long opt;
|
||||
@@ -115,7 +115,7 @@ extern int df_main(int argc, char **argv)
|
||||
bb_perror_msg("%s", mount_point);
|
||||
goto SET_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if ((s.f_blocks > 0) || !mount_table){
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = 0;
|
||||
@@ -124,25 +124,25 @@ extern int df_main(int argc, char **argv)
|
||||
+ (blocks_used + s.f_bavail)/2
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(device, "rootfs") == 0) {
|
||||
continue;
|
||||
} else if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
if ((device = find_real_root_device_name(device)) == NULL) {
|
||||
if ((device = find_real_root_device_name()) == NULL) {
|
||||
goto SET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
bb_printf("%-21s%9s ", device,
|
||||
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
|
||||
|
||||
|
||||
bb_printf("%9s ",
|
||||
make_human_readable_str( (s.f_blocks - s.f_bfree),
|
||||
s.f_bsize, df_disp_hr));
|
||||
|
||||
|
||||
bb_printf("%9s %3ld%% %s\n",
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -50,7 +50,7 @@ typedef unsigned long int bb_uint64_t;
|
||||
static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
// if fn is NULL then input is stdin and output is stdout
|
||||
static int convert(char *fn, int ConvType)
|
||||
static int convert(char *fn, int ConvType)
|
||||
{
|
||||
int c, fd;
|
||||
struct timeval tv;
|
||||
@@ -64,7 +64,9 @@ static int convert(char *fn, int ConvType)
|
||||
c = strlen(tempFn);
|
||||
tempFn[c] = '.';
|
||||
while(1) {
|
||||
if (c >=BUFSIZ)
|
||||
/* tempFn is BUFSIZ so the last addressable spot it BUFSIZ-1.
|
||||
* The loop increments by 2. So this must check for BUFSIZ-3. */
|
||||
if (c >=BUFSIZ-3)
|
||||
bb_error_msg_and_die("unique name not found");
|
||||
/* Get some semi random stuff to try and make a
|
||||
* random filename based (and in the same dir as)
|
||||
@@ -156,12 +158,12 @@ static int convert(char *fn, int ConvType)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char *argv[])
|
||||
int dos2unix_main(int argc, char *argv[])
|
||||
{
|
||||
int ConvType = CT_AUTO;
|
||||
int o;
|
||||
|
||||
//See if we are supposed to be doing dos2unix or unix2dos
|
||||
//See if we are supposed to be doing dos2unix or unix2dos
|
||||
if (argv[0][0]=='d') {
|
||||
ConvType = CT_DOS2UNIX;
|
||||
}
|
||||
|
||||
+8
-4
@@ -56,7 +56,7 @@ static unsigned int disp_k; /* bss inits to 0 */
|
||||
#endif
|
||||
|
||||
static int max_print_depth = INT_MAX;
|
||||
static int count_hardlinks = INT_MAX;
|
||||
static int count_hardlinks = 1;
|
||||
|
||||
static int status
|
||||
#if EXIT_SUCCESS == 0
|
||||
@@ -77,7 +77,11 @@ static void print(long size, char *filename)
|
||||
bb_printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
|
||||
filename);
|
||||
#else
|
||||
bb_printf("%ld\t%s\n", size >> disp_k, filename);
|
||||
if (disp_k) {
|
||||
size++;
|
||||
size >>= 1;
|
||||
}
|
||||
bb_printf("%ld\t%s\n", size, filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -177,7 +181,7 @@ int du_main(int argc, char **argv)
|
||||
#else
|
||||
disp_k = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Note: SUSv3 specifies that -a and -s options can not be used together
|
||||
@@ -234,7 +238,7 @@ int du_main(int argc, char **argv)
|
||||
}
|
||||
if((opt & (1 << 7))) {
|
||||
/* -l opt */
|
||||
count_hardlinks = 1;
|
||||
count_hardlinks = INT_MAX;
|
||||
}
|
||||
print_final_total = opt & (1 << 8); /* -c opt */
|
||||
|
||||
|
||||
+5
-5
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
||||
*
|
||||
* Because of behavioral differences, implemented configureable SUSv3
|
||||
* Because of behavioral differences, implemented configurable SUSv3
|
||||
* or 'fancy' gnu-ish behaviors. Also, reduced size and fixed bugs.
|
||||
* 1) In handling '\c' escape, the previous version only suppressed the
|
||||
* trailing newline. SUSv3 specifies _no_ output after '\c'.
|
||||
@@ -55,7 +55,7 @@ extern int echo_main(int argc, char** argv)
|
||||
* that all of the options specified are actually valid.
|
||||
* Otherwise, the string should just be echoed.
|
||||
*/
|
||||
|
||||
|
||||
if (!*(p = *argv + 1)) { /* A single '-', so echo it. */
|
||||
goto just_echo;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ just_echo:
|
||||
while ((c = *(*argv)++)) {
|
||||
if (c == eflag) { /* Check for escape seq. */
|
||||
if (**argv == 'c') {
|
||||
/* '\c' means cancel newline and
|
||||
/* '\c' means cancel newline and
|
||||
* ignore all subsequent chars. */
|
||||
goto DONE;
|
||||
}
|
||||
@@ -141,8 +141,8 @@ DONE:
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
||||
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
||||
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
||||
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
||||
*
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
|
||||
+3
-3
@@ -34,8 +34,8 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by Vladimir Oleynik <andersen@codepoet.org> (C) 2003
|
||||
* - corretion "-" option usage
|
||||
* Modified by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003
|
||||
* - correct "-" option usage
|
||||
* - multiple "-u unsetenv" support
|
||||
* - GNU long option support
|
||||
* - save errno after exec failed before bb_perror_msg()
|
||||
@@ -62,7 +62,7 @@ extern int env_main(int argc, char** argv)
|
||||
char **ep, *p;
|
||||
char *cleanenv[1] = { NULL };
|
||||
unsigned long opt;
|
||||
llist_t *unset_env;
|
||||
llist_t *unset_env = NULL;
|
||||
extern char **environ;
|
||||
|
||||
bb_opt_complementaly = "u*";
|
||||
|
||||
+106
-114
@@ -5,27 +5,28 @@
|
||||
* based on GNU expr Mike Parker.
|
||||
* Copyright (C) 86, 1991-1997, 1999 Free Software Foundation, Inc.
|
||||
*
|
||||
* Busybox modifications
|
||||
* Busybox modifications
|
||||
* Copyright (c) 2000 Edward Betts <edward@debian.org>.
|
||||
* Aug 2003 Vladimir Oleynik - reduced 464 bytes.
|
||||
*
|
||||
* this program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the gnu general public license as published by
|
||||
* the free software foundation; either version 2 of the license, or
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* this program is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. see the gnu
|
||||
* general public license for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* you should have received a copy of the gnu general public license
|
||||
* along with this program; if not, write to the free software
|
||||
* foundation, inc., 59 temple place, suite 330, boston, ma 02111-1307 usa
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/* This program evaluates expressions. Each token (operator, operand,
|
||||
* parenthesis) of the expression must be a seperate argument. The
|
||||
* parenthesis) of the expression must be a separate argument. The
|
||||
* parser used is a reasonably general one, though any incarnation of
|
||||
* it is language-specific. It is especially nice for expressions.
|
||||
*
|
||||
@@ -40,6 +41,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <regex.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
@@ -115,7 +117,7 @@ static VALUE *str_value (char *s)
|
||||
|
||||
v = xmalloc (sizeof(VALUE));
|
||||
v->type = string;
|
||||
v->u.s = strdup (s);
|
||||
v->u.s = bb_xstrdup (s);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -135,10 +137,8 @@ static int null (VALUE *v)
|
||||
switch (v->type) {
|
||||
case integer:
|
||||
return v->u.i == 0;
|
||||
case string:
|
||||
default: /* string: */
|
||||
return v->u.s[0] == '\0' || strcmp (v->u.s, "0") == 0;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,24 +156,20 @@ static void tostring (VALUE *v)
|
||||
|
||||
static int toarith (VALUE *v)
|
||||
{
|
||||
int i;
|
||||
if(v->type == string) {
|
||||
int i;
|
||||
char *e;
|
||||
|
||||
switch (v->type) {
|
||||
case integer:
|
||||
return 1;
|
||||
case string:
|
||||
i = 0;
|
||||
/* Don't interpret the empty string as an integer. */
|
||||
if (v->u.s == 0)
|
||||
return 0;
|
||||
i = atoi(v->u.s);
|
||||
free (v->u.s);
|
||||
v->u.i = i;
|
||||
v->type = integer;
|
||||
return 1;
|
||||
default:
|
||||
abort ();
|
||||
/* Don't interpret the empty string as an integer. */
|
||||
/* Currently does not worry about overflow or int/long differences. */
|
||||
i = (int) strtol(v->u.s, &e, 10);
|
||||
if ((v->u.s == e) || *e)
|
||||
return 0;
|
||||
free (v->u.s);
|
||||
v->u.i = i;
|
||||
v->type = integer;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return nonzero if the next token matches STR exactly.
|
||||
@@ -189,56 +185,59 @@ nextarg (char *str)
|
||||
|
||||
/* The comparison operator handling functions. */
|
||||
|
||||
#define cmpf(name, rel) \
|
||||
static int name (VALUE *l, VALUE *r) \
|
||||
{ \
|
||||
if (l->type == string || r->type == string) { \
|
||||
tostring (l); \
|
||||
tostring (r); \
|
||||
return strcmp (l->u.s, r->u.s) rel 0; \
|
||||
} \
|
||||
else \
|
||||
return l->u.i rel r->u.i; \
|
||||
}
|
||||
cmpf (less_than, <)
|
||||
cmpf (less_equal, <=)
|
||||
cmpf (equal, ==)
|
||||
cmpf (not_equal, !=)
|
||||
cmpf (greater_equal, >=)
|
||||
cmpf (greater_than, >)
|
||||
static int cmp_common (VALUE *l, VALUE *r, int op)
|
||||
{
|
||||
int cmpval;
|
||||
|
||||
#undef cmpf
|
||||
if (l->type == string || r->type == string) {
|
||||
tostring (l);
|
||||
tostring (r);
|
||||
cmpval = strcmp (l->u.s, r->u.s);
|
||||
}
|
||||
else
|
||||
cmpval = l->u.i - r->u.i;
|
||||
switch(op) {
|
||||
case '<':
|
||||
return cmpval < 0;
|
||||
case ('L'+'E'):
|
||||
return cmpval <= 0;
|
||||
case '=':
|
||||
return cmpval == 0;
|
||||
case '!':
|
||||
return cmpval != 0;
|
||||
case '>':
|
||||
return cmpval > 0;
|
||||
default: /* >= */
|
||||
return cmpval >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The arithmetic operator handling functions. */
|
||||
|
||||
#define arithf(name, op) \
|
||||
static \
|
||||
int name (VALUE *l, VALUE *r) \
|
||||
{ \
|
||||
if (!toarith (l) || !toarith (r)) \
|
||||
bb_error_msg_and_die ("non-numeric argument"); \
|
||||
return l->u.i op r->u.i; \
|
||||
static int arithmetic_common (VALUE *l, VALUE *r, int op)
|
||||
{
|
||||
int li, ri;
|
||||
|
||||
if (!toarith (l) || !toarith (r))
|
||||
bb_error_msg_and_die ("non-numeric argument");
|
||||
li = l->u.i;
|
||||
ri = r->u.i;
|
||||
if((op == '/' || op == '%') && ri == 0)
|
||||
bb_error_msg_and_die ( "division by zero");
|
||||
switch(op) {
|
||||
case '+':
|
||||
return li + ri;
|
||||
case '-':
|
||||
return li - ri;
|
||||
case '*':
|
||||
return li * ri;
|
||||
case '/':
|
||||
return li / ri;
|
||||
default:
|
||||
return li % ri;
|
||||
}
|
||||
}
|
||||
|
||||
#define arithdivf(name, op) \
|
||||
static int name (VALUE *l, VALUE *r) \
|
||||
{ \
|
||||
if (!toarith (l) || !toarith (r)) \
|
||||
bb_error_msg_and_die ( "non-numeric argument"); \
|
||||
if (r->u.i == 0) \
|
||||
bb_error_msg_and_die ( "division by zero"); \
|
||||
return l->u.i op r->u.i; \
|
||||
}
|
||||
|
||||
arithf (plus, +)
|
||||
arithf (minus, -)
|
||||
arithf (multiply, *)
|
||||
arithdivf (divide, /)
|
||||
arithdivf (mod, %)
|
||||
|
||||
#undef arithf
|
||||
#undef arithdivf
|
||||
|
||||
/* Do the : operator.
|
||||
SV is the VALUE for the lhs (the string),
|
||||
PV is the VALUE for the rhs (the pattern). */
|
||||
@@ -246,10 +245,9 @@ static int name (VALUE *l, VALUE *r) \
|
||||
static VALUE *docolon (VALUE *sv, VALUE *pv)
|
||||
{
|
||||
VALUE *v;
|
||||
const char *errmsg;
|
||||
struct re_pattern_buffer re_buffer;
|
||||
struct re_registers re_regs;
|
||||
int len;
|
||||
regex_t re_buffer;
|
||||
const int NMATCH = 2;
|
||||
regmatch_t re_regs[NMATCH];
|
||||
|
||||
tostring (sv);
|
||||
tostring (pv);
|
||||
@@ -261,27 +259,22 @@ of a basic regular expression is not portable; it is being ignored",
|
||||
pv->u.s);
|
||||
}
|
||||
|
||||
len = strlen (pv->u.s);
|
||||
memset (&re_buffer, 0, sizeof (re_buffer));
|
||||
memset (&re_regs, 0, sizeof (re_regs));
|
||||
re_buffer.allocated = 2 * len;
|
||||
re_buffer.buffer = (unsigned char *) xmalloc (re_buffer.allocated);
|
||||
re_buffer.translate = 0;
|
||||
re_syntax_options = RE_SYNTAX_POSIX_BASIC;
|
||||
errmsg = re_compile_pattern (pv->u.s, len, &re_buffer);
|
||||
if (errmsg) {
|
||||
bb_error_msg_and_die("%s", errmsg);
|
||||
}
|
||||
memset (re_regs, 0, sizeof (*re_regs));
|
||||
if( regcomp (&re_buffer, pv->u.s, 0) != 0 )
|
||||
bb_error_msg_and_die("Invalid regular expression");
|
||||
|
||||
len = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
|
||||
if (len >= 0) {
|
||||
/* expr uses an anchored pattern match, so check that there was a
|
||||
* match and that the match starts at offset 0. */
|
||||
if (regexec (&re_buffer, sv->u.s, NMATCH, re_regs, 0) != REG_NOMATCH &&
|
||||
re_regs[0].rm_so == 0) {
|
||||
/* Were \(...\) used? */
|
||||
if (re_buffer.re_nsub > 0) { /* was (re_regs.start[1] >= 0) */
|
||||
sv->u.s[re_regs.end[1]] = '\0';
|
||||
v = str_value (sv->u.s + re_regs.start[1]);
|
||||
if (re_buffer.re_nsub > 0) {
|
||||
sv->u.s[re_regs[1].rm_eo] = '\0';
|
||||
v = str_value (sv->u.s + re_regs[1].rm_so);
|
||||
}
|
||||
else
|
||||
v = int_value (len);
|
||||
v = int_value (re_regs[0].rm_eo);
|
||||
}
|
||||
else {
|
||||
/* Match failed -- return the right kind of null. */
|
||||
@@ -290,7 +283,6 @@ of a basic regular expression is not portable; it is being ignored",
|
||||
else
|
||||
v = int_value (0);
|
||||
}
|
||||
free (re_buffer.buffer);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -408,21 +400,21 @@ static VALUE *eval5 (void)
|
||||
static VALUE *eval4 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
int (*fxn) (VALUE *, VALUE *), val;
|
||||
int op, val;
|
||||
|
||||
l = eval5 ();
|
||||
while (1) {
|
||||
if (nextarg ("*"))
|
||||
fxn = multiply;
|
||||
op = '*';
|
||||
else if (nextarg ("/"))
|
||||
fxn = divide;
|
||||
op = '/';
|
||||
else if (nextarg ("%"))
|
||||
fxn = mod;
|
||||
op = '%';
|
||||
else
|
||||
return l;
|
||||
args++;
|
||||
r = eval5 ();
|
||||
val = (*fxn) (l, r);
|
||||
val = arithmetic_common (l, r, op);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (val);
|
||||
@@ -434,19 +426,19 @@ static VALUE *eval4 (void)
|
||||
static VALUE *eval3 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
int (*fxn) (VALUE *, VALUE *), val;
|
||||
int op, val;
|
||||
|
||||
l = eval4 ();
|
||||
while (1) {
|
||||
if (nextarg ("+"))
|
||||
fxn = plus;
|
||||
op = '+';
|
||||
else if (nextarg ("-"))
|
||||
fxn = minus;
|
||||
op = '-';
|
||||
else
|
||||
return l;
|
||||
args++;
|
||||
r = eval4 ();
|
||||
val = (*fxn) (l, r);
|
||||
val = arithmetic_common (l, r, op);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (val);
|
||||
@@ -458,29 +450,29 @@ static VALUE *eval3 (void)
|
||||
static VALUE *eval2 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
int (*fxn) (VALUE *, VALUE *), val;
|
||||
int op, val;
|
||||
|
||||
l = eval3 ();
|
||||
while (1) {
|
||||
if (nextarg ("<"))
|
||||
fxn = less_than;
|
||||
op = '<';
|
||||
else if (nextarg ("<="))
|
||||
fxn = less_equal;
|
||||
op = 'L'+'E';
|
||||
else if (nextarg ("=") || nextarg ("=="))
|
||||
fxn = equal;
|
||||
op = '=';
|
||||
else if (nextarg ("!="))
|
||||
fxn = not_equal;
|
||||
op = '!';
|
||||
else if (nextarg (">="))
|
||||
fxn = greater_equal;
|
||||
op = 'G'+'E';
|
||||
else if (nextarg (">"))
|
||||
fxn = greater_than;
|
||||
op = '>';
|
||||
else
|
||||
return l;
|
||||
args++;
|
||||
r = eval3 ();
|
||||
toarith (l);
|
||||
toarith (r);
|
||||
val = (*fxn) (l, r);
|
||||
val = cmp_common (l, r, op);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (val);
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini false implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
Copyright (C) 91, 1995-2002 Free Software Foundation, Inc.
|
||||
|
||||
Modified for busybox based on coreutils v 5.0
|
||||
Copyright (C) 2003 Glenn McGrath <bug1@optushome.com.au>
|
||||
Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
+91
-62
@@ -21,90 +21,119 @@
|
||||
*/
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "pwd_.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef CONFIG_SELINUX
|
||||
#include <proc_secure.h>
|
||||
#include <flask_util.h>
|
||||
#include <selinux/selinux.h>
|
||||
#endif
|
||||
|
||||
#define JUST_USER 1
|
||||
#define JUST_GROUP 2
|
||||
#define PRINT_REAL 4
|
||||
#define NAME_NOT_NUMBER 8
|
||||
#define PRINT_REAL 1
|
||||
#define NAME_NOT_NUMBER 2
|
||||
#define JUST_USER 4
|
||||
#define JUST_GROUP 8
|
||||
|
||||
static short printf_full(unsigned int id, const char *arg, const char prefix)
|
||||
{
|
||||
const char *fmt = "%cid=%u";
|
||||
short status=EXIT_FAILURE;
|
||||
|
||||
if(arg) {
|
||||
fmt = "%cid=%u(%s)";
|
||||
status=EXIT_SUCCESS;
|
||||
}
|
||||
bb_printf(fmt, prefix, id, arg);
|
||||
return status;
|
||||
}
|
||||
|
||||
extern int id_main(int argc, char **argv)
|
||||
{
|
||||
char user[9], group[9];
|
||||
long pwnam, grnam;
|
||||
int uid, gid;
|
||||
int flags;
|
||||
#ifdef CONFIG_SELINUX
|
||||
int is_flask_enabled_flag = is_flask_enabled();
|
||||
#endif
|
||||
|
||||
flags = bb_getopt_ulflags(argc, argv, "ugrn");
|
||||
struct passwd *p;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
unsigned long flags;
|
||||
short status;
|
||||
|
||||
if (((flags & (JUST_USER | JUST_GROUP)) == (JUST_USER | JUST_GROUP))
|
||||
|| (argc > optind + 1)
|
||||
) {
|
||||
|
||||
bb_opt_complementaly = "u~g:g~u";
|
||||
flags = bb_getopt_ulflags(argc, argv, "rnug");
|
||||
|
||||
if ((flags & BB_GETOPT_ERROR)
|
||||
/* Don't allow -n -r -nr */
|
||||
|| (flags <= 3 && flags > 0)
|
||||
/* Don't allow more than one username */
|
||||
|| (argc > optind + 1))
|
||||
bb_show_usage();
|
||||
|
||||
/* This values could be overwritten later */
|
||||
uid = geteuid();
|
||||
gid = getegid();
|
||||
if (flags & PRINT_REAL) {
|
||||
uid = getuid();
|
||||
gid = getgid();
|
||||
}
|
||||
|
||||
if(argv[optind]) {
|
||||
p=getpwnam(argv[optind]);
|
||||
/* my_getpwnam is needed because it exits on failure */
|
||||
uid = my_getpwnam(argv[optind]);
|
||||
gid = p->pw_gid;
|
||||
/* in this case PRINT_REAL is the same */
|
||||
}
|
||||
|
||||
if (argv[optind] == NULL) {
|
||||
if (flags & PRINT_REAL) {
|
||||
uid = getuid();
|
||||
gid = getgid();
|
||||
if(flags & (JUST_GROUP | JUST_USER)) {
|
||||
/* JUST_GROUP and JUST_USER are mutually exclusive */
|
||||
if(flags & NAME_NOT_NUMBER) {
|
||||
/* my_getpwuid and my_getgrgid exit on failure so puts cannot segfault */
|
||||
puts((flags & JUST_USER) ? my_getpwuid(NULL, uid, -1 ) : my_getgrgid(NULL, gid, -1 ));
|
||||
} else {
|
||||
uid = geteuid();
|
||||
gid = getegid();
|
||||
bb_printf("%u\n",(flags & JUST_USER) ? uid : gid);
|
||||
}
|
||||
my_getpwuid(user, uid);
|
||||
} else {
|
||||
safe_strncpy(user, argv[optind], sizeof(user));
|
||||
gid = my_getpwnamegid(user);
|
||||
/* exit */
|
||||
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
my_getgrgid(group, gid);
|
||||
|
||||
pwnam=my_getpwnam(user);
|
||||
grnam=my_getgrnam(group);
|
||||
|
||||
if (flags & (JUST_GROUP | JUST_USER)) {
|
||||
char *s = group;
|
||||
if (flags & JUST_USER) {
|
||||
s = user;
|
||||
grnam = pwnam;
|
||||
}
|
||||
if (flags & NAME_NOT_NUMBER) {
|
||||
puts(s);
|
||||
} else {
|
||||
printf("%ld\n", grnam);
|
||||
}
|
||||
} else {
|
||||
/* Print full info like GNU id */
|
||||
/* my_getpwuid doesn't exit on failure here */
|
||||
status=printf_full(uid, my_getpwuid(NULL, uid, 0), 'u');
|
||||
putchar(' ');
|
||||
/* my_getgrgid doesn't exit on failure here */
|
||||
status|=printf_full(gid, my_getgrgid(NULL, gid, 0), 'g');
|
||||
#ifdef CONFIG_SELINUX
|
||||
printf("uid=%ld(%s) gid=%ld(%s)", pwnam, user, grnam, group);
|
||||
if(is_flask_enabled_flag)
|
||||
{
|
||||
security_id_t mysid = getsecsid();
|
||||
if ( is_selinux_enabled() ) {
|
||||
security_context_t mysid;
|
||||
char context[80];
|
||||
int len = sizeof(context);
|
||||
|
||||
getcon(&mysid);
|
||||
context[0] = '\0';
|
||||
if(security_sid_to_context(mysid, context, &len))
|
||||
strcpy(context, "unknown");
|
||||
printf(" context=%s\n", context);
|
||||
}
|
||||
else
|
||||
printf("\n");
|
||||
#else
|
||||
printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
|
||||
#endif
|
||||
|
||||
if (mysid) {
|
||||
len = strlen(mysid)+1;
|
||||
safe_strncpy(context, mysid, len);
|
||||
freecon(mysid);
|
||||
}else{
|
||||
safe_strncpy(context, "unknown",8);
|
||||
}
|
||||
bb_printf(" context=%s", context);
|
||||
}
|
||||
|
||||
bb_fflush_stdout_and_exit(0);
|
||||
#endif
|
||||
putchar('\n');
|
||||
bb_fflush_stdout_and_exit(status);
|
||||
}
|
||||
|
||||
/* END CODE */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*
|
||||
* TODO: -d option, need a way of recursively making directories and changing
|
||||
* owner/group, will probably modify bb_make_directory(...)
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "busybox.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
|
||||
#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
|
||||
|
||||
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' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
extern int install_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
mode_t mode;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
char *gid_str = "-1";
|
||||
char *uid_str = "-1";
|
||||
char *mode_str = "0755";
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int flags;
|
||||
int i;
|
||||
|
||||
bb_applet_long_options = install_long_options;
|
||||
bb_opt_complementaly = "s~d:d~s";
|
||||
/* -c exists for backwards compatability, its needed */
|
||||
flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */
|
||||
|
||||
/* Check valid options were given */
|
||||
if(flags & BB_GETOPT_ERROR) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
|
||||
if (flags & INSTALL_OPT_PRESERVE_TIME) {
|
||||
copy_flags |= FILEUTILS_PRESERVE_STATUS;
|
||||
}
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
gid = get_ug_id(gid_str, my_getgrnam);
|
||||
uid = get_ug_id(uid_str, my_getpwnam);
|
||||
umask(0);
|
||||
|
||||
/* Create directories
|
||||
* dont use bb_make_directory() as it cant change uid or gid
|
||||
* perhaps bb_make_directory() should be improved.
|
||||
*/
|
||||
if (flags & INSTALL_OPT_DIRECTORY) {
|
||||
for (argv += optind; *argv; argv++) {
|
||||
char *old_argv_ptr = *argv + 1;
|
||||
char *argv_ptr;
|
||||
do {
|
||||
argv_ptr = strchr(old_argv_ptr, '/');
|
||||
old_argv_ptr = argv_ptr;
|
||||
if (argv_ptr) {
|
||||
*argv_ptr = '\0';
|
||||
old_argv_ptr++;
|
||||
}
|
||||
if (mkdir(*argv, mode) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
bb_perror_msg("coulnt create %s", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (lchown(*argv, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
if (argv_ptr) {
|
||||
*argv_ptr = '/';
|
||||
}
|
||||
} while (old_argv_ptr);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
cp_mv_stat2(argv[argc - 1], &statbuf, lstat);
|
||||
for (i = optind; i < argc - 1; i++) {
|
||||
unsigned char *dest;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
dest = concat_path_file(argv[argc - 1], basename(argv[i]));
|
||||
} else {
|
||||
dest = argv[argc - 1];
|
||||
}
|
||||
ret |= copy_file(argv[i], dest, copy_flags);
|
||||
|
||||
/* Set the file mode */
|
||||
if (chmod(dest, mode) == -1) {
|
||||
bb_perror_msg("cannot change permissions of %s", dest);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Set the user and group id */
|
||||
if (lchown(dest, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", dest);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
if (flags & INSTALL_OPT_STRIP) {
|
||||
if (execlp("strip", "strip", dest, NULL) == -1) {
|
||||
bb_error_msg("strip failed");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,13 +17,16 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR:= ../../
|
||||
top_srcdir=../..
|
||||
top_builddir=../..
|
||||
srcdir=$(top_srcdir)/coreutils/libcoreutils
|
||||
LIBCOREUTILS_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
LIBCOREUTILS_AR:=libcoreutils.a
|
||||
ifndef $(LIBCOREUTILS_DIR)
|
||||
LIBCOREUTILS_DIR:=$(TOPDIR)coreutils/libcoreutils/
|
||||
LIBCOREUTILS_DIR:=$(top_builddir)/coreutils/libcoreutils/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/coreutils/libcoreutils
|
||||
|
||||
LIBCOREUTILS_SRC:= cp_mv_stat.c getopt_mk_fifo_nod.c xgetoptfile_sort_uniq.c
|
||||
|
||||
@@ -29,4 +30,8 @@ LIBCOREUTILS_OBJS=$(patsubst %.c,$(LIBCOREUTILS_DIR)%.o, $(LIBCOREUTILS_SRC))
|
||||
libraries-y+=$(LIBCOREUTILS_DIR)$(LIBCOREUTILS_AR)
|
||||
|
||||
$(LIBCOREUTILS_DIR)$(LIBCOREUTILS_AR): $(LIBCOREUTILS_OBJS)
|
||||
$(AR) -ro $@ $(LIBCOREUTILS_OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $(LIBCOREUTILS_OBJS)
|
||||
|
||||
$(LIBCOREUTILS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+14
-17
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini ln implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -43,7 +43,8 @@ extern int ln_main(int argc, char **argv)
|
||||
int flag;
|
||||
char *last;
|
||||
char *src_name;
|
||||
const char *src;
|
||||
char *src;
|
||||
struct stat statbuf;
|
||||
int (*link_func)(const char *, const char *);
|
||||
|
||||
flag = bb_getopt_ulflags(argc, argv, "sfn");
|
||||
@@ -61,7 +62,7 @@ extern int ln_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
do {
|
||||
src_name = 0;
|
||||
src_name = NULL;
|
||||
src = last;
|
||||
|
||||
if (is_directory(src,
|
||||
@@ -70,7 +71,13 @@ extern int ln_main(int argc, char **argv)
|
||||
src_name = bb_xstrdup(*argv);
|
||||
src = concat_path_file(src, bb_get_last_path_component(src_name));
|
||||
free(src_name);
|
||||
src_name = (char *)src;
|
||||
src_name = src;
|
||||
}
|
||||
if (!(flag & LN_SYMLINK) && stat(*argv, &statbuf)) {
|
||||
bb_perror_msg(*argv);
|
||||
status = EXIT_FAILURE;
|
||||
free(src_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flag & LN_FORCE) {
|
||||
@@ -81,25 +88,15 @@ extern int ln_main(int argc, char **argv)
|
||||
if (flag & LN_SYMLINK) {
|
||||
link_func = symlink;
|
||||
}
|
||||
|
||||
|
||||
if (link_func(*argv, src) != 0) {
|
||||
bb_perror_msg(src);
|
||||
status = EXIT_FAILURE;;
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
free(src_name);
|
||||
|
||||
|
||||
} while ((++argv)[1]);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
* is _not_ the same. Erik apparently made this change almost 3 years
|
||||
* ago to avoid failing when no utmp was available. However, the
|
||||
* correct course of action wrt SUSv3 for a failing getlogin() is
|
||||
* a dianostic message and an error return.
|
||||
* a diagnostic message and an error return.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
+201
-161
@@ -61,22 +61,16 @@ enum {
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sysmacros.h> /* major() and minor() */
|
||||
#include "busybox.h"
|
||||
#ifdef CONFIG_SELINUX
|
||||
#include <fs_secure.h>
|
||||
#include <flask_util.h>
|
||||
#include <ss.h>
|
||||
#include <selinux/selinux.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
/* what is the overall style of the listing */
|
||||
#define STYLE_AUTO (0)
|
||||
#define STYLE_COLUMNS (1U<<21) /* fill columns */
|
||||
@@ -186,7 +180,7 @@ struct dnode { /* the basic node */
|
||||
char *fullname; /* the dir entry name */
|
||||
struct stat dstat; /* the file stat info */
|
||||
#ifdef CONFIG_SELINUX
|
||||
security_id_t sid;
|
||||
security_context_t sid;
|
||||
#endif
|
||||
struct dnode *next; /* point at the next node */
|
||||
};
|
||||
@@ -199,11 +193,11 @@ static int list_single(struct dnode *);
|
||||
static unsigned int all_fmt;
|
||||
|
||||
#ifdef CONFIG_SELINUX
|
||||
static int is_flask_enabled_flag;
|
||||
static int selinux_enabled= 0;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
static unsigned short terminal_width = TERMINAL_WIDTH;
|
||||
static int terminal_width = TERMINAL_WIDTH;
|
||||
static unsigned short tabstops = COLUMN_GAP;
|
||||
#else
|
||||
#define tabstops COLUMN_GAP
|
||||
@@ -217,18 +211,19 @@ static struct dnode *my_stat(char *fullname, char *name)
|
||||
struct stat dstat;
|
||||
struct dnode *cur;
|
||||
#ifdef CONFIG_SELINUX
|
||||
security_id_t sid;
|
||||
security_context_t sid=NULL;
|
||||
#endif
|
||||
int rc;
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||
if (all_fmt & FOLLOW_LINKS) {
|
||||
#ifdef CONFIG_SELINUX
|
||||
if(is_flask_enabled_flag)
|
||||
rc = stat_secure(fullname, &dstat, &sid);
|
||||
else
|
||||
if (is_selinux_enabled()) {
|
||||
rc=0; /* Set the number which means success before hand. */
|
||||
rc = getfilecon(fullname,&sid);
|
||||
}
|
||||
#endif
|
||||
rc = stat(fullname, &dstat);
|
||||
rc = stat(fullname, &dstat);
|
||||
if(rc)
|
||||
{
|
||||
bb_perror_msg("%s", fullname);
|
||||
@@ -239,9 +234,12 @@ static struct dnode *my_stat(char *fullname, char *name)
|
||||
#endif
|
||||
{
|
||||
#ifdef CONFIG_SELINUX
|
||||
if(is_flask_enabled_flag)
|
||||
rc = lstat_secure(fullname, &dstat, &sid);
|
||||
else
|
||||
if (is_selinux_enabled()) {
|
||||
rc=0; /* Set the number which means success before hand. */
|
||||
rc = lgetfilecon(fullname,&sid);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
rc = lstat(fullname, &dstat);
|
||||
if(rc)
|
||||
@@ -315,7 +313,7 @@ static int count_dirs(struct dnode **dn, int nfiles, int notsubdirs)
|
||||
if (S_ISDIR(dn[i]->dstat.st_mode)
|
||||
&& (notsubdirs
|
||||
|| ((dn[i]->name[0] != '.')
|
||||
|| (dn[i]->name[1]
|
||||
|| (dn[i]->name[1]
|
||||
&& ((dn[i]->name[1] != '.')
|
||||
|| dn[i]->name[2])))))
|
||||
dirs++;
|
||||
@@ -532,7 +530,7 @@ static void showfiles(struct dnode **dn, int nfiles)
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void showdirs(struct dnode **dn, int ndirs)
|
||||
static void showdirs(struct dnode **dn, int ndirs, int first)
|
||||
{
|
||||
int i, nfiles;
|
||||
struct dnode **subdnp;
|
||||
@@ -547,7 +545,10 @@ static void showdirs(struct dnode **dn, int ndirs)
|
||||
|
||||
for (i = 0; i < ndirs; i++) {
|
||||
if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
|
||||
printf("\n%s:\n", dn[i]->fullname);
|
||||
if (!first)
|
||||
printf("\n");
|
||||
first = 0;
|
||||
printf("%s:\n", dn[i]->fullname);
|
||||
}
|
||||
subdnp = list_dir(dn[i]->fullname);
|
||||
nfiles = countfiles(subdnp);
|
||||
@@ -566,7 +567,7 @@ static void showdirs(struct dnode **dn, int ndirs)
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
shellsort(dnd, dndirs);
|
||||
#endif
|
||||
showdirs(dnd, dndirs);
|
||||
showdirs(dnd, dndirs, 0);
|
||||
free(dnd); /* free the array of dnode pointers to the dirs */
|
||||
}
|
||||
}
|
||||
@@ -684,9 +685,9 @@ static int list_single(struct dnode *dn)
|
||||
break;
|
||||
case LIST_ID_NAME:
|
||||
#ifdef CONFIG_FEATURE_LS_USERNAME
|
||||
my_getpwuid(scratch, dn->dstat.st_uid);
|
||||
my_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
|
||||
printf("%-8.8s ", scratch);
|
||||
my_getgrgid(scratch, dn->dstat.st_gid);
|
||||
my_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
|
||||
printf("%-8.8s", scratch);
|
||||
column += 17;
|
||||
break;
|
||||
@@ -697,8 +698,8 @@ static int list_single(struct dnode *dn)
|
||||
case LIST_SIZE:
|
||||
case LIST_DEV:
|
||||
if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
|
||||
column += printf("%4d, %3d ", (int) MAJOR(dn->dstat.st_rdev),
|
||||
(int) MINOR(dn->dstat.st_rdev));
|
||||
column += printf("%4d, %3d ", (int) major(dn->dstat.st_rdev),
|
||||
(int) minor(dn->dstat.st_rdev));
|
||||
} else {
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
if (all_fmt & LS_DISP_HR) {
|
||||
@@ -717,32 +718,36 @@ static int list_single(struct dnode *dn)
|
||||
break;
|
||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
case LIST_FULLTIME:
|
||||
printf("%24.24s ", filetime);
|
||||
column += 25;
|
||||
break;
|
||||
case LIST_DATE_TIME:
|
||||
if (all_fmt & LIST_FULLTIME) {
|
||||
printf("%24.24s ", filetime);
|
||||
column += 25;
|
||||
break;
|
||||
if ((all_fmt & LIST_FULLTIME) == 0) {
|
||||
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 */
|
||||
printf("%5.5s ", filetime + 11);
|
||||
} else {
|
||||
printf(" %4.4s ", filetime + 20);
|
||||
}
|
||||
column += 13;
|
||||
}
|
||||
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 */
|
||||
printf("%5.5s ", filetime + 11);
|
||||
} else {
|
||||
printf(" %4.4s ", filetime + 20);
|
||||
}
|
||||
column += 13;
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_SELINUX
|
||||
case LIST_CONTEXT:
|
||||
{
|
||||
char context[64];
|
||||
int len = sizeof(context);
|
||||
if(security_sid_to_context(dn->sid, context, &len))
|
||||
{
|
||||
strcpy(context, "unknown");
|
||||
len = 7;
|
||||
char context[80];
|
||||
int len;
|
||||
|
||||
if (dn->sid) {
|
||||
/* I assume sid initilized with NULL */
|
||||
len = strlen(dn->sid)+1;
|
||||
safe_strncpy(context, dn->sid, len);
|
||||
freecon(dn->sid);
|
||||
}else {
|
||||
safe_strncpy(context, "unknown",8);
|
||||
}
|
||||
printf("%-32s ", context);
|
||||
column += MAX(33, len);
|
||||
@@ -808,95 +813,137 @@ static int list_single(struct dnode *dn)
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
static const char ls_opts[] = "1AaCdgilnsx"
|
||||
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
||||
"Fp"
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||
"R"
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
"rSvX"
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
"ecut"
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||
"L"
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
"h"
|
||||
#endif
|
||||
"k"
|
||||
#ifdef CONFIG_SELINUX
|
||||
"K"
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
"T:w:"
|
||||
#endif
|
||||
;
|
||||
/* "[-]Cadil1", POSIX mandated options, busybox always supports */
|
||||
/* "[-]gnsx", POSIX non-mandated options, busybox always supports */
|
||||
/* "[-]Ak" GNU options, busybox always supports */
|
||||
/* "[-]FLRctur", POSIX mandated options, busybox optionally supports */
|
||||
/* "[-]p", POSIX non-mandated options, busybox optionally supports */
|
||||
/* "[-]SXvThw", GNU options, busybox optionally supports */
|
||||
/* "[-]K", SELinux mandated options, busybox optionally supports */
|
||||
/* "[-]e", I think we made this one up */
|
||||
|
||||
#define LIST_MASK_TRIGGER LIST_SHORT
|
||||
#define STYLE_MASK_TRIGGER STYLE_MASK
|
||||
#define SORT_MASK_TRIGGER SORT_MASK
|
||||
#define DISP_MASK_TRIGGER DISP_ROWS
|
||||
#define TIME_MASK_TRIGGER TIME_MASK
|
||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
# define LS_STR_TIMESTAMPS "cetu"
|
||||
#else
|
||||
# define LS_STR_TIMESTAMPS ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
# define LS_STR_SORTFILES "SXrv"
|
||||
#else
|
||||
# define LS_STR_SORTFILES ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
||||
# define LS_STR_FILETYPES "Fp"
|
||||
#else
|
||||
# define LS_STR_FILETYPES ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||
# define LS_STR_FOLLOW_LINKS "L"
|
||||
#else
|
||||
# define LS_STR_FOLLOW_LINKS ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||
# define LS_STR_RECURSIVE "R"
|
||||
#else
|
||||
# define LS_STR_RECURSIVE ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
# define LS_STR_HUMAN_READABLE "h"
|
||||
#else
|
||||
# define LS_STR_HUMAN_READABLE ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SELINUX
|
||||
# define LS_STR_SELINUX "K"
|
||||
#else
|
||||
# define LS_STR_SELINUX ""
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
# define LS_STR_AUTOWIDTH "T:w:"
|
||||
#else
|
||||
# define LS_STR_AUTOWIDTH ""
|
||||
#endif
|
||||
|
||||
static const char ls_options[]="Cadil1gnsxAk" \
|
||||
LS_STR_TIMESTAMPS \
|
||||
LS_STR_SORTFILES \
|
||||
LS_STR_FILETYPES \
|
||||
LS_STR_FOLLOW_LINKS \
|
||||
LS_STR_RECURSIVE \
|
||||
LS_STR_HUMAN_READABLE \
|
||||
LS_STR_SELINUX \
|
||||
LS_STR_AUTOWIDTH;
|
||||
|
||||
#define LIST_MASK_TRIGGER 0
|
||||
#define STYLE_MASK_TRIGGER STYLE_MASK
|
||||
#define SORT_MASK_TRIGGER SORT_MASK
|
||||
#define DISP_MASK_TRIGGER DISP_ROWS
|
||||
#define TIME_MASK_TRIGGER TIME_MASK
|
||||
|
||||
static const unsigned opt_flags[] = {
|
||||
LIST_SHORT | STYLE_SINGLE, /* 1 */
|
||||
DISP_HIDDEN, /* A */
|
||||
DISP_HIDDEN | DISP_DOT, /* a */
|
||||
LIST_SHORT | STYLE_COLUMNS, /* C */
|
||||
DISP_NOLIST, /* d */
|
||||
0, /* g - ingored */
|
||||
LIST_INO, /* i */
|
||||
LIST_LONG | STYLE_LONG, /* l - remember LS_DISP_HR in mask! */
|
||||
LIST_ID_NUMERIC, /* n */
|
||||
LIST_BLOCKS, /* s */
|
||||
DISP_ROWS, /* x */
|
||||
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
||||
LIST_FILETYPE | LIST_EXEC, /* F */
|
||||
LIST_FILETYPE, /* p */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||
DISP_RECURSIVE, /* R */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
SORT_ORDER_REVERSE, /* r */
|
||||
SORT_SIZE, /* S */
|
||||
SORT_VERSION, /* v */
|
||||
SORT_EXT, /* v */
|
||||
DISP_HIDDEN | DISP_DOT, /* a */
|
||||
DISP_NOLIST, /* d */
|
||||
LIST_INO, /* i */
|
||||
LIST_LONG | STYLE_LONG, /* l - remember LS_DISP_HR in mask! */
|
||||
LIST_SHORT | STYLE_SINGLE, /* 1 */
|
||||
0, /* g - ingored */
|
||||
LIST_ID_NUMERIC, /* n */
|
||||
LIST_BLOCKS, /* s */
|
||||
DISP_ROWS, /* x */
|
||||
DISP_HIDDEN, /* A */
|
||||
#ifdef CONFIG_SELINUX
|
||||
LIST_CONTEXT, /* k */
|
||||
#else
|
||||
0, /* k - ingored */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
LIST_FULLTIME, /* e */
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
# ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
TIME_CHANGE | SORT_CTIME, /* c */
|
||||
#else
|
||||
TIME_CHANGE, /* c */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
# else
|
||||
TIME_CHANGE, /* c */
|
||||
# endif
|
||||
LIST_FULLTIME, /* e */
|
||||
# ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
SORT_MTIME, /* t */
|
||||
# else
|
||||
0, /* t - ignored -- is this correct? */
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
TIME_ACCESS | SORT_ATIME, /* u */
|
||||
#else
|
||||
TIME_ACCESS, /* u */
|
||||
# else
|
||||
TIME_ACCESS, /* u */
|
||||
# endif
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
SORT_MTIME, /* t */
|
||||
#else
|
||||
0, /* t - ignored -- is this correct? */
|
||||
SORT_SIZE, /* S */
|
||||
SORT_EXT, /* X */
|
||||
SORT_ORDER_REVERSE, /* r */
|
||||
SORT_VERSION, /* v */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
||||
LIST_FILETYPE | LIST_EXEC, /* F */
|
||||
LIST_FILETYPE, /* p */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||
FOLLOW_LINKS, /* L */
|
||||
FOLLOW_LINKS, /* L */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||
DISP_RECURSIVE, /* R */
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
LS_DISP_HR, /* h */
|
||||
LS_DISP_HR, /* h */
|
||||
#endif
|
||||
#ifndef CONFIG_SELINUX
|
||||
0, /* k - ingored */
|
||||
#else
|
||||
LIST_CONTEXT, /* k */
|
||||
#ifdef CONFIG_SELINUX
|
||||
LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */
|
||||
#endif
|
||||
(1U<<31)
|
||||
};
|
||||
|
||||
|
||||
@@ -904,20 +951,24 @@ LS_DISP_HR, /* h */
|
||||
|
||||
extern int ls_main(int argc, char **argv)
|
||||
{
|
||||
struct dnode **dnf, **dnd;
|
||||
int dnfiles, dndirs;
|
||||
struct dnode *dn, *cur, **dnp;
|
||||
int i, nfiles;
|
||||
int opt;
|
||||
int oi, ac;
|
||||
struct dnode **dnd;
|
||||
struct dnode **dnf;
|
||||
struct dnode **dnp;
|
||||
struct dnode *dn;
|
||||
struct dnode *cur;
|
||||
long opt;
|
||||
int nfiles = 0;
|
||||
int dnfiles;
|
||||
int dndirs;
|
||||
int oi;
|
||||
int ac;
|
||||
int i;
|
||||
char **av;
|
||||
#ifdef CONFIG_SELINUX
|
||||
is_flask_enabled_flag = is_flask_enabled();
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
char *tabstops_str = NULL;
|
||||
char *terminal_width_str = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
struct winsize win = { 0, 0, 0, 0 };
|
||||
#endif
|
||||
|
||||
all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO
|
||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
@@ -927,40 +978,34 @@ extern int ls_main(int argc, char **argv)
|
||||
| SORT_NAME | SORT_ORDER_FORWARD
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
ioctl(fileno(stdout), TIOCGWINSZ, &win);
|
||||
if (win.ws_col > 0)
|
||||
terminal_width = win.ws_col - 1;
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(STDOUT_FILENO, &terminal_width, NULL);
|
||||
/* Go one less... */
|
||||
terminal_width--;
|
||||
#endif
|
||||
nfiles = 0;
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_COLOR
|
||||
if (isatty(fileno(stdout)))
|
||||
if (isatty(STDOUT_FILENO))
|
||||
show_color = 1;
|
||||
#endif
|
||||
|
||||
/* process options */
|
||||
while ((opt = getopt(argc, argv, ls_opts)) > 0) {
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
if (opt == 'T') {
|
||||
tabstops = atoi(optarg);
|
||||
continue;
|
||||
}
|
||||
if (opt == 'w') {
|
||||
terminal_width = atoi(optarg);
|
||||
continue;
|
||||
}
|
||||
if (opt == ':') {
|
||||
goto print_usage_message;
|
||||
}
|
||||
opt = bb_getopt_ulflags(argc, argv, ls_options, &tabstops_str, &terminal_width_str);
|
||||
if (tabstops_str) {
|
||||
tabstops = atoi(tabstops_str);
|
||||
}
|
||||
if (terminal_width_str) {
|
||||
terminal_width = atoi(terminal_width_str);
|
||||
}
|
||||
#else
|
||||
opt = bb_getopt_ulflags(argc, argv, ls_options);
|
||||
#endif
|
||||
{
|
||||
unsigned int flags;
|
||||
const char *p = strchr(ls_opts, opt);
|
||||
if (!p) { /* shouldn't be necessary */
|
||||
goto print_usage_message;
|
||||
}
|
||||
flags = opt_flags[(int)(p - ls_opts)];
|
||||
for (i = 0; opt_flags[i] != (1U<<31); i++) {
|
||||
if (opt & (1 << i)) {
|
||||
unsigned int flags = opt_flags[i];
|
||||
if (flags & LIST_MASK_TRIGGER) {
|
||||
all_fmt &= ~LIST_MASK;
|
||||
}
|
||||
@@ -992,7 +1037,6 @@ extern int ls_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* sort out which command line options take precedence */
|
||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||
if (all_fmt & DISP_NOLIST)
|
||||
@@ -1010,14 +1054,14 @@ extern int ls_main(int argc, char **argv)
|
||||
if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC))
|
||||
all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */
|
||||
#endif
|
||||
|
||||
|
||||
/* choose a display format */
|
||||
if ((all_fmt & STYLE_MASK) == STYLE_AUTO)
|
||||
#if STYLE_AUTO != 0
|
||||
all_fmt = (all_fmt & ~STYLE_MASK)
|
||||
| (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE);
|
||||
| (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
|
||||
#else
|
||||
all_fmt |= (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE);
|
||||
all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -1065,7 +1109,6 @@ extern int ls_main(int argc, char **argv)
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
|
||||
if (all_fmt & DISP_NOLIST) {
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
shellsort(dnp, nfiles);
|
||||
@@ -1087,11 +1130,8 @@ extern int ls_main(int argc, char **argv)
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
shellsort(dnd, dndirs);
|
||||
#endif
|
||||
showdirs(dnd, dndirs);
|
||||
showdirs(dnd, dndirs, dnfiles == 0);
|
||||
}
|
||||
}
|
||||
return (status);
|
||||
|
||||
print_usage_message:
|
||||
bb_show_usage();
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright (C) 2003 Glenn L. McGrath
|
||||
* Copyright (C) 2003-2004 Erik Andersen
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
#define FLAG_SILENT 1
|
||||
#define FLAG_CHECK 2
|
||||
#define FLAG_WARN 4
|
||||
|
||||
/* This might be useful elsewhere */
|
||||
static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
|
||||
unsigned char hash_length)
|
||||
{
|
||||
int x, len, max;
|
||||
unsigned char *hex_value;
|
||||
|
||||
max = (hash_length * 2) + 2;
|
||||
hex_value = xmalloc(max);
|
||||
for (x = len = 0; x < hash_length; x++) {
|
||||
len += snprintf((char*)(hex_value + len), max - len, "%02x", hash_value[x]);
|
||||
}
|
||||
return (hex_value);
|
||||
}
|
||||
|
||||
static uint8_t *hash_file(const char *filename, uint8_t hash_algo)
|
||||
{
|
||||
int src_fd = strcmp(filename, "-") == 0 ? STDIN_FILENO :
|
||||
open(filename, O_RDONLY);
|
||||
if (src_fd == -1) {
|
||||
bb_perror_msg("%s", filename);
|
||||
return NULL;
|
||||
} else {
|
||||
uint8_t *hash_value;
|
||||
RESERVE_CONFIG_UBUFFER(hash_value_bin, 20);
|
||||
hash_value = hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2 ?
|
||||
hash_bin_to_hex(hash_value_bin, hash_algo == HASH_MD5 ? 16 : 20) :
|
||||
NULL;
|
||||
RELEASE_CONFIG_BUFFER(hash_value_bin);
|
||||
close(src_fd);
|
||||
return hash_value;
|
||||
}
|
||||
}
|
||||
|
||||
/* This could become a common function for md5 as well, by using md5_stream */
|
||||
extern int hash_files(int argc, char **argv, const uint8_t hash_algo)
|
||||
{
|
||||
int return_value = EXIT_SUCCESS;
|
||||
uint8_t *hash_value;
|
||||
|
||||
#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
|
||||
unsigned int flags;
|
||||
|
||||
flags = bb_getopt_ulflags(argc, argv, "scw");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
|
||||
if (!(flags & FLAG_CHECK)) {
|
||||
if (flags & FLAG_SILENT) {
|
||||
bb_error_msg_and_die
|
||||
("the -s option is meaningful only when verifying checksums");
|
||||
} else if (flags & FLAG_WARN) {
|
||||
bb_error_msg_and_die
|
||||
("the -w option is meaningful only when verifying checksums");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argc == optind) {
|
||||
argv[argc++] = "-";
|
||||
}
|
||||
#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
|
||||
if (flags & FLAG_CHECK) {
|
||||
FILE *pre_computed_stream;
|
||||
int count_total = 0;
|
||||
int count_failed = 0;
|
||||
char *file_ptr = argv[optind];
|
||||
char *line;
|
||||
|
||||
if (optind + 1 != argc) {
|
||||
bb_error_msg_and_die
|
||||
("only one argument may be specified when using -c");
|
||||
}
|
||||
|
||||
if (strcmp(file_ptr, "-") == 0) {
|
||||
pre_computed_stream = stdin;
|
||||
} else {
|
||||
pre_computed_stream = bb_xfopen(file_ptr, "r");
|
||||
}
|
||||
|
||||
while ((line = bb_get_chomped_line_from_file(pre_computed_stream)) != NULL) {
|
||||
char *filename_ptr;
|
||||
|
||||
count_total++;
|
||||
filename_ptr = strstr(line, " ");
|
||||
if (filename_ptr == NULL) {
|
||||
if (flags & FLAG_WARN) {
|
||||
bb_error_msg("Invalid format");
|
||||
}
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
*filename_ptr = '\0';
|
||||
filename_ptr += 2;
|
||||
|
||||
hash_value = hash_file(filename_ptr, hash_algo);
|
||||
|
||||
if (hash_value && (strcmp((char*)hash_value, line) == 0)) {
|
||||
if (!(flags & FLAG_SILENT))
|
||||
printf("%s: OK\n", filename_ptr);
|
||||
} else {
|
||||
if (!(flags & FLAG_SILENT))
|
||||
printf("%s: FAILED\n", filename_ptr);
|
||||
count_failed++;
|
||||
return_value = EXIT_FAILURE;
|
||||
}
|
||||
/* possible free(NULL) */
|
||||
free(hash_value);
|
||||
free(line);
|
||||
}
|
||||
if (count_failed && !(flags & FLAG_SILENT)) {
|
||||
bb_error_msg("WARNING: %d of %d computed checksums did NOT match",
|
||||
count_failed, count_total);
|
||||
}
|
||||
if (bb_fclose_nonstdin(pre_computed_stream) == EOF) {
|
||||
bb_perror_msg_and_die("Couldnt close file %s", file_ptr);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
uint8_t hash_length;
|
||||
|
||||
if (hash_algo == HASH_MD5) {
|
||||
hash_length = 16;
|
||||
} else {
|
||||
hash_length = 20;
|
||||
}
|
||||
hash_value = xmalloc(hash_length);
|
||||
|
||||
while (optind < argc) {
|
||||
char *file_ptr = argv[optind++];
|
||||
|
||||
hash_value = hash_file(file_ptr, hash_algo);
|
||||
if (hash_value == NULL) {
|
||||
return_value = EXIT_FAILURE;
|
||||
} else {
|
||||
printf("%s %s\n", hash_value, file_ptr);
|
||||
free(hash_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MD5SUM
|
||||
extern int md5sum_main(int argc, char **argv)
|
||||
{
|
||||
return(hash_files(argc, argv, HASH_MD5));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SHA1SUM
|
||||
extern int sha1sum_main(int argc, char **argv)
|
||||
{
|
||||
return(hash_files(argc, argv, HASH_SHA1));
|
||||
}
|
||||
#endif
|
||||
-1102
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -50,7 +50,7 @@ extern int mknod_main(int argc, char **argv)
|
||||
dev = (bb_xgetularg10_bnd(argv[2], 0, 255) << 8)
|
||||
+ bb_xgetularg10_bnd(argv[3], 0, 255);
|
||||
}
|
||||
|
||||
|
||||
if (argc == 2) {
|
||||
name = *argv;
|
||||
if (mknod(name, mode, dev) == 0) {
|
||||
|
||||
+30
-34
@@ -41,7 +41,6 @@ static const struct option mv_long_options[] = {
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static const char mv_getopt_short_option[] = "fi";
|
||||
#define OPT_FILEUTILS_FORCE 1
|
||||
#define OPT_FILEUTILS_INTERACTIVE 2
|
||||
|
||||
@@ -49,21 +48,19 @@ static const char fmt[] = "cannot overwrite %sdirectory with %sdirectory";
|
||||
|
||||
extern int mv_main(int argc, char **argv)
|
||||
{
|
||||
struct stat source_stat;
|
||||
struct stat dest_stat;
|
||||
const char *last;
|
||||
const char *dest;
|
||||
int dest_exists;
|
||||
int source_exists;
|
||||
unsigned long flags;
|
||||
int dest_exists;
|
||||
int status = 0;
|
||||
|
||||
bb_applet_long_options = mv_long_options;
|
||||
bb_opt_complementaly = "f-i:i-f";
|
||||
flags = bb_getopt_ulflags(argc, argv, mv_getopt_short_option);
|
||||
|
||||
if (optind + 2 > argc)
|
||||
flags = bb_getopt_ulflags(argc, argv, "fi");
|
||||
if (optind + 2 > argc) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
last = argv[argc - 1];
|
||||
argv += optind;
|
||||
@@ -78,7 +75,7 @@ extern int mv_main(int argc, char **argv)
|
||||
goto DO_MOVE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
dest = concat_path_file(last, bb_get_last_path_component(*argv));
|
||||
|
||||
@@ -86,30 +83,34 @@ extern int mv_main(int argc, char **argv)
|
||||
goto RET_1;
|
||||
}
|
||||
|
||||
DO_MOVE:
|
||||
|
||||
DO_MOVE:
|
||||
|
||||
if (dest_exists && !(flags & OPT_FILEUTILS_FORCE) &&
|
||||
((access(dest, W_OK) < 0 && isatty(0)) ||
|
||||
(flags & OPT_FILEUTILS_INTERACTIVE))) {
|
||||
if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) {
|
||||
goto RET_1; /* Ouch! fprintf failed! */
|
||||
}
|
||||
if (!bb_ask_confirmation())
|
||||
goto RET_0;
|
||||
}
|
||||
|
||||
(flags & OPT_FILEUTILS_INTERACTIVE))) {
|
||||
if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) {
|
||||
goto RET_1; /* Ouch! fprintf failed! */
|
||||
}
|
||||
if (!bb_ask_confirmation()) {
|
||||
goto RET_0;
|
||||
}
|
||||
}
|
||||
if (rename(*argv, dest) < 0) {
|
||||
if (errno != EXDEV) {
|
||||
struct stat source_stat;
|
||||
int source_exists;
|
||||
|
||||
if (errno != EXDEV ||
|
||||
(source_exists = cp_mv_stat(*argv, &source_stat)) < 1) {
|
||||
bb_perror_msg("unable to rename `%s'", *argv);
|
||||
} else if ((source_exists = cp_mv_stat(*argv, &source_stat)) >= 0) {
|
||||
} else {
|
||||
if (dest_exists) {
|
||||
if (dest_exists & 2) {
|
||||
if (!(source_exists & 2)) {
|
||||
if (dest_exists == 3) {
|
||||
if (source_exists != 3) {
|
||||
bb_error_msg(fmt, "", "non-");
|
||||
goto RET_1;
|
||||
}
|
||||
} else {
|
||||
if (source_exists & 2) {
|
||||
if (source_exists == 3) {
|
||||
bb_error_msg(fmt, "non-", "");
|
||||
goto RET_1;
|
||||
}
|
||||
@@ -119,25 +120,20 @@ extern int mv_main(int argc, char **argv)
|
||||
goto RET_1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((copy_file(*argv, dest,
|
||||
FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0)
|
||||
&& (remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)
|
||||
) {
|
||||
FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) &&
|
||||
(remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) {
|
||||
goto RET_0;
|
||||
}
|
||||
|
||||
}
|
||||
RET_1:
|
||||
RET_1:
|
||||
status = 1;
|
||||
}
|
||||
|
||||
RET_0:
|
||||
RET_0:
|
||||
if (dest != last) {
|
||||
free((void *) dest);
|
||||
}
|
||||
|
||||
} while (*++argv != last);
|
||||
|
||||
exit(status);
|
||||
|
||||
return (status);
|
||||
}
|
||||
+5
-5
@@ -155,13 +155,13 @@ static const char * const add_strings[] = {
|
||||
"4/4 \" %011o \" \"\\n\"", /* O */
|
||||
};
|
||||
|
||||
static const signed char od_opts[] = "aBbcDdeFfHhIiLlOovXx";
|
||||
static const signed char od_opts[] = "aBbcDdeFfHhIiLlOoXxv";
|
||||
|
||||
static const signed char od_o2si[] = {
|
||||
0, 1, 2, 3, 5,
|
||||
4, 6, 6, 7, 8,
|
||||
9, 0xa, 0xb, 0xa, 0xa,
|
||||
0xb, 1, -1, 8, 9,
|
||||
0xb, 1, 8, 9,
|
||||
};
|
||||
|
||||
int od_main(int argc, char **argv)
|
||||
@@ -173,7 +173,9 @@ int od_main(int argc, char **argv)
|
||||
bb_dump_length = -1;
|
||||
|
||||
while ((ch = getopt(argc, argv, od_opts)) > 0) {
|
||||
if (((p = strchr(od_opts, ch)) != NULL) && (*p >= 0)) {
|
||||
if (ch == 'v') {
|
||||
bb_dump_vflag = ALL;
|
||||
} else if (((p = strchr(od_opts, ch)) != NULL) && (*p >= 0)) {
|
||||
if (first) {
|
||||
first = 0;
|
||||
bb_dump_add("\"%07.7_Ao\n\"");
|
||||
@@ -182,8 +184,6 @@ int od_main(int argc, char **argv)
|
||||
bb_dump_add("\" \"");
|
||||
}
|
||||
bb_dump_add(add_strings[od_o2si[(int)(p-od_opts)]]);
|
||||
} else if (ch == 'v') {
|
||||
bb_dump_vflag = ALL;
|
||||
} else { /* P, p, s, w, or other unhandled */
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
+26
-162
@@ -58,68 +58,19 @@
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
#ifndef S_IFMT
|
||||
static const int S_IFMT = 0170000;
|
||||
#endif
|
||||
#if !defined(S_ISBLK) && defined(S_IFBLK)
|
||||
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
#endif
|
||||
#if !defined(S_ISCHR) && defined(S_IFCHR)
|
||||
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
#endif
|
||||
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
#if !defined(S_ISFIFO) && defined(S_IFIFO)
|
||||
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
#endif
|
||||
#if !defined(S_ISLNK) && defined(S_IFLNK)
|
||||
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
||||
#endif
|
||||
#if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
||||
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
#endif
|
||||
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
||||
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
||||
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
||||
#endif
|
||||
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
||||
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
||||
#endif
|
||||
|
||||
#define IN_CTYPE_DOMAIN(c) 1
|
||||
|
||||
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
|
||||
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
|
||||
#define ISDIGIT(c) (((unsigned char) (c)) - '0' <= 9)
|
||||
|
||||
#define isodigit(c) ((c) >= '0' && (c) <= '7')
|
||||
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
|
||||
#define octtobin(c) ((c) - '0')
|
||||
|
||||
static double xstrtod __P((char *s));
|
||||
static int print_esc __P((char *escstart));
|
||||
static int print_formatted __P((char *format, int argc, char **argv));
|
||||
static long xstrtol __P((char *s));
|
||||
static unsigned long xstrtoul __P((char *s));
|
||||
static void print_direc __P( (char *start, size_t length,
|
||||
int field_width, int precision, char *argument));
|
||||
static void print_esc_char __P((int c));
|
||||
static void print_esc_string __P((char *str));
|
||||
|
||||
/* The value to return to the calling program. */
|
||||
static int exit_status;
|
||||
static int print_formatted __P((char *format, int argc, char **argv));
|
||||
static void print_direc __P( (char *start, size_t length,
|
||||
int field_width, int precision, char *argument));
|
||||
|
||||
int printf_main(int argc, char **argv)
|
||||
{
|
||||
char *format;
|
||||
int args_used;
|
||||
|
||||
exit_status = 0;
|
||||
if (argc <= 1 || **(argv + 1) == '-') {
|
||||
bb_show_usage();
|
||||
}
|
||||
@@ -140,7 +91,7 @@ int printf_main(int argc, char **argv)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
return(exit_status);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
@@ -188,7 +139,7 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
} else
|
||||
field_width = 0;
|
||||
} else
|
||||
while (ISDIGIT(*f)) {
|
||||
while (isdigit(*f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
@@ -205,7 +156,7 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
} else
|
||||
precision = 0;
|
||||
} else
|
||||
while (ISDIGIT(*f)) {
|
||||
while (isdigit(*f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
@@ -214,7 +165,7 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
/*
|
||||
/*
|
||||
if (!strchr ("diouxXfeEgGcs", *f))
|
||||
fprintf(stderr, "%%%c: invalid directive", *f);
|
||||
*/
|
||||
@@ -230,7 +181,10 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
f += print_esc(f);
|
||||
if (*++f == 'c')
|
||||
exit(0);
|
||||
putchar(bb_process_escape_sequence((const char **)&f));
|
||||
f--;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -241,84 +195,6 @@ static int print_formatted(char *format, int argc, char **argv)
|
||||
return save_argc - argc;
|
||||
}
|
||||
|
||||
/* Print a \ escape sequence starting at ESCSTART.
|
||||
Return the number of characters in the escape sequence
|
||||
besides the backslash. */
|
||||
|
||||
static int print_esc(char *escstart)
|
||||
{
|
||||
register char *p = escstart + 1;
|
||||
int esc_value = 0; /* Value of \nnn escape. */
|
||||
int esc_length; /* Length of \nnn escape. */
|
||||
|
||||
/* \0ooo and \xhhh escapes have maximum length of 3 chars. */
|
||||
if (*p == 'x') {
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && ISXDIGIT(*p); ++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin(*p);
|
||||
/* if (esc_length == 0)
|
||||
fprintf(stderr, "missing hex in esc");
|
||||
*/
|
||||
putchar(esc_value);
|
||||
} else if (*p == '0') {
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && isodigit(*p); ++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin(*p);
|
||||
putchar(esc_value);
|
||||
} else if (strchr("\"\\abcfnrtv", *p))
|
||||
print_esc_char(*p++);
|
||||
/* else
|
||||
fprintf(stderr, "\\%c: invalid esc", *p);
|
||||
*/
|
||||
return p - escstart - 1;
|
||||
}
|
||||
|
||||
/* Output a single-character \ escape. */
|
||||
|
||||
static void print_esc_char(int c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'a': /* Alert. */
|
||||
putchar(7);
|
||||
break;
|
||||
case 'b': /* Backspace. */
|
||||
putchar(8);
|
||||
break;
|
||||
case 'c': /* Cancel the rest of the output. */
|
||||
exit(0);
|
||||
break;
|
||||
case 'f': /* Form feed. */
|
||||
putchar(12);
|
||||
break;
|
||||
case 'n': /* New line. */
|
||||
putchar(10);
|
||||
break;
|
||||
case 'r': /* Carriage return. */
|
||||
putchar(13);
|
||||
break;
|
||||
case 't': /* Horizontal tab. */
|
||||
putchar(9);
|
||||
break;
|
||||
case 'v': /* Vertical tab. */
|
||||
putchar(11);
|
||||
break;
|
||||
default:
|
||||
putchar(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print string STR, evaluating \ escapes. */
|
||||
|
||||
static void print_esc_string(char *str)
|
||||
{
|
||||
for (; *str; str++)
|
||||
if (*str == '\\')
|
||||
str += print_esc(str);
|
||||
else
|
||||
putchar(*str);
|
||||
}
|
||||
|
||||
static void
|
||||
print_direc(char *start, size_t length, int field_width, int precision,
|
||||
char *argument)
|
||||
@@ -405,48 +281,36 @@ print_direc(char *start, size_t length, int field_width, int precision,
|
||||
static unsigned long xstrtoul(char *arg)
|
||||
{
|
||||
unsigned long result;
|
||||
char *endptr;
|
||||
//int errno_save = errno;
|
||||
|
||||
assert(arg!=NULL);
|
||||
|
||||
errno = 0;
|
||||
result = strtoul(arg, &endptr, 10);
|
||||
if (errno != 0 || *endptr!='\0' || endptr==arg)
|
||||
if (safe_strtoul(arg, &result))
|
||||
fprintf(stderr, "%s", arg);
|
||||
//errno = errno_save;
|
||||
return result;
|
||||
}
|
||||
|
||||
static long xstrtol(char *arg)
|
||||
{
|
||||
long result;
|
||||
char *endptr;
|
||||
//int errno_save = errno;
|
||||
|
||||
assert(arg!=NULL);
|
||||
|
||||
errno = 0;
|
||||
result = strtoul(arg, &endptr, 10);
|
||||
if (errno != 0 || *endptr!='\0' || endptr==arg)
|
||||
if (safe_strtol(arg, &result))
|
||||
fprintf(stderr, "%s", arg);
|
||||
//errno = errno_save;
|
||||
return result;
|
||||
}
|
||||
|
||||
static double xstrtod(char *arg)
|
||||
{
|
||||
double result;
|
||||
char *endptr;
|
||||
//int errno_save = errno;
|
||||
|
||||
assert(arg!=NULL);
|
||||
|
||||
errno = 0;
|
||||
result = strtod(arg, &endptr);
|
||||
if (errno != 0 || *endptr!='\0' || endptr==arg)
|
||||
if (safe_strtod(arg, &result))
|
||||
fprintf(stderr, "%s", arg);
|
||||
//errno = errno_save;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void print_esc_string(char *str)
|
||||
{
|
||||
for (; *str; str++) {
|
||||
if (*str == '\\') {
|
||||
str++;
|
||||
putchar(bb_process_escape_sequence((const char **)&str));
|
||||
} else {
|
||||
putchar(*str);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loaded 100 of 627 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user