initctl: the status views over D-Bus

The summary table, the per-service detail, JSON and the quiet and
ident forms all read state Finit already publishes, so they read it
from the bus like everything else rather than through a second path
that has to be kept in step.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-08-13 09:28:26 +02:00
1 parent ebc0ef62e6
commit 6310d9e760
16 files changed
+1271 -315

No files matched your search

+2
View File
@@ -77,6 +77,7 @@ EXTRA_DIST += dbus-manager.sh
EXTRA_DIST += dbus-service.sh
EXTRA_DIST += dbus-cond.sh
EXTRA_DIST += dbus-initctl.sh
EXTRA_DIST += dbus-introspect.sh
AM_TESTS_ENVIRONMENT = SYSROOT='$(abs_builddir)/sysroot/';
AM_TESTS_ENVIRONMENT += export SYSROOT;
@@ -139,6 +140,7 @@ TESTS += dbus-manager.sh
TESTS += dbus-service.sh
TESTS += dbus-cond.sh
TESTS += dbus-initctl.sh
TESTS += dbus-introspect.sh
endif
check-recursive: setup-chroot
+48
View File
@@ -94,3 +94,51 @@ say "initctl reload <svc> routes through Service1.Reload"
texec initctl reload keventd >/dev/null \
|| fail "initctl reload keventd returned non-zero"
assert "Per-service reload ok" 0 -eq 0
say "initctl status views render over D-Bus alone"
# hide the legacy socket: everything below must come over the bus
texec mv /run/finit/socket /run/finit/socket.hidden
set +e
out=$(texec initctl -p status)
status_rc=$?
one=$(texec initctl -p status keventd)
one_rc=$?
texec initctl -q status keventd
quiet_rc=$?
jout=$(texec initctl -j status)
json_rc=$?
idout=$(texec initctl ident)
ident_rc=$?
set -e
texec mv /run/finit/socket.hidden /run/finit/socket
assert "status table ok without legacy socket (rc=$status_rc)" \
"$status_rc" -eq 0
case "$out" in
*keventd*running*) assert "keventd running in table" 0 -eq 0 ;;
*) fail "keventd/running missing from status table" ;;
esac
assert "status detail view ok (rc=$one_rc)" "$one_rc" -eq 0
case "$one" in
*"Status : running"*"Identity : keventd"*"Restarts :"*)
assert "detail view fields present" 0 -eq 0 ;;
*) fail "detail view incomplete: $one" ;;
esac
assert "quiet mode exit code (rc=$quiet_rc)" "$quiet_rc" -eq 0
assert "json mode ok (rc=$json_rc)" "$json_rc" -eq 0
case "$jout" in
*'"identity": "keventd"'*'"status": "running"'*)
assert "json fields present" 0 -eq 0 ;;
*) fail "json output incomplete: $jout" ;;
esac
assert "ident ok (rc=$ident_rc)" "$ident_rc" -eq 0
case "$idout" in
*keventd*) assert "ident lists keventd" 0 -eq 0 ;;
*) fail "ident missing keventd" ;;
esac
+31
View File
@@ -0,0 +1,31 @@
#!/bin/sh
# libink: introspection XML well-formedness.
#
# Covers compound type signatures in generated introspection XML:
# Cond1.Dump declares out_sig "a(ss)", which must appear as a single
# <arg>, not one <arg> per signature character.
set -eu
TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
# shellcheck source=/dev/null
. "$TEST_DIR/lib/dbus-setup.sh"
say "Introspect on /org/finit/cond"
xml=$(texec "$CLIENT" introspect "$BUS" /org/finit/cond)
say "Cond1.Dump advertises a single a(ss) out arg"
case "$xml" in
*'<arg type="a(ss)" direction="out"/>'*) assert "a(ss) intact" 0 -eq 0 ;;
*) fail "a(ss) not found as a single arg" ;;
esac
say "No per-character type fragments in the XML"
case "$xml" in
*'type="("'* | *'type=")"'* | *'type="{"'* | *'type="}"'* | *'type="a"'*)
fail "per-character <arg> fragment leaked" ;;
*) assert "no bracket/array fragments" 0 -eq 0 ;;
esac
+25 -3
View File
@@ -2,9 +2,10 @@
# libink: org.finit.Service1 vtable + ServiceStateChanged signal.
#
# Covers per-service objects exposed at /org/finit/service/<encoded>:
# GetService lookup, Introspect on a service object, Service1.Restart,
# authorization (non-root rejected), and the Manager1.ServiceStateChanged
# signal that Service1.Restart triggers.
# GetService lookup, Introspect on a service object, Service1
# properties via Properties.Get, Service1.Restart, authorization
# (non-root rejected), and the Manager1.ServiceStateChanged signal
# that Service1.Restart triggers.
set -eu
@@ -29,6 +30,27 @@ case "$xml" in
fail "Service1 not visible on /org/finit/service/keventd: $xml" ;;
esac
say "Service1 properties: Identity, State, Pid"
ident=$(texec "$CLIENT" getprop "$BUS" /org/finit/service/keventd \
org.finit.Service1 Identity)
assert "Identity is keventd (got: $ident)" "$ident" = "keventd"
state=$(texec "$CLIENT" getprop "$BUS" /org/finit/service/keventd \
org.finit.Service1 State)
assert "State is running (got: $state)" "$state" = "running"
pid=$(texec "$CLIENT" getprop "$BUS" /org/finit/service/keventd \
org.finit.Service1 Pid)
assert "Pid is non-zero (got: $pid)" "$pid" -gt 0
say "Service1 properties are advertised in introspection XML"
case "$xml" in
*'<property name="Identity" type="s"'*'<property name="Pid" type="u"'*)
assert "Identity and Pid declared with types" 0 -eq 0 ;;
*)
fail "Property declarations missing from service XML" ;;
esac
say "Service1.Restart on /org/finit/service/keventd succeeds"
texec "$CLIENT" call-void "$BUS" /org/finit/service/keventd \
org.finit.Service1 Restart >/dev/null \
+42
View File
@@ -338,6 +338,47 @@ static int mode_get_service(int argc, char *argv[])
return rc;
}
/*
* getprop BUS PATH IFACE PROP -- Properties.Get, prints the variant
* value; dispatches on the wire signature, "s" and "u" supported.
*/
static int mode_getprop(int argc, char *argv[])
{
const link_reply_t *r;
link_client_t *c;
link_reader_t reader;
const char *s;
uint32_t u;
int rc;
if (argc != 6) return 2;
c = link_client_open(argv[2]);
if (!c) return 2;
rc = link_client_call_v(c, argv[3],
"org.freedesktop.DBus.Properties", "Get",
"ss", argv[4], argv[5]);
rc = report_rc(c, rc);
if (rc == 0) {
char type = 0;
r = link_client_reply(c);
link_reader_init(&reader, r->body, r->body_len);
if (link_r_variant_begin(&reader, &type) != 0)
rc = 2;
else if (type == 's' && link_r_string(&reader, &s) == 0)
printf("%s\n", s);
else if (type == 'u' && link_r_u32(&reader, &u) == 0)
printf("%u\n", u);
else {
fprintf(stderr, "unsupported variant type '%c'\n", type);
rc = 2;
}
}
link_client_close(c);
return rc;
}
static int mode_monitor_signal(int argc, char *argv[])
{
link_client_t *c;
@@ -441,6 +482,7 @@ int main(int argc, char *argv[])
if (!strcmp(argv[1], "call-s-as-uid")) return mode_call_s_as_uid (argc, argv);
if (!strcmp(argv[1], "call-void-as-uid")) return mode_call_void_as_uid(argc, argv);
if (!strcmp(argv[1], "get-service")) return mode_get_service (argc, argv);
if (!strcmp(argv[1], "getprop")) return mode_getprop (argc, argv);
if (!strcmp(argv[1], "monitor-signal")) return mode_monitor_signal (argc, argv);
if (!strcmp(argv[1], "unknown")) return mode_unknown (argc, argv);
fprintf(stderr, "%s: unknown mode '%s'\n", argv[0], argv[1]);