Commit Graph
100 Commits
Author SHA1 Message Date
Joachim Wiberg b87d235cf7 tmpfiles: add the % specifiers for path and argument
An entry with a % in the path was skipped, and files from
distributions have them:

    d /run/log/journal/%m 2755 root systemd-journal - -

Expand the specifiers that do not need the OS release or the
architecture: %b, %m, %H, %l, %v, the directories %t, %T, %V, %S, %C,
%L, %h, and the user ones %u, %U, %g, %G.  tmpfiles runs as root, so
the last ones are fixed.  An entry with any other specifier is still
skipped.

The argument of C, f, F, L, and w entries is expanded too, as in
tmpfiles.d(5).  A literal % in such an argument must from now on be
written %%.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:03:33 +01:00
Joachim Wiberg 83f4dceb1b tmpfiles: make a directory for v, q, and Q entries
Files from distributions use v, q, and Q for directories that should
be btrfs subvolumes when that is possible:

    v /var/lib/machines 0700 - - -

tmpfiles skipped them as unsupported, so the directory was missing.

On a file system without subvolumes tmpfiles.d(5) has them make a
plain directory.  Do that everywhere, read them as d.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:03:33 +01:00
Joachim Wiberg 7422a6fac7 doc: ChangeLog entry for the fgetval() crash fix
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:03:32 +01:00
Joachim Wiberg 4fcc7ba686 plugins: fix leak of unknown 'set' command in modules-load
An unknown 'set foo' line in modules-load.d leaks the string returned
by fgetval().  Free it before skipping the line.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
(cherry picked from commit b5d8c2b16b)
2026-11-20 18:03:32 +01:00
Joachim Wiberg b350ad0d94 helpers: fix fgetval() crash on empty value
getty crashes reading /etc/os-release when a key it looks for has no
value, e.g.:

    VERSION=

initctl crashes the same way reading .initrc, and so does the
modules-load plugin on a bare 'set' or 'set index=', which takes down
PID 1.

The loop skipping separators calls strchr(sep, str[0]), which matches
the NUL terminator at the end of the string.  strsep() then sets str to
NULL and the next iteration dereferences it.  A line with no separator
at all dereferences NULL right away.

Return NULL when there is no separator, and skip separators with
strspn() instead.

Reported-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
(cherry picked from commit f8c2927672)
2026-11-20 18:03:32 +01:00
Joachim Wiberg 74da582488 tmpfiles: set the owner before the mode
An entry that sets both setuid or setgid and another owner lost the
bit again:

    f /usr/libexec/helper 4755 app app

The mode was set first, and a change of owner drops setuid and setgid
from a file.  A second run put it back, the owner was right by then.

Change the owner first.  A mode that is not in the entry is put back
the same way.  Also, a mode that ~ masks down to 0 is now set, 0 was
taken for no mode.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:03:31 +01:00
Joachim Wiberg 777ecd77c8 tmpfiles: allow major or minor 0 in b and c entries
An entry for a device with a 0 in its number was skipped:

    c /dev/tty 0666 root tty - 5:0

parse_mm() took 0 to mean atoi() could not read the number.

Use atonum(), which tells the two apart.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:03:31 +01:00
Joachim Wiberg adf7080fca tmpfiles: set mode and owner for the entries that ignored them
Several types read the mode and owner of an entry and did nothing
with them.  An f entry was skipped when the file was there:

    f /var/log/app.log 0640 app adm

This left a file with another mode or owner as it was.  The owner of
p, b, and c entries was never set, and their mode was cut by the
umask.  C, z, and Z entries had neither applied.

Set them for all of these, Z for everything below the path.  Fifos
and device nodes are opened with O_PATH, so nothing is opened for
real.  A path that is not what the entry makes, like a directory
where a p entry wants a fifo, is left alone.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:03:30 +01:00
Joachim Wiberg ec67ecc805 tmpfiles: add the : and ~ prefixes for mode, user, and group
A mode with a prefix was not read as a number, so the entry was taken
to have no mode, and a user with one was looked up with the colon in
the name, which skipped the entry:

    d /var/lib/app :0750 :app :app

With : the mode, user, or group is only set on a path the entry
creates, an existing one keeps what it has.  With ~ the mode loses
read, write, or execute when no one has that on the existing path,
and setuid, setgid, and sticky when it is not a directory.

Mode and owner now go through perm_set() in tmpfiles, which knows the
entry created the path or not.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:37 +01:00
Joachim Wiberg a726aff30b tmpfiles: skip any entry with an unknown user
What an unknown user in an entry did depended on the type.  A d entry
was skipped, but this one made a file owned by root:

    f /run/frr/state 0640 frr frr

The user was looked up in each type on its own, and only d checked
the result.

Look it up once for the entry, and skip the entry when the user is
not known.  An unknown group leaves the group of the path as it is,
for a new path that is the group of root, as before.  Both are only
reported with --debug, Finit's own files have entries for services
that may not be installed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:36 +01:00
Joachim Wiberg f5e7946489 doc: how to run tmpfiles --clean, from cron
Finit only runs tmpfiles at boot, to create and remove.  The age of an
entry has no effect until something calls tmpfiles --clean, and the
documentation said there was no aging at all.

Describe how to call it from cron, with a service as the fallback on a
system without cron, and what cleaning leaves alone.  Update the
tmpfiles TODO to match.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:36 +01:00
Joachim Wiberg bc2f2ba4bb tmpfiles: age 0 cleans everything
An entry with the age 0 was read as having no age, so nothing in its
directory was ever cleaned:

    d /var/spool/work - - - 0

    tmpfiles --clean t.conf

In tmpfiles.d(5) age 0 means everything in the directory is removed
on each clean.  parse_age() returned 0 for both.

It now returns -1 for no age and for one it cannot read, and with
age 0 the timestamps are not looked at.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:36 +01:00
Joachim Wiberg 60cd11ab23 tmpfiles: keep what x and X entries name from being cleaned
The x and X entries were read and ignored, so a path that a package
had marked to be left alone was cleaned like the rest:

    d /var/tmp      - - - 30d
    x /var/tmp/keep

    tmpfiles --clean t.conf

