From de233eb9fa6f4ebccc74d7e54b650ca935d43927 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 25 Sep 2021 20:27:11 -0500 Subject: [PATCH] Add linux32, remove uname 32 bit hack, just say "Toybox" for -o, add to -a, add to help. --- toys/posix/uname.c | 78 ++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 48 deletions(-) diff --git a/toys/posix/uname.c b/toys/posix/uname.c index 7f18f6a5..905e2311 100644 --- a/toys/posix/uname.c +++ b/toys/posix/uname.c @@ -4,8 +4,9 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/uname.html -USE_UNAME(NEWTOY(uname, "oamvrns", TOYFLAG_BIN)) +USE_UNAME(NEWTOY(uname, "aomvrns", TOYFLAG_BIN)) USE_ARCH(NEWTOY(arch, 0, TOYFLAG_USR|TOYFLAG_BIN)) +USE_LINUX32(NEWTOY(linux32, 0, TOYFLAG_USR|TOYFLAG_BIN)) config ARCH bool "arch" @@ -15,6 +16,14 @@ config ARCH Print machine (hardware) name, same as uname -m. +config LINUX32 + bool "linux32" + default y + help + usage: linux32 [COMMAND...] + + Tell uname -m to line to autoconf (to build 32 bit binaries on 64 bit kernel). + config UNAME bool "uname" default y @@ -28,64 +37,30 @@ config UNAME -r Kernel Release number -v Kernel Version -m Machine (hardware) name - -a All of the above + -o Userspace type + -a All of the above (in order) */ #define FOR_uname #define FORCE_FLAGS #include "toys.h" -// If a 32 bit x86 build environment working in a chroot under an x86-64 -// kernel returns x86_64 for -m it confuses ./configure. Special case it. - -#if defined(__i686__) -#define GROSS "i686" -#elif defined(__i586__) -#define GROSS "i586" -#elif defined(__i486__) -#define GROSS "i486" -#elif defined(__i386__) -#define GROSS "i386" -#endif - void uname_main(void) { - int i, flags = toys.optflags, needspace=0; - struct utsname u; + int i, needspace = 0; + char *c; - uname(&u); - if (FLAG(o)) -#ifdef __ANDROID__ - printf("Android"); -#else - flags |= FLAG_s; -#endif - if (!flags) flags = FLAG_s; - for (i=0; i<5; i++) { - char *c = ((char *) &u)+(sizeof(u.sysname)*i); - - if (flags & ((1<sysname)*i; + if (needspace++) *(--c)=' '; // Can't decrement first entry } + xputsn(c); } - putchar('\n'); + xputc('\n'); } void arch_main(void) @@ -93,3 +68,10 @@ void arch_main(void) toys.optflags = FLAG_m; uname_main(); } + +#include +void linux32_main(void) +{ + personality(PER_LINUX32); + xexec(toys.optc ? toys.optargs : (char *[]){"/bin/sh", 0}); +} -- 2.39.2