aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2023-11-28 18:32:43 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-28 18:32:43 +0000
commitede300a4b1eb2d67fc5063ec91f29d95feed22be (patch)
tree1e654383aa3d85b34245e621a6c8c206ac6480f9
parent84da79e21a0342b407cb2e9c909e93467145d17a (diff)
parent7bc14909f36d72db16835598bcf6090f0dc50b00 (diff)
downloadtoybox-ede300a4b1eb2d67fc5063ec91f29d95feed22be.tar.gz
Upgrade toybox to 7fac232b4d25e51372ee22512c92e724ce97734e am: 7bc14909f3
Original change: https://android-review.googlesource.com/c/platform/external/toybox/+/2847696 Change-Id: I23564f60e560eafae4e6923363c694b71d378e6a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--METADATA4
-rw-r--r--Makefile2
-rw-r--r--android/device/generated/globals.h4
-rw-r--r--android/linux/generated/globals.h4
-rw-r--r--android/mac/generated/globals.h4
-rw-r--r--main.c7
-rwxr-xr-xmkroot/mkroot.sh9
-rwxr-xr-xmkroot/packages/busybox33
-rwxr-xr-xscripts/mcm-buildall.sh146
-rwxr-xr-xscripts/probes/GLOBALS8
-rw-r--r--scripts/probes/README1
-rwxr-xr-xscripts/probes/bloatcheck (renamed from scripts/bloatcheck)0
-rwxr-xr-xscripts/probes/findglobals (renamed from scripts/findglobals.sh)3
-rwxr-xr-xscripts/probes/showasm (renamed from scripts/showasm)0
-rw-r--r--toys.h1
-rw-r--r--toys/net/microcom.c8
-rw-r--r--toys/other/nbd_client.c10
-rw-r--r--toys/pending/dhcpd.c132
-rw-r--r--toys/pending/sh.c3
-rw-r--r--toys/posix/sed.c2
20 files changed, 221 insertions, 160 deletions
diff --git a/METADATA b/METADATA
index 500af60a..f5227968 100644
--- a/METADATA
+++ b/METADATA
@@ -13,11 +13,11 @@ third_party {
type: GIT
value: "https://github.com/landley/toybox"
}
- version: "cf63277fc064c4b566fa27869dadb3540a04f756"
+ version: "7fac232b4d25e51372ee22512c92e724ce97734e"
license_type: UNENCUMBERED
last_upgrade_date {
year: 2023
month: 11
- day: 10
+ day: 27
}
}
diff --git a/Makefile b/Makefile
index 0ffc3533..100fd30e 100644
--- a/Makefile
+++ b/Makefile
@@ -39,7 +39,7 @@ baseline: generated/unstripped/toybox
@cp generated/unstripped/toybox generated/unstripped/toybox_old
bloatcheck: generated/unstripped/toybox_old generated/unstripped/toybox
- @scripts/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox
+ @scripts/probes/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox
install_flat: toybox
scripts/install.sh --symlink --force
diff --git a/android/device/generated/globals.h b/android/device/generated/globals.h
index 54ee65ca..933fb4ff 100644
--- a/android/device/generated/globals.h
+++ b/android/device/generated/globals.h
@@ -700,8 +700,8 @@ struct dhcp6_data {
// toys/pending/dhcpd.c
struct dhcpd_data {
- char *iface;
- long port;
+ char *i;
+ long p;
};
// toys/pending/diff.c
diff --git a/android/linux/generated/globals.h b/android/linux/generated/globals.h
index 54ee65ca..933fb4ff 100644
--- a/android/linux/generated/globals.h
+++ b/android/linux/generated/globals.h
@@ -700,8 +700,8 @@ struct dhcp6_data {
// toys/pending/dhcpd.c
struct dhcpd_data {
- char *iface;
- long port;
+ char *i;
+ long p;
};
// toys/pending/diff.c
diff --git a/android/mac/generated/globals.h b/android/mac/generated/globals.h
index 54ee65ca..933fb4ff 100644
--- a/android/mac/generated/globals.h
+++ b/android/mac/generated/globals.h
@@ -700,8 +700,8 @@ struct dhcp6_data {
// toys/pending/dhcpd.c
struct dhcpd_data {
- char *iface;
- long port;
+ char *i;
+ long p;
};
// toys/pending/diff.c
diff --git a/main.c b/main.c
index 6fc27099..3d9f612e 100644
--- a/main.c
+++ b/main.c
@@ -72,7 +72,7 @@ static const int NEED_OPTIONS =
#endif
#include "generated/help.h"
-static char *help_data =
+static const char help_data[] =
#include "generated/newtoys.h"
;
@@ -88,7 +88,7 @@ void show_help(FILE *out, int flags)
: " (see https://landley.net/toybox)");
for (;;) {
- s = help_data;
+ s = (void *)help_data;
while (i--) s += strlen(s) + 1;
// If it's an alias, restart search for real name
if (*s != 255) break;
@@ -195,9 +195,6 @@ void toy_init(struct toy_list *which, char *argv[])
}
}
- // Free old toys contents (to be reentrant), but leave rebound if any
- // don't blank old optargs if our new argc lives in the old optargs.
- if (argv<toys.optargs || argv>toys.optargs+toys.optc) free(toys.optargs);
memset(&toys, 0, offsetof(struct toy_context, rebound));
if (oldwhich) memset(&this, 0, sizeof(this));
diff --git a/mkroot/mkroot.sh b/mkroot/mkroot.sh
index 689faa4f..f65515fc 100755
--- a/mkroot/mkroot.sh
+++ b/mkroot/mkroot.sh
@@ -247,9 +247,10 @@ else
# Write the qemu launch script
if [ -n "$QEMU" ]; then
- [ -z "$BUILTIN" ] && INITRD="-initrd initramfs.cpio.gz"
- { echo qemu-system-"$QEMU" -m 256 '"$@"' $QEMU_MORE -nographic -no-reboot \
- -kernel linux-kernel $INITRD ${DTB:+-dtb linux.dtb} \
+ [ -z "$BUILTIN" ] && INITRD='-initrd "$DIR"/initramfs.cpio.gz'
+ { echo DIR='"$(dirname $0)";' qemu-system-"$QEMU" -m 256 '"$@"' $QEMU_MORE \
+ -nographic -no-reboot -kernel '"$DIR"'/linux-kernel $INITRD \
+ ${DTB:+-dtb '"$DIR"'/linux.dtb} \
"-append \"panic=1 HOST=$CROSS console=$KARGS \$KARGS\"" &&
echo "echo -e '\\e[?7h'"
} > "$OUTPUT"/run-qemu.sh &&
@@ -261,7 +262,7 @@ else
cp -sfR "$LINUX" "$TEMP/linux" && pushd "$TEMP/linux" &&
# Write linux-miniconfig
- mkdir "$OUTDOC" &&
+ mkdir -p "$OUTDOC" &&
{ echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=linux-miniconfig"
echo -e "# make ARCH=$KARCH -j \$(nproc)\n# boot $VMLINUX\n\n"
diff --git a/mkroot/packages/busybox b/mkroot/packages/busybox
index fa2d1c22..b1e9e4f7 100755
--- a/mkroot/packages/busybox
+++ b/mkroot/packages/busybox
@@ -1,28 +1,33 @@
#!/bin/echo Try "scripts/mkroot.sh dropbear"
-echo === download source
-
-download d5514f5cf8eb89a3b20ac3b965f4463f14a5709a \
- http://www.busybox.net/downloads/busybox-1.31.1.tar.bz2
-
-echo === $HOST Native build static dropbear
+download a5d40ca0201b20909f7a8a561adf57adccc8a877 \
+ http://www.busybox.net/downloads/busybox-1.36.1.tar.bz2
# 4 commands: ash, route, udhcpc, stty
setupfor busybox
make defconfig &&
-sed -Ei 's/# CONFIG_NOMMU is not set/CONFIG_NOMMU=y/;s/CONFIG_(RUNSV|MONOTONIC_SYSCALL)=y/# CONFIG_\1 is not set/' .config &&
-make silentoldconfig &&
-LDFLAGS=--static make SKIP_STRIP=y &&
+# Busybox checks for host bzip2, which toybox does not provide.
+sed -i 's/^bzip2/true bzip2/' scripts/{mkconfigs,embedded_scripts} &&
+# zap script that wants diff
+ln -sf /bin/true scripts/generate_BUFSIZ.sh &&
+echo '#define COMMON_BUFSIZE (4096)
+extern char bb_common_bufsiz1[];
+#define setup_common_bufsiz()' > include/common_bufsiz.h &&
+LDFLAGS=--static make SKIP_STRIP=y -j $(nproc) &&
cp busybox "$ROOT/bin" &&
-ln -sf busybox "$ROOT/bin/sh" &&
+make busybox.links &&
+mkdir -p "$ROOT/busybox" || exit 1
+while read i; do ln -sf /bin/busybox "$ROOT/busybox/$(basename "$i")" || exit 1
+done < busybox.links
cp .config "$ROOT/../busybox-config"
cleanup
-# busybox doesn't support $(<file)
-mkdir -p "$ROOT/etc/rc" &&
-echo '[ -z "$CONSOLE" ] && CONSOLE="$(cat /sys/class/tty/console/active)"' > \
- "$ROOT/etc/rc/busybox.sh" &&
+# busybox ash doesn't support $(<file)
+#ln -sf busybox "$ROOT/bin/sh" &&
+#mkdir -p "$ROOT/etc/rc" &&
+#echo '[ -z "$CONSOLE" ] && CONSOLE="$(cat /sys/class/tty/console/active)"' > \
+# "$ROOT/etc/rc/busybox.sh" &&
cat > "$ROOT"/etc/dhcp.sh << 'EOF' &&
#!/bin/sh
diff --git a/scripts/mcm-buildall.sh b/scripts/mcm-buildall.sh
index 11a10136..7ea52903 100755
--- a/scripts/mcm-buildall.sh
+++ b/scripts/mcm-buildall.sh
@@ -15,25 +15,55 @@ then
exit 1
fi
+# List of known targets. The format is TARGET[@RENAME]:EXTRA:CONFIG resulting
+# in a gcc tuple TARGET-linux-muslEXTRA with CONFIG appended to $GCC_CONFIG
+# (and thus the gcc ./configure command line). So i686:: builds i686-linux-musl
+# and sh2eb::fdpic:--with-cpu=mj2 builds sh2eb-linux-muslfdpic adding
+# --with-cpu=mj2 to the gcc ./configure command line. @RENAME (if present)
+# changes the TARGET part of the toolchain prefix names afterwards.
+
+TARGETS=(i686:: aarch64:eabi:
+ armv4l:eabihf:"--with-arch=armv5t --with-float=soft"
+ "armv5l:eabihf:--with-arch=armv5t --with-fpu=vfpv2 --with-float=hard"
+ "armv7l:eabihf:--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard"
+ "armv7m:eabi:--with-arch=armv7-m --with-mode=thumb --disable-libatomic --enable-default-pie"
+ armv7r:eabihf:"--with-arch=armv7-r --enable-default-pie"
+ i486:: m68k:: microblaze:: mips:: mips64:: mipsel:: powerpc::
+ powerpc64:: powerpc64le:: s390x:: sh2eb:fdpic:--with-cpu=mj2
+ sh4::--enable-incomplete-targets x86_64::--with-mtune=nocona
+ x86_64@x32:x32:
+)
+
# All toolchains after the first are themselves cross compiled (so they
# can be statically linked against musl on the host, for binary portability.)
-# static i686 binaries are basically "poor man's x32".
-BOOTSTRAP=i686-linux-musl
+: ${BOOTSTRAP:=$(uname -m)} ${OUTPUT:="$PWD/ccc"}
-[ -z "$OUTPUT" ] && OUTPUT="$PWD/ccc"
+# Move the corresponding target to the front so rest of targets get built
+# with full instead of partial -host compiler (missing threads and NLS and such)
+unset TEMP
+for i in $(seq 0 $((${#TARGETS[@]}-1)));
+do
+ [ "${TARGETS[$i]}" == "${TARGETS[$i]#"$BOOTSTRAP:"}" ] && continue
+ TEMP="${TARGETS[$i]}"
+ TARGETS[$i]="$TARGETS[0]"
+ TARGETS[0]="$TEMP"
+ break;
+done
+[ -z "$TEMP" ] && { echo unknown target "$BOOTSTRAP"; exit 1; }
if [ "$1" == clean ]
then
- rm -rf "$OUTPUT" host-* *.log
+ rm -rf ccc host-* *.log # Not gonna rm -rf "$OUTPUT" blindly, could be $HOME
make clean
exit
fi
make_toolchain()
{
+
# Set cross compiler path
LP="$PATH"
- if [ -z "$TYPE" ]
+ if [ "$TYPE" == host ]
then
OUTPUT="$PWD/host-$TARGET"
EXTRASUB=y
@@ -57,6 +87,7 @@ make_toolchain()
OUTPUT="$OUTPUT/${RENAME:-$TARGET}-$TYPE"
fi
+ # Skip outputs that already exist
if [ -e "$OUTPUT.sqf" ] || [ -e "$OUTPUT/bin/$TARGET-cc" ] ||
[ -e "$OUTPUT/bin/cc" ]
then
@@ -69,12 +100,11 @@ make_toolchain()
echo -en "\033]2;$TARGET-$TYPE\007"
rm -rf build/"$TARGET" "$OUTPUT" &&
- [ -z "$CPUS" ] && CPUS=$(($(nproc)+1))
set -x &&
PATH="$LP" make OUTPUT="$OUTPUT" TARGET="$TARGET" \
GCC_CONFIG="--disable-nls --disable-libquadmath --disable-decimal-float --disable-multilib --enable-languages=c,c++ $GCC_CONFIG" \
- COMMON_CONFIG="CFLAGS=\"$CFLAGS -g0 -Os\" CXXFLAGS=\"$CXXFLAGS -g0 -Os\" LDFLAGS=\"$LDFLAGS -s\" $COMMON_CONFIG" \
- install -j$CPUS || exit 1
+ COMMON_CONFIG="CFLAGS=\"$CFLAGS -g0 -O2\" CXXFLAGS=\"$CXXFLAGS -g0 -O2\" \
+ LDFLAGS=\"$LDFLAGS -s\" $COMMON_CONFIG" install -j$(nproc) || exit 1
set +x
echo -e '#ifndef __MUSL__\n#define __MUSL__ 1\n#endif' \
>> "$OUTPUT/${EXTRASUB:+$TARGET/}include/features.h"
@@ -109,8 +139,7 @@ make_toolchain()
fi
}
-# Expand compressed target into binutils/gcc "tuple" and call make_toolchain
-make_tuple()
+split_tuple()
{
PART1=${1/:*/}
PART3=${1/*:/}
@@ -121,27 +150,50 @@ make_tuple()
[ "$RENAME" == "$PART1" ] && RENAME=
PART1=${PART1/@*/}
TARGET=${PART1}-linux-musl${PART2}
+}
+
+# Expand compressed target into binutils/gcc "tuple" and call make_toolchain
+make_tuple()
+{
+ split_tuple "$@"
[ -z "$NOCLEAN" ] && rm -rf build
- for TYPE in static native
+ for TYPE in "${@:2}"
do
TYPE=$TYPE TARGET=$TARGET GCC_CONFIG="$PART3" RENAME="$RENAME" \
make_toolchain 2>&1 | tee "$OUTPUT"/log/${RENAME:-$PART1}-${TYPE}.log
done
}
-# Packages detect nommu via the absence of fork(). Musl provides a broken fork()
-# on nommu builds that always returns -ENOSYS at runtime. Rip it out.
-# (Currently only for superh/jcore.)
-fix_nommu()
+patch_mcm()
{
- # Rich won't merge this
- sed -i 's/--enable-fdpic$/& --enable-twoprocess/' litecross/Makefile
+ # musl-cross-make commit fe915821b652 has been current for a year and a half,
+ # and doesn't even use the latest musl release by default, so fix it up.
+
+ # Select newer package versions and don't use dodgy mirrors
+ sed -i 's/mirror//;s/\(LINUX_VER =\).*/\1 6.6/;s/\(GCC_VER =\).*/\1 11.2.0/;s/\(MUSL_VER =\).*/\1 1.2.4/' \
+ Makefile &&
+ echo 'c8dbfa8285f1a90596a227690653d84b9eb2debe linux-6.6.tar.xz' > \
+ hashes/linux-6.6.tar.xz.sha1 &&
+ echo '78eb982244b857dbacb2ead25cc0f631ce44204d musl-1.2.4.tar.gz' > \
+ hashes/musl-1.2.4.tar.gz.sha1 &&
+ # mcm redundantly downloads tarball if hash file has newer timestamp,
+ # and it whack-a-moles how to download kernels by version for some reason.
+ touch -d @1 hashes/linux-6.6.tar.xz.sha1 &&
+ touch -d @1 hashes/musl-1.2.4.tar.gz.sha1 &&
+ sed -i 's/\(.*linux-\)3\(.*\)v3.x/\16\2v6.x/' Makefile &&
+
+ # Rich won't merge this: nommu toolchains need to vfork() and pipe.
+ sed -i 's/--enable-fdpic$/& --enable-twoprocess/' litecross/Makefile &&
- PP=patches/musl-"$(sed -n 's/MUSL_VER[ \t]*=[ \t]*//p' Makefile)"
+ # Packages detect nommu via the absence of fork(). Musl provides a broken
+ # fork() on nommu builds that always returns -ENOSYS at runtime. Rip it out.
+ # (Currently only for superh/jcore since no generic #ifdef __FDPIC__ symbol.)
+
+ PP=patches/musl-"$(sed -n 's/MUSL_VER[ \t]*=[ \t]*//p' Makefile)" &&
mkdir -p "$PP" &&
- cat > "$PP"/0001-nommu.patch << 'EOF'
+ cat > "$PP"/0001-nommu.patch << 'EOF' &&
--- a/src/legacy/daemon.c
+++ b/src/legacy/daemon.c
@@ -17,3 +17,3 @@
@@ -209,39 +261,67 @@ EOF
+ ch_id = vfork ();
switch (ch_id)
EOF
+
+ # Fix a gcc bug that breaks x86-64 build in gcc 11.2.0,
+ # from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100017#c20
+
+ PP=patches/gcc-"$(sed -n 's/GCC_VER[ \t]*=[ \t]*//p' Makefile)" &&
+ mkdir -p "$PP" &&
+ cat > "$PP"/0006-fixinc.patch << 'EOF' &&
+diff -ruN gcc-11.2.0.orig/configure gcc-11.2.0/configure
+--- gcc-11.2.0.orig/configure 2021-07-28 01:55:06.628278148 -0500
++++ gcc-11.2.0/configure 2023-11-17 03:07:53.819283027 -0600
+@@ -16478,7 +16478,7 @@
+ fi
+
+
+-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
++RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find the target ar" >&5
+ $as_echo_n "checking where to find the target ar... " >&6; }
+diff -ruN gcc-11.2.0.orig/configure.ac gcc-11.2.0/configure.ac
+--- gcc-11.2.0.orig/configure.ac 2021-07-28 01:55:06.628278148 -0500
++++ gcc-11.2.0/configure.ac 2023-11-17 03:08:05.975282593 -0600
+@@ -3520,7 +3520,7 @@
+ ACX_CHECK_INSTALLED_TARGET_TOOL(WINDRES_FOR_TARGET, windres)
+ ACX_CHECK_INSTALLED_TARGET_TOOL(WINDMC_FOR_TARGET, windmc)
+
+-RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET"
++RAW_CXX_FOR_TARGET="$CXX_FOR_TARGET -nostdinc++"
+
+ GCC_TARGET_TOOL(ar, AR_FOR_TARGET, AR, [binutils/ar])
+ GCC_TARGET_TOOL(as, AS_FOR_TARGET, AS, [gas/as-new])
+EOF
+
+ # So the && chain above is easier to extend
+ true
}
-fix_nommu || exit 1
+patch_mcm || exit 1
mkdir -p "$OUTPUT"/log
# Make bootstrap compiler (no $TYPE, dynamically linked against host libc)
# We build the rest of the cross compilers with this so they're linked against
# musl-libc, because glibc doesn't fully support static linking and dynamic
# binaries aren't really portable between distributions
-TARGET=$BOOTSTRAP make_toolchain 2>&1 | tee -a "$OUTPUT/log/$BOOTSTRAP"-host.log
+make_tuple "${TARGETS[0]}" host 2>&1 | tee -a "$OUTPUT/log/$BOOTSTRAP"-host.log
+split_tuple "${TARGETS[0]}"
+BOOTSTRAP="$TARGET"
if [ $# -gt 0 ]
then
for i in "$@"
do
- make_tuple "$i"
+ make_tuple "$i" static native
done
else
# Here's the list of cross compilers supported by this build script.
# First target builds a proper version of the $BOOTSTRAP compiler above,
# which is used to build the rest (in alphabetical order)
- for i in i686:: \
- aarch64:eabi: armv4l:eabihf:"--with-arch=armv5t --with-float=soft" \
- "armv5l:eabihf:--with-arch=armv5t --with-fpu=vfpv2 --with-float=hard" \
- "armv7l:eabihf:--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard" \
- "armv7m:eabi:--with-arch=armv7-m --with-mode=thumb --disable-libatomic --enable-default-pie" \
- armv7r:eabihf:"--with-arch=armv7-r --enable-default-pie" \
- i486:: m68k:: microblaze:: mips:: mips64:: mipsel:: powerpc:: \
- powerpc64:: powerpc64le:: s390x:: sh2eb:fdpic:--with-cpu=mj2 \
- sh4::--enable-incomplete-targets x86_64::--with-mtune=nocona \
- x86_64@x32:x32:
+ for i in $(seq 0 $((${#TARGETS[@]}-1)))
do
- make_tuple "$i"
+ make_tuple "${TARGETS[$i]}" static native
done
fi
diff --git a/scripts/probes/GLOBALS b/scripts/probes/GLOBALS
new file mode 100755
index 00000000..0ec57627
--- /dev/null
+++ b/scripts/probes/GLOBALS
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Show bytes used by each command's GLOBALS() block, based on last build
+{
+ echo -e '#include "toys.h"\nint main(void) {'
+ sed -n 's/^\tstruct \(.*\)_data .*/printf("%d \1\\n", (int)sizeof(struct \1_data));/p' generated/globals.h
+ echo '}'
+} | "${CROSS_COMPILE}"cc -xc - && ./a.out | sort -n
diff --git a/scripts/probes/README b/scripts/probes/README
new file mode 100644
index 00000000..db8efd3d
--- /dev/null
+++ b/scripts/probes/README
@@ -0,0 +1 @@
+Various development scripts to ask questions about a toybox binary.
diff --git a/scripts/bloatcheck b/scripts/probes/bloatcheck
index d62b4ea2..d62b4ea2 100755
--- a/scripts/bloatcheck
+++ b/scripts/probes/bloatcheck
diff --git a/scripts/findglobals.sh b/scripts/probes/findglobals
index 2bb94d69..c4855dec 100755
--- a/scripts/findglobals.sh
+++ b/scripts/probes/findglobals
@@ -3,4 +3,5 @@
# Quick and dirty check to see if anybody's leaked global variables.
# We should have this, toy_list, toybuf, and toys.
-nm --size-sort generated/unstripped/toybox | grep '[0-9A-Fa-f]* [BCDGRS]' #| cut -d ' ' -f 3
+nm --size-sort generated/unstripped/toybox | grep '[0-9A-Fa-f]* [BCDGRS]' | \
+ grep -v GLIBC
diff --git a/scripts/showasm b/scripts/probes/showasm
index 75a6efd7..75a6efd7 100755
--- a/scripts/showasm
+++ b/scripts/probes/showasm
diff --git a/toys.h b/toys.h
index bde3d90d..88b7a837 100644
--- a/toys.h
+++ b/toys.h
@@ -66,6 +66,7 @@
// Non-posix headers
#include <sys/ioctl.h>
#include <sys/syscall.h>
+#include <sys/ttydefaults.h>
#include "lib/lib.h"
#include "lib/lsm.h"
diff --git a/toys/net/microcom.c b/toys/net/microcom.c
index 770afa0b..d805a062 100644
--- a/toys/net/microcom.c
+++ b/toys/net/microcom.c
@@ -38,7 +38,7 @@ static void handle_esc(void)
char input;
xputsn("\r\n[b]reak, [p]aste file, [q]uit: ");
- if (read(0, &input, 1)<1 || input == 'D'-64 || input == 'q') {
+ if (read(0, &input, 1)<1 || input == CTRL('D') || input == 'q') {
xputs("exit\r");
xexit();
}
@@ -53,12 +53,12 @@ static void handle_esc(void)
memset(toybuf, 0, sizeof(toybuf));
while (1) {
xprintf("\r\e[2K\e[1mFilename: \e[0m%s", toybuf);
- if (read(0, &input, 1) <= 0 || input == '['-64) {
+ if (read(0, &input, 1) <= 0 || input == CTRL('[')) {
return;
}
if (input == '\r') break;
if (input == 0x7f && len > 0) toybuf[--len] = 0;
- else if (input == 'U'-64) while (len > 0) toybuf[--len] = 0;
+ else if (input == CTRL('U')) while (len > 0) toybuf[--len] = 0;
else if (input >= ' ' && input <= 0x7f && len < sizeof(toybuf))
toybuf[len++] = input;
}
@@ -122,7 +122,7 @@ void microcom_main(void)
// Read from stdin, write to connection.
if (fds[1].revents) {
if (read(0, toybuf, 1) != 1) break;
- if (!FLAG(X) && *toybuf == ']'-64) handle_esc();
+ if (!FLAG(X) && *toybuf == CTRL(']')) handle_esc();
else xwrite(TT.fd, toybuf, 1);
}
}
diff --git a/toys/other/nbd_client.c b/toys/other/nbd_client.c
index caa7da61..636c64ca 100644
--- a/toys/other/nbd_client.c
+++ b/toys/other/nbd_client.c
@@ -21,16 +21,6 @@ config NBD_CLIENT
-s nbd swap support (lock server into memory)
*/
-/* TODO:
- usage: nbd-client [-Sp] [-t SECS] [-N name] HOST PORT DEVICE
-
- -t timeout in seconds
- -S sdp
- -p persist
- -d DEVICE
- -c DEVICE
-*/
-
#define FOR_nbd_client
#include "toys.h"
#include <linux/nbd.h>
diff --git a/toys/pending/dhcpd.c b/toys/pending/dhcpd.c
index c5125e71..f6d063d6 100644
--- a/toys/pending/dhcpd.c
+++ b/toys/pending/dhcpd.c
@@ -123,8 +123,8 @@ config DEBUG_DHCP
#define DHCP6_DUID_UUID 4
GLOBALS(
- char *iface;
- long port;
+ char *i;
+ long p;
)
struct config_keyword {
@@ -134,29 +134,18 @@ struct config_keyword {
char *def;
};
-typedef struct __attribute__((packed)) dhcp_msg_s {
- uint8_t op;
- uint8_t htype;
- uint8_t hlen;
- uint8_t hops;
- uint32_t xid;
- uint16_t secs;
- uint16_t flags;
- uint32_t ciaddr;
- uint32_t yiaddr;
- uint32_t nsiaddr;
- uint32_t ngiaddr;
- uint8_t chaddr[16];
- uint8_t sname[64];
- uint8_t file[128];
- uint32_t cookie;
- uint8_t options[308];
+typedef struct dhcp_msg_s {
+ char op, htype, hlen, hops;
+ unsigned xid;
+ unsigned short secs, flags;
+ unsigned ciaddr, yiaddr, nsiaddr, ngiaddr;
+ char chaddr[16], sname[64], file[128];
+ unsigned cookie;
+ char options[308];
} dhcp_msg_t;
-typedef struct __attribute__((packed)) dhcp6_msg_s {
- uint8_t msgtype;
- uint8_t transaction_id[3];
- uint8_t options[524];
+typedef struct dhcp6_msg_s {
+ char msgtype, transaction_id[3], options[524];
} dhcp6_msg_t;
typedef struct __attribute__((packed)) dhcp_raw_s {
@@ -173,63 +162,53 @@ typedef struct __attribute__((packed)) dhcp6_raw_s {
typedef struct static_lease_s {
struct static_lease_s *next;
- uint32_t nip;
+ unsigned nip;
int mac[6];
} static_lease;
typedef struct static_lease6_s {
struct static_lease6_s *next;
- uint16_t duid_len;
- uint16_t ia_type;
- uint32_t iaid;
- uint8_t nip6[16];
- uint8_t duid[20];
+ unsigned short duid_len, ia_type;
+ unsigned iaid;
+ char nip6[16], duid[20];
} static_lease6;
typedef struct {
- uint32_t expires;
- uint32_t lease_nip;
- uint8_t lease_mac[6];
- char hostname[20];
- uint8_t pad[2];
+ unsigned expires, lease_nip;
+ char lease_mac[6], hostname[20], pad[2];
} dyn_lease;
typedef struct {
- uint16_t duid_len;
- uint16_t ia_type;
- uint32_t expires;
- uint32_t iaid;
- uint8_t lease_nip6[16];
- uint8_t duid[20];
+ unsigned short duid_len, ia_type;
+ unsigned expires, iaid;
+ char lease_nip6[16], duid[20];
} dyn_lease6;
typedef struct option_val_s {
char *key;
- uint16_t code;
+ unsigned short code;
void *val;
size_t len;
} option_val_t;
-struct __attribute__((packed)) optval_duid_llt {
- uint16_t type;
- uint16_t hwtype;
- uint32_t time;
- uint8_t lladdr[]; //flexible
+struct optval_duid_llt {
+ unsigned short type, hwtype;
+ unsigned time;
+ char lladdr[];
};
-struct __attribute__((packed)) optval_ia_na {
- uint32_t iaid;
- uint32_t t1, t2;
- uint8_t optval[]; //flexible
+struct optval_ia_na {
+ unsigned iaid, t1, t2;
+ char optval[];
};
-struct __attribute__((packed)) optval_ia_addr {
- uint8_t ipv6_addr[16];
- uint32_t pref_lifetime;
- uint32_t valid_lifetime;
+
+struct optval_ia_addr {
+ char ipv6_addr[16];
+ unsigned pref_lifetime, valid_lifetime;
};
-struct __attribute__((packed)) optval_status_code {
- uint16_t status_code;
- uint8_t status_msg[]; //flexible
+struct optval_status_code {
+ unsigned short status_code;
+ char status_msg[];
};
typedef struct __attribute__((__may_alias__)) server_config_s {
@@ -907,7 +886,7 @@ static int send_packet(uint8_t broadcast)
dhcp_raw_t packet;
unsigned padding;
int fd, result = -1;
- uint8_t bmacaddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ char bmacaddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
memset(&packet, 0, sizeof(dhcp_raw_t));
memcpy(&packet.dhcp, &gstate.send.send_pkt, sizeof(dhcp_msg_t));
@@ -1606,36 +1585,35 @@ void dhcpd_main(void)
{
struct timeval tv;
int retval, i;
- uint8_t *optptr, msgtype = 0;
- uint16_t optlen = 0;
- uint32_t waited = 0, serverid = 0, requested_nip = 0;
- uint8_t transactionid[3] = {0,};
- uint32_t reqested_lease = 0, ip_pool_size = 0;
- char *hstname = NULL;
+ char *optptr, msgtype = 0, *hstname = 0, transactionid[3] = {0};
+ unsigned short optlen = 0;
+ unsigned waited = 0, serverid = 0, requested_nip = 0, reqested_lease = 0,
+ ip_pool_size = 0;
fd_set rfds;
infomode = LOG_CONSOLE;
- if (!(toys.optflags & FLAG_f)) {
- daemon(0,0);
+ if (!FLAG(f)) {
+ daemon(0, 0);
infomode = LOG_SILENT;
}
- if (toys.optflags & FLAG_S) {
- openlog("UDHCPD :", LOG_PID, LOG_DAEMON);
- infomode |= LOG_SYSTEM;
+ if (FLAG(S)) {
+ openlog("UDHCPD :", LOG_PID, LOG_DAEMON);
+ infomode |= LOG_SYSTEM;
}
setlinebuf(stdout);
//DHCPD_CONF_FILE
- parse_server_config((toys.optc==1)?toys.optargs[0]:"/etc/dhcpd.conf", keywords);
+ parse_server_config((toys.optc==1) ? *toys.optargs: "/etc/dhcpd.conf",
+ keywords);
infomsg(infomode, "toybox dhcpd started");
- if (toys.optflags & FLAG_6){
+ if (FLAG(6)) {
addr_version = AF_INET6;
gconfig.t1 = ntohl(gconfig.t1);
gconfig.t2 = ntohl(gconfig.t2);
gconfig.pref_lifetime = ntohl(gconfig.pref_lifetime);
gconfig.valid_lifetime = ntohl(gconfig.valid_lifetime);
gconfig.port = 547;
- for(i=0;i<4;i++)
+ for(i=0; i<4; i++)
ip_pool_size += (gconfig.end_ip6[i]-gconfig.start_ip6[i])<<((3-i)*8);
} else {
gconfig.start_ip = ntohl(gconfig.start_ip);
@@ -1650,19 +1628,17 @@ void dhcpd_main(void)
}
write_pid(gconfig.pidfile);
set_maxlease();
- if(TT.iface) gconfig.interface = TT.iface;
- if(TT.port) gconfig.port = TT.port;
+ if (TT.i) gconfig.interface = TT.i;
+ if (TT.p) gconfig.port = TT.p;
(addr_version==AF_INET6) ? read_lease6file() : read_leasefile();
-
if (get_interface(gconfig.interface, &gconfig.ifindex,
(addr_version==AF_INET6)? (void*)gconfig.server_nip6 :
(void*)&gconfig.server_nip, gconfig.server_mac) < 0)
perror_exit("Failed to get interface %s", gconfig.interface);
setup_signal();
- if (addr_version==AF_INET6) {
- open_listensock6();
- } else {
+ if (addr_version==AF_INET6) open_listensock6();
+ else {
gconfig.server_nip = htonl(gconfig.server_nip);
open_listensock();
}
diff --git a/toys/pending/sh.c b/toys/pending/sh.c
index f65c478a..9299d8d6 100644
--- a/toys/pending/sh.c
+++ b/toys/pending/sh.c
@@ -4394,7 +4394,8 @@ void cd_main(void)
void exit_main(void)
{
- exit(*toys.optargs ? atoi(*toys.optargs) : 0);
+ toys.exitval = *toys.optargs ? atoi(*toys.optargs) : 0;
+ xexit();
}
// lib/args.c can't +prefix & "+o history" needs space so parse cmdline here
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index e6e13972..f7a49f2a 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -1087,7 +1087,7 @@ void sed_main(void)
}
// Handling our own --version means we handle our own --help too.
- if (FLAG(help)) help_exit(0);
+ if (FLAG(help)) return show_help(stdout, 0);
// Parse pattern into commands.