This removed what was old in /var/tmp/keep.

Gather the x and X entries of all files in a pass before the cleaning,
they may come after the entry they apply to, or in another file.  x
keeps the path and what is in it, X the path alone.  A directory that
is not empty afterwards is no longer warned about.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:36 +01:00
Joachim Wiberg 9392f2082e tmpfiles: stay on one file system when cleaning
Cleaning the directory of an entry with an age went into whatever was
mounted below it:

    d /srv - - - 10d

    tmpfiles --clean t.conf

With a disk mounted on /srv/data this removed every file on it older
than ten days.

Give nftw() FTW_MOUNT, so it stays on the file system of the directory.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:35 +01:00
Joachim Wiberg 3c9500fc08 tmpfiles: run boot-only entries only at boot
A ! after the type marks an entry that is only safe to run at boot.
Finit's own files have them, like this one in x11.conf:

    D! /tmp/.X11-unix 1777 root root

tmpfiles ignored the ! and ran these entries on every call, so this
emptied the directory under a running X server:

    tmpfiles --remove

Only the character right after the type was looked at, and only for
a +.

Read all the modifiers after the type, in any order, and skip an
entry with ! unless the new --boot option is given.  Finit gives it
at boot, together with --remove.  Before this the r, R, and D entries
were never run at boot, so "r! /forcefsck" in legacy.conf left the
file in place.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:35 +01:00
Joachim Wiberg 4a11294f98 tmpfiles: skip an entry that is not supported, do not exit
tmpfiles exited at the first entry with a type it does not know, or
with a % specifier in the path:

    h /tmp/dir - - - - +i
    f /tmp/dir/after

    tmpfiles --create t.conf

This never created /tmp/dir/after.  At boot it meant that one such
line, in any tmpfiles.d file, stopped every entry after it, in that
file and in all the files sorted after it.  The message says skipping,
but errx() exits.

Warn and go on with the next entry.  With two passes, for --create
with --remove, only the second one warns.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:34 +01:00
Joachim Wiberg 9195d145d1 tmpfiles: remove before creating when asked to do both
With both --create and --remove each entry was removed and then
created before the next one was read.  An r entry took what an entry
above it had just created:

    f /tmp/file - - - - new
    r /tmp/file

    tmpfiles --create --remove t.conf

This left no /tmp/file.  The same goes for --clean.

Run all the files twice in that case, first to remove and clean, then
to create.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:34 +01:00
Joachim Wiberg 3a283d40b5 tmpfiles: free the glob result of r, R, w, z, and Z entries
Same leak as for e entries: the path list from glob() was never freed.
With the address sanitizer LeakSanitizer makes tmpfiles exit with an
error:

    tmpfiles --remove r.conf

Free the list in glob_do() and after the loops for w and z/Z.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:34 +01:00
Joachim Wiberg 674cf8a2ed doc: list what tmpfiles lacks compared to tmpfiles.d(5)
Ranked, with what Finit's own tmpfiles.d files and common packages
already rely on first.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:34 +01:00
Joachim Wiberg f8571aba1f tmpfiles: add the a and A entries, POSIX ACLs
The tpm2-tss package sets a default ACL on its keystore:

    d  /var/lib/tpm2-tss/system/keystore 2775 tss tss - -
    a+ /var/lib/tpm2-tss/system/keystore -    -   -   - default:group:tss:rwx

tmpfiles skipped the a+ line as unsupported, so what was created in
the keystore did not get the group access it relies on.

Add a and A, the latter recursive, with and without +.  With + the
entries are added to the ACL of the path, without it they replace it.
The ACL is written to the system.posix_acl_access and _default
extended attributes in the format the kernel uses, which saves a
dependency on libacl.  As with setfacl, the mask is made to cover the
named entries unless the entry sets one.

An ACL can have at most 32 entries.  A path with more is left as it
is, with a warning.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:02:33 +01:00
Joachim Wiberg 3bc7c83731 tmpfiles: skip the space before the argument of an entry
An entry written in aligned columns got the space after the age field
as part of its argument:

    L  /tmp/null  -  -  -  -    /dev/null

This made a link to "   /dev/null".  Only the first separator after
the age was dropped.  A lone "-" for no argument was also taken as is,
so an f entry with it made a file holding a dash.

Skip all the space before the argument, and read "-" as no argument.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 12:00:50 +01:00
Joachim Wiberg f95db7e6df tmpfiles: keep the owner of an existing path when none is given
An entry without a user or group, or with "-", made root the owner of
an existing directory or file:

    mkdir -p /tmp/t && chown daemon:daemon /tmp/t
    echo 'd /tmp/t' > t.conf
    tmpfiles --create t.conf
    stat -c %U:%G /tmp/t

This gave root:root.  A missing field was read as "root" when parsing
the entry, the same as if it had been written out.  tmpfiles.d(5)
only adjusts the owner when the entry gives one.

A missing user or group is now -1, and fdperm() looks at the two ids
separately, so "d /tmp/t - - sys" changes the group and keeps the
owner.  mksubsys() and the service directories used uid -1 to skip
the chown altogether, they now pass -1 for the group as well.

Issue #523

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 11:23:36 +01:00
Joachim Wiberg 94bdccd200 tmpfiles: keep the mode of an existing directory when none is given
A d entry without a mode reset an existing directory to 0755.  On
finix a bare "d /tmp" line took the sticky bit and the write
permission for others off the /tmp mount, so nobody but root could
create files there:

    mkdir -p /tmp/t && chmod 1777 /tmp/t
    echo 'd /tmp/t' > t.conf
    tmpfiles --create t.conf
    stat -c %a /tmp/t

This gave 755.  Commit 9bfbdc6b made the chmod of an existing
directory work, and it used the 0755 default for a new directory as
the mode to set.

