- C 62.4%
- Python 22.8%
- Shell 11.5%
- Meson 3.3%
|
capezotte
1d4d89bf9f
dinit-turnstile-session: change ready type
POSIX does not guarantee the shell will be able to handle file descriptors with more than one digit: "The largest possible value is implementation-defined; however, all implementations shall support at least 0 to 9, inclusive, for use by the application." (POSIX.1-2024, Shell Command Language, Section 2.7). mksh (since R53) and dash happily refuse to support fds >=10, and dinit seems to like using these for `pipevar`. Let's just use 9 and call it a day. Plus being sure we can close it is a nice bonus. |
||
|---|---|---|
| contrib/tools.orig | move policy_xml out of contrib | |
| init-samples | dinit-turnstile-session: change ready type | |
| pkg | make policy no longer optional; install dbcs-policy-xml | |
| pysrc | move policy_xml out of contrib | |
| socktools | --print-address for dbcs-socketbinder | |
| src | waitid oops, again | |
| subprojects | here's tree | |
| .gitignore | update samples | |
| meson.build | make policy no longer optional; install dbcs-policy-xml | |
| meson_options.txt | make policy no longer optional; install dbcs-policy-xml | |
| POLICY.md | move policy_xml out of contrib | |
| README.md | --print-address for dbcs-socketbinder | |
dbus-controller-script
A non-systemd controller for dbus-broker with scriptable hooks (last tested with v37).
A fork of dbus-controller-s6 that replaces its suggested policy for s6 with entrypoints for scripts.
dbus-controller-script is configured through the command line and files in its working directory.
Options
It expects to have a bound and listening socket as its stdin, which is given to the broker over the D-Bus protocol.
There are three options:
-3: write a newline to a preopened file descriptor 3 after sending the first batch of commands todbus-broker. This is compatible withs6's notification-fd anddinit'sready-notification = pipefd.-C: change working directory after startingdbus-broker(see Files below).-v: number representing logging verbosity. 0 unrecoverable failures; 1 major, but recoverable, errors (default); 2 minor errors and warnings; 3 informational messages on program state; 4 debug.
After the options, a command line is expected. It is spawned with file descriptor 3 pointing to the reading end of the controller's IPC endpoint. The most obvious option is dbus-broker --controller=3 --machineid=..., but if additional setup is needed, you can prepend utilities that change process state, or give the path to a script that ultimately execs the broker.
Files
Whenever a the controller receives a relevant D-Bus signal from the broker, it runs scripts in its working directory:
populate-services(executable)/services(static): An executable that provides a list of bus-activable names onstdout, one per line (first), or a static list of services in the same format. If neither of these files is absent, bus activation is disabled, and the next file is a no-op.service-start: wheneverdbus-controller-scriptgets an activation request for a dbus-namepopulate-servicestold it about, it spawns./service-start $name(one argument).service-export: whenever a request to add some "key=value" to the D-Bus activation environment comes, it spawns./service-export $key $value(two arguments). If this file is absent, such requests are ignored.populate-policy(executable)/policy(static): The representation of the policy that shall govern connections, message passing and name ownership. This file has an ad-hoc format described in POLICY.md. Similarly topopulate-servicesandservices,populate-policyis an executable, whilepolicyis a ready-made list. Only this file is mandatory.
These files are exec'd as-is; you can write them in any programming language, all it takes is a suitable shebang. They also inherit the controller's working directory, so using relative paths is predictable.
Note that the files are assumed to respond correctly to SIGTERM, and to have proper timeouts in place. Otherwise, the process table and other system resources may be exhausted.
Signals
dbus-controller-script accepts two signals to reload configuration, SIGHUP and SIGALRM. The former causes it to reload its service list, while the latter causes it to reload the policy.
To reload both items, send both signals, or use the D-Bus method call, busctl --system call org.freedesktop.DBus / org.freedesktop.DBus ReloadConfig.
Socket Tools
Socket preopening is usually a better pattern than programs binding sockets themselves. That's why the options for connecting to syslog and choosing socket path were removed. As a fallback, the original code for the options was factored out as separate tools:
dbcs-socketbinder path ...: binds a Unix domain socket atpath, enables listening on it and makes it the program's stdin. This can be used in the command line for the controller itself.dbcs-streamclient syslog-sock ...anddbcs-journalclient syslog-sock ...: establish aSOCK_STREAM/SOCK_DGRAM(respectively) connection at fd 7. This can be used in the command-line that spawnsdbus-broker. Seedocs/dbus-broker.rston the broker's repository on the differences between the logging formats.
They support an -@ option, meaning path will be found in the abstract namespace for Unix sockets instead of the filesystem. Additionally, dbcs-socketbinder takes a -a option (set up octal permissions for the socket it binds)
and a -p option (print address, like dbus-daemon --print-address, after binding).
Rosetta stone:
dbus-controller-* -d /path/to/dbus-sock dbus-broker=dbcs-socketbinder /path/to/dbus-sock dbus-controller-script -- dbus-broker ...dbus-controller-* -s=dbus-controller-script -- dbcs-journalclient /dev/log dbus-broker --log=7 ...dbus-controller-s6 -e ...= don't provide a./service-exportfile.
They are extremely bare-bones, and perform very little validation of their input. If your init system supports socket preopening, it is far better to rely on it than on these tools. Do not use dbcs-socketbinder -p to supply readiness notification for your init system; use dbus-controller-script -3.
Examples
See the init-samples folder.