Compare commits

..
54 Commits
Author SHA1 Message Date
Joachim Wiberg d15e28ea6b Update ChangeLog and bump version for v4.7 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 19:48:31 +01:00
Joachim Wiberg 836bfff08b .github: update actions
... and try to fix weekly trigger

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 19:47:12 +01:00
Joachim Wiberg 59152b557c keventd: remove runlevels 0 and 6
The responsibility of the kernel event daemon is to relay kernel events
to Finit.  At shutdown and reboot it is too late for more events and the
daemon should just shut down with other services.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 15:18:52 +01:00
Joachim Wiberg 293b0ffa79 tmpfiles.d/var.conf: fix ordering and add legacy /run/lock/subsys
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 13:59:49 +01:00
Joachim Wiberg d5d9cd5645 tmpfiles: fix error message and ignore unremovable dirs (EBUSY)
Fix copy-paste of error message from cond-w.c

A read-only root filesystem may have /var/lock, while we want to remove
it and add a symlink to ../run/lock.  Ignore errors from this since we
cannot do anything about it.  It is up to the user to fix their skeleton
or use an overlay.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 13:56:31 +01:00
Joachim Wiberg 2f281665af Simplify and add links to Infix, br2-finit-demo, and Buildroot
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 02:00:47 +01:00
Joachim Wiberg b00e7394f8 Update ChangeLog and bump version for v4.7-rc1
No more changes or fixes expected.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 01:51:15 +01:00
Joachim Wiberg d5a5fffa52 Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 01:50:50 +01:00
Joachim Wiberg 4d24c34b28 Update screenshot URL to point to HowTo
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 01:39:30 +01:00
Joachim Wiberg 355265651e Retake new screenshot, fix resolution
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 01:32:52 +01:00
Joachim Wiberg 41093df2a9 Attempt 2, scaled
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 01:27:03 +01:00
Joachim Wiberg 0a816d1fa4 Test bump Alpine screenshot
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 01:23:03 +01:00
Joachim Wiberg 3bfc0f0fca contrib/alpine: drop softdog, we are not built with finit-watchdogd
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 00:59:27 +01:00
Joachim Wiberg 0aa6ee895c contrib/alpine: follow-up to 2c340f83
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 00:59:18 +01:00
Joachim Wiberg b1526fb2d6 contrib/alpine: bump version
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 00:56:41 +01:00
Joachim Wiberg b2624ac160 contrib/alpine: fix install script, grep for contrib/alpine
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 00:56:11 +01:00
Joachim Wiberg 2c340f83ce contrib/alpine: fix syslog.conf vs syslogd.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-07 00:26:19 +01:00
Joachim Wiberg 337ee003bb Mount /dev/mqueue if missing and set sticky bit to /dev/shm
Inspired by Alpine Linux, add /dev/mqueue if missing.  We should check
the /proc/filesystems first, but this is quicker.

The sticky bit ensures only the owner of files in /dev/shm can delete or
rename files.  This is also what Alpine Linux use.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 23:50:30 +01:00
Joachim Wiberg 791df0c986 Refactor, ensure basenm() returns a const char pointer of its arg.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 23:46:17 +01:00
Joachim Wiberg f29e92be21 Minor, update
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 20:02:45 +01:00
Joachim Wiberg 379a63fce4 .github: adjust path for cov-build
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 19:55:55 +01:00
Joachim Wiberg b1f9a11809 .github: update actions, sync coverity with latest
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 19:51:37 +01:00
Joachim Wiberg 2d9c63e48e test: actually verify the service asserts ready before continuing
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 16:31:45 +01:00
Joachim Wiberg d66455496a Fix #392: ensure 'ready' condition is cleared on pidfile removal
A service with notify:pid is 'ready' when the pidfile has been created,
the converse also holds true -- when a pidfile is removed the service is
no longer 'ready'.