The default is now only for creating the directory.  With no mode in
the entry, dirperm() leaves the mode alone.

Fixes #523

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 11:03:15 +01:00
Joachim Wiberg 73ebc7fb36 tmpfiles: free the glob result of an e entry
An e entry leaked the path list from glob().  tmpfiles exits right
after, so it only shows in a build with the address sanitizer, where
LeakSanitizer makes tmpfiles exit with an error:

    tmpfiles --create e.conf

Free the list when the entry is done.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 11:03:05 +01:00
Joachim Wiberg c94fd9c495 initctl: add the settings of a service to the JSON status
initctl -j status had the state of a service but little of how it is
set up.  A program reading it could not tell how the service is
stopped, what scripts it runs, or how it signals readiness.

Add the settings: stop, reload, notify, remain, scripts, directories,
cgroup-config, rlimits, log or tty, provides, conflicts, if, groups,
capabilities, pam, name, id, protected, and nowarn.  The restart
object also gets sec, respawn, and oncrash, and the state Finit keeps
for its own use goes in internal:

    "stop": {
      "signal": "SIGTERM",
      "timeout": 3,
      "scope": "pgroup"
    },
    "scripts": {
      "exec-stop-post": { "command": "/bin/true", "timeout": 7 }
    },

initctl reads the status over D-Bus first, so each setting is also a
property of org.finit.Service1.  The new test checks that the JSON is
the same over D-Bus as over the initctl socket.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 21:51:23 +01:00
Joachim Wiberg 9fa50746a7 initctl: add what was missing from the JSON status
initctl -j status is for other programs and should have all there is,
the plain view is the one kept short.  It was the other way around:
the restart counter and restart-max were only in the plain view, and
the restart delay of restart-max-sec was not in the JSON either.

Add a restart object:

    "restarts": 7,
    "restart": {
      "count": 4,
      "max": -1,
      "delay": 160,
      "limit": 300
    },

Also add manual and started, and give starts for all services, not
only those with manual-start.  The restarts total stays where it is.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:43 +01:00
Joachim Wiberg 308287923d initctl: show the restart delay of a service with restart-max-sec
With restart-max-sec the delay before the next restart varies, and
nothing showed what it was or how far it could grow.

Show both in initctl status, for a service that has the setting:

       Restarts : 7 (4/-1)
     Restart in : 160 sec (max 300)

Add the D-Bus properties RestartDelay and RestartDelayMax for it, so
the status is the same when initctl goes over D-Bus.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:43 +01:00
Joachim Wiberg 7f652770e3 test: list what to install to run the test suite
A new machine lacks more than the build dependencies.  Without the
uidmap package every test fails:

    unshare: failed to execute newuidmap: No such file or directory

List the packages for Debian, Ubuntu, and Linux Mint, and what each is
used for.  The build instructions asked for libite and libuEv v2.2.0,
configure wants v2.6.1 and v2.4.1.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:42 +01:00
Joachim Wiberg aae640b8f3 service: spell the restart_sec: option restart-sec:
restart_sec: was the only setting in snake_case.  Every other option
of the line-based format is in kebab-case, and so is the block format,
restart-sec = SEC.

Take restart-sec: and keep restart_sec: as an alias, so a .conf from
an older Finit loads as before:

    service restart-sec:10 foo -- Foo daemon

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:42 +01:00
Joachim Wiberg 62bd5f4892 service: add restart-max-sec, a limit for the restart back-off
The delay between restarts of a crashing service is fixed: two
seconds, then five, or restart-sec if that is longer.  A service that
should be retried quickly at first and then less and less often, e.g.
a modem dialer, cannot be set up.

Add restart-max-sec, in the block format and as the restart-max-sec:
token:

    service dialer {
        restart         = "always"
        restart-sec     = 10
        restart-max-sec = 300
        command         = "dialer"
    }

When set, the delay doubles for each restart, from restart-sec up to
the limit: 10, 20, 40, 80, 160, 300.  Without restart-sec the first
restart is at once, then after 2, 4, 8 seconds.  The delay follows the
restart counter, so it comes down again as the counter ages.  With
restart always the counter stops where the delay peaks.

Fixes #306

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:42 +01:00
Joachim Wiberg bba286036e service: save the configured restart delay when registering
The configured restart delay was saved at the first restart, when the
restart counter went from zero to one, and restored when a restart
succeeded.  The counter ages back to zero while the service runs.  If
it did so right after a restart and the service crashed again, the
back-off delay was saved over the configured one.  From then on the
first restart after a crash waited two or five seconds, until the next
reload.

Save it once, when the service is registered.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:41 +01:00
Joachim Wiberg 644279cd72 service: stop the restart counter of restart always from overflowing
The restart counter is a char, and with restart always nothing stops
it.  A service restarted more often than the counter ages wrapped it
after 127 restarts, 255 on Arm.  initctl status then showed a negative
count and the back-off fell back to two seconds.

Make the counter an int that stops at INT_MAX.  With restart always it
stops at 10, the default restart-max.  The back-off peaks at half of
that, and from 10 the counter ages back within the hour.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:41 +01:00
Joachim Wiberg 4e1b0d4fbe service: start restart always at two seconds between restarts
A crashing service with restart always waited five seconds before
every restart.  It should wait two seconds for the first five, like a
service with the default restart-max:

    service foo {
        restart = "always"
        command = "foo"
    }

The back-off starts after half of restart-max attempts.  For restart
always restart-max is -1, so half of it was zero and the back-off
began with the first restart.  Use the default restart-max instead.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-19 20:39:40 +01:00
Joachim Wiberg 631baab756 api: acknowledge reboot, halt, and poweroff
Finit carried out a reboot, halt, or poweroff requested over the
initctl socket, but replied with a NACK.  The command printed an
empty line and fell back to signalling PID 1.

