[Toybox] FreeBSD Toybox check-in

Rob Landley rob at landley.net
Thu Nov 9 11:01:59 PST 2023


On 11/8/23 17:04, Ed Maste wrote:
> I dropped off the mailing list a while back due to bounced mail, and
> hadn't been able to look at Toybox for some time. I recently had
> occasion to check on the state of Toybox on FreeBSD again.

I have a freebsd image running under qemu, which I do occasionally test on. :)

> I'm still carrying a patch to use `#!/usr/bin/env bash` in configure
> and seven files in scripts/ as we do not have bash in /usr/bin. I also
> changed the make invocation in configure to `gmake defconfig`.

I just switched to $(MAKE) in the Makefile so it should pass along gmake.

> Other than that, `gmake allnoconfig
> KCONFIG_ALLCONFIG=kconfig/freebsd_miniconfig && gmake` is successful.

$ make help | grep -i bsd
  bsd_defconfig   - Select commands known to build on freebsd
$ grep -m1 -A1 bsd kconfig/Makefile
bsd_defconfig: $(obj)/conf $(KCONFIG_TOP)
	KCONFIG_ALLCONFIG=$(obj)/freebsd_miniconfig $< -n $(KCONFIG_TOP) > /dev/null

In theory you should be able to "make bsd_defconfig toybox".

> There are a number of toys (or config options) that are not currently
> enabled in freebsd_miniconfig, but do build, on my FreeBSD 14 laptop:

Several of those are in pending. I'm happy to add the ones that are NOT in
pending to the defconfig. Let's see, looks like...

$ for i in $(sed 's/^CONFIG_//' blah.txt | tr '[A-Z]' '[a-z]'); do \
  ls toys/*/$i.c; done 2>/dev/null | grep -v pending
toys/posix/dd.c
toys/posix/fold.c
toys/posix/tsort.c
toys/other/nbd_server.c
toys/other/shuf.c
toys/other/ts.c
toys/lsb/su.c

I appended those to the miniconfig then expanded the config and ran it through
my miniconfig.sh to put them in the right places.

In doing so it dropped out EGREP/FGREP as not affecting the resulting config.
Which is correct, those don't have their own menuconfig selection (no
discription on the bool), the symbols show up automatically when GREP is
selected (default y but selective visibility) and exist to give the help text
and similar something to attach to.

I should test that the standalone builds distinguish the three properly, I
_think_ so? But I haven't got a make test_fgrep or make test_egrep for the
aliases. I know they work fine builtin, but "multiple entries in the dispatch
table on a standalone build" is a funky corner case that I'm special-casing for
sh, and it distinguishes them by checking the command name out of the table, ala
this.which->name, and the singleinit stuff at the end of main.c just calls the
first entry in the table. So if grep has all three enabled for all three builds,
and the order doesn't change, it'll call the first one each time...

> A few toys are disabled but would be nice to have -- at least cp, mv,
> install, tar, uname.

Hmmm, most of those are enabled for macos. We should figure out why those builds
break and maybe fix them?

cp/mv/install are the same plumbing with different UI.

No idea why tar is unhappy? (Possibly the sparse or selinux stuff?)

Ah, uname.c also has arch and linux32 shoved in there, and linux32() is calling
personality(PER_LINUX32) which you probably don't have (either the function or
the macro name). I could stick an #ifdef clause in portability.h?

Also, if I _do_ stick a #define personality(x) ; in portability.h for freebsd,
then linux32 would build but be a NOP. This is not unique and is why "it builds
for freebsd" and "it does anything interesting" are two different things to test. :)

> I'd also be interested in the networking commands
> (e.g. ifconfig and route). I hope that I might be able to use some of
> these tasks as projects for Google Summer of Code or interns in the
> future.

Sure. Although I note that ifconfig is cheating mightily, as in it uses the
numbers behind the syscalls to categorize here:

      // Is this an SIOCSI entry?
      if ((off|0xff) == 0x89ff) {

Plus there are a couple of /proc/net things opened.

As for route, I have a TODO item to rewrite it to handle multiple routing
tables, which is a different API. (That's why it's still in pending.)

> I ran the tests but I guess they stop on the first failure, which is currently:
> ...
> chmod: chmod 'file' to 1644: Inappropriate file type or format
> FAIL: chmod +t dir file
> echo -ne '' | chmod +t dir file && ls -ld dir file | cut -d' ' -f 1 |
> cut -d. -f 1
> --- expected    2023-11-08 17:51:50.158224000 -0500
> +++ actual      2023-11-08 17:51:50.165796000 -0500
> @@ -1,2 +0,0 @@
> -drwxr-xr-t
> --rw-r--r-T
> gmake: *** [Makefile:78: tests] Error 1

>From the start of scripts/runtest.sh (I think it's in the faq page too):

# The following environment variables enable optional behavior in "testing":
#    DEBUG - Show every command run by test script.
#    VERBOSE - "all"    continue after failed test
#              "fail"   show diff and stop at first failed test
#              "nopass" don't show successful tests
#              "quiet"  don't show diff -u for failures
#              "spam"   show passing test command lines

And you can glue 'em together, "VERBOSE=allquietnopass make tests"

> Anyhow, I just wanted to see where things stand these days, and give an update.

Two commits just added.

Still dunno what to do about the "/usr/bin/env is cannon but /bin/bash is not"
weirdness, especially given that a lot of Linux systems started symlinking
/usr/bin to /bin some years ago... (Yeah, partially my fault, but still...)

Rob


More information about the Toybox mailing list