Compare commits
153
Commits
1_8_stable
...
1_9_2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
150ed1d171 | ||
|
|
a8e183a577 | ||
|
|
77d390dc70 | ||
|
|
d4394120f7 | ||
|
|
a68cb75a2e | ||
|
|
0b18cd3d04 | ||
|
|
aeb725e185 | ||
|
|
4e9b8ea910 | ||
|
|
299c5c379e | ||
|
|
3b4921674e | ||
|
|
f7be20e70c | ||
|
|
fcfb5c04bb | ||
|
|
e4bc603f0b | ||
|
|
ef36c04ccf | ||
|
|
f882f08627 | ||
|
|
528a8b9769 | ||
|
|
4baed3a080 | ||
|
|
e3cbfb91d2 | ||
|
|
94e3365b8f | ||
|
|
88adfcd178 | ||
|
|
ee87ebf381 | ||
|
|
26b6fba9d3 | ||
|
|
619879246d | ||
|
|
fff145dba3 | ||
|
|
f77f369ce8 | ||
|
|
c794c51a1a | ||
|
|
0163111325 | ||
|
|
9ad2cb3f1a | ||
|
|
4ca2965b99 | ||
|
|
2cd4a747e5 | ||
|
|
d7e2e127a9 | ||
|
|
2afabe8b83 | ||
|
|
191836845e | ||
|
|
75aa615bef | ||
|
|
9cb220be9d | ||
|
|
a96425fe82 | ||
|
|
b851c42a14 | ||
|
|
f3fca91e9f | ||
|
|
c689fcfdb0 | ||
|
|
5f934b0785 | ||
|
|
d0bbbdcd6e | ||
|
|
7221c8c22d | ||
|
|
2bec513996 | ||
|
|
7ab3699b58 | ||
|
|
ab801874f8 | ||
|
|
8003e266ed | ||
|
|
8723a94c25 | ||
|
|
5cb40bbbd3 | ||
|
|
4c13922961 | ||
|
|
e2532ab5f2 | ||
|
|
1796e2c495 | ||
|
|
6672c8e480 | ||
|
|
b539c8452f | ||
|
|
64309f8669 | ||
|
|
745cd17926 | ||
|
|
c253778de9 | ||
|
|
35ff74676b | ||
|
|
41f5add965 | ||
|
|
1aa7e477b1 | ||
|
|
79c6904faf | ||
|
|
186c2b3d0e | ||
|
|
30297a5b83 | ||
|
|
bd9a48bc9c | ||
|
|
4e1e720523 | ||
|
|
ed270a5f32 | ||
|
|
b1bac0dab2 | ||
|
|
a09300a88c | ||
|
|
7c9d533a85 | ||
|
|
6446c2d4ab | ||
|
|
72e76044cf | ||
|
|
a8875efa85 | ||
|
|
dd8bbfd084 | ||
|
|
fe5e23bf75 | ||
|
|
c3c6659f12 | ||
|
|
d2023283ac | ||
|
|
1da0ad13fb | ||
|
|
96702ca945 | ||
|
|
8ec6ee47f1 | ||
|
|
5bc593ccb8 | ||
|
|
cccdc4e01a | ||
|
|
835068637e | ||
|
|
f962a0354e | ||
|
|
f23c3f95e8 | ||
|
|
fff9b699f1 | ||
|
|
3831c91c95 | ||
|
|
e85dbae389 | ||
|
|
ff2b6d2185 | ||
|
|
6884f665bd | ||
|
|
68af8e7a08 | ||
|
|
b559105cfb | ||
|
|
7d75a96b15 | ||
|
|
705eaf8b40 | ||
|
|
9cdfd14223 | ||
|
|
223bc97f61 | ||
|
|
c881c733bb | ||
|
|
ed6a49c657 | ||
|
|
2a587df80a | ||
|
|
49d15890e0 | ||
|
|
e13bd362e3 | ||
|
|
dbd18f639c | ||
|
|
70ab28f907 | ||
|
|
fbe5f39f0f | ||
|
|
16aec39ebe | ||
|
|
8512862163 | ||
|
|
7e3a5f58bc | ||
|
|
7c2db5c198 | ||
|
|
a702457eac | ||
|
|
e8979889b4 | ||
|
|
01cd9570c7 | ||
|
|
a6899c3587 | ||
|
|
6d38dc3af4 | ||
|
|
f430cdbf2e | ||
|
|
1fe4e9e573 | ||
|
|
ae6bf96659 | ||
|
|
9d6c46955f | ||
|
|
8d0a734d91 | ||
|
|
3d461676a9 | ||
|
|
a89d50fb9a | ||
|
|
130f559f4d | ||
|
|
05c8c4f745 | ||
|
|
72cc9641f8 | ||
|
|
40276648ab | ||
|
|
6df9e3c9a3 | ||
|
|
059c91711f | ||
|
|
4bfb84db4e | ||
|
|
e5569cb52e | ||
|
|
40702dac93 | ||
|
|
f6ccc62c70 | ||
|
|
5cc6459c46 | ||
|
|
73cb1fdfea | ||
|
|
e7fca5125a | ||
|
|
b4f608d8e0 | ||
|
|
d031b203c7 | ||
|
|
9bd8d0c23e | ||
|
|
599bbfbd9b | ||
|
|
abbd363261 | ||
|
|
53bd4015aa | ||
|
|
459a2ba1ef | ||
|
|
49cce2b838 | ||
|
|
6e1b62b18c | ||
|
|
a29a5e40ae | ||
|
|
cb12cb2407 | ||
|
|
5281630229 | ||
|
|
6bef3d1d22 | ||
|
|
1bec1b980e | ||
|
|
cd0fbb5e77 | ||
|
|
ef66d75704 | ||
|
|
018b155ad9 | ||
|
|
cb981638f5 | ||
|
|
f8b21d0933 | ||
|
|
15c3885688 | ||
|
|
9fcd799b98 | ||
|
|
3a3e50e3db |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 8
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 9
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
@@ -928,6 +928,8 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
|
||||
include/autoconf.h \
|
||||
include/bbconfigopts.h \
|
||||
include/usage_compressed.h \
|
||||
include/applet_tables.h \
|
||||
applets/usage \
|
||||
.kernelrelease Module.symvers tags TAGS cscope*
|
||||
|
||||
# clean - Delete most, but leave enough to build external modules
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ objsizes: busybox_unstripped
|
||||
|
||||
.PHONY: stksizes
|
||||
stksizes: busybox_unstripped
|
||||
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH)
|
||||
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq
|
||||
|
||||
.PHONY: bigdata
|
||||
bigdata: busybox_unstripped
|
||||
|
||||
+2
-1
@@ -97,4 +97,5 @@ endif
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
# TODO: use "make stksizes" to find & fix big stack users
|
||||
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
|
||||
FLTFLAGS += -s 20000
|
||||
# Reduced from 20k to 16k in 1.9.0.
|
||||
FLTFLAGS += -s 16000
|
||||
+2
-3
@@ -16,7 +16,6 @@ help:
|
||||
@echo 'Configuration:'
|
||||
@echo ' allnoconfig - disable all symbols in .config'
|
||||
@echo ' allyesconfig - enable all symbols in .config (see defconfig)'
|
||||
@echo ' allbareconfig - enable all applets without any sub-features'
|
||||
@echo ' config - text based configurator (of last resort)'
|
||||
@echo ' defconfig - set .config to largest generic configuration'
|
||||
@echo ' menuconfig - interactive curses-based configurator'
|
||||
@@ -24,10 +23,10 @@ help:
|
||||
@echo ' hosttools - build sed for the host.'
|
||||
@echo ' You can use these commands if the commands on the host'
|
||||
@echo ' is unusable. Afterwards use it like:'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo
|
||||
@echo 'Installation:'
|
||||
@echo ' install - install busybox into $(CONFIG_PREFIX)'
|
||||
@echo ' install - install busybox into CONFIG_PREFIX'
|
||||
@echo ' uninstall'
|
||||
@echo
|
||||
@echo 'Development:'
|
||||
|
||||
@@ -22,12 +22,9 @@ Rob Landley <rob@landley.net>:
|
||||
The command shell situation is a big mess. We have three or four different
|
||||
shells that don't really share any code, and the "standalone shell" doesn't
|
||||
work all that well (especially not in a chroot environment), due to apps not
|
||||
being reentrant. I'm writing a new shell (bbsh) to unify the various
|
||||
shells and configurably add the minimal set of bash features people
|
||||
actually use. The hardest part is it has to configure down as small as
|
||||
lash while providing lash's features. The rest is easy in comparison.
|
||||
bzip2
|
||||
Compression-side support.
|
||||
being reentrant.
|
||||
lash is phased out. hush can be configured down to be nearly as small,
|
||||
but less buggy :)
|
||||
init
|
||||
General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
|
||||
depmod
|
||||
@@ -35,8 +32,6 @@ Rob Landley <rob@landley.net>:
|
||||
use of the depmod.pl (perl is to bloated for most embedded setups) and or orig
|
||||
modutils. The orig depmod is rather pointless to have to add to a firmware image
|
||||
in when we already have a insmod/rmmod and friends.
|
||||
Unify base64 handling.
|
||||
[done]
|
||||
Do a SUSv3 audit
|
||||
Look at the full Single Unix Specification version 3 (available online at
|
||||
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
|
||||
|
||||
+132
-66
@@ -1,11 +1,7 @@
|
||||
# This .config compiles for NOMMU.
|
||||
# TODO:
|
||||
# Pick disabled applet, enable & try to make it compile & work on NOMMU
|
||||
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.6.0.svn
|
||||
# Wed Apr 11 01:29:04 2007
|
||||
# Busybox version: 1.9.0.svn
|
||||
# Mon Dec 24 14:21:28 2007
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -16,9 +12,9 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
#
|
||||
# General Configuration
|
||||
#
|
||||
# CONFIG_NITPICK is not set
|
||||
# CONFIG_DESKTOP is not set
|
||||
# CONFIG_FEATURE_BUFFERS_USE_MALLOC is not set
|
||||
CONFIG_NITPICK=y
|
||||
CONFIG_DESKTOP=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
CONFIG_SHOW_USAGE=y
|
||||
@@ -31,23 +27,22 @@ CONFIG_FEATURE_DEVPTS=y
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
CONFIG_FEATURE_PIDFILE=y
|
||||
CONFIG_FEATURE_SUID=y
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_SUID_CONFIG is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
CONFIG_FEATURE_SUID_CONFIG=y
|
||||
CONFIG_FEATURE_SUID_CONFIG_QUIET=y
|
||||
# CONFIG_SELINUX is not set
|
||||
CONFIG_FEATURE_PREFER_APPLETS=y
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
CONFIG_FEATURE_HAVE_RPC=y
|
||||
|
||||
#
|
||||
# Build Options
|
||||
#
|
||||
# CONFIG_STATIC is not set
|
||||
# CONFIG_BUILD_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_INDIVIDUAL is not set
|
||||
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
|
||||
CONFIG_LFS=y
|
||||
# CONFIG_BUILD_AT_ONCE is not set
|
||||
|
||||
#
|
||||
# Debugging Options
|
||||
@@ -65,7 +60,11 @@ CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_INSTALL_NO_USR is not set
|
||||
CONFIG_INSTALL_APPLET_SYMLINKS=y
|
||||
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
|
||||
# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
|
||||
# CONFIG_INSTALL_APPLET_DONT is not set
|
||||
# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
|
||||
# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
|
||||
# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
|
||||
CONFIG_PREFIX="./_install"
|
||||
|
||||
#
|
||||
@@ -73,14 +72,20 @@ CONFIG_PREFIX="./_install"
|
||||
#
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SIZE_VS_SPEED=2
|
||||
# CONFIG_FEATURE_FAST_TOP is not set
|
||||
# CONFIG_FEATURE_ETC_NETWORKS is not set
|
||||
CONFIG_FEATURE_EDITING=y
|
||||
CONFIG_FEATURE_EDITING_MAX_LEN=1024
|
||||
# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set
|
||||
# CONFIG_FEATURE_EDITING_VI is not set
|
||||
CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
# CONFIG_FEATURE_EDITING_SAVEHISTORY is not set
|
||||
# CONFIG_FEATURE_TAB_COMPLETION is not set
|
||||
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
|
||||
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
|
||||
CONFIG_FEATURE_TAB_COMPLETION=y
|
||||
CONFIG_FEATURE_USERNAME_COMPLETION=y
|
||||
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
|
||||
CONFIG_FEATURE_COPYBUF_KB=4
|
||||
CONFIG_MONOTONIC_SYSCALL=y
|
||||
CONFIG_IOCTL_HEX2STR_ERROR=y
|
||||
|
||||
#
|
||||
# Applets
|
||||
@@ -92,23 +97,26 @@ CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
# CONFIG_DPKG is not set
|
||||
# CONFIG_DPKG_DEB is not set
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
|
||||
CONFIG_GZIP=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
# CONFIG_RPM is not set
|
||||
CONFIG_RPM=y
|
||||
CONFIG_FEATURE_RPM_BZ2=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
# CONFIG_FEATURE_TAR_BZIP2 is not set
|
||||
# CONFIG_FEATURE_TAR_LZMA is not set
|
||||
CONFIG_FEATURE_TAR_BZIP2=y
|
||||
CONFIG_FEATURE_TAR_LZMA=y
|
||||
CONFIG_FEATURE_TAR_FROM=y
|
||||
# CONFIG_FEATURE_TAR_GZIP is not set
|
||||
# CONFIG_FEATURE_TAR_COMPRESS is not set
|
||||
CONFIG_FEATURE_TAR_GZIP=y
|
||||
CONFIG_FEATURE_TAR_COMPRESS=y
|
||||
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
@@ -120,9 +128,13 @@ CONFIG_UNZIP=y
|
||||
# Common options for cpio and tar
|
||||
#
|
||||
CONFIG_FEATURE_UNARCHIVE_TAPE=y
|
||||
# CONFIG_FEATURE_DEB_TAR_GZ is not set
|
||||
# CONFIG_FEATURE_DEB_TAR_BZ2 is not set
|
||||
# CONFIG_FEATURE_DEB_TAR_LZMA is not set
|
||||
|
||||
#
|
||||
# Common options for dpkg and dpkg_deb
|
||||
#
|
||||
CONFIG_FEATURE_DEB_TAR_GZ=y
|
||||
CONFIG_FEATURE_DEB_TAR_BZ2=y
|
||||
CONFIG_FEATURE_DEB_TAR_LZMA=y
|
||||
|
||||
#
|
||||
# Coreutils
|
||||
@@ -136,7 +148,6 @@ CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_CUT=y
|
||||
@@ -146,10 +157,7 @@ CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_FEATURE_DF_INODE=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
@@ -159,6 +167,8 @@ CONFIG_ECHO=y
|
||||
CONFIG_FEATURE_FANCY_ECHO=y
|
||||
CONFIG_ENV=y
|
||||
CONFIG_FEATURE_ENV_LONG_OPTIONS=y
|
||||
CONFIG_EXPAND=y
|
||||
CONFIG_FEATURE_EXPAND_LONG_OPTIONS=y
|
||||
CONFIG_EXPR=y
|
||||
CONFIG_EXPR_MATH_SUPPORT_64=y
|
||||
CONFIG_FALSE=y
|
||||
@@ -194,6 +204,8 @@ CONFIG_OD=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PRINTF=y
|
||||
CONFIG_PWD=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_FEATURE_READLINK_FOLLOW=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_RM=y
|
||||
CONFIG_RMDIR=y
|
||||
@@ -223,11 +235,12 @@ CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNEXPAND=y
|
||||
CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS=y
|
||||
CONFIG_UNIQ=y
|
||||
CONFIG_USLEEP=y
|
||||
CONFIG_UUDECODE=y
|
||||
CONFIG_UUENCODE=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_WC=y
|
||||
CONFIG_FEATURE_WC_LARGE=y
|
||||
CONFIG_WHO=y
|
||||
@@ -261,6 +274,7 @@ CONFIG_CHVT=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_DEALLOCVT=y
|
||||
CONFIG_DUMPKMAP=y
|
||||
CONFIG_KBD_MODE=y
|
||||
CONFIG_LOADFONT=y
|
||||
CONFIG_LOADKMAP=y
|
||||
CONFIG_OPENVT=y
|
||||
@@ -277,14 +291,12 @@ CONFIG_SETLOGCONS=y
|
||||
#
|
||||
CONFIG_MKTEMP=y
|
||||
CONFIG_PIPE_PROGRESS=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_FEATURE_READLINK_FOLLOW=y
|
||||
CONFIG_RUN_PARTS=y
|
||||
CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_RUN_PARTS_FANCY=y
|
||||
# CONFIG_START_STOP_DAEMON is not set
|
||||
# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
|
||||
# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
|
||||
CONFIG_START_STOP_DAEMON=y
|
||||
CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y
|
||||
CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y
|
||||
CONFIG_WHICH=y
|
||||
|
||||
#
|
||||
@@ -292,10 +304,17 @@ CONFIG_WHICH=y
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_MATH=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_MAX_LEN=4096
|
||||
# CONFIG_FEATURE_VI_8BIT is not set
|
||||
CONFIG_FEATURE_VI_COLON=y
|
||||
CONFIG_FEATURE_VI_YANKMARK=y
|
||||
CONFIG_FEATURE_VI_SEARCH=y
|
||||
@@ -318,6 +337,7 @@ CONFIG_FEATURE_FIND_MMIN=y
|
||||
CONFIG_FEATURE_FIND_PERM=y
|
||||
CONFIG_FEATURE_FIND_TYPE=y
|
||||
CONFIG_FEATURE_FIND_XDEV=y
|
||||
CONFIG_FEATURE_FIND_MAXDEPTH=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
@@ -328,6 +348,10 @@ CONFIG_FEATURE_FIND_DEPTH=y
|
||||
CONFIG_FEATURE_FIND_PAREN=y
|
||||
CONFIG_FEATURE_FIND_SIZE=y
|
||||
CONFIG_FEATURE_FIND_PRUNE=y
|
||||
CONFIG_FEATURE_FIND_DELETE=y
|
||||
CONFIG_FEATURE_FIND_PATH=y
|
||||
CONFIG_FEATURE_FIND_REGEX=y
|
||||
# CONFIG_FEATURE_FIND_CONTEXT is not set
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
@@ -361,16 +385,21 @@ CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_ADDGROUP=y
|
||||
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
|
||||
CONFIG_DELGROUP=y
|
||||
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y
|
||||
CONFIG_ADDUSER=y
|
||||
CONFIG_DELUSER=y
|
||||
CONFIG_GETTY=y
|
||||
CONFIG_FEATURE_UTMP=y
|
||||
CONFIG_FEATURE_WTMP=y
|
||||
CONFIG_LOGIN=y
|
||||
# CONFIG_PAM is not set
|
||||
CONFIG_LOGIN_SCRIPTS=y
|
||||
# CONFIG_FEATURE_NOLOGIN is not set
|
||||
CONFIG_FEATURE_SECURETTY=y
|
||||
CONFIG_PASSWD=y
|
||||
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
|
||||
CONFIG_CRYPTPW=y
|
||||
CONFIG_CHPASSWD=y
|
||||
CONFIG_SU=y
|
||||
CONFIG_FEATURE_SU_SYSLOG=y
|
||||
CONFIG_FEATURE_SU_CHECKS_SHELLS=y
|
||||
@@ -436,6 +465,8 @@ CONFIG_MKFS_MINIX=y
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_HEXDUMP=y
|
||||
CONFIG_HD=y
|
||||
CONFIG_FEATURE_HEXDUMP_REVERSE=y
|
||||
CONFIG_HWCLOCK=y
|
||||
CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
|
||||
@@ -445,12 +476,14 @@ CONFIG_LOSETUP=y
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_V0=y
|
||||
CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_MOUNT=y
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
CONFIG_FEATURE_MOUNT_HELPERS=y
|
||||
CONFIG_FEATURE_MOUNT_NFS=y
|
||||
CONFIG_FEATURE_MOUNT_CIFS=y
|
||||
CONFIG_FEATURE_MOUNT_FLAGS=y
|
||||
CONFIG_FEATURE_MOUNT_FSTAB=y
|
||||
@@ -504,25 +537,27 @@ CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
|
||||
CONFIG_MAKEDEVS=y
|
||||
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
|
||||
CONFIG_FEATURE_MAKEDEVS_TABLE=y
|
||||
CONFIG_MICROCOM=y
|
||||
CONFIG_MOUNTPOINT=y
|
||||
CONFIG_MT=y
|
||||
CONFIG_NMETER=y
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
CONFIG_READAHEAD=y
|
||||
CONFIG_RUNLEVEL=y
|
||||
CONFIG_RX=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_SETSID=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_TASKSET=y
|
||||
CONFIG_FEATURE_TASKSET_FANCY=y
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
# Networking Utilities
|
||||
#
|
||||
CONFIG_FEATURE_IPV6=y
|
||||
# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
|
||||
CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
|
||||
CONFIG_VERBOSE_RESOLUTION_ERRORS=y
|
||||
CONFIG_ARP=y
|
||||
CONFIG_ARPING=y
|
||||
CONFIG_DNSD=y
|
||||
@@ -532,16 +567,20 @@ CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
CONFIG_HOSTNAME=y
|
||||
# CONFIG_HTTPD is not set
|
||||
# CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP is not set
|
||||
# CONFIG_FEATURE_HTTPD_SETUID is not set
|
||||
# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
|
||||
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
|
||||
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES is not set
|
||||
# CONFIG_FEATURE_HTTPD_CGI is not set
|
||||
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
|
||||
# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
|
||||
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
CONFIG_FEATURE_HTTPD_AUTH_MD5=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES=y
|
||||
CONFIG_FEATURE_HTTPD_CGI=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
|
||||
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
|
||||
CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y
|
||||
CONFIG_FEATURE_HTTPD_ERROR_PAGES=y
|
||||
CONFIG_FEATURE_HTTPD_PROXY=y
|
||||
CONFIG_IFCONFIG=y
|
||||
CONFIG_FEATURE_IFCONFIG_STATUS=y
|
||||
CONFIG_FEATURE_IFCONFIG_SLIP=y
|
||||
@@ -549,13 +588,14 @@ CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
|
||||
CONFIG_FEATURE_IFCONFIG_HW=y
|
||||
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
|
||||
# CONFIG_IFUPDOWN is not set
|
||||
CONFIG_IFUPDOWN_IFSTATE_PATH=""
|
||||
# CONFIG_FEATURE_IFUPDOWN_IP is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPX is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
|
||||
# CONFIG_INETD is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
|
||||
@@ -570,6 +610,7 @@ CONFIG_FEATURE_IP_ROUTE=y
|
||||
CONFIG_FEATURE_IP_TUNNEL=y
|
||||
CONFIG_FEATURE_IP_RULE=y
|
||||
CONFIG_FEATURE_IP_SHORT_FORMS=y
|
||||
CONFIG_FEATURE_IP_RARE_PROTOCOLS=y
|
||||
CONFIG_IPADDR=y
|
||||
CONFIG_IPLINK=y
|
||||
CONFIG_IPROUTE=y
|
||||
@@ -579,35 +620,42 @@ CONFIG_IPCALC=y
|
||||
CONFIG_FEATURE_IPCALC_FANCY=y
|
||||
CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
|
||||
CONFIG_NAMEIF=y
|
||||
CONFIG_FEATURE_NAMEIF_EXTENDED=y
|
||||
CONFIG_NC=y
|
||||
CONFIG_NC_SERVER=y
|
||||
CONFIG_NC_EXTRA=y
|
||||
CONFIG_NETSTAT=y
|
||||
CONFIG_FEATURE_NETSTAT_WIDE=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
CONFIG_ROUTE=y
|
||||
CONFIG_SLATTACH=y
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
# CONFIG_TELNETD is not set
|
||||
# CONFIG_FEATURE_TELNETD_STANDALONE is not set
|
||||
CONFIG_TELNETD=y
|
||||
CONFIG_FEATURE_TELNETD_STANDALONE=y
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
# CONFIG_DEBUG_TFTP is not set
|
||||
CONFIG_TRACEROUTE=y
|
||||
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
|
||||
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
|
||||
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
|
||||
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
|
||||
CONFIG_APP_UDHCPD=y
|
||||
CONFIG_APP_DHCPRELAY=y
|
||||
CONFIG_APP_DUMPLEASES=y
|
||||
# CONFIG_APP_UDHCPC is not set
|
||||
# CONFIG_FEATURE_UDHCP_DEBUG is not set
|
||||
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
|
||||
CONFIG_APP_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCP_DEBUG=y
|
||||
CONFIG_FEATURE_RFC3397=y
|
||||
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
|
||||
CONFIG_VCONFIG=y
|
||||
CONFIG_WGET=y
|
||||
CONFIG_FEATURE_WGET_STATUSBAR=y
|
||||
@@ -623,23 +671,29 @@ CONFIG_FUSER=y
|
||||
CONFIG_KILL=y
|
||||
CONFIG_KILLALL=y
|
||||
CONFIG_KILLALL5=y
|
||||
CONFIG_NMETER=y
|
||||
CONFIG_PGREP=y
|
||||
CONFIG_PIDOF=y
|
||||
CONFIG_FEATURE_PIDOF_SINGLE=y
|
||||
CONFIG_FEATURE_PIDOF_OMIT=y
|
||||
CONFIG_PKILL=y
|
||||
CONFIG_PS=y
|
||||
CONFIG_FEATURE_PS_WIDE=y
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_UPTIME=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_LASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH is not set
|
||||
@@ -657,8 +711,14 @@ CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
# CONFIG_HUSH is not set
|
||||
# CONFIG_LASH is not set
|
||||
CONFIG_HUSH=y
|
||||
CONFIG_HUSH_HELP=y
|
||||
# CONFIG_HUSH_INTERACTIVE is not set
|
||||
# CONFIG_HUSH_JOB is not set
|
||||
CONFIG_HUSH_TICK=y
|
||||
CONFIG_HUSH_IF=y
|
||||
CONFIG_HUSH_LOOPS=y
|
||||
CONFIG_LASH=y
|
||||
CONFIG_MSH=y
|
||||
|
||||
#
|
||||
@@ -666,6 +726,7 @@ CONFIG_MSH=y
|
||||
#
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
CONFIG_CTTYHACK=y
|
||||
|
||||
#
|
||||
# System Logging Utilities
|
||||
@@ -684,7 +745,7 @@ CONFIG_LOGGER=y
|
||||
# Runit Utilities
|
||||
#
|
||||
# CONFIG_RUNSV is not set
|
||||
# CONFIG_RUNSVDIR is not set
|
||||
CONFIG_RUNSVDIR=y
|
||||
CONFIG_SV=y
|
||||
# CONFIG_SVLOGD is not set
|
||||
CONFIG_CHPST=y
|
||||
@@ -698,10 +759,15 @@ CONFIG_SOFTLIMIT=y
|
||||
# CONFIG_GETSEBOOL is not set
|
||||
# CONFIG_LOAD_POLICY is not set
|
||||
# CONFIG_MATCHPATHCON is not set
|
||||
# CONFIG_RESTORECON is not set
|
||||
# CONFIG_RUNCON is not set
|
||||
# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set
|
||||
# CONFIG_SELINUXENABLED is not set
|
||||
# CONFIG_SETENFORCE is not set
|
||||
# CONFIG_SETFILES is not set
|
||||
# CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set
|
||||
# CONFIG_SETSEBOOL is not set
|
||||
# CONFIG_SESTATUS is not set
|
||||
|
||||
#
|
||||
# ipsvd utilities
|
||||
|
||||
+14
-5
@@ -8,18 +8,27 @@ obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage
|
||||
hostprogs-y += usage applet_tables
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h include/applet_tables.h
|
||||
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
applets/applet_tables: .config
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
|
||||
$(call cmd,gen_usage_compressed)
|
||||
|
||||
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
|
||||
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h
|
||||
|
||||
include/applet_tables.h: applets/applet_tables
|
||||
$(call cmd,gen_applet_tables)
|
||||
@@ -0,0 +1,115 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Applet table generator.
|
||||
* Runs on host and produces include/applet_tables.h
|
||||
*
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../include/autoconf.h"
|
||||
#include "../include/busybox.h"
|
||||
|
||||
struct bb_applet {
|
||||
const char *name;
|
||||
const char *main;
|
||||
enum bb_install_loc_t install_loc;
|
||||
enum bb_suid_t need_suid;
|
||||
/* true if instead of fork(); exec("applet"); waitpid();
|
||||
* one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
|
||||
unsigned char noexec;
|
||||
/* Even nicer */
|
||||
/* true if instead of fork(); exec("applet"); waitpid();
|
||||
* one can simply call applet_main(argc,argv); */
|
||||
unsigned char nofork;
|
||||
};
|
||||
|
||||
/* Define struct bb_applet applets[] */
|
||||
#include "../include/applets.h"
|
||||
|
||||
enum { NUM_APPLETS = sizeof(applets)/sizeof(applets[0]) };
|
||||
|
||||
static int offset[NUM_APPLETS];
|
||||
|
||||
static int cmp_name(const void *a, const void *b)
|
||||
{
|
||||
const struct bb_applet *aa = a;
|
||||
const struct bb_applet *bb = b;
|
||||
return strcmp(aa->name, bb->name);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int ofs;
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
ofs = 0;
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
offset[i] = ofs;
|
||||
ofs += strlen(applets[i].name) + 1;
|
||||
}
|
||||
/* We reuse 4 high-order bits of offset array for other purposes,
|
||||
* so if they are indeed needed, refuse to proceed */
|
||||
if (ofs > 0xfff)
|
||||
return 1;
|
||||
if (!argv[1])
|
||||
return 1;
|
||||
|
||||
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
dup2(i, 1);
|
||||
|
||||
/* Keep in sync with include/busybox.h! */
|
||||
|
||||
puts("/* This is a generated file, don't edit */");
|
||||
|
||||
puts("const char applet_names[] ALIGN1 = \"\" \n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("\"%s\" \"\\0\"\n", applets[i].name);
|
||||
}
|
||||
puts(";");
|
||||
|
||||
puts("int (*const applet_main[])(int argc, char **argv) = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("%s_main,\n", applets[i].main);
|
||||
}
|
||||
puts("};");
|
||||
|
||||
puts("const uint16_t applet_nameofs[] ALIGN2 = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("0x%04x,\n",
|
||||
offset[i]
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
+ (applets[i].nofork << 12)
|
||||
+ (applets[i].noexec << 13)
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SUID
|
||||
+ (applets[i].need_suid << 14) /* 2 bits */
|
||||
#endif
|
||||
);
|
||||
}
|
||||
puts("};");
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
puts("const uint8_t applet_install_loc[] ALIGN1 = {");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].install_loc; /* 3 bits */
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].install_loc << 4; /* 3 bits */
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
puts("};");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Stub for linking busybox binary against libbusybox.
|
||||
*
|
||||
* Copyright (C) 2007 Denis Vlasenko
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
@@ -17,7 +17,7 @@
|
||||
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
|
||||
#warning Note that glibc is unsuitable for static linking anyway.
|
||||
#warning If you still want to do it, remove -Wl,--gc-sections
|
||||
#warning from top-level Makefile and remove this warning.
|
||||
#warning from scripts/trylink and remove this warning.
|
||||
#error Aborting compilation.
|
||||
#endif
|
||||
|
||||
|
||||
+15
-6
@@ -721,7 +721,8 @@ void mainQSort3(uint32_t* ptr,
|
||||
#define CLEARMASK (~(SETMASK))
|
||||
|
||||
static NOINLINE
|
||||
void mainSort(uint32_t* ptr,
|
||||
void mainSort(EState* state,
|
||||
uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
uint32_t* ftab,
|
||||
@@ -729,13 +730,18 @@ void mainSort(uint32_t* ptr,
|
||||
int32_t* budget)
|
||||
{
|
||||
int32_t i, j, k, ss, sb;
|
||||
int32_t runningOrder[256];
|
||||
Bool bigDone[256];
|
||||
int32_t copyStart[256];
|
||||
int32_t copyEnd [256];
|
||||
uint8_t c1;
|
||||
int32_t numQSorted;
|
||||
uint16_t s;
|
||||
Bool bigDone[256];
|
||||
/* bbox: moved to EState to save stack
|
||||
int32_t runningOrder[256];
|
||||
int32_t copyStart[256];
|
||||
int32_t copyEnd [256];
|
||||
*/
|
||||
#define runningOrder (state->mainSort__runningOrder)
|
||||
#define copyStart (state->mainSort__copyStart)
|
||||
#define copyEnd (state->mainSort__copyEnd)
|
||||
|
||||
/*-- set up the 2-byte frequency table --*/
|
||||
/* was: for (i = 65536; i >= 0; i--) ftab[i] = 0; */
|
||||
@@ -985,6 +991,9 @@ void mainSort(uint32_t* ptr,
|
||||
AssertH(((bbSize-1) >> shifts) <= 65535, 1002);
|
||||
}
|
||||
}
|
||||
#undef runningOrder
|
||||
#undef copyStart
|
||||
#undef copyEnd
|
||||
}
|
||||
|
||||
#undef BIGFREQ
|
||||
@@ -1041,7 +1050,7 @@ void BZ2_blockSort(EState* s)
|
||||
*/
|
||||
budget = nblock * ((wfact-1) / 3);
|
||||
|
||||
mainSort(ptr, block, quadrant, ftab, nblock, &budget);
|
||||
mainSort(s, ptr, block, quadrant, ftab, nblock, &budget);
|
||||
if (budget < 0) {
|
||||
fallbackSort(s->arr1, s->arr2, ftab, nblock);
|
||||
}
|
||||
|
||||
@@ -178,13 +178,22 @@ typedef struct EState {
|
||||
uint8_t selector [BZ_MAX_SELECTORS];
|
||||
uint8_t selectorMtf[BZ_MAX_SELECTORS];
|
||||
|
||||
uint8_t len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
|
||||
/* stack-saving measures: these can be local, but they are too big */
|
||||
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
/* second dimension: only 3 needed; 4 makes index calculations faster */
|
||||
uint32_t len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||
#endif
|
||||
int32_t BZ2_hbMakeCodeLengths__heap [BZ_MAX_ALPHA_SIZE + 2];
|
||||
int32_t BZ2_hbMakeCodeLengths__weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t BZ2_hbMakeCodeLengths__parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
|
||||
int32_t mainSort__runningOrder[256];
|
||||
int32_t mainSort__copyStart[256];
|
||||
int32_t mainSort__copyEnd[256];
|
||||
} EState;
|
||||
|
||||
|
||||
@@ -203,7 +212,7 @@ static void
|
||||
BZ2_hbAssignCodes(int32_t*, uint8_t*, int32_t, int32_t, int32_t);
|
||||
|
||||
static void
|
||||
BZ2_hbMakeCodeLengths(uint8_t*, int32_t*, int32_t, int32_t);
|
||||
BZ2_hbMakeCodeLengths(EState*, uint8_t*, int32_t*, int32_t, int32_t);
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib_private.h ---*/
|
||||
|
||||
@@ -264,13 +264,16 @@ void sendMTFValues(EState* s)
|
||||
* are also globals only used in this proc.
|
||||
* Made global to keep stack frame size small.
|
||||
*/
|
||||
#define code sendMTFValues__code
|
||||
#define rfreq sendMTFValues__rfreq
|
||||
#define len_pack sendMTFValues__len_pack
|
||||
|
||||
uint16_t cost[BZ_N_GROUPS];
|
||||
int32_t fave[BZ_N_GROUPS];
|
||||
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
alphaSize = s->nInUse+2;
|
||||
alphaSize = s->nInUse + 2;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->len[t][v] = BZ_GREATER_ICOST;
|
||||
@@ -453,7 +456,7 @@ void sendMTFValues(EState* s)
|
||||
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
|
||||
* comment in huffman.c for details. */
|
||||
for (t = 0; t < nGroups; t++)
|
||||
BZ2_hbMakeCodeLengths(&(s->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
|
||||
BZ2_hbMakeCodeLengths(s, &(s->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
|
||||
}
|
||||
|
||||
AssertH(nGroups < 8, 3002);
|
||||
@@ -602,6 +605,9 @@ void sendMTFValues(EState* s)
|
||||
selCtr++;
|
||||
}
|
||||
AssertH(selCtr == nSelectors, 3007);
|
||||
#undef code
|
||||
#undef rfreq
|
||||
#undef len_pack
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-1
@@ -98,7 +98,8 @@ void DOWNHEAP1(int32_t *heap, int32_t *weight, int32_t nHeap)
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_hbMakeCodeLengths(uint8_t *len,
|
||||
void BZ2_hbMakeCodeLengths(EState *s,
|
||||
uint8_t *len,
|
||||
int32_t *freq,
|
||||
int32_t alphaSize,
|
||||
int32_t maxLen)
|
||||
@@ -110,9 +111,14 @@ void BZ2_hbMakeCodeLengths(uint8_t *len,
|
||||
int32_t nNodes, nHeap, n1, n2, i, j, k;
|
||||
Bool tooLong;
|
||||
|
||||
/* bbox: moved to EState to save stack
|
||||
int32_t heap [BZ_MAX_ALPHA_SIZE + 2];
|
||||
int32_t weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
*/
|
||||
#define heap (s->BZ2_hbMakeCodeLengths__heap)
|
||||
#define weight (s->BZ2_hbMakeCodeLengths__weight)
|
||||
#define parent (s->BZ2_hbMakeCodeLengths__parent)
|
||||
|
||||
for (i = 0; i < alphaSize; i++)
|
||||
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
|
||||
@@ -189,6 +195,9 @@ void BZ2_hbMakeCodeLengths(uint8_t *len,
|
||||
weight[i] = j << 8;
|
||||
}
|
||||
}
|
||||
#undef heap
|
||||
#undef weight
|
||||
#undef parent
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
||||
#endif
|
||||
|
||||
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
|
||||
@@ -1178,6 +1178,7 @@ unpack_gz_stream(int in, int out)
|
||||
ALLOC_STATE;
|
||||
bytebuffer_max = 0x8000;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
gunzip_src_fd = in;
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE_ONLY)) {
|
||||
|
||||
@@ -59,8 +59,12 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
/* POSIX: "ustar" NUL "00" */
|
||||
/* GNU tar: "ustar " NUL */
|
||||
/* Normally it's defined as magic[6] followed by
|
||||
* version[2], but we put them together to save code.
|
||||
*/
|
||||
char magic[8]; /* 257-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
|
||||
@@ -11,7 +11,7 @@ char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2", "bunzip2", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -25,7 +25,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
}
|
||||
#endif
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -14,7 +14,7 @@ char get_header_tar_lzma(archive_handle_t * archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma", "unlzma", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
/*
|
||||
* On MMU machine, the transform_prog and ... are stripped
|
||||
* by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
|
||||
* On MMU machine, the transform_prog is removed by macro magic
|
||||
* in include/unarchive.h. On NOMMU, transformer is removed.
|
||||
*/
|
||||
int open_transformer(int src_fd,
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
|
||||
const char *transform_prog, ...)
|
||||
const char *transform_prog)
|
||||
{
|
||||
int fd_pipe[2];
|
||||
int pid;
|
||||
@@ -29,9 +29,6 @@ int open_transformer(int src_fd,
|
||||
bb_perror_msg_and_die("fork failed");
|
||||
|
||||
if (pid == 0) {
|
||||
#if !BB_MMU
|
||||
va_list ap;
|
||||
#endif
|
||||
/* child process */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
||||
// FIXME: error check?
|
||||
@@ -43,12 +40,17 @@ int open_transformer(int src_fd,
|
||||
}
|
||||
exit(0);
|
||||
#else
|
||||
xmove_fd(src_fd, 0);
|
||||
xmove_fd(fd_pipe[1], 1);
|
||||
va_start(ap, transform_prog);
|
||||
/* hoping that va_list -> char** on our CPU is working... */
|
||||
BB_EXECVP(transform_prog, (void*)ap);
|
||||
bb_perror_msg_and_die("exec failed");
|
||||
{
|
||||
char *argv[4];
|
||||
xmove_fd(src_fd, 0);
|
||||
xmove_fd(fd_pipe[1], 1);
|
||||
argv[0] = (char*)transform_prog;
|
||||
argv[1] = (char*)"-cf";
|
||||
argv[2] = (char*)"-";
|
||||
argv[3] = NULL;
|
||||
BB_EXECVP(transform_prog, argv);
|
||||
bb_perror_msg_and_die("exec failed");
|
||||
}
|
||||
#endif
|
||||
/* notreached */
|
||||
}
|
||||
|
||||
+1
-1
@@ -237,7 +237,7 @@ static void extract_cpio_gz(int fd)
|
||||
}
|
||||
|
||||
xchdir("/"); /* Install RPM's to root */
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog, xformer_prog, "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
+8
-4
@@ -50,14 +50,18 @@ struct TarHeader { /* byte offset */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[NAME_SIZE]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
/* POSIX: "ustar" NUL "00" */
|
||||
/* GNU tar: "ustar " NUL */
|
||||
/* Normally it's defined as magic[6] followed by
|
||||
* version[2], but we put them together to save code.
|
||||
*/
|
||||
char magic[8]; /* 257-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
|
||||
char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -662,7 +666,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress", "uncompress", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
+12
-4
@@ -41,8 +41,10 @@ enum {
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ZIP_HEADER_LEN 26
|
||||
|
||||
typedef union {
|
||||
uint8_t raw[26];
|
||||
uint8_t raw[ZIP_HEADER_LEN];
|
||||
struct {
|
||||
uint16_t version; /* 0-1 */
|
||||
uint16_t flags; /* 2-3 */
|
||||
@@ -55,10 +57,16 @@ typedef union {
|
||||
uint16_t filename_len; /* 22-23 */
|
||||
uint16_t extra_len; /* 24-25 */
|
||||
} formatted ATTRIBUTE_PACKED;
|
||||
} zip_header_t;
|
||||
} zip_header_t; /* ATTRIBUTE_PACKED - gcc 4.2.1 doesn't like it (spews warning) */
|
||||
|
||||
/* Check the offset of the last element, not the length. This leniency
|
||||
* allows for poor packing, whereby the overall struct may be too long,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
struct BUG_zip_header_must_be_26_bytes {
|
||||
char BUG_zip_header_must_be_26_bytes[sizeof(zip_header_t) == 26 ? 1 : -1];
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, formatted.extra_len) + 2 ==
|
||||
ZIP_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS(zip_header) do { \
|
||||
@@ -256,7 +264,7 @@ int unzip_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", magic);
|
||||
|
||||
/* Read the file header */
|
||||
xread(src_fd, zip_header.raw, sizeof(zip_header));
|
||||
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS(zip_header);
|
||||
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
|
||||
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
|
||||
|
||||
@@ -135,6 +135,13 @@ config DF
|
||||
df reports the amount of disk space used and available
|
||||
on filesystems.
|
||||
|
||||
config FEATURE_DF_INODE
|
||||
bool "Enable -i (inode information)"
|
||||
default n
|
||||
depends on DF
|
||||
help
|
||||
This option enables support for df -i.
|
||||
|
||||
config DIRNAME
|
||||
bool "dirname"
|
||||
default n
|
||||
|
||||
+37
-39
@@ -16,13 +16,11 @@
|
||||
|
||||
/* option vars */
|
||||
static const char optstring[] ALIGN1 = "b:c:f:d:sn";
|
||||
#define CUT_OPT_BYTE_FLGS (1<<0)
|
||||
#define CUT_OPT_CHAR_FLGS (1<<1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1<<2)
|
||||
#define CUT_OPT_DELIM_FLGS (1<<3)
|
||||
#define CUT_OPT_SUPPRESS_FLGS (1<<4)
|
||||
|
||||
static char delim = '\t'; /* delimiter, default is tab */
|
||||
#define CUT_OPT_BYTE_FLGS (1 << 0)
|
||||
#define CUT_OPT_CHAR_FLGS (1 << 1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1 << 2)
|
||||
#define CUT_OPT_DELIM_FLGS (1 << 3)
|
||||
#define CUT_OPT_SUPPRESS_FLGS (1 << 4)
|
||||
|
||||
struct cut_list {
|
||||
int startpos;
|
||||
@@ -47,7 +45,7 @@ static int cmpfunc(const void *a, const void *b)
|
||||
|
||||
}
|
||||
|
||||
static void cut_file(FILE * file)
|
||||
static void cut_file(FILE *file, char delim)
|
||||
{
|
||||
char *line = NULL;
|
||||
unsigned int linenum = 0; /* keep these zero-based to be consistent */
|
||||
@@ -163,11 +161,10 @@ static void cut_file(FILE * file)
|
||||
}
|
||||
}
|
||||
|
||||
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
|
||||
|
||||
int cut_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
char delim = '\t'; /* delimiter, default is tab */
|
||||
char *sopt, *ltok;
|
||||
|
||||
opt_complementary = "b--bcf:c--bcf:f--bcf";
|
||||
@@ -178,7 +175,7 @@ int cut_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
|
||||
|
||||
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
|
||||
if (strlen(ltok) > 1) {
|
||||
if (ltok[0] && ltok[1]) { /* more than 1 char? */
|
||||
bb_error_msg_and_die("the delimiter must be a single character");
|
||||
}
|
||||
delim = ltok[0];
|
||||
@@ -186,6 +183,8 @@ int cut_main(int argc, char **argv)
|
||||
|
||||
/* non-field (char or byte) cutting has some special handling */
|
||||
if (!(option_mask32 & CUT_OPT_FIELDS_FLGS)) {
|
||||
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
|
||||
|
||||
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS) {
|
||||
bb_error_msg_and_die
|
||||
("suppressing non-delimited lines makes sense%s",
|
||||
@@ -210,15 +209,12 @@ int cut_main(int argc, char **argv)
|
||||
while ((ltok = strsep(&sopt, ",")) != NULL) {
|
||||
|
||||
/* it's actually legal to pass an empty list */
|
||||
if (strlen(ltok) == 0)
|
||||
if (!ltok[0])
|
||||
continue;
|
||||
|
||||
/* get the start pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (ntok == NULL) {
|
||||
bb_error_msg
|
||||
("internal error: ntok is null for start pos!?\n");
|
||||
} else if (strlen(ntok) == 0) {
|
||||
if (!ntok[0]) {
|
||||
s = BOL;
|
||||
} else {
|
||||
s = xatoi_u(ntok);
|
||||
@@ -229,13 +225,12 @@ int cut_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* get the end pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (ntok == NULL) {
|
||||
if (ltok == NULL) {
|
||||
e = NON_RANGE;
|
||||
} else if (strlen(ntok) == 0) {
|
||||
} else if (!ltok[0]) {
|
||||
e = EOL;
|
||||
} else {
|
||||
e = xatoi_u(ntok);
|
||||
e = xatoi_u(ltok);
|
||||
/* if the user specified and end position of 0, that means "til the
|
||||
* end of the line */
|
||||
if (e == 0)
|
||||
@@ -245,11 +240,6 @@ int cut_main(int argc, char **argv)
|
||||
e = NON_RANGE;
|
||||
}
|
||||
|
||||
/* if there's something left to tokenize, the user passed
|
||||
* an invalid list */
|
||||
if (ltok)
|
||||
bb_error_msg_and_die("invalid byte or field list");
|
||||
|
||||
/* add the new list */
|
||||
cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
|
||||
cut_lists[nlists-1].startpos = s;
|
||||
@@ -266,23 +256,31 @@ int cut_main(int argc, char **argv)
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
}
|
||||
|
||||
/* argv[0..argc-1] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[0] == NULL || LONE_DASH(argv[0])) {
|
||||
cut_file(stdin);
|
||||
} else {
|
||||
FILE *file;
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
FILE *file = stdin;
|
||||
|
||||
if (!*argv) {
|
||||
argv--;
|
||||
goto jump_in;
|
||||
}
|
||||
|
||||
do {
|
||||
file = fopen_or_warn(argv[0], "r");
|
||||
if (file) {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
file = stdin;
|
||||
if (NOT_LONE_DASH(*argv))
|
||||
file = fopen_or_warn(*argv, "r");
|
||||
if (!file) {
|
||||
retval = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
jump_in:
|
||||
cut_file(file, delim);
|
||||
if (NOT_LONE_DASH(*argv))
|
||||
fclose(file);
|
||||
} while (*++argv);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(cut_lists);
|
||||
fflush_stdout_and_exit(retval);
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(cut_lists);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+22
-19
@@ -14,6 +14,11 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
enum {
|
||||
ifd = STDIN_FILENO,
|
||||
ofd = STDOUT_FILENO,
|
||||
};
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
@@ -45,19 +50,19 @@ static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
|
||||
G.out_full, G.out_part);
|
||||
}
|
||||
|
||||
static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
|
||||
static ssize_t full_write_or_warn(const void *buf, size_t len,
|
||||
const char *const filename)
|
||||
{
|
||||
ssize_t n = full_write(fd, buf, len);
|
||||
ssize_t n = full_write(ofd, buf, len);
|
||||
if (n < 0)
|
||||
bb_perror_msg("writing '%s'", filename);
|
||||
return n;
|
||||
}
|
||||
|
||||
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
|
||||
static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
const char *filename)
|
||||
{
|
||||
ssize_t n = full_write_or_warn(fd, buf, len, filename);
|
||||
ssize_t n = full_write_or_warn(buf, len, filename);
|
||||
if (n < 0)
|
||||
return 1;
|
||||
if (n == obs)
|
||||
@@ -105,13 +110,13 @@ int dd_main(int argc, char **argv)
|
||||
OP_conv_noerror,
|
||||
#endif
|
||||
};
|
||||
int exitcode = EXIT_FAILURE;
|
||||
size_t ibs = 512, obs = 512;
|
||||
ssize_t n, w;
|
||||
char *ibuf, *obuf;
|
||||
/* And these are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
int ifd, ofd;
|
||||
size_t oc;
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
@@ -121,8 +126,6 @@ int dd_main(int argc, char **argv)
|
||||
#endif
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define ifd (Z.ifd )
|
||||
#define ofd (Z.ofd )
|
||||
#define oc (Z.oc )
|
||||
#define count (Z.count )
|
||||
#define seek (Z.seek )
|
||||
@@ -133,6 +136,7 @@ int dd_main(int argc, char **argv)
|
||||
|
||||
memset(&Z, 0, sizeof(Z));
|
||||
INIT_G();
|
||||
//fflush(NULL); - is this needed because of NOEXEC?
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
sigact.sa_handler = dd_output_status;
|
||||
@@ -227,9 +231,8 @@ int dd_main(int argc, char **argv)
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
if (infile != NULL)
|
||||
ifd = xopen(infile, O_RDONLY);
|
||||
xmove_fd(xopen(infile, O_RDONLY), ifd);
|
||||
else {
|
||||
/* ifd = STDIN_FILENO; - it's zero and it's already there */
|
||||
infile = bb_msg_standard_input;
|
||||
}
|
||||
if (outfile != NULL) {
|
||||
@@ -238,7 +241,7 @@ int dd_main(int argc, char **argv)
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
ofd = xopen(outfile, oflag);
|
||||
xmove_fd(xopen(outfile, oflag), ofd);
|
||||
|
||||
if (seek && !(flags & FLAG_NOTRUNC)) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
@@ -250,7 +253,6 @@ int dd_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ofd = STDOUT_FILENO;
|
||||
outfile = bb_msg_standard_output;
|
||||
}
|
||||
if (skip) {
|
||||
@@ -276,11 +278,10 @@ int dd_main(int argc, char **argv)
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
if (flags & FLAG_NOERROR) {
|
||||
n = ibs;
|
||||
bb_simple_perror_msg(infile);
|
||||
} else
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
n = ibs;
|
||||
bb_simple_perror_msg(infile);
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
@@ -303,17 +304,17 @@ int dd_main(int argc, char **argv)
|
||||
tmp += d;
|
||||
oc += d;
|
||||
if (oc == obs) {
|
||||
if (write_and_stats(ofd, obuf, obs, obs, outfile))
|
||||
if (write_and_stats(obuf, obs, obs, outfile))
|
||||
goto out_status;
|
||||
oc = 0;
|
||||
}
|
||||
}
|
||||
} else if (write_and_stats(ofd, ibuf, n, obs, outfile))
|
||||
} else if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
|
||||
w = full_write_or_warn(ofd, obuf, oc, outfile);
|
||||
w = full_write_or_warn(obuf, oc, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w > 0)
|
||||
G.out_part++;
|
||||
@@ -327,8 +328,10 @@ int dd_main(int argc, char **argv)
|
||||
die_outfile:
|
||||
bb_simple_perror_msg_and_die(outfile);
|
||||
}
|
||||
|
||||
exitcode = EXIT_SUCCESS;
|
||||
out_status:
|
||||
dd_output_status(0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return exitcode;
|
||||
}
|
||||
+32
-8
@@ -45,23 +45,32 @@ int df_main(int argc, char **argv)
|
||||
/* default display is kilobytes */
|
||||
const char *disp_units_hdr = "1k-blocks";
|
||||
|
||||
enum {
|
||||
OPT_ALL = (1 << 0),
|
||||
OPT_INODE = (ENABLE_FEATURE_HUMAN_READABLE ? (1 << 4) : (1 << 2))
|
||||
* ENABLE_FEATURE_DF_INODE
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk";
|
||||
opt = getopt32(argv, "hmk");
|
||||
if (opt & 1) {
|
||||
opt = getopt32(argv, "ahmk" USE_FEATURE_DF_INODE("i"));
|
||||
if (opt & (1 << 1)) { // -h
|
||||
df_disp_hr = 0;
|
||||
disp_units_hdr = " Size";
|
||||
}
|
||||
if (opt & 2) {
|
||||
if (opt & (1 << 2)) { // -m
|
||||
df_disp_hr = 1024*1024;
|
||||
disp_units_hdr = "1M-blocks";
|
||||
}
|
||||
if (opt & OPT_INODE) {
|
||||
disp_units_hdr = " Inodes";
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, "k");
|
||||
opt = getopt32(argv, "ak" USE_FEATURE_DF_INODE("i"));
|
||||
#endif
|
||||
|
||||
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
|
||||
"", disp_units_hdr);
|
||||
printf("Filesystem %-15sUsed Available Use%% Mounted on\n",
|
||||
disp_units_hdr);
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
@@ -104,7 +113,16 @@ int df_main(int argc, char **argv)
|
||||
goto SET_ERROR;
|
||||
}
|
||||
|
||||
if ((s.f_blocks > 0) || !mount_table){
|
||||
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
|
||||
if (opt & OPT_INODE) {
|
||||
s.f_blocks = s.f_files;
|
||||
s.f_bavail = s.f_bfree = s.f_ffree;
|
||||
s.f_bsize = 1;
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
if (df_disp_hr)
|
||||
df_disp_hr = 1;
|
||||
#endif
|
||||
}
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = 0;
|
||||
if (blocks_used + s.f_bavail) {
|
||||
@@ -113,9 +131,14 @@ int df_main(int argc, char **argv)
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
|
||||
#ifdef WHY_IT_SHOULD_BE_HIDDEN
|
||||
if (strcmp(device, "rootfs") == 0) {
|
||||
continue;
|
||||
} else if (strcmp(device, "/dev/root") == 0) {
|
||||
}
|
||||
#endif
|
||||
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
||||
/* ... and also this is the only user of find_block_device */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
device = find_block_device("/");
|
||||
@@ -123,6 +146,7 @@ int df_main(int argc, char **argv)
|
||||
goto SET_ERROR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (printf("\n%-20s" + 1, device) > 20)
|
||||
printf("\n%-20s", "");
|
||||
|
||||
+142
-9
@@ -25,7 +25,13 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int bb_echo(char **argv)
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
/* argc is unused, but removing it precludes compiler from
|
||||
* using call -> jump optimization */
|
||||
|
||||
int echo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int echo_main(int argc, char **argv)
|
||||
{
|
||||
const char *arg;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
@@ -33,6 +39,18 @@ int bb_echo(char **argv)
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
|
||||
/* We must check that stdout is not closed.
|
||||
* The reason for this is highly non-obvious.
|
||||
* echo_main is used from shell. Shell must correctly handle "echo foo"
|
||||
* if stdout is closed. With stdio, output gets shoveled into
|
||||
* stdout buffer, and even fflush cannot clear it out. It seems that
|
||||
* even if libc receives EBADF on write attempts, it feels determined
|
||||
* to output data no matter what. So it will try later,
|
||||
* and possibly will clobber future output. Not good. */
|
||||
if (dup2(1, 1) != 1)
|
||||
return -1;
|
||||
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
@@ -41,6 +59,10 @@ int bb_echo(char **argv)
|
||||
char nflag = 1;
|
||||
char eflag = 0;
|
||||
|
||||
/* We must check that stdout is not closed. */
|
||||
if (dup2(1, 1) != 1)
|
||||
return -1;
|
||||
|
||||
while (1) {
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
@@ -117,14 +139,6 @@ int bb_echo(char **argv)
|
||||
return fflush(stdout);
|
||||
}
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int echo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int echo_main(int argc, char **argv)
|
||||
{
|
||||
return bb_echo(argv);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@@ -163,3 +177,122 @@ int echo_main(int argc, char **argv)
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#ifdef VERSION_WITH_WRITEV
|
||||
/* We can't use stdio.
|
||||
* The reason for this is highly non-obvious.
|
||||
* echo_main is used from shell. Shell must correctly handle "echo foo"
|
||||
* if stdout is closed. With stdio, output gets shoveled into
|
||||
* stdout buffer, and even fflush cannot clear it out. It seems that
|
||||
* even if libc receives EBADF on write attempts, it feels determined
|
||||
* to output data no matter what. So it will try later,
|
||||
* and possibly will clobber future output. Not good.
|
||||
*
|
||||
* Using writev instead, with 'direct' conversion of argv vector.
|
||||
*/
|
||||
|
||||
int echo_main(int argc, char **argv)
|
||||
{
|
||||
struct iovec io[argc];
|
||||
struct iovec *cur_io = io;
|
||||
char *arg;
|
||||
char *p;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
#else
|
||||
char nflag = 1;
|
||||
char eflag = 0;
|
||||
|
||||
while (1) {
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
if (*arg != '-')
|
||||
break;
|
||||
|
||||
/* If it appears that we are handling options, then make sure
|
||||
* that all of the options specified are actually valid.
|
||||
* Otherwise, the string should just be echoed.
|
||||
*/
|
||||
p = arg + 1;
|
||||
if (!*p) /* A single '-', so echo it. */
|
||||
goto just_echo;
|
||||
|
||||
do {
|
||||
if (!strrchr("neE", *p))
|
||||
goto just_echo;
|
||||
} while (*++p);
|
||||
|
||||
/* All of the options in this arg are valid, so handle them. */
|
||||
p = arg + 1;
|
||||
do {
|
||||
if (*p == 'n')
|
||||
nflag = 0;
|
||||
if (*p == 'e')
|
||||
eflag = '\\';
|
||||
} while (*++p);
|
||||
}
|
||||
just_echo:
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
/* arg is already == *argv and isn't NULL */
|
||||
int c;
|
||||
|
||||
cur_io->iov_base = p = arg;
|
||||
|
||||
if (!eflag) {
|
||||
/* optimization for very common case */
|
||||
p += strlen(arg);
|
||||
} else while ((c = *arg++)) {
|
||||
if (c == eflag) { /* Check for escape seq. */
|
||||
if (*arg == 'c') {
|
||||
/* '\c' means cancel newline and
|
||||
* ignore all subsequent chars. */
|
||||
cur_io->iov_len = p - (char*)cur_io->iov_base;
|
||||
cur_io++;
|
||||
goto ret;
|
||||
}
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
/* SUSv3 specifies that octal escapes must begin with '0'. */
|
||||
if ( (((unsigned char)*arg) - '1') >= 7)
|
||||
#endif
|
||||
{
|
||||
/* Since SUSv3 mandates a first digit of 0, 4-digit octals
|
||||
* of the form \0### are accepted. */
|
||||
if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
}
|
||||
/* bb_process_escape_sequence can handle nul correctly */
|
||||
c = bb_process_escape_sequence( (void*) &arg);
|
||||
}
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
|
||||
arg = *++argv;
|
||||
if (arg)
|
||||
*p++ = ' ';
|
||||
cur_io->iov_len = p - (char*)cur_io->iov_base;
|
||||
cur_io++;
|
||||
if (!arg)
|
||||
break;
|
||||
}
|
||||
|
||||
newline_ret:
|
||||
if (nflag) {
|
||||
cur_io->iov_base = (char*)"\n";
|
||||
cur_io->iov_len = 1;
|
||||
cur_io++;
|
||||
}
|
||||
ret:
|
||||
/* TODO: implement and use full_writev? */
|
||||
return writev(1, io, (cur_io - io)) >= 0;
|
||||
}
|
||||
#endif
|
||||
+20
-14
@@ -28,23 +28,29 @@ int mknod_main(int argc, char **argv)
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if ((argc >= 2) && ((name = strchr(modes_chars, argv[1][0])) != NULL)) {
|
||||
mode |= modes_cubp[(int)(name[4])];
|
||||
if (argc >= 2) {
|
||||
name = strchr(modes_chars, argv[1][0]);
|
||||
if (name != NULL) {
|
||||
mode |= modes_cubp[(int)(name[4])];
|
||||
|
||||
dev = 0;
|
||||
if ((*name != 'p') && ((argc -= 2) == 2)) {
|
||||
/* Autodetect what the system supports; these macros should
|
||||
* optimize out to two constants. */
|
||||
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
|
||||
xatoul_range(argv[3], 0, minor(UINT_MAX)));
|
||||
}
|
||||
dev = 0;
|
||||
if (*name != 'p') {
|
||||
argc -= 2;
|
||||
if (argc == 2) {
|
||||
/* Autodetect what the system supports; these macros should
|
||||
* optimize out to two constants. */
|
||||
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
|
||||
xatoul_range(argv[3], 0, minor(UINT_MAX)));
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
name = *argv;
|
||||
if (mknod(name, mode, dev) == 0) {
|
||||
return EXIT_SUCCESS;
|
||||
if (argc == 2) {
|
||||
name = *argv;
|
||||
if (mknod(name, mode, dev) == 0) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
}
|
||||
bb_show_usage();
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ int mv_main(int argc, char **argv)
|
||||
if (argc == 2) {
|
||||
dest_exists = cp_mv_stat(last, &dest_stat);
|
||||
if (dest_exists < 0) {
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!(dest_exists & 2)) {
|
||||
|
||||
+31
-42
@@ -181,14 +181,8 @@ static void (*format_address)(off_t, char);
|
||||
/* The difference between the old-style pseudo starting address and
|
||||
the number of bytes to skip. */
|
||||
static off_t pseudo_offset;
|
||||
/* The number of input bytes to skip before formatting and writing. */
|
||||
static off_t n_bytes_to_skip;
|
||||
/* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all
|
||||
input is formatted. */
|
||||
/* The maximum number of bytes that will be formatted. */
|
||||
static off_t max_bytes_to_format;
|
||||
/* The offset of the first byte after the last byte to be formatted. */
|
||||
static off_t end_offset;
|
||||
|
||||
/* The number of input bytes formatted per output line. It must be
|
||||
a multiple of the least common multiple of the sizes associated with
|
||||
@@ -196,22 +190,14 @@ static off_t end_offset;
|
||||
no larger than 16 -- unless specified with the -w option. */
|
||||
static size_t bytes_per_block;
|
||||
|
||||
/* Human-readable representation of *file_list (for error messages).
|
||||
It differs from *file_list only when *file_list is "-". */
|
||||
static char const *input_filename;
|
||||
|
||||
/* A NULL-terminated list of the file-arguments from the command line. */
|
||||
static char const *const *file_list;
|
||||
|
||||
/* Initializer for file_list if no file-arguments
|
||||
were specified on the command line. */
|
||||
static char const *const default_file_list[] = { "-", NULL };
|
||||
static const char *const *file_list;
|
||||
|
||||
/* The input stream associated with the current file. */
|
||||
static FILE *in_stream;
|
||||
|
||||
#define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t)
|
||||
static unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = {
|
||||
static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = {
|
||||
[sizeof(char)] = CHAR,
|
||||
#if USHRT_MAX != UCHAR_MAX
|
||||
[sizeof(short)] = SHORT,
|
||||
@@ -228,7 +214,7 @@ static unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = {
|
||||
};
|
||||
|
||||
#define MAX_FP_TYPE_SIZE sizeof(longdouble_t)
|
||||
static unsigned char fp_type_size[MAX_FP_TYPE_SIZE + 1] ALIGN1 = {
|
||||
static const unsigned char fp_type_size[MAX_FP_TYPE_SIZE + 1] ALIGN1 = {
|
||||
/* gcc seems to allow repeated indexes. Last one stays */
|
||||
[sizeof(longdouble_t)] = FLOAT_LONG_DOUBLE,
|
||||
[sizeof(double)] = FLOAT_DOUBLE,
|
||||
@@ -481,14 +467,10 @@ static void
|
||||
open_next_file(void)
|
||||
{
|
||||
while (1) {
|
||||
input_filename = *file_list;
|
||||
if (!input_filename)
|
||||
if (!*file_list)
|
||||
return;
|
||||
file_list++;
|
||||
in_stream = fopen_or_warn_stdin(input_filename);
|
||||
in_stream = fopen_or_warn_stdin(*file_list++);
|
||||
if (in_stream) {
|
||||
if (in_stream == stdin)
|
||||
input_filename = bb_msg_standard_input;
|
||||
break;
|
||||
}
|
||||
ioerror = 1;
|
||||
@@ -510,7 +492,10 @@ check_and_close(void)
|
||||
{
|
||||
if (in_stream) {
|
||||
if (ferror(in_stream)) {
|
||||
bb_error_msg("%s: read error", input_filename);
|
||||
bb_error_msg("%s: read error", (in_stream == stdin)
|
||||
? bb_msg_standard_input
|
||||
: file_list[-1]
|
||||
);
|
||||
ioerror = 1;
|
||||
}
|
||||
fclose_if_not_stdin(in_stream);
|
||||
@@ -804,8 +789,9 @@ skip(off_t n_skip)
|
||||
} else {
|
||||
/* If it's not a regular file with nonnegative size,
|
||||
position the file pointer by reading. */
|
||||
char buf[BUFSIZ];
|
||||
size_t n_bytes_read, n_bytes_to_read = BUFSIZ;
|
||||
char buf[1024];
|
||||
size_t n_bytes_to_read = 1024;
|
||||
size_t n_bytes_read;
|
||||
|
||||
while (n_skip > 0) {
|
||||
if (n_skip < n_bytes_to_read)
|
||||
@@ -1019,18 +1005,15 @@ parse_old_offset(const char *s, off_t *offset)
|
||||
Otherwise, return zero. */
|
||||
|
||||
static void
|
||||
dump(void)
|
||||
dump(off_t current_offset, off_t end_offset)
|
||||
{
|
||||
char *block[2];
|
||||
off_t current_offset;
|
||||
int idx;
|
||||
size_t n_bytes_read;
|
||||
|
||||
block[0] = xmalloc(2*bytes_per_block);
|
||||
block[1] = block[0] + bytes_per_block;
|
||||
|
||||
current_offset = n_bytes_to_skip;
|
||||
|
||||
idx = 0;
|
||||
if (limit_bytes_to_format) {
|
||||
while (1) {
|
||||
@@ -1133,11 +1116,10 @@ read_char(int *c)
|
||||
occurs. Otherwise, return zero. */
|
||||
|
||||
static void
|
||||
dump_strings(void)
|
||||
dump_strings(off_t address, off_t end_offset)
|
||||
{
|
||||
size_t bufsize = MAX(100, string_min);
|
||||
char *buf = xmalloc(bufsize);
|
||||
off_t address = n_bytes_to_skip;
|
||||
|
||||
while (1) {
|
||||
size_t i;
|
||||
@@ -1169,7 +1151,7 @@ dump_strings(void)
|
||||
if (i < string_min) /* Too short! */
|
||||
goto tryline;
|
||||
|
||||
/* If we get here, the string is all printable and null-terminated,
|
||||
/* If we get here, the string is all printable and NUL-terminated,
|
||||
* so print it. It is all in 'buf' and 'i' is its length. */
|
||||
buf[i] = 0;
|
||||
format_address(address - i - 1, ' ');
|
||||
@@ -1183,7 +1165,7 @@ dump_strings(void)
|
||||
case '\r': fputs("\\r", stdout); break;
|
||||
case '\t': fputs("\\t", stdout); break;
|
||||
case '\v': fputs("\\v", stdout); break;
|
||||
default: bb_putchar(c);
|
||||
default: putchar(c);
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
@@ -1199,17 +1181,13 @@ dump_strings(void)
|
||||
int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int od_main(int argc, char **argv)
|
||||
{
|
||||
static char const *const default_file_list[] = { "-", NULL };
|
||||
static const struct suffix_mult bkm[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ }
|
||||
};
|
||||
unsigned opt;
|
||||
int l_c_m;
|
||||
/* The old-style 'pseudo starting address' to be printed in parentheses
|
||||
after any true address. */
|
||||
off_t pseudo_start = 0; // only for gcc
|
||||
enum {
|
||||
OPT_A = 1 << 0,
|
||||
OPT_N = 1 << 1,
|
||||
@@ -1246,6 +1224,17 @@ int od_main(int argc, char **argv)
|
||||
char *str_A, *str_N, *str_j, *str_S;
|
||||
char *str_w = NULL;
|
||||
llist_t *lst_t = NULL;
|
||||
unsigned opt;
|
||||
int l_c_m;
|
||||
/* The old-style 'pseudo starting address' to be printed in parentheses
|
||||
after any true address. */
|
||||
off_t pseudo_start = pseudo_start; // for gcc
|
||||
/* The number of input bytes to skip before formatting and writing. */
|
||||
off_t n_bytes_to_skip = 0;
|
||||
/* The offset of the first byte after the last byte to be formatted. */
|
||||
off_t end_offset = 0;
|
||||
/* The maximum number of bytes that will be formatted. */
|
||||
off_t max_bytes_to_format = 0;
|
||||
|
||||
spec = NULL;
|
||||
format_address = format_address_std;
|
||||
@@ -1411,7 +1400,7 @@ int od_main(int argc, char **argv)
|
||||
/* skip over any unwanted header bytes */
|
||||
skip(n_bytes_to_skip);
|
||||
if (!in_stream)
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
|
||||
pseudo_offset = (flag_pseudo_start ? pseudo_start - n_bytes_to_skip : 0);
|
||||
|
||||
@@ -1441,9 +1430,9 @@ int od_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
if (flag_dump_strings)
|
||||
dump_strings();
|
||||
dump_strings(n_bytes_to_skip, end_offset);
|
||||
else
|
||||
dump();
|
||||
dump(n_bytes_to_skip, end_offset);
|
||||
|
||||
if (fclose(stdin) == EOF)
|
||||
bb_perror_msg_and_die(bb_msg_standard_input);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -16,6 +15,7 @@ int readlink_main(int argc, char **argv)
|
||||
{
|
||||
char *buf;
|
||||
char *fname;
|
||||
char pathbuf[PATH_MAX];
|
||||
|
||||
USE_FEATURE_READLINK_FOLLOW(
|
||||
unsigned opt;
|
||||
@@ -34,7 +34,7 @@ int readlink_main(int argc, char **argv)
|
||||
logmode = LOGMODE_NONE;
|
||||
|
||||
if (opt) {
|
||||
buf = realpath(fname, bb_common_bufsiz1);
|
||||
buf = realpath(fname, pathbuf);
|
||||
} else {
|
||||
buf = xmalloc_readlink_or_warn(fname);
|
||||
}
|
||||
|
||||
+2
-2
@@ -374,9 +374,9 @@ int sort_main(int argc, char **argv)
|
||||
for (i = 1; i < linecount; i++)
|
||||
if (compare_keys(&lines[i-1], &lines[i]) > j) {
|
||||
fprintf(stderr, "Check line %d\n", i);
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
/* Perform the actual sort */
|
||||
|
||||
+1
-1
@@ -137,5 +137,5 @@ int split_main(int argc, char **argv)
|
||||
src += to_write;
|
||||
} while (bytes_read);
|
||||
}
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+361
-152
@@ -133,18 +133,27 @@ enum {
|
||||
#define REV 4 /* Can be turned off by prepending '-' */
|
||||
#define OMIT 8 /* Don't display value */
|
||||
|
||||
/* Each mode */
|
||||
|
||||
/* Each mode.
|
||||
* This structure should be kept as small as humanly possible.
|
||||
*/
|
||||
struct mode_info {
|
||||
const char name[9]; /* Name given on command line */
|
||||
const unsigned char type; /* Which structure element to change */
|
||||
const unsigned char flags; /* Setting and display options */
|
||||
/* were using short here, but ppc32 was unhappy: */
|
||||
const uint8_t type; /* Which structure element to change */
|
||||
const uint8_t flags; /* Setting and display options */
|
||||
/* only these values are ever used, so... */
|
||||
#if (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x100
|
||||
const uint8_t mask;
|
||||
#elif (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x10000
|
||||
const uint16_t mask;
|
||||
#else
|
||||
const tcflag_t mask; /* Other bits to turn off for this mode */
|
||||
#endif
|
||||
/* was using short here, but ppc32 was unhappy */
|
||||
const tcflag_t bits; /* Bits to set for this mode */
|
||||
};
|
||||
|
||||
enum {
|
||||
/* Must match mode_info[] order! */
|
||||
/* Must match mode_name[] and mode_info[] order! */
|
||||
IDX_evenp = 0,
|
||||
IDX_parity,
|
||||
IDX_oddp,
|
||||
@@ -170,151 +179,302 @@ enum {
|
||||
#endif
|
||||
};
|
||||
|
||||
#define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B }
|
||||
#define MI_ENTRY(N,T,F,B,M) N "\0"
|
||||
|
||||
static const struct mode_info mode_info[] = {
|
||||
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("nl", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("ek", combination, OMIT, 0, 0 ),
|
||||
MI_ENTRY("sane", combination, OMIT, 0, 0 ),
|
||||
MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("raw", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("litout", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("crt", combination, OMIT, 0, 0 ),
|
||||
MI_ENTRY("dec", combination, OMIT, 0, 0 ),
|
||||
/* Mode names given on command line */
|
||||
static const char mode_name[] =
|
||||
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("nl", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("ek", combination, OMIT, 0, 0 )
|
||||
MI_ENTRY("sane", combination, OMIT, 0, 0 )
|
||||
MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("raw", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("litout", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("crt", combination, OMIT, 0, 0 )
|
||||
MI_ENTRY("dec", combination, OMIT, 0, 0 )
|
||||
#ifdef IXANY
|
||||
MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 )
|
||||
#endif
|
||||
#if defined(TABDLY) || defined(OXTABS)
|
||||
MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 )
|
||||
#endif
|
||||
#if defined(XCASE) && defined(IUCLC) && defined(OLCUC)
|
||||
MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ),
|
||||
MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 )
|
||||
#endif
|
||||
MI_ENTRY("parenb", control, REV, PARENB, 0 ),
|
||||
MI_ENTRY("parodd", control, REV, PARODD, 0 ),
|
||||
MI_ENTRY("cs5", control, 0, CS5, CSIZE),
|
||||
MI_ENTRY("cs6", control, 0, CS6, CSIZE),
|
||||
MI_ENTRY("cs7", control, 0, CS7, CSIZE),
|
||||
MI_ENTRY("cs8", control, 0, CS8, CSIZE),
|
||||
MI_ENTRY("hupcl", control, REV, HUPCL, 0 ),
|
||||
MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ),
|
||||
MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ),
|
||||
MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ),
|
||||
MI_ENTRY("clocal", control, REV, CLOCAL, 0 ),
|
||||
MI_ENTRY("parenb", control, REV, PARENB, 0 )
|
||||
MI_ENTRY("parodd", control, REV, PARODD, 0 )
|
||||
MI_ENTRY("cs5", control, 0, CS5, CSIZE)
|
||||
MI_ENTRY("cs6", control, 0, CS6, CSIZE)
|
||||
MI_ENTRY("cs7", control, 0, CS7, CSIZE)
|
||||
MI_ENTRY("cs8", control, 0, CS8, CSIZE)
|
||||
MI_ENTRY("hupcl", control, REV, HUPCL, 0 )
|
||||
MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 )
|
||||
MI_ENTRY("cstopb", control, REV, CSTOPB, 0 )
|
||||
MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 )
|
||||
MI_ENTRY("clocal", control, REV, CLOCAL, 0 )
|
||||
#ifdef CRTSCTS
|
||||
MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ),
|
||||
MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 )
|
||||
#endif
|
||||
MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ),
|
||||
MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ),
|
||||
MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ),
|
||||
MI_ENTRY("parmrk", input, REV, PARMRK, 0 ),
|
||||
MI_ENTRY("inpck", input, REV, INPCK, 0 ),
|
||||
MI_ENTRY("istrip", input, REV, ISTRIP, 0 ),
|
||||
MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ),
|
||||
MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ),
|
||||
MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ),
|
||||
MI_ENTRY("ixon", input, REV, IXON, 0 ),
|
||||
MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ),
|
||||
MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ),
|
||||
MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 )
|
||||
MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 )
|
||||
MI_ENTRY("ignpar", input, REV, IGNPAR, 0 )
|
||||
MI_ENTRY("parmrk", input, REV, PARMRK, 0 )
|
||||
MI_ENTRY("inpck", input, REV, INPCK, 0 )
|
||||
MI_ENTRY("istrip", input, REV, ISTRIP, 0 )
|
||||
MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 )
|
||||
MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 )
|
||||
MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 )
|
||||
MI_ENTRY("ixon", input, REV, IXON, 0 )
|
||||
MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 )
|
||||
MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 )
|
||||
#ifdef IUCLC
|
||||
MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ),
|
||||
MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 )
|
||||
#endif
|
||||
#ifdef IXANY
|
||||
MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ),
|
||||
MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 )
|
||||
#endif
|
||||
#ifdef IMAXBEL
|
||||
MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ),
|
||||
MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 )
|
||||
#endif
|
||||
MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ),
|
||||
MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 )
|
||||
#ifdef OLCUC
|
||||
MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ),
|
||||
MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 )
|
||||
#endif
|
||||
#ifdef OCRNL
|
||||
MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ),
|
||||
MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 )
|
||||
#endif
|
||||
#ifdef ONLCR
|
||||
MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ),
|
||||
MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 )
|
||||
#endif
|
||||
#ifdef ONOCR
|
||||
MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ),
|
||||
MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 )
|
||||
#endif
|
||||
#ifdef ONLRET
|
||||
MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ),
|
||||
MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 )
|
||||
#endif
|
||||
#ifdef OFILL
|
||||
MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ),
|
||||
MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 )
|
||||
#endif
|
||||
#ifdef OFDEL
|
||||
MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ),
|
||||
MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 )
|
||||
#endif
|
||||
#ifdef NLDLY
|
||||
MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY),
|
||||
MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY),
|
||||
MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY)
|
||||
MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY)
|
||||
#endif
|
||||
#ifdef CRDLY
|
||||
MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY),
|
||||
MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY),
|
||||
MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY),
|
||||
MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY),
|
||||
MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY)
|
||||
MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY)
|
||||
MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY)
|
||||
MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY)
|
||||
#endif
|
||||
|
||||
#ifdef TABDLY
|
||||
MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY),
|
||||
MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY),
|
||||
MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY),
|
||||
MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY),
|
||||
MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY)
|
||||
MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY)
|
||||
MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY)
|
||||
MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY)
|
||||
#else
|
||||
# ifdef OXTABS
|
||||
MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ),
|
||||
MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef BSDLY
|
||||
MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY),
|
||||
MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY),
|
||||
MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY)
|
||||
MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY)
|
||||
#endif
|
||||
#ifdef VTDLY
|
||||
MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY),
|
||||
MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY),
|
||||
MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY)
|
||||
MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY)
|
||||
#endif
|
||||
#ifdef FFDLY
|
||||
MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY),
|
||||
MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY),
|
||||
MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY)
|
||||
MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY)
|
||||
#endif
|
||||
MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ),
|
||||
MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ),
|
||||
MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 )
|
||||
MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 )
|
||||
#ifdef IEXTEN
|
||||
MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ),
|
||||
MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 )
|
||||
#endif
|
||||
MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ),
|
||||
MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ),
|
||||
MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ),
|
||||
MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ),
|
||||
MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ),
|
||||
MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ),
|
||||
MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 )
|
||||
MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 )
|
||||
MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 )
|
||||
MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 )
|
||||
MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 )
|
||||
MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 )
|
||||
#ifdef XCASE
|
||||
MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ),
|
||||
MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 )
|
||||
#endif
|
||||
#ifdef TOSTOP
|
||||
MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ),
|
||||
MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 )
|
||||
#endif
|
||||
#ifdef ECHOPRT
|
||||
MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ),
|
||||
MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ),
|
||||
MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 )
|
||||
MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 )
|
||||
#endif
|
||||
#ifdef ECHOCTL
|
||||
MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ),
|
||||
MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ),
|
||||
MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 )
|
||||
MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 )
|
||||
#endif
|
||||
#ifdef ECHOKE
|
||||
MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ),
|
||||
MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ),
|
||||
MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 )
|
||||
MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 )
|
||||
#endif
|
||||
;
|
||||
|
||||
#undef MI_ENTRY
|
||||
#define MI_ENTRY(N,T,F,B,M) { T, F, M, B },
|
||||
|
||||
static const struct mode_info mode_info[] = {
|
||||
/* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */
|
||||
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("nl", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("ek", combination, OMIT, 0, 0 )
|
||||
MI_ENTRY("sane", combination, OMIT, 0, 0 )
|
||||
MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("raw", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("litout", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("crt", combination, OMIT, 0, 0 )
|
||||
MI_ENTRY("dec", combination, OMIT, 0, 0 )
|
||||
#ifdef IXANY
|
||||
MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 )
|
||||
#endif
|
||||
#if defined(TABDLY) || defined(OXTABS)
|
||||
MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 )
|
||||
#endif
|
||||
#if defined(XCASE) && defined(IUCLC) && defined(OLCUC)
|
||||
MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 )
|
||||
#endif
|
||||
MI_ENTRY("parenb", control, REV, PARENB, 0 )
|
||||
MI_ENTRY("parodd", control, REV, PARODD, 0 )
|
||||
MI_ENTRY("cs5", control, 0, CS5, CSIZE)
|
||||
MI_ENTRY("cs6", control, 0, CS6, CSIZE)
|
||||
MI_ENTRY("cs7", control, 0, CS7, CSIZE)
|
||||
MI_ENTRY("cs8", control, 0, CS8, CSIZE)
|
||||
MI_ENTRY("hupcl", control, REV, HUPCL, 0 )
|
||||
MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 )
|
||||
MI_ENTRY("cstopb", control, REV, CSTOPB, 0 )
|
||||
MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 )
|
||||
MI_ENTRY("clocal", control, REV, CLOCAL, 0 )
|
||||
#ifdef CRTSCTS
|
||||
MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 )
|
||||
#endif
|
||||
MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 )
|
||||
MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 )
|
||||
MI_ENTRY("ignpar", input, REV, IGNPAR, 0 )
|
||||
MI_ENTRY("parmrk", input, REV, PARMRK, 0 )
|
||||
MI_ENTRY("inpck", input, REV, INPCK, 0 )
|
||||
MI_ENTRY("istrip", input, REV, ISTRIP, 0 )
|
||||
MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 )
|
||||
MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 )
|
||||
MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 )
|
||||
MI_ENTRY("ixon", input, REV, IXON, 0 )
|
||||
MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 )
|
||||
MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 )
|
||||
#ifdef IUCLC
|
||||
MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 )
|
||||
#endif
|
||||
#ifdef IXANY
|
||||
MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 )
|
||||
#endif
|
||||
#ifdef IMAXBEL
|
||||
MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 )
|
||||
#endif
|
||||
MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 )
|
||||
#ifdef OLCUC
|
||||
MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 )
|
||||
#endif
|
||||
#ifdef OCRNL
|
||||
MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 )
|
||||
#endif
|
||||
#ifdef ONLCR
|
||||
MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 )
|
||||
#endif
|
||||
#ifdef ONOCR
|
||||
MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 )
|
||||
#endif
|
||||
#ifdef ONLRET
|
||||
MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 )
|
||||
#endif
|
||||
#ifdef OFILL
|
||||
MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 )
|
||||
#endif
|
||||
#ifdef OFDEL
|
||||
MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 )
|
||||
#endif
|
||||
#ifdef NLDLY
|
||||
MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY)
|
||||
MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY)
|
||||
#endif
|
||||
#ifdef CRDLY
|
||||
MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY)
|
||||
MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY)
|
||||
MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY)
|
||||
MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY)
|
||||
#endif
|
||||
|
||||
#ifdef TABDLY
|
||||
MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY)
|
||||
MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY)
|
||||
MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY)
|
||||
MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY)
|
||||
#else
|
||||
# ifdef OXTABS
|
||||
MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef BSDLY
|
||||
MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY)
|
||||
MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY)
|
||||
#endif
|
||||
#ifdef VTDLY
|
||||
MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY)
|
||||
MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY)
|
||||
#endif
|
||||
#ifdef FFDLY
|
||||
MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY)
|
||||
MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY)
|
||||
#endif
|
||||
MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 )
|
||||
MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 )
|
||||
#ifdef IEXTEN
|
||||
MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 )
|
||||
#endif
|
||||
MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 )
|
||||
MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 )
|
||||
MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 )
|
||||
MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 )
|
||||
MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 )
|
||||
MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 )
|
||||
#ifdef XCASE
|
||||
MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 )
|
||||
#endif
|
||||
#ifdef TOSTOP
|
||||
MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 )
|
||||
#endif
|
||||
#ifdef ECHOPRT
|
||||
MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 )
|
||||
MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 )
|
||||
#endif
|
||||
#ifdef ECHOCTL
|
||||
MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 )
|
||||
MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 )
|
||||
#endif
|
||||
#ifdef ECHOKE
|
||||
MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 )
|
||||
MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 )
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -322,15 +482,15 @@ enum {
|
||||
NUM_mode_info = ARRAY_SIZE(mode_info)
|
||||
};
|
||||
|
||||
|
||||
/* Control characters */
|
||||
struct control_info {
|
||||
const char name[7]; /* Name given on command line */
|
||||
const unsigned char saneval; /* Value to set for 'stty sane' */
|
||||
const unsigned char offset; /* Offset in c_cc */
|
||||
const uint8_t saneval; /* Value to set for 'stty sane' */
|
||||
const uint8_t offset; /* Offset in c_cc */
|
||||
};
|
||||
|
||||
enum {
|
||||
/* Must match control_info[] order! */
|
||||
/* Must match control_name[] and control_info[] order! */
|
||||
CIDX_intr = 0,
|
||||
CIDX_quit,
|
||||
CIDX_erase,
|
||||
@@ -368,60 +528,111 @@ enum {
|
||||
CIDX_time,
|
||||
};
|
||||
|
||||
static const struct control_info control_info[] = {
|
||||
{"intr", CINTR, VINTR},
|
||||
{"quit", CQUIT, VQUIT},
|
||||
{"erase", CERASE, VERASE},
|
||||
{"kill", CKILL, VKILL},
|
||||
{"eof", CEOF, VEOF},
|
||||
{"eol", CEOL, VEOL},
|
||||
#define CI_ENTRY(n,s,o) n "\0"
|
||||
|
||||
/* Name given on command line */
|
||||
static const char control_name[] =
|
||||
CI_ENTRY("intr", CINTR, VINTR )
|
||||
CI_ENTRY("quit", CQUIT, VQUIT )
|
||||
CI_ENTRY("erase", CERASE, VERASE )
|
||||
CI_ENTRY("kill", CKILL, VKILL )
|
||||
CI_ENTRY("eof", CEOF, VEOF )
|
||||
CI_ENTRY("eol", CEOL, VEOL )
|
||||
#ifdef VEOL2
|
||||
{"eol2", CEOL2, VEOL2},
|
||||
CI_ENTRY("eol2", CEOL2, VEOL2 )
|
||||
#endif
|
||||
#ifdef VSWTCH
|
||||
{"swtch", CSWTCH, VSWTCH},
|
||||
CI_ENTRY("swtch", CSWTCH, VSWTCH )
|
||||
#endif
|
||||
{"start", CSTART, VSTART},
|
||||
{"stop", CSTOP, VSTOP},
|
||||
{"susp", CSUSP, VSUSP},
|
||||
CI_ENTRY("start", CSTART, VSTART )
|
||||
CI_ENTRY("stop", CSTOP, VSTOP )
|
||||
CI_ENTRY("susp", CSUSP, VSUSP )
|
||||
#ifdef VDSUSP
|
||||
{"dsusp", CDSUSP, VDSUSP},
|
||||
CI_ENTRY("dsusp", CDSUSP, VDSUSP )
|
||||
#endif
|
||||
#ifdef VREPRINT
|
||||
{"rprnt", CRPRNT, VREPRINT},
|
||||
CI_ENTRY("rprnt", CRPRNT, VREPRINT)
|
||||
#endif
|
||||
#ifdef VWERASE
|
||||
{"werase", CWERASE, VWERASE},
|
||||
CI_ENTRY("werase", CWERASE, VWERASE )
|
||||
#endif
|
||||
#ifdef VLNEXT
|
||||
{"lnext", CLNEXT, VLNEXT},
|
||||
CI_ENTRY("lnext", CLNEXT, VLNEXT )
|
||||
#endif
|
||||
#ifdef VFLUSHO
|
||||
{"flush", CFLUSHO, VFLUSHO},
|
||||
CI_ENTRY("flush", CFLUSHO, VFLUSHO )
|
||||
#endif
|
||||
#ifdef VSTATUS
|
||||
{"status", CSTATUS, VSTATUS},
|
||||
CI_ENTRY("status", CSTATUS, VSTATUS )
|
||||
#endif
|
||||
/* These must be last because of the display routines */
|
||||
{"min", 1, VMIN},
|
||||
{"time", 0, VTIME},
|
||||
CI_ENTRY("min", 1, VMIN )
|
||||
CI_ENTRY("time", 0, VTIME )
|
||||
;
|
||||
|
||||
#undef CI_ENTRY
|
||||
#define CI_ENTRY(n,s,o) { s, o },
|
||||
|
||||
static const struct control_info control_info[] = {
|
||||
/* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */
|
||||
CI_ENTRY("intr", CINTR, VINTR )
|
||||
CI_ENTRY("quit", CQUIT, VQUIT )
|
||||
CI_ENTRY("erase", CERASE, VERASE )
|
||||
CI_ENTRY("kill", CKILL, VKILL )
|
||||
CI_ENTRY("eof", CEOF, VEOF )
|
||||
CI_ENTRY("eol", CEOL, VEOL )
|
||||
#ifdef VEOL2
|
||||
CI_ENTRY("eol2", CEOL2, VEOL2 )
|
||||
#endif
|
||||
#ifdef VSWTCH
|
||||
CI_ENTRY("swtch", CSWTCH, VSWTCH )
|
||||
#endif
|
||||
CI_ENTRY("start", CSTART, VSTART )
|
||||
CI_ENTRY("stop", CSTOP, VSTOP )
|
||||
CI_ENTRY("susp", CSUSP, VSUSP )
|
||||
#ifdef VDSUSP
|
||||
CI_ENTRY("dsusp", CDSUSP, VDSUSP )
|
||||
#endif
|
||||
#ifdef VREPRINT
|
||||
CI_ENTRY("rprnt", CRPRNT, VREPRINT)
|
||||
#endif
|
||||
#ifdef VWERASE
|
||||
CI_ENTRY("werase", CWERASE, VWERASE )
|
||||
#endif
|
||||
#ifdef VLNEXT
|
||||
CI_ENTRY("lnext", CLNEXT, VLNEXT )
|
||||
#endif
|
||||
#ifdef VFLUSHO
|
||||
CI_ENTRY("flush", CFLUSHO, VFLUSHO )
|
||||
#endif
|
||||
#ifdef VSTATUS
|
||||
CI_ENTRY("status", CSTATUS, VSTATUS )
|
||||
#endif
|
||||
/* These must be last because of the display routines */
|
||||
CI_ENTRY("min", 1, VMIN )
|
||||
CI_ENTRY("time", 0, VTIME )
|
||||
};
|
||||
|
||||
enum {
|
||||
NUM_control_info = ARRAY_SIZE(control_info)
|
||||
};
|
||||
|
||||
/* The width of the screen, for output wrapping */
|
||||
unsigned max_col = 80; /* default */
|
||||
|
||||
struct globals {
|
||||
const char *device_name; // = bb_msg_standard_input;
|
||||
/* The width of the screen, for output wrapping */
|
||||
unsigned max_col; // = 80;
|
||||
/* Current position, to know when to wrap */
|
||||
unsigned current_col;
|
||||
char buf[10];
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() \
|
||||
do { \
|
||||
G.device_name = bb_msg_standard_input; \
|
||||
G.max_col = 80; \
|
||||
} while (0)
|
||||
|
||||
static const char *device_name = bb_msg_standard_input;
|
||||
|
||||
/* Return a string that is the printable representation of character CH */
|
||||
/* Adapted from 'cat' by Torbjorn Granlund */
|
||||
@@ -454,7 +665,7 @@ static const char *visible(unsigned ch)
|
||||
|
||||
static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
|
||||
{
|
||||
static const unsigned char tcflag_offsets[] ALIGN1 = {
|
||||
static const uint8_t tcflag_offsets[] ALIGN1 = {
|
||||
offsetof(struct termios, c_cflag), /* control */
|
||||
offsetof(struct termios, c_iflag), /* input */
|
||||
offsetof(struct termios, c_oflag), /* output */
|
||||
@@ -484,12 +695,12 @@ static void set_speed_or_die(enum speed_setting type, const char *const arg,
|
||||
|
||||
static ATTRIBUTE_NORETURN void perror_on_device_and_die(const char *fmt)
|
||||
{
|
||||
bb_perror_msg_and_die(fmt, device_name);
|
||||
bb_perror_msg_and_die(fmt, G.device_name);
|
||||
}
|
||||
|
||||
static void perror_on_device(const char *fmt)
|
||||
{
|
||||
bb_perror_msg(fmt, device_name);
|
||||
bb_perror_msg(fmt, G.device_name);
|
||||
}
|
||||
|
||||
/* Print format string MESSAGE and optional args.
|
||||
@@ -511,7 +722,7 @@ static void wrapf(const char *message, ...)
|
||||
if (G.current_col > 0) {
|
||||
G.current_col++;
|
||||
if (buf[0] != '\n') {
|
||||
if (G.current_col + buflen >= max_col) {
|
||||
if (G.current_col + buflen >= G.max_col) {
|
||||
bb_putchar('\n');
|
||||
G.current_col = 0;
|
||||
} else
|
||||
@@ -526,7 +737,7 @@ static void wrapf(const char *message, ...)
|
||||
|
||||
static void set_window_size(const int rows, const int cols)
|
||||
{
|
||||
struct winsize win = { 0, 0, 0, 0};
|
||||
struct winsize win = { 0, 0, 0, 0 };
|
||||
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win)) {
|
||||
if (errno != EINVAL) {
|
||||
@@ -569,20 +780,14 @@ static const struct suffix_mult stty_suffixes[] = {
|
||||
|
||||
static const struct mode_info *find_mode(const char *name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < NUM_mode_info; ++i)
|
||||
if (!strcmp(name, mode_info[i].name))
|
||||
return &mode_info[i];
|
||||
return 0;
|
||||
int i = index_in_strings(mode_name, name);
|
||||
return i >= 0 ? &mode_info[i] : NULL;
|
||||
}
|
||||
|
||||
static const struct control_info *find_control(const char *name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < NUM_control_info; ++i)
|
||||
if (!strcmp(name, control_info[i].name))
|
||||
return &control_info[i];
|
||||
return 0;
|
||||
int i = index_in_strings(control_name, name);
|
||||
return i >= 0 ? &control_info[i] : NULL;
|
||||
}
|
||||
|
||||
enum {
|
||||
@@ -704,7 +909,7 @@ static void do_display(const struct termios *mode, const int all)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
wrapf("%s = %s;", control_info[i].name,
|
||||
wrapf("%s = %s;", nth_string(control_name, i),
|
||||
visible(mode->c_cc[control_info[i].offset]));
|
||||
}
|
||||
#if VEOF == VMIN
|
||||
@@ -726,12 +931,13 @@ static void do_display(const struct termios *mode, const int all)
|
||||
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
|
||||
if ((*bitsp & mask) == mode_info[i].bits) {
|
||||
if (all || (mode_info[i].flags & SANE_UNSET))
|
||||
wrapf("%s", mode_info[i].name);
|
||||
wrapf("-%s"+1, nth_string(mode_name, i));
|
||||
} else {
|
||||
if ((all && mode_info[i].flags & REV) ||
|
||||
(!all &&
|
||||
(mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)))
|
||||
wrapf("-%s", mode_info[i].name);
|
||||
if ((all && mode_info[i].flags & REV)
|
||||
|| (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV))
|
||||
) {
|
||||
wrapf("-%s", nth_string(mode_name, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (G.current_col) wrapf("\n");
|
||||
@@ -861,8 +1067,8 @@ static void set_mode(const struct mode_info *info, int reversed,
|
||||
mode->c_oflag &= ~OPOST;
|
||||
}
|
||||
} else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) {
|
||||
if ((info->name[0] == 'r' && reversed)
|
||||
|| (info->name[0] == 'c' && !reversed)
|
||||
if ((info == &mode_info[IDX_raw] && reversed)
|
||||
|| (info == &mode_info[IDX_cooked] && !reversed)
|
||||
) {
|
||||
/* Cooked mode */
|
||||
mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;
|
||||
@@ -944,11 +1150,12 @@ static void set_control_char_or_die(const struct control_info *info,
|
||||
mode->c_cc[info->offset] = value;
|
||||
}
|
||||
|
||||
#define STTY_require_set_attr (1<<0)
|
||||
#define STTY_speed_was_set (1<<1)
|
||||
#define STTY_verbose_output (1<<2)
|
||||
#define STTY_recoverable_output (1<<3)
|
||||
#define STTY_noargs (1<<4)
|
||||
#define STTY_require_set_attr (1 << 0)
|
||||
#define STTY_speed_was_set (1 << 1)
|
||||
#define STTY_verbose_output (1 << 2)
|
||||
#define STTY_recoverable_output (1 << 3)
|
||||
#define STTY_noargs (1 << 4)
|
||||
|
||||
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int stty_main(int argc, char **argv)
|
||||
{
|
||||
@@ -959,6 +1166,8 @@ int stty_main(int argc, char **argv)
|
||||
int stty_state;
|
||||
int k;
|
||||
|
||||
INIT_G();
|
||||
|
||||
stty_state = STTY_noargs;
|
||||
output_func = do_display;
|
||||
|
||||
@@ -1086,8 +1295,8 @@ int stty_main(int argc, char **argv)
|
||||
/* Now it is safe to start doing things */
|
||||
if (file_name) {
|
||||
int fd, fdflags;
|
||||
device_name = file_name;
|
||||
fd = xopen(device_name, O_RDONLY | O_NONBLOCK);
|
||||
G.device_name = file_name;
|
||||
fd = xopen(G.device_name, O_RDONLY | O_NONBLOCK);
|
||||
if (fd != STDIN_FILENO) {
|
||||
dup2(fd, STDIN_FILENO);
|
||||
close(fd);
|
||||
@@ -1105,7 +1314,7 @@ int stty_main(int argc, char **argv)
|
||||
perror_on_device_and_die("%s");
|
||||
|
||||
if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
|
||||
get_terminal_width_height(STDOUT_FILENO, &max_col, NULL);
|
||||
get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);
|
||||
output_func(&mode, display_all);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+314
-276
@@ -23,7 +23,11 @@
|
||||
#include "libbb.h"
|
||||
#include <setjmp.h>
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
/* test_main() is called from shells, and we need to be extra careful here.
|
||||
* This is true regardless of PREFER_APPLETS and STANDALONE_SHELL
|
||||
* state. */
|
||||
|
||||
|
||||
/* test(1) accepts the following grammar:
|
||||
@@ -85,12 +89,12 @@ enum token {
|
||||
RPAREN,
|
||||
OPERAND
|
||||
};
|
||||
#define is_int_op(a) (((unsigned char)((a) - INTEQ)) <= 5)
|
||||
#define is_str_op(a) (((unsigned char)((a) - STREZ)) <= 5)
|
||||
#define is_file_op(a) (((unsigned char)((a) - FILNT)) <= 2)
|
||||
#define is_int_op(a) (((unsigned char)((a) - INTEQ)) <= 5)
|
||||
#define is_str_op(a) (((unsigned char)((a) - STREZ)) <= 5)
|
||||
#define is_file_op(a) (((unsigned char)((a) - FILNT)) <= 2)
|
||||
#define is_file_access(a) (((unsigned char)((a) - FILRD)) <= 2)
|
||||
#define is_file_type(a) (((unsigned char)((a) - FILREG)) <= 5)
|
||||
#define is_file_bit(a) (((unsigned char)((a) - FILSUID)) <= 2)
|
||||
#define is_file_type(a) (((unsigned char)((a) - FILREG)) <= 5)
|
||||
#define is_file_bit(a) (((unsigned char)((a) - FILSUID)) <= 2)
|
||||
enum token_types {
|
||||
UNOP,
|
||||
BINOP,
|
||||
@@ -153,98 +157,35 @@ typedef int64_t arith_t;
|
||||
typedef int arith_t;
|
||||
#endif
|
||||
|
||||
/* Cannot eliminate these static data (do the G trick)
|
||||
* because of test_main usage from other applets */
|
||||
static char **t_wp;
|
||||
static const struct t_op *t_wp_op;
|
||||
static gid_t *group_array;
|
||||
static int ngroups;
|
||||
static jmp_buf leaving;
|
||||
|
||||
static enum token t_lex(char *s);
|
||||
static arith_t oexpr(enum token n);
|
||||
static arith_t aexpr(enum token n);
|
||||
static arith_t nexpr(enum token n);
|
||||
static int binop(void);
|
||||
/* We try to minimize both static and stack usage. */
|
||||
struct statics {
|
||||
char **t_wp;
|
||||
const struct t_op *t_wp_op;
|
||||
gid_t *group_array;
|
||||
int ngroups;
|
||||
jmp_buf leaving;
|
||||
};
|
||||
|
||||
/* Make it reside in writable memory, yet make compiler understand
|
||||
* that it is not going to change. */
|
||||
static struct statics *const ptr_to_statics __attribute__ ((section (".data")));
|
||||
|
||||
#define S (*ptr_to_statics)
|
||||
#define t_wp (S.t_wp )
|
||||
#define t_wp_op (S.t_wp_op )
|
||||
#define group_array (S.group_array )
|
||||
#define ngroups (S.ngroups )
|
||||
#define leaving (S.leaving )
|
||||
|
||||
#define INIT_S() do { \
|
||||
(*(struct statics**)&ptr_to_statics) = xzalloc(sizeof(S)); \
|
||||
} while (0)
|
||||
#define DEINIT_S() do { \
|
||||
free(ptr_to_statics); \
|
||||
} while (0)
|
||||
|
||||
static arith_t primary(enum token n);
|
||||
static int filstat(char *nm, enum token mode);
|
||||
static arith_t getn(const char *s);
|
||||
/* UNUSED
|
||||
static int newerf(const char *f1, const char *f2);
|
||||
static int olderf(const char *f1, const char *f2);
|
||||
static int equalf(const char *f1, const char *f2);
|
||||
*/
|
||||
static int test_eaccess(char *path, int mode);
|
||||
static int is_a_group_member(gid_t gid);
|
||||
static void initialize_group_array(void);
|
||||
|
||||
int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
const char *arg0;
|
||||
bool _off;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if (arg0[0] == '[') {
|
||||
--argc;
|
||||
if (!arg0[1]) { /* "[" ? */
|
||||
if (NOT_LONE_CHAR(argv[argc], ']')) {
|
||||
bb_error_msg("missing ]");
|
||||
return 2;
|
||||
}
|
||||
} else { /* assuming "[[" */
|
||||
if (strcmp(argv[argc], "]]") != 0) {
|
||||
bb_error_msg("missing ]]");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
|
||||
res = setjmp(leaving);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
/* resetting ngroups is probably unnecessary. it will
|
||||
* force a new call to getgroups(), which prevents using
|
||||
* group data fetched during a previous call. but the
|
||||
* only way the group data could be stale is if there's
|
||||
* been an intervening call to setgroups(), and this
|
||||
* isn't likely in the case of a shell. paranoia
|
||||
* prevails...
|
||||
*/
|
||||
ngroups = 0;
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
if (argc == 1)
|
||||
return 1;
|
||||
if (argc == 2)
|
||||
return *argv[1] == '\0';
|
||||
//assert(argc);
|
||||
/* remember if we saw argc==4 which wants *no* '!' test */
|
||||
_off = argc - 4;
|
||||
if (_off ?
|
||||
(LONE_CHAR(argv[1], '!'))
|
||||
: (argv[1][0] != '!' || argv[1][1] != '\0'))
|
||||
{
|
||||
if (argc == 3)
|
||||
return *argv[2] != '\0';
|
||||
|
||||
t_lex(argv[2 + _off]);
|
||||
if (t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[1 + _off];
|
||||
return binop() == _off;
|
||||
}
|
||||
}
|
||||
t_wp = &argv[1];
|
||||
res = !oexpr(t_lex(*t_wp));
|
||||
|
||||
if (*t_wp != NULL && *++t_wp != NULL) {
|
||||
bb_error_msg("%s: unknown operand", *t_wp);
|
||||
return 2;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void syntax(const char *op, const char *msg) ATTRIBUTE_NORETURN;
|
||||
static void syntax(const char *op, const char *msg)
|
||||
@@ -257,69 +198,82 @@ static void syntax(const char *op, const char *msg)
|
||||
longjmp(leaving, 2);
|
||||
}
|
||||
|
||||
static arith_t oexpr(enum token n)
|
||||
/* atoi with error detection */
|
||||
//XXX: FIXME: duplicate of existing libbb function?
|
||||
static arith_t getn(const char *s)
|
||||
{
|
||||
arith_t res;
|
||||
char *p;
|
||||
#if ENABLE_FEATURE_TEST_64
|
||||
long long r;
|
||||
#else
|
||||
long r;
|
||||
#endif
|
||||
|
||||
res = aexpr(n);
|
||||
if (t_lex(*++t_wp) == BOR) {
|
||||
return oexpr(t_lex(*++t_wp)) || res;
|
||||
}
|
||||
t_wp--;
|
||||
return res;
|
||||
errno = 0;
|
||||
#if ENABLE_FEATURE_TEST_64
|
||||
r = strtoll(s, &p, 10);
|
||||
#else
|
||||
r = strtol(s, &p, 10);
|
||||
#endif
|
||||
|
||||
if (errno != 0)
|
||||
syntax(s, "out of range");
|
||||
|
||||
if (*(skip_whitespace(p)))
|
||||
syntax(s, "bad number");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static arith_t aexpr(enum token n)
|
||||
/* UNUSED
|
||||
static int newerf(const char *f1, const char *f2)
|
||||
{
|
||||
arith_t res;
|
||||
struct stat b1, b2;
|
||||
|
||||
res = nexpr(n);
|
||||
if (t_lex(*++t_wp) == BAND)
|
||||
return aexpr(t_lex(*++t_wp)) && res;
|
||||
t_wp--;
|
||||
return res;
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 && b1.st_mtime > b2.st_mtime);
|
||||
}
|
||||
|
||||
static arith_t nexpr(enum token n)
|
||||
static int olderf(const char *f1, const char *f2)
|
||||
{
|
||||
if (n == UNOT)
|
||||
return !nexpr(t_lex(*++t_wp));
|
||||
return primary(n);
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 && b1.st_mtime < b2.st_mtime);
|
||||
}
|
||||
|
||||
static arith_t primary(enum token n)
|
||||
static int equalf(const char *f1, const char *f2)
|
||||
{
|
||||
arith_t res;
|
||||
struct stat b1, b2;
|
||||
|
||||
if (n == EOI) {
|
||||
syntax(NULL, "argument expected");
|
||||
}
|
||||
if (n == LPAREN) {
|
||||
res = oexpr(t_lex(*++t_wp));
|
||||
if (t_lex(*++t_wp) != RPAREN)
|
||||
syntax(NULL, "closing paren expected");
|
||||
return res;
|
||||
}
|
||||
if (t_wp_op && t_wp_op->op_type == UNOP) {
|
||||
/* unary expression */
|
||||
if (*++t_wp == NULL)
|
||||
syntax(t_wp_op->op_text, "argument expected");
|
||||
if (n == STREZ)
|
||||
return t_wp[0][0] == '\0';
|
||||
if (n == STRNZ)
|
||||
return t_wp[0][0] != '\0';
|
||||
if (n == FILTT)
|
||||
return isatty(getn(*t_wp));
|
||||
return filstat(*t_wp, n);
|
||||
}
|
||||
|
||||
t_lex(t_wp[1]);
|
||||
if (t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
return binop();
|
||||
}
|
||||
|
||||
return t_wp[0][0] != '\0';
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static enum token t_lex(char *s)
|
||||
{
|
||||
const struct t_op *op;
|
||||
|
||||
t_wp_op = NULL;
|
||||
if (s == NULL) {
|
||||
return EOI;
|
||||
}
|
||||
|
||||
op = ops;
|
||||
do {
|
||||
if (strcmp(s, op->op_text) == 0) {
|
||||
t_wp_op = op;
|
||||
return op->op_num;
|
||||
}
|
||||
op++;
|
||||
} while (op < ops + ARRAY_SIZE(ops));
|
||||
|
||||
return OPERAND;
|
||||
}
|
||||
|
||||
|
||||
static int binop(void)
|
||||
{
|
||||
@@ -381,6 +335,80 @@ static int binop(void)
|
||||
return 1; /* NOTREACHED */
|
||||
}
|
||||
|
||||
|
||||
static void initialize_group_array(void)
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
if (ngroups > 0) {
|
||||
/* FIXME: ash tries so hard to not die on OOM,
|
||||
* and we spoil it with just one xrealloc here */
|
||||
/* We realloc, because test_main can be entered repeatedly by shell.
|
||||
* Testcase (ash): 'while true; do test -x some_file; done'
|
||||
* and watch top. (some_file must have owner != you) */
|
||||
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
|
||||
getgroups(ngroups, group_array);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Return non-zero if GID is one that we have in our groups list. */
|
||||
//XXX: FIXME: duplicate of existing libbb function?
|
||||
// see toplevel TODO file:
|
||||
// possible code duplication ingroup() and is_a_group_member()
|
||||
static int is_a_group_member(gid_t gid)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Short-circuit if possible, maybe saving a call to getgroups(). */
|
||||
if (gid == getgid() || gid == getegid())
|
||||
return 1;
|
||||
|
||||
if (ngroups == 0)
|
||||
initialize_group_array();
|
||||
|
||||
/* Search through the list looking for GID. */
|
||||
for (i = 0; i < ngroups; i++)
|
||||
if (gid == group_array[i])
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Do the same thing access(2) does, but use the effective uid and gid,
|
||||
and don't make the mistake of telling root that any file is
|
||||
executable. */
|
||||
static int test_eaccess(char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
unsigned int euid = geteuid();
|
||||
|
||||
if (stat(path, &st) < 0)
|
||||
return -1;
|
||||
|
||||
if (euid == 0) {
|
||||
/* Root can read or write any file. */
|
||||
if (mode != X_OK)
|
||||
return 0;
|
||||
|
||||
/* Root can execute any file that has any one of the execute
|
||||
bits set. */
|
||||
if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (st.st_uid == euid) /* owner */
|
||||
mode <<= 6;
|
||||
else if (is_a_group_member(st.st_gid))
|
||||
mode <<= 3;
|
||||
|
||||
if (st.st_mode & mode)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int filstat(char *nm, enum token mode)
|
||||
{
|
||||
struct stat s;
|
||||
@@ -453,147 +481,157 @@ static int filstat(char *nm, enum token mode)
|
||||
return 1; /* NOTREACHED */
|
||||
}
|
||||
|
||||
static enum token t_lex(char *s)
|
||||
{
|
||||
const struct t_op *op;
|
||||
|
||||
t_wp_op = NULL;
|
||||
if (s == NULL) {
|
||||
return EOI;
|
||||
static arith_t nexpr(enum token n)
|
||||
{
|
||||
if (n == UNOT)
|
||||
return !nexpr(t_lex(*++t_wp));
|
||||
return primary(n);
|
||||
}
|
||||
|
||||
|
||||
static arith_t aexpr(enum token n)
|
||||
{
|
||||
arith_t res;
|
||||
|
||||
res = nexpr(n);
|
||||
if (t_lex(*++t_wp) == BAND)
|
||||
return aexpr(t_lex(*++t_wp)) && res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static arith_t oexpr(enum token n)
|
||||
{
|
||||
arith_t res;
|
||||
|
||||
res = aexpr(n);
|
||||
if (t_lex(*++t_wp) == BOR) {
|
||||
return oexpr(t_lex(*++t_wp)) || res;
|
||||
}
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static arith_t primary(enum token n)
|
||||
{
|
||||
arith_t res;
|
||||
|
||||
if (n == EOI) {
|
||||
syntax(NULL, "argument expected");
|
||||
}
|
||||
if (n == LPAREN) {
|
||||
res = oexpr(t_lex(*++t_wp));
|
||||
if (t_lex(*++t_wp) != RPAREN)
|
||||
syntax(NULL, "closing paren expected");
|
||||
return res;
|
||||
}
|
||||
if (t_wp_op && t_wp_op->op_type == UNOP) {
|
||||
/* unary expression */
|
||||
if (*++t_wp == NULL)
|
||||
syntax(t_wp_op->op_text, "argument expected");
|
||||
if (n == STREZ)
|
||||
return t_wp[0][0] == '\0';
|
||||
if (n == STRNZ)
|
||||
return t_wp[0][0] != '\0';
|
||||
if (n == FILTT)
|
||||
return isatty(getn(*t_wp));
|
||||
return filstat(*t_wp, n);
|
||||
}
|
||||
|
||||
op = ops;
|
||||
do {
|
||||
if (strcmp(s, op->op_text) == 0) {
|
||||
t_wp_op = op;
|
||||
return op->op_num;
|
||||
t_lex(t_wp[1]);
|
||||
if (t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
return binop();
|
||||
}
|
||||
|
||||
return t_wp[0][0] != '\0';
|
||||
}
|
||||
|
||||
|
||||
int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
const char *arg0;
|
||||
bool negate = 0;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if (arg0[0] == '[') {
|
||||
--argc;
|
||||
if (!arg0[1]) { /* "[" ? */
|
||||
if (NOT_LONE_CHAR(argv[argc], ']')) {
|
||||
bb_error_msg("missing ]");
|
||||
return 2;
|
||||
}
|
||||
} else { /* assuming "[[" */
|
||||
if (strcmp(argv[argc], "]]") != 0) {
|
||||
bb_error_msg("missing ]]");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
op++;
|
||||
} while (op < ops + ARRAY_SIZE(ops));
|
||||
|
||||
return OPERAND;
|
||||
}
|
||||
|
||||
/* atoi with error detection */
|
||||
//XXX: FIXME: duplicate of existing libbb function?
|
||||
static arith_t getn(const char *s)
|
||||
{
|
||||
char *p;
|
||||
#if ENABLE_FEATURE_TEST_64
|
||||
long long r;
|
||||
#else
|
||||
long r;
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
#if ENABLE_FEATURE_TEST_64
|
||||
r = strtoll(s, &p, 10);
|
||||
#else
|
||||
r = strtol(s, &p, 10);
|
||||
#endif
|
||||
|
||||
if (errno != 0)
|
||||
syntax(s, "out of range");
|
||||
|
||||
if (*(skip_whitespace(p)))
|
||||
syntax(s, "bad number");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* UNUSED
|
||||
static int newerf(const char *f1, const char *f2)
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 && b1.st_mtime > b2.st_mtime);
|
||||
}
|
||||
|
||||
static int olderf(const char *f1, const char *f2)
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 && b1.st_mtime < b2.st_mtime);
|
||||
}
|
||||
|
||||
static int equalf(const char *f1, const char *f2)
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
|
||||
}
|
||||
*/
|
||||
|
||||
/* Do the same thing access(2) does, but use the effective uid and gid,
|
||||
and don't make the mistake of telling root that any file is
|
||||
executable. */
|
||||
static int test_eaccess(char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
unsigned int euid = geteuid();
|
||||
|
||||
if (stat(path, &st) < 0)
|
||||
return -1;
|
||||
|
||||
if (euid == 0) {
|
||||
/* Root can read or write any file. */
|
||||
if (mode != X_OK)
|
||||
return 0;
|
||||
|
||||
/* Root can execute any file that has any one of the execute
|
||||
bits set. */
|
||||
if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||
return 0;
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
|
||||
if (st.st_uid == euid) /* owner */
|
||||
mode <<= 6;
|
||||
else if (is_a_group_member(st.st_gid))
|
||||
mode <<= 3;
|
||||
/* We must do DEINIT_S() prior to returning */
|
||||
INIT_S();
|
||||
|
||||
if (st.st_mode & mode)
|
||||
return 0;
|
||||
res = setjmp(leaving);
|
||||
if (res)
|
||||
goto ret;
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* resetting ngroups is probably unnecessary. it will
|
||||
* force a new call to getgroups(), which prevents using
|
||||
* group data fetched during a previous call. but the
|
||||
* only way the group data could be stale is if there's
|
||||
* been an intervening call to setgroups(), and this
|
||||
* isn't likely in the case of a shell. paranoia
|
||||
* prevails...
|
||||
*/
|
||||
ngroups = 0;
|
||||
|
||||
static void initialize_group_array(void)
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
if (ngroups > 0) {
|
||||
/* FIXME: ash tries so hard to not die on OOM,
|
||||
* and we spoil it with just one xrealloc here */
|
||||
/* We realloc, because test_main can be entered repeatedly by shell.
|
||||
* Testcase (ash): 'while true; do test -x some_file; done'
|
||||
* and watch top. (some_file must have owner != you) */
|
||||
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
|
||||
getgroups(ngroups, group_array);
|
||||
//argc--;
|
||||
argv++;
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
if (!argv[0]) { /* "test" */
|
||||
res = 1;
|
||||
goto ret;
|
||||
}
|
||||
if (LONE_CHAR(argv[0], '!') && argv[1]) {
|
||||
negate = 1;
|
||||
//argc--;
|
||||
argv++;
|
||||
}
|
||||
if (!argv[1]) { /* "test [!] arg" */
|
||||
res = (*argv[0] == '\0');
|
||||
goto ret;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
t_lex(argv[1]);
|
||||
if (t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
t_wp = &argv[0];
|
||||
res = (binop() == 0);
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return non-zero if GID is one that we have in our groups list. */
|
||||
//XXX: FIXME: duplicate of existing libbb function?
|
||||
// see toplevel TODO file:
|
||||
// possible code duplication ingroup() and is_a_group_member()
|
||||
static int is_a_group_member(gid_t gid)
|
||||
{
|
||||
int i;
|
||||
/* Some complex expression. Undo '!' removal */
|
||||
if (negate) {
|
||||
negate = 0;
|
||||
//argc++;
|
||||
argv--;
|
||||
}
|
||||
t_wp = &argv[0];
|
||||
res = !oexpr(t_lex(*t_wp));
|
||||
|
||||
/* Short-circuit if possible, maybe saving a call to getgroups(). */
|
||||
if (gid == getgid() || gid == getegid())
|
||||
return 1;
|
||||
|
||||
if (ngroups == 0)
|
||||
initialize_group_array();
|
||||
|
||||
/* Search through the list looking for GID. */
|
||||
for (i = 0; i < ngroups; i++)
|
||||
if (gid == group_array[i])
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
if (*t_wp != NULL && *++t_wp != NULL) {
|
||||
bb_error_msg("%s: unknown operand", *t_wp);
|
||||
res = 2;
|
||||
}
|
||||
ret:
|
||||
DEINIT_S();
|
||||
return negate ? !res : res;
|
||||
}
|
||||
+2
-1
@@ -26,8 +26,9 @@ int touch_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int status = EXIT_SUCCESS;
|
||||
int flags = getopt32(argv, "c");
|
||||
int flags = getopt32(argv, "cf");
|
||||
|
||||
flags &= 1; /* ignoring -f (BSD compat thingy) */
|
||||
argv += optind;
|
||||
|
||||
if (!*argv) {
|
||||
|
||||
+79
-76
@@ -22,10 +22,6 @@
|
||||
|
||||
#define ASCII 0377
|
||||
|
||||
#define TR_OPT_complement (1<<0)
|
||||
#define TR_OPT_delete (1<<1)
|
||||
#define TR_OPT_squeeze_reps (1<<2)
|
||||
|
||||
static void map(char *pvector,
|
||||
unsigned char *string1, unsigned int string1_len,
|
||||
unsigned char *string2, unsigned int string2_len)
|
||||
@@ -42,19 +38,46 @@ static void map(char *pvector,
|
||||
}
|
||||
|
||||
/* supported constructs:
|
||||
* Ranges, e.g., [0-9] ==> 0123456789
|
||||
* Escapes, e.g., \a ==> Control-G
|
||||
* Character classes, e.g. [:upper:] ==> A ... Z
|
||||
* Ranges, e.g., 0-9 ==> 0123456789
|
||||
* Ranges, e.g., [0-9] ==> 0123456789
|
||||
* Escapes, e.g., \a ==> Control-G
|
||||
* Character classes, e.g. [:upper:] ==> A...Z
|
||||
* Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?)
|
||||
*/
|
||||
static unsigned int expand(const char *arg, char *buffer)
|
||||
{
|
||||
char *buffer_start = buffer;
|
||||
unsigned i; /* XXX: FIXME: use unsigned char? */
|
||||
unsigned i; /* can't be unsigned char: must be able to hold 256 */
|
||||
unsigned char ac;
|
||||
|
||||
while (*arg) {
|
||||
if (*arg == '\\') {
|
||||
arg++;
|
||||
*buffer++ = bb_process_escape_sequence(&arg);
|
||||
continue;
|
||||
}
|
||||
if (arg[1] == '-') { /* "0-9..." */
|
||||
ac = arg[2];
|
||||
if (ac == '\0') { /* "0-": copy verbatim */
|
||||
*buffer++ = *arg++; /* copy '0' */
|
||||
continue; /* next iter will copy '-' and stop */
|
||||
}
|
||||
i = *arg;
|
||||
while (i <= ac) /* ok: i is unsigned _int_ */
|
||||
*buffer++ = i++;
|
||||
arg += 3; /* skip 0-9 */
|
||||
continue;
|
||||
}
|
||||
if (*arg == '[') { /* "[xyz..." */
|
||||
arg++;
|
||||
i = *arg++;
|
||||
/* "[xyz...", i=x, arg points to y */
|
||||
if (ENABLE_FEATURE_TR_CLASSES && i == ':') {
|
||||
#define CLO ":]\0"
|
||||
static const char classes[] ALIGN1 =
|
||||
"alpha"CLO "alnum"CLO "digit"CLO "lower"CLO "upper"CLO "space"CLO
|
||||
"blank"CLO "punct"CLO "cntrl"CLO;
|
||||
static const char classes[] ALIGN1 =
|
||||
"alpha"CLO "alnum"CLO "digit"CLO
|
||||
"lower"CLO "upper"CLO "space"CLO
|
||||
"blank"CLO "punct"CLO "cntrl"CLO;
|
||||
#define CLASS_invalid 0 /* we increment the retval */
|
||||
#define CLASS_alpha 1
|
||||
#define CLASS_alnum 2
|
||||
@@ -68,27 +91,9 @@ static unsigned int expand(const char *arg, char *buffer)
|
||||
//#define CLASS_xdigit 10
|
||||
//#define CLASS_graph 11
|
||||
//#define CLASS_print 12
|
||||
while (*arg) {
|
||||
if (*arg == '\\') {
|
||||
arg++;
|
||||
*buffer++ = bb_process_escape_sequence(&arg);
|
||||
} else if (*(arg+1) == '-') {
|
||||
ac = *(arg+2);
|
||||
if (ac == 0) {
|
||||
*buffer++ = *arg++;
|
||||
continue;
|
||||
}
|
||||
i = *arg;
|
||||
while (i <= ac)
|
||||
*buffer++ = i++;
|
||||
arg += 3; /* Skip the assumed a-z */
|
||||
} else if (*arg == '[') {
|
||||
arg++;
|
||||
i = *arg++;
|
||||
if (ENABLE_FEATURE_TR_CLASSES && i == ':') {
|
||||
smalluint j;
|
||||
{ /* not really pretty.. */
|
||||
char *tmp = xstrndup(arg, 7); // warning: xdigit needs 8, not 7
|
||||
char *tmp = xstrndup(arg, 7); // warning: xdigit would need 8, not 7
|
||||
j = index_in_strings(classes, tmp) + 1;
|
||||
free(tmp);
|
||||
}
|
||||
@@ -115,10 +120,9 @@ static unsigned int expand(const char *arg, char *buffer)
|
||||
*buffer++ = ' ';
|
||||
}
|
||||
if (j == CLASS_punct || j == CLASS_cntrl) {
|
||||
for (i = 0; i <= ASCII; i++)
|
||||
if ((j == CLASS_punct &&
|
||||
isprint(i) && (!isalnum(i)) && (!isspace(i))) ||
|
||||
(j == CLASS_cntrl && iscntrl(i)))
|
||||
for (i = '\0'; i <= ASCII; i++)
|
||||
if ((j == CLASS_punct && isprint(i) && !isalnum(i) && !isspace(i))
|
||||
|| (j == CLASS_cntrl && iscntrl(i)))
|
||||
*buffer++ = i;
|
||||
}
|
||||
if (j == CLASS_invalid) {
|
||||
@@ -128,22 +132,26 @@ static unsigned int expand(const char *arg, char *buffer)
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ENABLE_FEATURE_TR_EQUIV && i == '=') {
|
||||
*buffer++ = *arg;
|
||||
arg += 3; /* Skip the closing =] */
|
||||
/* "[xyz...", i=x, arg points to y */
|
||||
if (ENABLE_FEATURE_TR_EQUIV && i == '=') { /* [=CHAR=] */
|
||||
*buffer++ = *arg; /* copy CHAR */
|
||||
arg += 3; /* skip CHAR=] */
|
||||
continue;
|
||||
}
|
||||
if (*arg++ != '-') {
|
||||
if (*arg != '-') { /* not [x-...] - copy verbatim */
|
||||
*buffer++ = '[';
|
||||
arg -= 2;
|
||||
continue;
|
||||
arg--; /* points to x */
|
||||
continue; /* copy all, including eventual ']' */
|
||||
}
|
||||
/* [x-y...] */
|
||||
arg++;
|
||||
ac = *arg++;
|
||||
while (i <= ac)
|
||||
*buffer++ = i++;
|
||||
arg++; /* Skip the assumed ']' */
|
||||
} else
|
||||
*buffer++ = *arg++;
|
||||
arg++; /* skip the assumed ']' */
|
||||
continue;
|
||||
}
|
||||
*buffer++ = *arg++;
|
||||
}
|
||||
return (buffer - buffer_start);
|
||||
}
|
||||
@@ -154,7 +162,7 @@ static int complement(char *buffer, int buffer_len)
|
||||
char conv[ASCII + 2];
|
||||
|
||||
ix = 0;
|
||||
for (i = 0; i <= ASCII; i++) {
|
||||
for (i = '\0'; i <= ASCII; i++) {
|
||||
for (j = 0; j < buffer_len; j++)
|
||||
if (buffer[j] == i)
|
||||
break;
|
||||
@@ -168,44 +176,39 @@ static int complement(char *buffer, int buffer_len)
|
||||
int tr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int tr_main(int argc, char **argv)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
int output_length = 0, input_length;
|
||||
int idx = 1;
|
||||
int i;
|
||||
smalluint flags = 0;
|
||||
size_t read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1;
|
||||
RESERVE_CONFIG_UBUFFER(output, BUFSIZ);
|
||||
RESERVE_CONFIG_BUFFER(vector, ASCII+1);
|
||||
RESERVE_CONFIG_BUFFER(invec, ASCII+1);
|
||||
RESERVE_CONFIG_BUFFER(outvec, ASCII+1);
|
||||
smalluint flags;
|
||||
ssize_t read_chars = 0;
|
||||
size_t in_index = 0, out_index = 0;
|
||||
unsigned last = UCHAR_MAX + 1; /* not equal to any char */
|
||||
unsigned char coded, c;
|
||||
unsigned char *output = xmalloc(BUFSIZ);
|
||||
char *vector = xzalloc((ASCII+1) * 3);
|
||||
char *invec = vector + (ASCII+1);
|
||||
char *outvec = vector + (ASCII+1) * 2;
|
||||
|
||||
#define TR_OPT_complement (1 << 0)
|
||||
#define TR_OPT_delete (1 << 1)
|
||||
#define TR_OPT_squeeze_reps (1 << 2)
|
||||
|
||||
flags = getopt32(argv, "+cds"); /* '+': stop at first non-option */
|
||||
argv += optind;
|
||||
|
||||
if (argc > 1 && argv[idx][0] == '-') {
|
||||
for (ptr = (unsigned char *) &argv[idx][1]; *ptr; ptr++) {
|
||||
if (*ptr == 'c')
|
||||
flags |= TR_OPT_complement;
|
||||
else if (*ptr == 'd')
|
||||
flags |= TR_OPT_delete;
|
||||
else if (*ptr == 's')
|
||||
flags |= TR_OPT_squeeze_reps;
|
||||
else
|
||||
bb_show_usage();
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
for (i = 0; i <= ASCII; i++) {
|
||||
vector[i] = i;
|
||||
invec[i] = outvec[i] = FALSE;
|
||||
/*invec[i] = outvec[i] = FALSE; - done by xzalloc */
|
||||
}
|
||||
|
||||
#define tr_buf bb_common_bufsiz1
|
||||
if (argv[idx] != NULL) {
|
||||
input_length = expand(argv[idx++], tr_buf);
|
||||
if (*argv != NULL) {
|
||||
input_length = expand(*argv++, tr_buf);
|
||||
if (flags & TR_OPT_complement)
|
||||
input_length = complement(tr_buf, input_length);
|
||||
if (argv[idx] != NULL) {
|
||||
if (*argv[idx] == '\0')
|
||||
if (*argv) {
|
||||
if (argv[0][0] == '\0')
|
||||
bb_error_msg_and_die("STRING2 cannot be empty");
|
||||
output_length = expand(argv[idx], output);
|
||||
output_length = expand(*argv, output);
|
||||
map(vector, tr_buf, input_length, output, output_length);
|
||||
}
|
||||
for (i = 0; i < input_length; i++)
|
||||
@@ -221,10 +224,10 @@ int tr_main(int argc, char **argv)
|
||||
xwrite(STDOUT_FILENO, (char *)output, out_index);
|
||||
out_index = 0;
|
||||
}
|
||||
read_chars = read(STDIN_FILENO, tr_buf, BUFSIZ);
|
||||
read_chars = safe_read(STDIN_FILENO, tr_buf, BUFSIZ);
|
||||
if (read_chars <= 0) {
|
||||
if (write(STDOUT_FILENO, (char *)output, out_index) != out_index)
|
||||
bb_perror_msg(bb_msg_write_error);
|
||||
if (read_chars < 0)
|
||||
bb_perror_msg_and_die(bb_msg_read_error);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
in_index = 0;
|
||||
@@ -233,8 +236,8 @@ int tr_main(int argc, char **argv)
|
||||
coded = vector[c];
|
||||
if ((flags & TR_OPT_delete) && invec[c])
|
||||
continue;
|
||||
if ((flags & TR_OPT_squeeze_reps) && last == coded &&
|
||||
(invec[c] || outvec[coded]))
|
||||
if ((flags & TR_OPT_squeeze_reps) && last == coded
|
||||
&& (invec[c] || outvec[coded]))
|
||||
continue;
|
||||
output[out_index++] = last = coded;
|
||||
}
|
||||
|
||||
+10
-10
@@ -16,6 +16,7 @@
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -H, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
|
||||
|
||||
#include "libbb.h"
|
||||
#include <utmp.h>
|
||||
@@ -46,31 +47,30 @@ int who_main(int argc, char **argv)
|
||||
struct utmp *ut;
|
||||
struct stat st;
|
||||
char *name;
|
||||
unsigned opt;
|
||||
|
||||
if (argc > 1) {
|
||||
bb_show_usage();
|
||||
}
|
||||
opt_complementary = "=0";
|
||||
opt = getopt32(argv, "a");
|
||||
|
||||
setutent();
|
||||
printf("USER TTY IDLE TIME HOST\n");
|
||||
printf("USER TTY IDLE TIME HOST\n");
|
||||
while ((ut = getutent()) != NULL) {
|
||||
if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
|
||||
time_t thyme = ut->ut_tv.tv_sec;
|
||||
|
||||
if (ut->ut_user[0] && (opt || ut->ut_type == USER_PROCESS)) {
|
||||
/* ut->ut_line is device name of tty - "/dev/" */
|
||||
name = concat_path_file("/dev", ut->ut_line);
|
||||
str6[0] = '?';
|
||||
str6[1] = '\0';
|
||||
if (stat(name, &st) == 0)
|
||||
idle_string(str6, st.st_atime);
|
||||
printf("%-10s %-8s %-9s %-14.14s %s\n",
|
||||
/* 15 chars for time: Nov 10 19:33:20 */
|
||||
printf("%-10s %-8s %-9s %-15.15s %s\n",
|
||||
ut->ut_user, ut->ut_line, str6,
|
||||
ctime(&thyme) + 4, ut->ut_host);
|
||||
ctime(&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(name);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
endutent();
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+2
-2
@@ -22,11 +22,11 @@ int which_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* We shouldn't do this. Ever. Not our business.
|
||||
/* This matches what is seen on e.g. ubuntu
|
||||
* "which" there is a shell script */
|
||||
if (!getenv("PATH")) {
|
||||
putenv((char*)bb_PATH_root_path);
|
||||
}
|
||||
*/
|
||||
|
||||
while (--argc > 0) {
|
||||
argv++;
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
<br>-<a href=http://busybox.net/~vda/linld/>linld</a>
|
||||
<br>-<a href=http://busybox.net/~vda/init_vs_runsv.html>init must die</a>
|
||||
<br>-<a href=http://busybox.net/~vda/no_ifup.txt>no ifup</a>
|
||||
<br>-<a href=http://busybox.net/~vda/unscd/>unscd</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
@@ -1,6 +1,100 @@
|
||||
<!--#include file="header.html" -->
|
||||
|
||||
<ul>
|
||||
<li><b>24 December 2007 -- BusyBox 1.9.0 (unstable)</b>
|
||||
<p><a href=http://busybox.net/downloads/busybox-1.9.0.tar.bz2>BusyBox 1.9.0</a>.
|
||||
(<a href=http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_9_stable/>svn</a>,
|
||||
<a href=http://busybox.net/downloads/fixes-1.9.0/>patches</a>,
|
||||
<a href=http://busybox.net/fix.html>how to add a patch</a>)</p>
|
||||
|
||||
<p>Sizes of busybox-1.8.2 and busybox-1.9.0 (with almost full config, static uclibc build):<pre>
|
||||
text data bss dec hex filename
|
||||
792796 978 9724 803498 c42aa busybox-1.8.2
|
||||
783803 683 7508 791994 c15ba busybox-1.9.0
|
||||
</pre>
|
||||
<p>Top 10 stack users:<pre>
|
||||
busybox-1.8.2: busybox-1.9.0:
|
||||
input_tab 10428 echo_dg 4116
|
||||
umount_main 8252 bb_full_fd_action 4112
|
||||
rtnl_talk 8240 discard_dg 4096
|
||||
xrtnl_dump_filter 8240 echo_stream 4096
|
||||
sendMTFValues 5316 discard_stream 4096
|
||||
mainSort 4700 find_list_entry2 4096
|
||||
mkfs_minix_main 4288 readlink_main 4096
|
||||
grave 4260 ipaddr_list_or_flush 3900
|
||||
unix_do_one 4156 iproute_list_or_flush 3680
|
||||
parse_prompt 4132 insmod_main 3152
|
||||
</pre>
|
||||
|
||||
<p>lash is deleted from this release. hush can be configured down to almost
|
||||
the same size, but it is significantly less buggy. It even works
|
||||
on NOMMU machines (interactive mode and backticks are not working on NOMMU,
|
||||
though). "lash" applet is still available, but it runs hush.
|
||||
|
||||
<p>init has some changes in this release, please report if it causes
|
||||
problems for you.
|
||||
|
||||
<p>Changes since previous release:
|
||||
<ul>
|
||||
<li>Build system improvements
|
||||
<li>Testsuite additions
|
||||
<li>Stack size reductions, code size reductions, data/bss reductions
|
||||
<li>An option to prefer IPv4 address if host has both
|
||||
<li>New applets: hd, sestatus
|
||||
<li>Removed applets: lash
|
||||
<li>hush: fixed a few bugs, wired up echo and test to be builtins
|
||||
<li>init: simplify forking of children
|
||||
<li>getty: special handling of '#' and '@' is removed
|
||||
<li>[su]login: sanitize environment if called by non-root
|
||||
<li>udhcpc: support "bad" servers which send oversized packets
|
||||
(Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>)
|
||||
<li>udhcpc: -O option allows to specify which options to ask tor
|
||||
(Stefan Hellermann <stefan at the2masters.de>)
|
||||
<li>udhcpc: optionally check whether given IP is really free (by ARP ping)
|
||||
(Jonas Danielsson <jonas.danielsson at axis.com>)
|
||||
<li>vi: now handles files with unlimited line length
|
||||
<li>vi: speedup for huge line lengths
|
||||
<li>vi: Del key works
|
||||
<li>sed: support GNUism '\t'
|
||||
<li>cp/mv/install: optionally use bigger buffer for bulk copying
|
||||
<li>line editing: don't eat stack like crazy
|
||||
<li>passwd: follows symlinked /etc/passwd
|
||||
<li>renice: accepts priority with +N too
|
||||
<li>netstat: wide output mode
|
||||
<li>nameif: extended matching (Nico Erfurth <masta at perlgolf.de>)
|
||||
<li>test: become NOFORK applet
|
||||
<li>find: -iname (Alexander Griesser <alexander.griesser at lkh-vil.or.at>)
|
||||
<li>df: -i option (show inode info) (Pascal Bellard <pascal.bellard at ads-lu.com>)
|
||||
<li>hexdump: -R option (Pascal Bellard <pascal.bellard at ads-lu.com>)
|
||||
</ul>
|
||||
|
||||
<p><a href=http://busybox.net/~vda/HOWTO_bbox_with_uclibc.txt>How to build static busybox against uclibc</a>
|
||||
|
||||
|
||||
<li><b>23 November 2007 -- BusyBox 1.8.2 (stable), BusyBox 1.7.4 (stable)</b>
|
||||
<p><a href=http://busybox.net/downloads/busybox-1.8.2.tar.bz2>BusyBox 1.8.2</a>.
|
||||
(<a href=http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_8_stable/>svn</a>,
|
||||
<a href=http://busybox.net/downloads/fixes-1.8.2/>patches</a>,
|
||||
<a href=http://busybox.net/fix.html>how to add a patch</a>)</p>
|
||||
<p><a href=http://busybox.net/downloads/busybox-1.7.4.tar.bz2>BusyBox 1.7.4</a>.
|
||||
(<a href=http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_7_stable/>svn</a>,
|
||||
<a href=http://busybox.net/downloads/fixes-1.7.4/>patches</a>,
|
||||
<a href=http://busybox.net/fix.html>how to add a patch</a>)</p>
|
||||
|
||||
<p>These are bugfix-only releases.
|
||||
1.8.2 contains fixes for inetd, lash, tar, tr, and build system.
|
||||
1.7.4 contains a fix for inetd.</p>
|
||||
</li>
|
||||
|
||||
<li><b>9 November 2007 -- BusyBox 1.8.1 (stable)</b>
|
||||
<p><a href=http://busybox.net/downloads/busybox-1.8.1.tar.bz2>BusyBox 1.8.1</a>.
|
||||
(<a href=http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_8_stable/>svn</a>,
|
||||
<a href=http://busybox.net/downloads/fixes-1.8.1/>patches</a>,
|
||||
<a href=http://busybox.net/fix.html>how to add a patch</a>)</p>
|
||||
|
||||
<p>This is a bugfix-only release, with fixes to login (PAM), modprobe, syslogd, telnetd, unzip.</p>
|
||||
</li>
|
||||
|
||||
<li><b>4 November 2007 -- BusyBox 1.8.0 (unstable)</b>
|
||||
<p><a href=http://busybox.net/downloads/busybox-1.8.0.tar.bz2>BusyBox 1.8.0</a>.
|
||||
(<a href=http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_8_stable/>svn</a>,
|
||||
@@ -53,8 +147,8 @@ Equivalent .config, i386 uclibc static builds:
|
||||
<li>hdparm: reduce possibility of numeric overflow in -T
|
||||
<li>hdparm: simplify timing measurement
|
||||
<li>wget: -O FILE is allowed to overwrite existing file (compat)
|
||||
<li>wget: allow dots in header field names.
|
||||
<li>telnetd: add -K option to close sessions as soon as child exits.
|
||||
<li>wget: allow dots in header field names
|
||||
<li>telnetd: add -K option to close sessions as soon as child exits
|
||||
<li>telnetd: don't SIGKILL child when closing the session, kernel will send SIGHUP for us
|
||||
<li>ed: large cleanup, add line editing
|
||||
<li>hush: feeble attempt at making it more NOMMU-friendly
|
||||
@@ -93,7 +187,7 @@ Equivalent .config, i386 uclibc static builds:
|
||||
<li>runsv: do not use clock_gettime if !MONOTONIC_CLOCK
|
||||
<li>runsvdir: fix "linear wait time" bug
|
||||
<li>sulogin: remove alarm handling, it is redundant there
|
||||
<li>svlogd: compat: svlogd -tt should timestanp stderr too
|
||||
<li>svlogd: compat: svlogd -tt should timestamp stderr too
|
||||
<li>syslogd: bail out if you see null read from Unix socket
|
||||
<li>syslogd: do not need to poll(), we can just block in read()
|
||||
<li>tail: work correctly on /proc files (Kazuo TAKADA <kztakada at sm.sony.co.jp>)
|
||||
@@ -108,7 +202,6 @@ Equivalent .config, i386 uclibc static builds:
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p><a href=http://busybox.net/~vda/HOWTO_bbox_with_uclibc.txt>How to build static busybox against uclibc</a></p>
|
||||
</li>
|
||||
|
||||
<li><b>4 November 2007 -- BusyBox 1.7.3 (stable)</b>
|
||||
|
||||
@@ -11,8 +11,10 @@ Everybody loves to look at screenshots, so here is a live action screenshot of B
|
||||
<pre style="background-color: black; color: lightgreen; padding: 5px;
|
||||
font-family: monospace; font-size: smaller;" width="100">
|
||||
|
||||
$ ./busybox
|
||||
BusyBox v1.6.0.svn (2007-04-07 04:27:00 CEST) multi-call binary
|
||||
$ busybox
|
||||
BusyBox v1.8.0 (2007-11-04 15:42:38 GMT) multi-call binary
|
||||
Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.
|
||||
Licensed under GPLv2. See source distribution for full notice.
|
||||
|
||||
Usage: busybox [function] [arguments]...
|
||||
or: [function] [arguments]...
|
||||
@@ -24,39 +26,38 @@ Usage: busybox [function] [arguments]...
|
||||
|
||||
Currently defined functions:
|
||||
[, [[, addgroup, adduser, adjtimex, ar, arp, arping, ash,
|
||||
awk, basename, bunzip2, bzcat, cal, cat, catv, chattr,
|
||||
chgrp, chmod, chown, chpst, chroot, chvt, cksum, clear,
|
||||
cmp, comm, cp, cpio, crond, crontab, cut, date, dc, dd,
|
||||
deallocvt, delgroup, deluser, df, dhcprelay, diff, dirname,
|
||||
dmesg, dnsd, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dumpleases,
|
||||
echo, ed, egrep, eject, env, envdir, envuidgid, expr,
|
||||
fakeidentd, false, fbset, fdflush, fdformat, fdisk, fgrep,
|
||||
find, fold, free, freeramdisk, fsck, fsck.minix, ftpget,
|
||||
ftpput, fuser, getopt, getty, grep, gunzip, gzip, halt,
|
||||
hdparm, head, hexdump, hostid, hostname, httpd, hwclock,
|
||||
id, ifconfig, ifdown, ifup, inetd, init, insmod, install,
|
||||
ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule,
|
||||
iptunnel, kill, killall, killall5, klogd, lash, last,
|
||||
length, less, linux32, linux64, linuxrc, ln, loadfont,
|
||||
loadkmap, logger, login, logname, logread, losetup, ls,
|
||||
lsattr, lsmod, lzmacat, makedevs, md5sum, mdev, mesg,
|
||||
mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, modprobe,
|
||||
more, mount, mountpoint, msh, mt, mv, nameif, nc, netstat,
|
||||
nice, nmeter, nohup, nslookup, od, openvt, passwd, patch,
|
||||
pidof, ping, ping6, pipe_progress, pivot_root, poweroff,
|
||||
printenv, printf, ps, pwd, raidautorun, rdate, readahead,
|
||||
readlink, readprofile, realpath, reboot, renice, reset,
|
||||
resize, rm, rmdir, rmmod, route, rpm, rpm2cpio, run-parts,
|
||||
runlevel, runsv, runsvdir, rx, sed, seq, setarch, setconsole,
|
||||
setkeycodes, setlogcons, setsid, setuidgid, sha1sum, sleep,
|
||||
softlimit, sort, split, start-stop-daemon, stat, strings,
|
||||
stty, su, sulogin, sum, sv, svlogd, swapoff, swapon, switch_root,
|
||||
sync, sysctl, syslogd, tail, tar, tcpsvd, tee, telnet,
|
||||
telnetd, test, tftp, time, top, touch, traceroute, true,
|
||||
tty, udhcpc, udhcpd, udpsvd, umount, uname, uncompress,
|
||||
uniq, unix2dos, unlzma, unzip, uptime, usleep, uudecode,
|
||||
uuencode, vconfig, vi, vlock, watch, watchdog, wc, wget,
|
||||
which, who, whoami, xargs, yes, zcat, zcip
|
||||
awk, basename, bunzip2, bzcat, bzip2, cal, cat, catv, chattr,
|
||||
chgrp, chmod, chown, chpasswd, chpst, chroot, chrt, chvt,
|
||||
cksum, clear, cmp, comm, cp, cpio, crond, crontab, cryptpw,
|
||||
cut, date, dc, dd, deallocvt, delgroup, deluser, df, dhcprelay,
|
||||
diff, dirname, dmesg, dnsd, dos2unix, dpkg, du, dumpkmap,
|
||||
dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid,
|
||||
expand, expr, fakeidentd, false, fbset, fdflush, fdformat,
|
||||
fdisk, fgrep, find, fold, free, freeramdisk, fsck, fsck.minix,
|
||||
ftpget, ftpput, fuser, getopt, getty, grep, gunzip, gzip,
|
||||
hdparm, head, hexdump, hostid, hostname, httpd, hush, hwclock,
|
||||
id, ifconfig, inetd, insmod, install, ip, ipaddr, ipcalc,
|
||||
ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode,
|
||||
kill, killall, killall5, klogd, lash, last, length, less,
|
||||
linux32, linux64, ln, loadfont, loadkmap, logger, login, logname,
|
||||
logread, losetup, ls, lsattr, lsmod, lzmacat, md5sum, mdev,
|
||||
mesg, microcom, mkdir, mkfifo, mkfs.minix, mknod, mkswap,
|
||||
mktemp, modprobe, more, mount, mountpoint, msh, mt, mv, nameif,
|
||||
nc, netstat, nice, nmeter, nohup, nslookup, od, openvt, passwd,
|
||||
patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root,
|
||||
pkill, printenv, printf, ps, pscan, pwd, raidautorun, rdate,
|
||||
readlink, readprofile, realpath, renice, reset, resize, rm,
|
||||
rmdir, rmmod, route, rpm, rpm2cpio, run-parts, runlevel, runsv,
|
||||
runsvdir, rx, sed, seq, setarch, setconsole, setkeycodes,
|
||||
setlogcons, setsid, setuidgid, sha1sum, slattach, sleep, softlimit,
|
||||
sort, split, start-stop-daemon, stat, strings, stty, su, sulogin,
|
||||
sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl,
|
||||
syslogd, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp,
|
||||
time, top, touch, tr, traceroute, true, tty, ttysize, udhcpc,
|
||||
udhcpd, udpsvd, umount, uname, uncompress, unexpand, uniq,
|
||||
unix2dos, unlzma, unzip, uptime, usleep, uudecode, uuencode,
|
||||
vconfig, vi, vlock, watch, watchdog, wc, wget, which, who,
|
||||
whoami, xargs, yes, zcat, zcip
|
||||
|
||||
$ <span style="text-decoration:blink;">_</span>
|
||||
|
||||
|
||||
+476
@@ -0,0 +1,476 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html><head>
|
||||
<!-- saved from http://www.win.tue.nl/~aeb/linux/lk/lk-10.html -->
|
||||
<meta name="GENERATOR" content="SGML-Tools 1.0.9"><title>The Linux kernel: Processes</title>
|
||||
</head>
|
||||
<body>
|
||||
<hr>
|
||||
<h2><a name="s10">10. Processes</a></h2>
|
||||
|
||||
<p>Before looking at the Linux implementation, first a general Unix
|
||||
description of threads, processes, process groups and sessions.
|
||||
</p><p>A session contains a number of process groups, and a process group
|
||||
contains a number of processes, and a process contains a number
|
||||
of threads.
|
||||
</p><p>A session can have a controlling tty.
|
||||
At most one process group in a session can be a foreground process group.
|
||||
An interrupt character typed on a tty ("Teletype", i.e., terminal)
|
||||
causes a signal to be sent to all members of the foreground process group
|
||||
in the session (if any) that has that tty as controlling tty.
|
||||
</p><p>All these objects have numbers, and we have thread IDs, process IDs,
|
||||
process group IDs and session IDs.
|
||||
</p><p>
|
||||
</p><h2><a name="ss10.1">10.1 Processes</a>
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
</p><h3>Creation</h3>
|
||||
|
||||
<p>A new process is traditionally started using the <code>fork()</code>
|
||||
system call:
|
||||
</p><blockquote>
|
||||
<pre>pid_t p;
|
||||
|
||||
p = fork();
|
||||
if (p == (pid_t) -1)
|
||||
/* ERROR */
|
||||
else if (p == 0)
|
||||
/* CHILD */
|
||||
else
|
||||
/* PARENT */
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>This creates a child as a duplicate of its parent.
|
||||
Parent and child are identical in almost all respects.
|
||||
In the code they are distinguished by the fact that the parent
|
||||
learns the process ID of its child, while <code>fork()</code>
|
||||
returns 0 in the child. (It can find the process ID of its
|
||||
parent using the <code>getppid()</code> system call.)
|
||||
</p><p>
|
||||
</p><h3>Termination</h3>
|
||||
|
||||
<p>Normal termination is when the process does
|
||||
</p><blockquote>
|
||||
<pre>exit(n);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
or
|
||||
<blockquote>
|
||||
<pre>return n;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
from its <code>main()</code> procedure. It returns the single byte <code>n</code>
|
||||
to its parent.
|
||||
<p>Abnormal termination is usually caused by a signal.
|
||||
</p><p>
|
||||
</p><h3>Collecting the exit code. Zombies</h3>
|
||||
|
||||
<p>The parent does
|
||||
</p><blockquote>
|
||||
<pre>pid_t p;
|
||||
int status;
|
||||
|
||||
p = wait(&status);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
and collects two bytes:
|
||||
<p>
|
||||
<figure>
|
||||
<eps file="absent">
|
||||
<img src="ctty_files/exit_status.png">
|
||||
</eps>
|
||||
</figure></p><p>A process that has terminated but has not yet been waited for
|
||||
is a <i>zombie</i>. It need only store these two bytes:
|
||||
exit code and reason for termination.
|
||||
</p><p>On the other hand, if the parent dies first, <code>init</code> (process 1)
|
||||
inherits the child and becomes its parent.
|
||||
</p><p>
|
||||
</p><h3>Signals</h3>
|
||||
|
||||
<p>
|
||||
</p><h3>Stopping</h3>
|
||||
|
||||
<p>Some signals cause a process to stop:
|
||||
<code>SIGSTOP</code> (stop!),
|
||||
<code>SIGTSTP</code> (stop from tty: probably ^Z was typed),
|
||||
<code>SIGTTIN</code> (tty input asked by background process),
|
||||
<code>SIGTTOU</code> (tty output sent by background process, and this was
|
||||
disallowed by <code>stty tostop</code>).
|
||||
</p><p>Apart from ^Z there also is ^Y. The former stops the process
|
||||
when it is typed, the latter stops it when it is read.
|
||||
</p><p>Signals generated by typing the corresponding character on some tty
|
||||
are sent to all processes that are in the foreground process group
|
||||
of the session that has that tty as controlling tty. (Details below.)
|
||||
</p><p>If a process is being traced, every signal will stop it.
|
||||
</p><p>
|
||||
</p><h3>Continuing</h3>
|
||||
|
||||
<p><code>SIGCONT</code>: continue a stopped process.
|
||||
</p><p>
|
||||
</p><h3>Terminating</h3>
|
||||
|
||||
<p><code>SIGKILL</code> (die! now!),
|
||||
<code>SIGTERM</code> (please, go away),
|
||||
<code>SIGHUP</code> (modem hangup),
|
||||
<code>SIGINT</code> (^C),
|
||||
<code>SIGQUIT</code> (^\), etc.
|
||||
Many signals have as default action to kill the target.
|
||||
(Sometimes with an additional core dump, when such is
|
||||
allowed by rlimit.)
|
||||
The signals <code>SIGCHLD</code> and <code>SIGWINCH</code>
|
||||
are ignored by default.
|
||||
All except <code>SIGKILL</code> and <code>SIGSTOP</code> can be
|
||||
caught or ignored or blocked.
|
||||
For details, see <code>signal(7)</code>.
|
||||
</p><p>
|
||||
</p><h2><a name="ss10.2">10.2 Process groups</a>
|
||||
</h2>
|
||||
|
||||
<p>Every process is member of a unique <i>process group</i>,
|
||||
identified by its <i>process group ID</i>.
|
||||
(When the process is created, it becomes a member of the process group
|
||||
of its parent.)
|
||||
By convention, the process group ID of a process group
|
||||
equals the process ID of the first member of the process group,
|
||||
called the <i>process group leader</i>.
|
||||
A process finds the ID of its process group using the system call
|
||||
<code>getpgrp()</code>, or, equivalently, <code>getpgid(0)</code>.
|
||||
One finds the process group ID of process <code>p</code> using
|
||||
<code>getpgid(p)</code>.
|
||||
</p><p>One may use the command <code>ps j</code> to see PPID (parent process ID),
|
||||
PID (process ID), PGID (process group ID) and SID (session ID)
|
||||
of processes. With a shell that does not know about job control,
|
||||
like <code>ash</code>, each of its children will be in the same session
|
||||
and have the same process group as the shell. With a shell that knows
|
||||
about job control, like <code>bash</code>, the processes of one pipeline. like
|
||||
</p><blockquote>
|
||||
<pre>% cat paper | ideal | pic | tbl | eqn | ditroff > out
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
form a single process group.
|
||||
<p>
|
||||
</p><h3>Creation</h3>
|
||||
|
||||
<p>A process <code>pid</code> is put into the process group <code>pgid</code> by
|
||||
</p><blockquote>
|
||||
<pre>setpgid(pid, pgid);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
If <code>pgid == pid</code> or <code>pgid == 0</code> then this creates
|
||||
a new process group with process group leader <code>pid</code>.
|
||||
Otherwise, this puts <code>pid</code> into the already existing
|
||||
process group <code>pgid</code>.
|
||||
A zero <code>pid</code> refers to the current process.
|
||||
The call <code>setpgrp()</code> is equivalent to <code>setpgid(0,0)</code>.
|
||||
<p>
|
||||
</p><h3>Restrictions on setpgid()</h3>
|
||||
|
||||
<p>The calling process must be <code>pid</code> itself, or its parent,
|
||||
and the parent can only do this before <code>pid</code> has done
|
||||
<code>exec()</code>, and only when both belong to the same session.
|
||||
It is an error if process <code>pid</code> is a session leader
|
||||
(and this call would change its <code>pgid</code>).
|
||||
</p><p>
|
||||
</p><h3>Typical sequence</h3>
|
||||
|
||||
<p>
|
||||
</p><blockquote>
|
||||
<pre>p = fork();
|
||||
if (p == (pid_t) -1) {
|
||||
/* ERROR */
|
||||
} else if (p == 0) { /* CHILD */
|
||||
setpgid(0, pgid);
|
||||
...
|
||||
} else { /* PARENT */
|
||||
setpgid(p, pgid);
|
||||
...
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
This ensures that regardless of whether parent or child is scheduled
|
||||
first, the process group setting is as expected by both.
|
||||
<p>
|
||||
</p><h3>Signalling and waiting</h3>
|
||||
|
||||
<p>One can signal all members of a process group:
|
||||
</p><blockquote>
|
||||
<pre>killpg(pgrp, sig);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>One can wait for children in ones own process group:
|
||||
</p><blockquote>
|
||||
<pre>waitpid(0, &status, ...);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
or in a specified process group:
|
||||
<blockquote>
|
||||
<pre>waitpid(-pgrp, &status, ...);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
</p><h3>Foreground process group</h3>
|
||||
|
||||
<p>Among the process groups in a session at most one can be
|
||||
the <i>foreground process group</i> of that session.
|
||||
The tty input and tty signals (signals generated by ^C, ^Z, etc.)
|
||||
go to processes in this foreground process group.
|
||||
</p><p>A process can determine the foreground process group in its session
|
||||
using <code>tcgetpgrp(fd)</code>, where <code>fd</code> refers to its
|
||||
controlling tty. If there is none, this returns a random value
|
||||
larger than 1 that is not a process group ID.
|
||||
</p><p>A process can set the foreground process group in its session
|
||||
using <code>tcsetpgrp(fd,pgrp)</code>, where <code>fd</code> refers to its
|
||||
controlling tty, and <code>pgrp</code> is a process group in the
|
||||
its session, and this session still is associated to the controlling
|
||||
tty of the calling process.
|
||||
</p><p>How does one get <code>fd</code>? By definition, <code>/dev/tty</code>
|
||||
refers to the controlling tty, entirely independent of redirects
|
||||
of standard input and output. (There is also the function
|
||||
<code>ctermid()</code> to get the name of the controlling terminal.
|
||||
On a POSIX standard system it will return <code>/dev/tty</code>.)
|
||||
Opening the name of the
|
||||
controlling tty gives a file descriptor <code>fd</code>.
|
||||
</p><p>
|
||||
</p><h3>Background process groups</h3>
|
||||
|
||||
<p>All process groups in a session that are not foreground
|
||||
process group are <i>background process groups</i>.
|
||||
Since the user at the keyboard is interacting with foreground
|
||||
processes, background processes should stay away from it.
|
||||
When a background process reads from the terminal it gets
|
||||
a SIGTTIN signal. Normally, that will stop it, the job control shell
|
||||
notices and tells the user, who can say <code>fg</code> to continue
|
||||
this background process as a foreground process, and then this
|
||||
process can read from the terminal. But if the background process
|
||||
ignores or blocks the SIGTTIN signal, or if its process group
|
||||
is orphaned (see below), then the read() returns an EIO error,
|
||||
and no signal is sent. (Indeed, the idea is to tell the process
|
||||
that reading from the terminal is not allowed right now.
|
||||
If it wouldn't see the signal, then it will see the error return.)
|
||||
</p><p>When a background process writes to the terminal, it may get
|
||||
a SIGTTOU signal. May: namely, when the flag that this must happen
|
||||
is set (it is off by default). One can set the flag by
|
||||
</p><blockquote>
|
||||
<pre>% stty tostop
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
and clear it again by
|
||||
<blockquote>
|
||||
<pre>% stty -tostop
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
and inspect it by
|
||||
<blockquote>
|
||||
<pre>% stty -a
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
Again, if TOSTOP is set but the background process ignores or blocks
|
||||
the SIGTTOU signal, or if its process group is orphaned (see below),
|
||||
then the write() returns an EIO error, and no signal is sent.
|
||||
<p>
|
||||
</p><h3>Orphaned process groups</h3>
|
||||
|
||||
<p>The process group leader is the first member of the process group.
|
||||
It may terminate before the others, and then the process group is
|
||||
without leader.
|
||||
</p><p>A process group is called <i>orphaned</i> when <i>the
|
||||
parent of every member is either in the process group
|
||||
or outside the session</i>.
|
||||
In particular, the process group of the session leader
|
||||
is always orphaned.
|
||||
</p><p>If termination of a process causes a process group to become
|
||||
orphaned, and some member is stopped, then all are sent first SIGHUP
|
||||
and then SIGCONT.
|
||||
</p><p>The idea is that perhaps the parent of the process group leader
|
||||
is a job control shell. (In the same session but a different
|
||||
process group.) As long as this parent is alive, it can
|
||||
handle the stopping and starting of members in the process group.
|
||||
When it dies, there may be nobody to continue stopped processes.
|
||||
Therefore, these stopped processes are sent SIGHUP, so that they
|
||||
die unless they catch or ignore it, and then SIGCONT to continue them.
|
||||
</p><p>Note that the process group of the session leader is already
|
||||
orphaned, so no signals are sent when the session leader dies.
|
||||
</p><p>Note also that a process group can become orphaned in two ways
|
||||
by termination of a process: either it was a parent and not itself
|
||||
in the process group, or it was the last element of the process group
|
||||
with a parent outside but in the same session.
|
||||
Furthermore, that a process group can become orphaned
|
||||
other than by termination of a process, namely when some
|
||||
member is moved to a different process group.
|
||||
</p><p>
|
||||
</p><h2><a name="ss10.3">10.3 Sessions</a>
|
||||
</h2>
|
||||
|
||||
<p>Every process group is in a unique <i>session</i>.
|
||||
(When the process is created, it becomes a member of the session
|
||||
of its parent.)
|
||||
By convention, the session ID of a session
|
||||
equals the process ID of the first member of the session,
|
||||
called the <i>session leader</i>.
|
||||
A process finds the ID of its session using the system call
|
||||
<code>getsid()</code>.
|
||||
</p><p>Every session may have a <i>controlling tty</i>,
|
||||
that then also is called the controlling tty of each of
|
||||
its member processes.
|
||||
A file descriptor for the controlling tty is obtained by
|
||||
opening <code>/dev/tty</code>. (And when that fails, there was no
|
||||
controlling tty.) Given a file descriptor for the controlling tty,
|
||||
one may obtain the SID using <code>tcgetsid(fd)</code>.
|
||||
</p><p>A session is often set up by a login process. The terminal
|
||||
on which one is logged in then becomes the controlling tty
|
||||
of the session. All processes that are descendants of the
|
||||
login process will in general be members of the session.
|
||||
</p><p>
|
||||
</p><h3>Creation</h3>
|
||||
|
||||
<p>A new session is created by
|
||||
</p><blockquote>
|
||||
<pre>pid = setsid();
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
This is allowed only when the current process is not a process group leader.
|
||||
In order to be sure of that we fork first:
|
||||
<blockquote>
|
||||
<pre>p = fork();
|
||||
if (p) exit(0);
|
||||
pid = setsid();
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
The result is that the current process (with process ID <code>pid</code>)
|
||||
becomes session leader of a new session with session ID <code>pid</code>.
|
||||
Moreover, it becomes process group leader of a new process group.
|
||||
Both session and process group contain only the single process <code>pid</code>.
|
||||
Furthermore, this process has no controlling tty.
|
||||
<p>The restriction that the current process must not be a process group leader
|
||||
is needed: otherwise its PID serves as PGID of some existing process group
|
||||
and cannot be used as the PGID of a new process group.
|
||||
</p><p>
|
||||
</p><h3>Getting a controlling tty</h3>
|
||||
|
||||
<p>How does one get a controlling terminal? Nobody knows,
|
||||
this is a great mystery.
|
||||
</p><p>The System V approach is that the first tty opened by the process
|
||||
becomes its controlling tty.
|
||||
</p><p>The BSD approach is that one has to explicitly call
|
||||
</p><blockquote>
|
||||
<pre>ioctl(fd, TIOCSCTTY, 0/1);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
to get a controlling tty.
|
||||
<p>Linux tries to be compatible with both, as always, and this
|
||||
results in a very obscure complex of conditions. Roughly:
|
||||
</p><p>The <code>TIOCSCTTY</code> ioctl will give us a controlling tty,
|
||||
provided that (i) the current process is a session leader,
|
||||
and (ii) it does not yet have a controlling tty, and
|
||||
(iii) maybe the tty should not already control some other session;
|
||||
if it does it is an error if we aren't root, or we steal the tty
|
||||
if we are all-powerful.
|
||||
[vda: correction: third parameter controls this: if 1, we steal tty from
|
||||
any such session, if 0, we don't steal]
|
||||
</p><p>Opening some terminal will give us a controlling tty,
|
||||
provided that (i) the current process is a session leader, and
|
||||
(ii) it does not yet have a controlling tty, and
|
||||
(iii) the tty does not already control some other session, and
|
||||
(iv) the open did not have the <code>O_NOCTTY</code> flag, and
|
||||
(v) the tty is not the foreground VT, and
|
||||
(vi) the tty is not the console, and
|
||||
(vii) maybe the tty should not be master or slave pty.
|
||||
</p><p>
|
||||
</p><h3>Getting rid of a controlling tty</h3>
|
||||
|
||||
<p>If a process wants to continue as a daemon, it must detach itself
|
||||
from its controlling tty. Above we saw that <code>setsid()</code>
|
||||
will remove the controlling tty. Also the ioctl TIOCNOTTY does this.
|
||||
Moreover, in order not to get a controlling tty again as soon as it
|
||||
opens a tty, the process has to fork once more, to assure that it
|
||||
is not a session leader. Typical code fragment:
|
||||
</p><p>
|
||||
</p><pre> if ((fork()) != 0)
|
||||
exit(0);
|
||||
setsid();
|
||||
if ((fork()) != 0)
|
||||
exit(0);
|
||||
</pre>
|
||||
<p>See also <code>daemon(3)</code>.
|
||||
</p><p>
|
||||
</p><h3>Disconnect</h3>
|
||||
|
||||
<p>If the terminal goes away by modem hangup, and the line was not local,
|
||||
then a SIGHUP is sent to the session leader.
|
||||
Any further reads from the gone terminal return EOF.
|
||||
(Or possibly -1 with <code>errno</code> set to EIO.)
|
||||
</p><p>If the terminal is the slave side of a pseudotty, and the master side
|
||||
is closed (for the last time), then a SIGHUP is sent to the foreground
|
||||
process group of the slave side.
|
||||
</p><p>When the session leader dies, a SIGHUP is sent to all processes
|
||||
in the foreground process group. Moreover, the terminal stops being
|
||||
the controlling terminal of this session (so that it can become
|
||||
the controlling terminal of another session).
|
||||
</p><p>Thus, if the terminal goes away and the session leader is
|
||||
a job control shell, then it can handle things for its descendants,
|
||||
e.g. by sending them again a SIGHUP.
|
||||
If on the other hand the session leader is an innocent process
|
||||
that does not catch SIGHUP, it will die, and all foreground processes
|
||||
get a SIGHUP.
|
||||
</p><p>
|
||||
</p><h2><a name="ss10.4">10.4 Threads</a>
|
||||
</h2>
|
||||
|
||||
<p>A process can have several threads. New threads (with the same PID
|
||||
as the parent thread) are started using the <code>clone</code> system
|
||||
call using the <code>CLONE_THREAD</code> flag. Threads are distinguished
|
||||
by a <i>thread ID</i> (TID). An ordinary process has a single thread
|
||||
with TID equal to PID. The system call <code>gettid()</code> returns the
|
||||
TID. The system call <code>tkill()</code> sends a signal to a single thread.
|
||||
</p><p>Example: a process with two threads. Both only print PID and TID and exit.
|
||||
(Linux 2.4.19 or later.)
|
||||
</p><pre>% cat << EOF > gettid-demo.c
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#define CLONE_SIGHAND 0x00000800
|
||||
#define CLONE_THREAD 0x00010000
|
||||
#include <linux/unistd.h>
|
||||
#include <errno.h>
|
||||
_syscall0(pid_t,gettid)
|
||||
|
||||
int thread(void *p) {
|
||||
printf("thread: %d %d\n", gettid(), getpid());
|
||||
}
|
||||
|
||||
main() {
|
||||
unsigned char stack[4096];
|
||||
int i;
|
||||
|
||||
i = clone(thread, stack+2048, CLONE_THREAD | CLONE_SIGHAND, NULL);
|
||||
if (i == -1)
|
||||
perror("clone");
|
||||
else
|
||||
printf("clone returns %d\n", i);
|
||||
printf("parent: %d %d\n", gettid(), getpid());
|
||||
}
|
||||
EOF
|
||||
% cc -o gettid-demo gettid-demo.c
|
||||
% ./gettid-demo
|
||||
clone returns 21826
|
||||
parent: 21825 21825
|
||||
thread: 21826 21825
|
||||
%
|
||||
</pre>
|
||||
<p>
|
||||
</p><p>
|
||||
</p><hr>
|
||||
|
||||
</body></html>
|
||||
@@ -665,6 +665,12 @@ static void execute(const char *type, const char *device, const char *mntpt,
|
||||
for (i = num_args+1; i < argc; i++)
|
||||
free(argv[i]);
|
||||
|
||||
/* No pid, so don't record an instance */
|
||||
if (pid < 0) {
|
||||
free(inst);
|
||||
return;
|
||||
}
|
||||
|
||||
inst->pid = pid;
|
||||
inst->prog = argv[0];
|
||||
inst->type = xstrdup(type);
|
||||
|
||||
@@ -161,7 +161,7 @@ void usage(char *prog)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_dev_iterate iter;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_dev dev;
|
||||
int c, ret;
|
||||
char *tmp;
|
||||
|
||||
@@ -364,7 +364,7 @@ void usage(char *prog)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_tag_iterate iter;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_dev dev;
|
||||
int c, ret, found;
|
||||
int flags = BLKID_DEV_FIND;
|
||||
|
||||
+14
-5
@@ -90,14 +90,23 @@ config VI
|
||||
you may wish to use something else.
|
||||
|
||||
config FEATURE_VI_MAX_LEN
|
||||
int "Maximum line length in vi"
|
||||
int "Maximum screen width in vi"
|
||||
range 256 16384
|
||||
default 1024
|
||||
default 4096
|
||||
depends on VI
|
||||
help
|
||||
vi uses on-stack buffers for intermediate line buffers.
|
||||
You may want to decrease this parameter if your target machine
|
||||
benefits from smaller stack usage.
|
||||
Contrary to what you may think, this is not eating much.
|
||||
Make it smaller than 4k only if you are very limited on memory.
|
||||
|
||||
config FEATURE_VI_8BIT
|
||||
bool "Allow vi to display 8-bit chars (otherwise shows dots)"
|
||||
default y
|
||||
depends on VI
|
||||
help
|
||||
If your terminal can display characters with high bit set,
|
||||
you may want to enable this. Note: vi is not Unicode-capable.
|
||||
If your terminal combines several 8-bit bytes into one character
|
||||
(as in Unicode mode), this will not work properly.
|
||||
|
||||
config FEATURE_VI_COLON
|
||||
bool "Enable \":\" colon commands (no \"ex\" mode)"
|
||||
|
||||
+5
-2
@@ -588,7 +588,9 @@ static void check(FILE * f1, FILE * f2)
|
||||
while (1) {
|
||||
ctold++;
|
||||
ctnew++;
|
||||
if ((c = getc(f1)) != (d = getc(f2))) {
|
||||
c = getc(f1);
|
||||
d = getc(f2);
|
||||
if (c != d) {
|
||||
J[i] = 0;
|
||||
if (c != '\n' && c != EOF)
|
||||
ctold += skipline(f1);
|
||||
@@ -668,7 +670,8 @@ static void fetch(long *f, int a, int b, FILE * lb, int ch)
|
||||
}
|
||||
col = 0;
|
||||
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
|
||||
if ((c = getc(lb)) == EOF) {
|
||||
c = getc(lb);
|
||||
if (c == EOF) {
|
||||
printf("\n\\ No newline at end of file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-10
@@ -71,12 +71,6 @@ static char *extract_filename(char *line, int patch_level)
|
||||
return xstrdup(filename_start_ptr);
|
||||
}
|
||||
|
||||
static int file_doesnt_exist(const char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
return stat(filename, &statbuf);
|
||||
}
|
||||
|
||||
int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int patch_main(int argc, char **argv)
|
||||
{
|
||||
@@ -84,7 +78,8 @@ int patch_main(int argc, char **argv)
|
||||
char *patch_line;
|
||||
int ret;
|
||||
FILE *patch_file = NULL;
|
||||
|
||||
struct stat saved_stat;
|
||||
|
||||
{
|
||||
char *p, *i;
|
||||
ret = getopt32(argv, "p:i:", &p, &i);
|
||||
@@ -134,8 +129,9 @@ int patch_main(int argc, char **argv)
|
||||
}
|
||||
new_filename = extract_filename(patch_line, patch_level);
|
||||
free(patch_line);
|
||||
|
||||
if (file_doesnt_exist(new_filename)) {
|
||||
|
||||
/* Get access rights from the file to be patched, -1 file does not exist */
|
||||
if (stat(new_filename, &saved_stat)) {
|
||||
char *line_ptr;
|
||||
/* Create leading directories */
|
||||
line_ptr = strrchr(new_filename, '/');
|
||||
@@ -155,9 +151,10 @@ int patch_main(int argc, char **argv)
|
||||
backup_filename);
|
||||
}
|
||||
dst_stream = xfopen(new_filename, "w");
|
||||
fchmod(fileno(dst_stream), saved_stat.st_mode);
|
||||
}
|
||||
|
||||
if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) {
|
||||
if ((backup_filename == NULL) || stat(original_filename, &saved_stat)) {
|
||||
src_stream = NULL;
|
||||
} else {
|
||||
if (strcmp(original_filename, new_filename) == 0) {
|
||||
|
||||
+9
-5
@@ -173,7 +173,7 @@ static void cleanup_outname(void)
|
||||
if (G.outname) unlink(G.outname);
|
||||
}
|
||||
|
||||
/* strdup, replacing "\n" with '\n', and "\delimiter" with 'delimiter' */
|
||||
/* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */
|
||||
|
||||
static void parse_escapes(char *dest, const char *string, int len, char from, char to)
|
||||
{
|
||||
@@ -188,9 +188,10 @@ static void parse_escapes(char *dest, const char *string, int len, char from, ch
|
||||
}
|
||||
*dest++ = string[i++];
|
||||
}
|
||||
/* TODO: is it safe wrt a string with trailing '\\' ? */
|
||||
*dest++ = string[i++];
|
||||
}
|
||||
*dest = 0;
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
static char *copy_parsing_escapes(const char *string, int len)
|
||||
@@ -198,6 +199,8 @@ static char *copy_parsing_escapes(const char *string, int len)
|
||||
char *dest = xmalloc(len + 1);
|
||||
|
||||
parse_escapes(dest, string, len, 'n', '\n');
|
||||
/* GNU sed also recognizes \t */
|
||||
parse_escapes(dest, dest, strlen(dest), 't', '\t');
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -205,7 +208,7 @@ static char *copy_parsing_escapes(const char *string, int len)
|
||||
/*
|
||||
* index_of_next_unescaped_regexp_delim - walks left to right through a string
|
||||
* beginning at a specified index and returns the index of the next regular
|
||||
* expression delimiter (typically a forward * slash ('/')) not preceded by
|
||||
* expression delimiter (typically a forward slash ('/')) not preceded by
|
||||
* a backslash ('\'). A negative delimiter disables square bracket checking.
|
||||
*/
|
||||
static int index_of_next_unescaped_regexp_delim(int delimiter, const char *str)
|
||||
@@ -425,7 +428,8 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
|
||||
break;
|
||||
}
|
||||
sed_cmd->string = xstrdup(cmdstr);
|
||||
parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), 0, 0);
|
||||
/* "\anychar" -> "anychar" */
|
||||
parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), '\0', '\0');
|
||||
cmdstr += strlen(cmdstr);
|
||||
/* handle file cmds: (r)ead */
|
||||
} else if (strchr("rw", sed_cmd->cmd)) {
|
||||
@@ -1337,7 +1341,7 @@ int sed_main(int argc, char **argv)
|
||||
// FIXME: error check / message?
|
||||
rename(G.outname, argv[i]);
|
||||
free(G.outname);
|
||||
G.outname = 0;
|
||||
G.outname = NULL;
|
||||
}
|
||||
if (G.input_file_count > G.current_input_file)
|
||||
process_files();
|
||||
|
||||
@@ -0,0 +1,425 @@
|
||||
http://www.student.northpark.edu/pemente/sed/sed1line.txt
|
||||
-------------------------------------------------------------------------
|
||||
HANDY ONE-LINERS FOR SED (Unix stream editor) Apr. 26, 2004
|
||||
compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.4
|
||||
Latest version of this file is usually at:
|
||||
http://sed.sourceforge.net/sed1line.txt
|
||||
http://www.student.northpark.edu/pemente/sed/sed1line.txt
|
||||
This file is also available in Portuguese at:
|
||||
http://www.lrv.ufsc.br/wmaker/sed_ptBR.html
|
||||
|
||||
FILE SPACING:
|
||||
|
||||
# double space a file
|
||||
sed G
|
||||
|
||||
# double space a file which already has blank lines in it. Output file
|
||||
# should contain no more than one blank line between lines of text.
|
||||
sed '/^$/d;G'
|
||||
|
||||
# triple space a file
|
||||
sed 'G;G'
|
||||
|
||||
# undo double-spacing (assumes even-numbered lines are always blank)
|
||||
sed 'n;d'
|
||||
|
||||
# insert a blank line above every line which matches "regex"
|
||||
sed '/regex/{x;p;x;}'
|
||||
|
||||
# insert a blank line below every line which matches "regex"
|
||||
sed '/regex/G'
|
||||
|
||||
# insert a blank line above and below every line which matches "regex"
|
||||
sed '/regex/{x;p;x;G;}'
|
||||
|
||||
NUMBERING:
|
||||
|
||||
# number each line of a file (simple left alignment). Using a tab (see
|
||||
# note on '\t' at end of file) instead of space will preserve margins.
|
||||
sed = filename | sed 'N;s/\n/\t/'
|
||||
|
||||
# number each line of a file (number on left, right-aligned)
|
||||
sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'
|
||||
|
||||
# number each line of file, but only print numbers if line is not blank
|
||||
sed '/./=' filename | sed '/./N; s/\n/ /'
|
||||
|
||||
# count lines (emulates "wc -l")
|
||||
sed -n '$='
|
||||
|
||||
TEXT CONVERSION AND SUBSTITUTION:
|
||||
|
||||
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
|
||||
sed 's/.$//' # assumes that all lines end with CR/LF
|
||||
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
|
||||
sed 's/\x0D$//' # gsed 3.02.80, but top script is easier
|
||||
|
||||
# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format
|
||||
sed "s/$/`echo -e \\\r`/" # command line under ksh
|
||||
sed 's/$'"/`echo \\\r`/" # command line under bash
|
||||
sed "s/$/`echo \\\r`/" # command line under zsh
|
||||
sed 's/$/\r/' # gsed 3.02.80
|
||||
|
||||
# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format
|
||||
sed "s/$//" # method 1
|
||||
sed -n p # method 2
|
||||
|
||||
# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
|
||||
# Can only be done with UnxUtils sed, version 4.0.7 or higher.
|
||||
# Cannot be done with other DOS versions of sed. Use "tr" instead.
|
||||
sed "s/\r//" infile >outfile # UnxUtils sed v4.0.7 or higher
|
||||
tr -d \r <infile >outfile # GNU tr version 1.22 or higher
|
||||
|
||||
# delete leading whitespace (spaces, tabs) from front of each line
|
||||
# aligns all text flush left
|
||||
sed 's/^[ \t]*//' # see note on '\t' at end of file
|
||||
|
||||
# delete trailing whitespace (spaces, tabs) from end of each line
|
||||
sed 's/[ \t]*$//' # see note on '\t' at end of file
|
||||
|
||||
# delete BOTH leading and trailing whitespace from each line
|
||||
sed 's/^[ \t]*//;s/[ \t]*$//'
|
||||
|
||||
# insert 5 blank spaces at beginning of each line (make page offset)
|
||||
sed 's/^/ /'
|
||||
|
||||
# align all text flush right on a 79-column width
|
||||
sed -e :a -e 's/^.\{1,78\}$/ &/;ta' # set at 78 plus 1 space
|
||||
|
||||
# center all text in the middle of 79-column width. In method 1,
|
||||
# spaces at the beginning of the line are significant, and trailing
|
||||
# spaces are appended at the end of the line. In method 2, spaces at
|
||||
# the beginning of the line are discarded in centering the line, and
|
||||
# no trailing spaces appear at the end of lines.
|
||||
sed -e :a -e 's/^.\{1,77\}$/ & /;ta' # method 1
|
||||
sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' # method 2
|
||||
|
||||
# substitute (find and replace) "foo" with "bar" on each line
|
||||
sed 's/foo/bar/' # replaces only 1st instance in a line
|
||||
sed 's/foo/bar/4' # replaces only 4th instance in a line
|
||||
sed 's/foo/bar/g' # replaces ALL instances in a line
|
||||
sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case
|
||||
sed 's/\(.*\)foo/\1bar/' # replace only the last case
|
||||
|
||||
# substitute "foo" with "bar" ONLY for lines which contain "baz"
|
||||
sed '/baz/s/foo/bar/g'
|
||||
|
||||
# substitute "foo" with "bar" EXCEPT for lines which contain "baz"
|
||||
sed '/baz/!s/foo/bar/g'
|
||||
|
||||
# change "scarlet" or "ruby" or "puce" to "red"
|
||||
sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g' # most seds
|
||||
gsed 's/scarlet\|ruby\|puce/red/g' # GNU sed only
|
||||
|
||||
# reverse order of lines (emulates "tac")
|
||||
# bug/feature in HHsed v1.5 causes blank lines to be deleted
|
||||
sed '1!G;h;$!d' # method 1
|
||||
sed -n '1!G;h;$p' # method 2
|
||||
|
||||
# reverse each character on the line (emulates "rev")
|
||||
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
|
||||
|
||||
# join pairs of lines side-by-side (like "paste")
|
||||
sed '$!N;s/\n/ /'
|
||||
|
||||
# if a line ends with a backslash, append the next line to it
|
||||
sed -e :a -e '/\\$/N; s/\\\n//; ta'
|
||||
|
||||
# if a line begins with an equal sign, append it to the previous line
|
||||
# and replace the "=" with a single space
|
||||
sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
|
||||
|
||||
# add commas to numeric strings, changing "1234567" to "1,234,567"
|
||||
gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta' # GNU sed
|
||||
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' # other seds
|
||||
|
||||
# add commas to numbers with decimal points and minus signs (GNU sed)
|
||||
gsed ':a;s/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/g;ta'
|
||||
|
||||
# add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)
|
||||
gsed '0~5G' # GNU sed only
|
||||
sed 'n;n;n;n;G;' # other seds
|
||||
|
||||
SELECTIVE PRINTING OF CERTAIN LINES:
|
||||
|
||||
# print first 10 lines of file (emulates behavior of "head")
|
||||
sed 10q
|
||||
|
||||
# print first line of file (emulates "head -1")
|
||||
sed q
|
||||
|
||||
# print the last 10 lines of a file (emulates "tail")
|
||||
sed -e :a -e '$q;N;11,$D;ba'
|
||||
|
||||
# print the last 2 lines of a file (emulates "tail -2")
|
||||
sed '$!N;$!D'
|
||||
|
||||
# print the last line of a file (emulates "tail -1")
|
||||
sed '$!d' # method 1
|
||||
sed -n '$p' # method 2
|
||||
|
||||
# print only lines which match regular expression (emulates "grep")
|
||||
sed -n '/regexp/p' # method 1
|
||||
sed '/regexp/!d' # method 2
|
||||
|
||||
# print only lines which do NOT match regexp (emulates "grep -v")
|
||||
sed -n '/regexp/!p' # method 1, corresponds to above
|
||||
sed '/regexp/d' # method 2, simpler syntax
|
||||
|
||||
# print the line immediately before a regexp, but not the line
|
||||
# containing the regexp
|
||||
sed -n '/regexp/{g;1!p;};h'
|
||||
|
||||
# print the line immediately after a regexp, but not the line
|
||||
# containing the regexp
|
||||
sed -n '/regexp/{n;p;}'
|
||||
|
||||
# print 1 line of context before and after regexp, with line number
|
||||
# indicating where the regexp occurred (similar to "grep -A1 -B1")
|
||||
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
|
||||
|
||||
# grep for AAA and BBB and CCC (in any order)
|
||||
sed '/AAA/!d; /BBB/!d; /CCC/!d'
|
||||
|
||||
# grep for AAA and BBB and CCC (in that order)
|
||||
sed '/AAA.*BBB.*CCC/!d'
|
||||
|
||||
# grep for AAA or BBB or CCC (emulates "egrep")
|
||||
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d # most seds
|
||||
gsed '/AAA\|BBB\|CCC/!d' # GNU sed only
|
||||
|
||||
# print paragraph if it contains AAA (blank lines separate paragraphs)
|
||||
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
|
||||
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
|
||||
|
||||
# print paragraph if it contains AAA and BBB and CCC (in any order)
|
||||
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'
|
||||
|
||||
# print paragraph if it contains AAA or BBB or CCC
|
||||
sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
|
||||
gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only
|
||||
|
||||
# print only lines of 65 characters or longer
|
||||
sed -n '/^.\{65\}/p'
|
||||
|
||||
# print only lines of less than 65 characters
|
||||
sed -n '/^.\{65\}/!p' # method 1, corresponds to above
|
||||
sed '/^.\{65\}/d' # method 2, simpler syntax
|
||||
|
||||
# print section of file from regular expression to end of file
|
||||
sed -n '/regexp/,$p'
|
||||
|
||||
# print section of file based on line numbers (lines 8-12, inclusive)
|
||||
sed -n '8,12p' # method 1
|
||||
sed '8,12!d' # method 2
|
||||
|
||||
# print line number 52
|
||||
sed -n '52p' # method 1
|
||||
sed '52!d' # method 2
|
||||
sed '52q;d' # method 3, efficient on large files
|
||||
|
||||
# beginning at line 3, print every 7th line
|
||||
gsed -n '3~7p' # GNU sed only
|
||||
sed -n '3,${p;n;n;n;n;n;n;}' # other seds
|
||||
|
||||
# print section of file between two regular expressions (inclusive)
|
||||
sed -n '/Iowa/,/Montana/p' # case sensitive
|
||||
|
||||
SELECTIVE DELETION OF CERTAIN LINES:
|
||||
|
||||
# print all of file EXCEPT section between 2 regular expressions
|
||||
sed '/Iowa/,/Montana/d'
|
||||
|
||||
# delete duplicate, consecutive lines from a file (emulates "uniq").
|
||||
# First line in a set of duplicate lines is kept, rest are deleted.
|
||||
sed '$!N; /^\(.*\)\n\1$/!P; D'
|
||||
|
||||
# delete duplicate, nonconsecutive lines from a file. Beware not to
|
||||
# overflow the buffer size of the hold space, or else use GNU sed.
|
||||
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'
|
||||
|
||||
# delete all lines except duplicate lines (emulates "uniq -d").
|
||||
sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'
|
||||
|
||||
# delete the first 10 lines of a file
|
||||
sed '1,10d'
|
||||
|
||||
# delete the last line of a file
|
||||
sed '$d'
|
||||
|
||||
# delete the last 2 lines of a file
|
||||
sed 'N;$!P;$!D;$d'
|
||||
|
||||
# delete the last 10 lines of a file
|
||||
sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1
|
||||
sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2
|
||||
|
||||
# delete every 8th line
|
||||
gsed '0~8d' # GNU sed only
|
||||
sed 'n;n;n;n;n;n;n;d;' # other seds
|
||||
|
||||
# delete ALL blank lines from a file (same as "grep '.' ")
|
||||
sed '/^$/d' # method 1
|
||||
sed '/./!d' # method 2
|
||||
|
||||
# delete all CONSECUTIVE blank lines from file except the first; also
|
||||
# deletes all blank lines from top and end of file (emulates "cat -s")
|
||||
sed '/./,/^$/!d' # method 1, allows 0 blanks at top, 1 at EOF
|
||||
sed '/^$/N;/\n$/D' # method 2, allows 1 blank at top, 0 at EOF
|
||||
|
||||
# delete all CONSECUTIVE blank lines from file except the first 2:
|
||||
sed '/^$/N;/\n$/N;//D'
|
||||
|
||||
# delete all leading blank lines at top of file
|
||||
sed '/./,$!d'
|
||||
|
||||
# delete all trailing blank lines at end of file
|
||||
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' # works on all seds
|
||||
sed -e :a -e '/^\n*$/N;/\n$/ba' # ditto, except for gsed 3.02*
|
||||
|
||||
# delete the last line of each paragraph
|
||||
sed -n '/^$/{p;h;};/./{x;/./p;}'
|
||||
|
||||
SPECIAL APPLICATIONS:
|
||||
|
||||
# remove nroff overstrikes (char, backspace) from man pages. The 'echo'
|
||||
# command may need an -e switch if you use Unix System V or bash shell.
|
||||
sed "s/.`echo \\\b`//g" # double quotes required for Unix environment
|
||||
sed 's/.^H//g' # in bash/tcsh, press Ctrl-V and then Ctrl-H
|
||||
sed 's/.\x08//g' # hex expression for sed v1.5
|
||||
|
||||
# get Usenet/e-mail message header
|
||||
sed '/^$/q' # deletes everything after first blank line
|
||||
|
||||
# get Usenet/e-mail message body
|
||||
sed '1,/^$/d' # deletes everything up to first blank line
|
||||
|
||||
# get Subject header, but remove initial "Subject: " portion
|
||||
sed '/^Subject: */!d; s///;q'
|
||||
|
||||
# get return address header
|
||||
sed '/^Reply-To:/q; /^From:/h; /./d;g;q'
|
||||
|
||||
# parse out the address proper. Pulls out the e-mail address by itself
|
||||
# from the 1-line return address header (see preceding script)
|
||||
sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//'
|
||||
|
||||
# add a leading angle bracket and space to each line (quote a message)
|
||||
sed 's/^/> /'
|
||||
|
||||
# delete leading angle bracket & space from each line (unquote a message)
|
||||
sed 's/^> //'
|
||||
|
||||
# remove most HTML tags (accommodates multiple-line tags)
|
||||
sed -e :a -e 's/<[^>]*>//g;/</N;//ba'
|
||||
|
||||
# extract multi-part uuencoded binaries, removing extraneous header
|
||||
# info, so that only the uuencoded portion remains. Files passed to
|
||||
# sed must be passed in the proper order. Version 1 can be entered
|
||||
# from the command line; version 2 can be made into an executable
|
||||
# Unix shell script. (Modified from a script by Rahul Dhesi.)
|
||||
sed '/^end/,/^begin/d' file1 file2 ... fileX | uudecode # vers. 1
|
||||
sed '/^end/,/^begin/d' "$@" | uudecode # vers. 2
|
||||
|
||||
# zip up each .TXT file individually, deleting the source file and
|
||||
# setting the name of each .ZIP file to the basename of the .TXT file
|
||||
# (under DOS: the "dir /b" switch returns bare filenames in all caps).
|
||||
echo @echo off >zipup.bat
|
||||
dir /b *.txt | sed "s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/" >>zipup.bat
|
||||
|
||||
TYPICAL USE: Sed takes one or more editing commands and applies all of
|
||||
them, in sequence, to each line of input. After all the commands have
|
||||
been applied to the first input line, that line is output and a second
|
||||
input line is taken for processing, and the cycle repeats. The
|
||||
preceding examples assume that input comes from the standard input
|
||||
device (i.e, the console, normally this will be piped input). One or
|
||||
more filenames can be appended to the command line if the input does
|
||||
not come from stdin. Output is sent to stdout (the screen). Thus:
|
||||
|
||||
cat filename | sed '10q' # uses piped input
|
||||
sed '10q' filename # same effect, avoids a useless "cat"
|
||||
sed '10q' filename > newfile # redirects output to disk
|
||||
|
||||
For additional syntax instructions, including the way to apply editing
|
||||
commands from a disk file instead of the command line, consult "sed &
|
||||
awk, 2nd Edition," by Dale Dougherty and Arnold Robbins (O'Reilly,
|
||||
1997; http://www.ora.com), "UNIX Text Processing," by Dale Dougherty
|
||||
and Tim O'Reilly (Hayden Books, 1987) or the tutorials by Mike Arst
|
||||
distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power
|
||||
of sed, one must understand "regular expressions." For this, see
|
||||
"Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly, 1997).
|
||||
The manual ("man") pages on Unix systems may be helpful (try "man
|
||||
sed", "man regexp", or the subsection on regular expressions in "man
|
||||
ed"), but man pages are notoriously difficult. They are not written to
|
||||
teach sed use or regexps to first-time users, but as a reference text
|
||||
for those already acquainted with these tools.
|
||||
|
||||
QUOTING SYNTAX: The preceding examples use single quotes ('...')
|
||||
instead of double quotes ("...") to enclose editing commands, since
|
||||
sed is typically used on a Unix platform. Single quotes prevent the
|
||||
Unix shell from intrepreting the dollar sign ($) and backquotes
|
||||
(`...`), which are expanded by the shell if they are enclosed in
|
||||
double quotes. Users of the "csh" shell and derivatives will also need
|
||||
to quote the exclamation mark (!) with the backslash (i.e., \!) to
|
||||
properly run the examples listed above, even within single quotes.
|
||||
Versions of sed written for DOS invariably require double quotes
|
||||
("...") instead of single quotes to enclose editing commands.
|
||||
|
||||
USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used
|
||||
the expression '\t' to indicate a tab character (0x09) in the scripts.
|
||||
However, most versions of sed do not recognize the '\t' abbreviation,
|
||||
so when typing these scripts from the command line, you should press
|
||||
the TAB key instead. '\t' is supported as a regular expression
|
||||
metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80.
|
||||
|
||||
VERSIONS OF SED: Versions of sed do differ, and some slight syntax
|
||||
variation is to be expected. In particular, most do not support the
|
||||
use of labels (:name) or branch instructions (b,t) within editing
|
||||
commands, except at the end of those commands. We have used the syntax
|
||||
which will be portable to most users of sed, even though the popular
|
||||
GNU versions of sed allow a more succinct syntax. When the reader sees
|
||||
a fairly long command such as this:
|
||||
|
||||
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
|
||||
|
||||
it is heartening to know that GNU sed will let you reduce it to:
|
||||
|
||||
sed '/AAA/b;/BBB/b;/CCC/b;d' # or even
|
||||
sed '/AAA\|BBB\|CCC/b;d'
|
||||
|
||||
In addition, remember that while many versions of sed accept a command
|
||||
like "/one/ s/RE1/RE2/", some do NOT allow "/one/! s/RE1/RE2/", which
|
||||
contains space before the 's'. Omit the space when typing the command.
|
||||
|
||||
OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to
|
||||
large input files or slow processors or hard disks), substitution will
|
||||
be executed more quickly if the "find" expression is specified before
|
||||
giving the "s/.../.../" instruction. Thus:
|
||||
|
||||
sed 's/foo/bar/g' filename # standard replace command
|
||||
sed '/foo/ s/foo/bar/g' filename # executes more quickly
|
||||
sed '/foo/ s//bar/g' filename # shorthand sed syntax
|
||||
|
||||
On line selection or deletion in which you only need to output lines
|
||||
from the first part of the file, a "quit" command (q) in the script
|
||||
will drastically reduce processing time for large files. Thus:
|
||||
|
||||
sed -n '45,50p' filename # print line nos. 45-50 of a file
|
||||
sed -n '51q;45,50p' filename # same, but executes much faster
|
||||
|
||||
If you have any additional scripts to contribute or if you find errors
|
||||
in this document, please send e-mail to the compiler. Indicate the
|
||||
version of sed you used, the operating system it was compiled for, and
|
||||
the nature of the problem. Various scripts in this file were written
|
||||
or contributed by:
|
||||
|
||||
Al Aab <af137@freenet.toronto.on.ca> # "seders" list moderator
|
||||
Edgar Allen <era@sky.net> # various
|
||||
Yiorgos Adamopoulos <adamo@softlab.ece.ntua.gr>
|
||||
Dale Dougherty <dale@songline.com> # author of "sed & awk"
|
||||
Carlos Duarte <cdua@algos.inesc.pt> # author of "do it with sed"
|
||||
Eric Pement <pemente@northpark.edu> # author of this document
|
||||
Ken Pizzini <ken@halcyon.com> # author of GNU sed v3.02
|
||||
S.G. Ravenhall <stew.ravenhall@totalise.co.uk> # great de-html script
|
||||
Greg Ubben <gsu@romulus.ncsc.mil> # many contributions & much help
|
||||
-------------------------------------------------------------------------
|
||||
@@ -0,0 +1,220 @@
|
||||
<html>
|
||||
|
||||
<head><title>Command Summary for sed (sed & awk, Second Edition)</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h2>Command Summary for sed</h2>
|
||||
|
||||
<dl>
|
||||
|
||||
<dt><b>: </b> <b> :</b><em>label</em></dt>
|
||||
<dd>Label a line in the script for the transfer of control by
|
||||
<b>b</b> or <b>t</b>.
|
||||
<em>label</em> may contain up to seven characters.
|
||||
(The POSIX standard says that an implementation can allow longer
|
||||
labels if it wishes to. GNU sed allows labels to be of any length.)
|
||||
</p></dd>
|
||||
|
||||
|
||||
<dt><b>=</b> [<em>address</em>]<b>=</b></dt>
|
||||
<dd>Write to standard output the line number of addressed line.</p></dd>
|
||||
|
||||
|
||||
<dt><b>a</b> [<em>address</em>]<b>a\</b></dt>
|
||||
<dd><em>text</em></p>
|
||||
|
||||
<p>Append <em>text</em>
|
||||
following each line matched by <em>address</em>. If
|
||||
<em>text</em> goes over more than one line, newlines
|
||||
must be "hidden" by preceding them with a backslash. The
|
||||
<em>text</em> will be terminated by the first
|
||||
newline that is not hidden in this way. The
|
||||
<em>text</em> is not available in the pattern space
|
||||
and subsequent commands cannot be applied to it. The results of this
|
||||
command are sent to standard output when the list of editing commands
|
||||
is finished, regardless of what happens to the current line in the
|
||||
pattern space.</p></dd>
|
||||
|
||||
|
||||
<dt><b>b</b> [<em>address1</em>[,<em>address2</em>]]<b>b</b>[<em>label</em>]</dt>
|
||||
<dd>Transfer control unconditionally (branch) to
|
||||
<b>:</b><em>label</em> elsewhere in
|
||||
script. That is, the command following the
|
||||
<em>label</em> is the next command applied to the
|
||||
current line. If no <em>label</em> is specified,
|
||||
control falls through to the end of the script, so no more commands
|
||||
are applied to the current line.</p></dd>
|
||||
|
||||
|
||||
<dt><b>c</b> [<em>address1</em>[,<em>address2</em>]]<b>c\</b></dt>
|
||||
<dd><em>text</em></p>
|
||||
|
||||
<p>Replace (change) the lines selected by the address with
|
||||
<em>text</em>. When a range of lines is specified,
|
||||
all lines as a group are replaced by a single copy of
|
||||
<em>text</em>. The newline following each line of
|
||||
<em>text</em> must be escaped by a backslash, except
|
||||
the last line. The contents of the pattern space are, in effect,
|
||||
deleted and no subsequent editing commands can be applied to it (or to
|
||||
<em>text</em>).</p></dd>
|
||||
|
||||
|
||||
<dt><b>d</b> [<em>address1</em>[,<em>address2</em>]]<b>d</b></dt>
|
||||
<dd>Delete line(s) from pattern space. Thus, the line is not passed to standard
|
||||
output. A new line of input is read and editing resumes with first
|
||||
command in script.</p></dd>
|
||||
|
||||
|
||||
<dt><b>D</b> [<em>address1</em>[,<em>address2</em>]]<b>D</b></dt>
|
||||
<dd>Delete first part (up to embedded newline) of multiline pattern space created
|
||||
by <b>N</b> command and resume editing with first command in
|
||||
script. If this command empties the pattern space, then a new line
|
||||
of input is read, as if the <b>d</b> command had been executed.</p></dd>
|
||||
|
||||
|
||||
<dt><b>g</b> [<em>address1</em>[,<em>address2</em>]]<b>g</b></dt>
|
||||
<dd>Copy (get) contents of hold space (see <b>h</b> or
|
||||
<b>H</b> command) into the pattern space, wiping out
|
||||
previous contents.</p></dd>
|
||||
|
||||
|
||||
<dt><b>G</b> [<em>address1</em>[,<em>address2</em>]]<b>G</b></dt>
|
||||
<dd>Append newline followed by contents of hold space (see
|
||||
<b>h</b> or <b>H</b> command) to contents of
|
||||
the pattern space. If hold space is empty, a newline is still
|
||||
appended to the pattern space.</p></dd>
|
||||
|
||||
|
||||
<dt><b>h</b> [<em>address1</em>[,<em>address2</em>]]<b>h</b></dt>
|
||||
<dd>Copy pattern space into hold space, a special temporary buffer.
|
||||
Previous contents of hold space are wiped out.</p></dd>
|
||||
|
||||
|
||||
<dt><b>H</b> [<em>address1</em>[,<em>address2</em>]]<b>H</b></dt>
|
||||
<dd>Append newline and contents of pattern space to contents of the hold
|
||||
space. Even if hold space is empty, this command still appends the
|
||||
newline first.</p></dd>
|
||||
|
||||
|
||||
<dt><b>i</b> [<em>address1</em>]<b>i\</b></dt>
|
||||
<dd><em>text</em></p>
|
||||
|
||||
<p>Insert <em>text</em> before each line matched by
|
||||
<em>address</em>. (See <b>a</b> for
|
||||
details on <em>text</em>.)</p></dd>
|
||||
|
||||
|
||||
<dt><b>l</b> [<em>address1</em>[,<em>address2</em>]]<b>l</b></dt>
|
||||
<dd>List the contents of the pattern space, showing nonprinting characters
|
||||
as ASCII codes. Long lines are wrapped.</p></dd>
|
||||
|
||||
|
||||
<dt><b>n</b> [<em>address1</em>[,<em>address2</em>]]<b>n</b></dt>
|
||||
<dd>Read next line of input into pattern space. Current line is sent to
|
||||
standard output. New line becomes current line and increments line
|
||||
counter. Control passes to command following <b>n</b>
|
||||
instead of resuming at the top of the script.</p></dd>
|
||||
|
||||
|
||||
<dt><b>N</b> [<em>address1</em>[,<em>address2</em>]]<b>N</b></dt>
|
||||
<dd>Append next input line to contents of pattern space; the new line is
|
||||
separated from the previous contents of the pattern space by a newline.
|
||||
(This command is designed to allow pattern matches across two
|
||||
lines. Using \n to match the embedded newline, you can match
|
||||
patterns across multiple lines.)</p></dd>
|
||||
|
||||
|
||||
<dt><b>p</b> [<em>address1</em>[,<em>address2</em>]]<b>p</b></dt>
|
||||
<dd>Print the addressed line(s). Note that this can result in duplicate
|
||||
output unless default output is suppressed by using "#n" or
|
||||
the <span class="option">-n</span>
|
||||
|
||||
command-line option. Typically used before commands that change flow
|
||||
control (<b>d</b>, <b>n</b>,
|
||||
<b>b</b>) and might prevent the current line from being
|
||||
output.</p></dd>
|
||||
|
||||
|
||||
<dt><b>P</b> [<em>address1</em>[,<em>address2</em>]]<b>P</b></dt>
|
||||
<dd>Print first part (up to embedded newline) of multiline pattern space
|
||||
created by <b>N</b> command. Same as <b>p</b>
|
||||
if <b>N</b> has not been applied to a line.</p></dd>
|
||||
|
||||
|
||||
<dt><b>q</b> [<em>address</em>]<b>q</b></dt>
|
||||
<dd>Quit when <em>address</em> is encountered. The
|
||||
addressed line is first written to output (if default output is not
|
||||
suppressed), along with any text appended to it by previous
|
||||
<b>a</b> or <b>r</b> commands.</p></dd>
|
||||
|
||||
|
||||
<dt><b>r</b> [<em>address</em>]<b>r</b> <em>file</em></dt>
|
||||
<dd>Read contents of <em>file</em> and append after the
|
||||
contents of the pattern space. Exactly one space must be put between
|
||||
<b>r</b> and the filename.</p></dd>
|
||||
|
||||
|
||||
<dt><b>s</b> [<em>address1</em>[,<em>address2</em>]]<b>s</b>/<em>pattern</em>/<em>replacement</em>/[<em>flags</em>]</dt>
|
||||
<dd>Substitute <em>replacement</em> for
|
||||
<em>pattern</em> on each addressed line. If pattern
|
||||
addresses are used, the pattern <b>//</b> represents the
|
||||
last pattern address specified. The following flags can be specified:</p>
|
||||
|
||||
<dl>
|
||||
|
||||
<dt><b>n</b></dt>
|
||||
<dd>Replace <em>n</em>th instance of
|
||||
/<em>pattern</em>/ on each addressed line.
|
||||
<em>n</em> is any number in the range 1 to 512, and
|
||||
the default is 1.</p></dd>
|
||||
|
||||
<dt><b>g</b></dt>
|
||||
<dd>Replace all instances of /<em>pattern</em>/ on each
|
||||
addressed line, not just the first instance.</p></dd>
|
||||
|
||||
<dt><b>p</b></dt>
|
||||
<dd>Print the line if a successful substitution is done. If several
|
||||
successful substitutions are done, multiple copies of the line will be
|
||||
printed.</p></dd>
|
||||
|
||||
<dt><b>w</b> <em>file</em></dt>
|
||||
<dd>Write the line to <em>file</em> if a replacement
|
||||
was done. A maximum of 10 different <em>files</em> can be opened.</p></dd>
|
||||
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
<dt><b>t</b> [<em>address1</em>[,<em>address2</em>]]<b>t </b>[<em>label</em>]</dt>
|
||||
<dd>Test if successful substitutions have been made on addressed lines,
|
||||
and if so, branch to line marked by :<em>label</em>.
|
||||
(See <b>b</b> and <b>:</b>.) If label is not
|
||||
specified, control falls through to bottom of script.</p></dd>
|
||||
|
||||
|
||||
<dt><b>w</b> [<em>address1</em>[,<em>address2</em>]]<b>w</b> <em>file</em></dt>
|
||||
<dd>Append contents of pattern space to <em>file</em>.
|
||||
This action occurs when the command is encountered rather than when
|
||||
the pattern space is output. Exactly one space must separate the
|
||||
<b>w</b> and the filename. A maximum of 10 different
|
||||
files can be opened in a script. This command will create the file if
|
||||
it does not exist; if the file exists, its contents will be
|
||||
overwritten each time the script is executed. Multiple write commands
|
||||
that direct output to the same file append to the end of the file.</p></dd>
|
||||
|
||||
|
||||
<dt><b>x</b> [<em>address1</em>[,<em>address2</em>]]<b>x</b></dt>
|
||||
<dd>Exchange contents of the pattern space with the contents of the hold
|
||||
space.</p></dd>
|
||||
|
||||
|
||||
<dt><b>y</b> [<em>address1</em>[,<em>address2</em>]]<b>y</b>/<em>abc</em>/<em>xyz</em>/</dt>
|
||||
<dd>Transform each character by position in string
|
||||
<em>abc</em> to its equivalent in string
|
||||
<em>xyz</em>.</p></dd>
|
||||
|
||||
|
||||
</dl>
|
||||
+489
-443
File diff suppressed because it is too large.
Load diff
@@ -76,7 +76,7 @@ The following steps will create a root file system.
|
||||
|
||||
- Make device files in /dev:
|
||||
|
||||
This can be done by running the 'mkdevs.sh' script. If you want the gory
|
||||
This can be done by running the 'mkdevs.sh' script. If you want the gory
|
||||
details, you can read the script.
|
||||
|
||||
- Make necessary files in /etc:
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ sub build_ref_tables
|
||||
} else {
|
||||
# exporting all symbols
|
||||
foreach ( @$sym_ar ) {
|
||||
/ [ABCDGRST] (.*)$/ and do {
|
||||
/ [ABCDGRSTW] (.*)$/ and do {
|
||||
warn "syma = $1\n" if $verbose;
|
||||
$exp->{$1} = $name;
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ REGISTER ^radio0$ EXECUTE /bin/ln -sf radio0 radio
|
||||
UNREGISTER ^radio0$ EXECUTE /bin/rm -f radio
|
||||
|
||||
# ALSA stuff
|
||||
#LOOKUP snd MODLOAD ACTION snd
|
||||
#LOOKUP snd MODLOAD ACTION snd
|
||||
|
||||
# Uncomment this to let PAM manage devfs
|
||||
# Not supported by busybox
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# The start and end of the IP lease block
|
||||
|
||||
start 192.168.0.20 #default: 192.168.0.20
|
||||
start 192.168.0.20 #default: 192.168.0.20
|
||||
end 192.168.0.254 #default: 192.168.0.254
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ interface eth0 #default: eth0
|
||||
|
||||
#notify_file #default: (no script)
|
||||
|
||||
#notify_file dumpleases # <--- useful for debugging
|
||||
#notify_file dumpleases # <--- useful for debugging
|
||||
|
||||
# The following are bootp specific options, setable by udhcpd.
|
||||
|
||||
|
||||
+7
-3
@@ -76,7 +76,7 @@ typedef struct {
|
||||
#define ACTS(name, arg...) typedef struct { action a; arg; } action_##name;
|
||||
#define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
|
||||
ACTS(print)
|
||||
ACTS(name, const char *pattern;)
|
||||
ACTS(name, const char *pattern; bool iname;)
|
||||
USE_FEATURE_FIND_PATH( ACTS(path, const char *pattern;))
|
||||
USE_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
|
||||
USE_FEATURE_FIND_PRINT0( ACTS(print0))
|
||||
@@ -188,8 +188,9 @@ ACTF(name)
|
||||
if (*tmp == '/')
|
||||
tmp++;
|
||||
}
|
||||
return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0;
|
||||
return fnmatch(ap->pattern, tmp, FNM_PERIOD | (ap->iname ? FNM_CASEFOLD : 0)) == 0;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_FIND_PATH
|
||||
ACTF(path)
|
||||
{
|
||||
@@ -458,6 +459,7 @@ static action*** parse_params(char **argv)
|
||||
USE_FEATURE_FIND_PAREN( PARM_char_brace,)
|
||||
/* All options starting from here require argument */
|
||||
PARM_name ,
|
||||
PARM_iname ,
|
||||
USE_FEATURE_FIND_PATH( PARM_path ,)
|
||||
USE_FEATURE_FIND_REGEX( PARM_regex ,)
|
||||
USE_FEATURE_FIND_TYPE( PARM_type ,)
|
||||
@@ -490,6 +492,7 @@ static action*** parse_params(char **argv)
|
||||
USE_FEATURE_FIND_PAREN( "(\0" )
|
||||
/* All options starting from here require argument */
|
||||
"-name\0"
|
||||
"-iname\0"
|
||||
USE_FEATURE_FIND_PATH( "-path\0" )
|
||||
USE_FEATURE_FIND_REGEX( "-regex\0" )
|
||||
USE_FEATURE_FIND_TYPE( "-type\0" )
|
||||
@@ -654,10 +657,11 @@ static action*** parse_params(char **argv)
|
||||
argv = endarg;
|
||||
}
|
||||
#endif
|
||||
else if (parm == PARM_name) {
|
||||
else if (parm == PARM_name || parm == PARM_iname) {
|
||||
action_name *ap;
|
||||
ap = ALLOC_ACTION(name);
|
||||
ap->pattern = arg1;
|
||||
ap->iname = (parm == PARM_iname);
|
||||
}
|
||||
#if ENABLE_FEATURE_FIND_PATH
|
||||
else if (parm == PARM_path) {
|
||||
|
||||
+10
-10
@@ -59,12 +59,12 @@ s - suid type:
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) LINK l name
|
||||
|
||||
#else
|
||||
const struct bb_applet applets[] = { /* name, main, location, need_suid */
|
||||
# define APPLET(name,l,s) { #name, name##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) },
|
||||
# define APPLET_NOUSAGE(name,main,l,s) { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) },
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) },
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) USE_FEATURE_PREFER_APPLETS(,1) },
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) { #name, main##_main USE_FEATURE_INSTALLER(,l) USE_FEATURE_SUID(,s) USE_FEATURE_PREFER_APPLETS(,1 ,1) },
|
||||
static struct bb_applet applets[] = { /* name, main, location, need_suid */
|
||||
# define APPLET(name,l,s) { #name, #name, l, s },
|
||||
# define APPLET_NOUSAGE(name,main,l,s) { #name, #main, l, s },
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) { #name, #main, l, s },
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) { #name, #main, l, s, 1 },
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) { #name, #main, l, s, 1, 1 },
|
||||
#endif
|
||||
|
||||
#if ENABLE_INSTALL_NO_USR
|
||||
@@ -73,7 +73,7 @@ s - suid type:
|
||||
#endif
|
||||
|
||||
|
||||
USE_TEST(APPLET_NOEXEC([, test, _BB_DIR_USR_BIN, _BB_SUID_NEVER, test))
|
||||
USE_TEST(APPLET_NOFORK([, test, _BB_DIR_USR_BIN, _BB_SUID_NEVER, test))
|
||||
USE_TEST(APPLET_NOUSAGE([[, test, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
USE_ADDGROUP(APPLET(addgroup, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_ADDUSER(APPLET(adduser, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
@@ -111,7 +111,7 @@ USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
||||
USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
|
||||
USE_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
USE_CTTYHACK(APPLET_NOUSAGE(cttyhack, cttyhack, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
USE_CTTYHACK(APPLET_NOUSAGE(cttyhack, cttyhack, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut))
|
||||
USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
@@ -171,6 +171,7 @@ USE_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_GZIP(APPLET(gzip, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_HALT(APPLET(halt, _BB_DIR_SBIN, _BB_SUID_NEVER))
|
||||
USE_HD(APPLET_ODDNAME(hd, hexdump, _BB_DIR_USR_BIN, _BB_SUID_NEVER, hd))
|
||||
USE_HDPARM(APPLET(hdparm, _BB_DIR_SBIN, _BB_SUID_NEVER))
|
||||
USE_HEAD(APPLET(head, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
USE_HEXDUMP(APPLET_NOEXEC(hexdump, hexdump, _BB_DIR_USR_BIN, _BB_SUID_NEVER, hexdump))
|
||||
@@ -299,6 +300,7 @@ USE_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
USE_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
||||
USE_SEQ(APPLET_NOFORK(seq, seq, _BB_DIR_USR_BIN, _BB_SUID_NEVER, seq))
|
||||
USE_SESTATUS(APPLET(sestatus, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
||||
USE_SETARCH(APPLET(setarch, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_SETCONSOLE(APPLET(setconsole, _BB_DIR_SBIN, _BB_SUID_NEVER))
|
||||
USE_SETENFORCE(APPLET(setenforce, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
||||
@@ -310,7 +312,6 @@ USE_SETSID(APPLET(setsid, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||
USE_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, _BB_DIR_USR_BIN, _BB_SUID_NEVER, setuidgid))
|
||||
USE_FEATURE_SH_IS_ASH(APPLET_NOUSAGE(sh, ash, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_FEATURE_SH_IS_HUSH(APPLET_NOUSAGE(sh, hush, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_FEATURE_SH_IS_LASH(APPLET_NOUSAGE(sh, lash, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_FEATURE_SH_IS_MSH(APPLET_NOUSAGE(sh, msh, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||
USE_SHA1SUM(APPLET_ODDNAME(sha1sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_NEVER, sha1sum))
|
||||
USE_SLATTACH(APPLET(slattach, _BB_DIR_SBIN, _BB_SUID_NEVER))
|
||||
@@ -384,7 +385,6 @@ USE_GUNZIP(APPLET_ODDNAME(zcat, gunzip, _BB_DIR_BIN, _BB_SUID_NEVER, zcat))
|
||||
USE_ZCIP(APPLET(zcip, _BB_DIR_SBIN, _BB_SUID_NEVER))
|
||||
|
||||
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE)
|
||||
{ NULL }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
+27
-24
@@ -9,8 +9,7 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
/* order matters: used as index into "install_dir[]" in busybox.c */
|
||||
/* order matters: used as index into "install_dir[]" in appletlib.c */
|
||||
typedef enum bb_install_loc_t {
|
||||
_BB_DIR_ROOT = 0,
|
||||
_BB_DIR_BIN,
|
||||
@@ -18,40 +17,44 @@ typedef enum bb_install_loc_t {
|
||||
_BB_DIR_USR_BIN,
|
||||
_BB_DIR_USR_SBIN
|
||||
} bb_install_loc_t;
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
typedef enum bb_suid_t {
|
||||
_BB_SUID_NEVER = 0,
|
||||
_BB_SUID_MAYBE,
|
||||
_BB_SUID_ALWAYS
|
||||
} bb_suid_t;
|
||||
|
||||
|
||||
/* Defined in appletlib.c (by including generated applet_tables.h) */
|
||||
/* Keep in sync with applets/applet_tables.c! */
|
||||
extern const char applet_names[];
|
||||
extern int (*const applet_main[])(int argc, char **argv);
|
||||
extern const uint16_t applet_nameofs[];
|
||||
extern const uint8_t applet_install_loc[];
|
||||
|
||||
#if ENABLE_FEATURE_SUID || ENABLE_FEATURE_PREFER_APPLETS
|
||||
#define APPLET_NAME(i) (applet_names + (applet_nameofs[i] & 0x0fff))
|
||||
#else
|
||||
#define APPLET_NAME(i) (applet_names + applet_nameofs[i])
|
||||
#endif
|
||||
|
||||
struct bb_applet {
|
||||
const char *name;
|
||||
int (*main) (int argc, char **argv);
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
__extension__ enum bb_install_loc_t install_loc:8;
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SUID
|
||||
__extension__ enum bb_suid_t need_suid:8;
|
||||
#endif
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
/* true if instead of fork(); exec("applet"); waitpid();
|
||||
* one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
|
||||
unsigned char noexec;
|
||||
/* Even nicer */
|
||||
/* true if instead of fork(); exec("applet"); waitpid();
|
||||
* one can simply call applet_main(argc,argv); */
|
||||
unsigned char nofork;
|
||||
#define APPLET_IS_NOFORK(i) (applet_nameofs[i] & (1 << 12))
|
||||
#define APPLET_IS_NOEXEC(i) (applet_nameofs[i] & (1 << 13))
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
#define APPLET_SUID(i) ((applet_nameofs[i] >> 14) & 0x3)
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
#define APPLET_INSTALL_LOC(i) ({ \
|
||||
unsigned v = (i); \
|
||||
if (v & 1) v = applet_install_loc[v/2] >> 4; \
|
||||
else v = applet_install_loc[v/2] & 0xf; \
|
||||
v; })
|
||||
#endif
|
||||
|
||||
/* Defined in appletlib.c */
|
||||
extern const struct bb_applet applets[];
|
||||
extern const unsigned short NUM_APPLETS;
|
||||
|
||||
/* Length of these names has effect on size of libbusybox
|
||||
* and "individual" binaries. Keep them short.
|
||||
|
||||
+74
-47
@@ -26,7 +26,6 @@
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
/* #include <strings.h> - said to be obsolete */
|
||||
#include <sys/poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
@@ -40,6 +39,12 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
/* Try to pull in PATH_MAX */
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
#include <selinux/selinux.h>
|
||||
@@ -62,14 +67,37 @@
|
||||
#include "shadow_.h"
|
||||
#endif
|
||||
|
||||
/* Try to pull in PATH_MAX */
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#if defined(__GLIBC__) && __GLIBC__ < 2
|
||||
int vdprintf(int d, const char *format, va_list ap);
|
||||
#endif
|
||||
/* klogctl is in libc's klog.h, but we cheat and not #include that */
|
||||
int klogctl(int type, char *b, int len);
|
||||
/* This is declared here rather than #including <libgen.h> in order to avoid
|
||||
* confusing the two versions of basename. See the dirname/basename man page
|
||||
* for details. */
|
||||
char *dirname(char *path);
|
||||
/* Include our own copy of struct sysinfo to avoid binary compatibility
|
||||
* problems with Linux 2.4, which changed things. Grumble, grumble. */
|
||||
struct sysinfo {
|
||||
long uptime; /* Seconds since boot */
|
||||
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
|
||||
unsigned long totalram; /* Total usable main memory size */
|
||||
unsigned long freeram; /* Available memory size */
|
||||
unsigned long sharedram; /* Amount of shared memory */
|
||||
unsigned long bufferram; /* Memory used by buffers */
|
||||
unsigned long totalswap; /* Total swap space size */
|
||||
unsigned long freeswap; /* swap space still available */
|
||||
unsigned short procs; /* Number of current processes */
|
||||
unsigned short pad; /* Padding needed for m68k */
|
||||
unsigned long totalhigh; /* Total high memory size */
|
||||
unsigned long freehigh; /* Available high memory size */
|
||||
unsigned int mem_unit; /* Memory unit size in bytes */
|
||||
char _f[20 - 2*sizeof(long) - sizeof(int)]; /* Padding: libc5 uses this.. */
|
||||
};
|
||||
int sysinfo(struct sysinfo* info);
|
||||
|
||||
/* Tested to work correctly (IIRC :]) */
|
||||
|
||||
/* Tested to work correctly with all int types (IIRC :]) */
|
||||
#define MAXINT(T) (T)( \
|
||||
((T)-1) > 0 \
|
||||
? (T)-1 \
|
||||
@@ -83,7 +111,7 @@
|
||||
)
|
||||
|
||||
/* Large file support */
|
||||
/* Note that CONFIG_LFS forces bbox to be built with all common ops
|
||||
/* Note that CONFIG_LFS=y forces bbox to be built with all common ops
|
||||
* (stat, lseek etc) mapped to "largefile" variants by libc.
|
||||
* Practically it means that open() automatically has O_LARGEFILE added
|
||||
* and all filesize/file_offset parameters and struct members are "large"
|
||||
@@ -167,7 +195,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
/* glibc uses __errno_location() to get a ptr to errno */
|
||||
/* We can just memorize it once - no multithreading in busybox :) */
|
||||
@@ -176,33 +203,6 @@ extern int *const bb_errno;
|
||||
#define errno (*bb_errno)
|
||||
#endif
|
||||
|
||||
#if defined(__GLIBC__) && __GLIBC__ < 2
|
||||
int vdprintf(int d, const char *format, va_list ap);
|
||||
#endif
|
||||
// This is declared here rather than #including <libgen.h> in order to avoid
|
||||
// confusing the two versions of basename. See the dirname/basename man page
|
||||
// for details.
|
||||
char *dirname(char *path);
|
||||
/* Include our own copy of struct sysinfo to avoid binary compatibility
|
||||
* problems with Linux 2.4, which changed things. Grumble, grumble. */
|
||||
struct sysinfo {
|
||||
long uptime; /* Seconds since boot */
|
||||
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
|
||||
unsigned long totalram; /* Total usable main memory size */
|
||||
unsigned long freeram; /* Available memory size */
|
||||
unsigned long sharedram; /* Amount of shared memory */
|
||||
unsigned long bufferram; /* Memory used by buffers */
|
||||
unsigned long totalswap; /* Total swap space size */
|
||||
unsigned long freeswap; /* swap space still available */
|
||||
unsigned short procs; /* Number of current processes */
|
||||
unsigned short pad; /* Padding needed for m68k */
|
||||
unsigned long totalhigh; /* Total high memory size */
|
||||
unsigned long freehigh; /* Available high memory size */
|
||||
unsigned int mem_unit; /* Memory unit size in bytes */
|
||||
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
|
||||
};
|
||||
int sysinfo(struct sysinfo* info);
|
||||
|
||||
unsigned long long monotonic_us(void);
|
||||
unsigned monotonic_sec(void);
|
||||
|
||||
@@ -263,6 +263,7 @@ char *xmalloc_readlink(const char *path);
|
||||
char *xmalloc_readlink_or_warn(const char *path);
|
||||
char *xrealloc_getcwd_or_warn(char *cwd);
|
||||
|
||||
char *xmalloc_follow_symlinks(const char *path);
|
||||
|
||||
//TODO: signal(sid, f) is the same? then why?
|
||||
extern void sig_catch(int,void (*)(int));
|
||||
@@ -288,6 +289,30 @@ void xpipe(int filedes[2]);
|
||||
off_t xlseek(int fd, off_t offset, int whence);
|
||||
off_t fdlength(int fd);
|
||||
|
||||
/* Useful for having small structure members/global variables */
|
||||
typedef int8_t socktype_t;
|
||||
typedef int8_t family_t;
|
||||
struct BUG_too_small {
|
||||
char BUG_socktype_t_too_small[(0
|
||||
| SOCK_STREAM
|
||||
| SOCK_DGRAM
|
||||
| SOCK_RDM
|
||||
| SOCK_SEQPACKET
|
||||
| SOCK_RAW
|
||||
) <= 127 ? 1 : -1];
|
||||
char BUG_family_t_too_small[(0
|
||||
| AF_UNSPEC
|
||||
| AF_INET
|
||||
| AF_INET6
|
||||
| AF_UNIX
|
||||
| AF_PACKET
|
||||
| AF_NETLINK
|
||||
/* | AF_DECnet */
|
||||
/* | AF_IPX */
|
||||
) <= 127 ? 1 : -1];
|
||||
};
|
||||
|
||||
|
||||
int xsocket(int domain, int type, int protocol);
|
||||
void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
|
||||
void xlisten(int s, int backlog);
|
||||
@@ -525,7 +550,6 @@ void clear_username_cache(void);
|
||||
enum { USERNAME_MAX_SIZE = 16 - sizeof(int) };
|
||||
|
||||
|
||||
struct bb_applet;
|
||||
int execable_file(const char *name);
|
||||
char *find_execable(const char *filename);
|
||||
int exists_execable(const char *filename);
|
||||
@@ -537,7 +561,7 @@ int exists_execable(const char *filename);
|
||||
int bb_execvp(const char *file, char *const argv[]);
|
||||
#define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
|
||||
#define BB_EXECLP(prog,cmd,...) \
|
||||
execlp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, \
|
||||
execlp((find_applet_by_name(prog) >= 0) ? CONFIG_BUSYBOX_EXEC_PATH : prog, \
|
||||
cmd, __VA_ARGS__)
|
||||
#else
|
||||
#define BB_EXECVP(prog,cmd) execvp(prog,cmd)
|
||||
@@ -575,8 +599,8 @@ struct nofork_save_area {
|
||||
void save_nofork_data(struct nofork_save_area *save);
|
||||
void restore_nofork_data(struct nofork_save_area *save);
|
||||
/* Does NOT check that applet is NOFORK, just blindly runs it */
|
||||
int run_nofork_applet(const struct bb_applet *a, char **argv);
|
||||
int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv);
|
||||
int run_nofork_applet(int applet_no, char **argv);
|
||||
int run_nofork_applet_prime(struct nofork_save_area *old, int applet_no, char **argv);
|
||||
|
||||
/* Helpers for daemonization.
|
||||
*
|
||||
@@ -617,12 +641,17 @@ enum {
|
||||
void re_exec(char **argv) ATTRIBUTE_NORETURN;
|
||||
void forkexit_or_rexec(char **argv);
|
||||
extern bool re_execed;
|
||||
int BUG_fork_is_unavailable_on_nommu(void);
|
||||
int BUG_daemon_is_unavailable_on_nommu(void);
|
||||
void BUG_bb_daemonize_is_unavailable_on_nommu(void);
|
||||
# define fork() BUG_fork_is_unavailable_on_nommu()
|
||||
# define daemon(a,b) BUG_daemon_is_unavailable_on_nommu()
|
||||
# define bb_daemonize(a) BUG_bb_daemonize_is_unavailable_on_nommu()
|
||||
#endif
|
||||
void bb_daemonize_or_rexec(int flags, char **argv);
|
||||
void bb_sanitize_stdio(void);
|
||||
/* Clear dangerous stuff, set PATH */
|
||||
void sanitize_env_for_suid(void);
|
||||
|
||||
|
||||
extern const char *opt_complementary;
|
||||
@@ -701,7 +730,7 @@ extern void bb_verror_msg(const char *s, va_list p, const char *strerr);
|
||||
|
||||
/* applets which are useful from another applets */
|
||||
int bb_cat(char** argv);
|
||||
int bb_echo(char** argv);
|
||||
int echo_main(int argc, char** argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int test_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int kill_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
#if ENABLE_ROUTE
|
||||
@@ -759,10 +788,10 @@ const struct hwtype *get_hwntype(int type);
|
||||
|
||||
|
||||
#ifndef BUILD_INDIVIDUAL
|
||||
extern const struct bb_applet *find_applet_by_name(const char *name);
|
||||
extern int find_applet_by_name(const char *name);
|
||||
/* Returns only if applet is not found. */
|
||||
extern void run_applet_and_exit(const char *name, char **argv);
|
||||
extern void run_appletstruct_and_exit(const struct bb_applet *a, char **argv) ATTRIBUTE_NORETURN;
|
||||
extern void run_applet_no_and_exit(int a, char **argv) ATTRIBUTE_NORETURN;
|
||||
#endif
|
||||
|
||||
extern int match_fstype(const struct mntent *mt, const char *fstypes);
|
||||
@@ -785,7 +814,6 @@ extern int set_loop(char **devname, const char *file, unsigned long long offset)
|
||||
//TODO: pass buf pointer or return allocated buf (avoid statics)?
|
||||
char *bb_askpass(int timeout, const char * prompt);
|
||||
int bb_ask_confirmation(void);
|
||||
int klogctl(int type, char * b, int len);
|
||||
|
||||
extern int bb_parse_mode(const char* s, mode_t* theMode);
|
||||
|
||||
@@ -925,10 +953,9 @@ enum {
|
||||
};
|
||||
line_input_t *new_line_input_t(int flags);
|
||||
/* Returns:
|
||||
* -1 on read errors or EOF, or on bare Ctrl-D.
|
||||
* 0 on ctrl-C,
|
||||
* -1 on read errors or EOF, or on bare Ctrl-D,
|
||||
* 0 on ctrl-C (the line entered is still returned in 'command'),
|
||||
* >0 length of input string, including terminating '\n'
|
||||
* [is this true? stores "" in 'command' if return value is 0 or -1]
|
||||
*/
|
||||
int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state);
|
||||
#else
|
||||
|
||||
+3
-3
@@ -116,10 +116,10 @@ extern USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd);
|
||||
#if BB_MMU
|
||||
extern int open_transformer(int src_fd,
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd));
|
||||
#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transformer)
|
||||
#define open_transformer(src_fd, transformer, transform_prog) open_transformer(src_fd, transformer)
|
||||
#else
|
||||
extern int open_transformer(int src_fd, const char *transform_prog, ...);
|
||||
#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transform_prog, __VA_ARGS__)
|
||||
extern int open_transformer(int src_fd, const char *transform_prog);
|
||||
#define open_transformer(src_fd, transformer, transform_prog) open_transformer(src_fd, transform_prog)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+125
-96
@@ -76,7 +76,7 @@
|
||||
"\n -H hwtype Hardware address type"
|
||||
|
||||
#define arping_trivial_usage \
|
||||
"[-fqbDUA] [-c count] [-w timeout] [-i device] [-s sender] target"
|
||||
"[-fqbDUA] [-c count] [-w timeout] [-I dev] [-s sender] target"
|
||||
#define arping_full_usage \
|
||||
"Ping hosts by ARP requests/replies" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -84,13 +84,13 @@
|
||||
" -q Quiet\n" \
|
||||
" -b Keep broadcasting, don't go unicast\n" \
|
||||
" -D Duplicated address detection mode\n" \
|
||||
" -U Unsolicited ARP mode, update your neighbours\n" \
|
||||
" -A ARP answer mode, update your neighbours\n" \
|
||||
" -c count Stop after sending count ARP request packets\n" \
|
||||
" -U Unsolicited ARP mode, update your neighbors\n" \
|
||||
" -A ARP answer mode, update your neighbors\n" \
|
||||
" -c N Stop after sending N ARP requests\n" \
|
||||
" -w timeout Time to wait for ARP reply, in seconds\n" \
|
||||
" -I device Outgoing interface name, default is eth0\n" \
|
||||
" -s sender Set specific sender IP address\n" \
|
||||
" target Target IP address of ARP request"
|
||||
" -I dev Interface to use (default eth0)\n" \
|
||||
" -s sender Sender IP address\n" \
|
||||
" target Target IP address"
|
||||
|
||||
#define ash_trivial_usage \
|
||||
"[FILE]...\n" \
|
||||
@@ -99,7 +99,7 @@
|
||||
"The ash shell (command interpreter)"
|
||||
|
||||
#define awk_trivial_usage \
|
||||
"[OPTION]... [program-text] [FILE ...]"
|
||||
"[OPTION]... [program-text] [FILE...]"
|
||||
#define awk_full_usage \
|
||||
"Options:\n" \
|
||||
" -v var=val Set variable\n" \
|
||||
@@ -548,7 +548,7 @@
|
||||
"Wed Apr 12 18:52:41 MDT 2000\n"
|
||||
|
||||
#define dc_trivial_usage \
|
||||
"expression ..."
|
||||
"expression..."
|
||||
#define dc_full_usage \
|
||||
"This is a Tiny RPN calculator that understands the\n" \
|
||||
"following operations: +, add, -, sub, *, mul, /, div, %, mod, " \
|
||||
@@ -617,7 +617,7 @@
|
||||
|
||||
#define devfsd_trivial_usage \
|
||||
"mntpnt [-v]" \
|
||||
USE_DEVFSD_FG_NP("[-fg][-np]" )
|
||||
USE_DEVFSD_FG_NP("[-fg][-np]")
|
||||
#define devfsd_full_usage \
|
||||
"Manage devfs permissions and old device name symlinks" \
|
||||
"\n\nOptions:" \
|
||||
@@ -630,18 +630,28 @@
|
||||
"\n and processing synthetic REGISTER events," \
|
||||
"\n do not poll for events")
|
||||
|
||||
/* -k is accepted but ignored for !HUMAN_READABLE,
|
||||
* but we won't mention this (unimportant) */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE || ENABLE_FEATURE_DF_INODE
|
||||
#define DF_HAS_OPTIONS(x) x
|
||||
#else
|
||||
#define DF_HAS_OPTIONS(x)
|
||||
#endif
|
||||
#define df_trivial_usage \
|
||||
"[-" USE_FEATURE_HUMAN_READABLE("hm") "k] [FILESYSTEM ...]"
|
||||
DF_HAS_OPTIONS("[-") \
|
||||
USE_FEATURE_HUMAN_READABLE("hmk") USE_FEATURE_DF_INODE("i") \
|
||||
DF_HAS_OPTIONS("] ") "[FILESYSTEM...]"
|
||||
#define df_full_usage \
|
||||
"Print the filesystem space used and space available" \
|
||||
"Print filesystem usage statistics" \
|
||||
DF_HAS_OPTIONS("\n\nOptions:") \
|
||||
USE_FEATURE_HUMAN_READABLE( \
|
||||
"\n\nOptions control size display:" \
|
||||
"\n -h Human readable (e.g. 1K 243M 2G)" \
|
||||
"\n -m 1024*1024 blocks" \
|
||||
"\n -k 1024 blocks") \
|
||||
SKIP_FEATURE_HUMAN_READABLE( \
|
||||
"\n\nOptions:" \
|
||||
"\n -k Ignored")
|
||||
"\n -k 1024 blocks" \
|
||||
) \
|
||||
USE_FEATURE_DF_INODE( \
|
||||
"\n -i Inodes" \
|
||||
)
|
||||
#define df_example_usage \
|
||||
"$ df\n" \
|
||||
"Filesystem 1k-blocks Used Available Use% Mounted on\n" \
|
||||
@@ -828,7 +838,7 @@
|
||||
" -L file Set badblocks list"
|
||||
|
||||
#define echo_trivial_usage \
|
||||
USE_FEATURE_FANCY_ECHO("[-neE] ") "[ARG ...]"
|
||||
USE_FEATURE_FANCY_ECHO("[-neE] ") "[ARG...]"
|
||||
#define echo_full_usage \
|
||||
"Print the specified ARGs to stdout" \
|
||||
USE_FEATURE_FANCY_ECHO( \
|
||||
@@ -998,6 +1008,7 @@
|
||||
"\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \
|
||||
"\n tests/actions to command line arguments only") \
|
||||
"\n -name PATTERN File name (w/o directory name) matches PATTERN" \
|
||||
"\n -iname PATTERN Case insensitive -name" \
|
||||
USE_FEATURE_FIND_PATH( \
|
||||
"\n -path PATTERN Path matches PATTERN") \
|
||||
USE_FEATURE_FIND_REGEX( \
|
||||
@@ -1075,7 +1086,7 @@
|
||||
"$ freeramdisk /dev/ram2\n"
|
||||
|
||||
#define fsck_trivial_usage \
|
||||
"[-ANPRTV] [-C fd] [-t fstype] [fs-options] [filesys ...]"
|
||||
"[-ANPRTV] [-C fd] [-t fstype] [fs-options] [filesys...]"
|
||||
#define fsck_full_usage \
|
||||
"Check and repair filesystems" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -1374,21 +1385,28 @@
|
||||
"daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n"
|
||||
|
||||
#define hexdump_trivial_usage \
|
||||
"[-[bcCdefnosvx]] [OPTION] FILE"
|
||||
"[-bcCdefnosvx" USE_FEATURE_HEXDUMP_REVERSE("R") "] FILE..."
|
||||
#define hexdump_full_usage \
|
||||
"Display file(s) or standard input in a user specified format" \
|
||||
"\n\nOptions:\n" \
|
||||
" -b One-byte octal display\n" \
|
||||
" -c One-byte character display\n" \
|
||||
" -C Canonical hex+ASCII, 16 bytes per line\n" \
|
||||
" -d Two-byte decimal display\n" \
|
||||
" -e FORMAT STRING\n" \
|
||||
" -f FORMAT FILE\n" \
|
||||
" -n LENGTH Interpret only LENGTH bytes of input\n" \
|
||||
" -o Two-byte octal display\n" \
|
||||
" -s OFFSET Skip OFFSET bytes\n" \
|
||||
" -v Display all input data\n" \
|
||||
" -x Two-byte hexadecimal display"
|
||||
"\n\nOptions:" \
|
||||
"\n -b One-byte octal display" \
|
||||
"\n -c One-byte character display" \
|
||||
"\n -C Canonical hex+ASCII, 16 bytes per line" \
|
||||
"\n -d Two-byte decimal display" \
|
||||
"\n -e FORMAT STRING" \
|
||||
"\n -f FORMAT FILE" \
|
||||
"\n -n LENGTH Interpret only LENGTH bytes of input" \
|
||||
"\n -o Two-byte octal display" \
|
||||
"\n -s OFFSET Skip OFFSET bytes" \
|
||||
"\n -v Display all input data" \
|
||||
"\n -x Two-byte hexadecimal display" \
|
||||
USE_FEATURE_HEXDUMP_REVERSE( \
|
||||
"\n -R Reverse of 'hexdump -Cv'") \
|
||||
|
||||
#define hd_trivial_usage \
|
||||
"FILE..."
|
||||
#define hd_full_usage \
|
||||
"hd is an alias for hexdump -C"
|
||||
|
||||
#define hostid_trivial_usage \
|
||||
""
|
||||
@@ -1825,7 +1843,7 @@
|
||||
" -u Unicode (utf-8)"
|
||||
|
||||
#define kill_trivial_usage \
|
||||
"[-l] [-signal] process-id [process-id ...]"
|
||||
"[-l] [-signal] process-id [process-id...]"
|
||||
#define kill_full_usage \
|
||||
"Send a signal (default is TERM) to the specified process(es)" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -1841,7 +1859,7 @@
|
||||
"$ kill 252\n"
|
||||
|
||||
#define killall_trivial_usage \
|
||||
"[-l] [-q] [-signal] process-name [process-name ...]"
|
||||
"[-l] [-q] [-signal] process-name [process-name...]"
|
||||
#define killall_full_usage \
|
||||
"Send a signal (default is TERM) to the specified process(es)" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -1887,7 +1905,7 @@
|
||||
" reached"
|
||||
|
||||
#define setarch_trivial_usage \
|
||||
"personality program [args ...]"
|
||||
"personality program [args...]"
|
||||
#define setarch_full_usage \
|
||||
"Personality may be:\n" \
|
||||
" linux32 Set 32bit uname emulation\n" \
|
||||
@@ -1940,7 +1958,7 @@
|
||||
"$ logger \"hello\"\n"
|
||||
|
||||
#define login_trivial_usage \
|
||||
"[OPTION]... [username] [ENV=VAR ...]"
|
||||
"[OPTION]... [username] [ENV=VAR...]"
|
||||
#define login_full_usage \
|
||||
"Begin a new session on the system" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -2166,8 +2184,8 @@
|
||||
"and * (run both after creating and before deleting). The commands run in\n" \
|
||||
"the /dev directory, and use system() which calls /bin/sh.\n\n" \
|
||||
) \
|
||||
"Config file parsing stops on the first matching line. If no config\n"\
|
||||
"entry is matched, devices are created with default 0:0 660. (Make\n"\
|
||||
"Config file parsing stops on the first matching line. If no config\n" \
|
||||
"entry is matched, devices are created with default 0:0 660. (Make\n" \
|
||||
"the last line match .* to override this.)\n\n" \
|
||||
)
|
||||
|
||||
@@ -2297,7 +2315,7 @@
|
||||
"-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n"
|
||||
|
||||
#define modprobe_trivial_usage \
|
||||
"[-knqrsv] MODULE [symbol=value ...]"
|
||||
"[-knqrsv] MODULE [symbol=value...]"
|
||||
#define modprobe_full_usage \
|
||||
"Options:\n" \
|
||||
" -k Make module autoclean-able\n" \
|
||||
@@ -2331,7 +2349,7 @@
|
||||
" the module and the alias.\n" \
|
||||
" A module can be aliased more than once.\n" \
|
||||
"\n" \
|
||||
" options <mod_name|alias_name> <symbol=value ...>\n" \
|
||||
" options <mod_name|alias_name> <symbol=value...>\n" \
|
||||
" When loading module mod_name (or the module aliased by alias_name), pass\n" \
|
||||
" the \"symbol=value\" pairs as option to that module.\n" \
|
||||
"\n" \
|
||||
@@ -2367,7 +2385,7 @@
|
||||
" from the command line\n"
|
||||
|
||||
#define more_trivial_usage \
|
||||
"[FILE ...]"
|
||||
"[FILE...]"
|
||||
#define more_full_usage \
|
||||
"View FILE or standard input one screenful at a time"
|
||||
#define more_example_usage \
|
||||
@@ -2560,7 +2578,7 @@
|
||||
)
|
||||
|
||||
#define nice_trivial_usage \
|
||||
"[-n ADJUST] [COMMAND [ARG] ...]"
|
||||
"[-n ADJUST] [COMMAND [ARG]...]"
|
||||
#define nice_full_usage \
|
||||
"Run a program with modified scheduling priority" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -2678,7 +2696,7 @@
|
||||
#endif
|
||||
|
||||
#define pidof_trivial_usage \
|
||||
"process-name [OPTION] [process-name ...]"
|
||||
"process-name [OPTION] [process-name...]"
|
||||
|
||||
#define pidof_full_usage \
|
||||
"List the PIDs of all processes with names that match the\n" \
|
||||
@@ -2895,7 +2913,7 @@
|
||||
" -n Disable byte order auto-detection"
|
||||
|
||||
#define realpath_trivial_usage \
|
||||
"pathname ..."
|
||||
"pathname..."
|
||||
#define realpath_full_usage \
|
||||
"Return the absolute pathnames of given argument"
|
||||
|
||||
@@ -2909,7 +2927,7 @@
|
||||
" -f Force reboot (don't go through init)"
|
||||
|
||||
#define renice_trivial_usage \
|
||||
"{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID ...]"
|
||||
"{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"
|
||||
#define renice_full_usage \
|
||||
"Change priority of running processes" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -3104,6 +3122,12 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
" FIRST LAST\n" \
|
||||
" FIRST INCREMENT LAST"
|
||||
|
||||
#define sestatus_trivial_usage \
|
||||
"[-vb]"
|
||||
#define sestatus_full_usage \
|
||||
"-v Verbose\n" \
|
||||
"-b Display current state of booleans"
|
||||
|
||||
#define setconsole_trivial_usage \
|
||||
"[-r" USE_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"
|
||||
#define setconsole_full_usage \
|
||||
@@ -3141,7 +3165,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"\n -W Display warnings about entries that had no matching files"
|
||||
|
||||
#define setkeycodes_trivial_usage \
|
||||
"SCANCODE KEYCODE ..."
|
||||
"SCANCODE KEYCODE..."
|
||||
#define setkeycodes_full_usage \
|
||||
"Set entries into the kernel's scancode-to-keycode map,\n" \
|
||||
"allowing unusual keyboards to generate usable keycodes.\n\n" \
|
||||
@@ -3162,7 +3186,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"Change boolean setting"
|
||||
|
||||
#define setsid_trivial_usage \
|
||||
"program [arg ...]"
|
||||
"program [arg...]"
|
||||
#define setsid_full_usage \
|
||||
"Run any program in a new session by calling setsid() before\n" \
|
||||
"exec'ing the rest of its arguments. See setsid(2) for details."
|
||||
@@ -3171,15 +3195,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"[FILE]...\n" \
|
||||
"or: sh -c command [args]..."
|
||||
#define lash_full_usage \
|
||||
"The BusyBox LAme SHell (command interpreter)"
|
||||
#define lash_notes_usage \
|
||||
"This command does not yet have proper documentation.\n\n" \
|
||||
"Use lash just as you would use any other shell. It properly handles pipes,\n" \
|
||||
"redirects, job control, can be used as the shell for scripts, and has a\n" \
|
||||
"sufficient set of builtins to do what is needed. It does not (yet) support\n" \
|
||||
"Bourne Shell syntax. If you need things like \"if-then-else\", \"while\", and such\n" \
|
||||
"use ash or bash. If you just need a very simple and extremely small shell,\n" \
|
||||
"this will do the job."
|
||||
"lash is deprecated, please use hush"
|
||||
|
||||
#define last_trivial_usage \
|
||||
""
|
||||
@@ -3338,7 +3354,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
USE_FEATURE_STAT_FORMAT( \
|
||||
" -c fmt Use the specified format\n") \
|
||||
" -f Display filesystem status\n" \
|
||||
" -L,-l Dereference links\n" \
|
||||
" -L Dereference links\n" \
|
||||
" -t Display info in terse form" \
|
||||
USE_SELINUX( \
|
||||
"\n -Z Print security context" \
|
||||
@@ -3390,7 +3406,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
)
|
||||
|
||||
#define strings_trivial_usage \
|
||||
"[-afo] [-n length] [file ...]"
|
||||
"[-afo] [-n length] [file...]"
|
||||
#define strings_full_usage \
|
||||
"Display printable strings in a binary file" \
|
||||
"\n\nOptions:" \
|
||||
@@ -3490,16 +3506,17 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"Configure kernel parameters at runtime" \
|
||||
"\n\nOptions:\n" \
|
||||
" -n Disable printing of key names\n" \
|
||||
" -e Don't warn about unknown keys\n" \
|
||||
" -w Change sysctl setting\n" \
|
||||
" -p FILE Load sysctl settings from FILE (default /etc/sysctl.conf)\n" \
|
||||
" -a Display all values\n" \
|
||||
" -A Display all values in table form"
|
||||
#define sysctl_example_usage \
|
||||
"sysctl [-n] variable ...\n" \
|
||||
"sysctl [-n] -w variable=value ...\n" \
|
||||
"sysctl [-n] -a\n" \
|
||||
"sysctl [-n] -p file (default /etc/sysctl.conf)\n" \
|
||||
"sysctl [-n] -A\n"
|
||||
"sysctl [-n] [-e] variable...\n" \
|
||||
"sysctl [-n] [-e] -w variable=value...\n" \
|
||||
"sysctl [-n] [-e] -a\n" \
|
||||
"sysctl [-n] [-e] -p file (default /etc/sysctl.conf)\n" \
|
||||
"sysctl [-n] [-e] -A\n"
|
||||
|
||||
#define syslogd_trivial_usage \
|
||||
"[OPTION]..."
|
||||
@@ -3553,7 +3570,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
USE_FEATURE_TAR_BZIP2("j") USE_FEATURE_TAR_LZMA("a") \
|
||||
USE_FEATURE_TAR_COMPRESS("Z") "xtvO] " \
|
||||
USE_FEATURE_TAR_FROM("[-X FILE] ") \
|
||||
"[-f TARFILE] [-C DIR] [FILE(s)] ..."
|
||||
"[-f TARFILE] [-C DIR] [FILE(s)]..."
|
||||
#define tar_full_usage \
|
||||
"Create, extract, or list files from a tar file" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -3737,7 +3754,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"and show the status for however many processes will fit on the screen."
|
||||
|
||||
#define touch_trivial_usage \
|
||||
"[-c] FILE [FILE ...]"
|
||||
"[-c] FILE [FILE...]"
|
||||
#define touch_full_usage \
|
||||
"Update the last-modified date on the given FILE[s]" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -3823,43 +3840,53 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
|
||||
#define udhcpc_trivial_usage \
|
||||
"[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \
|
||||
" [-p pidfile] [-r IP] [-s script]"
|
||||
" [-p pidfile] [-r IP] [-s script] [-O dhcp-option]..."
|
||||
#define udhcpc_full_usage \
|
||||
USE_GETOPT_LONG( \
|
||||
" -V,--vendorclass=CLASSID Set vendor class identifier" \
|
||||
"\n -i,--interface=INTERFACE Interface to use (default: eth0)" \
|
||||
" -V,--vendorclass=CLASSID Vendor class identifier" \
|
||||
"\n -i,--interface=INTERFACE Interface to use (default eth0)" \
|
||||
"\n -H,-h,--hostname=HOSTNAME Client hostname" \
|
||||
"\n -c,--clientid=CLIENTID Set client identifier" \
|
||||
"\n -c,--clientid=CLIENTID Client identifier" \
|
||||
"\n -C,--clientid-none Suppress default client identifier" \
|
||||
"\n -p,--pidfile=file Store process ID of daemon in file" \
|
||||
"\n -p,--pidfile=file Create pidfile" \
|
||||
"\n -r,--request=IP IP address to request" \
|
||||
"\n -s,--script=file Run file at dhcp events (default: /usr/share/udhcpc/default.script)" \
|
||||
"\n -t,--retries=N Send up to N request packets"\
|
||||
"\n -s,--script=file Run file at dhcp events (default /usr/share/udhcpc/default.script)" \
|
||||
"\n -t,--retries=N Send up to N request packets" \
|
||||
"\n -T,--timeout=N Try to get a lease for N seconds (default 3)" \
|
||||
"\n -A,--tryagain=N Wait N seconds (default 20) after failure" \
|
||||
"\n -f,--foreground Run in foreground" \
|
||||
"\n -b,--background Background if lease cannot be immediately negotiated" \
|
||||
"\n -b,--background Background if lease is not immediately obtained" \
|
||||
"\n -S,--syslog Log to syslog too" \
|
||||
"\n -n,--now Exit with failure if lease cannot be immediately negotiated" \
|
||||
"\n -n,--now Exit with failure if lease is not immediately obtained" \
|
||||
"\n -q,--quit Quit after obtaining lease" \
|
||||
"\n -R,--release Release IP on quit" \
|
||||
"\n -v,--version Display version" \
|
||||
"\n -O,--request-option=OPT Request DHCP option OPT from server" \
|
||||
USE_FEATURE_UDHCPC_ARPING( \
|
||||
"\n -a,--arping Use arping to validate offered address" \
|
||||
) \
|
||||
) \
|
||||
SKIP_GETOPT_LONG( \
|
||||
" -V CLASSID Set vendor class identifier" \
|
||||
" -V CLASSID Vendor class identifier" \
|
||||
"\n -i INTERFACE Interface to use (default: eth0)" \
|
||||
"\n -H,-h HOSTNAME Client hostname" \
|
||||
"\n -c CLIENTID Set client identifier" \
|
||||
"\n -c CLIENTID Client identifier" \
|
||||
"\n -C Suppress default client identifier" \
|
||||
"\n -p file Store process ID of daemon in file" \
|
||||
"\n -p file Create pidfile" \
|
||||
"\n -r IP IP address to request" \
|
||||
"\n -s file Run file at dhcp events (default: /usr/share/udhcpc/default.script)" \
|
||||
"\n -t N Send up to N request packets"\
|
||||
"\n -s file Run file at dhcp events (default /usr/share/udhcpc/default.script)" \
|
||||
"\n -t N Send up to N request packets" \
|
||||
"\n -T N Try to get a lease for N seconds (default 3)" \
|
||||
"\n -A N Wait N seconds (default 20) after failure" \
|
||||
"\n -f Run in foreground" \
|
||||
"\n -b Background if lease cannot be immediately negotiated" \
|
||||
"\n -b Background if lease is not immediately obtained" \
|
||||
"\n -S Log to syslog too" \
|
||||
"\n -n Exit with failure if lease cannot be immediately negotiated" \
|
||||
"\n -n Exit with failure if lease is not immediately obtained" \
|
||||
"\n -q Quit after obtaining lease" \
|
||||
"\n -R Release IP on quit" \
|
||||
"\n -v Display version" \
|
||||
"\n -O OPT Request DHCP option OPT from server" \
|
||||
USE_FEATURE_UDHCPC_ARPING( \
|
||||
"\n -a Use arping to validate offered address" \
|
||||
) \
|
||||
)
|
||||
|
||||
#define udhcpd_trivial_usage \
|
||||
@@ -3888,17 +3915,17 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"$ umount /dev/hdc1\n"
|
||||
|
||||
#define uname_trivial_usage \
|
||||
"[OPTION]..."
|
||||
"[-amnrspv]"
|
||||
#define uname_full_usage \
|
||||
"Print certain system information. With no OPTION, same as -s." \
|
||||
"Print system information." \
|
||||
"\n\nOptions:\n" \
|
||||
" -a Print all information\n" \
|
||||
" -a Print all\n" \
|
||||
" -m The machine (hardware) type\n" \
|
||||
" -n Print machine's hostname\n" \
|
||||
" -r Print OS release\n" \
|
||||
" -s Print OS name\n" \
|
||||
" -p Print host processor type\n" \
|
||||
" -v Print OS version"
|
||||
" -n Hostname\n" \
|
||||
" -r OS release\n" \
|
||||
" -s OS name (default)\n" \
|
||||
" -p Processor type\n" \
|
||||
" -v OS version"
|
||||
#define uname_example_usage \
|
||||
"$ uname -a\n" \
|
||||
"Linux debian 2.4.23 #2 Tue Dec 23 17:09:10 MST 2003 i686 GNU/Linux\n"
|
||||
@@ -3909,7 +3936,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"Uncompress .Z file[s]" \
|
||||
"\n\nOptions:\n" \
|
||||
" -c Extract to stdout\n" \
|
||||
" -f Force overwrite an existing file"
|
||||
" -f Overwrite an existing file"
|
||||
|
||||
#define unexpand_trivial_usage \
|
||||
"[-f][-a][-t NUM] [FILE|-]"
|
||||
@@ -4007,7 +4034,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"$\n"
|
||||
|
||||
#define vconfig_trivial_usage \
|
||||
"COMMAND [OPTIONS] ..."
|
||||
"COMMAND [OPTIONS]..."
|
||||
#define vconfig_full_usage \
|
||||
"Create and remove virtual ethernet devices" \
|
||||
"\n\nOptions:\n" \
|
||||
@@ -4090,7 +4117,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
" -Y Use proxy ('on' or 'off')"
|
||||
|
||||
#define which_trivial_usage \
|
||||
"[COMMAND ...]"
|
||||
"[COMMAND...]"
|
||||
#define which_full_usage \
|
||||
"Locate a COMMAND"
|
||||
#define which_example_usage \
|
||||
@@ -4098,9 +4125,11 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
|
||||
"/bin/login\n"
|
||||
|
||||
#define who_trivial_usage \
|
||||
" "
|
||||
"[-a]"
|
||||
#define who_full_usage \
|
||||
"Print the current user names and related information"
|
||||
"Show who is logged on" \
|
||||
"\n\nOptions:\n" \
|
||||
" -a show all"
|
||||
|
||||
#define whoami_trivial_usage \
|
||||
""
|
||||
|
||||
@@ -37,6 +37,7 @@ config FEATURE_INIT_SCTTY
|
||||
controlling tty (TIOCSCTTY). This is not the traditional init
|
||||
behavour, but is often what you want in an embedded system where
|
||||
the console is only accessed during development or for maintenance.
|
||||
NB: using cttyhack applet may work better.
|
||||
|
||||
config FEATURE_INIT_SYSLOG
|
||||
bool "Enable init to write to syslog"
|
||||
|
||||
+148
-137
@@ -11,9 +11,6 @@
|
||||
|
||||
#include "libbb.h"
|
||||
#include <paths.h>
|
||||
//#include <signal.h>
|
||||
//#include <sys/ioctl.h>
|
||||
//#include <sys/wait.h>
|
||||
#include <sys/reboot.h>
|
||||
|
||||
#if ENABLE_FEATURE_INIT_SYSLOG
|
||||
@@ -50,31 +47,22 @@
|
||||
#define SHUTDOWN 0x040
|
||||
#define RESTART 0x080
|
||||
|
||||
/* A mapping between "inittab" action name strings and action type codes. */
|
||||
struct init_action_type {
|
||||
const char *name;
|
||||
int action;
|
||||
};
|
||||
|
||||
static const struct init_action_type actions[] = {
|
||||
{"sysinit", SYSINIT},
|
||||
{"respawn", RESPAWN},
|
||||
{"askfirst", ASKFIRST},
|
||||
{"wait", WAIT},
|
||||
{"once", ONCE},
|
||||
{"ctrlaltdel", CTRLALTDEL},
|
||||
{"shutdown", SHUTDOWN},
|
||||
{"restart", RESTART},
|
||||
{0, 0}
|
||||
};
|
||||
#define STR_SYSINIT "\x01"
|
||||
#define STR_RESPAWN "\x02"
|
||||
#define STR_ASKFIRST "\x04"
|
||||
#define STR_WAIT "\x08"
|
||||
#define STR_ONCE "\x10"
|
||||
#define STR_CTRLALTDEL "\x20"
|
||||
#define STR_SHUTDOWN "\x40"
|
||||
#define STR_RESTART "\x80"
|
||||
|
||||
/* Set up a linked list of init_actions, to be read from inittab */
|
||||
struct init_action {
|
||||
struct init_action *next;
|
||||
int action;
|
||||
pid_t pid;
|
||||
char command[INIT_BUFFS_SIZE];
|
||||
uint8_t action;
|
||||
char terminal[CONSOLE_NAME_SIZE];
|
||||
char command[INIT_BUFFS_SIZE];
|
||||
};
|
||||
|
||||
/* Static variables */
|
||||
@@ -116,7 +104,7 @@ static const char *const environment[] = {
|
||||
|
||||
/* Function prototypes */
|
||||
static void delete_init_action(struct init_action *a);
|
||||
static int waitfor(const struct init_action *a, pid_t pid);
|
||||
static int waitfor(pid_t pid);
|
||||
#if !ENABLE_DEBUG_INIT
|
||||
static void shutdown_signal(int sig);
|
||||
#endif
|
||||
@@ -196,43 +184,6 @@ static void message(int device, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
/* Set terminal settings to reasonable defaults */
|
||||
static void set_sane_term(void)
|
||||
{
|
||||
struct termios tty;
|
||||
|
||||
tcgetattr(STDIN_FILENO, &tty);
|
||||
|
||||
/* set control chars */
|
||||
tty.c_cc[VINTR] = 3; /* C-c */
|
||||
tty.c_cc[VQUIT] = 28; /* C-\ */
|
||||
tty.c_cc[VERASE] = 127; /* C-? */
|
||||
tty.c_cc[VKILL] = 21; /* C-u */
|
||||
tty.c_cc[VEOF] = 4; /* C-d */
|
||||
tty.c_cc[VSTART] = 17; /* C-q */
|
||||
tty.c_cc[VSTOP] = 19; /* C-s */
|
||||
tty.c_cc[VSUSP] = 26; /* C-z */
|
||||
|
||||
/* use line dicipline 0 */
|
||||
tty.c_line = 0;
|
||||
|
||||
/* Make it be sane */
|
||||
tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
|
||||
tty.c_cflag |= CREAD | HUPCL | CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = ICRNL | IXON | IXOFF;
|
||||
|
||||
/* output modes */
|
||||
tty.c_oflag = OPOST | ONLCR;
|
||||
|
||||
/* local modes */
|
||||
tty.c_lflag =
|
||||
ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty);
|
||||
}
|
||||
|
||||
/* From <linux/serial.h> */
|
||||
struct serial_struct {
|
||||
int type;
|
||||
@@ -274,13 +225,27 @@ static void console_init(void)
|
||||
}
|
||||
messageD(L_LOG, "console='%s'", s);
|
||||
} else {
|
||||
/* Make sure fd 0,1,2 are not closed */
|
||||
bb_sanitize_stdio();
|
||||
/* Make sure fd 0,1,2 are not closed
|
||||
* (so that they won't be used by future opens) */
|
||||
|
||||
/* bb_sanitize_stdio(); - WRONG.
|
||||
* Fail if "/dev/null" doesnt exist, and for init
|
||||
* this is a real possibility! Open code it instead. */
|
||||
|
||||
int fd = open(bb_dev_null, O_RDWR);
|
||||
if (fd < 0) {
|
||||
/* Give me _ANY_ open descriptor! */
|
||||
fd = xopen("/", O_RDONLY); /* we don't believe this can fail */
|
||||
}
|
||||
while ((unsigned)fd < 2)
|
||||
fd = dup(fd);
|
||||
if (fd > 2)
|
||||
close (fd);
|
||||
}
|
||||
|
||||
s = getenv("TERM");
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
/* Force the TERM setting to vt102 for serial console --
|
||||
/* Force the TERM setting to vt102 for serial console
|
||||
* if TERM is set to linux (the default) */
|
||||
if (!s || strcmp(s, "linux") == 0)
|
||||
putenv((char*)"TERM=vt102");
|
||||
@@ -291,14 +256,41 @@ static void console_init(void)
|
||||
putenv((char*)"TERM=linux");
|
||||
}
|
||||
|
||||
static void fixup_argv(char **argv)
|
||||
/* Set terminal settings to reasonable defaults */
|
||||
static void set_sane_term(void)
|
||||
{
|
||||
/* Fix up argv[0] to be certain we claim to be init */
|
||||
strncpy(argv[0], "init", strlen(argv[0]));
|
||||
struct termios tty;
|
||||
|
||||
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
|
||||
while (*++argv)
|
||||
memset(*argv, 0, strlen(*argv));
|
||||
tcgetattr(STDIN_FILENO, &tty);
|
||||
|
||||
/* set control chars */
|
||||
tty.c_cc[VINTR] = 3; /* C-c */
|
||||
tty.c_cc[VQUIT] = 28; /* C-\ */
|
||||
tty.c_cc[VERASE] = 127; /* C-? */
|
||||
tty.c_cc[VKILL] = 21; /* C-u */
|
||||
tty.c_cc[VEOF] = 4; /* C-d */
|
||||
tty.c_cc[VSTART] = 17; /* C-q */
|
||||
tty.c_cc[VSTOP] = 19; /* C-s */
|
||||
tty.c_cc[VSUSP] = 26; /* C-z */
|
||||
|
||||
/* use line dicipline 0 */
|
||||
tty.c_line = 0;
|
||||
|
||||
/* Make it be sane */
|
||||
tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
|
||||
tty.c_cflag |= CREAD | HUPCL | CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = ICRNL | IXON | IXOFF;
|
||||
|
||||
/* output modes */
|
||||
tty.c_oflag = OPOST | ONLCR;
|
||||
|
||||
/* local modes */
|
||||
tty.c_lflag =
|
||||
ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty);
|
||||
}
|
||||
|
||||
/* Open the new terminal device */
|
||||
@@ -327,6 +319,7 @@ static void open_stdio_to_tty(const char* tty_name, int fail)
|
||||
set_sane_term();
|
||||
}
|
||||
|
||||
/* Used only by run_actions */
|
||||
static pid_t run(const struct init_action *a)
|
||||
{
|
||||
int i;
|
||||
@@ -336,16 +329,20 @@ static pid_t run(const struct init_action *a)
|
||||
char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */
|
||||
sigset_t nmask, omask;
|
||||
|
||||
/* Block sigchild while forking. */
|
||||
/* Block sigchild while forking (why?) */
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &nmask, &omask);
|
||||
pid = fork();
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
|
||||
if (pid < 0)
|
||||
message(L_LOG | L_CONSOLE, "Can't fork");
|
||||
if (pid)
|
||||
return pid;
|
||||
|
||||
/* Child */
|
||||
|
||||
/* Reset signal handlers that were set by the parent process */
|
||||
signal(SIGUSR1, SIG_DFL);
|
||||
signal(SIGUSR2, SIG_DFL);
|
||||
@@ -362,33 +359,35 @@ static pid_t run(const struct init_action *a)
|
||||
setsid();
|
||||
|
||||
/* Open the new terminal device */
|
||||
open_stdio_to_tty(a->terminal, 1);
|
||||
open_stdio_to_tty(a->terminal, 1 /* - exit if open fails*/);
|
||||
|
||||
#ifdef BUT_RUN_ACTIONS_ALREADY_DOES_WAITING
|
||||
/* If the init Action requires us to wait, then force the
|
||||
* supplied terminal to be the controlling tty. */
|
||||
if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
||||
|
||||
/* Now fork off another process to just hang around */
|
||||
if ((pid = fork()) < 0) {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
message(L_LOG | L_CONSOLE, "Can't fork");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
|
||||
/* We are the parent -- wait till the child is done */
|
||||
/* Parent - wait till the child is done */
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
waitfor(NULL, pid);
|
||||
waitfor(pid);
|
||||
/* See if stealing the controlling tty back is necessary */
|
||||
if (tcgetpgrp(0) != getpid())
|
||||
_exit(0);
|
||||
|
||||
/* Use a temporary process to steal the controlling tty. */
|
||||
if ((pid = fork()) < 0) {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
message(L_LOG | L_CONSOLE, "Can't fork");
|
||||
_exit(1);
|
||||
}
|
||||
@@ -397,12 +396,13 @@ static pid_t run(const struct init_action *a)
|
||||
ioctl(0, TIOCSCTTY, 1);
|
||||
_exit(0);
|
||||
}
|
||||
waitfor(NULL, pid);
|
||||
waitfor(pid);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/* Now fall though to actually execute things */
|
||||
/* Child - fall though to actually execute things */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* See if any special /bin/sh requiring characters are present */
|
||||
if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
|
||||
@@ -435,9 +435,9 @@ static pid_t run(const struct init_action *a)
|
||||
/* skip over the dash */
|
||||
++cmdpath;
|
||||
|
||||
#ifdef WHY_WE_DO_THIS_SHELL_MUST_HANDLE_THIS_ITSELF
|
||||
/* find the last component in the command pathname */
|
||||
s = bb_get_last_path_component_nostrip(cmdpath);
|
||||
|
||||
/* make a new argv[0] */
|
||||
cmd[0] = malloc(strlen(s) + 2);
|
||||
if (cmd[0] == NULL) {
|
||||
@@ -447,16 +447,16 @@ static pid_t run(const struct init_action *a)
|
||||
cmd[0][0] = '-';
|
||||
strcpy(cmd[0] + 1, s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_INIT_SCTTY
|
||||
/* Establish this process as session leader and
|
||||
* (attempt) to make the tty (if any) a controlling tty.
|
||||
* _attempt_ to make stdin a controlling tty.
|
||||
*/
|
||||
setsid();
|
||||
ioctl(0, TIOCSCTTY, 0 /*don't steal it*/);
|
||||
ioctl(0, TIOCSCTTY, 0 /*only try, don't steal*/);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__)
|
||||
if (a->action & ASKFIRST) {
|
||||
static const char press_enter[] ALIGN1 =
|
||||
#ifdef CUSTOMIZED_BANNER
|
||||
@@ -476,10 +476,10 @@ static pid_t run(const struct init_action *a)
|
||||
"(pid %d, tty '%s')\n",
|
||||
cmdpath, getpid(), a->terminal);
|
||||
full_write(1, press_enter, sizeof(press_enter) - 1);
|
||||
while (read(0, &c, 1) == 1 && c != '\n')
|
||||
;
|
||||
while (safe_read(0, &c, 1) == 1 && c != '\n')
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Log the process name and args */
|
||||
message(L_LOG, "starting pid %d, tty '%s': '%s'",
|
||||
getpid(), a->terminal, cmdpath);
|
||||
@@ -506,22 +506,15 @@ static pid_t run(const struct init_action *a)
|
||||
_exit(-1);
|
||||
}
|
||||
|
||||
static int waitfor(const struct init_action *a, pid_t pid)
|
||||
static int waitfor(pid_t runpid)
|
||||
{
|
||||
int runpid;
|
||||
int status, wpid;
|
||||
|
||||
runpid = (NULL == a)? pid : run(a);
|
||||
while (1) {
|
||||
wpid = waitpid(runpid, &status, 0);
|
||||
if (wpid == runpid)
|
||||
break;
|
||||
if (wpid == -1 && errno == ECHILD) {
|
||||
/* we missed its termination */
|
||||
break;
|
||||
}
|
||||
/* FIXME other errors should maybe trigger an error, but allow
|
||||
* the program to continue */
|
||||
if (wpid == -1 && errno == EINTR)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
return wpid;
|
||||
}
|
||||
@@ -534,11 +527,14 @@ static void run_actions(int action)
|
||||
for (a = init_action_list; a; a = tmp) {
|
||||
tmp = a->next;
|
||||
if (a->action == action) {
|
||||
/* a->terminal of "" means "init's console" */
|
||||
if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
|
||||
delete_init_action(a);
|
||||
} else if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
||||
waitfor(a, 0);
|
||||
// Pointless: run() will error out if open of device fails.
|
||||
///* a->terminal of "" means "init's console" */
|
||||
//if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
|
||||
// //message(L_LOG | L_CONSOLE, "Device %s cannot be opened in RW mode", a->terminal /*, strerror(errno)*/);
|
||||
// delete_init_action(a);
|
||||
//} else
|
||||
if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
|
||||
waitfor(run(a));
|
||||
delete_init_action(a);
|
||||
} else if (a->action & ONCE) {
|
||||
run(a);
|
||||
@@ -609,6 +605,29 @@ static void shutdown_system(void)
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
static void shutdown_signal(int sig)
|
||||
{
|
||||
const char *m;
|
||||
int rb;
|
||||
|
||||
shutdown_system();
|
||||
|
||||
m = "halt";
|
||||
rb = RB_HALT_SYSTEM;
|
||||
if (sig == SIGTERM) {
|
||||
m = "reboot";
|
||||
rb = RB_AUTOBOOT;
|
||||
} else if (sig == SIGUSR2) {
|
||||
m = "poweroff";
|
||||
rb = RB_POWER_OFF;
|
||||
}
|
||||
message(L_CONSOLE | L_LOG, "Requesting system %s", m);
|
||||
/* allow time for last message to reach serial console */
|
||||
sleep(2);
|
||||
init_reboot(rb);
|
||||
loop_forever();
|
||||
}
|
||||
|
||||
static void exec_signal(int sig ATTRIBUTE_UNUSED)
|
||||
{
|
||||
struct init_action *a, *tmp;
|
||||
@@ -634,7 +653,7 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED)
|
||||
sigprocmask(SIG_UNBLOCK, &unblock_signals, NULL);
|
||||
|
||||
/* Open the new terminal device */
|
||||
open_stdio_to_tty(a->terminal, 0);
|
||||
open_stdio_to_tty(a->terminal, 0 /* - shutdown_signal(SIGUSR1) [halt] if open fails */);
|
||||
|
||||
messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command);
|
||||
BB_EXECLP(a->command, a->command, NULL);
|
||||
@@ -648,29 +667,6 @@ static void exec_signal(int sig ATTRIBUTE_UNUSED)
|
||||
}
|
||||
}
|
||||
|
||||
static void shutdown_signal(int sig)
|
||||
{
|
||||
const char *m;
|
||||
int rb;
|
||||
|
||||
shutdown_system();
|
||||
|
||||
m = "halt";
|
||||
rb = RB_HALT_SYSTEM;
|
||||
if (sig == SIGTERM) {
|
||||
m = "reboot";
|
||||
rb = RB_AUTOBOOT;
|
||||
} else if (sig == SIGUSR2) {
|
||||
m = "poweroff";
|
||||
rb = RB_POWER_OFF;
|
||||
}
|
||||
message(L_CONSOLE | L_LOG, "Requesting system %s", m);
|
||||
/* allow time for last message to reach serial console */
|
||||
sleep(2);
|
||||
init_reboot(rb);
|
||||
loop_forever();
|
||||
}
|
||||
|
||||
static void ctrlaltdel_signal(int sig ATTRIBUTE_UNUSED)
|
||||
{
|
||||
run_actions(CTRLALTDEL);
|
||||
@@ -684,7 +680,7 @@ static void stop_handler(int sig ATTRIBUTE_UNUSED)
|
||||
got_cont = 0;
|
||||
while (!got_cont)
|
||||
pause();
|
||||
got_cont = 0;
|
||||
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
@@ -696,7 +692,7 @@ static void cont_handler(int sig ATTRIBUTE_UNUSED)
|
||||
|
||||
#endif /* !ENABLE_DEBUG_INIT */
|
||||
|
||||
static void new_init_action(int action, const char *command, const char *cons)
|
||||
static void new_init_action(uint8_t action, const char *command, const char *cons)
|
||||
{
|
||||
struct init_action *new_action, *a, *last;
|
||||
|
||||
@@ -756,11 +752,21 @@ static void delete_init_action(struct init_action *action)
|
||||
static void parse_inittab(void)
|
||||
{
|
||||
#if ENABLE_FEATURE_USE_INITTAB
|
||||
static const char actions[] =
|
||||
STR_SYSINIT "sysinit\0"
|
||||
STR_RESPAWN "respawn\0"
|
||||
STR_ASKFIRST "askfirst\0"
|
||||
STR_WAIT "wait\0"
|
||||
STR_ONCE "once\0"
|
||||
STR_CTRLALTDEL "ctrlaltdel\0"
|
||||
STR_SHUTDOWN "shutdown\0"
|
||||
STR_RESTART "restart\0"
|
||||
;
|
||||
|
||||
FILE *file;
|
||||
char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE];
|
||||
char tmpConsole[CONSOLE_NAME_SIZE];
|
||||
char *id, *runlev, *action, *command, *eol;
|
||||
const struct init_action_type *a = actions;
|
||||
|
||||
file = fopen(INITTAB, "r");
|
||||
if (file == NULL) {
|
||||
@@ -771,7 +777,8 @@ static void parse_inittab(void)
|
||||
/* Umount all filesystems on halt/reboot */
|
||||
new_init_action(SHUTDOWN, "umount -a -r", "");
|
||||
/* Swapoff on halt/reboot */
|
||||
if (ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "swapoff -a", "");
|
||||
if (ENABLE_SWAPONOFF)
|
||||
new_init_action(SHUTDOWN, "swapoff -a", "");
|
||||
/* Prepare to restart init when a HUP is received */
|
||||
new_init_action(RESTART, "init", "");
|
||||
/* Askfirst shell on tty1-4 */
|
||||
@@ -787,6 +794,8 @@ static void parse_inittab(void)
|
||||
}
|
||||
|
||||
while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) {
|
||||
const char *a;
|
||||
|
||||
/* Skip leading spaces */
|
||||
for (id = buf; *id == ' ' || *id == '\t'; id++);
|
||||
|
||||
@@ -834,8 +843,8 @@ static void parse_inittab(void)
|
||||
}
|
||||
|
||||
/* Ok, now process it */
|
||||
for (a = actions; a->name != 0; a++) {
|
||||
if (strcmp(a->name, action) == 0) {
|
||||
for (a = actions; a[0]; a += strlen(a) + 1) {
|
||||
if (strcmp(a + 1, action) == 0) {
|
||||
if (*id != '\0') {
|
||||
if (strncmp(id, "/dev/", 5) == 0)
|
||||
id += 5;
|
||||
@@ -844,11 +853,11 @@ static void parse_inittab(void)
|
||||
sizeof(tmpConsole) - 5);
|
||||
id = tmpConsole;
|
||||
}
|
||||
new_init_action(a->action, command, id);
|
||||
new_init_action((uint8_t)a[0], command, id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (a->name == 0) {
|
||||
if (!a[0]) {
|
||||
/* Choke on an unknown action */
|
||||
message(L_LOG | L_CONSOLE, "Bad inittab entry: %s", lineAsRead);
|
||||
}
|
||||
@@ -976,7 +985,6 @@ int init_main(int argc, char **argv)
|
||||
BB_EXECVP(argv[0], argv);
|
||||
} else if (enforce > 0) {
|
||||
/* SELinux in enforcing mode but load_policy failed */
|
||||
/* At this point, we probably can't open /dev/console, so log() won't work */
|
||||
message(L_CONSOLE, "Cannot load SELinux Policy. "
|
||||
"Machine is in enforcing mode. Halting now.");
|
||||
exit(1);
|
||||
@@ -984,8 +992,11 @@ int init_main(int argc, char **argv)
|
||||
}
|
||||
#endif /* CONFIG_SELINUX */
|
||||
|
||||
/* Make the command line just say "init" -- thats all, nothing else */
|
||||
fixup_argv(argv);
|
||||
/* Make the command line just say "init" - thats all, nothing else */
|
||||
strncpy(argv[0], "init", strlen(argv[0]));
|
||||
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
|
||||
while (*++argv)
|
||||
memset(*argv, 0, strlen(*argv));
|
||||
|
||||
/* Now run everything that needs to be run */
|
||||
|
||||
|
||||
@@ -110,6 +110,16 @@ config FEATURE_EDITING_FANCY_PROMPT
|
||||
Setting this option allows for prompts to use things like \w and
|
||||
\$ and escape codes.
|
||||
|
||||
config FEATURE_COPYBUF_KB
|
||||
int "Copy buffer size, in kilobytes"
|
||||
range 1 1024
|
||||
default 4
|
||||
help
|
||||
Size of buffer used by cp, mv, install etc.
|
||||
Buffers which are 4 kb or less will be allocated on stack.
|
||||
Bigger buffers will be allocated with mmap, with fallback to 4 kb
|
||||
stack buffer if mmap fails.
|
||||
|
||||
config MONOTONIC_SYSCALL
|
||||
bool "Use clock_gettime(CLOCK_MONOTONIC) syscall"
|
||||
default y
|
||||
|
||||
+50
-49
@@ -33,13 +33,9 @@ static const char usage_messages[] ALIGN1 = ""
|
||||
#define usage_messages 0
|
||||
#endif /* SHOW_USAGE */
|
||||
|
||||
/* Define struct bb_applet applets[] */
|
||||
#include "applets.h"
|
||||
|
||||
#if ENABLE_FEATURE_SH_STANDALONE
|
||||
/* -1 because last entry is NULL */
|
||||
const unsigned short NUM_APPLETS = ARRAY_SIZE(applets) - 1;
|
||||
#endif
|
||||
/* Include generated applet names, pointers to <apllet>_main, etc */
|
||||
#include "applet_tables.h"
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_COMPRESS_USAGE
|
||||
@@ -84,16 +80,14 @@ void bb_show_usage(void)
|
||||
const char *format_string;
|
||||
const char *p;
|
||||
const char *usage_string = p = unpack_usage_messages();
|
||||
const struct bb_applet *ap = find_applet_by_name(applet_name);
|
||||
int i;
|
||||
int ap = find_applet_by_name(applet_name);
|
||||
|
||||
if (!ap) /* never happens, paranoia */
|
||||
if (ap < 0) /* never happens, paranoia */
|
||||
xfunc_die();
|
||||
|
||||
i = ap - applets;
|
||||
while (i) {
|
||||
while (ap) {
|
||||
while (*p++) continue;
|
||||
i--;
|
||||
ap--;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s multi-call binary\n", bb_banner);
|
||||
@@ -107,18 +101,20 @@ void bb_show_usage(void)
|
||||
}
|
||||
|
||||
|
||||
static int applet_name_compare(const void *name, const void *vapplet)
|
||||
/* NB: any char pointer will work as well, not necessarily applet_names */
|
||||
static int applet_name_compare(const void *name, const void *v)
|
||||
{
|
||||
const struct bb_applet *applet = vapplet;
|
||||
|
||||
return strcmp(name, applet->name);
|
||||
int i = (const char *)v - applet_names;
|
||||
return strcmp(name, APPLET_NAME(i));
|
||||
}
|
||||
|
||||
const struct bb_applet *find_applet_by_name(const char *name)
|
||||
int find_applet_by_name(const char *name)
|
||||
{
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]),
|
||||
applet_name_compare);
|
||||
const char *p;
|
||||
p = bsearch(name, applet_names, ARRAY_SIZE(applet_main), 1, applet_name_compare);
|
||||
if (!p)
|
||||
return -1;
|
||||
return p - applet_names;
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +162,7 @@ USE_FEATURE_SUID(static uid_t ruid;) /* real uid */
|
||||
|
||||
/* applets[] is const, so we have to define this "override" structure */
|
||||
static struct BB_suid_config {
|
||||
const struct bb_applet *m_applet;
|
||||
int m_applet;
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
@@ -232,7 +228,7 @@ static void parse_config_file(void)
|
||||
{
|
||||
struct BB_suid_config *sct_head;
|
||||
struct BB_suid_config *sct;
|
||||
const struct bb_applet *applet;
|
||||
int applet_no;
|
||||
FILE *f;
|
||||
const char *errmsg;
|
||||
char *s;
|
||||
@@ -343,14 +339,14 @@ static void parse_config_file(void)
|
||||
* applet is currently built in and ignore it otherwise.
|
||||
* Note: this can hide config file bugs which only pop
|
||||
* up when the busybox configuration is changed. */
|
||||
applet = find_applet_by_name(s);
|
||||
if (applet) {
|
||||
applet_no = find_applet_by_name(s);
|
||||
if (applet_no >= 0) {
|
||||
/* 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_applet = applet_no;
|
||||
sct->m_mode = 0;
|
||||
sct->m_next = sct_head;
|
||||
sct_head = sct;
|
||||
@@ -441,7 +437,7 @@ static inline void parse_config_file(void)
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
static void check_suid(const struct bb_applet *applet)
|
||||
static void check_suid(int applet_no)
|
||||
{
|
||||
gid_t rgid; /* real gid */
|
||||
|
||||
@@ -456,7 +452,7 @@ static void check_suid(const struct bb_applet *applet)
|
||||
mode_t m;
|
||||
|
||||
for (sct = suid_config; sct; sct = sct->m_next) {
|
||||
if (sct->m_applet == applet)
|
||||
if (sct->m_applet == applet_no)
|
||||
goto found;
|
||||
}
|
||||
goto check_need_suid;
|
||||
@@ -504,12 +500,12 @@ static void check_suid(const struct bb_applet *applet)
|
||||
#endif
|
||||
check_need_suid:
|
||||
#endif
|
||||
if (applet->need_suid == _BB_SUID_ALWAYS) {
|
||||
if (APPLET_SUID(applet_no) == _BB_SUID_ALWAYS) {
|
||||
/* Real uid is not 0. If euid isn't 0 too, suid bit
|
||||
* is most probably not set on our executable */
|
||||
if (geteuid())
|
||||
bb_error_msg_and_die("must be suid to work properly");
|
||||
} else if (applet->need_suid == _BB_SUID_NEVER) {
|
||||
} else if (APPLET_SUID(applet_no) == _BB_SUID_NEVER) {
|
||||
xsetgid(rgid); /* drop all privileges */
|
||||
xsetuid(ruid);
|
||||
}
|
||||
@@ -536,18 +532,21 @@ static void install_links(const char *busybox, int use_symbolic_links)
|
||||
usr_sbin
|
||||
};
|
||||
|
||||
int (*lf)(const char *, const char *) = link;
|
||||
int (*lf)(const char *, const char *);
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
lf = link;
|
||||
if (use_symbolic_links)
|
||||
lf = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(applet_main); i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].install_loc],
|
||||
applets[i].name);
|
||||
install_dir[APPLET_INSTALL_LOC(i)],
|
||||
APPLET_NAME(i));
|
||||
// debug: bb_error_msg("%slinking %s to busybox",
|
||||
// use_symbolic_links ? "sym" : "", fpc);
|
||||
rc = lf(busybox, fpc);
|
||||
if (rc != 0 && errno != EEXIST) {
|
||||
bb_simple_perror_msg(fpc);
|
||||
@@ -564,7 +563,7 @@ static int busybox_main(char **argv)
|
||||
{
|
||||
if (!argv[1]) {
|
||||
/* Called without arguments */
|
||||
const struct bb_applet *a;
|
||||
const char *a;
|
||||
int col, output_width;
|
||||
help:
|
||||
output_width = 80;
|
||||
@@ -576,26 +575,28 @@ static int busybox_main(char **argv)
|
||||
output_width -= sizeof("start-stop-daemon, ") + 8;
|
||||
|
||||
printf("%s multi-call binary\n", bb_banner); /* reuse const string... */
|
||||
printf("Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n"
|
||||
"Licensed under GPLv2. See source distribution for full notice.\n"
|
||||
printf("Copyright (C) 1998-2007 Erik Andersen, Rob Landley, Denys Vlasenko\n"
|
||||
"and others. Licensed under GPLv2.\n"
|
||||
"See source distribution for full notice.\n"
|
||||
"\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [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");
|
||||
"\n"
|
||||
"Currently defined functions:\n");
|
||||
col = 0;
|
||||
a = applets;
|
||||
while (a->name) {
|
||||
a = applet_names;
|
||||
while (*a) {
|
||||
if (col > output_width) {
|
||||
puts(",");
|
||||
col = 0;
|
||||
}
|
||||
col += printf("%s%s", (col ? ", " : "\t"), a->name);
|
||||
a++;
|
||||
col += printf("%s%s", (col ? ", " : "\t"), a);
|
||||
a += strlen(a) + 1;
|
||||
}
|
||||
puts("\n");
|
||||
return 0;
|
||||
@@ -629,7 +630,7 @@ static int busybox_main(char **argv)
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
void run_appletstruct_and_exit(const struct bb_applet *applet, char **argv)
|
||||
void run_applet_no_and_exit(int applet_no, char **argv)
|
||||
{
|
||||
int argc = 1;
|
||||
|
||||
@@ -640,19 +641,19 @@ void run_appletstruct_and_exit(const struct bb_applet *applet, char **argv)
|
||||
optind = 1;
|
||||
xfunc_error_retval = EXIT_FAILURE;
|
||||
|
||||
applet_name = applet->name;
|
||||
applet_name = APPLET_NAME(applet_no);
|
||||
if (argc == 2 && !strcmp(argv[1], "--help"))
|
||||
bb_show_usage();
|
||||
if (ENABLE_FEATURE_SUID)
|
||||
check_suid(applet);
|
||||
exit(applet->main(argc, argv));
|
||||
check_suid(applet_no);
|
||||
exit(applet_main[applet_no](argc, argv));
|
||||
}
|
||||
|
||||
void run_applet_and_exit(const char *name, char **argv)
|
||||
{
|
||||
const struct bb_applet *applet = find_applet_by_name(name);
|
||||
if (applet)
|
||||
run_appletstruct_and_exit(applet, argv);
|
||||
int applet = find_applet_by_name(name);
|
||||
if (applet >= 0)
|
||||
run_applet_no_and_exit(applet, argv);
|
||||
if (!strncmp(name, "busybox", 7))
|
||||
exit(busybox_main(argv));
|
||||
}
|
||||
|
||||
+26
-8
@@ -9,31 +9,44 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if BUFSIZ < 4096
|
||||
#undef BUFSIZ
|
||||
#define BUFSIZ 4096
|
||||
#endif
|
||||
|
||||
/* Used by NOFORK applets (e.g. cat) - must not use xmalloc */
|
||||
|
||||
static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
|
||||
{
|
||||
int status = -1;
|
||||
off_t total = 0;
|
||||
char buffer[BUFSIZ];
|
||||
#if CONFIG_FEATURE_COPYBUF_KB <= 4
|
||||
char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
|
||||
enum { buffer_size = sizeof(buffer) };
|
||||
#else
|
||||
char *buffer;
|
||||
int buffer_size;
|
||||
|
||||
/* We want page-aligned buffer, just in case kernel is clever
|
||||
* and can do page-aligned io more efficiently */
|
||||
buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON,
|
||||
/* ignored: */ -1, 0);
|
||||
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
|
||||
if (buffer == MAP_FAILED) {
|
||||
buffer = alloca(4 * 1024);
|
||||
buffer_size = 4 * 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (src_fd < 0)
|
||||
goto out;
|
||||
|
||||
if (!size) {
|
||||
size = BUFSIZ;
|
||||
size = buffer_size;
|
||||
status = 1; /* copy until eof */
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ssize_t rd;
|
||||
|
||||
rd = safe_read(src_fd, buffer, size > BUFSIZ ? BUFSIZ : size);
|
||||
rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size);
|
||||
|
||||
if (!rd) { /* eof - all done */
|
||||
status = 0;
|
||||
@@ -62,6 +75,11 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
|
||||
}
|
||||
}
|
||||
out:
|
||||
|
||||
#if CONFIG_FEATURE_COPYBUF_KB > 4
|
||||
if (buffer_size != 4 * 1024)
|
||||
munmap(buffer, buffer_size);
|
||||
#endif
|
||||
return status ? -1 : total;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -12,15 +12,17 @@
|
||||
/* try to open up the specified device */
|
||||
int device_open(const char *device, int mode)
|
||||
{
|
||||
int m, f, fd = -1;
|
||||
int m, f, fd;
|
||||
|
||||
m = mode | O_NONBLOCK;
|
||||
|
||||
/* Retry up to 5 times */
|
||||
/* TODO: explain why it can't be considered insane */
|
||||
for (f = 0; f < 5; f++)
|
||||
if ((fd = open(device, m, 0600)) >= 0)
|
||||
for (f = 0; f < 5; f++) {
|
||||
fd = open(device, m, 0600);
|
||||
if (fd >= 0)
|
||||
break;
|
||||
}
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
/* Reset original flags. */
|
||||
|
||||
+4
-2
@@ -59,7 +59,8 @@ int bb_dump_size(FS * fs)
|
||||
prec = atoi(fmt);
|
||||
while (isdigit(*++fmt));
|
||||
}
|
||||
if (!(p = strchr(size_conv_str + 12, *fmt))) {
|
||||
p = strchr(size_conv_str + 12, *fmt);
|
||||
if (!p) {
|
||||
if (*fmt == 's') {
|
||||
bcnt += prec;
|
||||
} else if (*fmt == '_') {
|
||||
@@ -162,7 +163,8 @@ static void rewrite(FS * fs)
|
||||
DO_INT_CONV:
|
||||
{
|
||||
const char *e;
|
||||
if (!(e = strchr(lcc, *p1))) {
|
||||
e = strchr(lcc, *p1);
|
||||
if (!e) {
|
||||
goto DO_BAD_CONV_CHAR;
|
||||
}
|
||||
pr->flags = F_INT;
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ int exists_execable(const char *filename)
|
||||
*/
|
||||
int bb_execvp(const char *file, char *const argv[])
|
||||
{
|
||||
return execvp(find_applet_by_name(file) ? bb_busybox_exec_path : file,
|
||||
return execvp(find_applet_by_name(file) >= 0 ? bb_busybox_exec_path : file,
|
||||
argv);
|
||||
}
|
||||
#endif
|
||||
@@ -63,7 +63,7 @@ pid_t* find_pid_by_name(const char* procName)
|
||||
(!p->comm[sizeof(p->comm)-2] && strcmp(p->comm, procName) == 0)
|
||||
/* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/
|
||||
|| (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0)
|
||||
/* TOOD: we can also try exe, do we want that? */
|
||||
/* TOOD: we can also try /proc/NUM/exe link, do we want that? */
|
||||
) {
|
||||
pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
|
||||
pidList[i++] = p->pid;
|
||||
|
||||
+221
-143
@@ -41,7 +41,6 @@
|
||||
#define ENABLE_FEATURE_TAB_COMPLETION 0
|
||||
#define ENABLE_FEATURE_USERNAME_COMPLETION 0
|
||||
#define ENABLE_FEATURE_NONPRINTABLE_INVERSE_PUT 0
|
||||
#define ENABLE_FEATURE_CLEAN_UP 0
|
||||
|
||||
#endif /* TEST */
|
||||
|
||||
@@ -56,36 +55,117 @@
|
||||
#endif
|
||||
|
||||
#define ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR \
|
||||
(ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT)
|
||||
(ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT)
|
||||
#define USE_FEATURE_GETUSERNAME_AND_HOMEDIR(...)
|
||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
#undef USE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
#define USE_FEATURE_GETUSERNAME_AND_HOMEDIR(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
enum { MAX_LINELEN = CONFIG_FEATURE_EDITING_MAX_LEN };
|
||||
enum {
|
||||
/* We use int16_t for positions, need to limit line len */
|
||||
MAX_LINELEN = CONFIG_FEATURE_EDITING_MAX_LEN < 0x7ff0
|
||||
? CONFIG_FEATURE_EDITING_MAX_LEN
|
||||
: 0x7ff0
|
||||
};
|
||||
|
||||
static line_input_t *state;
|
||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
static const char null_str[] ALIGN1 = "";
|
||||
#endif
|
||||
|
||||
static struct termios initial_settings, new_settings;
|
||||
/* We try to minimize both static and stack usage. */
|
||||
struct statics {
|
||||
line_input_t *state;
|
||||
|
||||
static volatile unsigned cmdedit_termw = 80; /* actual terminal width */
|
||||
volatile unsigned cmdedit_termw; /* = 80; */ /* actual terminal width */
|
||||
sighandler_t previous_SIGWINCH_handler;
|
||||
|
||||
static int cmdedit_x; /* real x terminal position */
|
||||
static int cmdedit_y; /* pseudoreal y terminal position */
|
||||
static int cmdedit_prmt_len; /* length of prompt (without colors etc) */
|
||||
|
||||
static unsigned cursor;
|
||||
static unsigned command_len;
|
||||
static char *command_ps;
|
||||
static const char *cmdedit_prompt;
|
||||
int cmdedit_x; /* real x terminal position */
|
||||
int cmdedit_y; /* pseudoreal y terminal position */
|
||||
int cmdedit_prmt_len; /* length of prompt (without colors etc) */
|
||||
|
||||
unsigned cursor;
|
||||
unsigned command_len;
|
||||
char *command_ps;
|
||||
|
||||
const char *cmdedit_prompt;
|
||||
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||
static char *hostname_buf;
|
||||
static int num_ok_lines = 1;
|
||||
int num_ok_lines; /* = 1; */
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
static const char null_str[] = "";
|
||||
static char *user_buf;
|
||||
static char *home_pwd_buf = (char*)null_str;
|
||||
char *user_buf;
|
||||
char *home_pwd_buf; /* = (char*)null_str; */
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
char **matches;
|
||||
unsigned num_matches;
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_EDITING_VI
|
||||
#define DELBUFSIZ 128
|
||||
char *delptr;
|
||||
smallint newdelflag; /* whether delbuf should be reused yet */
|
||||
char delbuf[DELBUFSIZ]; /* a place to store deleted characters */
|
||||
#endif
|
||||
|
||||
/* Formerly these were big buffers on stack: */
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
char exe_n_cwd_tab_completion__dirbuf[MAX_LINELEN];
|
||||
char input_tab__matchBuf[MAX_LINELEN];
|
||||
int16_t find_match__int_buf[MAX_LINELEN + 1]; /* need to have 9 bits at least */
|
||||
int16_t find_match__pos_buf[MAX_LINELEN + 1];
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Make it reside in writable memory, yet make compiler understand
|
||||
* that it is not going to change. */
|
||||
static struct statics *const ptr_to_statics __attribute__ ((section (".data")));
|
||||
|
||||
#define S (*ptr_to_statics)
|
||||
#define state (S.state )
|
||||
#define cmdedit_termw (S.cmdedit_termw )
|
||||
#define previous_SIGWINCH_handler (S.previous_SIGWINCH_handler)
|
||||
#define cmdedit_x (S.cmdedit_x )
|
||||
#define cmdedit_y (S.cmdedit_y )
|
||||
#define cmdedit_prmt_len (S.cmdedit_prmt_len)
|
||||
#define cursor (S.cursor )
|
||||
#define command_len (S.command_len )
|
||||
#define command_ps (S.command_ps )
|
||||
#define cmdedit_prompt (S.cmdedit_prompt )
|
||||
#define num_ok_lines (S.num_ok_lines )
|
||||
#define user_buf (S.user_buf )
|
||||
#define home_pwd_buf (S.home_pwd_buf )
|
||||
#define matches (S.matches )
|
||||
#define num_matches (S.num_matches )
|
||||
#define delptr (S.delptr )
|
||||
#define newdelflag (S.newdelflag )
|
||||
#define delbuf (S.delbuf )
|
||||
|
||||
#define INIT_S() do { \
|
||||
(*(struct statics**)&ptr_to_statics) = xzalloc(sizeof(S)); \
|
||||
cmdedit_termw = 80; \
|
||||
USE_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines = 1;) \
|
||||
USE_FEATURE_GETUSERNAME_AND_HOMEDIR(home_pwd_buf = (char*)null_str;) \
|
||||
} while (0)
|
||||
static void deinit_S(void)
|
||||
{
|
||||
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||
/* This one is allocated only if FANCY_PROMPT is on
|
||||
* (otherwise it points to verbatim prompt (NOT malloced) */
|
||||
free((char*)cmdedit_prompt);
|
||||
#endif
|
||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
free(user_buf);
|
||||
if (home_pwd_buf != null_str)
|
||||
free(home_pwd_buf);
|
||||
#endif
|
||||
free(ptr_to_statics);
|
||||
}
|
||||
#define DEINIT_S() deinit_S()
|
||||
|
||||
/* Put 'command_ps[cursor]', cursor++.
|
||||
* Advance cursor on screen. If we reached right margin, scroll text up
|
||||
* and remove terminal margin effect by printing 'next_char' */
|
||||
@@ -110,8 +190,7 @@ static void cmdedit_set_out_char(int next_char)
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (initial_settings.c_lflag & ECHO)
|
||||
bb_putchar(c);
|
||||
bb_putchar(c);
|
||||
}
|
||||
if (++cmdedit_x >= cmdedit_termw) {
|
||||
/* terminal is scrolled down */
|
||||
@@ -167,7 +246,15 @@ static void input_backward(unsigned num)
|
||||
if (cmdedit_x >= num) {
|
||||
cmdedit_x -= num;
|
||||
if (num <= 4) {
|
||||
printf("\b\b\b\b" + (4-num));
|
||||
/* This is longer by 5 bytes on x86.
|
||||
* Also gets mysteriously
|
||||
* miscompiled for some ARM users.
|
||||
* printf(("\b\b\b\b" + 4) - num);
|
||||
* return;
|
||||
*/
|
||||
do {
|
||||
bb_putchar('\b');
|
||||
} while (--num);
|
||||
return;
|
||||
}
|
||||
printf("\033[%uD", num);
|
||||
@@ -204,13 +291,6 @@ static void redraw(int y, int back_cursor)
|
||||
input_backward(back_cursor);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_EDITING_VI
|
||||
#define DELBUFSIZ 128
|
||||
static char *delbuf; /* a (malloced) place to store deleted characters */
|
||||
static char *delp;
|
||||
static char newdelflag; /* whether delbuf should be reused yet */
|
||||
#endif
|
||||
|
||||
/* Delete the char in front of the cursor, optionally saving it
|
||||
* for later putback */
|
||||
static void input_delete(int save)
|
||||
@@ -223,14 +303,11 @@ static void input_delete(int save)
|
||||
#if ENABLE_FEATURE_EDITING_VI
|
||||
if (save) {
|
||||
if (newdelflag) {
|
||||
if (!delbuf)
|
||||
delbuf = malloc(DELBUFSIZ);
|
||||
/* safe if malloc fails */
|
||||
delp = delbuf;
|
||||
delptr = delbuf;
|
||||
newdelflag = 0;
|
||||
}
|
||||
if (delbuf && (delp - delbuf < DELBUFSIZ))
|
||||
*delp++ = command_ps[j];
|
||||
if ((delptr - delbuf) < DELBUFSIZ)
|
||||
*delptr++ = command_ps[j];
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -245,7 +322,7 @@ static void input_delete(int save)
|
||||
static void put(void)
|
||||
{
|
||||
int ocursor;
|
||||
int j = delp - delbuf;
|
||||
int j = delptr - delbuf;
|
||||
|
||||
if (j == 0)
|
||||
return;
|
||||
@@ -275,12 +352,8 @@ static void input_forward(void)
|
||||
cmdedit_set_out_char(command_ps[cursor + 1]);
|
||||
}
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
|
||||
static char **matches;
|
||||
static unsigned num_matches;
|
||||
|
||||
static void free_tab_completion_data(void)
|
||||
{
|
||||
if (matches) {
|
||||
@@ -313,14 +386,14 @@ static void username_tab_completion(char *ud, char *with_shash_flg)
|
||||
if (with_shash_flg) { /* "~/..." or "~user/..." */
|
||||
char *sav_ud = ud - 1;
|
||||
char *home = NULL;
|
||||
char *temp;
|
||||
|
||||
if (*ud == '/') { /* "~/..." */
|
||||
home = home_pwd_buf;
|
||||
} else {
|
||||
/* "~user/..." */
|
||||
char *temp;
|
||||
temp = strchr(ud, '/');
|
||||
*temp = 0; /* ~user\0 */
|
||||
*temp = '\0'; /* ~user\0 */
|
||||
entry = getpwnam(ud);
|
||||
*temp = '/'; /* restore ~user/... */
|
||||
ud = temp;
|
||||
@@ -329,11 +402,8 @@ static void username_tab_completion(char *ud, char *with_shash_flg)
|
||||
}
|
||||
if (home) {
|
||||
if ((userlen + strlen(home) + 1) < MAX_LINELEN) {
|
||||
char temp2[MAX_LINELEN]; /* argument size */
|
||||
|
||||
/* /home/user/... */
|
||||
sprintf(temp2, "%s%s", home, ud);
|
||||
strcpy(sav_ud, temp2);
|
||||
sprintf(sav_ud, "%s%s", home, ud);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -411,7 +481,6 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *next;
|
||||
char dirbuf[MAX_LINELEN];
|
||||
struct stat st;
|
||||
char *path1[1];
|
||||
char **paths = path1;
|
||||
@@ -419,6 +488,8 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
int i;
|
||||
char *found;
|
||||
char *pfind = strrchr(command, '/');
|
||||
/* char dirbuf[MAX_LINELEN]; */
|
||||
#define dirbuf (S.exe_n_cwd_tab_completion__dirbuf)
|
||||
|
||||
npaths = 1;
|
||||
path1[0] = (char*)".";
|
||||
@@ -492,21 +563,25 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
free(paths[0]); /* allocated memory only in first member */
|
||||
free(paths);
|
||||
}
|
||||
#undef dirbuf
|
||||
}
|
||||
|
||||
#define QUOT (UCHAR_MAX+1)
|
||||
|
||||
#define collapse_pos(is, in) { \
|
||||
memmove(int_buf+(is), int_buf+(in), (MAX_LINELEN+1-(is)-(in))*sizeof(int)); \
|
||||
memmove(pos_buf+(is), pos_buf+(in), (MAX_LINELEN+1-(is)-(in))*sizeof(int)); }
|
||||
#define collapse_pos(is, in) do { \
|
||||
memmove(int_buf+(is), int_buf+(in), (MAX_LINELEN+1-(is)-(in)) * sizeof(pos_buf[0])); \
|
||||
memmove(pos_buf+(is), pos_buf+(in), (MAX_LINELEN+1-(is)-(in)) * sizeof(pos_buf[0])); \
|
||||
} while (0)
|
||||
|
||||
static int find_match(char *matchBuf, int *len_with_quotes)
|
||||
{
|
||||
int i, j;
|
||||
int command_mode;
|
||||
int c, c2;
|
||||
int int_buf[MAX_LINELEN + 1];
|
||||
int pos_buf[MAX_LINELEN + 1];
|
||||
/* int16_t int_buf[MAX_LINELEN + 1]; */
|
||||
/* int16_t pos_buf[MAX_LINELEN + 1]; */
|
||||
#define int_buf (S.find_match__int_buf)
|
||||
#define pos_buf (S.find_match__pos_buf)
|
||||
|
||||
/* set to integer dimension characters and own positions */
|
||||
for (i = 0;; i++) {
|
||||
@@ -622,8 +697,8 @@ static int find_match(char *matchBuf, int *len_with_quotes)
|
||||
for (i = 0; int_buf[i]; i++)
|
||||
if (int_buf[i] == ' ' || int_buf[i] == '<' || int_buf[i] == '>') {
|
||||
if (int_buf[i] == ' ' && command_mode == FIND_EXE_ONLY
|
||||
&& matchBuf[pos_buf[0]]=='c'
|
||||
&& matchBuf[pos_buf[1]]=='d'
|
||||
&& matchBuf[pos_buf[0]] == 'c'
|
||||
&& matchBuf[pos_buf[1]] == 'd'
|
||||
) {
|
||||
command_mode = FIND_DIR_ONLY;
|
||||
} else {
|
||||
@@ -657,11 +732,13 @@ static int find_match(char *matchBuf, int *len_with_quotes)
|
||||
matchBuf[c++] = matchBuf[pos_buf[i]];
|
||||
j = pos_buf[i] + 1;
|
||||
}
|
||||
matchBuf[c] = 0;
|
||||
matchBuf[c] = '\0';
|
||||
/* old length matchBuf with quotes symbols */
|
||||
*len_with_quotes = j ? j - pos_buf[0] : 0;
|
||||
|
||||
return command_mode;
|
||||
#undef int_buf
|
||||
#undef pos_buf
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -724,7 +801,7 @@ static int match_compare(const void *a, const void *b)
|
||||
}
|
||||
|
||||
/* Do TAB completion */
|
||||
static void input_tab(int *lastWasTab)
|
||||
static void input_tab(smallint *lastWasTab)
|
||||
{
|
||||
if (!(state->flags & TAB_COMPLETION))
|
||||
return;
|
||||
@@ -732,7 +809,8 @@ static void input_tab(int *lastWasTab)
|
||||
if (!*lastWasTab) {
|
||||
char *tmp, *tmp1;
|
||||
int len_found;
|
||||
char matchBuf[MAX_LINELEN];
|
||||
/* char matchBuf[MAX_LINELEN]; */
|
||||
#define matchBuf (S.input_tab__matchBuf)
|
||||
int find_type;
|
||||
int recalc_pos;
|
||||
|
||||
@@ -782,7 +860,6 @@ static void input_tab(int *lastWasTab)
|
||||
if (!matches)
|
||||
return; /* not found */
|
||||
/* find minimal match */
|
||||
// ash: yet another failure in trying to achieve "we don't die on OOM"
|
||||
tmp1 = xstrdup(matches[0]);
|
||||
for (tmp = tmp1; *tmp; tmp++)
|
||||
for (len_found = 1; len_found < num_matches; len_found++)
|
||||
@@ -811,7 +888,7 @@ static void input_tab(int *lastWasTab)
|
||||
/* have space to placed match? */
|
||||
if ((len_found - strlen(matchBuf) + command_len) < MAX_LINELEN) {
|
||||
/* before word for match */
|
||||
command_ps[cursor - recalc_pos] = 0;
|
||||
command_ps[cursor - recalc_pos] = '\0';
|
||||
/* save tail line */
|
||||
strcpy(matchBuf, command_ps + cursor);
|
||||
/* add match */
|
||||
@@ -828,6 +905,7 @@ static void input_tab(int *lastWasTab)
|
||||
redraw(cmdedit_y, command_len - recalc_pos);
|
||||
}
|
||||
free(tmp);
|
||||
#undef matchBuf
|
||||
} else {
|
||||
/* Ok -- the last char was a TAB. Since they
|
||||
* just hit TAB again, print a list of all the
|
||||
@@ -843,8 +921,6 @@ static void input_tab(int *lastWasTab)
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#define input_tab(a) ((void)0)
|
||||
#endif /* FEATURE_COMMAND_TAB_COMPLETION */
|
||||
|
||||
|
||||
@@ -1079,34 +1155,36 @@ vi_back_motion(char *command)
|
||||
*/
|
||||
|
||||
#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||
static void parse_prompt(const char *prmt_ptr)
|
||||
static void parse_and_put_prompt(const char *prmt_ptr)
|
||||
{
|
||||
cmdedit_prompt = prmt_ptr;
|
||||
cmdedit_prmt_len = strlen(prmt_ptr);
|
||||
put_prompt();
|
||||
}
|
||||
#else
|
||||
static void parse_prompt(const char *prmt_ptr)
|
||||
static void parse_and_put_prompt(const char *prmt_ptr)
|
||||
{
|
||||
int prmt_len = 0;
|
||||
size_t cur_prmt_len = 0;
|
||||
char flg_not_length = '[';
|
||||
char *prmt_mem_ptr = xzalloc(1);
|
||||
char *pwd_buf = xrealloc_getcwd_or_warn(NULL);
|
||||
char buf2[PATH_MAX + 1];
|
||||
char buf[2];
|
||||
char *cwd_buf = xrealloc_getcwd_or_warn(NULL);
|
||||
char cbuf[2];
|
||||
char c;
|
||||
char *pbuf;
|
||||
|
||||
cmdedit_prmt_len = 0;
|
||||
|
||||
if (!pwd_buf) {
|
||||
pwd_buf = (char *)bb_msg_unknown;
|
||||
if (!cwd_buf) {
|
||||
cwd_buf = (char *)bb_msg_unknown;
|
||||
}
|
||||
|
||||
cbuf[1] = '\0'; /* never changes */
|
||||
|
||||
while (*prmt_ptr) {
|
||||
pbuf = buf;
|
||||
pbuf[1] = 0;
|
||||
char *free_me = NULL;
|
||||
|
||||
pbuf = cbuf;
|
||||
c = *prmt_ptr++;
|
||||
if (c == '\\') {
|
||||
const char *cp = prmt_ptr;
|
||||
@@ -1114,9 +1192,10 @@ static void parse_prompt(const char *prmt_ptr)
|
||||
|
||||
c = bb_process_escape_sequence(&prmt_ptr);
|
||||
if (prmt_ptr == cp) {
|
||||
if (*cp == 0)
|
||||
if (*cp == '\0')
|
||||
break;
|
||||
c = *prmt_ptr++;
|
||||
|
||||
switch (c) {
|
||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
case 'u':
|
||||
@@ -1124,97 +1203,86 @@ static void parse_prompt(const char *prmt_ptr)
|
||||
break;
|
||||
#endif
|
||||
case 'h':
|
||||
pbuf = hostname_buf;
|
||||
if (!pbuf) {
|
||||
pbuf = xzalloc(256);
|
||||
if (gethostname(pbuf, 255) < 0) {
|
||||
strcpy(pbuf, "?");
|
||||
} else {
|
||||
char *s = strchr(pbuf, '.');
|
||||
if (s)
|
||||
*s = '\0';
|
||||
}
|
||||
hostname_buf = pbuf;
|
||||
pbuf = free_me = xzalloc(256);
|
||||
if (gethostname(pbuf, 255) < 0) {
|
||||
pbuf[0] = '?';
|
||||
pbuf[1] = '\0';
|
||||
}
|
||||
*strchrnul(pbuf, '.') = '\0';
|
||||
break;
|
||||
case '$':
|
||||
c = (geteuid() == 0 ? '#' : '$');
|
||||
break;
|
||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||
case 'w':
|
||||
pbuf = pwd_buf;
|
||||
/* /home/user[/something] -> ~[/something] */
|
||||
pbuf = cwd_buf;
|
||||
l = strlen(home_pwd_buf);
|
||||
if (l != 0
|
||||
&& strncmp(home_pwd_buf, pbuf, l) == 0
|
||||
&& (pbuf[l]=='/' || pbuf[l]=='\0')
|
||||
&& strlen(pwd_buf+l)<PATH_MAX
|
||||
&& strncmp(home_pwd_buf, cwd_buf, l) == 0
|
||||
&& (cwd_buf[l]=='/' || cwd_buf[l]=='\0')
|
||||
&& strlen(cwd_buf + l) < PATH_MAX
|
||||
) {
|
||||
pbuf = buf2;
|
||||
*pbuf = '~';
|
||||
strcpy(pbuf+1, pwd_buf+l);
|
||||
pbuf = free_me = xasprintf("~%s", cwd_buf + l);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 'W':
|
||||
pbuf = pwd_buf;
|
||||
pbuf = cwd_buf;
|
||||
cp = strrchr(pbuf, '/');
|
||||
if (cp != NULL && cp != pbuf)
|
||||
pbuf += (cp-pbuf) + 1;
|
||||
break;
|
||||
case '!':
|
||||
pbuf = buf2;
|
||||
snprintf(buf2, sizeof(buf2), "%d", num_ok_lines);
|
||||
pbuf = free_me = xasprintf("%d", num_ok_lines);
|
||||
break;
|
||||
case 'e': case 'E': /* \e \E = \033 */
|
||||
c = '\033';
|
||||
break;
|
||||
case 'x': case 'X':
|
||||
case 'x': case 'X': {
|
||||
char buf2[4];
|
||||
for (l = 0; l < 3;) {
|
||||
int h;
|
||||
unsigned h;
|
||||
buf2[l++] = *prmt_ptr;
|
||||
buf2[l] = 0;
|
||||
h = strtol(buf2, &pbuf, 16);
|
||||
buf2[l] = '\0';
|
||||
h = strtoul(buf2, &pbuf, 16);
|
||||
if (h > UCHAR_MAX || (pbuf - buf2) < l) {
|
||||
l--;
|
||||
buf2[--l] = '\0';
|
||||
break;
|
||||
}
|
||||
prmt_ptr++;
|
||||
}
|
||||
buf2[l] = 0;
|
||||
c = (char)strtol(buf2, NULL, 16);
|
||||
c = (char)strtoul(buf2, NULL, 16);
|
||||
if (c == 0)
|
||||
c = '?';
|
||||
pbuf = buf;
|
||||
pbuf = cbuf;
|
||||
break;
|
||||
}
|
||||
case '[': case ']':
|
||||
if (c == flg_not_length) {
|
||||
flg_not_length = flg_not_length == '[' ? ']' : '[';
|
||||
flg_not_length = (flg_not_length == '[' ? ']' : '[');
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pbuf == buf)
|
||||
*pbuf = c;
|
||||
} /* switch */
|
||||
} /* if */
|
||||
} /* if */
|
||||
cbuf[0] = c;
|
||||
cur_prmt_len = strlen(pbuf);
|
||||
prmt_len += cur_prmt_len;
|
||||
if (flg_not_length != ']')
|
||||
cmdedit_prmt_len += cur_prmt_len;
|
||||
prmt_mem_ptr = strcat(xrealloc(prmt_mem_ptr, prmt_len+1), pbuf);
|
||||
}
|
||||
if (pwd_buf != (char *)bb_msg_unknown)
|
||||
free(pwd_buf);
|
||||
free(free_me);
|
||||
} /* while */
|
||||
|
||||
if (cwd_buf != (char *)bb_msg_unknown)
|
||||
free(cwd_buf);
|
||||
cmdedit_prompt = prmt_mem_ptr;
|
||||
put_prompt();
|
||||
}
|
||||
#endif
|
||||
|
||||
#define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp)
|
||||
#define getTermSettings(fd, argp) tcgetattr(fd, argp);
|
||||
|
||||
static sighandler_t previous_SIGWINCH_handler;
|
||||
|
||||
static void cmdedit_setwidth(unsigned w, int redraw_flg)
|
||||
{
|
||||
cmdedit_termw = w;
|
||||
@@ -1255,13 +1323,15 @@ static void win_changed(int nsig)
|
||||
#define CTRL(a) ((a) & ~0x40)
|
||||
|
||||
/* Returns:
|
||||
* -1 on read errors or EOF, or on bare Ctrl-D.
|
||||
* 0 on ctrl-C,
|
||||
* -1 on read errors or EOF, or on bare Ctrl-D,
|
||||
* 0 on ctrl-C (the line entered is still returned in 'command'),
|
||||
* >0 length of input string, including terminating '\n'
|
||||
*/
|
||||
int read_line_input(const char *prompt, char *command, int maxsize, line_input_t *st)
|
||||
{
|
||||
int lastWasTab = FALSE;
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
smallint lastWasTab = FALSE;
|
||||
#endif
|
||||
unsigned int ic;
|
||||
unsigned char c;
|
||||
smallint break_out = 0;
|
||||
@@ -1269,14 +1339,24 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
smallint vi_cmdmode = 0;
|
||||
smalluint prevc;
|
||||
#endif
|
||||
struct termios initial_settings;
|
||||
struct termios new_settings;
|
||||
|
||||
getTermSettings(0, (void *) &initial_settings);
|
||||
/* Happens when e.g. stty -echo was run before */
|
||||
if (!(initial_settings.c_lflag & ECHO)) {
|
||||
parse_prompt(prompt);
|
||||
INIT_S();
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &initial_settings) < 0
|
||||
|| !(initial_settings.c_lflag & ECHO)
|
||||
) {
|
||||
/* Happens when e.g. stty -echo was run before */
|
||||
int len;
|
||||
parse_and_put_prompt(prompt);
|
||||
fflush(stdout);
|
||||
fgets(command, maxsize, stdin);
|
||||
return strlen(command);
|
||||
if (fgets(command, maxsize, stdin) == NULL)
|
||||
len = -1; /* EOF or error */
|
||||
else
|
||||
len = strlen(command);
|
||||
DEINIT_S();
|
||||
return len;
|
||||
}
|
||||
|
||||
// FIXME: audit & improve this
|
||||
@@ -1296,7 +1376,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
command_ps = command;
|
||||
command[0] = '\0';
|
||||
|
||||
memcpy(&new_settings, &initial_settings, sizeof(new_settings));
|
||||
new_settings = initial_settings;
|
||||
new_settings.c_lflag &= ~ICANON; /* unbuffered input */
|
||||
/* Turn off echoing and CTRL-C, so we can trap it */
|
||||
new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
|
||||
@@ -1308,7 +1388,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
#define _POSIX_VDISABLE '\0'
|
||||
#endif
|
||||
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
|
||||
setTermSettings(0, (void *) &new_settings);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_settings);
|
||||
|
||||
/* Now initialize things */
|
||||
previous_SIGWINCH_handler = signal(SIGWINCH, win_changed);
|
||||
@@ -1319,24 +1399,18 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
|
||||
entry = getpwuid(geteuid());
|
||||
if (entry) {
|
||||
/* If we enter read_line_input for the Nth time,
|
||||
* they may be already allocated! Need to free. */
|
||||
free(user_buf);
|
||||
if (home_pwd_buf != null_str)
|
||||
free(home_pwd_buf);
|
||||
user_buf = xstrdup(entry->pw_name);
|
||||
home_pwd_buf = xstrdup(entry->pw_dir);
|
||||
/* They are not freed on exit (too small to bother) */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Print out the command prompt */
|
||||
parse_prompt(prompt);
|
||||
parse_and_put_prompt(prompt);
|
||||
|
||||
while (1) {
|
||||
fflush(stdout);
|
||||
|
||||
if (safe_read(0, &c, 1) < 1) {
|
||||
if (safe_read(STDIN_FILENO, &c, 1) < 1) {
|
||||
/* if we can't read input then exit */
|
||||
goto prepare_to_die;
|
||||
}
|
||||
@@ -1411,9 +1485,11 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
input_backspace();
|
||||
break;
|
||||
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
case '\t':
|
||||
input_tab(&lastWasTab);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_EDITING_FANCY_KEYS
|
||||
case CTRL('K'):
|
||||
@@ -1526,7 +1602,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
int nc, sc;
|
||||
sc = cursor;
|
||||
prevc = ic;
|
||||
if (safe_read(0, &c, 1) < 1)
|
||||
if (safe_read(STDIN_FILENO, &c, 1) < 1)
|
||||
goto prepare_to_die;
|
||||
if (c == (prevc & 0xff)) {
|
||||
/* "cc", "dd" */
|
||||
@@ -1587,7 +1663,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
put();
|
||||
break;
|
||||
case 'r'|vbit:
|
||||
if (safe_read(0, &c, 1) < 1)
|
||||
if (safe_read(STDIN_FILENO, &c, 1) < 1)
|
||||
goto prepare_to_die;
|
||||
if (c == 0)
|
||||
beep();
|
||||
@@ -1610,19 +1686,19 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
}
|
||||
#endif
|
||||
/* escape sequence follows */
|
||||
if (safe_read(0, &c, 1) < 1)
|
||||
if (safe_read(STDIN_FILENO, &c, 1) < 1)
|
||||
goto prepare_to_die;
|
||||
/* different vt100 emulations */
|
||||
if (c == '[' || c == 'O') {
|
||||
vi_case('['|vbit:)
|
||||
vi_case('O'|vbit:)
|
||||
if (safe_read(0, &c, 1) < 1)
|
||||
if (safe_read(STDIN_FILENO, &c, 1) < 1)
|
||||
goto prepare_to_die;
|
||||
}
|
||||
if (c >= '1' && c <= '9') {
|
||||
unsigned char dummy;
|
||||
|
||||
if (safe_read(0, &dummy, 1) < 1)
|
||||
if (safe_read(STDIN_FILENO, &dummy, 1) < 1)
|
||||
goto prepare_to_die;
|
||||
if (dummy != '~')
|
||||
c = '\0';
|
||||
@@ -1687,7 +1763,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
#if ENABLE_FEATURE_NONPRINTABLE_INVERSE_PUT
|
||||
/* Control-V -- Add non-printable symbol */
|
||||
if (c == CTRL('V')) {
|
||||
if (safe_read(0, &c, 1) < 1)
|
||||
if (safe_read(STDIN_FILENO, &c, 1) < 1)
|
||||
goto prepare_to_die;
|
||||
if (c == 0) {
|
||||
beep();
|
||||
@@ -1727,8 +1803,10 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
if (break_out) /* Enter is the command terminator, no more input. */
|
||||
break;
|
||||
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
if (c != '\t')
|
||||
lastWasTab = FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (command_len > 0)
|
||||
@@ -1739,18 +1817,18 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
|
||||
command[command_len] = '\0';
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_TAB_COMPLETION
|
||||
#if ENABLE_FEATURE_TAB_COMPLETION
|
||||
free_tab_completion_data();
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||
free((char*)cmdedit_prompt);
|
||||
#endif
|
||||
/* restore initial_settings */
|
||||
setTermSettings(STDIN_FILENO, (void *) &initial_settings);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &initial_settings);
|
||||
/* restore SIGWINCH handler */
|
||||
signal(SIGWINCH, previous_SIGWINCH_handler);
|
||||
fflush(stdout);
|
||||
|
||||
DEINIT_S();
|
||||
|
||||
return command_len;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,3 +99,29 @@ void print_login_prompt(void)
|
||||
fputs(LOGIN, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Clear dangerous stuff, set PATH */
|
||||
static const char forbid[] ALIGN1 =
|
||||
"ENV" "\0"
|
||||
"BASH_ENV" "\0"
|
||||
"HOME" "\0"
|
||||
"IFS" "\0"
|
||||
"SHELL" "\0"
|
||||
"LD_LIBRARY_PATH" "\0"
|
||||
"LD_PRELOAD" "\0"
|
||||
"LD_TRACE_LOADED_OBJECTS" "\0"
|
||||
"LD_BIND_NOW" "\0"
|
||||
"LD_AOUT_LIBRARY_PATH" "\0"
|
||||
"LD_AOUT_PRELOAD" "\0"
|
||||
"LD_NOWARN" "\0"
|
||||
"LD_KEEPDIR" "\0";
|
||||
|
||||
void sanitize_env_for_suid(void)
|
||||
{
|
||||
const char *p = forbid;
|
||||
do {
|
||||
unsetenv(p);
|
||||
p += strlen(p) + 1;
|
||||
} while (*p);
|
||||
putenv((char*)bb_PATH_root_path);
|
||||
}
|
||||
+2
-1
@@ -130,7 +130,8 @@ static const char *obscure_msg(const char *old_p, const char *new_p, const struc
|
||||
c = 0;
|
||||
p = new_p;
|
||||
while (1) {
|
||||
if ((p = strchr(p, new_p[i])) == NULL) {
|
||||
p = strchr(p, new_p[i]);
|
||||
if (p == NULL) {
|
||||
break;
|
||||
}
|
||||
c++;
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static const char signals[32][7] = {
|
||||
/* Believe it or not, but some arches have more than 32 SIGs!
|
||||
* HPPA: SIGSTKFLT == 36. */
|
||||
|
||||
static const char signals[][7] = {
|
||||
// SUSv3 says kill must support these, and specifies the numerical values,
|
||||
// http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html
|
||||
// TODO: "[SIG]EXIT" shouldn't work for kill, right?
|
||||
// {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"},
|
||||
// {6, "ABRT"}, {9, "KILL"}, {14, "ALRM"}, {15, "TERM"}
|
||||
// And Posix adds the following:
|
||||
@@ -20,6 +22,7 @@ static const char signals[32][7] = {
|
||||
// {SIGSEGV, "SEGV"}, {SIGUSR2, "USR2"}, {SIGPIPE, "PIPE"}, {SIGCHLD, "CHLD"},
|
||||
// {SIGCONT, "CONT"}, {SIGSTOP, "STOP"}, {SIGTSTP, "TSTP"}, {SIGTTIN, "TTIN"},
|
||||
// {SIGTTOU, "TTOU"}
|
||||
|
||||
[0] = "EXIT",
|
||||
#ifdef SIGHUP
|
||||
[SIGHUP ] = "HUP",
|
||||
@@ -132,7 +135,9 @@ int get_signum(const char *name)
|
||||
return i;
|
||||
|
||||
#if ENABLE_DESKTOP && (defined(SIGIOT) || defined(SIGIO))
|
||||
/* These are aliased to other names */
|
||||
/* SIGIO[T] are aliased to other names,
|
||||
* thus cannot be stored in the signals[] array.
|
||||
* Need special code to recognize them */
|
||||
if ((name[0] | 0x20) == 'i' && (name[1] | 0x20) == 'o') {
|
||||
#ifdef SIGIO
|
||||
if (!name[2])
|
||||
|
||||
@@ -52,6 +52,10 @@ int update_passwd(const char *filename, const char *username,
|
||||
int cnt = 0;
|
||||
int ret = -1; /* failure */
|
||||
|
||||
filename = xmalloc_follow_symlinks(filename);
|
||||
if (filename == NULL)
|
||||
return -1;
|
||||
|
||||
check_selinux_update_passwd(username);
|
||||
|
||||
/* New passwd file, "/etc/passwd+" for now */
|
||||
@@ -143,6 +147,7 @@ int update_passwd(const char *filename, const char *username,
|
||||
|
||||
free_mem:
|
||||
free(fnamesfx);
|
||||
free((char*)username);
|
||||
free((char *)filename);
|
||||
free((char *)username);
|
||||
return ret;
|
||||
}
|
||||
+4
-2
@@ -45,8 +45,10 @@ void bb_verror_msg(const char *s, va_list p, const char* strerr)
|
||||
msg[applet_len - 2] = ':';
|
||||
msg[applet_len - 1] = ' ';
|
||||
if (strerr) {
|
||||
msg[used++] = ':';
|
||||
msg[used++] = ' ';
|
||||
if (s[0]) { /* not perror_nomsg? */
|
||||
msg[used++] = ':';
|
||||
msg[used++] = ' ';
|
||||
}
|
||||
strcpy(&msg[used], strerr);
|
||||
used += strerr_len;
|
||||
}
|
||||
|
||||
+11
-11
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <paths.h>
|
||||
#include "busybox.h" /* for struct bb_applet */
|
||||
#include "busybox.h" /* uses applet tables */
|
||||
|
||||
/* This does a fork/exec in one call, using vfork(). Returns PID of new child,
|
||||
* -1 for failure. Runs argv[0], searching path if that has no / in it. */
|
||||
@@ -120,11 +120,11 @@ void restore_nofork_data(struct nofork_save_area *save)
|
||||
die_sleep = save->die_sleep;
|
||||
}
|
||||
|
||||
int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv)
|
||||
int run_nofork_applet_prime(struct nofork_save_area *old, int applet_no, char **argv)
|
||||
{
|
||||
int rc, argc;
|
||||
|
||||
applet_name = a->name;
|
||||
applet_name = APPLET_NAME(applet_no);
|
||||
xfunc_error_retval = EXIT_FAILURE;
|
||||
/*option_mask32 = 0; - not needed */
|
||||
/* special flag for xfunc_die(). If xfunc will "die"
|
||||
@@ -143,7 +143,7 @@ int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet
|
||||
char *tmp_argv[argc+1];
|
||||
memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0]));
|
||||
/* Finally we can call NOFORK applet's main() */
|
||||
rc = a->main(argc, tmp_argv);
|
||||
rc = applet_main[applet_no](argc, tmp_argv);
|
||||
} else { /* xfunc died in NOFORK applet */
|
||||
/* in case they meant to return 0... */
|
||||
if (rc == -2222)
|
||||
@@ -155,13 +155,13 @@ int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet
|
||||
return rc;
|
||||
}
|
||||
|
||||
int run_nofork_applet(const struct bb_applet *a, char **argv)
|
||||
int run_nofork_applet(int applet_no, char **argv)
|
||||
{
|
||||
struct nofork_save_area old;
|
||||
|
||||
/* Saving globals */
|
||||
save_nofork_data(&old);
|
||||
return run_nofork_applet_prime(&old, a, argv);
|
||||
return run_nofork_applet_prime(&old, applet_no, argv);
|
||||
}
|
||||
#endif /* FEATURE_PREFER_APPLETS */
|
||||
|
||||
@@ -169,15 +169,15 @@ int spawn_and_wait(char **argv)
|
||||
{
|
||||
int rc;
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
const struct bb_applet *a = find_applet_by_name(argv[0]);
|
||||
int a = find_applet_by_name(argv[0]);
|
||||
|
||||
if (a && (a->nofork
|
||||
if (a >= 0 && (APPLET_IS_NOFORK(a)
|
||||
#if BB_MMU
|
||||
|| a->noexec /* NOEXEC trick needs fork() */
|
||||
|| APPLET_IS_NOEXEC(a) /* NOEXEC trick needs fork() */
|
||||
#endif
|
||||
)) {
|
||||
#if BB_MMU
|
||||
if (a->nofork)
|
||||
if (APPLET_IS_NOFORK(a))
|
||||
#endif
|
||||
{
|
||||
return run_nofork_applet(a, argv);
|
||||
@@ -190,7 +190,7 @@ int spawn_and_wait(char **argv)
|
||||
return wait4pid(rc);
|
||||
/* child */
|
||||
xfunc_error_retval = EXIT_FAILURE;
|
||||
run_appletstruct_and_exit(a, argv);
|
||||
run_applet_no_and_exit(a, argv);
|
||||
#endif
|
||||
}
|
||||
#endif /* FEATURE_PREFER_APPLETS */
|
||||
|
||||
@@ -21,9 +21,8 @@ unsigned type xstrtou(_range_sfx)(const char *numstr, int base,
|
||||
int old_errno;
|
||||
char *e;
|
||||
|
||||
/* Disallow '-' and any leading whitespace. Speed isn't critical here
|
||||
* since we're parsing commandline args. So make sure we get the
|
||||
* actual isspace function rather than a lnumstrer macro implementaion. */
|
||||
/* Disallow '-' and any leading whitespace. Make sure we get the
|
||||
* actual isspace function rather than a macro implementaion. */
|
||||
if (*numstr == '-' || *numstr == '+' || (isspace)(*numstr))
|
||||
goto inval;
|
||||
|
||||
@@ -127,9 +126,12 @@ type xstrto(_range_sfx)(const char *numstr, int base,
|
||||
type r;
|
||||
const char *p = numstr;
|
||||
|
||||
if (p[0] == '-') {
|
||||
/* NB: if you'll decide to disallow '+':
|
||||
* at least renice applet needs to allow it */
|
||||
if (p[0] == '+' || p[0] == '-') {
|
||||
++p;
|
||||
++u; /* two's complement */
|
||||
if (p[0] == '-')
|
||||
++u; /* = <type>_MIN (01111... + 1 == 10000...) */
|
||||
}
|
||||
|
||||
r = xstrtou(_range_sfx)(p, base, 0, u, suffixes);
|
||||
|
||||
+16
-3
@@ -125,6 +125,7 @@ USE_FEATURE_IPV6(sa_family_t af,)
|
||||
int rc;
|
||||
len_and_sockaddr *r = NULL;
|
||||
struct addrinfo *result = NULL;
|
||||
struct addrinfo *used_res;
|
||||
const char *org_host = host; /* only for error msg */
|
||||
const char *cp;
|
||||
struct addrinfo hint;
|
||||
@@ -169,9 +170,21 @@ USE_FEATURE_IPV6(sa_family_t af,)
|
||||
xfunc_die();
|
||||
goto ret;
|
||||
}
|
||||
r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen);
|
||||
r->len = result->ai_addrlen;
|
||||
memcpy(&r->sa, result->ai_addr, result->ai_addrlen);
|
||||
used_res = result;
|
||||
#if ENABLE_FEATURE_PREFER_IPV4_ADDRESS
|
||||
while (1) {
|
||||
if (used_res->ai_family == AF_INET)
|
||||
break;
|
||||
used_res = used_res->ai_next;
|
||||
if (!used_res) {
|
||||
used_res = result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
r = xmalloc(offsetof(len_and_sockaddr, sa) + used_res->ai_addrlen);
|
||||
r->len = used_res->ai_addrlen;
|
||||
memcpy(&r->sa, used_res->ai_addr, used_res->ai_addrlen);
|
||||
set_nport(r, htons(port));
|
||||
ret:
|
||||
freeaddrinfo(result);
|
||||
|
||||
+54
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
/*
|
||||
* NOTE: This function returns a malloced char* that you will have to free
|
||||
* yourself. You have been warned.
|
||||
* yourself.
|
||||
*/
|
||||
char *xmalloc_readlink(const char *path)
|
||||
{
|
||||
@@ -32,6 +32,59 @@ char *xmalloc_readlink(const char *path)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine is not the same as realpath(), which
|
||||
* canonicalizes the given path completely. This routine only
|
||||
* follows trailing symlinks until a real file is reached and
|
||||
* returns its name. If the path ends in a dangling link or if
|
||||
* the target doesn't exist, the path is returned in any case.
|
||||
* Intermediate symlinks in the path are not expanded -- only
|
||||
* those at the tail.
|
||||
* A malloced char* is returned, which must be freed by the caller.
|
||||
*/
|
||||
char *xmalloc_follow_symlinks(const char *path)
|
||||
{
|
||||
char *buf;
|
||||
char *lpc;
|
||||
char *linkpath;
|
||||
int bufsize;
|
||||
int looping = MAXSYMLINKS + 1;
|
||||
|
||||
buf = xstrdup(path);
|
||||
goto jump_in;
|
||||
|
||||
while (1) {
|
||||
|
||||
linkpath = xmalloc_readlink(buf);
|
||||
if (!linkpath) {
|
||||
/* not a symlink, or doesn't exist */
|
||||
if (errno == EINVAL || errno == ENOENT)
|
||||
return buf;
|
||||
goto free_buf_ret_null;
|
||||
}
|
||||
|
||||
if (!--looping) {
|
||||
free(linkpath);
|
||||
free_buf_ret_null:
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*linkpath != '/') {
|
||||
bufsize += strlen(linkpath);
|
||||
buf = xrealloc(buf, bufsize);
|
||||
lpc = bb_get_last_path_component_strip(buf);
|
||||
strcpy(lpc, linkpath);
|
||||
free(linkpath);
|
||||
} else {
|
||||
free(buf);
|
||||
buf = linkpath;
|
||||
jump_in:
|
||||
bufsize = strlen(buf) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *xmalloc_readlink_or_warn(const char *path)
|
||||
{
|
||||
char *buf = xmalloc_readlink(path);
|
||||
|
||||
+191
-252
@@ -28,13 +28,16 @@
|
||||
* System V, assume it is SunOS 4.
|
||||
*/
|
||||
#ifdef LOGIN_PROCESS /* defined in System V utmp.h */
|
||||
#define SYSV_STYLE /* select System V style getty */
|
||||
#include <sys/utsname.h>
|
||||
#include <time.h>
|
||||
#if ENABLE_FEATURE_WTMP
|
||||
extern void updwtmp(const char *filename, const struct utmp *ut);
|
||||
static void update_utmp(const char *line);
|
||||
#endif
|
||||
#else /* if !sysV style, wtmp/utmp code is off */
|
||||
#undef ENABLE_FEATURE_UTMP
|
||||
#undef ENABLE_FEATURE_WTMP
|
||||
#define ENABLE_FEATURE_UTMP 0
|
||||
#define ENABLE_FEATURE_WTMP 0
|
||||
#endif /* LOGIN_PROCESS */
|
||||
|
||||
/*
|
||||
@@ -47,6 +50,7 @@ static void update_utmp(const char *line);
|
||||
|
||||
/* I doubt there are systems which still need this */
|
||||
#undef HANDLE_ALLCAPS
|
||||
#undef ANCIENT_BS_KILL_CHARS
|
||||
|
||||
#define _PATH_LOGIN "/bin/login"
|
||||
|
||||
@@ -76,36 +80,20 @@ static void update_utmp(const char *line);
|
||||
* When multiple baud rates are specified on the command line, the first one
|
||||
* we will try is the first one specified.
|
||||
*/
|
||||
#define FIRST_SPEED 0
|
||||
|
||||
/* Storage for command-line options. */
|
||||
|
||||
#define MAX_SPEED 10 /* max. nr. of baud rates */
|
||||
|
||||
/* Storage for command-line options. */
|
||||
struct options {
|
||||
int flags; /* toggle switches, see below */
|
||||
unsigned timeout; /* time-out period */
|
||||
const char *login; /* login program */
|
||||
const char *tty; /* name of tty */
|
||||
const char *initstring; /* modem init string */
|
||||
const char *issue; /* alternative issue file */
|
||||
const char *login; /* login program */
|
||||
const char *tty; /* name of tty */
|
||||
const char *initstring; /* modem init string */
|
||||
const char *issue; /* alternative issue file */
|
||||
int numspeed; /* number of baud rates to try */
|
||||
int speeds[MAX_SPEED]; /* baud rates to be tried */
|
||||
};
|
||||
|
||||
static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn";
|
||||
#define F_INITSTRING (1<<0) /* initstring is set */
|
||||
#define F_LOCAL (1<<1) /* force local */
|
||||
#define F_FAKEHOST (1<<2) /* force fakehost */
|
||||
#define F_CUSTISSUE (1<<3) /* give alternative issue file */
|
||||
#define F_RTSCTS (1<<4) /* enable RTS/CTS flow control */
|
||||
#define F_ISSUE (1<<5) /* display /etc/issue */
|
||||
#define F_LOGIN (1<<6) /* non-default login program */
|
||||
#define F_PARSE (1<<7) /* process modem status messages */
|
||||
#define F_TIMEOUT (1<<8) /* time out */
|
||||
#define F_WAITCRLF (1<<9) /* wait for CR or LF */
|
||||
#define F_NOPROMPT (1<<10) /* don't ask for login name! */
|
||||
|
||||
/* Storage for things detected while the login name was read. */
|
||||
struct chardata {
|
||||
unsigned char erase; /* erase character */
|
||||
@@ -117,6 +105,7 @@ struct chardata {
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* Initial values for the above. */
|
||||
static const struct chardata init_chardata = {
|
||||
DEF_ERASE, /* default erase character */
|
||||
@@ -128,12 +117,23 @@ static const struct chardata init_chardata = {
|
||||
#endif
|
||||
};
|
||||
|
||||
static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn";
|
||||
#define F_INITSTRING (1 << 0) /* -I initstring is set */
|
||||
#define F_LOCAL (1 << 1) /* -L force local */
|
||||
#define F_FAKEHOST (1 << 2) /* -H fake hostname */
|
||||
#define F_CUSTISSUE (1 << 3) /* -f give alternative issue file */
|
||||
#define F_RTSCTS (1 << 4) /* -h enable RTS/CTS flow control */
|
||||
#define F_ISSUE (1 << 5) /* -i display /etc/issue */
|
||||
#define F_LOGIN (1 << 6) /* -l non-default login program */
|
||||
#define F_PARSE (1 << 7) /* -m process modem status messages */
|
||||
#define F_TIMEOUT (1 << 8) /* -t time out */
|
||||
#define F_WAITCRLF (1 << 9) /* -w wait for CR or LF */
|
||||
#define F_NOPROMPT (1 << 10) /* -n don't ask for login name */
|
||||
|
||||
|
||||
#define line_buf bb_common_bufsiz1
|
||||
|
||||
/* The following is used for understandable diagnostics. */
|
||||
|
||||
/* Fake hostname for ut_host specified on command line. */
|
||||
static char *fakehost = NULL;
|
||||
|
||||
/* ... */
|
||||
#ifdef DEBUGGING
|
||||
#define debug(s) fprintf(dbf,s); fflush(dbf)
|
||||
#define DEBUGTERM "/dev/ttyp0"
|
||||
@@ -158,36 +158,39 @@ static int bcode(const char *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* parse_speeds - parse alternate baud rates */
|
||||
static void parse_speeds(struct options *op, char *arg)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
/* NB: at least one iteration is always done */
|
||||
debug("entered parse_speeds\n");
|
||||
for (cp = strtok(arg, ","); cp != 0; cp = strtok((char *) 0, ",")) {
|
||||
if ((op->speeds[op->numspeed++] = bcode(cp)) <= 0)
|
||||
while ((cp = strsep(&arg, ",")) != NULL) {
|
||||
op->speeds[op->numspeed] = bcode(cp);
|
||||
if (op->speeds[op->numspeed] <= 0)
|
||||
bb_error_msg_and_die("bad speed: %s", cp);
|
||||
op->numspeed++;
|
||||
if (op->numspeed > MAX_SPEED)
|
||||
bb_error_msg_and_die("too many alternate speeds");
|
||||
}
|
||||
debug("exiting parsespeeds\n");
|
||||
debug("exiting parse_speeds\n");
|
||||
}
|
||||
|
||||
|
||||
/* parse_args - parse command-line arguments */
|
||||
static void parse_args(int argc, char **argv, struct options *op)
|
||||
static void parse_args(char **argv, struct options *op, char **fakehost_p)
|
||||
{
|
||||
char *ts;
|
||||
|
||||
opt_complementary = "-2"; /* at least 2 args */
|
||||
op->flags = getopt32(argv, opt_string,
|
||||
&(op->initstring), &fakehost, &(op->issue),
|
||||
&(op->initstring), fakehost_p, &(op->issue),
|
||||
&(op->login), &ts);
|
||||
argv += optind;
|
||||
if (op->flags & F_INITSTRING) {
|
||||
const char *p = op->initstring;
|
||||
char *q;
|
||||
|
||||
op->initstring = q = xstrdup(op->initstring);
|
||||
op->initstring = q = xstrdup(p);
|
||||
/* copy optarg into op->initstring decoding \ddd
|
||||
octal codes into chars */
|
||||
while (*p) {
|
||||
@@ -200,45 +203,40 @@ static void parse_args(int argc, char **argv, struct options *op)
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
op->flags ^= F_ISSUE; /* revert flag show /etc/issue */
|
||||
op->flags ^= F_ISSUE; /* invert flag show /etc/issue */
|
||||
if (op->flags & F_TIMEOUT) {
|
||||
op->timeout = xatoul_range(ts, 1, INT_MAX);
|
||||
op->timeout = xatoi_u(ts);
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
debug("after getopt loop\n");
|
||||
if (argc < 2) /* check parameter count */
|
||||
bb_show_usage();
|
||||
debug("after getopt\n");
|
||||
|
||||
/* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
|
||||
op->tty = argv[0]; /* tty name */
|
||||
ts = argv[1]; /* baud rate(s) */
|
||||
if (isdigit(argv[0][0])) {
|
||||
/* a number first, assume it's a speed (BSD style) */
|
||||
parse_speeds(op, argv[0]); /* baud rate(s) */
|
||||
op->tty = argv[1]; /* tty name */
|
||||
} else {
|
||||
op->tty = argv[0]; /* tty name */
|
||||
parse_speeds(op, argv[1]); /* baud rate(s) */
|
||||
op->tty = ts; /* tty name is in argv[1] */
|
||||
ts = argv[0]; /* baud rate(s) */
|
||||
}
|
||||
parse_speeds(op, ts);
|
||||
|
||||
if (argv[2])
|
||||
setenv("TERM", argv[2], 1);
|
||||
|
||||
debug("exiting parseargs\n");
|
||||
debug("exiting parse_args\n");
|
||||
}
|
||||
|
||||
/* open_tty - set up tty as standard { input, output, error } */
|
||||
static void open_tty(const char *tty, struct termios *tp, int local)
|
||||
static void open_tty(const char *tty)
|
||||
{
|
||||
int chdir_to_root = 0;
|
||||
|
||||
/* Set up new standard input, unless we are given an already opened port. */
|
||||
if (NOT_LONE_DASH(tty)) {
|
||||
struct stat st;
|
||||
int cur_dir_fd;
|
||||
int fd;
|
||||
|
||||
/* Sanity checks... */
|
||||
cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK);
|
||||
xchdir("/dev");
|
||||
chdir_to_root = 1;
|
||||
xstat(tty, &st);
|
||||
if ((st.st_mode & S_IFMT) != S_IFCHR)
|
||||
bb_error_msg_and_die("%s: not a character device", tty);
|
||||
@@ -246,9 +244,23 @@ static void open_tty(const char *tty, struct termios *tp, int local)
|
||||
/* Open the tty as standard input. */
|
||||
debug("open(2)\n");
|
||||
fd = xopen(tty, O_RDWR | O_NONBLOCK);
|
||||
|
||||
/* Restore current directory */
|
||||
fchdir(cur_dir_fd);
|
||||
|
||||
/* Open the tty as standard input, continued */
|
||||
xdup2(fd, 0);
|
||||
/* fd is >= cur_dir_fd, and cur_dir_fd gets closed too here: */
|
||||
while (fd > 2)
|
||||
close(fd--);
|
||||
|
||||
/* Set proper protections and ownership. Mode 0622
|
||||
* is suitable for SYSV < 4 because /bin/login does not change
|
||||
* protections. SunOS 4 login will change the protections to 0620
|
||||
* (write access for group tty) after the login has succeeded.
|
||||
*/
|
||||
fchown(0, 0, 0); /* 0:0 */
|
||||
fchmod(0, 0622); /* crw--w--w- */
|
||||
} else {
|
||||
/*
|
||||
* Standard input should already be connected to an open port. Make
|
||||
@@ -257,71 +269,6 @@ static void open_tty(const char *tty, struct termios *tp, int local)
|
||||
if ((fcntl(0, F_GETFL) & O_RDWR) != O_RDWR)
|
||||
bb_error_msg_and_die("stdin is not open for read/write");
|
||||
}
|
||||
|
||||
/* Replace current standard output/error fd's with new ones */
|
||||
debug("duping\n");
|
||||
xdup2(0, 1);
|
||||
xdup2(0, 2);
|
||||
|
||||
/*
|
||||
* The following ioctl will fail if stdin is not a tty, but also when
|
||||
* there is noise on the modem control lines. In the latter case, the
|
||||
* common course of action is (1) fix your cables (2) give the modem more
|
||||
* time to properly reset after hanging up. SunOS users can achieve (2)
|
||||
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
||||
* 5 seconds seems to be a good value.
|
||||
*/
|
||||
ioctl_or_perror_and_die(0, TCGETS, tp, "%s: TCGETS", tty);
|
||||
|
||||
/*
|
||||
* It seems to be a terminal. Set proper protections and ownership. Mode
|
||||
* 0622 is suitable for SYSV <4 because /bin/login does not change
|
||||
* protections. SunOS 4 login will change the protections to 0620 (write
|
||||
* access for group tty) after the login has succeeded.
|
||||
*/
|
||||
|
||||
#ifdef DEBIAN
|
||||
#warning Debian /dev/vcs[a]NN hack is deprecated and will be removed
|
||||
{
|
||||
/* tty to root.dialout 660 */
|
||||
struct group *gr;
|
||||
int id;
|
||||
|
||||
gr = getgrnam("dialout");
|
||||
id = gr ? gr->gr_gid : 0;
|
||||
chown(tty, 0, id);
|
||||
chmod(tty, 0660);
|
||||
|
||||
/* vcs,vcsa to root.sys 600 */
|
||||
if (!strncmp(tty, "tty", 3) && isdigit(tty[3])) {
|
||||
char *vcs, *vcsa;
|
||||
|
||||
vcs = xstrdup(tty);
|
||||
vcsa = xmalloc(strlen(tty) + 2);
|
||||
strcpy(vcs, "vcs");
|
||||
strcpy(vcs + 3, tty + 3);
|
||||
strcpy(vcsa, "vcsa");
|
||||
strcpy(vcsa + 4, tty + 3);
|
||||
|
||||
gr = getgrnam("sys");
|
||||
id = gr ? gr->gr_gid : 0;
|
||||
chown(vcs, 0, id);
|
||||
chmod(vcs, 0600);
|
||||
chown(vcsa, 0, id);
|
||||
chmod(vcs, 0600);
|
||||
|
||||
free(vcs);
|
||||
free(vcsa);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (NOT_LONE_DASH(tty)) {
|
||||
chown(tty, 0, 0); /* 0:0 */
|
||||
chmod(tty, 0622); /* crw--w--w- */
|
||||
}
|
||||
#endif
|
||||
if (chdir_to_root)
|
||||
xchdir("/");
|
||||
}
|
||||
|
||||
/* termios_init - initialize termios settings */
|
||||
@@ -349,17 +296,13 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
|
||||
tp->c_cc[VTIME] = 0;
|
||||
|
||||
/* Optionally enable hardware flow control */
|
||||
|
||||
#ifdef CRTSCTS
|
||||
#ifdef CRTSCTS
|
||||
if (op->flags & F_RTSCTS)
|
||||
tp->c_cflag |= CRTSCTS;
|
||||
#endif
|
||||
|
||||
ioctl(0, TCSETS, tp);
|
||||
|
||||
/* go to blocking input even in local mode */
|
||||
ndelay_off(0);
|
||||
|
||||
debug("term_io 2\n");
|
||||
}
|
||||
|
||||
@@ -391,26 +334,24 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
|
||||
* Use 7-bit characters, don't block if input queue is empty. Errors will
|
||||
* be dealt with later on.
|
||||
*/
|
||||
|
||||
iflag = tp->c_iflag;
|
||||
tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */
|
||||
vmin = tp->c_cc[VMIN];
|
||||
tp->c_cc[VMIN] = 0; /* don't block if queue empty */
|
||||
tp->c_cc[VMIN] = 0; /* don't block if queue empty */
|
||||
ioctl(0, TCSETS, tp);
|
||||
|
||||
/*
|
||||
* Wait for a while, then read everything the modem has said so far and
|
||||
* try to extract the speed of the dial-in call.
|
||||
*/
|
||||
|
||||
sleep(1);
|
||||
nread = read(0, buf, size_buf - 1);
|
||||
nread = safe_read(0, buf, size_buf - 1);
|
||||
if (nread > 0) {
|
||||
buf[nread] = '\0';
|
||||
for (bp = buf; bp < buf + nread; bp++) {
|
||||
if (isascii(*bp) && isdigit(*bp)) {
|
||||
if (isdigit(*bp)) {
|
||||
speed = bcode(bp);
|
||||
if (speed) {
|
||||
if (speed > 0) {
|
||||
tp->c_cflag &= ~CBAUD;
|
||||
tp->c_cflag |= speed;
|
||||
}
|
||||
@@ -418,25 +359,13 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Restore terminal settings. Errors will be dealt with later on. */
|
||||
|
||||
/* Restore terminal settings. Errors will be dealt with later on. */
|
||||
tp->c_iflag = iflag;
|
||||
tp->c_cc[VMIN] = vmin;
|
||||
ioctl(0, TCSETS, tp);
|
||||
}
|
||||
|
||||
/* next_speed - select next baud rate */
|
||||
static void next_speed(struct termios *tp, struct options *op)
|
||||
{
|
||||
static int baud_index = FIRST_SPEED; /* current speed index */
|
||||
|
||||
baud_index = (baud_index + 1) % op->numspeed;
|
||||
tp->c_cflag &= ~CBAUD;
|
||||
tp->c_cflag |= op->speeds[baud_index];
|
||||
ioctl(0, TCSETS, tp);
|
||||
}
|
||||
|
||||
|
||||
/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
|
||||
static void do_prompt(struct options *op, struct termios *tp)
|
||||
{
|
||||
@@ -447,9 +376,9 @@ static void do_prompt(struct options *op, struct termios *tp)
|
||||
}
|
||||
|
||||
#ifdef HANDLE_ALLCAPS
|
||||
/* caps_lock - string contains upper case without lower case */
|
||||
/* all_is_upcase - string contains upper case without lower case */
|
||||
/* returns 1 if true, 0 if false */
|
||||
static int caps_lock(const char *s)
|
||||
static int all_is_upcase(const char *s)
|
||||
{
|
||||
while (*s)
|
||||
if (islower(*s++))
|
||||
@@ -458,8 +387,8 @@ static int caps_lock(const char *s)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* get_logname - get user name, establish parity, speed, erase, kill, eol */
|
||||
/* return NULL on failure, logname on success */
|
||||
/* get_logname - get user name, establish parity, speed, erase, kill, eol;
|
||||
* return NULL on BREAK, logname on success */
|
||||
static char *get_logname(char *logname, unsigned size_logname,
|
||||
struct options *op, struct chardata *cp, struct termios *tp)
|
||||
{
|
||||
@@ -475,26 +404,19 @@ static char *get_logname(char *logname, unsigned size_logname,
|
||||
"\210\240\210", /* no parity */
|
||||
};
|
||||
|
||||
/* Initialize kill, erase, parity etc. (also after switching speeds). */
|
||||
|
||||
*cp = init_chardata;
|
||||
/* NB: *cp is pre-initialized with init_chardata */
|
||||
|
||||
/* Flush pending input (esp. after parsing or switching the baud rate). */
|
||||
|
||||
sleep(1);
|
||||
ioctl(0, TCFLSH, TCIFLUSH);
|
||||
|
||||
/* Prompt for and read a login name. */
|
||||
|
||||
logname[0] = '\0';
|
||||
while (!logname[0]) {
|
||||
|
||||
/* Write issue file and prompt, with "parity" bit == 0. */
|
||||
|
||||
do_prompt(op, tp);
|
||||
|
||||
/* Read name, watch for break, parity, erase, kill, end-of-line. */
|
||||
|
||||
bp = logname;
|
||||
cp->eol = '\0';
|
||||
while (cp->eol == '\0') {
|
||||
@@ -506,7 +428,8 @@ static char *get_logname(char *logname, unsigned size_logname,
|
||||
bb_perror_msg_and_die("%s: read", op->tty);
|
||||
}
|
||||
|
||||
/* Do BREAK handling elsewhere. */
|
||||
/* BREAK. If we have speeds to try,
|
||||
* return NULL (will switch speeds and return here) */
|
||||
if (c == '\0' && op->numspeed > 1)
|
||||
return NULL;
|
||||
|
||||
@@ -533,18 +456,22 @@ static char *get_logname(char *logname, unsigned size_logname,
|
||||
break;
|
||||
case BS:
|
||||
case DEL:
|
||||
#ifdef ANCIENT_BS_KILL_CHARS
|
||||
case '#':
|
||||
#endif
|
||||
cp->erase = ascval; /* set erase character */
|
||||
if (bp > logname) {
|
||||
write(1, erase[cp->parity], 3);
|
||||
full_write(1, erase[cp->parity], 3);
|
||||
bp--;
|
||||
}
|
||||
break;
|
||||
case CTL('U'):
|
||||
#ifdef ANCIENT_BS_KILL_CHARS
|
||||
case '@':
|
||||
#endif
|
||||
cp->kill = ascval; /* set kill character */
|
||||
while (bp > logname) {
|
||||
write(1, erase[cp->parity], 3);
|
||||
full_write(1, erase[cp->parity], 3);
|
||||
bp--;
|
||||
}
|
||||
break;
|
||||
@@ -556,7 +483,7 @@ static char *get_logname(char *logname, unsigned size_logname,
|
||||
} else if (bp - logname >= size_logname - 1) {
|
||||
bb_error_msg_and_die("%s: input overrun", op->tty);
|
||||
} else {
|
||||
write(1, &c, 1); /* echo the character */
|
||||
full_write(1, &c, 1); /* echo the character */
|
||||
*bp++ = ascval; /* and store it */
|
||||
}
|
||||
break;
|
||||
@@ -566,7 +493,7 @@ static char *get_logname(char *logname, unsigned size_logname,
|
||||
/* Handle names with upper case and no lower case. */
|
||||
|
||||
#ifdef HANDLE_ALLCAPS
|
||||
cp->capslock = caps_lock(logname);
|
||||
cp->capslock = all_is_upcase(logname);
|
||||
if (cp->capslock) {
|
||||
for (bp = logname; *bp; bp++)
|
||||
if (isupper(*bp))
|
||||
@@ -639,17 +566,24 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
|
||||
ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty);
|
||||
}
|
||||
|
||||
|
||||
#ifdef SYSV_STYLE
|
||||
#if ENABLE_FEATURE_UTMP
|
||||
static void touch(const char *filename)
|
||||
{
|
||||
if (access(filename, R_OK | W_OK) == -1)
|
||||
close(open(filename, O_WRONLY | O_CREAT, 0664));
|
||||
}
|
||||
|
||||
/* update_utmp - update our utmp entry */
|
||||
static void update_utmp(const char *line)
|
||||
static void update_utmp(const char *line, char *fakehost)
|
||||
{
|
||||
struct utmp ut;
|
||||
struct utmp *utp;
|
||||
time_t t;
|
||||
int mypid = getpid();
|
||||
|
||||
/* In case we won't find an entry below... */
|
||||
memset(&ut, 0, sizeof(ut));
|
||||
safe_strncpy(ut.ut_id, line + 3, sizeof(ut.ut_id));
|
||||
|
||||
/*
|
||||
* The utmp file holds miscellaneous information about things started by
|
||||
* /sbin/init and other system-related events. Our purpose is to update
|
||||
@@ -658,30 +592,22 @@ static void update_utmp(const char *line)
|
||||
* utmp file can be opened for update, and if we are able to find our
|
||||
* entry in the utmp file.
|
||||
*/
|
||||
if (access(_PATH_UTMP, R_OK|W_OK) == -1) {
|
||||
close(creat(_PATH_UTMP, 0664));
|
||||
}
|
||||
touch(_PATH_UTMP);
|
||||
|
||||
utmpname(_PATH_UTMP);
|
||||
setutent();
|
||||
while ((utp = getutent())
|
||||
&& !(utp->ut_type == INIT_PROCESS && utp->ut_pid == mypid))
|
||||
/* nothing */;
|
||||
|
||||
if (utp) {
|
||||
memcpy(&ut, utp, sizeof(ut));
|
||||
} else {
|
||||
/* some inits don't initialize utmp... */
|
||||
memset(&ut, 0, sizeof(ut));
|
||||
safe_strncpy(ut.ut_id, line + 3, sizeof(ut.ut_id));
|
||||
while ((utp = getutent()) != NULL) {
|
||||
if (utp->ut_type == INIT_PROCESS && utp->ut_pid == mypid) {
|
||||
memcpy(&ut, utp, sizeof(ut));
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* endutent(); */
|
||||
|
||||
strcpy(ut.ut_user, "LOGIN");
|
||||
safe_strncpy(ut.ut_line, line, sizeof(ut.ut_line));
|
||||
if (fakehost)
|
||||
safe_strncpy(ut.ut_host, fakehost, sizeof(ut.ut_host));
|
||||
time(&t);
|
||||
ut.ut_time = t;
|
||||
ut.ut_time = time(NULL);
|
||||
ut.ut_type = LOGIN_PROCESS;
|
||||
ut.ut_pid = mypid;
|
||||
|
||||
@@ -689,51 +615,50 @@ static void update_utmp(const char *line)
|
||||
endutent();
|
||||
|
||||
#if ENABLE_FEATURE_WTMP
|
||||
if (access(bb_path_wtmp_file, R_OK|W_OK) == -1)
|
||||
close(creat(bb_path_wtmp_file, 0664));
|
||||
touch(bb_path_wtmp_file);
|
||||
updwtmp(bb_path_wtmp_file, &ut);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FEATURE_UTMP */
|
||||
#endif /* SYSV_STYLE */
|
||||
|
||||
|
||||
int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int getty_main(int argc, char **argv)
|
||||
{
|
||||
int nullfd;
|
||||
char *logname = NULL; /* login name, given to /bin/login */
|
||||
int n;
|
||||
char *fakehost = NULL; /* Fake hostname for ut_host */
|
||||
char *logname; /* login name, given to /bin/login */
|
||||
/* Merging these into "struct local" may _seem_ to reduce
|
||||
* parameter passing, but today's gcc will inline
|
||||
* statics which are called once anyway, so don't do that */
|
||||
struct chardata chardata; /* set by get_logname() */
|
||||
struct termios termios; /* terminal mode bits */
|
||||
struct options options = {
|
||||
0, /* show /etc/issue (SYSV_STYLE) */
|
||||
0, /* no timeout */
|
||||
_PATH_LOGIN, /* default login program */
|
||||
"tty1", /* default tty line */
|
||||
"", /* modem init string */
|
||||
struct termios termios; /* terminal mode bits */
|
||||
struct options options;
|
||||
|
||||
memset(&options, 0, sizeof(options));
|
||||
options.login = _PATH_LOGIN; /* default login program */
|
||||
options.tty = "tty1"; /* default tty line */
|
||||
options.initstring = ""; /* modem init string */
|
||||
#ifdef ISSUE
|
||||
ISSUE, /* default issue file */
|
||||
#else
|
||||
NULL,
|
||||
options.issue = ISSUE; /* default issue file */
|
||||
#endif
|
||||
0, /* no baud rates known yet */
|
||||
};
|
||||
|
||||
/* Already too late because of theoretical
|
||||
* possibility of getty --help somehow triggered
|
||||
* inadvertently before we reach this. Oh well. */
|
||||
logmode = LOGMODE_NONE;
|
||||
|
||||
/* Create new session, lose controlling tty, if any */
|
||||
/* docs/ctty.htm says:
|
||||
* "This is allowed only when the current process
|
||||
* is not a process group leader" - is this a problem? */
|
||||
setsid();
|
||||
nullfd = xopen(bb_dev_null, O_RDWR);
|
||||
/* dup2(nullfd, 0); - no, because of possible "getty - 9600" */
|
||||
/* open_tty() will take care of fd# 0 anyway */
|
||||
dup2(nullfd, 1);
|
||||
dup2(nullfd, 2);
|
||||
while (nullfd > 2) close(nullfd--);
|
||||
|
||||
n = xopen(bb_dev_null, O_RDWR);
|
||||
/* dup2(n, 0); - no, because of possible "getty - 9600" */
|
||||
dup2(n, 1);
|
||||
dup2(n, 2);
|
||||
while (n > 2)
|
||||
close(n--);
|
||||
/* We want special flavor of error_msg_and_die */
|
||||
die_sleep = 10;
|
||||
msg_eol = "\r\n";
|
||||
@@ -742,69 +667,72 @@ int getty_main(int argc, char **argv)
|
||||
|
||||
#ifdef DEBUGGING
|
||||
dbf = xfopen(DEBUGTERM, "w");
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
debug(argv[i]);
|
||||
debug("\n");
|
||||
}
|
||||
for (n = 1; n < argc; n++) {
|
||||
debug(argv[n]);
|
||||
debug("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Parse command-line arguments. */
|
||||
parse_args(argc, argv, &options);
|
||||
|
||||
#ifdef SYSV_STYLE
|
||||
#if ENABLE_FEATURE_UTMP
|
||||
/* Update the utmp file. */
|
||||
update_utmp(options.tty);
|
||||
#endif
|
||||
#endif
|
||||
parse_args(argv, &options, &fakehost);
|
||||
|
||||
debug("calling open_tty\n");
|
||||
/* Open the tty as standard { input, output, error }. */
|
||||
open_tty(options.tty, &termios, options.flags & F_LOCAL);
|
||||
/* Open the tty as standard input, if it is not "-" */
|
||||
open_tty(options.tty);
|
||||
|
||||
debug("duping\n");
|
||||
ndelay_off(0);
|
||||
xdup2(0, 1);
|
||||
xdup2(0, 2);
|
||||
|
||||
/*
|
||||
* The following ioctl will fail if stdin is not a tty, but also when
|
||||
* there is noise on the modem control lines. In the latter case, the
|
||||
* common course of action is (1) fix your cables (2) give the modem more
|
||||
* time to properly reset after hanging up. SunOS users can achieve (2)
|
||||
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
||||
* 5 seconds seems to be a good value.
|
||||
*/
|
||||
ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty);
|
||||
|
||||
#if ENABLE_FEATURE_UTMP
|
||||
/* Update the utmp file */
|
||||
update_utmp(options.tty, fakehost);
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
{
|
||||
int iv;
|
||||
|
||||
iv = getpid();
|
||||
ioctl(0, TIOCSPGRP, &iv);
|
||||
}
|
||||
/* Make ourself a foreground process group within our session */
|
||||
tcsetpgrp(0, getpid());
|
||||
// /* Forcibly make fd 0 our controlling tty, even if another session
|
||||
// * has it as a ctty. (Another session loses ctty). */
|
||||
// ioctl(0, TIOCSCTTY, (void*)1);
|
||||
#endif
|
||||
|
||||
/* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
|
||||
debug("calling termios_init\n");
|
||||
termios_init(&termios, options.speeds[FIRST_SPEED], &options);
|
||||
termios_init(&termios, options.speeds[0], &options);
|
||||
|
||||
/* write the modem init string and DON'T flush the buffers */
|
||||
/* Write the modem init string and DON'T flush the buffers */
|
||||
if (options.flags & F_INITSTRING) {
|
||||
debug("writing init string\n");
|
||||
write(1, options.initstring, strlen(options.initstring));
|
||||
full_write(1, options.initstring, strlen(options.initstring));
|
||||
}
|
||||
|
||||
if (!(options.flags & F_LOCAL)) {
|
||||
/* go to blocking write mode unless -L is specified */
|
||||
ndelay_off(1);
|
||||
}
|
||||
|
||||
/* Optionally detect the baud rate from the modem status message. */
|
||||
/* Optionally detect the baud rate from the modem status message */
|
||||
debug("before autobaud\n");
|
||||
if (options.flags & F_PARSE)
|
||||
auto_baud(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), &termios);
|
||||
auto_baud(line_buf, sizeof(line_buf), &termios);
|
||||
|
||||
/* Set the optional timer. */
|
||||
/* Set the optional timer */
|
||||
if (options.timeout)
|
||||
alarm(options.timeout);
|
||||
|
||||
/* optionally wait for CR or LF before writing /etc/issue */
|
||||
/* Optionally wait for CR or LF before writing /etc/issue */
|
||||
if (options.flags & F_WAITCRLF) {
|
||||
char ch;
|
||||
|
||||
debug("waiting for cr-lf\n");
|
||||
while (read(0, &ch, 1) == 1) {
|
||||
while (safe_read(0, &ch, 1) == 1) {
|
||||
ch &= 0x7f; /* strip "parity bit" */
|
||||
#ifdef DEBUGGING
|
||||
fprintf(dbf, "read %c\n", ch);
|
||||
@@ -814,31 +742,42 @@ int getty_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
logname = NULL;
|
||||
chardata = init_chardata;
|
||||
if (!(options.flags & F_NOPROMPT)) {
|
||||
/* Read the login name. */
|
||||
debug("reading login name\n");
|
||||
logname = get_logname(bb_common_bufsiz1, sizeof(bb_common_bufsiz1),
|
||||
/* NB:termios_init already set line speed
|
||||
* to options.speeds[0] */
|
||||
int baud_index = 0;
|
||||
|
||||
while (1) {
|
||||
/* Read the login name. */
|
||||
debug("reading login name\n");
|
||||
logname = get_logname(line_buf, sizeof(line_buf),
|
||||
&options, &chardata, &termios);
|
||||
while (logname == NULL)
|
||||
next_speed(&termios, &options);
|
||||
if (logname)
|
||||
break;
|
||||
/* we are here only if options.numspeed > 1 */
|
||||
baud_index = (baud_index + 1) % options.numspeed;
|
||||
termios.c_cflag &= ~CBAUD;
|
||||
termios.c_cflag |= options.speeds[baud_index];
|
||||
ioctl(0, TCSETS, &termios);
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable timer. */
|
||||
|
||||
if (options.timeout)
|
||||
alarm(0);
|
||||
|
||||
/* Finalize the termios settings. */
|
||||
|
||||
termios_final(&options, &termios, &chardata);
|
||||
|
||||
/* Now the newline character should be properly written. */
|
||||
|
||||
write(1, "\n", 1);
|
||||
full_write(1, "\n", 1);
|
||||
|
||||
/* Let the login program take care of password validation. */
|
||||
|
||||
execl(options.login, options.login, "--", logname, (char *) 0);
|
||||
/* We use PATH because we trust that root doesn't set "bad" PATH,
|
||||
* and getty is not suid-root applet. */
|
||||
/* Hmm... with -n, logname == NULL! Is it ok? */
|
||||
BB_EXECLP(options.login, options.login, "--", logname, NULL);
|
||||
bb_error_msg_and_die("%s: can't exec %s", options.tty, options.login);
|
||||
}
|
||||
+57
-25
@@ -201,7 +201,7 @@ static void motd(void)
|
||||
int fd;
|
||||
|
||||
fd = open(bb_path_motd_file, O_RDONLY);
|
||||
if (fd) {
|
||||
if (fd >= 0) {
|
||||
fflush(stdout);
|
||||
bb_copyfd_eof(fd, STDOUT_FILENO);
|
||||
close(fd);
|
||||
@@ -216,6 +216,10 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED)
|
||||
ndelay_on(1);
|
||||
ndelay_on(2);
|
||||
printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT);
|
||||
/* unix API is brain damaged regarding O_NONBLOCK,
|
||||
* we should undo it, or else we can affect other processes */
|
||||
ndelay_off(1);
|
||||
ndelay_off(2);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -239,9 +243,14 @@ int login_main(int argc, char **argv)
|
||||
char full_tty[TTYNAME_SIZE];
|
||||
USE_SELINUX(security_context_t user_sid = NULL;)
|
||||
USE_FEATURE_UTMP(struct utmp utent;)
|
||||
USE_PAM(pam_handle_t *pamh;)
|
||||
USE_PAM(int pamret;)
|
||||
USE_PAM(const char *failed_msg;)
|
||||
#if ENABLE_PAM
|
||||
int pamret;
|
||||
pam_handle_t *pamh;
|
||||
const char *pamuser;
|
||||
const char *failed_msg;
|
||||
struct passwd pwdstruct;
|
||||
char pwdbuf[256];
|
||||
#endif
|
||||
|
||||
short_tty = full_tty;
|
||||
username[0] = '\0';
|
||||
@@ -254,6 +263,11 @@ int login_main(int argc, char **argv)
|
||||
* and any extra open fd's are closed.
|
||||
* (The name of the function is misleading. Not daemonizing here.) */
|
||||
bb_daemonize_or_rexec(DAEMON_ONLY_SANITIZE | DAEMON_CLOSE_EXTRA_FDS, NULL);
|
||||
/* More of suid paranoia if called by non-root */
|
||||
if (!amroot) {
|
||||
/* Clear dangerous stuff, set PATH */
|
||||
sanitize_env_for_suid();
|
||||
}
|
||||
|
||||
opt = getopt32(argv, "f:h:p", &opt_user, &opt_host);
|
||||
if (opt & LOGIN_OPT_f) {
|
||||
@@ -291,24 +305,27 @@ int login_main(int argc, char **argv)
|
||||
openlog(applet_name, LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH);
|
||||
|
||||
while (1) {
|
||||
/* flush away any type-ahead (as getty does) */
|
||||
ioctl(0, TCFLSH, TCIFLUSH);
|
||||
|
||||
if (!username[0])
|
||||
get_username_or_die(username, sizeof(username));
|
||||
|
||||
#if ENABLE_PAM
|
||||
pamret = pam_start("login", username, &conv, &pamh);
|
||||
if (pamret != PAM_SUCCESS) {
|
||||
failed_msg = "pam_start";
|
||||
failed_msg = "start";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
/* set TTY (so things like securetty work) */
|
||||
pamret = pam_set_item(pamh, PAM_TTY, short_tty);
|
||||
if (pamret != PAM_SUCCESS) {
|
||||
failed_msg = "pam_set_item(TTY)";
|
||||
failed_msg = "set_item(TTY)";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
pamret = pam_authenticate(pamh, 0);
|
||||
if (pamret != PAM_SUCCESS) {
|
||||
failed_msg = "pam_authenticate";
|
||||
failed_msg = "authenticate";
|
||||
goto pam_auth_failed;
|
||||
/* TODO: or just "goto auth_failed"
|
||||
* since user seems to enter wrong password
|
||||
@@ -318,28 +335,42 @@ int login_main(int argc, char **argv)
|
||||
/* check that the account is healthy */
|
||||
pamret = pam_acct_mgmt(pamh, 0);
|
||||
if (pamret != PAM_SUCCESS) {
|
||||
failed_msg = "account setup";
|
||||
failed_msg = "acct_mgmt";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
/* read user back */
|
||||
{
|
||||
const char *pamuser;
|
||||
/* gcc: "dereferencing type-punned pointer breaks aliasing rules..."
|
||||
* thus we cast to (void*) */
|
||||
if (pam_get_item(pamh, PAM_USER, (void*)&pamuser) != PAM_SUCCESS) {
|
||||
failed_msg = "pam_get_item(USER)";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
safe_strncpy(username, pamuser, sizeof(username));
|
||||
pamuser = NULL;
|
||||
/* gcc: "dereferencing type-punned pointer breaks aliasing rules..."
|
||||
* thus we cast to (void*) */
|
||||
if (pam_get_item(pamh, PAM_USER, (void*)&pamuser) != PAM_SUCCESS) {
|
||||
failed_msg = "get_item(USER)";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
/* If we get here, the user was authenticated, and is
|
||||
* granted access. */
|
||||
pw = getpwnam(username);
|
||||
if (pw)
|
||||
break;
|
||||
goto auth_failed;
|
||||
if (!pamuser || !pamuser[0])
|
||||
goto auth_failed;
|
||||
safe_strncpy(username, pamuser, sizeof(username));
|
||||
/* Don't use "pw = getpwnam(username);",
|
||||
* PAM is said to be capable of destroying static storage
|
||||
* used by getpwnam(). We are using safe(r) function */
|
||||
pw = NULL;
|
||||
getpwnam_r(username, &pwdstruct, pwdbuf, sizeof(pwdbuf), &pw);
|
||||
if (!pw)
|
||||
goto auth_failed;
|
||||
pamret = pam_open_session(pamh, 0);
|
||||
if (pamret != PAM_SUCCESS) {
|
||||
failed_msg = "open_session";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
pamret = pam_setcred(pamh, PAM_ESTABLISH_CRED);
|
||||
if (pamret != PAM_SUCCESS) {
|
||||
failed_msg = "setcred";
|
||||
goto pam_auth_failed;
|
||||
}
|
||||
break; /* success, continue login process */
|
||||
|
||||
pam_auth_failed:
|
||||
bb_error_msg("%s failed: %s (%d)", failed_msg, pam_strerror(pamh, pamret), pamret);
|
||||
bb_error_msg("pam_%s call failed: %s (%d)", failed_msg,
|
||||
pam_strerror(pamh, pamret), pamret);
|
||||
safe_strncpy(username, "UNKNOWN", sizeof(username));
|
||||
#else /* not PAM */
|
||||
pw = getpwnam(username);
|
||||
@@ -411,7 +442,8 @@ int login_main(int argc, char **argv)
|
||||
fchown(0, pw->pw_uid, pw->pw_gid);
|
||||
fchmod(0, 0600);
|
||||
|
||||
if (ENABLE_LOGIN_SCRIPTS) {
|
||||
/* We trust environment only if we run by root */
|
||||
if (ENABLE_LOGIN_SCRIPTS && amroot) {
|
||||
char *t_argv[2];
|
||||
|
||||
t_argv[0] = getenv("LOGIN_PRE_SUID_SCRIPT");
|
||||
|
||||
+2
-23
@@ -9,22 +9,6 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static const char forbid[] ALIGN1 =
|
||||
"ENV" "\0"
|
||||
"BASH_ENV" "\0"
|
||||
"HOME" "\0"
|
||||
"IFS" "\0"
|
||||
"PATH" "\0"
|
||||
"SHELL" "\0"
|
||||
"LD_LIBRARY_PATH" "\0"
|
||||
"LD_PRELOAD" "\0"
|
||||
"LD_TRACE_LOADED_OBJECTS" "\0"
|
||||
"LD_BIND_NOW" "\0"
|
||||
"LD_AOUT_LIBRARY_PATH" "\0"
|
||||
"LD_AOUT_PRELOAD" "\0"
|
||||
"LD_NOWARN" "\0"
|
||||
"LD_KEEPDIR" "\0";
|
||||
|
||||
//static void catchalarm(int ATTRIBUTE_UNUSED junk)
|
||||
//{
|
||||
// exit(EXIT_FAILURE);
|
||||
@@ -37,7 +21,6 @@ int sulogin_main(int argc, char **argv)
|
||||
char *cp;
|
||||
int timeout = 0;
|
||||
char *timeout_arg;
|
||||
const char *p;
|
||||
struct passwd *pwd;
|
||||
const char *shell;
|
||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
||||
@@ -66,12 +49,8 @@ int sulogin_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("not a tty");
|
||||
}
|
||||
|
||||
/* Clear out anything dangerous from the environment */
|
||||
p = forbid;
|
||||
do {
|
||||
unsetenv(p);
|
||||
p += strlen(p) + 1;
|
||||
} while (*p);
|
||||
/* Clear dangerous stuff, set PATH */
|
||||
sanitize_env_for_suid();
|
||||
|
||||
// bb_askpass() already handles this
|
||||
// signal(SIGALRM, catchalarm);
|
||||
|
||||
+24
-13
@@ -465,7 +465,8 @@ static void read_config_file(char *path, int optional, unsigned long *event_mask
|
||||
free(p);
|
||||
return;
|
||||
}
|
||||
if ((fp = fopen(path, "r")) != NULL) {
|
||||
fp = fopen(path, "r");
|
||||
if (fp != NULL) {
|
||||
while (fgets(buf, STRING_LENGTH, fp) != NULL) {
|
||||
/* Skip whitespace */
|
||||
line = buf;
|
||||
@@ -560,7 +561,8 @@ static void process_config_line(const char *line, unsigned long *event_mask)
|
||||
case 4: /* "PERMISSIONS" */
|
||||
new->action.what = AC_PERMISSIONS;
|
||||
/* Get user and group */
|
||||
if ((ptr = strchr(p[0], '.')) == NULL) {
|
||||
ptr = strchr(p[0], '.');
|
||||
if (ptr == NULL) {
|
||||
msg = "UID.GID";
|
||||
goto process_config_line_err; /*"missing '.' in UID.GID"*/
|
||||
}
|
||||
@@ -979,8 +981,9 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
|
||||
if ((source_stat->st_mode & S_IFMT) ==(dest_stat->st_mode & S_IFMT)) {
|
||||
/* Same type */
|
||||
if (S_ISLNK(source_stat->st_mode)) {
|
||||
if ((source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1)) < 0
|
||||
|| (dest_len = readlink(destpath , dest_link , STRING_LENGTH - 1)) < 0
|
||||
source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1);
|
||||
if ((source_len < 0)
|
||||
|| (dest_len = readlink(destpath, dest_link, STRING_LENGTH - 1)) < 0
|
||||
)
|
||||
return FALSE;
|
||||
source_link[source_len] = '\0';
|
||||
@@ -999,7 +1002,8 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
|
||||
unlink(destpath);
|
||||
switch (source_stat->st_mode & S_IFMT) {
|
||||
case S_IFSOCK:
|
||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
break;
|
||||
un_addr.sun_family = AF_UNIX;
|
||||
snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", destpath);
|
||||
@@ -1009,14 +1013,16 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
|
||||
break;
|
||||
goto do_chown;
|
||||
case S_IFLNK:
|
||||
if ((val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1)) < 0)
|
||||
val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1);
|
||||
if (val < 0)
|
||||
break;
|
||||
symlink_val[val] = '\0';
|
||||
if (symlink(symlink_val, destpath) == 0)
|
||||
return TRUE;
|
||||
break;
|
||||
case S_IFREG:
|
||||
if ((fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT)) < 0)
|
||||
fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT);
|
||||
if (fd < 0)
|
||||
break;
|
||||
close(fd);
|
||||
if (chmod(destpath, new_mode & ~S_IFMT) != 0)
|
||||
@@ -1082,7 +1088,7 @@ static int get_uid_gid(int flag, const char *string)
|
||||
if (isdigit(string[0]) ||((string[0] == '-') && isdigit(string[1])))
|
||||
return atoi(string);
|
||||
|
||||
if (flag == UID && (pw_ent = getpwnam(string)) != NULL)
|
||||
if (flag == UID && (pw_ent = getpwnam(string)) != NULL)
|
||||
return pw_ent->pw_uid;
|
||||
|
||||
if (flag == GID && (grp_ent = getgrnam(string)) != NULL)
|
||||
@@ -1197,7 +1203,8 @@ static void dir_operation(int type, const char * dir_name, int var, unsigned lon
|
||||
struct dirent *de;
|
||||
char *path;
|
||||
|
||||
if ((dp = warn_opendir(dir_name)) == NULL)
|
||||
dp = warn_opendir(dir_name);
|
||||
if (dp == NULL)
|
||||
return;
|
||||
|
||||
while ((de = readdir(dp)) != NULL) {
|
||||
@@ -1581,7 +1588,8 @@ int st_expr_expand(char *output, unsigned int length, const char *input,
|
||||
ch = input[1];
|
||||
if (isspace(ch) ||(ch == '/') ||(ch == '\0')) {
|
||||
/* User's own home directory: leave separator for next time */
|
||||
if ((env = getenv("HOME")) == NULL) {
|
||||
env = getenv("HOME");
|
||||
if (env == NULL) {
|
||||
info_logger(LOG_INFO, bb_msg_variable_not_found, "HOME");
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1600,7 +1608,8 @@ int st_expr_expand(char *output, unsigned int length, const char *input,
|
||||
goto st_expr_expand_out;
|
||||
safe_memcpy(tmp, input, len);
|
||||
input = ptr - 1;
|
||||
if ((pwent = getpwnam(tmp)) == NULL) {
|
||||
pwent = getpwnam(tmp);
|
||||
if (pwent == NULL) {
|
||||
info_logger(LOG_INFO, "no pwent for: %s", tmp);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1680,7 +1689,8 @@ static const char *expand_variable(char *buffer, unsigned int length,
|
||||
|
||||
safe_memcpy(tmp, input, len);
|
||||
input = ptr - 1;
|
||||
if ((env = get_variable_v2(tmp, func, info)) == NULL) {
|
||||
env = get_variable_v2(tmp, func, info);
|
||||
if (env == NULL) {
|
||||
info_logger(LOG_INFO, bb_msg_variable_not_found, tmp);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1740,7 +1750,8 @@ static const char *expand_variable(char *buffer, unsigned int length,
|
||||
}
|
||||
--ptr;
|
||||
/* At this point ptr should point to closing brace of "${var:-word}" */
|
||||
if ((env = get_variable_v2(tmp, func, info)) != NULL) {
|
||||
env = get_variable_v2(tmp, func, info);
|
||||
if (env != NULL) {
|
||||
/* Found environment variable, so skip the input to the closing brace
|
||||
and return the variable */
|
||||
input = ptr;
|
||||
|
||||
+8
-7
@@ -1111,7 +1111,8 @@ static void identify(uint16_t *val)
|
||||
/* reset result */
|
||||
jj = val[HWRST_RSLT];
|
||||
if ((jj & VALID) == VALID_VAL) {
|
||||
if (!(oo = (jj & RST0)))
|
||||
oo = (jj & RST0);
|
||||
if (!oo)
|
||||
jj >>= 8;
|
||||
if ((jj & DEV_DET) == JUMPER_VAL)
|
||||
strng = " determined by the jumper";
|
||||
@@ -1763,7 +1764,7 @@ static void process_dev(char *devname)
|
||||
}
|
||||
}
|
||||
if (get_unmask) {
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, (unsigned long *)parm))
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm))
|
||||
print_value_on_off("unmaskirq", parm);
|
||||
}
|
||||
|
||||
@@ -1780,24 +1781,24 @@ static void process_dev(char *devname)
|
||||
}
|
||||
#endif
|
||||
if (get_dma_q) {
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_QDMA, (unsigned long *)parm))
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm))
|
||||
print_value_on_off("queue_depth", parm);
|
||||
}
|
||||
if (get_keep) {
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, (unsigned long *)parm))
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm))
|
||||
print_value_on_off("keepsettings", parm);
|
||||
}
|
||||
|
||||
if (get_nowerr) {
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_NOWERR, (unsigned long *)parm))
|
||||
if(!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm))
|
||||
print_value_on_off("nowerr", parm);
|
||||
}
|
||||
if (get_readonly) {
|
||||
if(!ioctl_or_warn(fd, BLKROGET, (unsigned long *)parm))
|
||||
if(!ioctl_or_warn(fd, BLKROGET, &parm))
|
||||
print_value_on_off("readonly", parm);
|
||||
}
|
||||
if (get_readahead) {
|
||||
if(!ioctl_or_warn(fd, BLKRAGET, (unsigned long *)parm))
|
||||
if(!ioctl_or_warn(fd, BLKRAGET, &parm))
|
||||
print_value_on_off("readahead", parm);
|
||||
}
|
||||
if (get_geom) {
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int readahead_main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
if (argc == 1) bb_show_usage();
|
||||
|
||||
while (*++argv) {
|
||||
if ((f = fopen_or_warn(*argv, "r")) != NULL) {
|
||||
int r, fd=fileno(f);
|
||||
|
||||
r = readahead(fd, 0, fdlength(fd));
|
||||
fclose(f);
|
||||
int fd = open_or_warn(*argv, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
int r = readahead(fd, 0, fdlength(fd));
|
||||
close(fd);
|
||||
if (r >= 0) continue;
|
||||
}
|
||||
retval = EXIT_FAILURE;
|
||||
|
||||
+4
-3
@@ -1951,7 +1951,8 @@ static unsigned long obj_elf_hash_n(const char *name, unsigned long n)
|
||||
while (n > 0) {
|
||||
ch = *name++;
|
||||
h = (h << 4) + ch;
|
||||
if ((g = (h & 0xf0000000)) != 0) {
|
||||
g = (h & 0xf0000000);
|
||||
if (g != 0) {
|
||||
h ^= g >> 24;
|
||||
h &= ~g;
|
||||
}
|
||||
@@ -4241,8 +4242,8 @@ static int insmod_ng_main(int argc, char **argv)
|
||||
|
||||
ret = syscall(__NR_init_module, map, len, options);
|
||||
if (ret != 0) {
|
||||
bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
|
||||
filename, moderror(errno), ret);
|
||||
bb_error_msg_and_die("cannot insert '%s': %s",
|
||||
filename, moderror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -791,7 +791,7 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t
|
||||
if (*tail)
|
||||
(*tail)->m_next = find;
|
||||
find->m_prev = *tail;
|
||||
/*find->m_next = NULL; - xzalloc did it */
|
||||
find->m_next = NULL; /* possibly NOT done by xzalloc! */
|
||||
|
||||
if (!*head)
|
||||
*head = find;
|
||||
@@ -865,7 +865,7 @@ int modprobe_main(int argc, char **argv)
|
||||
int rc = EXIT_SUCCESS;
|
||||
char *unused;
|
||||
|
||||
opt_complementary = "?V-:q-v:v-q";
|
||||
opt_complementary = "q-v:v-q";
|
||||
getopt32(argv, MAIN_OPT_STR, &unused, &unused);
|
||||
|
||||
if (option_mask32 & (DUMP_CONF_EXIT | LIST_ALL))
|
||||
|
||||
@@ -12,6 +12,21 @@ config FEATURE_IPV6
|
||||
Enable IPv6 support in busybox.
|
||||
This adds IPv6 support in the networking applets.
|
||||
|
||||
config FEATURE_PREFER_IPV4_ADDRESS
|
||||
bool "Preferentially use IPv4 addresses from DNS queries"
|
||||
default y
|
||||
depends on FEATURE_IPV6
|
||||
help
|
||||
Use IPv4 address of network host if it has one.
|
||||
|
||||
If this option is off, the first returned address will be used.
|
||||
This may cause problems when your DNS server is IPv6-capable and
|
||||
is returning IPv6 host addresses too. If IPv6 address
|
||||
precedes IPv4 one in DNS reply, busybox network applets
|
||||
(e.g. wget) will use IPv6 address. On an IPv6-incapable host
|
||||
or network applets will fail to connect to the host
|
||||
using IPv6 address.
|
||||
|
||||
config VERBOSE_RESOLUTION_ERRORS
|
||||
bool "Verbose resolution errors"
|
||||
default n
|
||||
@@ -534,6 +549,19 @@ config NAMEIF
|
||||
# Comment
|
||||
new_interface_name XX:XX:XX:XX:XX:XX
|
||||
|
||||
config FEATURE_NAMEIF_EXTENDED
|
||||
bool "Extended nameif"
|
||||
default n
|
||||
depends on NAMEIF
|
||||
help
|
||||
This extends the nameif syntax to support the bus_info and driver
|
||||
checks. The syntax is compatible to the normal nameif.
|
||||
File format:
|
||||
new_interface_name driver=asix bus=usb-0000:00:08.2-3
|
||||
new_interface_name bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
|
||||
new_interface_name mac=00:80:C8:38:91:B5
|
||||
new_interface_name 00:80:C8:38:91:B5
|
||||
|
||||
config NC
|
||||
bool "nc"
|
||||
default n
|
||||
|
||||
+79
-60
@@ -18,12 +18,6 @@
|
||||
/* We don't expect to see 1000+ seconds delay, unsigned is enough */
|
||||
#define MONOTONIC_US() ((unsigned)monotonic_us())
|
||||
|
||||
static struct in_addr src;
|
||||
static struct in_addr dst;
|
||||
static struct sockaddr_ll me;
|
||||
static struct sockaddr_ll he;
|
||||
static unsigned last;
|
||||
|
||||
enum {
|
||||
DAD = 1,
|
||||
UNSOLICITED = 2,
|
||||
@@ -34,21 +28,49 @@ enum {
|
||||
UNICASTING = 64
|
||||
};
|
||||
|
||||
static int sock;
|
||||
static unsigned count = UINT_MAX;
|
||||
static unsigned timeout_us;
|
||||
static unsigned sent;
|
||||
static unsigned brd_sent;
|
||||
static unsigned received;
|
||||
static unsigned brd_recv;
|
||||
static unsigned req_recv;
|
||||
struct globals {
|
||||
struct in_addr src;
|
||||
struct in_addr dst;
|
||||
struct sockaddr_ll me;
|
||||
struct sockaddr_ll he;
|
||||
int sock_fd;
|
||||
|
||||
int count; // = -1;
|
||||
unsigned last;
|
||||
unsigned timeout_us;
|
||||
unsigned start;
|
||||
|
||||
unsigned sent;
|
||||
unsigned brd_sent;
|
||||
unsigned received;
|
||||
unsigned brd_recv;
|
||||
unsigned req_recv;
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define src (G.src )
|
||||
#define dst (G.dst )
|
||||
#define me (G.me )
|
||||
#define he (G.he )
|
||||
#define sock_fd (G.sock_fd )
|
||||
#define count (G.count )
|
||||
#define last (G.last )
|
||||
#define timeout_us (G.timeout_us)
|
||||
#define start (G.start )
|
||||
#define sent (G.sent )
|
||||
#define brd_sent (G.brd_sent )
|
||||
#define received (G.received )
|
||||
#define brd_recv (G.brd_recv )
|
||||
#define req_recv (G.req_recv )
|
||||
#define INIT_G() \
|
||||
do { \
|
||||
count = -1; \
|
||||
} while (0)
|
||||
|
||||
static int send_pack(struct in_addr *src_addr,
|
||||
struct in_addr *dst_addr, struct sockaddr_ll *ME,
|
||||
struct sockaddr_ll *HE)
|
||||
{
|
||||
int err;
|
||||
unsigned now;
|
||||
unsigned char buf[256];
|
||||
struct arphdr *ah = (struct arphdr *) buf;
|
||||
unsigned char *p = (unsigned char *) (ah + 1);
|
||||
@@ -75,10 +97,9 @@ static int send_pack(struct in_addr *src_addr,
|
||||
memcpy(p, dst_addr, 4);
|
||||
p += 4;
|
||||
|
||||
now = MONOTONIC_US();
|
||||
err = sendto(sock, buf, p - buf, 0, (struct sockaddr *) HE, sizeof(*HE));
|
||||
err = sendto(sock_fd, buf, p - buf, 0, (struct sockaddr *) HE, sizeof(*HE));
|
||||
if (err == p - buf) {
|
||||
last = now;
|
||||
last = MONOTONIC_US();
|
||||
sent++;
|
||||
if (!(option_mask32 & UNICASTING))
|
||||
brd_sent++;
|
||||
@@ -106,18 +127,18 @@ static void finish(void)
|
||||
|
||||
static void catcher(void)
|
||||
{
|
||||
static unsigned start;
|
||||
|
||||
unsigned now;
|
||||
|
||||
now = MONOTONIC_US();
|
||||
if (start == 0)
|
||||
start = now;
|
||||
|
||||
if (count == 0 || (timeout_us && (now - start) > (timeout_us + 500000)))
|
||||
if (count == 0 || (timeout_us && (now - start) > timeout_us))
|
||||
finish();
|
||||
|
||||
count--;
|
||||
/* count < 0 means "infinite count" */
|
||||
if (count > 0)
|
||||
count--;
|
||||
|
||||
if (last == 0 || (now - last) > 500000) {
|
||||
send_pack(&src, &dst, &me, &he);
|
||||
@@ -160,7 +181,7 @@ static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
|
||||
memcpy(&src_ip, p + ah->ar_hln, 4);
|
||||
memcpy(&dst_ip, p + ah->ar_hln + 4 + ah->ar_hln, 4);
|
||||
if (!(option_mask32 & DAD)) {
|
||||
if (src_ip.s_addr != dst.s_addr)
|
||||
if (dst.s_addr != src_ip.s_addr)
|
||||
return 0;
|
||||
if (src.s_addr != dst_ip.s_addr)
|
||||
return 0;
|
||||
@@ -207,7 +228,8 @@ static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
|
||||
}
|
||||
|
||||
if (last) {
|
||||
printf(" %u.%03ums\n", last / 1000, last % 1000);
|
||||
unsigned diff = MONOTONIC_US() - last;
|
||||
printf(" %u.%03ums\n", diff / 1000, diff % 1000);
|
||||
} else {
|
||||
printf(" UNSOLICITED?\n");
|
||||
}
|
||||
@@ -231,15 +253,17 @@ int arping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int arping_main(int argc, char **argv)
|
||||
{
|
||||
const char *device = "eth0";
|
||||
int ifindex;
|
||||
char *source = NULL;
|
||||
char *target;
|
||||
unsigned char *packet;
|
||||
|
||||
sock = xsocket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
INIT_G();
|
||||
|
||||
sock_fd = xsocket(AF_PACKET, SOCK_DGRAM, 0);
|
||||
|
||||
// Drop suid root privileges
|
||||
xsetuid(getuid());
|
||||
// Need to remove SUID_NEVER from applets.h for this to work
|
||||
//xsetuid(getuid());
|
||||
|
||||
{
|
||||
unsigned opt;
|
||||
@@ -252,14 +276,9 @@ int arping_main(int argc, char **argv)
|
||||
opt = getopt32(argv, "DUAqfbc:w:I:s:",
|
||||
&str_count, &str_timeout, &device, &source);
|
||||
if (opt & 0x40) /* -c: count */
|
||||
count = xatou(str_count);
|
||||
count = xatoi_u(str_count);
|
||||
if (opt & 0x80) /* -w: timeout */
|
||||
timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000;
|
||||
//if (opt & 0x100) /* -I: interface */
|
||||
if (strlen(device) >= IF_NAMESIZE) {
|
||||
bb_error_msg_and_die("interface name '%s' is too long",
|
||||
device);
|
||||
}
|
||||
timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
|
||||
//if (opt & 0x200) /* -s: source */
|
||||
option_mask32 &= 0x3f; /* set respective flags */
|
||||
}
|
||||
@@ -272,11 +291,13 @@ int arping_main(int argc, char **argv)
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
|
||||
ioctl_or_perror_and_die(sock, SIOCGIFINDEX, &ifr, "interface %s not found", device);
|
||||
ifindex = ifr.ifr_ifindex;
|
||||
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name) - 1);
|
||||
/* We use ifr.ifr_name in error msg so that problem
|
||||
* with truncated name will be visible */
|
||||
ioctl_or_perror_and_die(sock_fd, SIOCGIFINDEX, &ifr, "interface %s not found", ifr.ifr_name);
|
||||
me.sll_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
xioctl(sock, SIOCGIFFLAGS, (char *) &ifr);
|
||||
xioctl(sock_fd, SIOCGIFFLAGS, (char *) &ifr);
|
||||
|
||||
if (!(ifr.ifr_flags & IFF_UP)) {
|
||||
bb_error_msg_and_die("interface %s is down", device);
|
||||
@@ -287,7 +308,7 @@ int arping_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!inet_aton(target, &dst)) {
|
||||
/* if (!inet_aton(target, &dst)) - not needed */ {
|
||||
len_and_sockaddr *lsa;
|
||||
lsa = xhost_and_af2sockaddr(target, 0, AF_INET);
|
||||
memcpy(&dst, &lsa->sin.sin_addr.s_addr, 4);
|
||||
@@ -299,66 +320,64 @@ int arping_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("invalid source address %s", source);
|
||||
}
|
||||
|
||||
if (!(option_mask32 & DAD) && (option_mask32 & UNSOLICITED) && src.s_addr == 0)
|
||||
if ((option_mask32 & (DAD|UNSOLICITED)) == UNSOLICITED && src.s_addr == 0)
|
||||
src = dst;
|
||||
|
||||
if (!(option_mask32 & DAD) || src.s_addr) {
|
||||
struct sockaddr_in saddr;
|
||||
int probe_fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if (device) {
|
||||
if (setsockopt(probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) == -1)
|
||||
bb_error_msg("warning: interface %s is ignored", device);
|
||||
}
|
||||
if (setsockopt(probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) == -1)
|
||||
bb_perror_msg("cannot bind to device %s", device);
|
||||
memset(&saddr, 0, sizeof(saddr));
|
||||
saddr.sin_family = AF_INET;
|
||||
if (src.s_addr) {
|
||||
/* Check that this is indeed our IP */
|
||||
saddr.sin_addr = src;
|
||||
xbind(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr));
|
||||
} else if (!(option_mask32 & DAD)) {
|
||||
} else { /* !(option_mask32 & DAD) case */
|
||||
/* Find IP address on this iface */
|
||||
socklen_t alen = sizeof(saddr);
|
||||
|
||||
saddr.sin_port = htons(1025);
|
||||
saddr.sin_addr = dst;
|
||||
|
||||
if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1)
|
||||
bb_perror_msg("warning: setsockopt(SO_DONTROUTE)");
|
||||
bb_perror_msg("setsockopt(SO_DONTROUTE)");
|
||||
xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr));
|
||||
if (getsockname(probe_fd, (struct sockaddr *) &saddr, &alen) == -1) {
|
||||
bb_error_msg_and_die("getsockname");
|
||||
bb_perror_msg_and_die("getsockname");
|
||||
}
|
||||
if (saddr.sin_family != AF_INET)
|
||||
bb_error_msg_and_die("no IP address configured");
|
||||
src = saddr.sin_addr;
|
||||
}
|
||||
close(probe_fd);
|
||||
}
|
||||
|
||||
me.sll_family = AF_PACKET;
|
||||
me.sll_ifindex = ifindex;
|
||||
//me.sll_ifindex = ifindex; - done before
|
||||
me.sll_protocol = htons(ETH_P_ARP);
|
||||
xbind(sock, (struct sockaddr *) &me, sizeof(me));
|
||||
xbind(sock_fd, (struct sockaddr *) &me, sizeof(me));
|
||||
|
||||
{
|
||||
socklen_t alen = sizeof(me);
|
||||
|
||||
if (getsockname(sock, (struct sockaddr *) &me, &alen) == -1) {
|
||||
bb_error_msg_and_die("getsockname");
|
||||
if (getsockname(sock_fd, (struct sockaddr *) &me, &alen) == -1) {
|
||||
bb_perror_msg_and_die("getsockname");
|
||||
}
|
||||
}
|
||||
if (me.sll_halen == 0) {
|
||||
bb_error_msg("interface \"%s\" is not ARPable (no ll address)", device);
|
||||
bb_error_msg("interface %s is not ARPable (no ll address)", device);
|
||||
return (option_mask32 & DAD ? 0 : 2);
|
||||
}
|
||||
he = me;
|
||||
memset(he.sll_addr, -1, he.sll_halen);
|
||||
|
||||
if (!(option_mask32 & QUIET)) {
|
||||
printf("ARPING to %s from %s via %s\n",
|
||||
inet_ntoa(dst), inet_ntoa(src),
|
||||
device ? device : "unknown");
|
||||
}
|
||||
|
||||
if (!src.s_addr && !(option_mask32 & DAD)) {
|
||||
bb_error_msg_and_die("no src address in the non-DAD mode");
|
||||
/* inet_ntoa uses static storage, can't use in same printf */
|
||||
printf("ARPING to %s", inet_ntoa(dst));
|
||||
printf(" from %s via %s\n", inet_ntoa(src), device);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -383,7 +402,7 @@ int arping_main(int argc, char **argv)
|
||||
socklen_t alen = sizeof(from);
|
||||
int cc;
|
||||
|
||||
cc = recvfrom(sock, packet, 4096, 0, (struct sockaddr *) &from, &alen);
|
||||
cc = recvfrom(sock_fd, packet, 4096, 0, (struct sockaddr *) &from, &alen);
|
||||
if (cc < 0) {
|
||||
bb_perror_msg("recvfrom");
|
||||
continue;
|
||||
|
||||
@@ -0,0 +1,451 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Network Working Group M. Allman
|
||||
Request for Comments: 2428 NASA Lewis/Sterling Software
|
||||
Category: Standards Track S. Ostermann
|
||||
Ohio University
|
||||
C. Metz
|
||||
The Inner Net
|
||||
September 1998
|
||||
|
||||
|
||||
FTP Extensions for IPv6 and NATs
|
||||
|
||||
Status of this Memo
|
||||
|
||||
This document specifies an Internet standards track protocol for the
|
||||
Internet community, and requests discussion and suggestions for
|
||||
improvements. Please refer to the current edition of the "Internet
|
||||
Official Protocol Standards" (STD 1) for the standardization state
|
||||
and status of this protocol. Distribution of this memo is unlimited.
|
||||
|
||||
Copyright Notice
|
||||
|
||||
Copyright (C) The Internet Society (1998). All Rights Reserved.
|
||||
|
||||
Abstract
|
||||
|
||||
The specification for the File Transfer Protocol assumes that the
|
||||
underlying network protocol uses a 32-bit network address
|
||||
(specifically IP version 4). With the deployment of version 6 of the
|
||||
Internet Protocol, network addresses will no longer be 32-bits. This
|
||||
paper specifies extensions to FTP that will allow the protocol to
|
||||
work over IPv4 and IPv6. In addition, the framework defined can
|
||||
support additional network protocols in the future.
|
||||
|
||||
1. Introduction
|
||||
|
||||
The keywords, such as MUST and SHOULD, found in this document are
|
||||
used as defined in RFC 2119 [Bra97].
|
||||
|
||||
The File Transfer Protocol [PR85] only provides the ability to
|
||||
communicate information about IPv4 data connections. FTP assumes
|
||||
network addresses will be 32 bits in length. However, with the
|
||||
deployment of version 6 of the Internet Protocol [DH96] addresses
|
||||
will no longer be 32 bits long. RFC 1639 [Pis94] specifies
|
||||
extensions to FTP to enable its use over various network protocols.
|
||||
Unfortunately, the mechanism can fail in a multi-protocol
|
||||
environment. During the transition between IPv4 and IPv6, FTP needs
|
||||
the ability to negotiate the network protocol that will be used for
|
||||
data transfer.
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 1]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
This document provides a specification for a way that FTP can
|
||||
communicate data connection endpoint information for network
|
||||
protocols other than IPv4. In this specification, the FTP commands
|
||||
PORT and PASV are replaced with EPRT and EPSV, respectively. This
|
||||
document is organized as follows. Section 2 outlines the EPRT
|
||||
command and Section 3 outlines the EPSV command. Section 4 defines
|
||||
the utilization of these two new FTP commands. Section 5 briefly
|
||||
presents security considerations. Finally, Section 6 provides
|
||||
conclusions.
|
||||
|
||||
2. The EPRT Command
|
||||
|
||||
The EPRT command allows for the specification of an extended address
|
||||
for the data connection. The extended address MUST consist of the
|
||||
network protocol as well as the network and transport addresses. The
|
||||
format of EPRT is:
|
||||
|
||||
EPRT<space><d><net-prt><d><net-addr><d><tcp-port><d>
|
||||
|
||||
The EPRT command keyword MUST be followed by a single space (ASCII
|
||||
32). Following the space, a delimiter character (<d>) MUST be
|
||||
specified. The delimiter character MUST be one of the ASCII
|
||||
characters in range 33-126 inclusive. The character "|" (ASCII 124)
|
||||
is recommended unless it coincides with a character needed to encode
|
||||
the network address.
|
||||
|
||||
The <net-prt> argument MUST be an address family number defined by
|
||||
IANA in the latest Assigned Numbers RFC (RFC 1700 [RP94] as of the
|
||||
writing of this document). This number indicates the protocol to be
|
||||
used (and, implicitly, the address length). This document will use
|
||||
two of address family numbers from [RP94] as examples, according to
|
||||
the following table:
|
||||
|
||||
AF Number Protocol
|
||||
--------- --------
|
||||
1 Internet Protocol, Version 4 [Pos81a]
|
||||
2 Internet Protocol, Version 6 [DH96]
|
||||
|
||||
The <net-addr> is a protocol specific string representation of the
|
||||
network address. For the two address families specified above (AF
|
||||
Number 1 and 2), addresses MUST be in the following format:
|
||||
|
||||
AF Number Address Format Example
|
||||
--------- -------------- -------
|
||||
1 dotted decimal 132.235.1.2
|
||||
2 IPv6 string 1080::8:800:200C:417A
|
||||
representations
|
||||
defined in [HD96]
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 2]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
The <tcp-port> argument must be the string representation of the
|
||||
number of the TCP port on which the host is listening for the data
|
||||
connection.
|
||||
|
||||
The following are sample EPRT commands:
|
||||
|
||||
EPRT |1|132.235.1.2|6275|
|
||||
|
||||
EPRT |2|1080::8:800:200C:417A|5282|
|
||||
|
||||
The first command specifies that the server should use IPv4 to open a
|
||||
data connection to the host "132.235.1.2" on TCP port 6275. The
|
||||
second command specifies that the server should use the IPv6 network
|
||||
protocol and the network address "1080::8:800:200C:417A" to open a
|
||||
TCP data connection on port 5282.
|
||||
|
||||
Upon receipt of a valid EPRT command, the server MUST return a code
|
||||
of 200 (Command OK). The standard negative error code 500 and 501
|
||||
[PR85] are sufficient to handle most errors (e.g., syntax errors)
|
||||
involving the EPRT command. However, an additional error code is
|
||||
needed. The response code 522 indicates that the server does not
|
||||
support the requested network protocol. The interpretation of this
|
||||
new error code is:
|
||||
|
||||
5yz Negative Completion
|
||||
x2z Connections
|
||||
xy2 Extended Port Failure - unknown network protocol
|
||||
|
||||
The text portion of the response MUST indicate which network
|
||||
protocols the server does support. If the network protocol is
|
||||
unsupported, the format of the response string MUST be:
|
||||
|
||||
<text stating that the network protocol is unsupported> \
|
||||
(prot1,prot2,...,protn)
|
||||
|
||||
Both the numeric code specified above and the protocol information
|
||||
between the characters '(' and ')' are intended for the software
|
||||
automata receiving the response; the textual message between the
|
||||
numeric code and the '(' is intended for the human user and can be
|
||||
any arbitrary text, but MUST NOT include the characters '(' and ')'.
|
||||
In the above case, the text SHOULD indicate that the network protocol
|
||||
in the EPRT command is not supported by the server. The list of
|
||||
protocols inside the parenthesis MUST be a comma separated list of
|
||||
address family numbers. Two example response strings follow:
|
||||
|
||||
Network protocol not supported, use (1)
|
||||
|
||||
Network protocol not supported, use (1,2)
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 3]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
3. The EPSV Command
|
||||
|
||||
The EPSV command requests that a server listen on a data port and
|
||||
wait for a connection. The EPSV command takes an optional argument.
|
||||
The response to this command includes only the TCP port number of the
|
||||
listening connection. The format of the response, however, is
|
||||
similar to the argument of the EPRT command. This allows the same
|
||||
parsing routines to be used for both commands. In addition, the
|
||||
format leaves a place holder for the network protocol and/or network
|
||||
address, which may be needed in the EPSV response in the future. The
|
||||
response code for entering passive mode using an extended address
|
||||
MUST be 229. The interpretation of this code, according to [PR85]
|
||||
is:
|
||||
|
||||
2yz Positive Completion
|
||||
x2z Connections
|
||||
xy9 Extended Passive Mode Entered
|
||||
|
||||
The text returned in response to the EPSV command MUST be:
|
||||
|
||||
<text indicating server is entering extended passive mode> \
|
||||
(<d><d><d><tcp-port><d>)
|
||||
|
||||
The portion of the string enclosed in parentheses MUST be the exact
|
||||
string needed by the EPRT command to open the data connection, as
|
||||
specified above.
|
||||
|
||||
The first two fields contained in the parenthesis MUST be blank. The
|
||||
third field MUST be the string representation of the TCP port number
|
||||
on which the server is listening for a data connection. The network
|
||||
protocol used by the data connection will be the same network
|
||||
protocol used by the control connection. In addition, the network
|
||||
address used to establish the data connection will be the same
|
||||
network address used for the control connection. An example response
|
||||
string follows:
|
||||
|
||||
Entering Extended Passive Mode (|||6446|)
|
||||
|
||||
The standard negative error codes 500 and 501 are sufficient to
|
||||
handle all errors involving the EPSV command (e.g., syntax errors).
|
||||
|
||||
When the EPSV command is issued with no argument, the server will
|
||||
choose the network protocol for the data connection based on the
|
||||
protocol used for the control connection. However, in the case of
|
||||
proxy FTP, this protocol might not be appropriate for communication
|
||||
between the two servers. Therefore, the client needs to be able to
|
||||
request a specific protocol. If the server returns a protocol that
|
||||
is not supported by the host that will be connecting to the port, the
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 4]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
client MUST issue an ABOR (abort) command to allow the server to
|
||||
close down the listening connection. The client can then send an
|
||||
EPSV command requesting the use of a specific network protocol, as
|
||||
follows:
|
||||
|
||||
EPSV<space><net-prt>
|
||||
|
||||
If the requested protocol is supported by the server, it SHOULD use
|
||||
the protocol. If not, the server MUST return the 522 error messages
|
||||
as outlined in section 2.
|
||||
|
||||
Finally, the EPSV command can be used with the argument "ALL" to
|
||||
inform Network Address Translators that the EPRT command (as well as
|
||||
other data commands) will no longer be used. An example of this
|
||||
command follows:
|
||||
|
||||
EPSV<space>ALL
|
||||
|
||||
Upon receipt of an EPSV ALL command, the server MUST reject all data
|
||||
connection setup commands other than EPSV (i.e., EPRT, PORT, PASV, et
|
||||
al.). This use of the EPSV command is further explained in section
|
||||
4.
|
||||
|
||||
4. Command Usage
|
||||
|
||||
For all FTP transfers where the control and data connection(s) are
|
||||
being established between the same two machines, the EPSV command
|
||||
MUST be used. Using the EPSV command benefits performance of
|
||||
transfers that traverse firewalls or Network Address Translators
|
||||
(NATs). RFC 1579 [Bel94] recommends using the passive command when
|
||||
behind firewalls since firewalls do not generally allow incoming
|
||||
connections (which are required when using the PORT (EPRT) command).
|
||||
In addition, using EPSV as defined in this document does not require
|
||||
NATs to change the network address in the traffic as it is forwarded.
|
||||
The NAT would have to change the address if the EPRT command was
|
||||
used. Finally, if the client issues an "EPSV ALL" command, NATs may
|
||||
be able to put the connection on a "fast path" through the
|
||||
translator, as the EPRT command will never be used and therefore,
|
||||
translation of the data portion of the segments will never be needed.
|
||||
When a client only expects to do two-way FTP transfers, it SHOULD
|
||||
issue this command as soon as possible. If a client later finds that
|
||||
it must do a three-way FTP transfer after issuing an EPSV ALL
|
||||
command, a new FTP session MUST be started.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 5]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
5. Security Issues
|
||||
|
||||
The authors do not believe that these changes to FTP introduce new
|
||||
security problems. A companion Work in Progress [AO98] is a more
|
||||
general discussion of FTP security issues and techniques to reduce
|
||||
these security problems.
|
||||
|
||||
6. Conclusions
|
||||
|
||||
The extensions specified in this paper will enable FTP to operate
|
||||
over a variety of network protocols.
|
||||
|
||||
References
|
||||
|
||||
[AO98] Allman, M., and S. Ostermann, "FTP Security
|
||||
Considerations", Work in Progress.
|
||||
|
||||
[Bel94] Bellovin, S., "Firewall-Friendly FTP", RFC 1579, February
|
||||
1994.
|
||||
|
||||
[Bra97] Bradner, S., "Key words for use in RFCs to Indicate
|
||||
Requirement Levels", BCP 14, RFC 2119, March 1997.
|
||||
|
||||
[DH96] Deering, S., and R. Hinden, "Internet Protocol, Version 6
|
||||
(IPv6) Specification", RFC 1883, December 1995.
|
||||
|
||||
[HD96] Hinden, R., and S. Deering, "IP Version 6 Addressing
|
||||
Architecture", RFC 2373, July 1998.
|
||||
|
||||
[Pis94] Piscitello, D., "FTP Operation Over Big Address Records
|
||||
(FOOBAR)", RFC 1639, June 1994.
|
||||
|
||||
[Pos81a] Postel, J., "Internet Protocol", STD 5, RFC 791, September
|
||||
1981.
|
||||
|
||||
[Pos81b] Postel, J., "Transmission Control Protocol", STD 7, RFC 793,
|
||||
September 1981.
|
||||
|
||||
[PR85] Postel, J., and J. Reynolds, "File Transfer Protocol (FTP)",
|
||||
STD 9, RFC 959, October 1985.
|
||||
|
||||
[RP94] Reynolds, J., and J. Postel, "Assigned Numbers", STD 2, RFC
|
||||
1700, October 1994. See also:
|
||||
http://www.iana.org/numbers.html
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 6]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
Authors' Addresses
|
||||
|
||||
Mark Allman
|
||||
NASA Lewis Research Center/Sterling Software
|
||||
21000 Brookpark Rd. MS 54-2
|
||||
Cleveland, OH 44135
|
||||
|
||||
Phone: (216) 433-6586
|
||||
EMail: mallman@lerc.nasa.gov
|
||||
http://gigahertz.lerc.nasa.gov/~mallman/
|
||||
|
||||
|
||||
Shawn Ostermann
|
||||
School of Electrical Engineering and Computer Science
|
||||
Ohio University
|
||||
416 Morton Hall
|
||||
Athens, OH 45701
|
||||
|
||||
Phone: (740) 593-1234
|
||||
EMail: ostermann@cs.ohiou.edu
|
||||
|
||||
|
||||
Craig Metz
|
||||
The Inner Net
|
||||
Box 10314-1954
|
||||
Blacksburg, VA 24062-0314
|
||||
|
||||
Phone: (DSN) 754-8590
|
||||
EMail: cmetz@inner.net
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 7]
|
||||
|
||||
RFC 2428 FTP Extensions for IPv6 and NATs September 1998
|
||||
|
||||
|
||||
Full Copyright Statement
|
||||
|
||||
Copyright (C) The Internet Society (1998). All Rights Reserved.
|
||||
|
||||
This document and translations of it may be copied and furnished to
|
||||
others, and derivative works that comment on or otherwise explain it
|
||||
or assist in its implementation may be prepared, copied, published
|
||||
and distributed, in whole or in part, without restriction of any
|
||||
kind, provided that the above copyright notice and this paragraph are
|
||||
included on all such copies and derivative works. However, this
|
||||
document itself may not be modified in any way, such as by removing
|
||||
the copyright notice or references to the Internet Society or other
|
||||
Internet organizations, except as needed for the purpose of
|
||||
developing Internet standards in which case the procedures for
|
||||
copyrights defined in the Internet Standards process must be
|
||||
followed, or as required to translate it into languages other than
|
||||
English.
|
||||
|
||||
The limited permissions granted above are perpetual and will not be
|
||||
revoked by the Internet Society or its successors or assigns.
|
||||
|
||||
This document and the information contained herein is provided on an
|
||||
"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
|
||||
TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
|
||||
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Allman, et. al. Standards Track [Page 8]
|
||||
|
||||
+1
-1
@@ -1950,7 +1950,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
|
||||
if ((STRNCASECMP(iobuf, "Content-length:") == 0)) {
|
||||
/* extra read only for POST */
|
||||
if (prequest != request_GET) {
|
||||
tptr = iobuf + sizeof("Content-length:") - 1;
|
||||
tptr = skip_whitespace(iobuf + sizeof("Content-length:") - 1);
|
||||
if (!tptr[0])
|
||||
send_headers_and_exit(HTTP_BAD_REQUEST);
|
||||
errno = 0;
|
||||
|
||||
@@ -134,13 +134,15 @@ static char *get_var(const char *id, size_t idlen, struct interface_defn_t *ifd)
|
||||
int i;
|
||||
|
||||
if (strncmpz(id, "iface", idlen) == 0) {
|
||||
char *result;
|
||||
static char label_buf[20];
|
||||
safe_strncpy(label_buf, ifd->iface, sizeof(label_buf));
|
||||
result = strchr(label_buf, ':');
|
||||
if (result) {
|
||||
*result = '\0';
|
||||
}
|
||||
static char *label_buf;
|
||||
//char *result;
|
||||
|
||||
free(label_buf);
|
||||
label_buf = xstrdup(ifd->iface);
|
||||
// Remove virtual iface suffix - why?
|
||||
// ubuntu's ifup doesn't do this
|
||||
//result = strchrnul(label_buf, ':');
|
||||
//*result = '\0';
|
||||
return label_buf;
|
||||
}
|
||||
if (strncmpz(id, "label", idlen) == 0) {
|
||||
|
||||
+17
-51
@@ -206,21 +206,6 @@ extern char **environ;
|
||||
# define INETD_SETPROCTITLE
|
||||
#endif
|
||||
|
||||
typedef int8_t socktype_t;
|
||||
typedef int8_t family_t;
|
||||
struct BUG_too_small {
|
||||
char BUG_socktype_t_too_small[(0
|
||||
| SOCK_STREAM
|
||||
| SOCK_DGRAM
|
||||
| SOCK_RDM
|
||||
| SOCK_SEQPACKET
|
||||
| SOCK_RAW) <= 127 ? 1 : -1];
|
||||
char BUG_family_t_too_small[(0
|
||||
| AF_INET
|
||||
| AF_INET6
|
||||
| AF_UNIX) <= 127 ? 1 : -1];
|
||||
};
|
||||
|
||||
typedef struct servtab_t {
|
||||
/* The most frequently referenced one: */
|
||||
int se_fd; /* open descriptor */
|
||||
@@ -430,7 +415,8 @@ static void register_rpc(servtab_t *sep)
|
||||
struct protoent *pp;
|
||||
socklen_t size;
|
||||
|
||||
if ((pp = getprotobyname(sep->se_proto + 4)) == NULL) {
|
||||
pp = getprotobyname(sep->se_proto + 4);
|
||||
if (pp == NULL) {
|
||||
bb_perror_msg("%s: getproto", sep->se_proto);
|
||||
return;
|
||||
}
|
||||
@@ -569,9 +555,8 @@ static void setup(servtab_t *sep)
|
||||
static char *nextline(void)
|
||||
{
|
||||
char *cp;
|
||||
FILE *fd = fconfig;
|
||||
|
||||
if (fgets(line, LINE_SIZE, fd) == NULL)
|
||||
if (fgets(line, LINE_SIZE, fconfig) == NULL)
|
||||
return NULL;
|
||||
cp = strchr(line, '\n');
|
||||
if (cp)
|
||||
@@ -585,7 +570,7 @@ static char *skip(char **cpp) /* int report; */
|
||||
char *start;
|
||||
|
||||
/* erp: */
|
||||
if (*cpp == NULL) {
|
||||
if (cp == NULL) {
|
||||
/* if (report) */
|
||||
/* bb_error_msg("syntax error in inetd config file"); */
|
||||
return NULL;
|
||||
@@ -595,9 +580,7 @@ static char *skip(char **cpp) /* int report; */
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
cp++;
|
||||
if (*cp == '\0') {
|
||||
int c;
|
||||
|
||||
c = getc(fconfig);
|
||||
int c = getc(fconfig);
|
||||
ungetc(c, fconfig);
|
||||
if (c == ' ' || c == '\t') {
|
||||
cp = nextline();
|
||||
@@ -605,7 +588,6 @@ static char *skip(char **cpp) /* int report; */
|
||||
goto again;
|
||||
}
|
||||
*cpp = NULL;
|
||||
/* goto erp; */
|
||||
return NULL;
|
||||
}
|
||||
start = cp;
|
||||
@@ -613,8 +595,6 @@ static char *skip(char **cpp) /* int report; */
|
||||
cp++;
|
||||
if (*cp != '\0')
|
||||
*cp++ = '\0';
|
||||
/* if ((*cpp = cp) == NULL) */
|
||||
/* goto erp; */
|
||||
|
||||
*cpp = cp;
|
||||
return start;
|
||||
@@ -622,7 +602,7 @@ static char *skip(char **cpp) /* int report; */
|
||||
|
||||
static servtab_t *new_servtab(void)
|
||||
{
|
||||
return xmalloc(sizeof(servtab_t));
|
||||
return xzalloc(sizeof(servtab_t));
|
||||
}
|
||||
|
||||
static servtab_t *dupconfig(servtab_t *sep)
|
||||
@@ -631,7 +611,6 @@ static servtab_t *dupconfig(servtab_t *sep)
|
||||
int argc;
|
||||
|
||||
newtab = new_servtab();
|
||||
memset(newtab, 0, sizeof(servtab_t));
|
||||
newtab->se_service = xstrdup(sep->se_service);
|
||||
newtab->se_socktype = sep->se_socktype;
|
||||
newtab->se_family = sep->se_family;
|
||||
@@ -667,17 +646,14 @@ static servtab_t *getconfigent(void)
|
||||
|
||||
sep = new_servtab();
|
||||
|
||||
/* memset(sep, 0, sizeof *sep); */
|
||||
more:
|
||||
/* freeconfig(sep); */
|
||||
|
||||
while ((cp = nextline()) && *cp == '#') /* skip comment line */;
|
||||
while ((cp = nextline()) && *cp == '#')
|
||||
continue; /* skip comment lines */
|
||||
if (cp == NULL) {
|
||||
/* free(sep); */
|
||||
free(sep);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset((char *) sep, 0, sizeof *sep);
|
||||
arg = skip(&cp);
|
||||
if (arg == NULL) {
|
||||
/* A blank line. */
|
||||
@@ -775,9 +751,7 @@ static servtab_t *getconfigent(void)
|
||||
} else
|
||||
sep->se_max = toomany;
|
||||
}
|
||||
sep->se_wait = strcmp(arg, "wait") == 0;
|
||||
/* if ((arg = skip(&cp, 1)) == NULL) */
|
||||
/* goto more; */
|
||||
sep->se_wait = (strcmp(arg, "wait") == 0);
|
||||
sep->se_user = xxstrdup(skip(&cp));
|
||||
arg = strchr(sep->se_user, '.');
|
||||
if (arg == NULL)
|
||||
@@ -787,10 +761,10 @@ static servtab_t *getconfigent(void)
|
||||
sep->se_group = xstrdup(arg);
|
||||
}
|
||||
|
||||
arg = skip(&cp);
|
||||
sep->se_server = xxstrdup(arg);
|
||||
if (strcmp(sep->se_server, "internal") == 0) {
|
||||
sep->se_server = xxstrdup(skip(&cp));
|
||||
#ifdef INETD_FEATURE_ENABLED
|
||||
/* sep->se_bi = NULL; - done by new_servtab() */
|
||||
if (strcmp(sep->se_server, "internal") == 0) {
|
||||
const struct builtin *bi;
|
||||
|
||||
for (bi = builtins; bi->bi_service; bi++)
|
||||
@@ -803,22 +777,14 @@ static servtab_t *getconfigent(void)
|
||||
}
|
||||
sep->se_bi = bi;
|
||||
sep->se_wait = 0; /* = bi->bi_wait; - always 0 */
|
||||
#else
|
||||
bb_perror_msg("internal service %s unknown", sep->se_service);
|
||||
goto more;
|
||||
#endif
|
||||
}
|
||||
#ifdef INETD_FEATURE_ENABLED
|
||||
else
|
||||
sep->se_bi = NULL;
|
||||
#endif
|
||||
argc = 0;
|
||||
for (; cp; arg = skip(&cp)) {
|
||||
if (argc < MAXARGV)
|
||||
sep->se_argv[argc++] = xxstrdup(arg);
|
||||
while ((arg = skip(&cp)) != NULL && argc < MAXARGV) {
|
||||
sep->se_argv[argc++] = xxstrdup(arg);
|
||||
}
|
||||
while (argc <= MAXARGV)
|
||||
sep->se_argv[argc++] = NULL;
|
||||
/* while (argc <= MAXARGV) */
|
||||
/* sep->se_argv[argc++] = NULL; - done by new_servtab() */
|
||||
|
||||
/*
|
||||
* Now that we've processed the entire line, check if the hostname
|
||||
|
||||
+15
-22
@@ -24,57 +24,50 @@
|
||||
|| ENABLE_FEATURE_IP_TUNNEL \
|
||||
|| ENABLE_FEATURE_IP_RULE
|
||||
|
||||
static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
|
||||
static int ATTRIBUTE_NORETURN ip_print_help(char ATTRIBUTE_UNUSED **argv)
|
||||
{
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
static int (*ip_func)(int argc, char **argv) = ip_print_help;
|
||||
|
||||
static int ip_do(int argc, char **argv)
|
||||
static int ip_do(int (*ip_func)(char **argv), char **argv)
|
||||
{
|
||||
ip_parse_common_args(&argc, &argv);
|
||||
return ip_func(argc-1, argv+1);
|
||||
argv = ip_parse_common_args(argv);
|
||||
return ip_func(argv);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_IP_ADDRESS
|
||||
int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ipaddr_main(int argc, char **argv)
|
||||
{
|
||||
ip_func = do_ipaddr;
|
||||
return ip_do(argc, argv);
|
||||
return ip_do(do_ipaddr, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_LINK
|
||||
int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iplink_main(int argc, char **argv)
|
||||
{
|
||||
ip_func = do_iplink;
|
||||
return ip_do(argc, argv);
|
||||
return ip_do(do_iplink, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_ROUTE
|
||||
int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iproute_main(int argc, char **argv)
|
||||
{
|
||||
ip_func = do_iproute;
|
||||
return ip_do(argc, argv);
|
||||
return ip_do(do_iproute, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_RULE
|
||||
int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iprule_main(int argc, char **argv)
|
||||
{
|
||||
ip_func = do_iprule;
|
||||
return ip_do(argc, argv);
|
||||
return ip_do(do_iprule, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_TUNNEL
|
||||
int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iptunnel_main(int argc, char **argv)
|
||||
{
|
||||
ip_func = do_iptunnel;
|
||||
return ip_do(argc, argv);
|
||||
return ip_do(do_iptunnel, argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -97,12 +90,12 @@ int ip_main(int argc, char **argv)
|
||||
USE_FEATURE_IP_RULE(IP_rule,)
|
||||
IP_none
|
||||
};
|
||||
int (*ip_func)(char**) = ip_print_help;
|
||||
|
||||
ip_parse_common_args(&argc, &argv);
|
||||
if (argc > 1) {
|
||||
int key = index_in_substrings(keywords, argv[1]);
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
argv = ip_parse_common_args(argv + 1);
|
||||
if (*argv) {
|
||||
int key = index_in_substrings(keywords, *argv);
|
||||
argv++;
|
||||
#if ENABLE_FEATURE_IP_ADDRESS
|
||||
if (key == IP_addr)
|
||||
ip_func = do_ipaddr;
|
||||
@@ -124,7 +117,7 @@ int ip_main(int argc, char **argv)
|
||||
ip_func = do_iprule;
|
||||
#endif
|
||||
}
|
||||
return ip_func(argc, argv);
|
||||
return ip_func(argv);
|
||||
}
|
||||
|
||||
#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */
|
||||
@@ -13,20 +13,20 @@
|
||||
#include <linux/if_link.h>
|
||||
#endif
|
||||
|
||||
extern void ip_parse_common_args(int *argcp, char ***argvp);
|
||||
extern char **ip_parse_common_args(char **argv);
|
||||
extern int print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
|
||||
extern int ipaddr_list_or_flush(int argc, char **argv, int flush);
|
||||
extern int iproute_monitor(int argc, char **argv);
|
||||
extern int ipaddr_list_or_flush(char **argv, int flush);
|
||||
extern int iproute_monitor(char **argv);
|
||||
extern void iplink_usage(void) ATTRIBUTE_NORETURN;
|
||||
extern void ipneigh_reset_filter(void);
|
||||
|
||||
extern int do_ipaddr(int argc, char **argv);
|
||||
extern int do_iproute(int argc, char **argv);
|
||||
extern int do_iprule(int argc, char **argv);
|
||||
extern int do_ipneigh(int argc, char **argv);
|
||||
extern int do_iptunnel(int argc, char **argv);
|
||||
extern int do_iplink(int argc, char **argv);
|
||||
extern int do_ipmonitor(int argc, char **argv);
|
||||
extern int do_multiaddr(int argc, char **argv);
|
||||
extern int do_multiroute(int argc, char **argv);
|
||||
extern int do_ipaddr(char **argv);
|
||||
extern int do_iproute(char **argv);
|
||||
extern int do_iprule(char **argv);
|
||||
extern int do_ipneigh(char **argv);
|
||||
extern int do_iptunnel(char **argv);
|
||||
extern int do_iplink(char **argv);
|
||||
extern int do_ipmonitor(char **argv);
|
||||
extern int do_multiaddr(char **argv);
|
||||
extern int do_multiroute(char **argv);
|
||||
#endif /* ip_common.h */
|
||||
@@ -18,71 +18,67 @@
|
||||
#include "ip_common.h" /* #include "libbb.h" is inside */
|
||||
#include "utils.h"
|
||||
|
||||
int preferred_family = AF_UNSPEC;
|
||||
family_t preferred_family = AF_UNSPEC;
|
||||
smallint oneline;
|
||||
char _SL_;
|
||||
|
||||
void ip_parse_common_args(int *argcp, char ***argvp)
|
||||
char **ip_parse_common_args(char **argv)
|
||||
{
|
||||
int argc = *argcp;
|
||||
char **argv = *argvp;
|
||||
static const char ip_common_commands[] ALIGN1 =
|
||||
"-family\0""inet\0""inet6\0""link\0"
|
||||
"-4\0""-6\0""-0\0""-oneline\0";
|
||||
"oneline" "\0"
|
||||
"family" "\0"
|
||||
"4" "\0"
|
||||
"6" "\0"
|
||||
"0" "\0"
|
||||
;
|
||||
enum {
|
||||
ARG_family = 1,
|
||||
ARG_inet,
|
||||
ARG_inet6,
|
||||
ARG_link,
|
||||
ARG_oneline,
|
||||
ARG_family,
|
||||
ARG_IPv4,
|
||||
ARG_IPv6,
|
||||
ARG_packet,
|
||||
ARG_oneline
|
||||
};
|
||||
smalluint arg;
|
||||
static const family_t af_numbers[] = { AF_INET, AF_INET6, AF_PACKET };
|
||||
int arg;
|
||||
|
||||
while (argc > 1) {
|
||||
char *opt = argv[1];
|
||||
while (*argv) {
|
||||
char *opt = *argv;
|
||||
|
||||
if (strcmp(opt,"--") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
break;
|
||||
}
|
||||
if (opt[0] != '-')
|
||||
break;
|
||||
if (opt[1] == '-')
|
||||
opt++;
|
||||
if (opt[0] == '-') {
|
||||
opt++;
|
||||
arg = index_in_strings(ip_common_commands, opt) + 1;
|
||||
if (arg == ARG_family) {
|
||||
argc--;
|
||||
argv++;
|
||||
if (!argv[1])
|
||||
bb_show_usage();
|
||||
arg = index_in_strings(ip_common_commands, argv[1]) + 1;
|
||||
if (arg == ARG_inet)
|
||||
preferred_family = AF_INET;
|
||||
else if (arg == ARG_inet6)
|
||||
preferred_family = AF_INET6;
|
||||
else if (arg == ARG_link)
|
||||
preferred_family = AF_PACKET;
|
||||
else
|
||||
invarg(argv[1], "protocol family");
|
||||
} else if (arg == ARG_IPv4) {
|
||||
preferred_family = AF_INET;
|
||||
} else if (arg == ARG_IPv6) {
|
||||
preferred_family = AF_INET6;
|
||||
} else if (arg == ARG_packet) {
|
||||
preferred_family = AF_PACKET;
|
||||
} else if (arg == ARG_oneline) {
|
||||
++oneline;
|
||||
} else {
|
||||
bb_show_usage();
|
||||
if (!opt[0]) { /* "--" */
|
||||
argv++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
arg = index_in_strings(ip_common_commands, opt);
|
||||
if (arg < 0)
|
||||
bb_show_usage();
|
||||
if (arg == ARG_oneline) {
|
||||
oneline = 1;
|
||||
argv++;
|
||||
continue;
|
||||
}
|
||||
if (arg == ARG_family) {
|
||||
static const char families[] ALIGN1 =
|
||||
"inet" "\0" "inet6" "\0" "link" "\0";
|
||||
argv++;
|
||||
if (!*argv)
|
||||
bb_show_usage();
|
||||
arg = index_in_strings(families, *argv);
|
||||
if (arg < 0)
|
||||
invarg(*argv, "protocol family");
|
||||
/* now arg == 0, 1 or 2 */
|
||||
} else {
|
||||
arg -= ARG_IPv4;
|
||||
/* now arg == 0, 1 or 2 */
|
||||
}
|
||||
preferred_family = af_numbers[arg];
|
||||
argv++;
|
||||
}
|
||||
_SL_ = oneline ? '\\' : '\n';
|
||||
*argcp = argc;
|
||||
*argvp = argv;
|
||||
return argv;
|
||||
}
|
||||
Loaded 100 of 191 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user