The result was never set from the action taken.  Return what
shutdown_now() returns.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 11:00:49 +01:00
Joachim Wiberg 20c422af69 shutdown: add time argument, wall message, and cancel
shutdown ignored everything after its options, so a delayed shutdown
went down right away:

    shutdown -r +10 "Upgrading, back in five"

Take a time, now, +MIN, or the next HH:MM, and an optional message.
Finit keeps the countdown, so it survives logging out:

  - warns logged-in users at 60, 30, 15 and 10 minutes left, then
    every minute from five, and on the console
  - writes the message to /etc/nologin from five minutes before,
    leaving one already in place alone
  - shutdown -c cancels, and a new shutdown TIME replaces it

Without a time, or with now and no message, shutdown acts right away
as before.  An immediate reboot, halt, or power-off, also over D-Bus,
cancels a scheduled one.  The warnings are written by a child, reading
utmp and closing a serial tty can block.

Fixes #149

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 11:00:49 +01:00
Joachim Wiberg d51f521bf8 service: add stop-scope, which processes a stop applies to
When the main process of a service exits, Finit sends SIGKILL to its
process group.  That killed the action script of avahi-autoipd, which
it runs on SIGTERM to deconfigure the interface, before it was done.

Add stop-scope, in the block format and as the stop-scope: token:

    service avahi-autoipd {
        stop-scope = "process"
        command    = "avahi-autoipd eth0"
    }

  - pgroup: the stop signal to the main process, SIGKILL to its
    process group when it exits, as before and the default
  - process: only the main process
  - cgroup: the stop signal to all of the cgroup, SIGKILL to the rest
  - mixed: the stop signal to the main process, SIGKILL to the rest of
    the cgroup, like systemd's KillMode=mixed

SIGKILL to a cgroup uses cgroup.kill when the kernel has it.  Without
a cgroup, cgroup and mixed fall back to the process group.  Services
in the same .conf file share a cgroup, Finit warns when one of them
uses a cgroup scope.

Fixes #413

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 11:00:48 +01:00
Joachim Wiberg 35c313c2fa service: keep a stop of a forking service waiting for its PID file
Stopping a forking service after its start script had exited, but
before the daemon had written its PID file, did not hold.  When the
PID file showed up, the service was reported running again and the
daemon was left alone:

    initctl stop ext

service_forked() cleared any block on the service, the user's stop
included.

Keep a user stop, and let the state machine stop the late daemon of
a service no longer enabled.  The service is briefly RUNNING on its
way to STOPPING, so service/NAME/running blinks on and off.

Follow-up to #452

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 07:49:50 +01:00
Joachim Wiberg a1706e8ebd pidfile: don't let a stopped service claim a PID file
A stopped service with a daemon-owned PID file came back as running
when another process wrote that file, e.g., a container started by
hand:

    sudo podman start dash

turned container:dash from stopped to running in initctl, with the
podman PID adopted, moved to the service's cgroup, and its conditions
set.  The same happened to a service waiting for its conditions.

The plugin acted on any new or changed PID file, only skipping
services stopping or running scripts, and service_forked() then
cleared the stop.

Only let a service that is starting or running claim its PID file.

Fixes #452

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 06:44:45 +01:00
Joachim Wiberg a162551896 service: bind the systemd notify socket before fork
A notify:systemd service that calls sd_notify() early could lose its
READY=1 and never become ready.  Seen with udevd in an initramfs.

The socket address contained the PID of the service, so it was bound
in the parent after fork(), racing the service.

Let the kernel pick a unique abstract address instead, bound before
fork(), and pass it in NOTIFY_SOCKET.

Fixes #505

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 06:21:26 +01:00
Joachim Wiberg 14fd315f38 keventd: touch the PID file after SIGHUP
After a SIGHUP, from initctl reload or a changed service, Finit waits
for a pid-notify daemon to recreate or touch its PID file to reassert
readiness.  keventd only reloaded its rules, so with a daemon-owned
PID file it never did.

Touch it with pidfile() after reloading the rules, once keventd has
created it.  With -c that is after the coldplug queue has drained.

Fixes #503

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 06:21:26 +01:00
Joachim Wiberg bf42811a13 service: drop a service's group when the configuration drops it
Changing a service from @alice:wheel to @alice, or removing group from
a block, and reloading kept the service running as group wheel, also
after a restart.

The group is only set when the configuration has one, and on reload
the service is updated in place, so the old one stayed.

Clear it before parsing, like a new service gets it.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 06:21:25 +01:00
Joachim Wiberg de73b06415 service: lift the limit of four supplementary groups
A service listing more than four supplementary groups, in extra-groups
or as @user:group,sup1,sup2,..., got only the first four:

    too many supplementary groups, max 4

The names were stored in a fixed array of four.  It was also only
reset when the new configuration listed groups, so groups dropped from
a service lingered until reboot.

Store the list as one string, split when the service starts, and set
it on every (re)registration.  A list longer than 511 characters drops
the name it cuts off, which may otherwise match another group.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-17 06:21:24 +01:00
Joachim Wiberg 8451c4087a Merge pull request #522 from firasuke/master
doc: list libcap as a dependency
2026-11-14 12:14:04 +01:00
Joachim Wiberg f15e95d1cc service: don't take a command named like an option for one
A run/task/service whose command starts like an option without a ':'
lost its command, e.g. the example in finit.conf(5):

    run [2345] @joe:users logger "Hello world"

was registered as the log option, running "Hello world".  Same for
pidof, pidproxy, cgroupfs-mount, and in block format too.

The option parser matches with MATCH_CMD(), a prefix match, also for
the options with no trailing ':' to end the prefix: log, pid, cgroup,
respawn, nowarn, and the rest.

Match these against the whole token, allowing only the separator that
starts a value: "log:", "pid:", "cgroup." and "cgroup:".

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-13 16:00:25 +01:00
Joachim Wiberg 34a0a4b1ff conf: pass -- in a block command to the program
A command that takes -- as an argument lost it, and everything after
it, to the description:

    service name {
        command     = "cmd -- arg"
        description = "a cmd"
    }