The state transition for the service has probably already been done, in
svc_set_state(), clearing all <service/foo/*> conditions when the PID
was collected.  The pidfile event may arrive later, so for completeness
we make sure the 'ready' condition is not recreated at least.

Problem introduced in 912a281 with the original supoport for service
readiness notification.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 12:25:41 +01:00
Joachim Wiberg 77cf72cb40 test: regression test to reproduce issue #392
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 12:03:33 +01:00
Joachim Wiberg 6cc587068b Log service identifier, not process name, in debug message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 11:59:46 +01:00
Joachim Wiberg cc96e8908a Open v4.7 release cycle
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 11:59:33 +01:00
Joachim Wiberg adb25d52cd test: minor, rename test case native -> pid
We now support notify:pid, so let's use it, even though it's the default.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-06 10:13:13 +01:00
Joachim Wiberg 7d09567ec8 Mention cgroup.root workaround to Linux SCHED_RR limitation
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-01-05 10:27:03 +01:00
Joachim Wiberg 9130af1c77 Merge pull request #390 from Stargirl-chan/master
Fix compilation on musl by implementing a custom basename

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-12-29 14:57:10 +01:00
Stargirl-chan cbea83b369 Simplified function comment and follow coding style 2023-12-29 13:37:08 +01:00
Stargirl-chan 42cd8d284b Implement custom basename function (basenm)
There exist two possible basename functions, a xpg compliant one in libgen.h
and a GLIBC exclusive one declared in string.h, that was previously also declared by musl libc.
Both implementations are expecting different parameter types (`const char *` for GLIBC and `char *` for xpg)

With the removal of the basename function from string.h in musl libc, we could only rely on the xpg implementation.

Unfortunately, the xpg implementation of basename does modify the contents of whatever you put in it,
even though that there really is no need for it.

This is an issue in some cases, where we might want to get the basename of a read-only variable, e.g. a `const char *`,
as trying to modify something read-only is undefined behavior.

So in order to keep things consistent for us, we implement our own version of basename called `basenm`,
that does not modify the passed argument.
2023-12-29 10:44:40 +01:00
Stargirl-chan 72ebc92622 Fix compilation on musl by using posix basename 2023-12-28 03:41:00 +01:00
Joachim Wiberg 06adecaaea Merge pull request #388 from soggyfries/soggyfries-log-fix
Fix log child exiting with debug disabled
2023-12-19 06:43:24 +01:00
Ryan Rorison efc0592961 Fix log child exiting with debug disabled 2023-12-18 21:00:45 -08:00
Joachim Wiberg ed88469276 Actually silence the log message, missing hunk for previous change
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-12-10 17:32:19 +01:00
Joachim Wiberg cbf96a1de0 Silence 'not available' log messages for nowarn run/task/service
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-12-10 16:42:29 +01:00
Joachim Wiberg cc979f27f1 tmpfiles.d: add missing /var/tmp and /var/lock -> /run/lock
- /var/tmp  https://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html
 - /run/lock std Debian

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-22 08:08:24 +01:00
Joachim Wiberg fca5ce57ea Bump version for v4.6 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 07:03:30 +01:00
Joachim Wiberg 53aa195ad5 test: update, pid/B is no longer assert by Finit if notify != pid
As of Finit v4.6 we no longer assert the PID condition for services
declaring themselves as notify != pid.  We replace D with a forking
service to catch any future regressions in the pidfile plugin.

No need to check reload PID of D, it is enough to check PID of C.

Also, reduce the number of retries at startup.  If we haven't gone
up within 10 sec with this tiny config something is really wrong.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 06:09:35 +01:00
Joachim Wiberg e60211168e Fix type:forking regression in 66020f4, caught by tests
Premise, a service declaring itself 'notify:none' should never assert a
pid condition.  However, forking services still need to be supported and
the only way to do that is if they create a pid file.  Hence, instead of
skipping pidfile_update_conds() completely we need to filter the type.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 06:06:58 +01:00
Joachim Wiberg dc3ee9e467 Handle rare warning when registering configuration changes
2023-11-13T04:02:23 [WRN]: conf_change_act():failed registering /etc/finit.conf/ event mask 00000004: Not a directory

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 05:05:07 +01:00
Joachim Wiberg 6918f3b711 Update ChangeLog for v4.6
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 04:39:08 +01:00
Joachim Wiberg 66020f48ea Do not create PID conditions for services that do not support it
Follow-up to issue #386

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 04:37:03 +01:00
Joachim Wiberg 47b0d4cccf Reassert both PID and ready conditions when leaving paused state
Follow-up to issue #386

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 04:35:31 +01:00
Joachim Wiberg 92c2efa655 Minor, use svc_ident() instead of incomplete svc->name in debug logs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-13 04:32:30 +01:00
Joachim Wiberg b69aa8a8bd Bump version for 4.6 bug fix release, rc1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 19:08:40 +01:00
Joachim Wiberg ca90bbfb04 Fix #387: sanity check environment variables before sourcing
This fixes an issue when finding a global environment variable with
spaces in the variable name:

    set COLORTERM=yes

Literally, 'set COLORTERM' was the name of the variable.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 19:07:54 +01:00
Joachim Wiberg 0b5c555c7f Add 'notify:pid' style readiness notifaction and 'readiness none'
This change expands the readiness notification system in Finit with the
native 'pid' style, which will remain the default readiness in Finit 4.x

For systems that want to transition to Finit 5.x early, a global option
to set 'readiness none' in /etc/finit.conf, has been added.  This change
the service default notification mode to 'notify:none', which can also
be set by Finit 4.x ('readiness pid') for select services.

Fixes #386.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 19:07:12 +01:00
Joachim Wiberg 6443995fc9 Fix #385: internal conditions are type oneshot, always active
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 09:04:35 +01:00
Joachim Wiberg 180faf8a40 test: minor, disable debug as final step in function
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 09:04:15 +01:00
Joachim Wiberg 0ebdd32f6b Fix #384: reassemble value fragments after wordexp() before setenv()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 08:50:12 +01:00
Joachim Wiberg 60bf858302 test: extend svc-env.sh with more common use-case
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-12 08:37:05 +01:00
Joachim Wiberg 7c86b40190 Fix #383: configure must expand FINIT_RUNPATH_ before define
This fixes an annying buglet that creeped in just before the v4.5 release
causing none of the internal services to be registered properly:

    conf_save_service():Failed creating ${localstatedir}/run/finit/system/dbus.conf: No such file or directory
    plugin_run_hook():Calling modules-load hook n:o 5 (arg: 0x55c4c8133621) ...
    load():Scanning /etc/modules-load.d for config files ...
    cond_set_oneshot():hook/svc/plugin
    cond_set_oneshot_noupdate():hook/svc/plugin => /run/finit/cond/hook/svc/plugin
    cond_update():hook/svc/plugin
    parse_conf():*** Parsing /etc/finit.conf
    conf_save_service():Failed creating ${localstatedir}/run/finit/system/runparts.conf: No such file or directory

The fix, like most, is simple when you find it.  We must expand $runstatedir
before creating the #define in config.h

For convenience, here's the patch for the generated configure script:

&<---------------------------[cut here]---------------------------
--- a/configure	2023-11-05 23:39:51.907334321 +0100
+++ b/configure	2023-11-05 23:39:58.339299795 +0100
@@ -15352,7 +15352,15 @@
 printf "%s\n" "#define FINIT_EXECPATH_ \"$pkglibexecdir\"" >>confdefs.h

-printf "%s\n" "#define FINIT_RUNPATH_ \"$runstatedir/finit/system\"" >>confdefs.h
+	finit_runpath="$runstatedir/finit/system"
+	finit_runpath=`(
+	    test "x$prefix" = xNONE && prefix="$ac_default_prefix"
+	    test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
+	    eval echo \""$finit_runpath"\"
+	    )`
+
+
+printf "%s\n" "#define FINIT_RUNPATH_ \"$finit_runpath\"" >>confdefs.h

&<---------------------------[cut here]---------------------------
Ensure you include the three empty lines for context at the end!

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-11-05 23:46:26 +01:00
101 changed files with 587 additions and 282 deletions
+2 -2
View File
@@ -28,7 +28,7 @@ jobs:
run: | run: |
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y install pkg-config tree jq libuev-dev libite-dev sudo apt-get -y install pkg-config tree jq libuev-dev libite-dev
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Static Finit - name: Static Finit
run: | run: |
./autogen.sh ./autogen.sh
@@ -61,7 +61,7 @@ jobs:
run: | run: |
make check || (cat test/test-suite.log; false) make check || (cat test/test-suite.log; false)
- name: Upload Test Results - name: Upload Test Results
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: finit-test-${{ matrix.compiler }} name: finit-test-${{ matrix.compiler }}
path: test/*.log path: test/*.log
+40 -16
View File
@@ -15,22 +15,39 @@ jobs:
coverity: coverity:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/cache@v3 - name: Fetch latest Coverity Scan MD5
id: coverity-toolchain-cache id: var
with:
path: cov-analysis-linux64
key: ${{ runner.os }}-coverity
- name: Download Coverity Scan
if: steps.coverity-toolchain-cache.outputs.cache-hit != 'true'
env: env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: | run: |
wget -q https://scan.coverity.com/download/cxx/linux64 \ wget -q https://scan.coverity.com/download/cxx/linux64 \
--post-data "token=$TOKEN&project=${COVERITY_PROJ}" \ --post-data "token=$TOKEN&project=${COVERITY_PROJ}&md5=1" \
-O cov-analysis-linux64.tar.gz -O coverity-latest.tar.gz.md5
mkdir cov-analysis-linux64 echo "md5=$(cat coverity-latest.tar.gz.md5)" | tee -a $GITHUB_OUTPUT
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64 - uses: actions/cache@v3
id: cache
with:
path: coverity-latest.tar.gz
key: ${{ runner.os }}-coverity-${{ steps.var.outputs.md5 }}
restore-keys: |
${{ runner.os }}-coverity-${{ steps.var.outputs.md5 }}
${{ runner.os }}-coverity-
${{ runner.os }}-coverity
- name: Download Coverity Scan
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: |
if [ ! -f coverity-latest.tar.gz ]; then
wget -q https://scan.coverity.com/download/cxx/linux64 \
--post-data "token=$TOKEN&project=${COVERITY_PROJ}" \
-O coverity-latest.tar.gz
else
echo "Latest Coverity Scan available from cache :-)"
md5sum coverity-latest.tar.gz
fi
mkdir coverity
tar xzf coverity-latest.tar.gz --strip 1 -C coverity
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get -y update sudo apt-get -y update
@@ -42,13 +59,15 @@ jobs:
(cd libuev-2.4.0 && ./configure --prefix=/usr && make && sudo make install-strip) (cd libuev-2.4.0 && ./configure --prefix=/usr && make && sudo make install-strip)
(cd libite-2.5.2 && ./configure --prefix=/usr && make && sudo make install-strip) (cd libite-2.5.2 && ./configure --prefix=/usr && make && sudo make install-strip)
sudo ldconfig sudo ldconfig
- name: Build - name: Configure
run: | run: |
./autogen.sh ./autogen.sh
./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd ./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd
export PATH=`pwd`/cov-analysis-linux64/bin:$PATH - name: Build
run: |
export PATH=`pwd`/coverity/bin:$PATH
cov-build --dir cov-int make cov-build --dir cov-int make
- name: Submit result to Coverity Scan - name: Submit results to Coverity Scan
env: env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: | run: |
@@ -61,3 +80,8 @@ jobs:
--form version=trunk \ --form version=trunk \
--form description="${PROJECT_NAME} $(git rev-parse HEAD)" \ --form description="${PROJECT_NAME} $(git rev-parse HEAD)" \
https://scan.coverity.com/builds?project=${COVERITY_PROJ} https://scan.coverity.com/builds?project=${COVERITY_PROJ}
- name: Upload build.log
uses: actions/upload-artifact@v4
with:
name: coverity-build.log
path: cov-int/build-log.txt
+1 -1
View File
@@ -13,7 +13,7 @@ jobs:
env: env:
MAKEFLAGS: -j3 MAKEFLAGS: -j3
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Installing dependencies ... - name: Installing dependencies ...
run: | run: |
sudo apt-get -y update sudo apt-get -y update
+3 -3
View File
@@ -13,7 +13,7 @@ jobs:
outputs: outputs:
run: ${{ steps.check.outputs.run }} run: ${{ steps.check.outputs.run }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Check for any commits since last week - name: Check for any commits since last week
id: schedule id: schedule
run: | run: |
@@ -25,14 +25,14 @@ jobs:
fi fi
distcheck: distcheck:
needs: schedule needs: schedule
if: ${{ needs.schedule.outputs.run }} if: ${{ needs.schedule.outputs.run == 'true' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y install pkg-config jq libuev-dev libite-dev sudo apt-get -y install pkg-config jq libuev-dev libite-dev
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Base run - name: Base run
run: | run: |
./autogen.sh ./autogen.sh
+4
View File
@@ -14,6 +14,7 @@ GTAGS
/autom4te.cache /autom4te.cache
/aclocal.m4 /aclocal.m4
/ar-lib /ar-lib
/backup/
/compile /compile
/config.cache /config.cache
/config.h /config.h
@@ -36,6 +37,9 @@ GTAGS
/test-driver /test-driver
/test-suite.log /test-suite.log
# Misc
/.gdb_history
# TroglOS build system # TroglOS build system
/.config /.config
/.stamp /.stamp
+45 -1
View File
@@ -4,6 +4,48 @@ Change Log
All relevant changes are documented in this file. All relevant changes are documented in this file.
[4.7][] - 2024-01-07
--------------------
### Changes
- Silence "not available" messages for run/task/service with `nowarn`
- Update docs, `cgroup.root` workaround for `SCHED_RR` tasks
- Drop runlevels 0 and 6 from `keventd`, not needed at reboot/poweroff
- Mount `/dev/shm` with mode 1777 (sticky bit)
- Mount `/dev/mqueue` if available, inspiration from Alpine Linux
- Update Alpine Linux installer and configuration files, tested on
Alpine v3.19, some assembly still required
### Fixes
- Fix confusing warning message when tmpfiles.d fails to install symlink
- Fix tmpfiles.d legacy `/run/lock/subsys`, ordering
- Add missing `/var/tmp` and `/var/lock -> /run/lock` (tmpfiles.d)
- Fix #388: log redirection broken unless Finit runs in debug mode.
Found and fixed by Ryan Rorison
- Fix #389: must libc requires `libgen.h` for `basename()` function.
Reported and worked around with new `basenm()` function by Stargirl
[4.6][] - 2023-11-13
--------------------
### Changes
- Add support for service `notify:pid` and `readiness none` global
option to change how Finit expects readiness notification, issue #386
### Fixes
- Fix #383: dbus and runparts regression in Finit v4.5. The configure
script must expand `FINIT_RUNPATH_` before defining it in `config.h`
- Fix #384: service environment variables drop everything but the first
argument, e.g., `VAR="foo bar qux"` drops everything but `foo`
- Fix #385: internal conditions, e.g., `<int/bootstrap>` turn into flux
when leaving bootstrap, causing depending services to stop
- Fix #387: global environment variables declared with `set VAR=NAME` do
not drop leading `set `, causing `'set VAR'='NAME'` in env.
- Sanity check environment variables, for services and globally. Ensure
the variable name (key) does not contain spaces, or a leading `set `
[4.5][] - 2023-10-30 [4.5][] - 2023-10-30
-------------------- --------------------
@@ -1613,7 +1655,9 @@ Major bug fix release.
* Initial release * Initial release
[UNRELEASED]: https://github.com/troglobit/finit/compare/4.5...HEAD [UNRELEASED]: https://github.com/troglobit/finit/compare/4.7...HEAD
[4.7]: https://github.com/troglobit/finit/compare/4.6...4.7
[4.6]: https://github.com/troglobit/finit/compare/4.5...4.6
[4.5]: https://github.com/troglobit/finit/compare/4.4...4.5 [4.5]: https://github.com/troglobit/finit/compare/4.4...4.5
[4.4]: https://github.com/troglobit/finit/compare/4.3...4.4 [4.4]: https://github.com/troglobit/finit/compare/4.3...4.4
[4.3]: https://github.com/troglobit/finit/compare/4.2...4.3 [4.3]: https://github.com/troglobit/finit/compare/4.2...4.3
+1 -1
View File
@@ -1,5 +1,5 @@
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+8 -5
View File
@@ -22,11 +22,10 @@ Introduction
------------ ------------
Fast init for Linux systems. Reverse engineered from the [EeePC Fast init for Linux systems. Reverse engineered from the [EeePC
fastinit][] over ten years ago by [Claudio Matsuoka][] — "gaps filled fastinit][] by [Claudio Matsuoka][] — "gaps filled with frog DNA …"
with frog DNA …"
![Alpine screenshot](img/finit4-screenshot.png) ![Alpine screenshot](img/alpine-screenshot2.png)
*Figure 1: Screenshot showing Finit booting [Alpine Linux](https://www.alpinelinux.org/).* *Figure 1: Screenshot of Finit booting [Alpine Linux (HowTo)](https://github.com/troglobit/finit/tree/master/contrib/alpine).*
Features include: Features include:
@@ -65,7 +64,9 @@ distributions:
> **Note:** support for various Linux distributions does not mean Finit > **Note:** support for various Linux distributions does not mean Finit
> installs easily on all architectures. The bundled install scripts are > installs easily on all architectures. The bundled install scripts are
> examples for standard installations, tested on amd64 (x86_64) systems. > examples for standard installations, tested on amd64 (x86_64) systems.
> Custom setups, for embedded systems, can be found in [myLinux][]. > Custom setups, e.g., for embedded systems, can be found in any of the
> following [Buildroot][] based examples: [myLinux][], [Infix][], or the
> plain [br2-finit-demo](https://github.com/troglobit/br2-finit-demo).
Example Example
@@ -705,6 +706,8 @@ and proposed extensions.
[EeePC fastinit]: https://web.archive.org/web/20071208212450/http://wiki.eeeuser.com/boot_process:the_boot_process [EeePC fastinit]: https://web.archive.org/web/20071208212450/http://wiki.eeeuser.com/boot_process:the_boot_process
[Claudio Matsuoka]: https://github.com/cmatsuoka [Claudio Matsuoka]: https://github.com/cmatsuoka
[Joachim Wiberg]: https://troglobit.com [Joachim Wiberg]: https://troglobit.com
[Buildroot]: https://buildroot.org
[Infix]: https://kernelkit.github.io
[finit.conf(5)]: https://man.troglobit.com/man5/finit.conf.5.html [finit.conf(5)]: https://man.troglobit.com/man5/finit.conf.5.html
[License]: https://en.wikipedia.org/wiki/MIT_License [License]: https://en.wikipedia.org/wiki/MIT_License
[License Badge]: https://img.shields.io/badge/License-MIT-teal.svg [License Badge]: https://img.shields.io/badge/License-MIT-teal.svg
+3 -2
View File
@@ -1,4 +1,4 @@
AC_INIT([Finit], [4.5], [https://github.com/troglobit/finit/issues], AC_INIT([Finit], [4.7], [https://github.com/troglobit/finit/issues],
[finit], [https://troglobit.com/projects/finit/]) [finit], [https://troglobit.com/projects/finit/])
AC_CONFIG_AUX_DIR(aux) AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects]) AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
@@ -314,7 +314,8 @@ pkglibdir=$libdir/finit
AC_SUBST(pkglibexecdir) AC_SUBST(pkglibexecdir)
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit") AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path]) AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path])
AC_DEFINE_UNQUOTED(FINIT_RUNPATH_, "$runstatedir/finit/system", [Finit runtime dynamic system services]) AC_EXPAND_DIR(finit_runpath, "$runstatedir/finit/system")
AC_DEFINE_UNQUOTED(FINIT_RUNPATH_, "$finit_runpath", [Finit runtime dynamic system services])
AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins") AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins")
AC_SUBST(plugin_path) AC_SUBST(plugin_path)
+2 -2
View File
@@ -1,5 +1,5 @@
HowTo: Finit on Alpine Linux 3.4-3.6 HowTo: Finit on Alpine Linux 3.4...3.19
==================================== =======================================
HowTo use Finit to boot an [Alpine Linux][] system. It is assumed that HowTo use Finit to boot an [Alpine Linux][] system. It is assumed that
the user has already installed make, a compiler, C library header files, the user has already installed make, a compiler, C library header files,
+1 -2
View File
@@ -1,8 +1,7 @@
SUBDIRS = available SUBDIRS = available
docsdir := @docdir@/contrib/alpine/finit.d docsdir := @docdir@/contrib/alpine/finit.d
d_LINKS = acpid.conf crond.conf dropbear.conf getty.conf \ d_LINKS = acpid.conf crond.conf dropbear.conf getty.conf \
keymap.conf modules.conf ntpd.conf \ keymap.conf modules.conf ntpd.conf syslogd.conf
klogd.conf syslogd.conf
install-exec-hook: install-exec-hook:
@$(MKDIR_P) $(DESTDIR)$(docsdir)/available @$(MKDIR_P) $(DESTDIR)$(docsdir)/available
+1 -1
View File
@@ -1,4 +1,4 @@
docsdir := @docdir@/contrib/alpine/finit.d/available docsdir := @docdir@/contrib/alpine/finit.d/available
docs_DATA = acpid.conf crond.conf dropbear.conf getty.conf keymap.conf \ docs_DATA = acpid.conf crond.conf dropbear.conf getty.conf keymap.conf \
lxdm.conf modules.conf ntpd.conf syslog.conf watchdog.conf lxdm.conf modules.conf ntpd.conf syslogd.conf watchdog.conf
EXTRA_DIST = $(docs_DATA) EXTRA_DIST = $(docs_DATA)
@@ -4,4 +4,4 @@
#module evdev #module evdev
#module mousedev #module mousedev
#module 8139cp #module 8139cp
module softdog #module softdog
+35 -29
View File
@@ -1,45 +1,53 @@
#!/bin/sh #!/bin/sh
if [ "x`id -u`" != "x0" ]; then if [ "$(id -u)" != "0" ]; then
echo printf "\n\e[1m*** This script must run as root\e[0m\n\n"
echo "*** This script must run as root"
echo
exit 1 exit 1
fi fi
# shellcheck disable=SC3037,SC3045,SC2154
yorn()
{
printf "\e[1m> %s (y/N)?\e[0m " "$*"
read -rn1 yorn
echo
if [ "$yorn" = "y" ] || [ "$yorn" = "Y" ]; then
return 0
fi
return 1
}
# Adjust base directory # Adjust base directory
grep -q alpine Makefile 2>/dev/null if grep -q contrib/alpine Makefile 2>/dev/null; then
if [ $? -eq 0 ]; then
cd ../.. cd ../..
elif [ ! -e configure.ac ]; then fi
echo "*** Please run this script from the Finit base directory."
if [ ! -e configure.ac ]; then
printf "\n\e[1m*** Please run this script from the Finit base directory.\e[0m\n"
exit 1 exit 1
fi fi
echo printf "\n\e[1mInstall Finit on Alpine Linux\n"
echo "*** Install Finit on Alpine Linux" printf "========================================================================\e[0m\n"
echo "========================================================================" printf "/sbin/finit - PID 1\n"
echo "/sbin/finit - PID 1" printf "/lib/finit/plugins/* - All enabled Finit plugins\n"
echo "/lib/finit/plugins/* - All enabled Finit plugins" printf "/etc/finit.conf - Finit configuration file\n"
echo "/etc/finit.conf - Finit configuration file" printf "/etc/finit.d/ - Finit services\n"
echo "/etc/finit.d/ - Finit services"
echo
read -p "Do you want to continue (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then if yorn "Do you want to continue"; then
echo printf "\n\e[1m*** Installing Finit files ...\e[0m\n"
echo "*** Installing Finit files ..."
make install make install
cd /usr/share/doc/finit/contrib/alpine cd /usr/share/doc/finit/contrib/alpine || exit 1
for file in finit.conf rc.local; do for file in finit.conf rc.local; do
install -vbD $file /etc/$file install -vbD $file /etc/$file
done done
cp -va finit.d /etc/ cp -va finit.d /etc/
read -p "*** Install Finit as the system default Init (y/N)? " yorn if yorn "Install Finit as the system default Init"; then
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then printf "\e[1m*** Updating /sbin/init symlink --> finit ...\e[0m\n"
echo "*** Updating /sbin/init symlink --> finit ..." cd /sbin || exit 1
cd /sbin
rm init rm init
ln -s finit init ln -s finit init
@@ -48,10 +56,8 @@ if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
ln -s reboot shutdown ln -s reboot shutdown
ln -s reboot suspend ln -s reboot suspend
fi fi
echo "*** Done" printf "\n\e[1m*** Done\e[0m\n"
echo echo
else else
echo printf "\n\e[1m*** Aborting install.\e[0m\n\n"
echo "*** Aborting install."
echo
fi fi
+24 -6
View File
@@ -356,17 +356,31 @@ most notably systemd and s6, other methods for signaling "readiness"
arrived and daemons were adapted to these new schemes to a larger arrived and daemons were adapted to these new schemes to a larger
extent. extent.
As of Finit v4.4 partial support for systemd and s6 is available. The As of Finit v4.4 partial support for systemd and s6 style readiness
native PID file mode of operation is still default, the other's can be notification is available, and the native PID file mode of operation is,
defined per service, like this: as of Finit v4.6 optional, by default it is still enabled, but this can
be changed in `finit.conf`:
readiness none
This will be made the default in Finit 5.0. In this mode of operation,
every service needs to explicitly declare their readiness notification,
like this:
service notify:pid watchdogd
service notify:systemd foo service notify:systemd foo
service notify:s6 bar service notify:s6 bar
service notify:none qux
The `notify:none` syntax is for completeness in systems which run in
`readiness pid` mode (default). Services declared with `notify:none`
will assert ready condition as soon as Finit has started them, e.g.,
`service/qux/ready`.
To synchronize two services the following condition can be used: To synchronize two services the following condition can be used:
service notify:systemd A service notify:pid watchdogd
service <service/A/ready> B service <service/watchdogd/ready> stress-ng --cpu 8
For details on the syntax and options, see below. For details on the syntax and options, see below.
@@ -445,7 +459,7 @@ Cgroups
There are three major cgroup configuration directives: There are three major cgroup configuration directives:
1. Global top-level group: init, system, user, or a custom group 1. Global top-level group: `init`, `system`, `user`, or a custom group
2. Selecting a top-level group for a set of run/task/services 2. Selecting a top-level group for a set of run/task/services
3. Per run/task/service limits 3. Per run/task/service limits
@@ -496,6 +510,10 @@ except for expanding the shorthand `mem.` to `memory.`, if the file is
not available, either the cgroup controller is not available in your not available, either the cgroup controller is not available in your
Linux kernel, or the name is misspelled. Linux kernel, or the name is misspelled.
A daemon using `SCHED_RR` currently need to run outside the default cgroups.
service [...] <...> cgroup.root /path/to/daemon arg -- Real-Time process
> Linux cgroups and details surrounding values are not explained in the > Linux cgroups and details surrounding values are not explained in the
> Finit documentation. The Linux admin-guide cover this well: > Finit documentation. The Linux admin-guide cover this well:
> <https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html> > <https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+1 -1
View File
@@ -1,6 +1,6 @@
/* Save and restore ALSA sound settings using alsactl /* Save and restore ALSA sound settings using alsactl
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Setup necessary system files for, e.g. UTMP (tracking logins) /* Setup necessary system files for, e.g. UTMP (tracking logins)
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+3 -3
View File
@@ -1,6 +1,6 @@
/* Setup and start system message bus, D-Bus /* Setup and start system message bus, D-Bus
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -150,11 +150,11 @@ static void setup(void *arg)
* Note: dbus drops privs after starting up. * Note: dbus drops privs after starting up.
*/ */
if (pidfn) { if (pidfn) {
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus pid:!%s %s %s -- %s", snprintf(line, sizeof(line), "[S123456789] cgroup.system notify:none name:dbus pid:!%s %s %s -- %s",
pidfn, cmd, DBUS_ARGS, DBUS_DESC); pidfn, cmd, DBUS_ARGS, DBUS_DESC);
free(pidfn); free(pidfn);
} else } else
snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s", snprintf(line, sizeof(line), "[S123456789] cgroup.system notify:none name:dbus %s %s -- %s",
cmd, DBUS_ARGS, DBUS_DESC); cmd, DBUS_ARGS, DBUS_DESC);
conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf"); conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf");
+3 -4
View File
@@ -1,6 +1,6 @@
/* Coldplug modules using modalias magic /* Coldplug modules using modalias magic
* *
* Copyright (c) 2021-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2021-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -132,11 +132,10 @@ static FILE *maybe_fopen_alias(const char *file, const char *path)
{ {
const char *basename; const char *basename;
basename = rindex(path, '/'); basename = basenm(path);
if (!basename) if (!strcmp(basename, path))
return NULL; return NULL;
basename++;
if (strcmp(file, basename)) if (strcmp(file, basename))
return NULL; return NULL;
+1 -1
View File
@@ -2,7 +2,7 @@
/* Netlink plugin for IFUP/IFDN and GW events /* Netlink plugin for IFUP/IFDN and GW events
* *
* Copyright (C) 2009-2011 Mårten Wikström <marten.wikstrom@keystream.se> * Copyright (C) 2009-2011 Mårten Wikström <marten.wikstrom@keystream.se>
* Copyright (C) 2009-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (C) 2009-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+11 -10
View File
@@ -1,7 +1,7 @@
/* Simple pidfile event monitor for the Finit condition engine /* Simple pidfile event monitor for the Finit condition engine
* *
* Copyright (c) 2015-2016 Tobias Waldekranz <tobias@waldekranz.com> * Copyright (c) 2015-2016 Tobias Waldekranz <tobias@waldekranz.com>
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -79,7 +79,7 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
return; return;
} }
dbg("Found svc %s for %s with pid %d", svc->name, fn, svc->pid); dbg("Found svc %s for %s with pid %d", svc_ident(svc, NULL, 0), fn, svc->pid);
mkcond(svc, cond, sizeof(cond)); mkcond(svc, cond, sizeof(cond));
if (mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) { if (mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) {
@@ -88,7 +88,7 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
* systemd style services rely on their respective * systemd style services rely on their respective
* readiness notification. Issue #343 * readiness notification. Issue #343
*/ */
if (!svc->notify) if (svc->notify == SVC_NOTIFY_PID)
svc_started(svc); svc_started(svc);
if (!svc_has_pidfile(svc)) { if (!svc_has_pidfile(svc)) {
@@ -120,13 +120,14 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
} }
} }
cond_set(cond); if (svc->notify == SVC_NOTIFY_PID)
if (!svc->notify) cond_set(cond);
service_ready(svc); if (svc->notify == SVC_NOTIFY_PID || svc->notify == SVC_NOTIFY_NONE)
service_ready(svc, 1);
} else if (mask & IN_DELETE) { } else if (mask & IN_DELETE) {
cond_clear(cond); cond_clear(cond);
if (!svc->notify) if (svc->notify == SVC_NOTIFY_PID)
service_ready(svc); service_ready(svc, 0);
} }
} }
@@ -240,8 +241,8 @@ static void pidfile_reconf(void *arg)
if (svc_is_changed(svc) || svc_is_starting(svc)) if (svc_is_changed(svc) || svc_is_starting(svc))
continue; continue;
if (!svc->notify) if (svc->notify == SVC_NOTIFY_PID)
service_ready(svc); service_ready(svc, 1);
mkcond(svc, cond, sizeof(cond)); mkcond(svc, cond, sizeof(cond));
if (cond_get(cond) == COND_ON) if (cond_get(cond) == COND_ON)
+1 -1
View File
@@ -1,6 +1,6 @@
/* Set kernel variables from /etc/sysctl.conf et al /* Set kernel variables from /etc/sysctl.conf et al
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Setup necessary files for resolvconf /* Setup necessary files for resolvconf
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Save and restore RTC using hwclock /* Save and restore RTC using hwclock
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* System condition event monitor for the Finit condition engine /* System condition event monitor for the Finit condition engine
* *
* Copyright (c) 2021-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2021-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Optional TTY Watcher, used to catch new TTYs that are discovered, e.g., USB /* Optional TTY Watcher, used to catch new TTYs that are discovered, e.g., USB
* *
* Copyright (c) 2013 Mattias Walström <lazzer@gmail.com> * Copyright (c) 2013 Mattias Walström <lazzer@gmail.com>
* Copyright (c) 2013-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2013-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Setup and save random seed at boot/shutdown /* Setup and save random seed at boot/shutdown
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* User-defined condition event monitor for the Finit condition engine /* User-defined condition event monitor for the Finit condition engine
* *
* Copyright (c) 2021-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2021-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Console setup (for X) /* Console setup (for X)
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* External client API, using UNIX domain socket. /* External client API, using UNIX domain socket.
* *
* Copyright (c) 2015-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2015-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Finit control group support functions /* Finit control group support functions
* *
* Copyright (c) 2019-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2019-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Finit control group support functions /* Finit control group support functions
* *
* Copyright (c) 2019-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2019-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* New client tool, replaces old /dev/initctl API and telinit tool /* New client tool, replaces old /dev/initctl API and telinit tool
* *
* Copyright (c) 2019-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2019-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Cgroup utility functions for initctl /* Cgroup utility functions for initctl
* *
* Copyright (c) 2019-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2019-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* External client API, using UNIX domain socket. /* External client API, using UNIX domain socket.
* *
* Copyright (c) 2015-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2015-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* External client API, using UNIX domain socket. /* External client API, using UNIX domain socket.
* *
* Copyright (c) 2015-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2015-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+36 -6
View File
@@ -1,6 +1,6 @@
/* Parser for /etc/finit.conf and /etc/finit.d/<SVC>.conf /* Parser for /etc/finit.conf and /etc/finit.d/<SVC>.conf
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -545,6 +545,23 @@ static void parse_env(char *line)
*end-- = 0; *end-- = 0;
} }
/* strip any leading 'set ' */
end = key;
if (!strncmp(key, "set", 3))
end += 3;
/* check key, no spaces allowed */
while (*end && isspace(*end))
end++;
key = end;
while (*end && !isspace(*end))
end++;
if (*end != 0) {
warnx("'%s=%s': not a valid identifier", key, val);
return; /* invalid key */
}
dbg("Global env '%s'='%s'", key, val);
setenv(key, val, 1); setenv(key, val, 1);
node = malloc(sizeof(*node)); node = malloc(sizeof(*node));
@@ -958,6 +975,18 @@ static int parse_static(char *line, int is_rcsd)
return 0; return 0;
} }
/*
* Before Finit 5 the default readiness notification is PID.
* This default can be changed by setting 'readiness none' in
* the file /etc/finit.conf, only read once at bootstrap.
*/
if (BOOTSTRAP && MATCH_CMD(line, "readiness ", x)) {
char *token = strip_line(x);
if (!strcmp(token, "none"))
readiness = SVC_NOTIFY_NONE;
}
if (MATCH_CMD(line, "reboot-delay ", x)) { if (MATCH_CMD(line, "reboot-delay ", x)) {
syncsec = strtonum(strip_line(x), 0, 60, NULL); syncsec = strtonum(strip_line(x), 0, 60, NULL);
return 0; return 0;
@@ -1282,7 +1311,7 @@ int conf_reload(void)
if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) && if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) &&
strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_))) strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_)))
continue; continue;
if (strcmp(basename(path), basename(gl.gl_pathv[j]))) if (strcmp(basenm(path), basenm(gl.gl_pathv[j])))
continue; continue;
path = NULL; /* replacement later in list, skip this */ path = NULL; /* replacement later in list, skip this */
break; break;
@@ -1393,7 +1422,8 @@ static int conf_change_act(char *dir, char *name, uint32_t mask)
struct conf_change *node; struct conf_change *node;
char *rp = NULL; char *rp = NULL;
if (name[0]) /* Check for actual printable characters, sometimes STX */
if (name[0] && name[0] >= ' ')
paste(fn, sizeof(fn), dir, name); paste(fn, sizeof(fn), dir, name);
else else
strlcpy(fn, dir, sizeof(fn)); strlcpy(fn, dir, sizeof(fn));
@@ -1579,7 +1609,7 @@ int conf_init(uev_ctx_t *ctx)
*/ */
#ifdef WDT_DEVNODE #ifdef WDT_DEVNODE
if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) { if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) {
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit " conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init notify:none name:watchdog :finit "
FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", "watchdogd.conf"); FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", "watchdogd.conf");
} }
#endif #endif
@@ -1587,7 +1617,7 @@ int conf_init(uev_ctx_t *ctx)
* Start kernel event daemon as soon as possible, if enabled * Start kernel event daemon as soon as possible, if enabled
*/ */
if (whichp(FINIT_EXECPATH_ "/keventd")) if (whichp(FINIT_EXECPATH_ "/keventd"))
conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init " conf_save_service(SVC_TYPE_SERVICE, "[S12345789] cgroup.init notify:none "
FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", "keventd.conf"); FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", "keventd.conf");
dbg("Allow plugins to register early runlevel 1 run/task/services ..."); dbg("Allow plugins to register early runlevel 1 run/task/services ...");
@@ -1621,7 +1651,7 @@ int conf_init(uev_ctx_t *ctx)
if (runparts_sysv) if (runparts_sysv)
strlcat(args, "-s ", sizeof(args)); strlcat(args, "-s ", sizeof(args));
snprintf(conf, sizeof(conf), "[S] <int/bootstrap> log:console %s %s %s" snprintf(conf, sizeof(conf), "[S] <int/bootstrap> notify:none log:console %s %s %s"
" -- Calling runparts %s in the background", " -- Calling runparts %s in the background",
_PATH_RUNPARTS, args, runparts, runparts); _PATH_RUNPARTS, args, runparts, runparts);
conf_save_service(SVC_TYPE_TASK, conf, "runparts.conf"); conf_save_service(SVC_TYPE_TASK, conf, "runparts.conf");
+1 -1
View File
@@ -1,6 +1,6 @@
/* Parser for /etc/finit.conf and /etc/finit.d/<SVC>.conf /* Parser for /etc/finit.conf and /etc/finit.d/<SVC>.conf
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Device node monitor for the Finit condition engine /* Device node monitor for the Finit condition engine
* *
* Copyright (c) 2022-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2022-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Device node monitor for the Finit condition engine /* Device node monitor for the Finit condition engine
* *
* Copyright (c) 2022-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2022-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Functions for exec'ing processes /* Functions for exec'ing processes
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+14 -5
View File
@@ -1,7 +1,7 @@
/* Finit - Fast /sbin/init replacement w/ I/O, hook & service plugins /* Finit - Fast /sbin/init replacement w/ I/O, hook & service plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -69,6 +69,7 @@ int single = 0; /* single user mode from kernel cmdline */
int bootstrap = 1; /* set while bootrapping (for TTYs) */ int bootstrap = 1; /* set while bootrapping (for TTYs) */
int kerndebug = 0; /* set if /proc/sys/kernel/printk > 7 */ int kerndebug = 0; /* set if /proc/sys/kernel/printk > 7 */
int syncsec = 0; /* reboot delay */ int syncsec = 0; /* reboot delay */
int readiness = SVC_NOTIFY_PID;
char *finit_conf= NULL; char *finit_conf= NULL;
char *finit_rcsd= NULL; char *finit_rcsd= NULL;
char *fstab = NULL; char *fstab = NULL;
@@ -354,6 +355,8 @@ static void fs_remount_root(int fsckerr)
*/ */
static void fs_finalize(void) static void fs_finalize(void)
{ {
int flags = MS_NOEXEC | MS_NOSUID;
/* /*
* Some systems rely on us to both create /dev/shm and, to mount * Some systems rely on us to both create /dev/shm and, to mount
* a tmpfs there. Any system with dbus needs shared memory, so * a tmpfs there. Any system with dbus needs shared memory, so
@@ -361,8 +364,8 @@ static void fs_finalize(void)
* the /etc/fstab file already. * the /etc/fstab file already.
*/ */
if (!fismnt("/dev/shm")) { if (!fismnt("/dev/shm")) {
makedir("/dev/shm", 0777); makedir("/dev/shm", 1777);
fs_mount("shm", "/dev/shm", "tmpfs", 0, "mode=0777"); fs_mount("shm", "/dev/shm", "tmpfs", flags | MS_NODEV, "mode=1777");
} }
/* Modern systems use /dev/pts */ /* Modern systems use /dev/pts */
@@ -380,7 +383,13 @@ static void fs_finalize(void)
snprintf(opts, sizeof(opts), "gid=%d,mode=%d,ptmxmode=0666", gid, mode); snprintf(opts, sizeof(opts), "gid=%d,mode=%d,ptmxmode=0666", gid, mode);
makedir("/dev/pts", 0755); makedir("/dev/pts", 0755);
fs_mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, opts); fs_mount("devpts", "/dev/pts", "devpts", flags, opts);
}
/* Needed on systems like Alpine Linux */
if (!fismnt("/dev/mqueue")) {
makedir("/dev/mqueue", 1777);
fs_mount("mqueue", "/dev/mqueue", "tmpfs", flags | MS_NODEV, NULL);
} }
/* /*
@@ -697,7 +706,7 @@ int main(int argc, char *argv[])
/* Some bootstrap tasks may need to know if we're in a container. */ /* Some bootstrap tasks may need to know if we're in a container. */
if (in_container()) if (in_container())
cond_set("int/container"); cond_set_oneshot("int/container");
/* /*
* Initialize .conf system and load static /etc/finit.conf then * Initialize .conf system and load static /etc/finit.conf then
+2 -1
View File
@@ -1,7 +1,7 @@
/* Finit - Fast /sbin/init replacement w/ I/O, hook & service plugins /* Finit - Fast /sbin/init replacement w/ I/O, hook & service plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -121,6 +121,7 @@ extern int single;
extern int bootstrap; extern int bootstrap;
extern int kerndebug; extern int kerndebug;
extern int syncsec; extern int syncsec;
extern int readiness;
extern char *fstab; extern char *fstab;
extern char *sdown; extern char *sdown;
extern char *network; extern char *network;
+1 -1
View File
@@ -1,6 +1,6 @@
/* Initialize and serve a login terminal /* Initialize and serve a login terminal
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Misc. utility functions for finit and its plugins /* Misc. utility functions for finit and its plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Misc. utility functions and C-library extensions for finit and its plugins /* Misc. utility functions and C-library extensions for finit and its plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* New client tool, replaces old /dev/initctl API and telinit tool /* New client tool, replaces old /dev/initctl API and telinit tool
* *
* Copyright (c) 2015-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2015-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* New client tool, replaces old /dev/initctl API and telinit tool /* New client tool, replaces old /dev/initctl API and telinit tool
* *
* Copyright (c) 2015-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2015-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* inotify watcher for files or directories /* inotify watcher for files or directories
* *
* Copyright (c) 2015-2016 Tobias Waldekranz <tobias@waldekranz.com> * Copyright (c) 2015-2016 Tobias Waldekranz <tobias@waldekranz.com>
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* inotify watcher for files or directories /* inotify watcher for files or directories
* *
* Copyright (c) 2015-2016 Tobias Waldekranz <tobias@waldekranz.com> * Copyright (c) 2015-2016 Tobias Waldekranz <tobias@waldekranz.com>
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Listens to kernel events like AC power status and manages sys/ conditions /* Listens to kernel events like AC power status and manages sys/ conditions
* *
* Copyright (c) 2021-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2021-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Finit daemon log functions /* Finit daemon log functions
* *
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Finit daemon log functions /* Finit daemon log functions
* *
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2018-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2018-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+8 -6
View File
@@ -1,6 +1,6 @@
/* Handle MD arrays /* Handle MD arrays
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include "helpers.h" #include "helpers.h"
#include "util.h"
static glob_t *get_arrays(void) static glob_t *get_arrays(void)
@@ -48,17 +49,18 @@ static glob_t *get_arrays(void)
*/ */
void mdadm_wait(void) void mdadm_wait(void)
{ {
size_t i;
glob_t *gl; glob_t *gl;
char cmd[160];
/* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */
gl = get_arrays(); gl = get_arrays();
if (gl) { if (gl) {
for (i = 0; i < gl->gl_pathc; i++) { size_t i;
char *array;
array = basename(gl->gl_pathv[i]); for (i = 0; i < gl->gl_pathc; i++) {
const char *array;
char cmd[160];
array = basenm(gl->gl_pathv[i]);
snprintf(cmd, sizeof(cmd), "mdadm --wait-clean /dev/%s >/dev/null", array); snprintf(cmd, sizeof(cmd), "mdadm --wait-clean /dev/%s >/dev/null", array);
run_interactive(cmd, "Marking MD array %s as clean", array); run_interactive(cmd, "Marking MD array %s as clean", array);
} }
+1 -1
View File
@@ -1,6 +1,6 @@
/* Mount and unmount helpers /* Mount and unmount helpers
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* PID and PID file helpers /* PID and PID file helpers
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* PID and PID file helpers /* PID and PID file helpers
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+13 -9
View File
@@ -1,6 +1,6 @@
/* Plugin based services architecture for finit /* Plugin based services architecture for finit
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -43,6 +43,7 @@
#include "private.h" #include "private.h"
#include "service.h" #include "service.h"
#include "sig.h" #include "sig.h"
#include "util.h"
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd > 0) #define is_io_plugin(p) ((p)->io.cb && (p)->io.fd > 0)
#define SEARCH_PLUGIN(str) \ #define SEARCH_PLUGIN(str) \
@@ -77,23 +78,26 @@ static char *trim_ext(char *name)
int plugin_register(plugin_t *plugin) int plugin_register(plugin_t *plugin)
{ {
const char *nm;
if (!plugin) { if (!plugin) {
errno = EINVAL; errno = EINVAL;
return 1; return 1;
} }
/* Setup default name if none is provided */ /* Setup default name if none is provided */
if (!plugin->name) { nm = plugin->name;
if (!nm) {
#ifndef ENABLE_STATIC #ifndef ENABLE_STATIC
Dl_info info; Dl_info info;
if (dladdr(plugin, &info) && info.dli_fname) if (dladdr(plugin, &info) && info.dli_fname)
plugin->name = basename(info.dli_fname); nm = basenm(info.dli_fname);
#endif #endif
if (!plugin->name) if (!nm)
plugin->name = "unknown"; nm = "unknown";
} }
plugin->name = trim_ext(strdup(plugin->name)); plugin->name = trim_ext(strdup(nm));
/* Already registered? */ /* Already registered? */
if (plugin_find(plugin->name)) { if (plugin_find(plugin->name)) {
@@ -253,7 +257,7 @@ void plugin_run_hook(hook_point_t no, void *arg)
PLUGIN_ITERATOR(p, tmp) { PLUGIN_ITERATOR(p, tmp) {
if (p->hook[no].cb) { if (p->hook[no].cb) {
dbg("Calling %s hook n:o %d (arg: %p) ...", basename(p->name), no, arg ?: "NIL"); dbg("Calling %s hook n:o %d (arg: %p) ...", basenm(p->name), no, arg ?: "NIL");
p->hook[no].cb(arg ? arg : p->hook[no].arg); p->hook[no].cb(arg ? arg : p->hook[no].arg);
} }
} }
@@ -301,9 +305,9 @@ int plugin_io_init(plugin_t *p)
if (!is_io_plugin(p)) if (!is_io_plugin(p))
return 0; return 0;
dbg("Initializing plugin %s for I/O", basename(p->name)); dbg("Initializing plugin %s for I/O", basenm(p->name));
if (uev_io_init(ctx, &p->watcher, generic_io_cb, p, p->io.fd, p->io.flags)) { if (uev_io_init(ctx, &p->watcher, generic_io_cb, p, p->io.fd, p->io.flags)) {
warn("Failed setting up I/O plugin %s", basename(p->name)); warn("Failed setting up I/O plugin %s", basenm(p->name));
return 1; return 1;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
/* Plugin based services architecture for finit /* Plugin based services architecture for finit
* *
* Copyright (c) 2012-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2012-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Private header file for main finit daemon, not for plugins /* Private header file for main finit daemon, not for plugins
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* reboot, halt, poweroff, shutdown, suspend for finit /* reboot, halt, poweroff, shutdown, suspend for finit
* *
* Copyright (c) 2009-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2009-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Work queue helper functions /* Work queue helper functions
* *
* Copyright (c) 2018-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2018-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Work queue helper functions /* Work queue helper functions
* *
* Copyright (c) 2018-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2018-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* List and enable/disable service configurations /* List and enable/disable service configurations
* *
* Copyright (c) 2017-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2017-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* List and enable/disable service configurations /* List and enable/disable service configurations
* *
* Copyright (c) 2017-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2017-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+96 -58
View File
@@ -1,7 +1,7 @@
/* Finit service monitor, task starter and generic API for managing svc_t /* Finit service monitor, task starter and generic API for managing svc_t
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -330,14 +330,15 @@ static int lredirect(svc_t *svc)
snprintf(rot, sizeof(rot), "%d:%d", logfile_size_max, logfile_count_max); snprintf(rot, sizeof(rot), "%d:%d", logfile_size_max, logfile_count_max);
snprintf(pid, sizeof(pid), "%d", svc_pid); snprintf(pid, sizeof(pid), "%d", svc_pid);
execlp("logger", "logger", "-f", svc->log.file, "-b", "-t", tag, "-p", prio, debug ? "-s" : "", "-I", pid, "-r", rot, NULL); execlp("logger", "logger", "-f", svc->log.file, "-b", "-t", tag, "-p", prio, "-I", pid, "-r", rot, debug ? "-s" : NULL, NULL);
} else { } else {
char sz[20], num[3]; char sz[20], num[3];
snprintf(sz, sizeof(sz), "%d", logfile_size_max); snprintf(sz, sizeof(sz), "%d", logfile_size_max);
snprintf(num, sizeof(num), "%d", logfile_count_max); snprintf(num, sizeof(num), "%d", logfile_count_max);
execlp(_PATH_LOGIT, "logit", "-f", svc->log.file, "-n", sz, "-r", num, debug ? "-s" : "", NULL); execlp(_PATH_LOGIT, "logit", "-f", svc->log.file, "-n", sz, "-r", num, debug ? "-s" : NULL, NULL);
} }
_exit(1); _exit(1);
} }
@@ -351,9 +352,9 @@ static int lredirect(svc_t *svc)
char pid[16]; char pid[16];
snprintf(pid, sizeof(pid), "%d", svc_pid); snprintf(pid, sizeof(pid), "%d", svc_pid);
execlp("logger", "logger", "-t", tag, "-p", prio, debug ? "-s" : "", "-I", pid, NULL); execlp("logger", "logger", "-t", tag, "-p", prio, "-I", pid, debug ? "-s" : NULL, NULL);
} else { } else {
execlp(_PATH_LOGIT, "logit", "-t", tag, "-p", prio, debug ? "-s" : "", NULL); execlp(_PATH_LOGIT, "logit", "-t", tag, "-p", prio, debug ? "-s" : NULL, NULL);
} }
_exit(1); _exit(1);
} }
@@ -394,11 +395,8 @@ static int redirect(svc_t *svc)
*/ */
static void source_env(svc_t *svc) static void source_env(svc_t *svc)
{ {
char buf[LINE_SIZE]; char *buf, *val, *line, *fn;
char *line;
size_t len;
FILE *fp; FILE *fp;
char *fn;
fn = svc_getenv(svc); fn = svc_getenv(svc);
if (!fn) if (!fn)
@@ -409,12 +407,19 @@ static void source_env(svc_t *svc)
if (!fp) if (!fp)
return; return;
buf = alloca(LINE_SIZE);
val = alloca(LINE_SIZE);
if (!buf || !val) {
warn("Failed allocating temporary env buffer");
return;
}
line = buf; line = buf;
len = sizeof(buf); while (fgets(line, LINE_SIZE, fp)) {
while (fgets(line, len, fp)) {
char *key = chomp(line); char *key = chomp(line);
wordexp_t we = { 0 }; wordexp_t we = { 0 };
char *value, *end; char *value, *end;
size_t i;
/* skip any leading whitespace */ /* skip any leading whitespace */
while (isspace(*key)) while (isspace(*key))
@@ -467,9 +472,30 @@ static void source_env(svc_t *svc)
*end-- = 0; *end-- = 0;
} }
/* strip any leading 'set ' */
end = key;
if (!strncmp(key, "set", 3))
end += 3;
/* check key, no spaces allowed */
while (*end && isspace(*end))
end++;
key = end;
while (*end && !isspace(*end))
end++;
if (*end != 0) {
warnx("'%s=%s': not a valid identifier", key, val);
continue; /* invalid key */
}
switch (wordexp(value, &we, 0)) { switch (wordexp(value, &we, 0)) {
case 0: case 0:
setenv(key, we.we_wordv[0], 1); for (i = 0, *val = 0; i < we.we_wordc; i++) {
if (i > 0)
strlcat(val, " ", LINE_SIZE);
strlcat(val, we.we_wordv[i], LINE_SIZE);
}
setenv(key, val, 1);
wordfree(&we); wordfree(&we);
break; break;
@@ -692,11 +718,12 @@ static int service_start(svc_t *svc)
wordexp_t we = { 0 }; wordexp_t we = { 0 };
int rc; int rc;
if (svc->notify) { if (svc->notify == SVC_NOTIFY_SYSTEMD || svc->notify == SVC_NOTIFY_S6) {
if (client_command(INIT_CMD_NOTIFY_SOCKET)) { if (client_command(INIT_CMD_NOTIFY_SOCKET)) {
err(1, "%s: failed creating notify socket", svc_ident(svc, NULL, 0)); err(1, "%s: failed creating notify socket", svc_ident(svc, NULL, 0));
client_disconnect(); client_disconnect();
svc->notify = 0; /* does not change parent, restarting may work. */ /* does not change parent, restarting may work. */
svc->notify = SVC_NOTIFY_NONE;
} else { } else {
char val[20]; char val[20];
@@ -721,7 +748,7 @@ static int service_start(svc_t *svc)
if (len == 0) if (len == 0)
break; break;
if (svc->notify) { if (svc->notify == SVC_NOTIFY_SYSTEMD || svc->notify == SVC_NOTIFY_S6) {
char *ptr = strstr(arg, "%n"); char *ptr = strstr(arg, "%n");
if (ptr) { if (ptr) {
@@ -898,6 +925,19 @@ static void service_kill(svc_t *svc)
print(2, NULL); print(2, NULL);
} }
/* Ensure we don't have any notify socket lingering */
static void service_notify_stop(svc_t *svc)
{
if (svc->notify != SVC_NOTIFY_SYSTEMD && svc->notify != SVC_NOTIFY_S6)
return;
uev_io_stop(&svc->notify_watcher);
if (svc->notify_watcher.fd > 0) {
close(svc->notify_watcher.fd);
svc->notify_watcher.fd = 0;
}
}
/* /*
* Clean up any lingering state from dead/killed services * Clean up any lingering state from dead/killed services
*/ */
@@ -913,12 +953,7 @@ static void service_cleanup(svc_t *svc)
logit(LOG_CRIT, "Failed removing service %s pidfile %s", logit(LOG_CRIT, "Failed removing service %s pidfile %s",
svc_ident(svc, NULL, 0), fn); svc_ident(svc, NULL, 0), fn);
/* Ensure we don't have any notify socket lingering */ service_notify_stop(svc);
if (svc->notify && svc->notify_watcher.fd > 0) {
uev_io_stop(&svc->notify_watcher);
close(svc->notify_watcher.fd);
svc->notify_watcher.fd = 0;
}
/* No longer running, update books. */ /* No longer running, update books. */
if (svc_is_tty(svc) && svc->pid > 1) if (svc_is_tty(svc) && svc->pid > 1)
@@ -968,7 +1003,7 @@ int service_stop(svc_t *svc)
return 0; return 0;
} }
dbg("Sending %s to pid:%d name:%s", sig, svc->pid, nm); dbg("Sending %s to pid:%d name:%s(%s)", sig, svc->pid, id, nm);
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending %s ...", id, svc->pid, sig); logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending %s ...", id, svc->pid, sig);
} else { } else {
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s stop' ...", cmdline); logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s stop' ...", cmdline);
@@ -1179,13 +1214,15 @@ static void parse_log(svc_t *svc, char *arg)
} }
} }
static int parse_notify(char *arg) static svc_notify_t parse_notify(char *arg)
{ {
if (!strcmp(arg, "systemd")) if (!strcmp(arg, "systemd"))
return 1; return SVC_NOTIFY_SYSTEMD;
if (!strcmp(arg, "s6")) if (!strcmp(arg, "s6"))
return 2; return SVC_NOTIFY_S6;
return 0; /* unsupported/disabled */ if (!strcmp(arg, "pid"))
return SVC_NOTIFY_PID;
return SVC_NOTIFY_NONE; /* unsupported/none */
} }
static void parse_env(svc_t *svc, char *env) static void parse_env(svc_t *svc, char *env)
@@ -1584,7 +1621,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
strlcat(ident, id, sizeof(ident)); strlcat(ident, id, sizeof(ident));
} }
if (ifstmt && !svc_ifthen(1, ident, ifstmt)) if (ifstmt && !svc_ifthen(1, ident, ifstmt, nowarn))
return 0; return 0;
levels = conf_parse_runlevels(runlevels); levels = conf_parse_runlevels(runlevels);
@@ -1750,17 +1787,12 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
else else
svc->log.enabled = 0; svc->log.enabled = 0;
} }
if (notify) {
int type = parse_notify(notify);
if (type <= 0) if (notify)
goto disable_notify; svc->notify = parse_notify(notify);
svc->notify = type; else
} else if (svc->notify) { svc->notify = readiness;
disable_notify:
/* XXX: close existing socket */
svc->notify = 0;
}
if (desc) if (desc)
strlcpy(svc->desc, desc, sizeof(svc->desc)); strlcpy(svc->desc, desc, sizeof(svc->desc));
else if (type == SVC_TYPE_TTY) else if (type == SVC_TYPE_TTY)
@@ -1996,7 +2028,7 @@ void service_mark_unavail(void)
if (!svc->ifstmt[0]) if (!svc->ifstmt[0])
continue; continue;
if (!svc_ifthen(1, svc_ident(svc, buf, sizeof(buf)), svc->ifstmt)) if (!svc_ifthen(1, svc_ident(svc, buf, sizeof(buf)), svc->ifstmt, svc->nowarn))
svc_mark(svc); svc_mark(svc);
} }
} }
@@ -2298,8 +2330,8 @@ void service_forked(svc_t *svc)
svc_set_state(svc, SVC_RUNNING_STATE); svc_set_state(svc, SVC_RUNNING_STATE);
} }
/* Set service/foo/ready condition for services and call optional ready:script */ /* Set or clear service/foo/ready condition for services and call optional ready:script */
void service_ready(svc_t *svc) void service_ready(svc_t *svc, int ready)
{ {
char buf[MAX_COND_LEN]; char buf[MAX_COND_LEN];
@@ -2307,10 +2339,13 @@ void service_ready(svc_t *svc)
return; return;
snprintf(buf, sizeof(buf), "service/%s/ready", svc_ident(svc, NULL, 0)); snprintf(buf, sizeof(buf), "service/%s/ready", svc_ident(svc, NULL, 0));
cond_set(buf); if (ready) {
cond_set(buf);
if (svc_has_ready(svc)) if (svc_has_ready(svc))
service_ready_script(svc); service_ready_script(svc);
} else
cond_clear(buf);
} }
/* /*
@@ -2364,11 +2399,7 @@ restart:
char condstr[MAX_COND_LEN]; char condstr[MAX_COND_LEN];
dbg("%s: stopped, cleaning up timers and conditions ...", svc_ident(svc, NULL, 0)); dbg("%s: stopped, cleaning up timers and conditions ...", svc_ident(svc, NULL, 0));
if (svc->notify && svc->notify_watcher.fd > 0) { service_notify_stop(svc);
uev_io_stop(&svc->notify_watcher);
close(svc->notify_watcher.fd);
svc->notify_watcher.fd = 0;
}
service_timeout_cancel(svc); service_timeout_cancel(svc);
cond_clear(mkcond(svc, condstr, sizeof(condstr))); cond_clear(mkcond(svc, condstr, sizeof(condstr)));
@@ -2522,6 +2553,8 @@ restart:
svc_mark_clean(svc); svc_mark_clean(svc);
} }
if (svc->notify == SVC_NOTIFY_NONE)
service_ready(svc, 1);
break; break;
} }
break; break;
@@ -2546,16 +2579,21 @@ restart:
svc_set_state(svc, SVC_RUNNING_STATE); svc_set_state(svc, SVC_RUNNING_STATE);
/* Reassert condition if we go from waiting and no change */ /* Reassert condition if we go from waiting and no change */
if (!svc_is_changed(svc)) { if (!svc_is_changed(svc)) {
char name[MAX_COND_LEN]; if (svc->notify == SVC_NOTIFY_PID) {
char name[MAX_COND_LEN];
mkcond(svc, name, sizeof(name)); mkcond(svc, name, sizeof(name));
dbg("Reassert condition %s", name); dbg("Reassert condition %s", name);
cond_set_path(cond_path(name), COND_ON); cond_set_path(cond_path(name), COND_ON);
}
dbg("Reassert %s ready condition", svc_ident(svc, NULL, 0));
service_ready(svc, 1);
} }
break; break;
case COND_OFF: case COND_OFF:
dbg("Condition for %s is off, sending SIGCONT + SIGTERM", svc->name); dbg("Condition for %s is off, sending SIGCONT + SIGTERM", svc_ident(svc, NULL, 0));
kill(svc->pid, SIGCONT); kill(svc->pid, SIGCONT);
service_stop(svc); service_stop(svc);
break; break;
@@ -2677,16 +2715,16 @@ void service_notify_reconf(void)
svc_t *svc, *iter = NULL; svc_t *svc, *iter = NULL;
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) { for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (!svc->notify) if (svc->notify == SVC_NOTIFY_PID)
continue; /* managed by pidfile plugin */ continue; /* managed by pidfile plugin */
if (svc->state != SVC_RUNNING_STATE) if (svc->state != SVC_RUNNING_STATE)
continue; continue;
if (svc_is_changed(svc) || svc_is_starting(svc)) if (svc->notify != SVC_NOTIFY_NONE && (svc_is_changed(svc) || svc_is_starting(svc)))
continue; continue;
service_ready(svc); service_ready(svc, 1);
} }
} }
@@ -2727,10 +2765,10 @@ void service_notify_cb(uev_t *w, void *arg, int events)
* the service_notify_reconf() function to step the * the service_notify_reconf() function to step the
* generation of the READY condition. * generation of the READY condition.
*/ */
service_ready(svc); service_ready(svc, 1);
/* s6 applications close their socket after notification */ /* s6 applications close their socket after notification */
if (svc->notify == 2) { if (svc->notify == SVC_NOTIFY_S6) {
uev_io_stop(w); uev_io_stop(w);
close(w->fd); close(w->fd);
w->fd = 0; w->fd = 0;
+2 -2
View File
@@ -1,7 +1,7 @@
/* Finit service monitor, task starter and generic API for managing svc_t /* Finit service monitor, task starter and generic API for managing svc_t
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -42,7 +42,7 @@ int service_timeout_after (svc_t *svc, int timeout, void (*cb)(svc_t *svc
int service_timeout_cancel (svc_t *svc); int service_timeout_cancel (svc_t *svc);
void service_forked (svc_t *svc); void service_forked (svc_t *svc);
void service_ready (svc_t *svc); void service_ready (svc_t *svc, int ready);
int service_stop (svc_t *svc); int service_stop (svc_t *svc);
int service_step (svc_t *svc); int service_step (svc_t *svc);
+1 -1
View File
@@ -1,7 +1,7 @@
/* Signal management - Be conservative with what finit responds to! /* Signal management - Be conservative with what finit responds to!
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Signal management - Be conservative with what finit responds to! /* Signal management - Be conservative with what finit responds to!
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -216,7 +216,7 @@ restart:
service_step_all(SVC_TYPE_ANY); service_step_all(SVC_TYPE_ANY);
/* Allow runparts to start */ /* Allow runparts to start */
cond_set("int/bootstrap"); cond_set_oneshot("int/bootstrap");
if (sm->newlevel == -1) if (sm->newlevel == -1)
break; break;
+1 -1
View File
@@ -1,6 +1,6 @@
/* Reset terminal line settings (stty sane) /* Reset terminal line settings (stty sane)
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* poor man's sulogin, may be statically linked /* poor man's sulogin, may be statically linked
* *
* Copyright (c) 2021-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2021-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+8 -5
View File
@@ -1,7 +1,7 @@
/* Low-level service primitives and generic API for managing svc_t structures /* Low-level service primitives and generic API for managing svc_t structures
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -649,7 +649,7 @@ int svc_enabled(svc_t *svc)
return 0; return 0;
} }
if (!svc_ifthen(0, NULL, svc->ifstmt)) { if (!svc_ifthen(0, NULL, svc->ifstmt, svc->nowarn)) {
// dbg("ifthen:%s>", svc->ifstmt[0] ? svc->ifstmt : "<"); // dbg("ifthen:%s>", svc->ifstmt[0] ? svc->ifstmt : "<");
return 0; return 0;
} }
@@ -704,11 +704,12 @@ int svc_conflicts(svc_t *svc)
* @is_conf: Set when called by service_mark_unavail() * @is_conf: Set when called by service_mark_unavail()
* @ident: svc_t identififcation (name:id) * @ident: svc_t identififcation (name:id)
* @stmt: if: statement from .conf file * @stmt: if: statement from .conf file
* @quiet: If non-zero, do not warn in syslog
* *
* Returns: * Returns:
* %TRUE(1) yes, use this svc_t, %FALSE(0) prune * %TRUE(1) yes, use this svc_t, %FALSE(0) prune
*/ */
int svc_ifthen(int is_conf, const char *ident, char *stmt) int svc_ifthen(int is_conf, const char *ident, char *stmt, int quiet)
{ {
char stmts[MAX_IDENT_LEN]; char stmts[MAX_IDENT_LEN];
int not = 0; int not = 0;
@@ -758,11 +759,13 @@ int svc_ifthen(int is_conf, const char *ident, char *stmt)
svc = svc_find_by_str(stmt); svc = svc_find_by_str(stmt);
if (not && svc) { if (not && svc) {
logit(LOG_NOTICE, "skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0)); if (!quiet)
logit(LOG_NOTICE, "skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0));
return 0; return 0;
} }
if (!not && !svc) { if (!not && !svc) {
logit(LOG_NOTICE, "skipping %s, %s not available.", ident, stmt); if (!quiet)
logit(LOG_NOTICE, "skipping %s, %s not available.", ident, stmt);
return 0; return 0;
} }
} }
+11 -3
View File
@@ -1,7 +1,7 @@
/* Low-level service primitives and generic API for managing svc_t structures /* Low-level service primitives and generic API for managing svc_t structures
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2008-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -83,6 +83,14 @@ typedef enum {
SVC_ONCRASH_SCRIPT, SVC_ONCRASH_SCRIPT,
} svc_oncrash_action_t; } svc_oncrash_action_t;
/* 0: none, 1: systemd, 2: s6 */
typedef enum {
SVC_NOTIFY_NONE = 0,
SVC_NOTIFY_PID,
SVC_NOTIFY_SYSTEMD,
SVC_NOTIFY_S6,
} svc_notify_t;
#define MAX_ID_LEN 16 #define MAX_ID_LEN 16
#define MAX_ARG_LEN 64 #define MAX_ARG_LEN 64
#define MAX_CMD_LEN 256 #define MAX_CMD_LEN 256
@@ -202,7 +210,7 @@ typedef struct svc {
/* /*
* Readiness notification socket: systemd, s6 * Readiness notification socket: systemd, s6
*/ */
int notify; /* 0: none, 1: systemd, 2: s6 */ svc_notify_t notify;
uev_t notify_watcher; /* i/o watcher */ uev_t notify_watcher; /* i/o watcher */
/* time at svc_del(), used by gc timer */ /* time at svc_del(), used by gc timer */
@@ -241,7 +249,7 @@ void svc_prune_bootstrap (void);
void svc_enable (svc_t *svc); void svc_enable (svc_t *svc);
int svc_enabled (svc_t *svc); int svc_enabled (svc_t *svc);
int svc_conflicts (svc_t *svc); int svc_conflicts (svc_t *svc);
int svc_ifthen (int is_conf, const char *ident, char *stmt); int svc_ifthen (int is_conf, const char *ident, char *stmt, int quiet);
int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *)); int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *));
+4 -4
View File
@@ -1,6 +1,6 @@
/* Limited tmpfiles.d implementation /* Limited tmpfiles.d implementation
* *
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -78,8 +78,8 @@ static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct
if (ftw->level == 0) if (ftw->level == 0)
return 1; return 1;
if (remove(fpath)) if (remove(fpath) && errno != EBUSY)
warn("Failed removing condition %s", fpath); warn("Failed removing %s", fpath);
return 0; return 0;
@@ -492,7 +492,7 @@ void tmpfilesd(void)
/* check for overrides */ /* check for overrides */
for (j = i + 1; j < gl.gl_pathc; j++) { for (j = i + 1; j < gl.gl_pathc; j++) {
if (strcmp(basename(fn), basename(gl.gl_pathv[j]))) if (strcmp(basenm(fn), basenm(gl.gl_pathv[j])))
continue; continue;
fn = NULL; fn = NULL;
break; break;
+1 -1
View File
@@ -1,6 +1,6 @@
/* Limited tmpfiles.d implementation /* Limited tmpfiles.d implementation
* *
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Finit TTY handling /* Finit TTY handling
* *
* Copyright (c) 2013 Mattias Walström <lazzer@gmail.com> * Copyright (c) 2013 Mattias Walström <lazzer@gmail.com>
* Copyright (c) 2013-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2013-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,7 +1,7 @@
/* Finit TTY handling /* Finit TTY handling
* *
* Copyright (c) 2013 Mattias Walström <lazzer@gmail.com> * Copyright (c) 2013 Mattias Walström <lazzer@gmail.com>
* Copyright (c) 2013-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2013-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+14 -1
View File
@@ -1,6 +1,6 @@
/* Misc. shared utility functions for initctl, reboot and finit /* Misc. shared utility functions for initctl, reboot and finit
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -151,6 +151,19 @@ char *progname(char *arg0)
return prognm; return prognm;
} }
/* basename(3) replacement that does not modify its argument */
const char *basenm(const char *path)
{
const char *basename;
basename = rindex(path, '/');
if (!basename)
return path;
basename++;
return basename;
}
char *str(char *fmt, ...) char *str(char *fmt, ...)
{ {
static char buf[32]; static char buf[32];
+2 -1
View File
@@ -1,6 +1,6 @@
/* Misc. shared utility functions for initctl, reboot and finit /* Misc. shared utility functions for initctl, reboot and finit
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -55,6 +55,7 @@ extern char *prognm;
#endif #endif
char *progname (char *arg0); char *progname (char *arg0);
const char *basenm (const char *path);
char *str (char *fmt, ...) __attribute__ ((format (printf, 1, 2))); char *str (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int fnread (char *buf, size_t len, char *fmt, ...) __attribute__ ((format (printf, 3, 4))); int fnread (char *buf, size_t len, char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
+1 -1
View File
@@ -1,6 +1,6 @@
/* UTMP API /* UTMP API
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* UTMP API /* UTMP API
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Built-in watchdog daemon /* Built-in watchdog daemon
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Built-in watchdog daemon /* Built-in watchdog daemon
* *
* Copyright (c) 2016-2023 Joachim Wiberg <troglobit@gmail.com> * Copyright (c) 2016-2024 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+9 -9
View File
@@ -18,23 +18,23 @@
# change the contents any way you like, it can even be empty. # change the contents any way you like, it can even be empty.
# Check for systemd-udevd and eudev, if we find both, we opt for the latter. # Check for systemd-udevd and eudev, if we find both, we opt for the latter.
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log /lib/systemd/systemd-udevd -- Device event daemon (udev) service nowarn [S12345789] cgroup.system name:udevd notify:none pid:udevd log /lib/systemd/systemd-udevd -- Device event daemon (udev)
service nowarn [S12345789] cgroup.system name:udevd pid:udevd log udevd -D -- Device event daemon (udev) service nowarn [S12345789] cgroup.system name:udevd notify:none pid:udevd log udevd -D -- Device event daemon (udev)
# Wait for udevd to start, then trigger coldplug events and module loading. # Wait for udevd to start, then trigger coldplug events and module loading.
# The last 'settle' call waits for it to finalize processing all uevents. # The last 'settle' call waits for it to finalize processing all uevents.
run nowarn if:udevd cgroup.init :1 [S] <pid/udevd> log udevadm settle -t 0 -- run nowarn if:udevd cgroup.init :1 [S] <service/udevd/ready> 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 :2 [S] <service/udevd/ready> 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 :3 [S] <service/udevd/ready> 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 :4 [S] <service/udevd/ready> log udevadm trigger -c add -t subsystems -- Requesting subsystem events
run nowarn if:udevd cgroup.init :5 [S] <pid/udevd> log udevadm settle -t 30 -- Waiting for udev to finish run nowarn if:udevd cgroup.init :5 [S] <service/udevd/ready> log udevadm settle -t 30 -- Waiting for udev to finish
# If udevd is not available, check for mdevd. Unlike plain 'mdev -df', the # If udevd is not available, check for mdevd. Unlike plain 'mdev -df', the
# mdevd-coldplug process exits when mdevd has completed. So the condition # mdevd-coldplug process exits when mdevd has completed. So the condition
# <run/coldplug/success> (same as for plain mdev below) can be relied on as a # <run/coldplug/success> (same as for plain mdev below) can be relied on as a
# barrier for services that, e.g., need to probe for switchcore ports or PHYs # barrier for services that, e.g., need to probe for switchcore ports or PHYs
# that require firmware loading before they show up. # that require firmware loading before they show up.
service nowarn conflict:udevd,mdev cgroup.init if:!udevd \ service nowarn conflict:udevd,mdev cgroup.init notify:none if:!udevd \
[S12345789] notify:s6 mdevd -O 4 -D %n -- Device event daemon (mdevd) [S12345789] notify:s6 mdevd -O 4 -D %n -- Device event daemon (mdevd)
run nowarn conflict:udevd,mdev cgroup.init name:coldplug <service/mdevd/ready> \ run nowarn conflict:udevd,mdev cgroup.init name:coldplug <service/mdevd/ready> \
[S] mdevd-coldplug -- Cold plugging system [S] mdevd-coldplug -- Cold plugging system
@@ -42,7 +42,7 @@ run nowarn conflict:udevd,mdev cgroup.init name:coldplug <service/mdevd/read
# If neither udevd or mdevd are available, fall back to mdev. The new daemon # If neither udevd or mdevd are available, fall back to mdev. The new daemon
# mode calls `mdev -s` internally but does not create a PID file when that is # mode calls `mdev -s` internally but does not create a PID file when that is
# done, so synchronization with coldplug is fragile. # done, so synchronization with coldplug is fragile.
service nowarn conflict:udevd,mdevd cgroup.init if:!udevd,!mdevd \ service nowarn conflict:udevd,mdevd cgroup.init notify:none if:!udevd,!mdevd \
[S12345789] mdev -df -S -- Device event daemon (mdev) [S12345789] mdev -df -S -- Device event daemon (mdev)
# Trigger a replay of all uevents from boot, before userspace was up and the # Trigger a replay of all uevents from boot, before userspace was up and the
+1 -1
View File
@@ -1,4 +1,4 @@
# Test service, only used for `make check`, not for public use # Test service, only used for `make check`, not for public use
service [S123456789] name:testserv pid:!/run/testserv.pid \ service [S123456789] name:testserv pid:!/run/testserv.pid \
<boot/testserv> cgroup.system \ <boot/testserv> cgroup.system notify:none \
/sbin/serv -n -p -i testserv -- Test serv daemon /sbin/serv -n -p -i testserv -- Test serv daemon
+2
View File
@@ -38,6 +38,7 @@ EXTRA_DIST += initctl-status-subset.sh
EXTRA_DIST += notify.sh EXTRA_DIST += notify.sh
EXTRA_DIST += pidfile.sh EXTRA_DIST += pidfile.sh
EXTRA_DIST += pre-post-serv.sh EXTRA_DIST += pre-post-serv.sh
EXTRA_DIST += process-depends.sh
EXTRA_DIST += rclocal.sh EXTRA_DIST += rclocal.sh
EXTRA_DIST += ready-serv.sh EXTRA_DIST += ready-serv.sh
EXTRA_DIST += restart-self.sh EXTRA_DIST += restart-self.sh
@@ -83,6 +84,7 @@ TESTS += initctl-status-subset.sh
TESTS += notify.sh TESTS += notify.sh
TESTS += pidfile.sh TESTS += pidfile.sh
TESTS += pre-post-serv.sh TESTS += pre-post-serv.sh
TESTS += process-depends.sh
TESTS += rclocal.sh TESTS += rclocal.sh
TESTS += ready-serv.sh TESTS += ready-serv.sh
TESTS += restart-self.sh TESTS += restart-self.sh
+3
View File
@@ -80,6 +80,9 @@ test_one()
say "Done, drop stanza from $TEST_CONF ..." say "Done, drop stanza from $TEST_CONF ..."
run "rm $TEST_CONF" run "rm $TEST_CONF"
run "initctl reload" run "initctl reload"
# Done, disable debug
run "initctl debug"
} }
+9 -3
View File
@@ -2,6 +2,11 @@
set -eu set -eu
TEST_DIR=$(dirname "$0") TEST_DIR=$(dirname "$0")
# shellcheck disable=SC2034
BOOTSTRAP="foo=bar\n\
set COLORTERM=yes\n\
b aq=oroszoe\n\
baz=qux"
test_setup() test_setup()
{ {
@@ -19,13 +24,14 @@ test_teardown()
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh" . "$TEST_DIR/lib/setup.sh"
say "Waiting for runlevel 2"
sleep 2
#run "initctl debug" #run "initctl debug"
say "Add custom envs to $FINIT_CONF ..."
run "echo 'foo=bar' > $FINIT_CONF"
run "echo 'baz=qux' >> $FINIT_CONF"
say "Add service stanza to $FINIT_CONF ..." say "Add service stanza to $FINIT_CONF ..."
run "echo 'service serv -np -e foo:bar -- Verify foo=bar' >> $FINIT_CONF" run "echo 'service serv -np -e foo:bar -- Verify foo=bar' >> $FINIT_CONF"
#run "cat $FINIT_CONF"
say 'Reload Finit' say 'Reload Finit'
run "initctl reload" run "initctl reload"
+8
View File
@@ -96,6 +96,14 @@ assert_nocond()
assert "Condition $cond cleared" "$(texec initctl -v cond get "$cond")" = "off" assert "Condition $cond cleared" "$(texec initctl -v cond get "$cond")" = "off"
} }
assert_ready()
{
srv=$1
cond="service/$srv/ready"
assert "$cond asserted" "$(texec initctl cond dump |grep "<$cond>" |awk '{print $3}')" = "on"
}
assert_is_pidfile() assert_is_pidfile()
{ {
assert "Process has PID file: $2" "$(texec initctl -p status "$1" | awk '/PID file/{print $4}')" = "$2" assert "Process has PID file: $2" "$(texec initctl -p status "$1" | awk '/PID file/{print $4}')" = "$2"
+2 -2
View File
@@ -74,7 +74,7 @@ test_one()
# Issue #343; pidfile.so inadvertedly marked systemd services as # Issue #343; pidfile.so inadvertedly marked systemd services as
# 'started' when they created their PID file. The serv test daemon # 'started' when they created their PID file. The serv test daemon
# waits 3 sec between pidfile and notify to trigger this bug. # waits 3 sec between pidfile and notify to trigger this bug.
if [ "$type" != "native" ]; then if [ "$type" != "pid" ]; then
say "Verify 'ready' is *not* asserted immediately on restart + reload" say "Verify 'ready' is *not* asserted immediately on restart + reload"
run "initctl restart serv" run "initctl restart serv"
run "initctl reload" run "initctl reload"
@@ -103,7 +103,7 @@ test_one()
#run "initctl debug" #run "initctl debug"
test_one "native" "service log:stdout serv -np -- pid file readiness" test_one "pid" "service log:stdout notify:pid serv -np -- pid file readiness"
test_one "s6" "service log:stdout notify:s6 serv -n -N %n -- s6 readiness" test_one "s6" "service log:stdout notify:s6 serv -n -N %n -- s6 readiness"
test_one "systemd" "service log:stdout notify:systemd serv -n -- systemd readiness" test_one "systemd" "service log:stdout notify:systemd serv -n -- systemd readiness"
+66
View File
@@ -0,0 +1,66 @@
#!/bin/sh
# Regression test for issue #392
set -eu
#set -x
TEST_DIR=$(dirname "$0")
test_setup()
{
say "Test start $(date)"
run "mkdir -p /etc/default"
}
test_teardown()
{
say "Test done $(date)"
say "Running test teardown."
run "rm -f $FINIT_CONF"
}
srv()
{
say "Adding service $(echo "$1" | sed -n -e 's/^.*-- //p')"
run "echo '$1' >> $FINIT_CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
#run "initctl debug"
# Test systemd notify
srv 'service name:test1_systemd [2345] notify:systemd restart:0 serv -i test1 -n -- Systemd proc'
srv 'service name:test2 [2345] <service/test1_systemd/ready> serv -i test2 -np -- Dependency test 1'
# Test pid notify
srv "service name:test3_pid [2345] notify:pid <service/test1_systemd/ready> serv -i test3 -np -- Dependency test 2"
srv "service name:test4 [2345] <service/test3_pid/ready> serv -i test4 -np -- Dependency test 3"
sep "$FINIT_CONF"
run "cat $FINIT_CONF"
sep
say 'Reload Finit'
run "initctl reload"
say "Waiting for all services to start"
retry 'assert_status "test4" "running"' 5 1
# Load bearing debug. Without this the bug cannot be reproduced!
run "initctl debug"
sep
say "Stopping root service, all others should also stop"
run "initctl stop test1_systemd"
retry 'assert_status "test3_pid" "waiting"' 5 1
sep
say "Verify test4 does not restart"
run "initctl status"
run "initctl cond dump"
assert_status "test4" "waiting"
return 0
+8 -4
View File
@@ -19,9 +19,10 @@ test_teardown()
test_one() test_one()
{ {
service=$1 service=$(echo "$1" | tr -s " ")
file=/tmp/ready file=/tmp/ready
sep
say "Add service stanza '$service' to $FINIT_CONF ..." say "Add service stanza '$service' to $FINIT_CONF ..."
run "echo '$service' > $FINIT_CONF" run "echo '$service' > $FINIT_CONF"
@@ -29,6 +30,9 @@ test_one()
run "initctl reload" run "initctl reload"
retry 'assert_num_children 1 serv' retry 'assert_num_children 1 serv'
retry 'assert_ready "serv"' 5 1
# run "initctl status"
# run "initctl cond dump"
assert_file_contains "$file" "READY" assert_file_contains "$file" "READY"
run "rm -f $file" run "rm -f $file"
@@ -46,6 +50,6 @@ test_one()
#run "initctl debug" #run "initctl debug"
test_one "service ready:/bin/ready.sh serv -np -- Native style notification" test_one "service ready:/bin/ready.sh serv -np -- Native PID style notification"
test_one "service notify:s6 ready:/bin/ready.sh serv -np -N %n -- s6 style notification" test_one "service notify:s6 ready:/bin/ready.sh serv -n -N %n -- s6 style notification"
test_one "service notify:systemd ready:/bin/ready.sh serv -np -- systemd style notification" test_one "service notify:systemd ready:/bin/ready.sh serv -n -- systemd style notification"
+2
View File
@@ -5,3 +5,5 @@ foo=bar
baz=qux baz=qux
xyzzy=$foo xyzzy=$foo
FOO_ARGS="-i $foo -l $xyzzy endarg"
+1 -1
View File
@@ -22,7 +22,7 @@ test_teardown()
sep "/etc/env:" sep "/etc/env:"
run "cat /etc/env" run "cat /etc/env"
run "echo 'service env:/etc/env serv -np -e xyzzy:bar -- serv checks xyzzy=bar' > $FINIT_CONF" run "echo 'service env:/etc/env serv -np -e xyzzy:bar -e \"FOO_ARGS:-i bar -l bar endarg\" -- serv checks xyzzy=bar' > $FINIT_CONF"
say 'Reload Finit' say 'Reload Finit'
run "initctl reload" run "initctl reload"
+13 -12
View File
@@ -14,10 +14,10 @@ TEST_DIR=$(dirname "$0")
test_setup() test_setup()
{ {
run "cat >> $FINIT_CONF" <<EOF run "cat >> $FINIT_CONF" <<EOF
service log:stdout name:A serv -np -i A service log:stdout notify:pid name:A serv -np -i A -- A (pid)
service log:stdout notify:systemd <pid/A> name:B serv -np -i B -N 0 -- B needs A service log:stdout notify:systemd <pid/A> name:B serv -np -i B -N 0 -- B needs A (systemd)
service log:stdout notify:systemd <service/B/ready> name:C serv -np -i C -N 0 -- C needs B(service) service log:stdout notify:s6 <service/B/ready> name:C serv -np -i C -N 0 -- C needs B (s6)
service log:stdout notify:systemd <pid/B> name:D serv -np -i D -N 0 -- D needs B(pid) service log:stdout notify:none <pid/A> name:D type:forking serv -i D -- D needs A (forking)
task <service/C/ready,service/D/ready> name:allup initctl cond set allup -- Everything is up task <service/C/ready,service/D/ready> name:allup initctl cond set allup -- Everything is up
EOF EOF
say "Test start $(date)" say "Test start $(date)"
@@ -41,17 +41,18 @@ run "cat $FINIT_CONF"
sep sep
run "initctl reload" run "initctl reload"
run "initctl status" run "initctl status"
run "initctl cond dump"
sep sep
run "initctl debug"
say "waiting for primary startup to complete" say "waiting for primary startup to complete"
retry 'assert_status allup "done"' 100 1 retry 'assert_status allup "done"' 10 1
assert_status C "running" assert_status C "running"
oldpid=$(pidof C) oldpid=$(pidof C)
assert_status D "running"
doldpid=$(pidof D)
sep "pre-reload status" sep "pre-reload status"
run "initctl status" run "initctl status"
run "initctl cond dump"
sep sep
say "Reload Finit, who gets restarted?" say "Reload Finit, who gets restarted?"
@@ -59,15 +60,15 @@ say "Reload Finit, who gets restarted?"
run "initctl reload" run "initctl reload"
sleep 2 sleep 2
sep "post-reload status"
run "initctl status"
run "initctl cond dump"
sep
assert_status A "running" assert_status A "running"
assert_status B "running" assert_status B "running"
assert_status C "running" assert_status C "running"
assert_status D "running"
newpid=$(pidof C) newpid=$(pidof C)
# shellcheck disable=SC2086 # shellcheck disable=SC2086
assert "C was not restarted" $oldpid -eq $newpid assert "C was not restarted" $oldpid -eq $newpid
dnewpid=$(pidof D)
# shellcheck disable=SC2086
assert "D was not restarted" $doldpid -eq $dnewpid

Some files were not shown because too many files have changed in this diff Show More