[Toybox] [PATCH] macOS: numerous fixes.

Rob Landley rob at landley.net
Fri Jun 7 20:17:48 PDT 2019



On 6/7/19 6:29 PM, enh via Toybox wrote:
> This patch adds a BSD version of xgetmountlist (for the path ==
> NULL case only), tested on macOS. It also papers over the differences
> between macOS' and Linux's xattr APIs. For once I think the macOS
> one is better. The imitation of mknodat I've had to write swings
> things back in Linux's favor though.
> 
> BSD calls f_frsize by the name f_iosize instead. (FWIW, it looks
> like this is meaningless on Linux and actually meaningful on macOS.)
> 
> I've added one #if to toys/ --- I'm calling pathconf in stat.c to
> work around the absence of f_namelen, and have left a TODO with an
> explanation. I'm not sure what the best fix is here, so punting.
> 
> No-one can agree what f_fsid is, even if they're all basically the
> same, so work around the `val` versus `__val` issue between macOS
> and Linux.
> 
> With this patch, it's now possible to build cp/mv/install and stat
> for macOS too. (Which completes the set of "toybox commands currently
> used on Linux as part of the AOSP build" if you ignore stuff that
> deals with processes, which I doubt we'll ever be able to support
> for lack of any API.)

I have a tab open with
https://svnweb.freebsd.org/base/head/lib/libprocstat/libprocstat.c?revision=341448&view=markup
which is the BSD library they use instead of reading /proc, and under the covers
it seems to be a sysctl() and then a whole lot of parsing of the binary
structure(s) it returns?

5	        if (procstat->type == PROCSTAT_SYSCTL) {
1786	                name[0] = CTL_KERN;
1787	                name[1] = KERN_PROC;
1788	                name[2] = env ? KERN_PROC_ENV : KERN_PROC_ARGS;
1789	                name[3] = kp->ki_pid;
1790	                len = nchr;
1791	                error = sysctl(name, nitems(name), av->buf, &len, NULL, 0);

It's doable, I just need to get a development environment set up and clear a
couple weeks of focus.

The way toys/*/ps.c is set up, the only function that would need to be replaced
is get_ps(). Unfortunately, that's about 300 lines of code (starting at line
700), and the new one can't cheat and go "the slot layout started life as the
order fields occur in /proc/$PID/stat so we get 2/3 of them for free with a for
(;;) loop reading long long and the units are what the filter/search/display
code expects..."

On the bright side, we don't have to populate _all_ the fields, at least not to
start. The code won't care if most of them stay zero.

(I need to break up ps.c so there aren't 5 commands and 1900 lines of code in a
single file. I should make a lib/ps.c, I just need to turn the TT.stuff into a
structure in lib/lib.h and do the surgery...

Lemme get toysh to a good checkin point first...

Rob



More information about the Toybox mailing list