ran `cmd` with description `arg`.

The block translator builds a legacy one-liner, appending the
description as "-- text", and service_register() splits that line at
the first "-- ", here the one in the command.

Split the description off only for legacy one-liners.  Blocks now hand
it to the new service_register_desc() as an argument.

Fixes #512

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-13 15:56:30 +01:00
Joachim Wiberg 297d2de1da Merge pull request #511 from zhangxiaohui1/fix/remain-task-control
service: preserve explicit stop for remain tasks
2026-11-12 21:06:47 +01:00
Joachim Wiberg 3acf1cb7b1 Merge pull request #517 from vazub/hwdb-parse-fix
keventd: fix hwdb lookups that never match
2026-11-12 19:25:38 +01:00
Joachim Wiberg eb9fb83011 Merge pull request #516 from vazub/symlink-fix
keventd: fix dangling and misnamed /dev/input/by-id links
2026-11-12 19:24:02 +01:00
Joachim Wiberg b6f0d5314b Merge pull request #521 from firasuke/firasuke-patch-1
Add conditional include for sm.h based on AUTO_RELOAD
2026-11-12 19:22:53 +01:00
Joachim Wiberg 59a2f69345 Merge pull request #515 from augustebaum/patch-1
docs: Fix nested bulleted list
2026-11-09 17:14:29 +01:00
Joachim Wiberg a220e0fa9b Merge pull request #514 from vazub/static-fix
Fix static build dropping all built-in plugins
2026-10-27 12:24:28 +01:00
Joachim Wiberg 096e6337c5 Merge pull request #513 from vazub/keventd-input
keventd: fix ENV{} match on unset properties
2026-10-24 12:33:46 +02:00
Joachim Wiberg 530d6703f1 Merge pull request #509 from anees-r3hman/umount-rc
mount: report unmount failures
2026-10-12 09:38:08 +02:00
Joachim Wiberg cec76f18a3 doc: ChangeLog entry for the lost reload fix
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-09-27 18:56:03 +02:00
Joachim Wiberg ee6d4a1dae service: keep a pending reload across a second conf reload
A service whose condition goes into flux during a reload is paused
with its reload still pending.  If another reload was requested in
the meantime, re-parsing its unchanged .conf file cleared the pending
mark, so the service was resumed without ever being reloaded.  Seen
with sshd <pid/syslogd> on Infix, where a configuration change that
touched both landed as two reloads in a row and sshd kept its old
listen addresses.

The mark is only ever cleared once the change has been applied, so a
mark that is still set when the file is parsed again means exactly
that: not applied yet.  Leave it alone.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-09-27 18:41:05 +02:00
Joachim Wiberg 0548485be1 doc: update ChangeLog for 5.0
Covers the longer user and group names, the tmpfiles mode and owner
work, the shutdown remount order, and the stop/reload script timeout.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-09-27 18:00:13 +02:00
Joachim Wiberg 1b10c3746e Merge pull request #508 from anees-r3hman/avoid-fstab-on-root-remount
sig: avoid reading fstab during shutdown
2026-09-27 17:58:33 +02:00
Joachim Wiberg 24911ebbc2 Merge pull request #507 from anees-r3hman/master
svc: allow longer user and group names
2026-09-27 17:42:11 +02:00
Joachim Wiberg 88a9e6575b tmpfiles: apply mode and owner of e and f/F entries through an fd
Same treatment as d/D got: e went through fisdir() and a path based
chmod/chown, f/F did the chmod/chown by path after closing the file.
Both now work on the open fd, so the mode and owner end up on the
directory or file that was just checked or written.  f/F use open(2)
directly, which lets a plain f rely on O_EXCL for create-if-missing
instead of the earlier stat().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
(cherry picked from commit 75739fbeef)
2026-09-27 17:30:16 +02:00
Joachim Wiberg 417abf9000 Merge pull request #500 from finit-project/pam 2026-09-23 17:52:38 +02:00
Joachim Wiberg 61b0e0f3e6 Fix #420: run services inside a PAM session
Apply a PAM session to run/task/sysv/services Finit starts, pam_limits
above all, so a service running as a given user picks up that user's
limits the way a login does.

Add a new `pam` setting for the new block format (only), like the
per-service directories, naming a file in /etc/pam.d:

    service weston {
        user    = "weston"
        pam     = "weston-autologin"
        command = "/usr/bin/weston --continue-without-input"
    }

pam_close_session() has to be called by a process still holding the
handle, and the handle does not survive exec().  Hence the keeper: it
holds the handle, drops to the service's credentials, and waits for a
parent-death signal before closing the session.  Same shape as
systemd's (sd-pam), for the same reason, and one per fork, so the
script hooks open and close their own.

The keeper closes the descriptors it inherited from Finit and only
those.  Closing everything would also take out what pam_open_session()
opened for itself, a keyring fd or a lock file, and leave the modules
to close a session with those pulled out from under them.  Closing
nothing, as (sd-pam) does, would leave it holding the write end of the
notify pipe for the service's whole lifetime and starve notify = "s6"
services of their ready signal.  So the fds open before pam_start()
are snapshotted and exactly those are closed, while the ones PAM opens
after are marked close-on-exec so the daemon does not inherit them
either.

A refused value, a denied account stack, an uninstalled pam.d file,
and a build without PAM support all keep the service from starting
rather than running it with the stacks skipped: one that quietly loses
pam_limits and its private /tmp, with nothing said.  Capabilities a
module like pam_cap.so granted are merged into the IAB Finit applies
instead of being replaced by it, which only helps a service that also
sets capabilities, the other arm being a plain setuid() with nothing
left to restore once permitted is empty.

The test sysroot gains pam_permit.so, pam_deny.so and pam_limits.so,
which ldd cannot see, libpam dlopen()s them, and the test skips when
the host has none to stage.  The negative cases pin the exit status
rather than only asserting crashed, which serv reports for any early
exit, so a bad command or an unwritable pidfile cannot pass for a
rejected session.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-09-23 16:30:14 +02:00
Joachim Wiberg bad7c5c99a .github: unwrap ChangeLog paragraphs in release notes
The ChangeLog is hard-wrapped at 72 columns, which the GitHub releases
page renders verbatim as a ragged right edge.  Join the continuation
lines of each paragraph and list item, as already done in Infix, and
let the browser do the wrapping.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-30 10:12:29 +02:00
Joachim Wiberg 4c16190831 build: drop md5 and sha256 files from releases
GitHub now shows a sha256 digest for every uploaded release asset, so
the sidecar hash files only clutter the asset list.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-30 10:12:29 +02:00
Joachim Wiberg a274677f05 configure: keep the replacement libsystemd opt-in
Building it by default installs our libsystemd.so.0 in $libdir.  Where
the real one is already present, and contrib/debian/build.sh configures
--prefix=/usr --exec-prefix= on a Debian host, ours outranks it in the
loader cache, and every program linking libsystemd loses
sd_journal_stream_fd and the LIBSYSTEMD_209 symbol versions.  The test
sysroot ran into exactly that, dbus-daemon exited 127 on every restart.

Restore the default to no.  sulogin and watchdogd stay on, they only add
binaries.  distcheck asks for the library so it stays covered.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 15:21:29 +02:00
Joachim Wiberg f51aee1ec5 test: keep the replacement libsystemd out of the sysroot
dbus-broker fails, the bus never comes up:

    Service dbus[19] died (exit status: 127), restarting

The sysroot stages dbus-daemon from the host, which links the real
libsystemd, and since v5.0 builds ours by default the install puts a
second libsystemd.so.0 in the sysroot.  It wins the ld.so cache, and
dbus-daemon finds neither sd_journal_stream_fd nor the LIBSYSTEMD_209
symbol versions in it.

Uninstall the library from the sysroot after the install.  The test serv
compiles sd-daemon.c in, so nothing there needs it.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 14:28:59 +02:00
Joachim Wiberg cdf2337346 configure: build sulogin, watchdogd, and libsystemd by default
v5.0 ships keventd and the D-Bus support enabled out of the box, but the
remaining bundled pieces stayed opt-in, and the help text for two of them
already claimed otherwise.

Default all three to yes; --without-sulogin, --without-watchdog, and
--without-libsystemd opt out.  The distcheck and CI configure lines drop
the flags they no longer need, so CI exercises the defaults.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 13:54:19 +02:00
Joachim Wiberg 847f4db974 dbus: install the bus policy in $datadir/dbus-1/system.d
make distcheck fails in install:

    /usr/bin/install: cannot create regular file '/etc/dbus-1/system.d/org.finit.conf': Permission denied

The policy was installed to $sysconfdir/dbus-1/system.d.  distcheck only
overrides the prefix, so the file escaped its sandbox and aimed for the
real /etc.

Install it where dbus looks for package owned policy, leaving
/etc/dbus-1/system.d to the admin.  The test bus config reads it
relative to itself.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 13:54:14 +02:00
Joachim Wiberg 969f9a112c test: locate the fuzz sweep in the build tree
fuzz-msg-parse.sh looked for its driver next to the script, which only
holds when srcdir and builddir are the same.  Every VPATH build skipped
the sweep, claiming D-Bus was off:

    SKIP: fuzz-msg-parse.sh

distcheck, and with it the release job, is a VPATH build.  Use
top_builddir, which the test environment already exports.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 13:54:13 +02:00
Joachim Wiberg 2b812101be test: run keventd from the configured libexec path
make distcheck fails in dbus-device:

    sh: /libexec/finit/keventd: not found

distcheck configures with --prefix=$(distdir)/_inst, so the bundled
helpers install below that prefix, not in /libexec/finit, which the test
had hard coded.

Export the configured pkglibexecdir as FINIT_EXECPATH in test.env and
run keventd from there, the same path finit itself is built with.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 13:54:06 +02:00
Joachim Wiberg 7644874b42 Update ChangeLog and bump version for v5.0-rc1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 09:35:11 +02:00
Joachim Wiberg c512d57df4 doc: describe the udev rules keventd actually implements
The engine covers most of the udev grammar but not all of it, and the
gaps are invisible until a rule silently does nothing.  Write down what
is implemented and where it parts ways with udev(7), rather than
leaving people to infer it from a ruleset that happens to work.  The
man page gets the directory precedence and a pointer to udev(7) and
the User's Guide, which hold the details.

Rename the menu entry to Device Manager while here, matching how the
watchdog daemon is listed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 09:27:26 +02:00
Joachim Wiberg 59945b87f7 keventd: load udev rules in udev's order, with masking
The rules directories were read one after the other, each sorted on
its own.  udev instead sorts all files from all directories together
and lets a file mask one of the same name in a lower priority
directory.  The difference broke both standard override idioms
without a sound: copying a rules file to /etc/udev/rules.d/ to edit
it left the original running too, and symlinking a name to /dev/null
disabled nothing.

Collect everything with glob(), drop entries shadowed by a later
directory, and sort the survivors by filename, same as udev and the
tmpfiles.d handling in Finit itself.  The -r directory sits above
/etc/ so a test ruleset can override anything shipped.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-29 09:26:18 +02:00
Joachim Wiberg d23a9b8a16 Merge pull request #499 from aanderse/docs
docs: cleanup some development work
2026-08-29 08:05:54 +02:00
Joachim Wiberg e5040385f5 test: fix flaky crashing.sh
Two races, both around the post:script Finit runs when it gives up on a
service.

Finit marks the service crashed before it forks post:script, so the file
the test greps for lands a moment later.  Waiting for the state is not
enough.

