3

InitWare Comes to macOS – A NetBSD User's Blog

 3 years ago
source link: https://anetbsduser.wordpress.com/2021/08/24/initware-comes-to-macos/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

InitWare Comes to macOS

When I incepted InitWare, my fork of systemd aiming — among other things — at portability, one of my goals was to support all the major BSD platforms. With InitWare now having ran on NetBSD, then FreeBSD, DragonFlyBSD, and finally OpenBSD, this left one major BSD operating system — macOS — for which support was wanting.

After picking up a second hand iMac, I spent the early afternoon getting InitWare to build on macOS. Before long, the service manager and journal started to work:

  • svcctl (systemctl equiv.) inspecting the state of the service manager
  • the manager object coming up and installing jobs
  • the journal viewer evlogctl (journalctl equiv.)

The process began with installing the build and runtime dependencies of InitWare with pkgsrc, the portable package manager that originated on NetBSD. Numerous platforms support pkgsrc. For the bigger platforms (macOS, NetBSD, Illumos, GNU/Linux) there’s binary packages available as well to relieve the burden of building the biggest packages from source. Being a NetBSD native, pkgsrc seemed the wisest choice of package manager for macOS.

The porting process itself was quite straightforward: InitWare has ran on four BSDs already, so bringing it to a fifth hardly required any real work; most of the heavy lifting was already done. 90% of the work was replacing number of minor GNU/Linux extensions to POSIX, used in the systemd source code, with the POSIX equivalents; functions like pipe2 and accept4, providing an atomic way to set close-on-exec() and non-blocking flags on their newly-created FDs, the uses of which in a single-threaded app like the InitWare manager only offer convenience over pipe and accept.

There are still some issues to deal with before this port is up to par with the other BSD ports.

The major issue involves Kernel Queues: the BSD event notification system. It provides the proc event filter, which InitWare uses to track processes as they fork and exit. The NOTE_TRACK flag allows you to attach the filter to a process and to all of its transitive children, inescapably. But this flag was broken on macOS quite a long time ago, and is now absent. It should still be possible to manually add each child process to the filter when a fork is detected – but this introduces a race condition, making the process tracking much less inescapable.

Other issues include finding a replacement for the Kernel Virtual Memory (or KVM) API which is used by InitWare on the free-software BSDs to get metadata about processes, like their UID, process title, and parent PID. This was abolished in macOS 10.5. There is no ProcFS either, as on Linux, which provides similar information – but I suspect the BSD-standard sysctl(3) interface of macOS has similar information available. A few other things need supporting, like retrieving the PID of a Unix stream socket peer with LOCAL_PEERPID. When these are out of the way, InitWare on macOS should be similarly powerful as on the other BSDs.


I realise that this is not a thing that has been much in want by the macOS community – after all, macOS already has launchd, the pioneer of the idea of generalising the inetd approach of ‘socket activation’ to other kinds of communications channels. Launchd even omits dependency specifications, with the manual noting that by registering sockets and other channels in advance, daemons can now launch in any order. Systemd (and in turn InitWare) are much more pragmatic in their provision of dependency specification — and much less beautiful for it.

Replacing launchd is obviously not a goal; it’s not remotely practical. But I do hope to get InitWare working well as an auxiliary service manager under launchd though. I plan to extend the existing pkgsrc-wip recipe for InitWare on NetBSD to support InitWare on macOS as well, which will allow anyone who wants to try InitWare on macOS to do so quite more easily – though InitWare as a whole remains alpha software for now.

Whether this port will be of use to anyone remains to be seen. But a fairly clear road forward exists to first-class support of macOS as an InitWare platform, and some of systemd’s power has made it to the world’s most popular Unix operating system.

Loading...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK