mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d38c333e04 | ||
|
|
095f6b645c | ||
|
|
b4d10cbade | ||
|
|
5d703fd39e | ||
|
|
eaaf8d862e | ||
|
|
2468f11cd8 | ||
|
|
f8a6a119ac | ||
|
|
1889b88aab | ||
|
|
0d70023bfe | ||
|
|
41648a073b | ||
|
|
33cee0ba5f | ||
|
|
2235fb8352 | ||
|
|
eb9e94935e | ||
|
|
fb230f2137 | ||
|
|
6aa48a8b32 | ||
|
|
5b9cebbfd3 | ||
|
|
38791616e0 | ||
|
|
fede3fd2e1 | ||
|
|
a46a33238d | ||
|
|
afe0488bf2 | ||
|
|
ec5e42694d | ||
|
|
2e73563eea |
@@ -23,11 +23,16 @@ jobs:
|
||||
run: |
|
||||
ver=${GITHUB_REF#refs/tags/}
|
||||
echo "ver=${ver}" >> $GITHUB_OUTPUT
|
||||
if echo $ver | grep -qE '[0-9.]+(-alpha|-beta|-rc)[0-9]*'; then
|
||||
if echo $ver | grep -qE '^[0-9]+\.[0-9]+(\.[0-9]+)?(-alpha|-beta|-rc)[0-9]*$'; then
|
||||
echo "pre=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "pre=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
if echo $ver | grep -qE '^[0-9.]+\.[0-9.]+(\.[0-9]+)?$'; then
|
||||
echo "latest=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "latest=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: Creating Makefiles ...
|
||||
run: |
|
||||
./autogen.sh
|
||||
@@ -48,6 +53,7 @@ jobs:
|
||||
- uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: Finit v${{ github.ref_name }}
|
||||
prerelease: ${{ needs.build.outputs.pre }}
|
||||
prerelease: ${{ steps.build.outputs.pre }}
|
||||
makeLatest: ${{ steps.build.outputs.latest }}
|
||||
bodyFile: "release.md"
|
||||
artifacts: "artifacts/*"
|
||||
|
||||
+23
-1
@@ -4,7 +4,7 @@ Change Log
|
||||
All relevant changes are documented in this file.
|
||||
|
||||
|
||||
[4.5][] - 2023-09-24
|
||||
[4.5][] - 2023-10-04
|
||||
--------------------
|
||||
|
||||
### Changes
|
||||
@@ -16,6 +16,9 @@ All relevant changes are documented in this file.
|
||||
- Add `initctl -f` to force-skip asking Finit for existing services
|
||||
when creating new services during bootstrap, e.g. `/etc/rc.local`
|
||||
- `initctl runlevel` now returns `N S` instead of `N 10` in bootstrap
|
||||
- `initctl runlevel N` during bootstrap is now allowed. It changes
|
||||
the next runlevel to go to when bootstrap has completed. Effectively
|
||||
overriding the `runlevel N` statement in `/etc/finit.conf`
|
||||
- Improved logging on failure to `execvp()` a run/task/service, now
|
||||
with `errno`, e.g., "No such file or directory" when the command
|
||||
is missing from `$PATH`
|
||||
@@ -30,6 +33,16 @@ All relevant changes are documented in this file.
|
||||
- Increased MAX path for commands, and arguments: 64 -> 256
|
||||
- The bundled watchdog daemon no longer tries to log at startup, because
|
||||
syslog is not available yet, any startup message leak to console
|
||||
- Extend `if:` option with runtime evaluation of conditions. E.g., start
|
||||
a task only `if:<run/foo/failure>` (here the run task 'foo' failed)
|
||||
- Document new `if:`, `conflict:`, `nowarn` options for run/task/service
|
||||
first introduced in v4.4
|
||||
- Failure to open fstab should log to console, not just log to `/dev/kmsg`
|
||||
- Rename `/lib/finit/system/*.conf`, added numbered prefix to ensure
|
||||
proper execution order, e.g., `udevd` should always run first
|
||||
- Plugins and bundled services: dbus, keventd, watchdogd, and runparts,
|
||||
are now loaded *after* all services in `/lib/finit/system/`. A new
|
||||
runtime-only path (for inspection) in `/run/finit/system/` is used
|
||||
|
||||
### Fixes
|
||||
- Fix #227: believed to have been fixed in v4.3, the root cause was
|
||||
@@ -45,6 +58,15 @@ All relevant changes are documented in this file.
|
||||
- Fix #366: document `fsck.*` kernel command line options and simplify
|
||||
the configure flags `--enable-fsckfix` and `--enable-fastboot` to
|
||||
only adjust the default values for the `fsck.*` options.
|
||||
- Fix #371: swap load order of `/lib/finit/system/*` vs `/etc/finit.d/*`
|
||||
We must run `10-hotplug.conf` first to ensure devices and modules are
|
||||
up and loaded before the user's run/task/services are called. The order
|
||||
at bootstrap is now saved in `/run/finit/conf.order` for inspection,
|
||||
`/run/finit/exec.order` shows the start order of each process
|
||||
- Fix #372: lost `udevadm` calls due to overloading
|
||||
- Fixed dbus plugin, the function that located `<pidfile> ...` in the
|
||||
`dbus/system.conf` caused spurious line breaks which led to the
|
||||
service not being loaded properly
|
||||
- The `runparts` executor now skips backup files (`foo~`)
|
||||
- The `runparts` stanza now properly appends ` start` to scripts that
|
||||
start with `S[0-9]+`. This has been broken for a very long time.
|
||||
|
||||
+5
-3
@@ -1,4 +1,5 @@
|
||||
AC_INIT([Finit],[4.5-rc3],[https://github.com/troglobit/finit/issues],[finit],[https://troglobit.com/projects/finit/])
|
||||
AC_INIT([Finit], [4.5-rc5], [https://github.com/troglobit/finit/issues],
|
||||
[finit], [https://troglobit.com/projects/finit/])
|
||||
AC_CONFIG_AUX_DIR(aux)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
@@ -297,6 +298,7 @@ pkglibdir=$libdir/finit
|
||||
AC_SUBST(pkglibexecdir)
|
||||
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
|
||||
AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path])
|
||||
AC_DEFINE_UNQUOTED(FINIT_RUNPATH_, "/run/finit/system", [Finit runtime dynamic system services])
|
||||
|
||||
AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins")
|
||||
AC_SUBST(plugin_path)
|
||||
@@ -304,7 +306,7 @@ AC_DEFINE_UNQUOTED(PLUGIN_PATH, "$plugin_path", [Finit plugin path])
|
||||
|
||||
AC_EXPAND_DIR(tmpfiles_path, "$libdir/tmpfiles.d")
|
||||
AC_SUBST(tmpfiles_path)
|
||||
AC_DEFINE_UNQUOTED(TMPFILES_PATH, "$tmpfiles_path", [Main tmpfiles.d/, override in /etc])
|
||||
AC_DEFINE_UNQUOTED(TMPFILES_PATH_, "$tmpfiles_path", [Main tmpfiles.d/, override in /etc])
|
||||
|
||||
AC_EXPAND_DIR(finit_tmpfiles, "$pkglibdir/tmpfiles.d")
|
||||
AC_SUBST(finit_tmpfiles)
|
||||
@@ -312,7 +314,7 @@ AC_DEFINE_UNQUOTED(FINIT_TMPFILES, "$finit_tmpfiles", [Finit tmpfiles.d/ .conf p
|
||||
|
||||
AC_EXPAND_DIR(system_path, "$pkglibdir/system")
|
||||
AC_SUBST(system_path)
|
||||
AC_DEFINE_UNQUOTED(FINIT_SYSPATH, "$system_path", [Static services, previously generated at runtime by plugins])
|
||||
AC_DEFINE_UNQUOTED(FINIT_SYSPATH_, "$system_path", [Static services, previously generated at runtime by plugins])
|
||||
|
||||
AC_EXPAND_DIR(rescue_conf, "$pkglibdir/rescue.conf")
|
||||
AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
|
||||
|
||||
+143
-25
@@ -52,21 +52,51 @@ PID file monitoring, or [conditions](conditions.md).
|
||||
|
||||
### Configuration Files
|
||||
|
||||
Originally Finit was configured using a single file, `/etc/finit.conf`.
|
||||
Although still possible to use this single configuration file, today the
|
||||
following familiar layout is recommended:
|
||||
Originally Finit was configured using a single file, `/etc/finit.conf`,
|
||||
and although still possible to use a single configuration file, today
|
||||
the following layout is recommended:
|
||||
|
||||
/etc/
|
||||
|- finit.d/
|
||||
| |- available/
|
||||
| | `- my-service.conf
|
||||
: |- enabled/
|
||||
: | `- my-service.conf -> ../available/my-service.conf
|
||||
: :
|
||||
: |- static-service.conf
|
||||
: `- another-static.conf
|
||||
:
|
||||
`- finit.conf
|
||||
/
|
||||
|- etc/
|
||||
| |- finit.d/
|
||||
| | |- available/
|
||||
| | | `- my-service.conf
|
||||
| : |- enabled/
|
||||
| : | `- my-service.conf -> ../available/my-service.conf
|
||||
| : :
|
||||
| : |- static-service.conf
|
||||
| : `- another-static.conf
|
||||
| :
|
||||
| `- finit.conf
|
||||
|- lib
|
||||
| `- finit/
|
||||
| `- system/
|
||||
| |- 10-hotplug.conf
|
||||
| `- ...
|
||||
`- run/
|
||||
`- finit/
|
||||
`- system/
|
||||
|- dbus.conf
|
||||
|- keventd.conf
|
||||
|- runparts.conf
|
||||
|- watchdogd.conf
|
||||
`- ...
|
||||
|
||||
Configuration files in `/etc` are provided by the user, or projects like
|
||||
[finit-skel](https://github.com/troglobit/finit-skel) and extended by
|
||||
the user.
|
||||
|
||||
The files in `/lib/finit/system/*.conf` are system critical services and
|
||||
setup provided by Finit, e.g. udev/mdev that must run very early at system
|
||||
bootstrap. This system directory was introduced in Finit v4.4 to replace
|
||||
the hard-coded services provided by plugins before. All .conf files in this
|
||||
directory be either replaced by a system administrator or overridden by a
|
||||
file with the same name in `/etc/finit.d/`.
|
||||
|
||||
The files in `/run/finit/system/*.conf` are created by plugins and Finit
|
||||
bundled services like runparts, the [watchdog](#watchdog), and `keventd`
|
||||
if they are enabled. Like `/lib/finit/system/*.conf`, these files can
|
||||
be overridden by file with the same name in `/etc/finit.d/`.
|
||||
|
||||
Services in the `available/` and `enabled/` sub-directories are called
|
||||
dynamic services, in contrast to static services -- the only difference
|
||||
@@ -75,9 +105,27 @@ with the `enable` and `disable` commands. An administrator can always
|
||||
create files and symlinks manually.
|
||||
|
||||
At bootstrap, and `initctl reload`, all .conf files are read, starting
|
||||
with `finit.conf`, then, in alphabetical order, all `finit.d/*.conf`
|
||||
files, and finally (still in alphabetical order) all `enabled/*.conf`
|
||||
files.
|
||||
with `finit.conf`, then `/lib/finit/system/*.conf`, `finit.d/*.conf`,
|
||||
and finally all `finit.d/enabled/*.conf` files. Each directory is a
|
||||
unique group, where files within each group are sorted alphabetically.
|
||||
|
||||
**Example:**
|
||||
|
||||
/lib/finit/system/10-hotplug.conf
|
||||
/lib/finit/system/90-testserv.conf
|
||||
/run/finit/system/dbus.conf
|
||||
/run/finit/system/runparts.conf
|
||||
/etc/finit.d/10-abc.conf
|
||||
/etc/finit.d/20-abc.conf
|
||||
/etc/finit.d/enabled/1-aaa.conf
|
||||
/etc/finit.d/enabled/1-abc.conf
|
||||
|
||||
The resulting combined configuration is read line by line, each `run`,
|
||||
`task`, and `service` added to an ordered list that ensures they are
|
||||
started in the same order. This is important because of the blocking
|
||||
properties of the `run` statement. For an example on the relation of
|
||||
`service` and `run` statements, and dependency handling between them,
|
||||
see [Conditional Loading](#conditional-loading), below.
|
||||
|
||||
> **Note:** the `finit.conf` and `finit.d/` names are only defaults.
|
||||
> They can be changed at compile-time with two `configure` options:
|
||||
@@ -164,14 +212,19 @@ everything is OK.
|
||||
task [S] /lib/console-setup/console-setup.sh
|
||||
service [S12345] env:-/etc/default/rsyslog rsyslogd -n $RSYSLOGD_ARGS
|
||||
|
||||
After runlevel S, Finit proceeds to runlevel 2. (This can be changed in
|
||||
`/etc/finit.conf` using the `runlevel N` directive.) Before starting
|
||||
the services in runlevel 2, Finit first stops everything that is not
|
||||
allowed to run in 2, and then brings up networking. Networking is
|
||||
expected to be available in all runlevels except: S, 1 (single user
|
||||
level), 6, and 0. Networking is enabled either by the `network script`
|
||||
directive, or if you have an `/etc/network/interfaces` file, Finit calls
|
||||
`ifup -a` -- at the very least the loopback interface is brought up.
|
||||
After runlevel S, Finit proceeds to runlevel 2. This can be changed in
|
||||
`/etc/finit.conf` using the `runlevel N` directive, or by a script
|
||||
running in runlevel S that calls, e.g., `initctl runlevel 9`. The
|
||||
latter is useful if startup scripts detect problems outside of Finit's
|
||||
control, e.g., critical services/devices missing or hardware problems.
|
||||
|
||||
Before starting the services in runlevel 2, Finit first stops everything
|
||||
that is not allowed to run in 2, and then brings up networking.
|
||||
Networking is expected to be available in all runlevels except: S, 1
|
||||
(single user level), 6, and 0. Networking is enabled either by the
|
||||
`network script` directive, or if you have an `/etc/network/interfaces`
|
||||
file, Finit calls `ifup -a` -- at the very least the loopback interface
|
||||
is brought up.
|
||||
|
||||
> **Note:** when moving from runlevel S to 2, all run/task/services that
|
||||
> were constrained to runlevel S only are dropped from bookkeeping. So
|
||||
@@ -839,6 +892,71 @@ These script actions *must terminate*, so they have a default execution
|
||||
time of 3 seconds before they are SIGKILLed, this can be adjusted using
|
||||
the above `kill:SEC` syntax.
|
||||
|
||||
#### Conditional Loading
|
||||
|
||||
Finit support conditional loading of stanzas. The following example is
|
||||
take from the `system/hotplug.conf` file in the Finit distribution.
|
||||
Here we only show a simplified subset.
|
||||
|
||||
Starting with the `nowarn` option.
|
||||
|
||||
service nowarn name:udevd pid:udevd /lib/systemd/systemd-udevd
|
||||
service nowarn name:udevd pid:udevd udevd
|
||||
|
||||
When loading the .conf file Finit looks for `/lib/systemd/systemd-udevd`
|
||||
if that is not found Finit automatically logs a warning. The `nowarn`
|
||||
option disables this warning so that the second line can be evaluated,
|
||||
which also provides a service named `udevd`.
|
||||
|
||||
run nowarn if:udevd <pid/udevd> :1 udevadm settle -t 0
|
||||
|
||||
This line is only loaded if we know of a service named `udevd`. Again,
|
||||
we do not warn if `udevadm` is not found, Execution will also stop here
|
||||
until the PID condition is asserted, i.e., Finit detecting udevd has
|
||||
started.
|
||||
|
||||
run nowarn conflict:udevd [S] mdev -s -- Populating device tree
|
||||
|
||||
If `udevd` is not available, we try to run `mdev`, but if that is not
|
||||
found, again we do not warn.
|
||||
|
||||
Conditional loading statements can also be negated, so the previous stanza
|
||||
can also be written as:
|
||||
|
||||
run nowarn if:!udevd [S] mdev -s -- Populating device tree
|
||||
|
||||
The reason for using `confict` in this example is that a conflict can be
|
||||
resolved. Stanzas marked with `conflict:foo` are rechecked at runtime.
|
||||
|
||||
#### Conditional Execution
|
||||
|
||||
Similar to conditional loading of stanzas there is conditional runtime
|
||||
execution. This can be confusing at first, since Finit already has a
|
||||
condition subsystem, but this is more akin to the qualification to a
|
||||
runlevel. E.g., a `task [123]` is qualified to run only in runlevel 1,
|
||||
2, and 3. It is not considered for other runlevels.
|
||||
|
||||
Conditional execution qualify a run/task/service based on a condition.
|
||||
Consider this (simplified) example from the Infix operating system:
|
||||
|
||||
run [S] name:startup <pid/sysrepo> confd -b --load startup-config
|
||||
run [S] if:<usr/fail-startup> name:failure <pid/sysrepo> confd --load failure-config
|
||||
|
||||
The two run statements reside in the same .conf file so Finit runs them
|
||||
in true sequence. If loading the file `startup-config` fails confd sets
|
||||
the condition `usr/fail-startup`, thus allowing the next run statement
|
||||
to load `failure-config`.
|
||||
|
||||
Notice critical the difference between `<pid/sysrepo>` condition and
|
||||
`if:<usr/fail-startup>`. The former is a condition for starting and the
|
||||
latter is a condition to check if a run/task/service is qualified to
|
||||
even be considered.
|
||||
|
||||
Conditional execution statements can also be negated, so provided the
|
||||
file loaded did the opposite, i.e., set a condition on success, the
|
||||
previous stanza can also be written as:
|
||||
|
||||
run [S] if:<!usr/startup-ok> name:failure <pid/sysrepo> confd ...
|
||||
|
||||
### Run-parts Scripts
|
||||
|
||||
|
||||
@@ -240,6 +240,11 @@ Show top-like listing based on cgroups.
|
||||
List installed plugins.
|
||||
.It Nm Ar runlevel Op Ar 0-9
|
||||
Show or set runlevel: 0 halt, 6 reboot.
|
||||
.Pp
|
||||
If called at boot (runlevel S) to set the runlevel, Finit only schedules
|
||||
the change, effectively overriding the configured runlevel from
|
||||
.Pa /etc/finit.conf .
|
||||
Useful to trigger a fail-safe mode, or similar.
|
||||
.It Nm Ar reboot
|
||||
Reboot system, default if
|
||||
.Cm reboot
|
||||
|
||||
+2
-3
@@ -83,6 +83,7 @@ static char *dbus_pidfn(void)
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
@@ -156,9 +157,7 @@ static void setup(void *arg)
|
||||
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s",
|
||||
cmd, DBUS_ARGS, DBUS_DESC);
|
||||
|
||||
if (service_register(SVC_TYPE_SERVICE, line, global_rlimit, NULL))
|
||||
err(1, "Failed registering %s", DBUS_DAEMON);
|
||||
|
||||
conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf");
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +367,6 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
}
|
||||
|
||||
switch (rq.cmd) {
|
||||
case INIT_CMD_RUNLVL:
|
||||
case INIT_CMD_RELOAD:
|
||||
case INIT_CMD_START_SVC:
|
||||
case INIT_CMD_RESTART_SVC:
|
||||
@@ -378,7 +377,7 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
case INIT_CMD_POWEROFF:
|
||||
case INIT_CMD_SUSPEND:
|
||||
if (IS_RESERVED_RUNLEVEL(runlevel)) {
|
||||
warnx("Unsupported command in runlevel S and 6.");
|
||||
warnx("Unsupported command in runlevel S and 6/0.");
|
||||
goto leave;
|
||||
}
|
||||
default:
|
||||
@@ -387,6 +386,14 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
switch (rq.cmd) {
|
||||
case INIT_CMD_RUNLVL:
|
||||
/* Allow changing cfglevel in runlevel S */
|
||||
if (IS_RESERVED_RUNLEVEL(runlevel)) {
|
||||
if (runlevel != INIT_LEVEL) {
|
||||
warnx("Cannot abort runlevel 6/0.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (rq.runlevel) {
|
||||
case 's':
|
||||
case 'S':
|
||||
@@ -400,7 +407,12 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
halt = SHUT_OFF;
|
||||
if (lvl == 6)
|
||||
halt = SHUT_REBOOT;
|
||||
service_runlevel(lvl);
|
||||
|
||||
/* User requested change in next runlevel */
|
||||
if (runlevel == INIT_LEVEL)
|
||||
cfglevel = lvl;
|
||||
else
|
||||
service_runlevel(lvl);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
+116
-8
@@ -414,6 +414,79 @@ void conf_saverc(void)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called at bootstrap to log execution order (for debug)
|
||||
*/
|
||||
void conf_save_exec_order(svc_t *svc, char *cmdline, int result)
|
||||
{
|
||||
const char *fn = _PATH_VARRUN "finit/exec.order";
|
||||
const char *ststr = !result ? "[ OK ]" : "[FAIL]";
|
||||
static char *prepared = NULL;
|
||||
int first = !fexist(fn);
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(fn, "a+");
|
||||
if (!fp) {
|
||||
err(1, "failed writing to %s", fn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (first) {
|
||||
fprintf(fp, "# Execution order of run/task/services at bootstrap\n");
|
||||
fprintf(fp, "# ST TYPE COMMAND LINE (DESC)\n");
|
||||
}
|
||||
|
||||
if (result == -1) {
|
||||
int len;
|
||||
|
||||
len = snprintf(NULL, 0, " %-7s %-64s (%s)", svc_typestr(svc), cmdline, svc->desc);
|
||||
if (len > 0) {
|
||||
if (prepared)
|
||||
free(prepared);
|
||||
prepared = malloc(++len);
|
||||
if (!prepared)
|
||||
return;
|
||||
snprintf(prepared, len, " %-7s %-64s (%s)", svc_typestr(svc), cmdline, svc->desc);
|
||||
}
|
||||
} else {
|
||||
if (prepared) {
|
||||
memcpy(prepared, ststr, strlen(ststr));
|
||||
fprintf(fp, "%s\n", prepared);
|
||||
free(prepared);
|
||||
prepared = NULL;
|
||||
} else {
|
||||
fprintf(fp, "%s %-7s %-64s (%s)\n", ststr, svc_typestr(svc), cmdline, svc->desc);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by plugins and similar that dynamically generate system services
|
||||
*/
|
||||
void conf_save_service(int type, char *cfg, char *file)
|
||||
{
|
||||
char fn[256];
|
||||
svc_t foo;
|
||||
FILE *fp;
|
||||
|
||||
mkpath(FINIT_RUNPATH_, 0755);
|
||||
snprintf(fn, sizeof(fn), "%s/%s", FINIT_RUNPATH_, file);
|
||||
if (fexist(fn))
|
||||
warn("File %s already exists, overwriting.", fn);
|
||||
fp = fopen(fn, "w");
|
||||
if (!fp) {
|
||||
err(1, "Failed creating %s", fn);
|
||||
return;
|
||||
}
|
||||
|
||||
foo.type = type;
|
||||
fprintf(fp, "# Generated by finit:%s()\n", __func__);
|
||||
fprintf(fp, "%s %s\n", svc_typestr(&foo), cfg);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets, and makes a note of, all KEY=VALUE lines in a given .conf line
|
||||
* from finit.conf, or other .conf file. Note, PATH is always reset in
|
||||
@@ -1152,20 +1225,51 @@ int conf_reload(void)
|
||||
* but are now regular files that can be overridden by files in
|
||||
* /etc/finit.d -- similar to how tmfiles.d(5) work. E.g., add
|
||||
* an override .conf, or an ignore by symlinking to /dev/null
|
||||
*
|
||||
* The .conf files (and run/task/service stanzas) are parsed and
|
||||
* started in order. Each directory is sorted alphanumerically
|
||||
* and then the result is appended to the overall order:
|
||||
*
|
||||
* /lib/finit/system/10-hotplug.conf
|
||||
* /lib/finit/system/90-testserv.conf
|
||||
* /run/finit/system/dbus.conf
|
||||
* /run/finit/system/tty.conf
|
||||
* /etc/finit.d/10-abc.conf
|
||||
* /etc/finit.d/20-abc.conf
|
||||
* /etc/finit.d/enabled/1-aaa.conf
|
||||
* /etc/finit.d/enabled/1-abc.conf
|
||||
* /etc/finit.d/enabled/2-aaa.conf
|
||||
*/
|
||||
glob_append(&gl, 0, "%s/*.conf", finit_rcsd);
|
||||
glob_append(&gl, 1, "%s/*.conf", FINIT_SYSPATH);
|
||||
glob_append(&gl, 0, "%s/*.conf", FINIT_SYSPATH_);
|
||||
glob_append(&gl, 1, "%s/*.conf", FINIT_RUNPATH_);
|
||||
glob_append(&gl, 1, "%s/*.conf", finit_rcsd);
|
||||
glob_append(&gl, 1, "%s/enabled/*.conf", finit_rcsd);
|
||||
|
||||
if (bootstrap) {
|
||||
const char *fn = _PATH_VARRUN "finit/conf.order";
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(fn, "w");
|
||||
if (!fp) {
|
||||
err(1, "failed creating %s", fn);
|
||||
} else {
|
||||
fprintf(fp, "# Evaluation & execution order of .conf files\n");
|
||||
for (i = 0; i < gl.gl_pathc; i++)
|
||||
fprintf(fp, "%s\n", gl.gl_pathv[i]);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < gl.gl_pathc; i++) {
|
||||
char *path = gl.gl_pathv[i];
|
||||
char *rp = NULL;
|
||||
struct stat st;
|
||||
size_t j, len;
|
||||
|
||||
/* check for FINIT_SYSPATH overrides */
|
||||
/* check for FINIT_SYSPATH_ or FINIT_RUNPATH_ overrides */
|
||||
for (j = i + 1; j < gl.gl_pathc; j++) {
|
||||
if (strncmp(path, FINIT_SYSPATH, strlen(FINIT_SYSPATH)))
|
||||
if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) &&
|
||||
strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_)))
|
||||
continue;
|
||||
if (strcmp(basename(path), basename(gl.gl_pathv[j])))
|
||||
continue;
|
||||
@@ -1225,6 +1329,9 @@ done:
|
||||
/* Drop record of all .conf changes */
|
||||
drop_changes();
|
||||
|
||||
if (bootstrap)
|
||||
wdog = svc_find("watchdog", "finit");
|
||||
|
||||
/* Override configured runlevel, user said 'S' on /proc/cmdline */
|
||||
if (BOOTSTRAP && single)
|
||||
cfglevel = 1;
|
||||
@@ -1461,15 +1568,16 @@ int conf_init(uev_ctx_t *ctx)
|
||||
*/
|
||||
#ifdef WDT_DEVNODE
|
||||
if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) {
|
||||
service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit " FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", global_rlimit, NULL);
|
||||
wdog = svc_find("watchdog", "finit");
|
||||
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit "
|
||||
FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", "watchdogd.conf");
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Start kernel event daemon as soon as possible, if enabled
|
||||
*/
|
||||
if (whichp(FINIT_EXECPATH_ "/keventd"))
|
||||
service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init " FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", global_rlimit, NULL);
|
||||
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init "
|
||||
FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", "keventd.conf");
|
||||
|
||||
dbg("Allow plugins to register early runlevel 1 run/task/services ...");
|
||||
plugin_run_hooks(HOOK_SVC_PLUGIN);
|
||||
@@ -1505,7 +1613,7 @@ int conf_init(uev_ctx_t *ctx)
|
||||
snprintf(conf, sizeof(conf), "[S] <int/bootstrap> log:console %s %s %s"
|
||||
" -- Calling runparts %s in the background",
|
||||
_PATH_RUNPARTS, args, runparts, runparts);
|
||||
service_register(SVC_TYPE_TASK, conf, global_rlimit, NULL);
|
||||
conf_save_service(SVC_TYPE_TASK, conf, "runparts.conf");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -44,6 +44,8 @@ int conf_monitor (void);
|
||||
|
||||
void conf_reset_env (void);
|
||||
void conf_saverc (void);
|
||||
void conf_save_exec_order (svc_t *svc, char *cmdline, int result);
|
||||
void conf_save_service (int type, char *cfg, char *file);
|
||||
void conf_parse_cmdline (int argc, char *argv[]);
|
||||
int conf_parse_runlevels (char *runlevels);
|
||||
void conf_parse_cond (svc_t *svc, char *cond);
|
||||
|
||||
+1
-1
@@ -237,7 +237,7 @@ static void devmon_cb(uev_t *w, void *arg, int events)
|
||||
continue;
|
||||
}
|
||||
|
||||
dbg("Got %s", ev->name);
|
||||
// dbg("Got %s", ev->name);
|
||||
if (ev->mask & (IN_CREATE | IN_DELETE))
|
||||
devmon_update_conds(iwp->path, ev->name, ev->mask);
|
||||
}
|
||||
|
||||
+1
-1
@@ -204,7 +204,7 @@ static int fsck(int pass)
|
||||
|
||||
fp = setmntent(fstab, "r");
|
||||
if (!fp) {
|
||||
err(1, "Failed opening fstab: %s", fstab);
|
||||
logit(LOG_CONSOLE | LOG_ALERT, "Failed opening fstab: %s", fstab);
|
||||
sulogin(1);
|
||||
}
|
||||
dbg("Opened %s, pass %d", fstab, pass);
|
||||
|
||||
+1
-1
@@ -288,7 +288,7 @@ static void generic_io_cb(uev_t *w, void *arg, int events)
|
||||
/* Stop watcher, callback may close descriptor on us ... */
|
||||
uev_io_stop(w);
|
||||
|
||||
dbg("Calling I/O %s from runloop...", basename(p->name));
|
||||
// dbg("Calling I/O %s from runloop...", basename(p->name));
|
||||
p->io.cb(p->io.arg, w->fd, events);
|
||||
|
||||
/* Update fd, may be changed by plugin callback, e.g., if FIFO */
|
||||
|
||||
+20
-7
@@ -629,6 +629,9 @@ static int service_start(svc_t *svc)
|
||||
}
|
||||
|
||||
compose_cmdline(svc, cmdline, sizeof(cmdline));
|
||||
if (bootstrap)
|
||||
conf_save_exec_order(svc, cmdline, -1);
|
||||
|
||||
if (svc_is_sysv(svc))
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", cmdline);
|
||||
|
||||
@@ -836,8 +839,10 @@ static int service_start(svc_t *svc)
|
||||
|
||||
fail:
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
if (do_progress)
|
||||
if (do_progress && !run_block_pid)
|
||||
print_result(result);
|
||||
if (bootstrap && !run_block_pid)
|
||||
conf_save_exec_order(svc, NULL, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1847,11 +1852,6 @@ void service_monitor(pid_t lost, int status)
|
||||
return;
|
||||
}
|
||||
|
||||
if (lost == run_block_pid) {
|
||||
svc_mark_clean(svc); /* done, regardless of exit status */
|
||||
run_block_pid = 0;
|
||||
}
|
||||
|
||||
switch (svc->state) {
|
||||
case SVC_CLEANUP_STATE:
|
||||
case SVC_SETUP_STATE:
|
||||
@@ -1900,6 +1900,17 @@ done:
|
||||
/* No longer running, update books. */
|
||||
svc->start_time = svc->pid = 0;
|
||||
cont:
|
||||
if (lost == run_block_pid) {
|
||||
int result = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
|
||||
|
||||
svc_mark_clean(svc); /* done, regardless of exit status */
|
||||
run_block_pid = 0;
|
||||
if (svc->desc[0])
|
||||
print_result(result);
|
||||
if (bootstrap)
|
||||
conf_save_exec_order(svc, NULL, result);
|
||||
}
|
||||
|
||||
if (!service_step(svc)) {
|
||||
/* Clean out any bootstrap tasks, they've had their time in the sun. */
|
||||
if (svc_clean_bootstrap(svc))
|
||||
@@ -1955,7 +1966,7 @@ void service_mark_unavail(void)
|
||||
if (!svc->ifstmt[0])
|
||||
continue;
|
||||
|
||||
if (!svc_ifthen(svc_ident(svc, buf, sizeof(buf)), svc->ifstmt))
|
||||
if (!svc_ifthen(1, svc_ident(svc, buf, sizeof(buf)), svc->ifstmt))
|
||||
svc_mark(svc);
|
||||
}
|
||||
}
|
||||
@@ -2294,9 +2305,11 @@ restart:
|
||||
svc_set_state(svc, SVC_WAITING_STATE);
|
||||
else {
|
||||
if (svc_is_conflict(svc)) {
|
||||
#if 0
|
||||
logit(svc->nowarn ? LOG_DEBUG : LOG_INFO,
|
||||
"%s in conflict with %s, checking again ...",
|
||||
svc_ident(svc, NULL, 0), svc->conflict);
|
||||
#endif
|
||||
if (!svc_conflicts(svc))
|
||||
svc_unblock(svc);
|
||||
}
|
||||
|
||||
@@ -634,17 +634,30 @@ int svc_enabled(svc_t *svc)
|
||||
if (!svc)
|
||||
return 0;
|
||||
|
||||
if (!svc_in_runlevel(svc, runlevel))
|
||||
if (!svc_in_runlevel(svc, runlevel)) {
|
||||
// dbg("Not in runlevel");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (svc_is_removed(svc) || svc_is_blocked(svc))
|
||||
if (svc_is_removed(svc) || svc_is_blocked(svc)) {
|
||||
// dbg("removed (%d) / blocked (%d)", svc->removed, svc->block);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (svc_is_missing(svc))
|
||||
if (svc_is_missing(svc)) {
|
||||
// dbg("missing");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (svc_is_tty(svc) && bootstrap)
|
||||
if (!svc_ifthen(0, NULL, svc->ifstmt)) {
|
||||
// dbg("ifthen:%s>", svc->ifstmt[0] ? svc->ifstmt : "<");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (svc_is_tty(svc) && bootstrap) {
|
||||
// dbg("is tty in bootstrap");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -688,13 +701,14 @@ int svc_conflicts(svc_t *svc)
|
||||
|
||||
/**
|
||||
* svc_ifthen - Check if: statement in declaration
|
||||
* @is_conf: Set when called by service_mark_unavail()
|
||||
* @ident: svc_t identififcation (name:id)
|
||||
* @stmt: if: statement from .conf file
|
||||
*
|
||||
* Returns:
|
||||
* %TRUE(1) yes, use this svc_t, %FALSE(0) prune
|
||||
*/
|
||||
int svc_ifthen(const char *ident, char *stmt)
|
||||
int svc_ifthen(int is_conf, const char *ident, char *stmt)
|
||||
{
|
||||
int not = 0;
|
||||
svc_t *svc;
|
||||
@@ -707,6 +721,9 @@ int svc_ifthen(const char *ident, char *stmt)
|
||||
char *ptr = ++stmt;
|
||||
int i = 0;
|
||||
|
||||
if (is_conf)
|
||||
return 1;
|
||||
|
||||
if (stmt[0] == '!') {
|
||||
stmt++;
|
||||
not++;
|
||||
@@ -717,17 +734,16 @@ int svc_ifthen(const char *ident, char *stmt)
|
||||
ptr[i] = 0;
|
||||
|
||||
cond = cond_get(stmt);
|
||||
if (not && cond == COND_ON) {
|
||||
logit(LOG_NOTICE, "skipping %s, cond %s is on.", ident, stmt);
|
||||
if (not && cond == COND_ON)
|
||||
return 0;
|
||||
}
|
||||
if (!not && cond == COND_OFF) {
|
||||
logit(LOG_NOTICE, "skipping %s, cond %s is off.", ident, stmt);
|
||||
if (!not && cond == COND_OFF)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!is_conf)
|
||||
return 1;
|
||||
|
||||
if (stmt[0] == '!') {
|
||||
stmt++;
|
||||
not++;
|
||||
|
||||
@@ -241,7 +241,7 @@ void svc_prune_bootstrap (void);
|
||||
void svc_enable (svc_t *svc);
|
||||
int svc_enabled (svc_t *svc);
|
||||
int svc_conflicts (svc_t *svc);
|
||||
int svc_ifthen (const char *ident, char *ifstm);
|
||||
int svc_ifthen (int is_conf, const char *ident, char *stmt);
|
||||
|
||||
int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *));
|
||||
|
||||
|
||||
+1
-1
@@ -471,7 +471,7 @@ void tmpfilesd(void)
|
||||
/* in priority order */
|
||||
char *dir[] = {
|
||||
FINIT_TMPFILES "/*.conf",
|
||||
TMPFILES_PATH "/*.conf",
|
||||
TMPFILES_PATH_ "/*.conf",
|
||||
"/usr/lib/tmpfiles.d/*.conf",
|
||||
"/run/tmpfiles.d/*.conf",
|
||||
"/etc/tmpfiles.d/*.conf", /* local admin overrides */
|
||||
|
||||
@@ -7,11 +7,11 @@ service nowarn [S12345789] cgroup.system name:udevd pid:udevd log /lib/systemd/s
|
||||
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log udevd -- Device event managing daemon
|
||||
|
||||
# Wait for udevd to start, then wait a couple of seconds for it to become ready
|
||||
run nowarn if:udevd cgroup.init [S] <pid/udevd> udevadm settle -t 0 --
|
||||
run nowarn if:udevd cgroup.init [S] <pid/udevd> log udevadm control --reload
|
||||
run nowarn if:udevd cgroup.init :1 [S] <pid/udevd> log udevadm trigger -c add -t devices -- Requesting device events
|
||||
run nowarn if:udevd cgroup.init :2 [S] <pid/udevd> log udevadm trigger -c add -t subsystems -- Requesting subsystem events
|
||||
run nowarn if:udevd cgroup.init [S] <pid/udevd> log udevadm settle -t 5 -- Waiting for udev to finish
|
||||
run nowarn if:udevd cgroup.init :1 [S] <pid/udevd> log udevadm settle -t 0 --
|
||||
run nowarn if:udevd cgroup.init :2 [S] <pid/udevd> log udevadm control --reload --
|
||||
run nowarn if:udevd cgroup.init :3 [S] <pid/udevd> log udevadm trigger -c add -t devices -- Requesting device events
|
||||
run nowarn if:udevd cgroup.init :4 [S] <pid/udevd> log udevadm trigger -c add -t subsystems -- Requesting subsystem events
|
||||
run nowarn if:udevd cgroup.init :5 [S] <pid/udevd> log udevadm settle -t 5 -- Waiting for udev to finish
|
||||
|
||||
# If udevd is not available, try mdev
|
||||
run nowarn conflict:udevd [S] mdev -s -- Populating device tree
|
||||
+2
-2
@@ -2,9 +2,9 @@ systemdir = $(system_path)
|
||||
dist_system_DATA =
|
||||
|
||||
if BUILD_HOTPLUG_PLUGIN
|
||||
dist_system_DATA += hotplug.conf
|
||||
dist_system_DATA += 10-hotplug.conf
|
||||
endif
|
||||
|
||||
if BUILD_TESTSERV_PLUGIN
|
||||
dist_system_DATA += testserv.conf
|
||||
dist_system_DATA += 90-testserv.conf
|
||||
endif
|
||||
|
||||
@@ -11,4 +11,4 @@ d /run/finit/cond 0755 - - -
|
||||
d /run/finit/cond/pid 0755 - - -
|
||||
d /run/finit/cond/sys 0755 - - -
|
||||
d /run/finit/cond/usr 0755 - - -
|
||||
|
||||
d /run/finit/system 0755 - - -
|
||||
|
||||
Reference in New Issue
Block a user