slay then takes the PID from initctl status, and service_post_script()
sets svc->pid to the script's PID, so once Finit has given up the PID
reported for the service is the post:script.  Killing that takes out the
script instead of the service and the file never arrives at all.  The
guard for this was already there, with a comment describing it, but
inside the loop that waits for a PID to appear, so it only covered the
case where there was none.  A PID that was already there went straight
to kill -9.  Hence the gcc leg killing once more at lap 13, after Finit
had stopped restarting, where clang stopped at 12.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-22 10:25:28 +02:00
Joachim Wiberg e9efec8694 Merge pull request #501 from aanderse/libsystemd
libsystemd: guard sd-daemon.h with extern C for c++ consumers
2026-08-22 07:51:27 +02:00
Joachim Wiberg 48e85efb88 Merge pull request #491 from finit-project/devman
Finit 5: udev/eudev replacement

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-18 10:37:14 +02:00
Joachim Wiberg e8391864d7 conf: read /run/finit/system before /lib/finit/system
Stanzas in /lib/finit/system cannot use if:keventd, or any other
built-in service: if: is evaluated at parse time, and the generated
.conf files for built-ins were read after the system directory, so the
referenced service did not exist yet and the stanza was dropped.

The late position was deliberate: it kept bundled services from starting
before udev (5d703fd3).  The motivating case was dbus, which has since
moved to a build-time 20-dbus.conf (2e0b1d6f), and the built-ins that
remain want the early slot: watchdogd should start as soon as possible,
keventd is the device manager, and runparts is gated on int/bootstrap so
its position never mattered.

Reading /run/finit/system first also puts the override chain in its
natural order: built-in/generated defaults, then bundled (read-only)
system files in /lib, then the administrator (override) .conf file in
/etc/finit.d, always read last.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-17 19:04:52 +02:00
Joachim Wiberg 2a2f7cda63 Merge pull request #496 from FixeQD/master
switch-root: return real errors instead of false success

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 23:41:08 +02:00
Joachim Wiberg 1a2cc950f0 man: sync keventd(8) with the daemon
Half the daemon was missing: -p, -r, -S, -t from SYNOPSIS and
OPTIONS, class/ and driver/ conditions, SIGHUP rules reload, the
rules engine and its directories, /run/udev/data, and the D-Bus
socket in FILES.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:45 +02:00
Joachim Wiberg 7eb32bc543 keventd: one condition emitter, one file reader, one clock
Three copies of read-first-line-from-a-file (sysfs_read_file, a
static sysfs_read, fgetline), two condition emitters symlinking the
same reconf marker (cond_emit, sys_cond), two seqnum-stable loops,
and five hand-rolled logit() prototypes, none with a printf
attribute, so no format string was ever checked.

Keep one of each: cond_emit() is exported and mkpaths its parents,
which also retires init_dev_condition_dir() and the sys/ directory
priming loop; logit() moves to keventd.h with the format attribute;
the stability test becomes seqnum_stable(), shared by the coldplug
gate and settle; kev_now_ms() serves dbus.c too.  rule_ctx_free()
and kev_seq_baseline() had one caller each in their own files, now
static.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:45 +02:00
Joachim Wiberg 558c0f8c3b dbus: notify externals when reconfiguration completes
initctl reload freezes conditions to the old generation and each
owner re-asserts.  Finit's own providers do this in-process; an
external provider whose conditions are generation files, rather than
the oneshot symlinks keventd uses, has no way to know the moment.
Emit Manager1.ConfigReloaded when reconfiguration completes.

keventd needs no subscriber: its conditions are symlinks to the
reconf marker itself, so they read the current generation by
construction and never flux, which the device bus test now pins
down.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:44 +02:00
Joachim Wiberg 230c65a080 test: cover org.finit.Device1 end to end
Introspection, queue-state properties, immediate and bus-first
settle, Info by devpath, Trigger(add, net) observed via the
DeviceProcessed signal, and RulesReload -- driven by dummy interface
hotplug like keventd.sh.  New call-ss and call-u client modes, and
getprop learns the b and t variants.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:44 +02:00
Joachim Wiberg 292e87c0d1 keventd: serve org.finit.Device1 on /run/keventd/bus
The udev parity gaps that were blocked on IPC -- settle, trigger,
info, queue introspection, runtime rule reload -- become bus methods.
keventd serves its own socket the way Finit serves /run/finit/bus:
brokerless, libink, one socket per daemon, no forwarding between the
two.

  Settle(u) -> b      parked until the queue drains or the timeout
                      passes; true when settled
  Trigger(s, s)       replay events, action + subsystem glob
  Info(s) -> a{ss}    /run/udev/data properties for a devpath
  RulesReload() -> u  re-read rules dirs, returns rule count
  QueueEmpty (b), SeqnumProcessed (t) properties
  DeviceProcessed (ss) signal after each fully handled event

The queue state is the highest kernel seqnum keventd has handled,
baselined at startup, against /sys/kernel/uevent_seqnum.  keventd -S
now asks the running daemon first and falls back to seqnum polling.
In passive mode Trigger and RulesReload refuse.  Adds
link_call_connection() for the park bookkeeping.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:43 +02:00
Joachim Wiberg 6e60b8183a keventd: read udev database records by devpath
udevdb_read_parent() contained the general capability, keyed from
sysfs when no uevent is in hand.  Split it out as
udevdb_read_devpath() for the D-Bus Info method; parent lookup
becomes a wrapper.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:43 +02:00
Joachim Wiberg 289c1e0de6 keventd: generalize coldplug into a filtered trigger
coldplug_trigger(action, subsystem-glob) replays events for a subset
of devices, the D-Bus Trigger method needs both knobs; coldplug() is
now the ("add", NULL) case.  nftw() has no user cookie, so the
parameters ride in file statics.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:42 +02:00
Joachim Wiberg 1bb7d508a4 libink: let a handler park its call and reply later
The park machinery was welded to broker uid resolution; a handler
that cannot answer yet, like a device-settle call waiting for the
event queue to drain, had no way to defer.  link_call_park() holds
the request, link_call_resume() re-runs the handler with
link_call_resumed() reading true, and the expire sweep remains the
backstop for a resume that never comes.

Resume also no longer drops a local caller's kernel group set in the
privileged re-check: group source now keys on broker-ness.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:42 +02:00
Joachim Wiberg 2b861ea0af libink: 64-bit integer marshalling
Device seqnums are 64-bit; the writer and reader stopped at u32.
Adds t/x/d to the skip path so a{sv} consumers tolerate them.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:42 +02:00
Joachim Wiberg a814e85356 doc: complete and cross-link the D-Bus documentation
dbus.md was orphaned: not in dist_docs_DATA, not linked from the
user guide.  Wire it into the doc dist and link it from the index
features list, features.md, initctl.md, and plugins.md, where the
dbus.so plugin entry now disambiguates the external system bus from
the built-in org.finit API.

Document the 64-peer cap, the supported AddMatch keys, the busconfig
policy file, the legacy-parity edge semantics with the deliberate
SetRunlevel InvalidArgs divergence, the reload-signal behavior of
Service1.Reload, and the reboot family timeout.  Refresh the stale
initctl.md usage paste, add monitor and the D-Bus transport to
initctl(8), add /run/finit/bus to the filesystem layout, and flatten
the ChangeLog D-Bus entry to house style.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:41 +02:00
Joachim Wiberg 39d21ca0bd .github: build leg without D-Bus
The D-Bus support is default-enabled, so the HAVE_DBUS paths only
bit-rot silently without this: the leg caught initctl failing to
build with --disable-dbus on its first local run.  Also asserts the
binaries carry no bus references and smoke-runs one non-dbus test.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:41 +02:00
Joachim Wiberg 480f9c6a9d build: initctl loses AM_CPPFLAGS without D-Bus
initctl_CPPFLAGS is only assigned under the DBUS conditional, but an
automake per-target variable exists even when its conditional is
false, so a --disable-dbus build dropped AM_CPPFLAGS entirely:

    util.c:319:16: error: invalid use of undefined type 'struct FTW'

Assign the base flags unconditionally and append under DBUS.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:40 +02:00
Joachim Wiberg 8f1cd35f1c test: exercise _HH object-path encoding with a name:id service
The path encoding in libink/path.c was untested for identities with
separators; dbus-service.sh only used the bare keventd identity.
Declare a dhcp-client:eth1 service and verify the escaped path, that
the object introspects, and that Identity round-trips.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:40 +02:00
Joachim Wiberg b743d15e35 libink: declare signals in introspection XML
All three org.finit signals were invisible to generated proxies, and
org.freedesktop.DBus was missing from the standard interfaces even
though Hello, AddMatch, and RemoveMatch are answered.

Add a link_signal_t table to the vtable, emitted like methods and
properties, declare the Manager1 and Cond1 signals, and complete the
static XML with PropertiesChanged and org.freedesktop.DBus.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:39 +02:00
Joachim Wiberg 9d4cc8e933 service: one owner for user-requested start/stop/restart
The D-Bus methods carried byte-for-byte copies of api.c's static
start/stop/restart helpers.  Promote them to service.c alongside
service_reload(), which already serves both callers, and reduce both
sides to svc_parse_jobstr-style adapters.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:39 +02:00
Joachim Wiberg 3efa9d6f41 test: cover Manager1 edge semantics against the legacy API
Regression tests for the recent handler fixes: bogus SetRunlevel is
InvalidArgs, Signal on a stopped service is Failed, and the reboot
family declares the timeout argument.  Reboot cannot be invoked
without taking down the sandbox, so the latter is asserted via
introspection.  New call-u and call-su modes in dbus-auth-client.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:39 +02:00
Joachim Wiberg 62b55d5b43 dbus: honor the shutdown timeout in the reboot family
initctl -t N reboot arms an emergency bypass timer over the legacy
socket, but the bus methods took no argument, so the timeout was
silently dropped whenever D-Bus was up.

Reboot, Halt, and Poweroff now take a timeout in seconds, 0 for
none, armed via the same shutdown_bypass() the legacy path uses.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:38 +02:00
Joachim Wiberg 8b61aaea1a dbus: report action and condition failures instead of empty success
Service1 Start/Stop/Restart discarded the action return value, their
Manager1 twins map it to org.finit.Error.Failed.  Cond1 Set/Clear
replied success even when the condition symlink operation failed,
where legacy initctl exits 73.  Verify the resulting condition state
with cond_get() rather than the noupdate return values, which report
no-change, not failure, and would reject an idempotent re-set.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:38 +02:00
Joachim Wiberg 2af83ea632 dbus: signalling a stopped service is an error
Manager1.Signal silently skipped stopped services, so the same
command gave different exit codes depending on transport: the legacy
INIT_CMD_SIGNAL path fails when the service is not running.  Mirror
the legacy behavior.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:37 +02:00
Joachim Wiberg b53c7e6879 dbus: mirror legacy runlevel edge cases in Manager1.SetRunlevel
The bus method called sm_runlevel() unconditionally.  In runlevel 0
and 6 that aborts an in-flight shutdown, which INIT_CMD_RUNLVL
refuses with a warning, and during bootstrap it switches immediately
where the legacy path defers via cfglevel to the end of runlevel S.

Port both.  A bad runlevel argument still returns InvalidArgs, where
the legacy protocol acks silently: a typed interface rejects garbage.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:37 +02:00
Joachim Wiberg 8114508bbb dbus: refuse Manager1.Suspend in bootstrap and shutdown
The legacy INIT_CMD_SUSPEND is refused in runlevel S, 0, and 6, the
bus method suspended unconditionally, even mid-shutdown.  Add the
same guard, replying WrongRunlevel like the reboot family.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:36 +02:00
Joachim Wiberg 8138b402a0 test: don't slay a service Finit has given up on
Once it gives up it forks the post:script and reports that PID as the
service's, so a slay still waiting for the service to come back killed
the script instead, and crashing.sh lost the /tmp/post it checks for.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 22:03:36 +02:00