mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d8fcfdf13 | ||
|
|
e4830c5614 | ||
|
|
f33261af6b | ||
|
|
e7516f2b63 | ||
|
|
d18167fe1d | ||
|
|
7d3f95c0a9 | ||
|
|
86c5bbb03d | ||
|
|
7530bb74f6 | ||
|
|
54dd726d16 | ||
|
|
bd9bb92ca0 | ||
|
|
01cb088e51 | ||
|
|
3d91112e0d | ||
|
|
16aef80682 | ||
|
|
fd34914936 | ||
|
|
21a890a04e | ||
|
|
7f5f7e8ef6 | ||
|
|
ff937576ea | ||
|
|
7d831170ae | ||
|
|
6a21ac55ad | ||
|
|
a0820c7f20 | ||
|
|
6d58c9ed0b | ||
|
|
bc2ffbc767 | ||
|
|
4c1fc2410e | ||
|
|
70e1aa889a | ||
|
|
c8c5e4e88a | ||
|
|
86c1398778 | ||
|
|
b37fa2b417 | ||
|
|
a91e197553 | ||
|
|
5adb92ca1b | ||
|
|
cfc99c4e8b | ||
|
|
3e51ed1c55 | ||
|
|
b5df0a6274 | ||
|
|
cbe8d56042 | ||
|
|
a3ec792b44 | ||
|
|
c24855d4d5 | ||
|
|
014e457fda | ||
|
|
21d89c7e24 | ||
|
|
639fb76f5a | ||
|
|
30c189b116 | ||
|
|
e2a8803f7a | ||
|
|
209e140ddd | ||
|
|
2e3fa72924 | ||
|
|
1502838a0d | ||
|
|
377c8bce8c | ||
|
|
a39d958d25 | ||
|
|
7f8a96a73e | ||
|
|
5c2577214d | ||
|
|
f03206a694 | ||
|
|
f0e328edc9 | ||
|
|
13342f2bd9 | ||
|
|
c926160853 | ||
|
|
462d5b22b4 | ||
|
|
b1bfab08f3 | ||
|
|
aeb48ef04b | ||
|
|
b8b200ad75 | ||
|
|
c148d8d783 | ||
|
|
27ba3b27f5 | ||
|
|
b4af86255d | ||
|
|
01a007b388 | ||
|
|
0e28741dcb | ||
|
|
c993feeb44 | ||
|
|
ec17f0aa23 | ||
|
|
6baf2990e8 | ||
|
|
6416e2a1a4 | ||
|
|
7c42986800 | ||
|
|
6f802a7ff1 | ||
|
|
879721839e | ||
|
|
20290a4166 | ||
|
|
ba77e4f217 | ||
|
|
e7b18feca5 | ||
|
|
4a90a3e8ef | ||
|
|
6d14ff84d3 | ||
|
|
89cc6017df | ||
|
|
f6fafdbd23 | ||
|
|
3480e42687 | ||
|
|
053c1643a7 | ||
|
|
2018cac050 | ||
|
|
f9090f535d | ||
|
|
10577f3e48 | ||
|
|
07f7caef0d | ||
|
|
093b3ba467 | ||
|
|
c63279630b | ||
|
|
4755e5206b | ||
|
|
2002157032 | ||
|
|
094e00d405 | ||
|
|
e01836c506 | ||
|
|
685f332c6e | ||
|
|
ae09272bcc | ||
|
|
d16f7e0c88 | ||
|
|
063d645d95 | ||
|
|
f87e9d8880 | ||
|
|
e8099f1bfa | ||
|
|
7dc7f9a968 | ||
|
|
996ab8c6c6 | ||
|
|
16c2198304 | ||
|
|
ecca01dea0 | ||
|
|
bda3cdd3ad | ||
|
|
4811f76294 | ||
|
|
0aba704312 | ||
|
|
57329832d0 | ||
|
|
078a1d0c95 | ||
|
|
0e695aa0c7 | ||
|
|
f7a1514131 | ||
|
|
11bc87ecc3 | ||
|
|
e1c59a2515 | ||
|
|
2faefd44a2 | ||
|
|
6fa3aa41df | ||
|
|
ef9e9ec786 | ||
|
|
d77e3a6113 | ||
|
|
0b1258b44c | ||
|
|
62dad82ba8 | ||
|
|
5423b5b0a2 | ||
|
|
6b10174bcb | ||
|
|
ec94f4d321 | ||
|
|
69800537f2 | ||
|
|
61faedb0b5 | ||
|
|
61014431aa | ||
|
|
49bd63994c | ||
|
|
85b29d9407 | ||
|
|
b83fdea49b | ||
|
|
beec0ee590 | ||
|
|
4121113688 | ||
|
|
62da379472 | ||
|
|
3c9053b055 | ||
|
|
71b07ce2bd | ||
|
|
ebea3d273e | ||
|
|
f3a76b8a63 | ||
|
|
ba93791077 | ||
|
|
b994858907 | ||
|
|
74ad34a0c5 | ||
|
|
1b5b37c06b | ||
|
|
c8e1bd0e9a | ||
|
|
e9c8d3d740 | ||
|
|
f567b866a0 | ||
|
|
3471d3ee2d | ||
|
|
6e197f5751 | ||
|
|
b568c18346 | ||
|
|
1b29876ba8 | ||
|
|
4c6f3d2d69 | ||
|
|
8d3f7eded2 | ||
|
|
0222feeda1 | ||
|
|
f10cf1a9a0 | ||
|
|
85b2089fd3 | ||
|
|
885808c64c | ||
|
|
78069b42e7 | ||
|
|
3e0063e874 | ||
|
|
6ec1ab3d4f | ||
|
|
33b4540ad9 | ||
|
|
a434b51653 | ||
|
|
222d8d3575 | ||
|
|
8e2d006048 | ||
|
|
fd9f204b6d | ||
|
|
f0f358a138 | ||
|
|
cfffcd4513 | ||
|
|
e51587c66e | ||
|
|
f930953e6a | ||
|
|
ebdc10d1c5 | ||
|
|
d12370568f | ||
|
|
176125deca | ||
|
|
cb934ca39f | ||
|
|
4fd95fdcbe | ||
|
|
cb62349054 | ||
|
|
1b72119673 | ||
|
|
add474e825 | ||
|
|
f32e4d4b30 | ||
|
|
eff87b3dc5 | ||
|
|
ea4821fd18 | ||
|
|
6285668dcd | ||
|
|
449bc7d12b | ||
|
|
ee867e7f3b | ||
|
|
b4c7ae9c8c | ||
|
|
95995a45cf | ||
|
|
823bb82b8c | ||
|
|
9a5bb46f78 | ||
|
|
950ca953f5 | ||
|
|
495c8c9eac | ||
|
|
2887795586 | ||
|
|
6a893f50ae | ||
|
|
5d08353284 | ||
|
|
a37037ded4 | ||
|
|
d331b72dfd | ||
|
|
3b21d35f23 | ||
|
|
62a694b8b7 | ||
|
|
eeba2960f9 | ||
|
|
91550c926b | ||
|
|
184525687c | ||
|
|
cdede817fd | ||
|
|
df42c2f6fe | ||
|
|
b53f2f4a60 | ||
|
|
5ff27c4fe2 | ||
|
|
e5fff5117d | ||
|
|
615cd5aac3 | ||
|
|
621d95a89e | ||
|
|
cd383167f9 | ||
|
|
cb2969002c | ||
|
|
1cf204e23d | ||
|
|
393834b253 | ||
|
|
4ca8256e18 | ||
|
|
280d91b9bf | ||
|
|
980152fd53 | ||
|
|
d994420d4d | ||
|
|
38f3ecf01f | ||
|
|
5cd0d05b31 | ||
|
|
62519c3638 | ||
|
|
27bb2deb1a | ||
|
|
a2c8e71f14 | ||
|
|
d1f56e7c2e | ||
|
|
a9fd0cbf02 | ||
|
|
be8c89ec00 | ||
|
|
4f53752693 | ||
|
|
393673222d | ||
|
|
a88f4524d5 | ||
|
|
3a02066a66 | ||
|
|
7e3981d1a3 | ||
|
|
ec2900e4dd | ||
|
|
d718a27abf | ||
|
|
db8027911c | ||
|
|
aef3b4117d | ||
|
|
6728b77aca | ||
|
|
a7c0b42965 | ||
|
|
667b6ecbbd | ||
|
|
b852878a4a | ||
|
|
940f1f7486 | ||
|
|
49c705b5ad | ||
|
|
5163e8a433 | ||
|
|
71e9603e4e | ||
|
|
c71102f44e | ||
|
|
9b9158a765 | ||
|
|
595e2b4e81 | ||
|
|
ae8e205343 | ||
|
|
00b33fbd42 | ||
|
|
841b06df37 | ||
|
|
522a06f864 | ||
|
|
fa14ed1649 | ||
|
|
64e41e066b | ||
|
|
2a71f35005 | ||
|
|
961a337a5e | ||
|
|
f0622a692e | ||
|
|
ef7042dd9d | ||
|
|
046ecfa329 | ||
|
|
47fbe49861 | ||
|
|
2f34315634 |
@@ -0,0 +1,70 @@
|
||||
name: Bob the Builder
|
||||
|
||||
# Run on all branches, including all pull requests, except the 'dev'
|
||||
# branch since that's where we run Coverity Scan (limited tokens/day)
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
- '!dev'
|
||||
pull_request:
|
||||
branches:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Verify we can build on latest Ubuntu with both gcc and clang
|
||||
name: ${{ matrix.compiler }}
|
||||
runs-on: ubuntu-18.04
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: [gcc, clang]
|
||||
fail-fast: false
|
||||
env:
|
||||
MAKEFLAGS: -j3
|
||||
CC: ${{ matrix.compiler }}
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y install pkg-config
|
||||
wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz
|
||||
wget https://github.com/troglobit/libite/releases/download/v2.3.1/libite-2.3.1.tar.gz
|
||||
tar xf libuev-2.3.2.tar.xz
|
||||
tar xf libite-2.3.1.tar.gz
|
||||
(cd libuev-2.3.2 && ./configure --prefix=/usr && make && sudo make install-strip)
|
||||
(cd libite-2.3.1 && ./configure --prefix=/usr && make && sudo make install-strip)
|
||||
sudo ldconfig
|
||||
- uses: actions/checkout@v2
|
||||
- name: Static Finit
|
||||
run: |
|
||||
./autogen.sh
|
||||
./configure --prefix= --enable-static
|
||||
make V=1
|
||||
- name: Regular Finit
|
||||
run: |
|
||||
./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd
|
||||
make clean
|
||||
make V=1
|
||||
- name: Install to ~/tmp and Inspect
|
||||
run: |
|
||||
DESTDIR=/tmp make install-strip
|
||||
tree /tmp
|
||||
ldd /tmp/sbin/finit
|
||||
size /tmp/sbin/finit
|
||||
ldd /tmp/sbin/initctl
|
||||
size /tmp/sbin/initctl
|
||||
ldd /tmp/sbin/reboot
|
||||
size /tmp/sbin/reboot
|
||||
/tmp/sbin/finit -h
|
||||
/tmp/sbin/initctl -h
|
||||
- name: Run Unit Tests
|
||||
run: |
|
||||
ver=$(/tmp/sbin/initctl -V | awk '/Finit.*/ {print $2;}')
|
||||
dir=finit-$ver/_build/sub
|
||||
make -j1 distcheck || (cat $dir/test/setup-root.log; cat $dir/test/test-suite.log; false)
|
||||
- name: Upload Test Results
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: finit-test-${{ matrix.compiler }}
|
||||
path: test/*
|
||||
@@ -0,0 +1,63 @@
|
||||
name: Coverity Scan
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'dev'
|
||||
|
||||
env:
|
||||
PROJECT_NAME: finit
|
||||
CONTACT_EMAIL: troglobit@gmail.com
|
||||
COVERITY_NAME: troglobit-finit
|
||||
COVERITY_PROJ: troglobit%2Ffinit
|
||||
|
||||
jobs:
|
||||
coverity:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/cache@v2
|
||||
id: coverity-toolchain-cache
|
||||
with:
|
||||
path: cov-analysis-linux64
|
||||
key: ${{ runner.os }}-coverity
|
||||
- name: Download Coverity Scan
|
||||
if: steps.coverity-toolchain-cache.outputs.cache-hit != 'true'
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
run: |
|
||||
wget -q https://scan.coverity.com/download/cxx/linux64 \
|
||||
--post-data "token=$TOKEN&project=${COVERITY_PROJ}" \
|
||||
-O cov-analysis-linux64.tar.gz
|
||||
mkdir cov-analysis-linux64
|
||||
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y install pkg-config
|
||||
wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz
|
||||
wget https://github.com/troglobit/libite/releases/download/v2.3.1/libite-2.3.1.tar.gz
|
||||
tar xf libuev-2.3.2.tar.xz
|
||||
tar xf libite-2.3.1.tar.gz
|
||||
(cd libuev-2.3.2 && ./configure --prefix=/usr && make && sudo make install-strip)
|
||||
(cd libite-2.3.1 && ./configure --prefix=/usr && make && sudo make install-strip)
|
||||
sudo ldconfig
|
||||
- name: Build
|
||||
run: |
|
||||
./autogen.sh
|
||||
./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd
|
||||
export PATH=`pwd`/cov-analysis-linux64/bin:$PATH
|
||||
cov-build --dir cov-int make
|
||||
- name: Submit result to Coverity Scan
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
run: |
|
||||
tar czvf ${PROJECT_NAME}.tgz cov-int
|
||||
curl \
|
||||
--form project=${COVERITY_NAME} \
|
||||
--form token=$TOKEN \
|
||||
--form email=${CONTACT_EMAIL} \
|
||||
--form file=@${PROJECT_NAME}.tgz \
|
||||
--form version=trunk \
|
||||
--form description="${PROJECT_NAME} $(git rev-parse HEAD)" \
|
||||
https://scan.coverity.com/builds?project=${COVERITY_PROJ}
|
||||
@@ -0,0 +1,69 @@
|
||||
name: Release General
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Create GitHub release
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
release_id: ${{ steps.create_release.outputs.id }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Extract ChangeLog entry ...
|
||||
# Hack to extract latest entry for body_path below
|
||||
run: |
|
||||
awk '/-----*/{if (x == 1) exit; x=1;next}x' ChangeLog.md \
|
||||
|head -n -1 > release.md
|
||||
cat release.md
|
||||
- name: Create release ...
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Finit v${{ github.ref }}
|
||||
body_path: release.md
|
||||
draft: false
|
||||
prerelease: false
|
||||
tarball:
|
||||
name: Build and upload release tarball
|
||||
needs: release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Installing dependencies
|
||||
run: |
|
||||
sudo apt-get -y update
|
||||
sudo apt-get -y install pkg-config
|
||||
wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz
|
||||
wget https://github.com/troglobit/libite/releases/download/v2.3.1/libite-2.3.1.tar.gz
|
||||
tar xf libuev-2.3.2.tar.xz
|
||||
tar xf libite-2.3.1.tar.gz
|
||||
(cd libuev-2.3.2 && ./configure --prefix=/usr && make && sudo make install-strip)
|
||||
(cd libite-2.3.1 && ./configure --prefix=/usr && make && sudo make install-strip)
|
||||
sudo ldconfig
|
||||
- name: Creating Makefiles
|
||||
run: |
|
||||
./autogen.sh
|
||||
./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd
|
||||
- name: Building release
|
||||
run: |
|
||||
make release
|
||||
ls -lF ../
|
||||
mkdir -p artifacts/
|
||||
mv ../*.tar.* artifacts/
|
||||
- name: Uploading release artifacts
|
||||
uses: skx/github-action-publish-binaries@release-0.15
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
releaseId: ${{ needs.release.outputs.release_id }}
|
||||
args: artifacts/*
|
||||
@@ -45,3 +45,6 @@ GTAGS
|
||||
/.autoconf
|
||||
/.automake
|
||||
/.built
|
||||
|
||||
# VS Code user settings
|
||||
.vscode
|
||||
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
# Travis CI integration -- https://travis-ci.org/troglobit/finit
|
||||
# Defaults to GNU GCC and autotools: ./configure && make && make test
|
||||
language: c
|
||||
|
||||
# Use docker for quicker builds, it now allows https://docs.travis-ci.com/user/apt/
|
||||
sudo: false
|
||||
|
||||
# Test build with both GCC and Clang (LLVM)
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
# The secure: declaration is the encrypted COVERITY_SCAN_TOKEN, created
|
||||
# via the "travis encrypt" command using the project repo's public key
|
||||
env:
|
||||
global:
|
||||
- PKG_CONFIG_PATH=/tmp/lib/pkgconfig
|
||||
- CFLAGS="-W -Wall -Wextra"
|
||||
- secure: "eOiuHs02lG2Uv146K9dMqucGTWUJFEhpz1oAtwe+kPrRXsXWc20hYMO+DSpMgD05vSvNeQA6p7h7LdRFQ+/g/Obj27TsOE+RKkUvRAtdwzxnKVyii9C/nmML8cFw7rIA0VS8O9mAkVYeyDxNDupBp3e9DPCibhKPvqCvioTnyy4="
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- tree
|
||||
coverity_scan:
|
||||
project:
|
||||
name: "troglobit/finit"
|
||||
description: "finit | Fast & Extensible init for Linux"
|
||||
notification_email: troglobit@gmail.com
|
||||
build_command_prepend: "./autogen.sh && ./configure --prefix= --disable-doc --disable-contrib --with-watchdog"
|
||||
build_command: "make"
|
||||
branch_pattern: dev
|
||||
|
||||
install:
|
||||
- wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz
|
||||
- wget https://github.com/troglobit/libite/releases/download/v2.3.1/libite-2.3.1.tar.gz
|
||||
- tar xf libuev-2.3.2.tar.xz
|
||||
- tar xf libite-2.3.1.tar.gz
|
||||
- (cd libuev-2.3.2 && ./configure --prefix=/tmp && make && make install-strip)
|
||||
- (cd libite-2.3.1 && ./configure --prefix=/tmp && make && make install-strip)
|
||||
|
||||
# Custom build script for the time being, no "make test" yet
|
||||
script:
|
||||
- ./autogen.sh
|
||||
- ./configure --prefix= --enable-static
|
||||
- make clean
|
||||
- make V=1 -j5
|
||||
- ./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd
|
||||
- cat config.log
|
||||
- make clean
|
||||
- make V=1 -j5
|
||||
- make install-strip DESTDIR=/tmp/finit
|
||||
- tree /tmp/finit
|
||||
- ldd /tmp/finit/sbin/finit
|
||||
- size /tmp/finit/sbin/finit
|
||||
- size /tmp/finit/sbin/initctl
|
||||
- size /tmp/finit/sbin/reboot
|
||||
- LD_LIBRARY_PATH=/tmp/lib /tmp/finit/sbin/initctl -h
|
||||
- unshare -V
|
||||
- nsenter -V
|
||||
- chroot --version
|
||||
- 'LD_LIBRARY_PATH=/tmp/lib make distcheck || (cat finit-4.0-beta1/_build/sub/test/test-suite.log; exit 1)'
|
||||
+135
-9
@@ -4,6 +4,130 @@ Change Log
|
||||
All relevant changes are documented in this file.
|
||||
|
||||
|
||||
[4.3][UNRELEASED]
|
||||
--------------------
|
||||
|
||||
Critical bug fix release. If you run a 32-bit target with GLIBC 2.34
|
||||
you *need* to upgrade!
|
||||
|
||||
> **Note:** system verbosity on console at start and shutdown has been
|
||||
> increased. Now the output of all commands is logged to the
|
||||
> system logger, for early services `/dev/kmsg` is used.
|
||||
>
|
||||
> **Also:** please notice the updated support for enabling and disabling
|
||||
> kernel and Finit debug messages on the system console. Very
|
||||
> useful when debugging either of them, e.g., a kernel module.
|
||||
> For details, see [cmdline.md](doc/cmdline.md).
|
||||
|
||||
### Changes
|
||||
* Loading `module`s no longer shows arguments in progress output
|
||||
* Warning messages in progress output now in yellow, not red, issue #214
|
||||
* `initctl`, new command line option `-v,--version` for ease of use
|
||||
* Extended environment variables for pre/post scripts, issue #189
|
||||
* New condition `done` for run task, issue #207 by Ming Liu, Atlas Copco
|
||||
* Refactor parts of shutdown and reboot sequence for PREEMPT-RT kernels,
|
||||
by Robert Andersson, Mathias Thore, and Ming Liu, Atlas Copco
|
||||
* Conditions for run/task/sysv status, e.g. `run/foo/success` and
|
||||
`task/bar/failure`. Issue #232, by Ming Liu, Atlas Copco
|
||||
* initctl support for sending signals to services, by Jörgen
|
||||
Sigvardsson, issue #225
|
||||
* `[WARN]` messages on console now printed in yellow, issue #214
|
||||
* Network services now also stopped when going to runlevel 6 (reboot),
|
||||
not just runlevel 0 (shutdown) or 1 (single-user)
|
||||
* When `ifup` is missing on the system, bring at least `lo` up at boot
|
||||
* Log output from `ifup -a` (and `ifdown -a`), to syslog
|
||||
* Avoid blocking PID 1 when starting SysV init scripts
|
||||
* Allow custom `pid:` for SysV init scripts
|
||||
* Document supported types of forking/non-forking services
|
||||
* Auto-detect running in some common forms of containers
|
||||
* Simplify shutdown/reboot when running in a container
|
||||
* Log to `stderr` when running in a container w/o syslog daemon
|
||||
* Add support for `type:forking` to services, already supported but
|
||||
with a very difficult `pid:` syntax. Documentation updated
|
||||
|
||||
### Fixes
|
||||
* Fix nasty 32/64-bit alignment issue between finit and its plugins,
|
||||
applicable to 32-bit targets with GLIBC 2.34 and later. External
|
||||
plugins must make sure to use, at least: `-D_TIME_BITS=64`
|
||||
* Fix #215: disable cgroup support at runtime if kernel lacks support
|
||||
or does not have the required controllers (cpu)
|
||||
* Fix #217: iwatcher initialization issue, by Ming Liu, Atlas Copco
|
||||
* Fix #218: initctl matches too many services, by Ming Liu, Atlas Copco
|
||||
* Fix #219: not all filesystems unmounted at shutdown, by Ming Liu,
|
||||
Mathias Thore, and Robert Andersson, Atlas Copco
|
||||
* Fix #226: initctl shows wrong PID for crashing services
|
||||
* Fix #227: reboot stalls if process stopped with `[WARN]`
|
||||
* Fix #233: initctl shows wrong status for run/task, by Sergio Morlans
|
||||
and Ming Liu, Atlas Copco
|
||||
* Fix start/stop of SysV init scripts
|
||||
* Fix call to `swapoff` at shutdown, does not support `-e` flag
|
||||
* Fix suspend to RAM issue. Previously `reboot(RB_SW_SUSPEND)` was
|
||||
used, now the modern `/sys/power/state` API is used instead.
|
||||
|
||||
|
||||
[4.2][] - 2022-01-16
|
||||
--------------------
|
||||
|
||||
### Changes
|
||||
* Support for non-root users to use `initctl`, e.g. group wheel
|
||||
* Support for new libite (-lite) header namespace
|
||||
* RTC plugin now reset an invalid RTC time to the kernel default
|
||||
time, 2000-01-01 00:00, prevents errors and is less crazy than
|
||||
some systems coming with with <= Jan 1, 1970
|
||||
* urandom plugin now use RNDADDENTROPY ioctl to seed kernel rng,
|
||||
incrementing entropy count. Also, 32 kiB instead of 512 bytes are
|
||||
now saved (and restored) on reboot. This should greatly improve
|
||||
reliability of systems with none or poor HWRNG
|
||||
* Kernel logging to console (loglevel >= 7, debug, when quiet mode is
|
||||
not used) is now honored by Finit, regardless of the finit.debug
|
||||
command line option
|
||||
* Reduced default log level from `LOG_NOTICE` to `LOG_INFO`
|
||||
* Wrapped all calls to mount(2) to add logging in case of failure
|
||||
* New configure options to control fastboot (no fsck) and fsck fix
|
||||
options, by Ming Liu, Atlas Copco
|
||||
* Support for overriding default `/etc/nologin` file with an external
|
||||
`#define`, by Ming Liu, Atlas Copco
|
||||
* Support for overriding default `/var/run/dbus/pid` file with an
|
||||
external `#define`, by Ming Liu, Atlas Copco
|
||||
* Support for more service options to control respawn behavior of
|
||||
crashing services, by Robert Andersson and Ming Liu, Atlas Copco
|
||||
* Support for `initctl ident [NAME]` which lists all instances of
|
||||
`NAME`, or all enabled system run/tasks and services
|
||||
* Show number of total restarts and current respawn count for a
|
||||
service in `initctl status foo`
|
||||
* Crashing services no longer have the crash/restart counter reset as
|
||||
soon as they have stabilized. Instead, a background timer will
|
||||
slowly (every 300 sec) age (decrement) the counter. This will still
|
||||
catch services that "rage quit", but also those that crash after a
|
||||
longer period of activity
|
||||
|
||||
### Fixes
|
||||
* Fix #180: user managed (`manual:yes`) services accidentally started
|
||||
by `initctl reload`, regression introduced in Finit v4.0
|
||||
* Fix #181: lots of typos all over the tree, by David Yang, Debian
|
||||
* Fix #187: fix typos, incl. small cleanup, in doc/bootstrap.md
|
||||
* Fix #188: support running on kernels that do not have cgroups v2.
|
||||
When this is detect, all functions related to cgroups support in
|
||||
Finit are disabled, *except* the .conf file parser. Hence, you
|
||||
may get parse error if you have invalid cgroup configuration in
|
||||
your Finit .conf files
|
||||
* Fix #197: `initctl status foo` now shows a focused overview of all
|
||||
matching instances; foo:1, foo:2 -- if only one instance matches the
|
||||
command line argument, or if onle one instance exists, the detailed
|
||||
view is shown, as before
|
||||
* Fix #198: a few typos found by Tim Gates
|
||||
* Fix #199: avoid using C++ reserved keywords
|
||||
* Fix #201: memory leak in usr condition plugin, by Ming Liu, Atlas Copco
|
||||
* Fix #203: ensure all filesystems listed in /proc/mounts are properly
|
||||
unumounted on shutdown/reboot, by Robert Andersson, Atlas Copco
|
||||
* Fix #210: resizing terminal (smaller) after boot causes empty lines
|
||||
to be inserted between boot progress
|
||||
* Fix #211: drop hard-coded 32 character limit in getty, now reads
|
||||
`_SC_LOGIN_NAME_MAX` from `sysconf(3)`
|
||||
* Fix #212: service PID file lost after inictl reload, visible from
|
||||
the output from `initctl status foo`
|
||||
|
||||
|
||||
[4.1][] - 2021-06-06
|
||||
--------------------
|
||||
|
||||
@@ -184,7 +308,7 @@ make sure to read the whole change log when upgrading.
|
||||
- As long as a stepped service changes state we queue another step all
|
||||
event, because services may depend on each other
|
||||
* Require new libuEv API: `uev_init1()` to reduce event cache so that
|
||||
the kernel can invalidate deleted events before enqueing to userspace
|
||||
the kernel can invalidate deleted events before enqueuing to userspace
|
||||
* Rename `hwclock.so` plugin to `rtc.so` since it now is stand-alone
|
||||
from the `hwclock` tool. Note: the kernel can also be set to load
|
||||
and store RTC to/from system clock at boot/halt as well, issue #110
|
||||
@@ -506,7 +630,7 @@ Bug fix release.
|
||||
|
||||
* Add support for status/show service by `name:id`
|
||||
* Enforce terse mode after boot, if verbose mode is disabled
|
||||
* Reenable verbose mode at reboot, if disabled at boot
|
||||
* Re-enable verbose mode at reboot, if disabled at boot
|
||||
* Update section mentioning BusyBox getty
|
||||
* Update debugging documentation
|
||||
* Allow debug to override terse mode
|
||||
@@ -561,7 +685,7 @@ handling and reconfiguration at runtime.
|
||||
* Clarify how to select different plugins with the configure script
|
||||
* Improve urandom plugin for embedded systems w/o random seed
|
||||
* Add `--debug` flag to `initctl`
|
||||
* The runlevels listed for services in `initctl show` now hightlight the
|
||||
* The runlevels listed for services in `initctl show` now highlight the
|
||||
active runlevel.
|
||||
* Clarify in the README and in `initctl help` that the GW event to
|
||||
listen for in service declarations is `GW:UP`
|
||||
@@ -593,7 +717,7 @@ handling and reconfiguration at runtime.
|
||||
* Do not use `-Os` use `-O2` as default optimization level. Many cross
|
||||
compiler toolchains are known to have problems with `-Os`
|
||||
* Do not allow build VERSION to be overloaded by an environment variable
|
||||
* Fix too small MAX arguments and too few argments in `svc_t` for
|
||||
* Fix too small MAX arguments and too few arguments in `svc_t` for
|
||||
reading currently running services with `initctl show`
|
||||
* Unblock blocked signals after forking off a child
|
||||
|
||||
@@ -693,7 +817,7 @@ The inetd release.
|
||||
### Changes
|
||||
* Add support for built-in inetd super server -- launch services on
|
||||
demand. Supports filtering per interface and custom Inet ports.
|
||||
* Upgrade to [libuEv] v1.1.0 to better handle error conditions.
|
||||
* Upgrade to [libuEv][] v1.1.0 to better handle error conditions.
|
||||
* Allow mixed case config directives in `finit.conf`
|
||||
* Add support for RFC 868 (rdate) time plugin, start as inetd service.
|
||||
* Load plugins before parsing `finit.conf`, this makes it possible to
|
||||
@@ -711,7 +835,7 @@ The inetd release.
|
||||
turned out to not work so well after all. For instance, launching
|
||||
TTYs in a background process completely blocked inetd services from
|
||||
even starting up listening sockets ... proper fork seems to work fine
|
||||
though. This is the casue for *yanking* the [1.11] release, below.
|
||||
though. This is the cause for *yanking* the [1.11] release, below.
|
||||
* Trap segfaults caused by external plugins/callbacks in a sub-process.
|
||||
This prevents a single programming mistake in by a 3rd party developer
|
||||
from taking down the entire system.
|
||||
@@ -724,7 +848,7 @@ The inetd release.
|
||||
[1.11][] - 2015-01-24 [YANKED]
|
||||
------------------------------
|
||||
|
||||
The [libuEv] release.
|
||||
The [libuEv][] release.
|
||||
|
||||
**Note:** This release has been *yanked* from distribution due to a
|
||||
regression in launching background processes and TTY's. Fixed in
|
||||
@@ -807,7 +931,7 @@ Major bug fix release.
|
||||
|
||||
### Changes
|
||||
* Show `__FILE__` in `_d()` debug messages, useful for plugins with
|
||||
similarily named callbacks. Also, only in debug mode anyway
|
||||
similarly named callbacks. Also, only in debug mode anyway
|
||||
* Make sure to cleanup recorded PID when a service is lost. Required by
|
||||
service plugins for their callbacks to work.
|
||||
* Only clear screen when in verbose mode. Maybe this should be removed
|
||||
@@ -975,7 +1099,9 @@ Major bug fix release.
|
||||
|
||||
* Initial release
|
||||
|
||||
[UNRELEASED]: https://github.com/troglobit/finit/compare/4.0...HEAD
|
||||
[UNRELEASED]: https://github.com/troglobit/finit/compare/4.2...HEAD
|
||||
[4.3]: https://github.com/troglobit/finit/compare/4.2...4.3
|
||||
[4.2]: https://github.com/troglobit/finit/compare/4.1...4.2
|
||||
[4.1]: https://github.com/troglobit/finit/compare/4.0...4.1
|
||||
[4.0]: https://github.com/troglobit/finit/compare/3.1...4.0
|
||||
[3.1]: https://github.com/troglobit/finit/compare/3.0...3.1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[![License Badge][]][License] [![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
|
||||
[![License Badge][]][License] [![GitHub Status][]][GitHub] [![Coverity Status][]][Coverity Scan]
|
||||
<img align="right" src="img/finit3.png" alt="Finit: Fast Init">
|
||||
|
||||
* [Introduction](#introduction)
|
||||
@@ -54,6 +54,11 @@ on server and desktop systems as well. For working examples, see the
|
||||
* [Alpine Linux](contrib/alpine/), and
|
||||
* [Debian GNU/Linux](contrib/debian/)
|
||||
|
||||
> **Note:** support for various Linux distributions does not mean Finit
|
||||
> installs easily on all architectures. The bundled install scripts are
|
||||
> examples for standard installations, tested on x86_64 systems. Custom
|
||||
> setups, targeted at embedded systems, can be found in [myLinux][].
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
@@ -119,10 +124,10 @@ some of the most common components needed to start a UNIX daemon:
|
||||
|
||||
```
|
||||
service [LVLS] <COND> log env:[-]/etc/default/daemon daemon ARGS -- Daemon daemon
|
||||
^ ^ ^ ^ ^ ^ ^ ^
|
||||
| | | | | | | `-- Optional description
|
||||
| | | | | | `----------- Daemon arguments
|
||||
| | | | | `-------------------------- Path to daemon
|
||||
^ ^ ^ ^ ^ ^ ^ ^
|
||||
| | | | | | | `---------- Optional description
|
||||
| | | | | | `------------------ Daemon arguments
|
||||
| | | | | `------------------------- Path to daemon
|
||||
| | | | `---------------------------------------------------- Optional env. file
|
||||
| | | `-------------------------------------------------------- Redirect output to log
|
||||
| | `--------------------------------------------------------------- Optional conditions
|
||||
@@ -140,7 +145,7 @@ Dependencies are handled using [conditions](doc/conditions.md). One of
|
||||
the most common conditions is to wait for basic networking to become
|
||||
available:
|
||||
|
||||
service <net/route/default> nginx -- High performace HTTP server
|
||||
service <net/route/default> nginx -- High performance HTTP server
|
||||
|
||||
Here is another example where we instruct Finit to not start BusyBox
|
||||
`ntpd` until `syslogd` has started properly. Finit waits for `syslogd`
|
||||
@@ -571,34 +576,35 @@ This project is based on the [original finit][] by [Claudio Matsuoka][]
|
||||
which was reverse engineered from syscalls of the [EeePC fastinit][] —
|
||||
"gaps filled with frog DNA …"
|
||||
|
||||
Finit is developed and maintained by [Joachim Wiberg][] at [GitHub][].
|
||||
Finit is developed and maintained by [Joachim Wiberg][] at [GitHub][6].
|
||||
Please file bug reports, clone it, or send pull requests for bug fixes
|
||||
and proposed extensions.
|
||||
|
||||
|
||||
[1]: https://en.wikipedia.org/wiki/Process_supervision
|
||||
[2]: http://cr.yp.to/daemontools.html
|
||||
[3]: http://smarden.org/runit/
|
||||
[4]: http://en.wikipedia.org/wiki/Init
|
||||
[5]: http://en.wikipedia.org/wiki/Runlevel
|
||||
[1]: https://en.wikipedia.org/wiki/Process_supervision
|
||||
[2]: https://cr.yp.to/daemontools.html
|
||||
[3]: https://smarden.org/runit/
|
||||
[4]: https://en.wikipedia.org/wiki/Init
|
||||
[5]: https://en.wikipedia.org/wiki/Runlevel
|
||||
[6]: https://github.com/troglobit/finit
|
||||
[RFC862]: https://tools.ietf.org/html/rfc862
|
||||
[RFC863]: https://tools.ietf.org/html/rfc863
|
||||
[RFC864]: https://tools.ietf.org/html/rfc864
|
||||
[RFC867]: https://tools.ietf.org/html/rfc867
|
||||
[RFC868]: https://tools.ietf.org/html/rfc868
|
||||
[init]: http://en.wikipedia.org/wiki/Init
|
||||
[upstart]: http://upstart.ubuntu.com/
|
||||
[systemd]: http://www.freedesktop.org/wiki/Software/systemd/
|
||||
[openrc]: http://www.gentoo.org/proj/en/base/openrc/
|
||||
[run-parts(8)]: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
|
||||
[init]: https://en.wikipedia.org/wiki/Init
|
||||
[upstart]: https://upstart.ubuntu.com/
|
||||
[systemd]: https://www.freedesktop.org/wiki/Software/systemd/
|
||||
[openrc]: https://www.gentoo.org/proj/en/base/openrc/
|
||||
[run-parts(8)]: https://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
|
||||
[original finit]: http://helllabs.org/finit/
|
||||
[EeePC fastinit]: https://web.archive.org/web/20071208212450/http://wiki.eeeuser.com/boot_process:the_boot_process
|
||||
[Claudio Matsuoka]: https://github.com/cmatsuoka
|
||||
[Joachim Wiberg]: http://troglobit.com
|
||||
[GitHub]: https://github.com/troglobit/finit
|
||||
[Joachim Wiberg]: https://troglobit.com
|
||||
[License]: https://en.wikipedia.org/wiki/MIT_License
|
||||
[License Badge]: https://img.shields.io/badge/License-MIT-teal.svg
|
||||
[Travis]: https://travis-ci.org/troglobit/finit
|
||||
[Travis Status]: https://travis-ci.org/troglobit/finit.svg?branch=master
|
||||
[GitHub]: https://github.com/troglobit/myLinux/
|
||||
[GitHub]: https://github.com/troglobit/finit/actions/workflows/build.yml/
|
||||
[GitHub Status]: https://github.com/troglobit/finit/actions/workflows/build.yml/badge.svg
|
||||
[Coverity Scan]: https://scan.coverity.com/projects/3545
|
||||
[Coverity Status]: https://scan.coverity.com/projects/3545/badge.svg
|
||||
|
||||
+31
-3
@@ -1,4 +1,4 @@
|
||||
AC_INIT(Finit, 4.1, https://github.com/troglobit/finit/issues, finit, https://troglobit.com/finit.html)
|
||||
AC_INIT(Finit, 4.3-rc1, https://github.com/troglobit/finit/issues, finit, https://troglobit.com/finit.html)
|
||||
AC_CONFIG_AUX_DIR(aux)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
@@ -14,8 +14,8 @@ AC_CONFIG_FILES([Makefile
|
||||
man/Makefile
|
||||
plugins/Makefile
|
||||
src/Makefile
|
||||
test/test.env
|
||||
test/Makefile])
|
||||
test/test.env test/Makefile
|
||||
test/tenv/Makefile test/common/Makefile])
|
||||
|
||||
# Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR()
|
||||
#m4_include([m4/plugin.m4])
|
||||
@@ -57,6 +57,14 @@ AC_ARG_ENABLE(kernel_cmdline,
|
||||
AS_HELP_STRING([--enable-kernel-cmdline], [Parse init args from /proc/cmdline (don't use!)]),,[
|
||||
enable_kernel_cmdline=no])
|
||||
|
||||
AC_ARG_ENABLE(fastboot,
|
||||
AS_HELP_STRING([--enable-fastboot], [Skip fsck check on filesystems listed in /etc/fstab]),,[
|
||||
enable_fastboot=no])
|
||||
|
||||
AC_ARG_ENABLE(fsckfix,
|
||||
AS_HELP_STRING([--enable-fsckfix], [Run fsck fix mode (options: -yf) on filesystems listed in /etc/fstab]),,[
|
||||
enable_fsckfix=no])
|
||||
|
||||
AC_ARG_ENABLE(redirect,
|
||||
AS_HELP_STRING([--disable-redirect], [Disable redirection of service output to /dev/null]),,[
|
||||
enable_redirect=yes])
|
||||
@@ -78,11 +86,13 @@ enable_all_plugins=auto
|
||||
AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl])
|
||||
AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus])
|
||||
AC_PLUGIN([modules-load], [no], [Scans /etc/modules-load.d for modules to load])
|
||||
AC_PLUGIN([modprobe], [yes], [Coldplug modules using modalias magic])
|
||||
AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf])
|
||||
AC_PLUGIN([x11-common], [no], [Console setup (for X)])
|
||||
AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.])
|
||||
AC_PLUGIN([hotplug], [yes], [Setup and start udev or mdev hotplug daemon])
|
||||
AC_PLUGIN([rtc], [yes], [Save and restore RTC using hwclock])
|
||||
AC_PLUGIN([tty], [yes], [Automatically activate new TTYs, e.g. USB-to-serial])
|
||||
AC_PLUGIN([urandom], [yes], [Setup and save random seed at boot/shutdown])
|
||||
|
||||
# Check for extra arguments or packages
|
||||
@@ -106,6 +116,10 @@ AC_ARG_WITH(sysconfig,
|
||||
AS_HELP_STRING([--with-sysconfig=DIR], [System environment directory, sourced by .conf files, default /etc/default & /etc/conf.d]),
|
||||
[sysconfig=$withval], [sysconfig=default])
|
||||
|
||||
AC_ARG_WITH(group,
|
||||
AS_HELP_STRING([--with-group=NAME], [Group for /run/finit/socket (initctl), default: root]),
|
||||
[group=$withval], [group=root])
|
||||
|
||||
AC_ARG_WITH(hostname,
|
||||
AS_HELP_STRING([--with-hostname=NAME], [If /etc/hostname is missing, default: noname]),
|
||||
[hostname=$withval], [hostname=yes])
|
||||
@@ -134,6 +148,12 @@ AS_IF([test "x$enable_auto_reload" = "xyes"], [
|
||||
AS_IF([test "x$enable_kernel_cmdline" = "xyes"], [
|
||||
AC_DEFINE(KERNEL_CMDLINE, 1, [Dumpster diving after init args from /proc/cmdline])])
|
||||
|
||||
AS_IF([test "x$enable_fastboot" = "xyes"], [
|
||||
AC_DEFINE(FAST_BOOT, 1, [Skip fsck check on filesystems listed in /etc/fstab])])
|
||||
|
||||
AS_IF([test "x$enable_fsckfix" = "xyes"], [
|
||||
AC_DEFINE(FSCK_FIX, 1, [Run fsck fix mode (options: -yf) on filesystems listed in /etc/fstab])])
|
||||
|
||||
AS_IF([test "x$enable_redirect" = "xyes"], [
|
||||
AC_DEFINE(REDIRECT_OUTPUT, 1, [Enable redirection of service output to /dev/null])])
|
||||
|
||||
@@ -174,6 +194,11 @@ AS_IF([test "x$with_heading" != "xno"], [
|
||||
AS_IF([test "x$heading" = "xyes"], [heading=""])
|
||||
AC_DEFINE_UNQUOTED(INIT_OSHEADING, "$heading", [Displayed by Finit at boot, defaults to /etc/os-release PRETTY_NAME])])
|
||||
|
||||
AS_IF([test "x$with_group" != "xno"], [
|
||||
AS_IF([test "x$group" = "xyes"], [
|
||||
group=root])])
|
||||
AC_DEFINE_UNQUOTED(DEFGROUP, "$group", [For /run/finit/socket])
|
||||
|
||||
AS_IF([test "x$with_hostname" != "xno"], [
|
||||
AS_IF([test "x$hostname" = "xyes"], [
|
||||
hostname=noname])])
|
||||
@@ -255,8 +280,11 @@ Optional features:
|
||||
Built-in keventd......: $with_keventd
|
||||
Built-in watchdogd....: $with_watchdog $watchdog
|
||||
Built-in logrotate....: $enable_logrotate
|
||||
Skip fsck check.......: $enable_fastboot
|
||||
Run fsck fix mode.....: $enable_fsckfix
|
||||
Redirect output.......: $enable_redirect
|
||||
Default hostname......: $hostname
|
||||
Default group.........: $group
|
||||
Default runlevel......: $runlevel
|
||||
|
||||
------------- Compiler version --------------
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
#
|
||||
# Each line is run in sequence.
|
||||
#
|
||||
# NOTE: Remeber to set the executable bit!
|
||||
# NOTE: Remember to set the executable bit!
|
||||
#
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
In Finit issue #196 we were reminded [1] of a missing inotify flag in
|
||||
Linux older kernels, IN_MASK_CREATE. Finit makes use of this internally
|
||||
for monitoring PID conditions, and more. This is a central mechanism to
|
||||
synchronize services at boot and reload at runtime.
|
||||
|
||||
The following patch for Linux 4.9.0, was provided by Andy Savage for
|
||||
other people that may want to run Finit on slightly older kernels.
|
||||
|
||||
[1]: https://github.com/troglobit/finit/issues/196
|
||||
|
||||
Index: fs/notify/inotify/inotify_user.c
|
||||
===================================================================
|
||||
--- fs.orig/notify/inotify/inotify_user.c
|
||||
+++ fs/notify/inotify/inotify_user.c
|
||||
@@ -522,6 +522,7 @@ static int inotify_update_existing_watch
|
||||
__u32 old_mask, new_mask;
|
||||
__u32 mask;
|
||||
int add = (arg & IN_MASK_ADD);
|
||||
+ int create = (arg & IN_MASK_CREATE);
|
||||
int ret;
|
||||
|
||||
mask = inotify_arg_to_mask(arg);
|
||||
@@ -529,6 +530,8 @@ static int inotify_update_existing_watch
|
||||
fsn_mark = fsnotify_find_inode_mark(group, inode);
|
||||
if (!fsn_mark)
|
||||
return -ENOENT;
|
||||
+ else if (create)
|
||||
+ return -EEXIST;
|
||||
|
||||
i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
|
||||
|
||||
@@ -726,6 +729,10 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
|
||||
if (unlikely(!f.file))
|
||||
return -EBADF;
|
||||
|
||||
+ /* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */
|
||||
+ if (unlikely((mask & IN_MASK_ADD) && (mask & IN_MASK_CREATE)))
|
||||
+ return -EINVAL;
|
||||
+
|
||||
/* verify that this is indeed an inotify instance */
|
||||
if (unlikely(f.file->f_op != &inotify_fops)) {
|
||||
ret = -EINVAL;
|
||||
@@ -814,7 +821,7 @@ static int __init inotify_user_setup(voi
|
||||
BUILD_BUG_ON(IN_ISDIR != FS_ISDIR);
|
||||
BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT);
|
||||
|
||||
- BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
|
||||
+ BUG_ON(hweight32(ALL_INOTIFY_BITS) != 22);
|
||||
|
||||
inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
|
||||
|
||||
Index: include/linux/inotify.h
|
||||
===================================================================
|
||||
--- include.orig/linux/inotify.h
|
||||
+++ include/linux/inotify.h
|
||||
@@ -17,6 +17,6 @@ extern struct ctl_table inotify_table[];
|
||||
IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT | \
|
||||
IN_Q_OVERFLOW | IN_IGNORED | IN_ONLYDIR | \
|
||||
IN_DONT_FOLLOW | IN_EXCL_UNLINK | IN_MASK_ADD | \
|
||||
- IN_ISDIR | IN_ONESHOT)
|
||||
+ IN_MASK_CREATE | IN_ISDIR | IN_ONESHOT)
|
||||
|
||||
#endif /* _LINUX_INOTIFY_H */
|
||||
Index: include/uapi/linux/inotify.h
|
||||
===================================================================
|
||||
--- include.orig/uapi/linux/inotify.h
|
||||
+++ include/uapi/linux/inotify.h
|
||||
@@ -52,6 +52,7 @@ struct inotify_event {
|
||||
#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */
|
||||
#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */
|
||||
#define IN_EXCL_UNLINK 0x04000000 /* exclude events on unlinked objects */
|
||||
+#define IN_MASK_CREATE 0x10000000 /* only create watches */
|
||||
#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */
|
||||
#define IN_ISDIR 0x40000000 /* event occurred against dir */
|
||||
#define IN_ONESHOT 0x80000000 /* only send event once */
|
||||
@@ -4,4 +4,4 @@
|
||||
#
|
||||
# Each line is run in sequence.
|
||||
#
|
||||
# NOTE: Remeber to set the executable bit!
|
||||
# NOTE: Remember to set the executable bit!
|
||||
|
||||
+9
-10
@@ -16,7 +16,9 @@ Bootstrap
|
||||
11. Load all `/etc/finit.d/*.conf` files and set hostname
|
||||
12. Remount `/` read-write if `/` is listed in `/etc/fstab` without `ro`
|
||||
13. Call 1st level hooks, `HOOK_ROOTFS_UP`
|
||||
14. Mount all file systems listed in `/etc/fstab` and swap, if available
|
||||
14. Mount all file systems listed in `/etc/fstab` and swap, if available.
|
||||
On mount error `HOOK_MOUNT_ERROR` is called. After mount, regardless
|
||||
of error, `HOOK_MOUNT_POST` is called
|
||||
15. Enable SysV init signals
|
||||
16. Call 2nd level hooks, `HOOK_BASEFS_UP`
|
||||
17. Cleanup stale files from `/tmp/*` et al, handled by `bootmisc` plugin
|
||||
@@ -38,16 +40,13 @@ Bootstrap
|
||||
26. Call 5th level (last) hooks, `HOOK_SYSTEM_UP`
|
||||
27. Start all configured TTYs
|
||||
|
||||
In (19) and (22) tasks and services defined in `/etc/finit.conf` and
|
||||
`/etc/sysctl.d/*.conf` are started. Remember, all `service` and `task`
|
||||
stanzas are started in parallel and `run` in sequence, and in the order
|
||||
listed. Hence, to emulate a SysV `/etc/init.d/rcS` one could write a
|
||||
long `finit.conf` with only `run` statements.
|
||||
In (19) and (23) tasks and services defined in `/etc/finit.conf` and
|
||||
`/etc/finit.d/*.conf` are started.
|
||||
|
||||
Notice the five hook points that are called at various point in the
|
||||
bootstrap process. This is where plugins can extend the boot in any way
|
||||
they please. There are other hook points, e.g. `HOOK_MOUNT_ERROR`, for
|
||||
more on this see [plugins.md](plugins.md).
|
||||
Notice the seven hook points that are called at various point in the
|
||||
bootstrap process. This is where plugins can extend the boot in any
|
||||
way they please. There are other hook points available, for more on
|
||||
this, see [plugins.md](plugins.md).
|
||||
|
||||
For instance, at `HOOK_BASEFS_UP` a plugin could read an XML file from a
|
||||
USB stick, convert/copy its contents to the system's `/etc/` directory,
|
||||
|
||||
+20
-11
@@ -27,10 +27,10 @@ optional plugins to enable. It depends on two external libraries:
|
||||
PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig ./configure
|
||||
|
||||
The configure script checks for all dependencies, including the correct
|
||||
version of the above mentioned libraries. Currently requried versions:
|
||||
version of the above mentioned libraries. Currently required versions:
|
||||
|
||||
- libite v2.2.0
|
||||
- libuEv v2.2.0
|
||||
- libite v2.2.0, or later
|
||||
- libuEv v2.2.0, or later
|
||||
|
||||
|
||||
Configure
|
||||
@@ -54,7 +54,7 @@ Below are a few of the main switches to configure:
|
||||
will be linked statically.
|
||||
|
||||
* `--enable-kernel-cmdline`: Enable Finit pre-4.1 parsing of init args from
|
||||
`/proc/cmdline`, this is not recommended since Finit may be running as the
|
||||
`/proc/cmdline`, this is *not recommended* since Finit may be running as the
|
||||
init for container apps that can see the host's `/proc` filesystem
|
||||
|
||||
* `--enable-alsa-utils-plugin`: Enable the optional `alsa-utils.so` sound plugin.
|
||||
@@ -67,6 +67,13 @@ Below are a few of the main switches to configure:
|
||||
|
||||
For more configure flags, see <kbd>./configure --help</kbd>
|
||||
|
||||
> **Note:** the configure script is not available in the GIT sources. It is
|
||||
> however included in (officially supported) released tarballs. The
|
||||
> idea is that you should not need GNU autotools to build, only the
|
||||
> above mentioned dependencies, a POSIX shell, a C compiler and make.
|
||||
> Any contributing to Finit can generate it from `configure.ac` using
|
||||
> the `autogen.sh` script.
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
@@ -74,8 +81,8 @@ Example
|
||||
First, unpack the archive:
|
||||
|
||||
```shell
|
||||
$ tar xf finit-4.1.tar.gz
|
||||
$ cd finit-4.1/
|
||||
$ tar xf finit-4.3.tar.gz
|
||||
$ cd finit-4.3/
|
||||
```
|
||||
|
||||
Then configure, build and install:
|
||||
@@ -83,7 +90,7 @@ Then configure, build and install:
|
||||
```shell
|
||||
$ ./configure --prefix=/usr --exec-prefix= \
|
||||
--sysconfdir=/etc --localstatedir=/var \
|
||||
--with-keventd --with-watchdog
|
||||
--with-keventd --with-watchdog
|
||||
$ make
|
||||
.
|
||||
.
|
||||
@@ -91,7 +98,7 @@ $ make
|
||||
$ DESTDIR=/tmp/finit make install
|
||||
```
|
||||
|
||||
In this example the [finit-4.1.tar.gz][1] archive is unpacked to the
|
||||
In this example the [finit-4.3.tar.gz][1] archive is unpacked to the
|
||||
user's home directory, configured, built and installed to a temporary
|
||||
staging directory. The environment variable `DESTDIR` controls the
|
||||
destination directory when installing, very useful for building binary
|
||||
@@ -151,12 +158,14 @@ Debugging
|
||||
---------
|
||||
|
||||
Edit, or append to, the kernel command line: remove `quiet` to enable
|
||||
kernel messages and add `debug` to enable Finit debug messages.
|
||||
kernel messages and add `finit.debug` to enable Finit debug messages.
|
||||
|
||||
```shell
|
||||
append="init=/sbin/finit debug"
|
||||
append="init=/sbin/finit -- finit.debug"
|
||||
```
|
||||
|
||||
Notice the `--` separator.
|
||||
|
||||
To debug startup issues, in particular issues with getty/login, add
|
||||
the following to your Finit .conf file:
|
||||
|
||||
@@ -175,6 +184,6 @@ it only for debugging start up issues when Finit crashes.
|
||||
systems since they can potentially give a user root access.
|
||||
|
||||
|
||||
[1]: ftp://troglobit.com/finit/finit-4.1.tar.gz
|
||||
[1]: ftp://troglobit.com/finit/finit-4.3.tar.gz
|
||||
[libuEv]: https://github.com/troglobit/libuev
|
||||
[libite]: https://github.com/troglobit/libite
|
||||
|
||||
+14
-7
@@ -10,13 +10,13 @@ The `bool` setting is one of `on, off, true false, 1, 0`.
|
||||
> parameters to init. E.g., `init=/sbin/finit -- finit.debug rescue`
|
||||
|
||||
* `debug`: Enable kernel debug. Debug messages are printed to the
|
||||
console until Finit starts up.
|
||||
console until Finit starts up, unless `loglevel=7` (below) is used.
|
||||
|
||||
* `finit.debug[=bool]`: Enable finit debug. This is operated
|
||||
independently of the kernel debug setting. New as of Finit v4.
|
||||
independently of the kernel `debug` setting. New as of Finit v4.
|
||||
|
||||
* `finit.show_status[=bool]`: Control finit boot progress, including
|
||||
banner.
|
||||
* `finit.status[=bool]`: Control finit boot progress, including banner.
|
||||
(Used to be `finit.show_status`, which works but is deprecated.)
|
||||
|
||||
* `finit.status_style=<classic,modern>`: Set Finit boot progress style,
|
||||
when enabled.
|
||||
@@ -26,11 +26,18 @@ The `bool` setting is one of `on, off, true false, 1, 0`.
|
||||
signals and has no job control. Recommend using, and modifying,
|
||||
`rescue` mode instead.
|
||||
|
||||
* `loglevel=<0-7>`, sets the kernel's log level, which is more granular
|
||||
than `debug`. Also, when `loglevel=7`, Finit will *not disable*
|
||||
kernel logs to the console. This is very useful when debugging the
|
||||
kernel at system bring-up. Since `loglevel=7` is the same as `debug`
|
||||
this means you have to use `quiet` for a quiet boot, until sysklogd
|
||||
takes over logging of kernel events.
|
||||
|
||||
* `panic=SEC`: By default the kernel does not reboot after a kernel
|
||||
panic. This setting will cause a kernel reboot after SEC seconds.
|
||||
|
||||
* `quiet`: Suppress kernel logging to console, except for warnings and
|
||||
errors.
|
||||
errors. Also, see `loglevel` and `quiet` above.
|
||||
|
||||
* `rescue`: Start rescue/maintenance mode. If your system comes with
|
||||
the bundled `sulogin` program (Finit, or from util-linux/Busybox),
|
||||
@@ -44,7 +51,7 @@ The `bool` setting is one of `on, off, true false, 1, 0`.
|
||||
`[1]` will be started, so a `tty [1] @console nologin` configuration
|
||||
presents you with a root console without login.
|
||||
|
||||
For more on kernel boot paramaters, see the man page [bootparam(7)][].
|
||||
For more on kernel boot parameters, see the man page [bootparam(7)][].
|
||||
|
||||
[config.md][]: config.md#rescue-mode
|
||||
[config.md]: config.md#rescue-mode
|
||||
[bootparam(7)]: https://www.man7.org/linux/man-pages/man7/bootparam.7.html
|
||||
|
||||
+2
-2
@@ -90,7 +90,7 @@ Built-in Conditions
|
||||
Finit comes with a set of plugins for conditions: `pidfile`, `netlink`,
|
||||
`sys`, and `usr`. The `pidfile` plugin (recursively) watches `/run/`
|
||||
(recursively) for PID files created by the monitored services, and sets
|
||||
a corresponding condition in the `pid/` namespace. Similarily, the
|
||||
a corresponding condition in the `pid/` namespace. Similarly, the
|
||||
`netlink` plugin provides basic conditions for when an interface is
|
||||
brought up/down and when a default route (gateway) is set, in the `net/`
|
||||
namespace. The `sys` and `usr` plugins monitor are passive condition
|
||||
@@ -180,7 +180,7 @@ PID IDENT STATUS CONDITION (+ ON, ~ FLUX, - OFF)
|
||||
|
||||
Here we can see that `netd` is allowed to run since both its conditions
|
||||
are in the `on` state, as indicated by the `+`-prefix. `udhcpc` however
|
||||
is not allowed to run since `net/vlan1/exist` condition is not satsifed.
|
||||
is not allowed to run since `net/vlan1/exist` condition is not satisfied.
|
||||
As indicated by the `-`-prefix.
|
||||
|
||||
To fake interface `vlan1` suddenly appearing, and test what happens to
|
||||
|
||||
+38
-6
@@ -59,7 +59,7 @@ files for a package and let the user decide when to enable a service.
|
||||
On `initctl reload` the following is checked for all services:
|
||||
|
||||
- If a service's `.conf` file has been removed, or its conditions are no
|
||||
longer satisifed, the service is stopped.
|
||||
longer satisfied, the service is stopped.
|
||||
- If the file is modified, or a service it depends on has been reloaded,
|
||||
the service is reloaded (stopped and started).
|
||||
- If a new service is added it is automatically started — respecting
|
||||
@@ -323,6 +323,10 @@ calls `init-script restart` on `initctl reload`. Similar to how
|
||||
|
||||
Forking services started with `sysv` scripts can be monitored by Finit
|
||||
by declaring the PID file to look for: `pid:!/path/to/pidfile.pid`.
|
||||
Notice the leading `!`, it signifies Finit should not try to create the
|
||||
file, but rather watch that file for the resulting forked-off PID. This
|
||||
syntax also works for forking daemons that do not have a command line
|
||||
option to run it in the foreground, more on this below in `service`.
|
||||
|
||||
> `<COND>` is described in the [Services](#services) section.
|
||||
|
||||
@@ -332,8 +336,11 @@ by declaring the PID file to look for: `pid:!/path/to/pidfile.pid`.
|
||||
**Syntax:** `service [LVLS] <COND> /path/to/daemon ARGS -- Optional description`
|
||||
|
||||
Service, or daemon, to be monitored and automatically restarted if it
|
||||
exits prematurely. Finit tries to restart services that die 10 times
|
||||
before giving up, then you have to `initctl restart NAME` it manually.
|
||||
exits prematurely. Finit tries to restart services that die, by
|
||||
default 10 times before giving up and marking them as *crashed*.
|
||||
After which they have to be manually restarted with `initctl restart
|
||||
NAME`. The limits controling this are configurable, see the options
|
||||
below.
|
||||
|
||||
For daemons that support it, we recommend appending `--foreground`,
|
||||
`--no-background`, `-n`, `-F`, or similar command line argument to
|
||||
@@ -341,9 +348,19 @@ prevent them from forking off a sub-process in the background. This is
|
||||
the most reliable way to monitor a service.
|
||||
|
||||
However, not all daemons support running in the foreground, or they may
|
||||
start logging to the foreground as well, these are called forking
|
||||
services and are supported using the same syntax as forking `sysv`
|
||||
services, using the `pid:!/path/to/pidfile.pid` syntax.
|
||||
start logging to the foreground as well, these are forking daemons and
|
||||
are supported using the same syntax as forking `sysv` services, using
|
||||
the `pid:!/path/to/pidfile.pid` syntax. There is an alternative syntax
|
||||
that may be more intuitive, where Finit can also guess the PID file
|
||||
based on the daemon's command name:
|
||||
|
||||
service type:forking ntpd -- NTP daemon
|
||||
|
||||
This example lets BusyBox `ntpd` daemonize itself. Finit uses the
|
||||
basename of the binary to guess the PID file to watch for the PID:
|
||||
`/var/run/ntpd.pid`. If Finit guesses wrong, you have to submit the
|
||||
full `pid:!/path/to/file.pid`.
|
||||
|
||||
|
||||
**Example:**
|
||||
|
||||
@@ -390,6 +407,21 @@ optional `name` argument:
|
||||
|
||||
name:<service-name>
|
||||
|
||||
As mentioned previously, services are automatically restarted, this is
|
||||
configurable with the following options:
|
||||
|
||||
* `restart:NUM` -- number of times Finit tries to restart a crashing
|
||||
service, default: 10. When this limit is reached the service is
|
||||
marked *crashed* and must be restarted manually with `initctl`
|
||||
* `restart_sec:SEC` -- number of seconds before Finit tries to restart
|
||||
a crashing service, default: 2 seconds for the first five retries,
|
||||
then back-off to 5 seconds. The maximum of this configured value
|
||||
and the above (2 and 5) will be used
|
||||
* `norestart` -- dont restart on failures, same as `restart:0`
|
||||
* `oncrash:reboot` -- when all retries have failed, and the service
|
||||
has *crashed*, if this option is set the system is rebooted.
|
||||
Note, future releases may include other `oncrash:` actions
|
||||
|
||||
When stopping a service (run/task/sysv/service), either manually or
|
||||
when moving to another runlevel, Finit starts by sending `SIGTERM`, to
|
||||
allow the process to shut down gracefully. If the process has not
|
||||
|
||||
+6
-4
@@ -35,25 +35,27 @@ For your convenience a set of *optional* plugins are available:
|
||||
_Optional plugin._
|
||||
|
||||
* *hotplug.so*: Setup and start either udev or mdev hotplug daemon, if
|
||||
available.
|
||||
available. Enabled by default.
|
||||
|
||||
* *rtc.so*: Restore and save system clock from/to RTC on boot/halt.
|
||||
Enabled by default.
|
||||
|
||||
* *modules-load.so*: Scans /etc/modules-load.d for modules to modprobe.
|
||||
|
||||
* *netlink.so*: Listens to Linux kernel Netlink events for gateway and
|
||||
interfaces. These events are then sent to the Finit service monitor
|
||||
for services that may want to be SIGHUP'ed on new default route or
|
||||
interfaces going up/down.
|
||||
interfaces going up/down. Enabled by default.
|
||||
|
||||
* *resolvconf.so*: Setup necessary files for `resolvconf` at startup.
|
||||
_Optional plugin._
|
||||
|
||||
* *tty.so*: Watches `/dev`, using inotify, for new device nodes (TTY's)
|
||||
to start/stop getty consoles on them on demand. Useful when plugging
|
||||
in a usb2serial converter to login to your embedded device.
|
||||
in a usb2serial converter to login to your embedded device. Enabled
|
||||
by default.
|
||||
|
||||
* *urandom.so*: Setup random seed at startup.
|
||||
* *urandom.so*: Setup random seed at startup. Enabled by default.
|
||||
|
||||
* *x11-common.so*: Setup necessary files for X-Window. _Optional plugin._
|
||||
|
||||
|
||||
+55
-1
@@ -1,7 +1,59 @@
|
||||
Finit Services
|
||||
==============
|
||||
|
||||

|
||||
Starting & Monitoring
|
||||
---------------------
|
||||
|
||||
Finit can start and monitor the following types of daemons:
|
||||
|
||||
* Forks to background, creates a PID file
|
||||
* Runs in foreground:
|
||||
- creates a PID file
|
||||
- does not create a PID file -- Finit can create it for you (optional)
|
||||
|
||||
Finit can *not* start and monitor a daemon that:
|
||||
|
||||
* Forks to background and does *not* create a PID file
|
||||
|
||||
| | Forking | Creates PID File | Finit creates PID File |
|
||||
|---|---------|------------------|------------------------|
|
||||
| ✔ | Yes | Yes | No |
|
||||
| ✔ | No | Yes | No |
|
||||
| ✔ | No | No | Yes, optionally |
|
||||
| ✘ | Yes | No | No |
|
||||
|
||||
> **Note:** PID files is one mechanism used to assert conditions to
|
||||
> synchronize the start and stop of other, dependent, services.
|
||||
|
||||
### Forks to Background w/ PID File
|
||||
|
||||
There are two syntax variants, type 1 and type 2. The former is the
|
||||
traditional one used also for `sysv` start/stop scripts, and the latter
|
||||
is inspired by systemd, with a twist -- it lets Finit guess the pifdile
|
||||
to look for based on the standard path and the basename of the command.
|
||||
|
||||
service pid:!/run/serv.pid serv -- Forking service, type 1
|
||||
service type:forking serv -- Forking service, type 2
|
||||
|
||||
In this example the resulting files to watch for are `/run/serv.pid` and
|
||||
`/var/run/serv.pid`, respectively. On most modern Linux systems this is
|
||||
the same directory (`/var/run` is a symlink to `../run`).
|
||||
|
||||
### Runs in Foreground w/ PID File
|
||||
|
||||
service serv -n -p -- Foreground service w/ PID file
|
||||
|
||||
### Runs in Foreground w/o PID File
|
||||
|
||||
Same as previous, but we tell Finit to create the PID file, because we
|
||||
need it to synchronize start/stop of a dependent service.
|
||||
|
||||
service pid:/run/serv.pid serv -n -- Foreground service w/o PID file
|
||||
|
||||
### Runs in Foreground w/ Custom PID File
|
||||
|
||||
service pid:/run/servy.pid serv -n -p -P /run/servy.pid -- Foreground service w/ custom PID file
|
||||
|
||||
|
||||
State Machine
|
||||
-------------
|
||||
@@ -11,6 +63,8 @@ For `run`s and `task`s there is an additional end state called `DONE`,
|
||||
not shown in the diagram for brevity. Services start in the `HALTED`
|
||||
state.
|
||||
|
||||

|
||||
|
||||
The current state depends on the two following conditions:
|
||||
|
||||
* `E`: Service enabled. In order for `E` to be satisfied, the service
|
||||
|
||||
+4
-3
@@ -11,8 +11,9 @@
|
||||
.Nd Fast init for Linux systems
|
||||
.Sh SYNOPSIS
|
||||
.Nm /sbin/finit
|
||||
.Op finit.status_style=classic
|
||||
.Op finit.show_status=[on,off]
|
||||
.Op --
|
||||
.Op finit.status=[on,off]
|
||||
.Op finit.status_style=[classic,modern]
|
||||
.Op finit.debug
|
||||
.Op rescue | recover
|
||||
.Op single | S
|
||||
@@ -107,7 +108,7 @@ Finit waits for the PID file of service A to be created/updated before
|
||||
it starts service B. Conversely, if service A is stopped and its PID
|
||||
file removed, service B is also stopped.
|
||||
.Pp
|
||||
The following condition families are availble today:
|
||||
The following condition families are available today:
|
||||
.Pp
|
||||
.Bl -tag -width pid -offset indent
|
||||
.It Cm net
|
||||
|
||||
+52
-5
@@ -174,9 +174,13 @@ the default behavior for the
|
||||
command modifier.
|
||||
.It Cm service Oo LVLS Oc Ao COND Ac Ar /path/to/daemon ARGS Op -- Optional description
|
||||
Service, or daemon, to be monitored and automatically restarted if it
|
||||
exits prematurely. Finit tries to restart services that die 10 times
|
||||
before giving up, then you have to restart it manually:
|
||||
.Cm initctl restart NAME
|
||||
exits prematurely. Finit tries to restart services that die, by
|
||||
default 10 times, before giving up and marking them as
|
||||
.Em crashed .
|
||||
After which they have to be restarted manually using
|
||||
.Cm initctl restart NAME .
|
||||
The number of restarts, the delay between each restart, and more is
|
||||
configurable, see the options below.
|
||||
.Pp
|
||||
For daemons that support it, we recommend appending
|
||||
.Cm --foreground , --no-background , -n , -F ,
|
||||
@@ -190,7 +194,21 @@ services and are supported using the same syntax as forking
|
||||
.Cm sysv
|
||||
services, using the
|
||||
.Cm pid:!/path/to/pidfile.pid
|
||||
command modifier syntax.
|
||||
command modifier syntax. There is an alternative syntax that may be
|
||||
more intuitive, where Finit can also guess the PID file based on the
|
||||
daemon's command name:
|
||||
.Bd -unfilled -offset indent
|
||||
service type:forking ntpd -- NTP daemon
|
||||
.Ed
|
||||
.Pp
|
||||
Here we let BusyBox
|
||||
.Nm ntpd
|
||||
daemonize itself. Finit uses the basename of the binary to guess the
|
||||
PID file to watch for the PID:
|
||||
.Pa /var/run/ntpd.pid .
|
||||
If Finit guesses wrong, you have to submit the full
|
||||
.Cm pid:!/path/to/file.pid
|
||||
option to your service stanza.
|
||||
.Pp
|
||||
.Sy Example: in the case of
|
||||
.Cm ospfd
|
||||
@@ -200,6 +218,7 @@ flag (daemonize) to prevent it from forking to the background:
|
||||
.Bd -unfilled -offset indent
|
||||
service [2345] <pid/zebra> /sbin/ospfd -- OSPF daemon
|
||||
.Ed
|
||||
.Pp
|
||||
.Cm [2345]
|
||||
denote the runlevels
|
||||
.Cm ospfd
|
||||
@@ -264,6 +283,34 @@ changed with the
|
||||
.Cm name:foo
|
||||
command modifier.
|
||||
.Pp
|
||||
As mentioned previously, services are automatically restarted should
|
||||
they crash, this is configurable with the following options:
|
||||
.Bl -tag -width 1n
|
||||
.It Cm restart:NUM
|
||||
number of times Finit tries to restart a crashing
|
||||
service, default: 10. When this limit is reached the service is
|
||||
marked
|
||||
.Em crashed
|
||||
and must be restarted manually with
|
||||
.Xr initctl 8 .
|
||||
.It Cm restart_sec:SEC
|
||||
number of seconds before Finit tries to restart
|
||||
a crashing service, default: 2 seconds for the first five retries,
|
||||
then back-off to 5 seconds. The maximum of this configured value
|
||||
and the above (2 and 5) will be used
|
||||
.It Cm norestart
|
||||
dont restart on failures, same as
|
||||
.Cm restart:0
|
||||
.It Cm oncrash:reboot
|
||||
when all retries have failed, and the service
|
||||
has
|
||||
.Em crashed ,
|
||||
if this option is set the system is rebooted. Note, future releases
|
||||
may include other
|
||||
.Cm oncrash:
|
||||
actions.
|
||||
.El
|
||||
.Pp
|
||||
When stopping a service (run/task/sysv/service), either manually or when
|
||||
moving to another runlevel, Finit starts by sending SIGTERM, to allow
|
||||
the process to shut down gracefully. If the process has not been
|
||||
@@ -301,7 +348,7 @@ services named
|
||||
may be
|
||||
.Cm foo:1 ,
|
||||
or any unique identifier specified in the .conf file. The
|
||||
.cm post:script
|
||||
.Cm post:script
|
||||
is called with an additional set of environment variables:
|
||||
.Bl -tag -offset indent -width 1n
|
||||
.It Cm EXIT_CODE=[exited,signal]
|
||||
|
||||
+23
-4
@@ -11,7 +11,7 @@
|
||||
.Nd Control tool for Finit
|
||||
.Sh SYNOPSIS
|
||||
.Nm /sbin/initctl
|
||||
.Op Fl bcfhlpqtv
|
||||
.Op Fl bcfhlpqtvV
|
||||
.Op COMMAND
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
@@ -41,16 +41,20 @@ Silent, only return status of command.
|
||||
Skip table headings.
|
||||
.It Fl v, -verbose
|
||||
Verbose output, where applicable.
|
||||
.It Fl V, -version
|
||||
Show program version.
|
||||
.El
|
||||
.Sh COMMANDS
|
||||
.Bl -tag -width Ds
|
||||
.It Nm Ar debug
|
||||
Toggle finit (daemon) debug to
|
||||
Toggle
|
||||
.Nm finit
|
||||
(daemon) debug to
|
||||
.Pa /dev/console
|
||||
.It Nm Ar help
|
||||
Show built-in help text
|
||||
.It Nm Ar version
|
||||
Show Finit (daemon) version
|
||||
Show program version
|
||||
.It Nm Ar ls | list
|
||||
List all
|
||||
.Cm *.conf
|
||||
@@ -118,6 +122,13 @@ Show condition status, default
|
||||
command.
|
||||
.It Nm Ar cond dump
|
||||
Dump all conditions and their status
|
||||
.It Nm Ar ident Op Cm NAME
|
||||
Display indentities of all run/task/services, or only instances
|
||||
matching
|
||||
.Cm NAME .
|
||||
A partial string, e.g.,
|
||||
.Cm NAM ,
|
||||
will not match anything
|
||||
.It Nm Ar log Op Cm NAME
|
||||
Show ten last Finit, or
|
||||
.Cm NAME ,
|
||||
@@ -129,10 +140,18 @@ Start service by name, with optional ID, e.g.,
|
||||
Stop/Pause a running service by name
|
||||
.It Nm Ar reload Cm NAME[:ID]
|
||||
Reload service by name (SIGHUP or restart)
|
||||
.It Nm Ar signal Cm NAME:[ID] S
|
||||
Send signal S to service, by name.
|
||||
.Cm S
|
||||
may be a complete signal name such as SIGHUP, or short name such as HUP, or the signal number such as 1 (SIGHUP).
|
||||
.It Nm Ar restart Cm NAME[:ID]
|
||||
Restart (stop/start) service by name
|
||||
.It Nm Ar status Cm NAME[:ID]
|
||||
Show service status, by name
|
||||
Show service status, by name. If only
|
||||
.Cm NAME
|
||||
is given and multiple instances exits, a summary of all matching
|
||||
instances are shown. Only an exact match displays the detailed status
|
||||
for a particular instance
|
||||
.It Nm Ar status
|
||||
Show status of all services, default command
|
||||
.It Nm Ar cgroup
|
||||
|
||||
+19
-3
@@ -3,11 +3,11 @@ AM_LDFLAGS = -module -avoid-version -shared
|
||||
AM_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/src -U_FORTIFY_SOURCE
|
||||
AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
|
||||
AM_CPPFLAGS += $(lite_CFLAGS)
|
||||
AM_CPPFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
||||
|
||||
if STATIC
|
||||
noinst_LTLIBRARIES = libplug.la
|
||||
libplug_la_SOURCES = bootmisc.c modprobe.c pidfile.c procps.c sys.c tty.c usr.c
|
||||
libplug_la_SOURCES = bootmisc.c pidfile.c procps.c sys.c usr.c
|
||||
|
||||
if BUILD_ALSA_UTILS_PLUGIN
|
||||
libplug_la_SOURCES += alsa-utils.c
|
||||
@@ -25,6 +25,10 @@ if BUILD_MODULES_LOAD_PLUGIN
|
||||
libplug_la_SOURCES += modules-load.c
|
||||
endif
|
||||
|
||||
if BUILD_MODPROBE_PLUGIN
|
||||
libplug_la_SOURCES += modprobe.c
|
||||
endif
|
||||
|
||||
if BUILD_NETLINK_PLUGIN
|
||||
libplug_la_SOURCES += netlink.c
|
||||
endif
|
||||
@@ -37,6 +41,10 @@ if BUILD_RTC_PLUGIN
|
||||
libplug_la_SOURCES += rtc.c
|
||||
endif
|
||||
|
||||
if BUILD_TTY_PLUGIN
|
||||
libplug_la_SOURCES += tty.c
|
||||
endif
|
||||
|
||||
if BUILD_URANDOM_PLUGIN
|
||||
libplug_la_SOURCES += urandom.c
|
||||
endif
|
||||
@@ -46,7 +54,7 @@ libplug_la_SOURCES += x11-common.c
|
||||
endif
|
||||
|
||||
else
|
||||
pkglib_LTLIBRARIES = bootmisc.la modprobe.la pidfile.la procps.la sys.la tty.la usr.la
|
||||
pkglib_LTLIBRARIES = bootmisc.la pidfile.la procps.la sys.la usr.la
|
||||
|
||||
if BUILD_ALSA_UTILS_PLUGIN
|
||||
pkglib_LTLIBRARIES += alsa-utils.la
|
||||
@@ -64,6 +72,10 @@ if BUILD_MODULES_LOAD_PLUGIN
|
||||
pkglib_LTLIBRARIES += modules-load.la
|
||||
endif
|
||||
|
||||
if BUILD_MODPROBE_PLUGIN
|
||||
pkglib_LTLIBRARIES += modprobe.la
|
||||
endif
|
||||
|
||||
if BUILD_NETLINK_PLUGIN
|
||||
pkglib_LTLIBRARIES += netlink.la
|
||||
endif
|
||||
@@ -76,6 +88,10 @@ if BUILD_RTC_PLUGIN
|
||||
pkglib_LTLIBRARIES += rtc.la
|
||||
endif
|
||||
|
||||
if BUILD_TTY_PLUGIN
|
||||
pkglib_LTLIBRARIES += tty.la
|
||||
endif
|
||||
|
||||
if BUILD_URANDOM_PLUGIN
|
||||
pkglib_LTLIBRARIES += urandom.la
|
||||
endif
|
||||
|
||||
@@ -21,7 +21,12 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "plugin.h"
|
||||
|
||||
+16
-6
@@ -24,7 +24,11 @@
|
||||
#include <ftw.h>
|
||||
#include <mntent.h>
|
||||
#include <string.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "finit.h"
|
||||
@@ -100,6 +104,12 @@ static void clean(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
static void ln(const char *target, const char *linkpath)
|
||||
{
|
||||
if (symlink(target, linkpath) && errno != EEXIST)
|
||||
_pe("Failed creating %s -> %s symlink", target, linkpath);
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup standard FHS 2.3 structure in /var, and write runlevel to UTMP
|
||||
*/
|
||||
@@ -121,11 +131,11 @@ static void setup(void *arg)
|
||||
_d("System with new /run tmpfs ...");
|
||||
if (!fisdir("/run/lock"))
|
||||
makedir("/run/lock", 1777);
|
||||
symlink("/run/lock", "/var/lock");
|
||||
symlink("/dev/shm", "/run/shm");
|
||||
ln("/run/lock", "/var/lock");
|
||||
ln("/dev/shm", "/run/shm");
|
||||
|
||||
/* compat only, should really be set up by OS/dist */
|
||||
symlink("/run", "/var/run");
|
||||
ln("/run", "/var/run");
|
||||
} else {
|
||||
makedir("/var/lock", 1777);
|
||||
makedir("/var/run", 0755);
|
||||
@@ -179,7 +189,7 @@ static void setup(void *arg)
|
||||
makedir("/var/run/sshd", 01755); /* OpenSSH */
|
||||
|
||||
if (!fexist("/etc/mtab"))
|
||||
symlink("../proc/self/mounts", "/etc/mtab");
|
||||
ln("../proc/self/mounts", "/etc/mtab");
|
||||
|
||||
/* Void Linux has a uuidd that runs as uuid:uuid and needs /run/uuid */
|
||||
mksubsys("/var/run/uuidd", 0755, "uuidd", "uuidd");
|
||||
@@ -188,7 +198,7 @@ static void setup(void *arg)
|
||||
mksubsys("/var/run/sudo", 0711, "root", "root");
|
||||
mksubsys("/var/run/sudo/ts", 0700, "root", "root");
|
||||
if (whichp("restorecon"))
|
||||
run("restorecon /var/run/sudo /var/run/sudo/ts");
|
||||
run("restorecon /var/run/sudo /var/run/sudo/ts", "restorecon");
|
||||
|
||||
umask(prev);
|
||||
}
|
||||
|
||||
+14
-4
@@ -22,7 +22,11 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "config.h"
|
||||
@@ -35,7 +39,13 @@
|
||||
#define ARGS "--nofork --system --syslog-only"
|
||||
#define DESC "D-Bus message bus daemon"
|
||||
|
||||
#ifndef DAEMONUSER
|
||||
#define DAEMONUSER "messagebus"
|
||||
#endif
|
||||
|
||||
#ifndef DAEMONPIDFILE
|
||||
#define DAEMONPIDFILE "/var/run/dbus/pid"
|
||||
#endif
|
||||
|
||||
static void setup(void *arg)
|
||||
{
|
||||
@@ -61,11 +71,11 @@ static void setup(void *arg)
|
||||
run_interactive("dbus-uuidgen --ensure", "Creating machine UUID for D-Bus");
|
||||
|
||||
/* Clean up from any previous pre-bootstrap run */
|
||||
remove("/var/run/dbus/pid");
|
||||
remove(DAEMONPIDFILE);
|
||||
|
||||
/* Register service with Finit */
|
||||
snprintf(line, sizeof(line), "[S12345789] cgroup.system @%s:%s %s %s -- %s",
|
||||
DAEMONUSER, DAEMONUSER, cmd, ARGS, DESC);
|
||||
snprintf(line, sizeof(line), "[S12345789] cgroup.system pid:!%s @%s:%s %s %s -- %s",
|
||||
DAEMONPIDFILE, DAEMONUSER, DAEMONUSER, cmd, ARGS, DESC);
|
||||
if (service_register(SVC_TYPE_SERVICE, line, global_rlimit, NULL))
|
||||
_pe("Failed registering %s", DAEMON);
|
||||
free(cmd);
|
||||
|
||||
+6
-2
@@ -40,11 +40,15 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h> /* gettimeofday() */
|
||||
#include <sys/types.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "util.h"
|
||||
#include "plugin.h"
|
||||
|
||||
struct module {
|
||||
|
||||
+23
-13
@@ -21,10 +21,14 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <lite/lite.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -40,36 +44,42 @@
|
||||
|
||||
static void load(void *arg)
|
||||
{
|
||||
FILE *fp;
|
||||
DIR *dirp;
|
||||
struct dirent *direntp;
|
||||
struct dirent *d;
|
||||
char line[256];
|
||||
int index = 1;
|
||||
FILE *fp;
|
||||
DIR *dir;
|
||||
|
||||
_d("Scanning " MODULES_LOAD_PATH " for config files ...");
|
||||
|
||||
dirp = opendir(MODULES_LOAD_PATH);
|
||||
if (!dirp) return;
|
||||
dir = opendir(MODULES_LOAD_PATH);
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
while ((direntp = readdir(dirp)))
|
||||
{
|
||||
while ((d = readdir(dir))) {
|
||||
char module_path[PATH_MAX];
|
||||
|
||||
strlcpy(module_path, MODULES_LOAD_PATH "/", sizeof(module_path));
|
||||
strlcat(module_path, direntp->d_name, sizeof(module_path));
|
||||
strlcat(module_path, d->d_name, sizeof(module_path));
|
||||
|
||||
fp = fopen(module_path, "r");
|
||||
if (!fp) continue;
|
||||
if (!fp)
|
||||
continue;
|
||||
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
char cmd[CMD_SIZE], *mod, *args;
|
||||
|
||||
mod = strip_line(line);
|
||||
if (!*mod) continue;
|
||||
if (!*mod)
|
||||
continue;
|
||||
|
||||
mod = chomp(mod);
|
||||
if (!mod || !*mod) continue;
|
||||
if (!mod || !*mod)
|
||||
continue;
|
||||
|
||||
mod = strtok_r(mod, " ", &args);
|
||||
if (!mod)
|
||||
continue;
|
||||
|
||||
snprintf(cmd, sizeof(cmd), SERVICE_LINE, index, mod, mod, args, mod);
|
||||
service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL);
|
||||
@@ -80,7 +90,7 @@ static void load(void *arg)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
static plugin_t plugin = {
|
||||
|
||||
+4
-2
@@ -1,3 +1,4 @@
|
||||
|
||||
/* Netlink plugin for IFUP/IFDN and GW events
|
||||
*
|
||||
* Copyright (C) 2009-2011 Mårten Wikström <marten.wikstrom@keystream.se>
|
||||
@@ -252,7 +253,7 @@ static int nl_parse(int sd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
_d("recv %lld bytes", len);
|
||||
_d("recv %zd bytes", len);
|
||||
l = (size_t)len;
|
||||
for (nh = (struct nlmsghdr *)nl_buf; NLMSG_OK(nh, l); nh = NLMSG_NEXT(nh, l)) {
|
||||
struct nlmsgerr *nle;
|
||||
@@ -355,7 +356,7 @@ static void nl_resync(int all)
|
||||
|
||||
if (all) {
|
||||
_d("============================ RESYNC =================================");
|
||||
/* this doesn't update condtions, and thus does not stop services */
|
||||
/* this doesn't update conditions, and thus does not stop services */
|
||||
cond_deassert("net/");
|
||||
|
||||
nl_resync_ifaces(sd, seq++);
|
||||
@@ -449,6 +450,7 @@ PLUGIN_INIT(plugin_init)
|
||||
PLUGIN_EXIT(plugin_exit)
|
||||
{
|
||||
plugin_unregister(&plugin);
|
||||
close(plugin.io.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-2
@@ -84,8 +84,10 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
|
||||
mkcond(svc, cond, sizeof(cond));
|
||||
if (mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) {
|
||||
svc_started(svc);
|
||||
if (!svc_has_pidfile(svc))
|
||||
if (!svc_has_pidfile(svc)) {
|
||||
_d("Setting %s PID file to %s", svc->name, fn);
|
||||
pid_file_set(svc, fn, 1);
|
||||
}
|
||||
|
||||
if (svc_is_forking(svc)) {
|
||||
pid_t pid;
|
||||
@@ -303,8 +305,8 @@ PLUGIN_INIT(plugin_init)
|
||||
|
||||
PLUGIN_EXIT(plugin_exit)
|
||||
{
|
||||
iwatch_exit(&iw_pidfile);
|
||||
plugin_unregister(&plugin);
|
||||
iwatch_exit(&iw_pidfile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-5
@@ -22,7 +22,11 @@
|
||||
*/
|
||||
|
||||
#include <glob.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -30,9 +34,7 @@
|
||||
|
||||
static void setup(void *arg)
|
||||
{
|
||||
size_t i;
|
||||
glob_t gl;
|
||||
char buf[160];
|
||||
|
||||
if (rescue) {
|
||||
_d("Skipping %s plugin in rescue mode.", __FILE__);
|
||||
@@ -47,9 +49,13 @@ static void setup(void *arg)
|
||||
glob("/mnt/sysctl.d/*.conf", GLOB_APPEND, NULL, &gl);
|
||||
glob("/etc/sysctl.conf", GLOB_APPEND, NULL, &gl);
|
||||
if (gl.gl_pathc > 0) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < gl.gl_pathc; i++) {
|
||||
snprintf(buf, sizeof(buf), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]);
|
||||
run(buf);
|
||||
char cmd[160];
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]);
|
||||
run(cmd, "sysctl");
|
||||
}
|
||||
globfree(&gl);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,11 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
|
||||
+16
-2
@@ -24,7 +24,11 @@
|
||||
#include <time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/rtc.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -152,8 +156,18 @@ static void rtc_restore(void *arg)
|
||||
logit(LOG_ERR, "RTC has no previously saved (valid) time.");
|
||||
else
|
||||
logit(LOG_ERR, "RTC error code %d: %s", errno, strerror(errno));
|
||||
|
||||
/* Been here already? */
|
||||
if (rc)
|
||||
goto out;
|
||||
|
||||
/* Attempt to set RTC to a sane value ... */
|
||||
tv.tv_sec = RTC_TIMESTAMP_BEGIN_2000;
|
||||
if (!gmtime_r(&tv.tv_sec, &tm))
|
||||
goto out;
|
||||
|
||||
logit(LOG_NOTICE, "Resetting RTC to kernel default, 2000-01-01 00:00.");
|
||||
rc = 2;
|
||||
goto out;
|
||||
}
|
||||
|
||||
print_desc(NULL, "Restoring system clock (UTC) from RTC");
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
/* System condtion event monitor for the Finit condition engine
|
||||
/* System condition event monitor for the Finit condition engine
|
||||
*
|
||||
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||
*
|
||||
@@ -197,8 +197,8 @@ PLUGIN_INIT(plugin_init)
|
||||
|
||||
PLUGIN_EXIT(plugin_exit)
|
||||
{
|
||||
iwatch_exit(&iw_sys);
|
||||
plugin_unregister(&plugin);
|
||||
iwatch_exit(&iw_sys);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-3
@@ -27,7 +27,11 @@
|
||||
#include <unistd.h> /* read() */
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/stat.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -112,10 +116,9 @@ PLUGIN_INIT(plugin_init)
|
||||
|
||||
PLUGIN_EXIT(plugin_exit)
|
||||
{
|
||||
plugin_unregister(&plugin);
|
||||
if (plugin.io.fd)
|
||||
close(plugin.io.fd);
|
||||
|
||||
plugin_unregister(&plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+70
-3
@@ -22,19 +22,34 @@
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h> /* gettimeofday() */
|
||||
#include <sys/types.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include <linux/random.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#ifndef RANDOM_BYTES
|
||||
#define RANDOM_BYTES (32*1024)
|
||||
#endif
|
||||
|
||||
static void setup(void *arg)
|
||||
{
|
||||
#ifdef RANDOMSEED
|
||||
struct rand_pool_info *rpi;
|
||||
ssize_t len = 0;
|
||||
int rc = -1;
|
||||
int fd, err;
|
||||
|
||||
if (rescue) {
|
||||
_d("Skipping %s plugin in rescue mode.", __FILE__);
|
||||
return;
|
||||
@@ -67,7 +82,59 @@ static void setup(void *arg)
|
||||
}
|
||||
|
||||
print_desc("Initializing random number generator", NULL);
|
||||
print_result(512 != copyfile(RANDOMSEED, "/dev/urandom", 0, 0));
|
||||
|
||||
/*
|
||||
* Simply copying our saved entropy to /dev/urandom doesn't
|
||||
* increment the kernel "entropy count", instead we must use
|
||||
* the ioctl below.
|
||||
*/
|
||||
fd = open(RANDOMSEED, O_RDONLY);
|
||||
if (fd < 0)
|
||||
goto fallback;
|
||||
|
||||
rpi = malloc(sizeof(*rpi) + RANDOM_BYTES);
|
||||
if (!rpi) {
|
||||
close(fd);
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
do {
|
||||
ssize_t num;
|
||||
|
||||
num = read(fd, &rpi->buf[len], RANDOM_BYTES - len);
|
||||
if (num <= 0) {
|
||||
if (num == -1 && errno == EINTR)
|
||||
continue;
|
||||
if (len > 0)
|
||||
break;
|
||||
|
||||
close(fd);
|
||||
free(rpi);
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
len += num;
|
||||
} while (len < RANDOM_BYTES);
|
||||
close(fd);
|
||||
|
||||
fd = open("/dev/urandom", O_WRONLY);
|
||||
if (fd < 0) {
|
||||
free(rpi);
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
rpi->buf_size = len;
|
||||
rpi->entropy_count = len * 8;
|
||||
rc = ioctl(fd, RNDADDENTROPY, rpi);
|
||||
err = errno;
|
||||
close(fd);
|
||||
free(rpi);
|
||||
if (rc < 0)
|
||||
logit(LOG_ERR, "Failed adding entropy to kernel random pool: %s", strerror(err));
|
||||
print_result(rc < 0);
|
||||
return;
|
||||
fallback:
|
||||
print_result(512 > copyfile(RANDOMSEED, "/dev/urandom", 0, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -84,7 +151,7 @@ static void save(void *arg)
|
||||
prev = umask(077);
|
||||
|
||||
print_desc("Saving random seed", NULL);
|
||||
print_result(512 != copyfile("/dev/urandom", RANDOMSEED, 512, 0));
|
||||
print_result(RANDOM_BYTES != copyfile("/dev/urandom", RANDOMSEED, RANDOM_BYTES, 0));
|
||||
|
||||
umask(prev);
|
||||
#endif
|
||||
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
/* User-defined condtion event monitor for the Finit condition engine
|
||||
/* User-defined condition event monitor for the Finit condition engine
|
||||
*
|
||||
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||
*
|
||||
@@ -97,6 +97,8 @@ static void usr_init(void *arg)
|
||||
|
||||
if (iwatch_add(&iw_usr, path, IN_ONLYDIR))
|
||||
iwatch_exit(&iw_usr);
|
||||
|
||||
free(path);
|
||||
}
|
||||
|
||||
static plugin_t plugin = {
|
||||
@@ -121,8 +123,8 @@ PLUGIN_INIT(plugin_init)
|
||||
|
||||
PLUGIN_EXIT(plugin_exit)
|
||||
{
|
||||
iwatch_exit(&iw_usr);
|
||||
plugin_unregister(&plugin);
|
||||
iwatch_exit(&iw_usr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,11 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -54,7 +58,7 @@ static void setup(void *arg)
|
||||
if ((fd = open("/var/run/console/console.lock", O_CREAT|O_WRONLY|O_TRUNC, 0644)) >= 0) {
|
||||
write(fd, username, strlen(username));
|
||||
close(fd);
|
||||
run("pam_console_apply");
|
||||
run("pam_console_apply", "pam-console");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -62,7 +66,7 @@ static void setup(void *arg)
|
||||
makedir("/tmp/.ICE-unix", 01777);
|
||||
|
||||
if (whichp("restorecon"))
|
||||
run("restorecon /tmp/.ICE-unix /tmp/.X11-unix");
|
||||
run("restorecon /tmp/.ICE-unix /tmp/.X11-unix", "restorecon");
|
||||
|
||||
umask(prev);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include <uev/uev.h>
|
||||
|
||||
#include "config.h"
|
||||
@@ -47,12 +51,12 @@
|
||||
extern svc_t *wdog;
|
||||
static uev_t api_watcher;
|
||||
|
||||
static int call(int (*action)(svc_t *), char *buf, size_t len)
|
||||
static int call(int (*action)(svc_t *, void *), char *buf, size_t len)
|
||||
{
|
||||
return svc_parse_jobstr(buf, len, action, NULL);
|
||||
return svc_parse_jobstr(buf, len, NULL, action, NULL);
|
||||
}
|
||||
|
||||
static int stop(svc_t *svc)
|
||||
static int stop(svc_t *svc, void *user_data)
|
||||
{
|
||||
if (!svc)
|
||||
return 1;
|
||||
@@ -63,7 +67,7 @@ static int stop(svc_t *svc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int start(svc_t *svc)
|
||||
static int start(svc_t *svc, void *user_data)
|
||||
{
|
||||
if (!svc)
|
||||
return 1;
|
||||
@@ -79,7 +83,7 @@ static int start(svc_t *svc)
|
||||
* responsibility of initctl to do. Otherwise we'd block PID 1,
|
||||
* or introduce some nasty race conditions.
|
||||
*/
|
||||
static int restart(svc_t *svc)
|
||||
static int restart(svc_t *svc, void *user_data)
|
||||
{
|
||||
if (!svc)
|
||||
return 1;
|
||||
@@ -91,7 +95,7 @@ static int restart(svc_t *svc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reload(svc_t *svc)
|
||||
static int reload(svc_t *svc, void *user_data)
|
||||
{
|
||||
if (!svc)
|
||||
return 1;
|
||||
@@ -110,8 +114,28 @@ static int do_start (char *buf, size_t len) { return call(start, buf, len); }
|
||||
static int do_restart(char *buf, size_t len) { return call(restart, buf, len); }
|
||||
static int do_reload (char *buf, size_t len) { return call(reload, buf, len); }
|
||||
|
||||
static int do_signal_svc(svc_t *svc, void *user_data)
|
||||
{
|
||||
int signo;
|
||||
|
||||
if (!svc || !user_data || !svc_is_running(svc))
|
||||
return 1;
|
||||
|
||||
signo = *(int *)user_data;
|
||||
return !!kill(svc->pid, signo);
|
||||
}
|
||||
|
||||
static int do_signal(char *buf, size_t len, int sig)
|
||||
{
|
||||
/* Sanity check: do we know this signal? */
|
||||
if (!*sig2str(sig))
|
||||
return 1;
|
||||
|
||||
return svc_parse_jobstr(buf, len, &sig, do_signal_svc, NULL);
|
||||
}
|
||||
|
||||
static char query_buf[368];
|
||||
static int missing(char *job, char *id)
|
||||
static int missing(char *job, char *id, void *user_data)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
@@ -129,7 +153,7 @@ static int missing(char *job, char *id)
|
||||
static int do_query(char *buf, size_t len)
|
||||
{
|
||||
query_buf[0] = 0;
|
||||
if (svc_parse_jobstr(buf, len, NULL, missing)) {
|
||||
if (svc_parse_jobstr(buf, len, NULL, NULL, missing)) {
|
||||
memcpy(buf, query_buf, len);
|
||||
return 1;
|
||||
}
|
||||
@@ -226,10 +250,10 @@ static int do_reboot(int cmd, char *buf, size_t len)
|
||||
case INIT_CMD_SUSPEND:
|
||||
_d("suspend");
|
||||
sync();
|
||||
rc = reboot(RB_SW_SUSPEND);
|
||||
rc = suspend();
|
||||
if (rc) {
|
||||
if (errno == EINVAL)
|
||||
snprintf(buf, len, "Kernel does not support suspend.");
|
||||
snprintf(buf, len, "Kernel does not support suspend to RAM.");
|
||||
else
|
||||
snprintf(buf, len, "Failed: %s", strerror(errno));
|
||||
}
|
||||
@@ -387,7 +411,7 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
break;
|
||||
}
|
||||
|
||||
_e("Request to hand-over wdog ... to PID %d", rq.runlevel);
|
||||
_d("Request to hand-over wdog ... to PID %d", rq.runlevel);
|
||||
svc = svc_find_by_pid(rq.runlevel);
|
||||
if (!svc) {
|
||||
logit(LOG_ERR, "Cannot find PID %d, not registered.", rq.runlevel);
|
||||
@@ -403,7 +427,7 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
if (wdog->protect) {
|
||||
logit(LOG_NOTICE, "Stopping and deleting built-in watchdog.");
|
||||
stop(wdog);
|
||||
stop(wdog, NULL);
|
||||
svc_del(wdog);
|
||||
}
|
||||
}
|
||||
@@ -413,7 +437,7 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
case INIT_CMD_SVC_ITER:
|
||||
// _d("svc iter, first: %d", rq.runlevel);
|
||||
/*
|
||||
* XXX: This severly limits the number of
|
||||
* XXX: This severely limits the number of
|
||||
* simultaneous client connections, but will
|
||||
* have to do for now.
|
||||
*/
|
||||
@@ -439,6 +463,13 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
send_svc(sd, do_find_byc(rq.data, sizeof(rq.data)));
|
||||
goto leave;
|
||||
|
||||
case INIT_CMD_SIGNAL:
|
||||
/* runlevel is reused for signal */
|
||||
_d("svc signal %d: %s", rq.runlevel, rq.data);
|
||||
strterm(rq.data, sizeof(rq.data));
|
||||
result = do_signal(rq.data, sizeof(rq.data), rq.runlevel);
|
||||
break;
|
||||
|
||||
default:
|
||||
_d("Unsupported cmd: %d", rq.cmd);
|
||||
break;
|
||||
@@ -466,12 +497,13 @@ error:
|
||||
|
||||
int api_init(uev_ctx_t *ctx)
|
||||
{
|
||||
int sd;
|
||||
mode_t oldmask;
|
||||
struct sockaddr_un sun = {
|
||||
.sun_family = AF_UNIX,
|
||||
.sun_path = INIT_SOCKET,
|
||||
};
|
||||
mode_t oldmask;
|
||||
int uid, gid;
|
||||
int sd;
|
||||
|
||||
_d("Setting up external API socket ...");
|
||||
sd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
|
||||
@@ -480,20 +512,26 @@ int api_init(uev_ctx_t *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
uid = geteuid();
|
||||
gid = getgroup(DEFGROUP);
|
||||
|
||||
erase(INIT_SOCKET);
|
||||
oldmask = umask(0077);
|
||||
oldmask = umask(0117);
|
||||
if (-1 == bind(sd, (struct sockaddr*)&sun, sizeof(sun)))
|
||||
goto error;
|
||||
|
||||
if (-1 == listen(sd, 10))
|
||||
goto error;
|
||||
|
||||
if (chown(INIT_SOCKET, uid, gid))
|
||||
_pe("Failed setting group %s on %s", DEFGROUP, INIT_SOCKET);
|
||||
|
||||
umask(oldmask);
|
||||
if (!uev_io_init(ctx, &api_watcher, api_cb, NULL, sd, UEV_READ))
|
||||
return 0;
|
||||
|
||||
error:
|
||||
_pe("Failed intializing API socket");
|
||||
_pe("Failed initializing API socket");
|
||||
umask(oldmask);
|
||||
close(sd);
|
||||
return 1;
|
||||
|
||||
+67
-15
@@ -24,8 +24,13 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <lite/lite.h>
|
||||
#include <lite/queue.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
#include <sys/mount.h>
|
||||
#include <sys/sysinfo.h> /* get_nprocs_conf() */
|
||||
|
||||
@@ -42,7 +47,7 @@ struct cg {
|
||||
char *cfg; /* kernel settings */
|
||||
|
||||
int active; /* for mark & sweep */
|
||||
int protected; /* for init/, user/, & system/ */
|
||||
int is_protected; /* for init/, user/, & system/ */
|
||||
};
|
||||
|
||||
static TAILQ_HEAD(, cg) cgroups = TAILQ_HEAD_INITIALIZER(cgroups);
|
||||
@@ -51,6 +56,7 @@ static char controllers[256];
|
||||
|
||||
static struct iwatch iw_cgroup;
|
||||
static uev_t cgw;
|
||||
static int avail;
|
||||
|
||||
|
||||
static void cgset(const char *path, char *ctrl, char *prop)
|
||||
@@ -159,6 +165,9 @@ static int cgroup_leaf_init(char *group, char *name, int pid, const char *cfg)
|
||||
|
||||
int cgroup_user(char *name, int pid)
|
||||
{
|
||||
if (!avail)
|
||||
return 0;
|
||||
|
||||
return cgroup_leaf_init("user", name, pid, NULL);
|
||||
}
|
||||
|
||||
@@ -166,6 +175,9 @@ int cgroup_service(char *name, int pid, struct cgroup *cg)
|
||||
{
|
||||
char *group = "system";
|
||||
|
||||
if (!avail)
|
||||
return 0;
|
||||
|
||||
if (cg && cg->name[0]) {
|
||||
char path[256];
|
||||
|
||||
@@ -302,8 +314,11 @@ void cgroup_mark_all(void)
|
||||
{
|
||||
struct cg *cg;
|
||||
|
||||
if (!avail)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH(cg, &cgroups, link) {
|
||||
if (cg->protected)
|
||||
if (cg->is_protected)
|
||||
continue;
|
||||
|
||||
cg->active = 0;
|
||||
@@ -318,6 +333,9 @@ void cgroup_cleanup(void)
|
||||
struct cg *cg, *tmp;
|
||||
char path[256];
|
||||
|
||||
if (!avail)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH_SAFE(cg, &cgroups, link, tmp) {
|
||||
if (cg->active)
|
||||
continue;
|
||||
@@ -330,10 +348,13 @@ void cgroup_cleanup(void)
|
||||
/*
|
||||
* Add, or update, settings for top-level cgroup
|
||||
*/
|
||||
int cgroup_add(char *name, char *cfg, int protected)
|
||||
int cgroup_add(char *name, char *cfg, int is_protected)
|
||||
{
|
||||
struct cg *cg;
|
||||
|
||||
if (!avail)
|
||||
return 0;
|
||||
|
||||
if (!name)
|
||||
return -1;
|
||||
if (!cfg)
|
||||
@@ -364,7 +385,7 @@ int cgroup_add(char *name, char *cfg, int protected)
|
||||
free(cg);
|
||||
return -1;
|
||||
}
|
||||
cg->protected = protected;
|
||||
cg->is_protected = is_protected;
|
||||
cg->active = 1;
|
||||
|
||||
return 0;
|
||||
@@ -378,6 +399,9 @@ int cgroup_del(char *dir)
|
||||
struct cg *cg;
|
||||
char path[256];
|
||||
|
||||
if (!avail)
|
||||
return 0;
|
||||
|
||||
TAILQ_FOREACH(cg, &cgroups, link) {
|
||||
snprintf(path, sizeof(path), FINIT_CGPATH "/%s", cg->name);
|
||||
if (strcmp(path, dir))
|
||||
@@ -409,6 +433,9 @@ void cgroup_config(void)
|
||||
{
|
||||
struct cg *cg;
|
||||
|
||||
if (!avail)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH(cg, &cgroups, link) {
|
||||
char path[256];
|
||||
int leaf = 0;
|
||||
@@ -437,14 +464,24 @@ void cgroup_init(uev_ctx_t *ctx)
|
||||
int fd;
|
||||
|
||||
if (mount("none", FINIT_CGPATH, "cgroup2", opts, NULL)) {
|
||||
_pe("Failed mounting cgroup v2");
|
||||
if (errno == ENOENT)
|
||||
logit(LOG_NOTICE, "Kernel does not support cgroups v2, disabling.");
|
||||
else if (errno == EPERM) /* Probably inside an unpriviliged container */
|
||||
logit(LOG_NOTICE, "Not allowed to mount cgroups v2, disabling.");
|
||||
else
|
||||
_pe("Failed mounting cgroup v2");
|
||||
avail = 0;
|
||||
return;
|
||||
}
|
||||
avail = 1;
|
||||
|
||||
/* Find available controllers */
|
||||
fp = fopen(FINIT_CGPATH "/cgroup.controllers", "r");
|
||||
if (!fp) {
|
||||
_pe("Failed opening %s", FINIT_CGPATH "/cgroup.controllers");
|
||||
abort:
|
||||
umount(FINIT_CGPATH);
|
||||
avail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -460,9 +497,26 @@ void cgroup_init(uev_ctx_t *ctx)
|
||||
|
||||
fclose(fp);
|
||||
|
||||
/* Check for cpu controller, abort if missing */
|
||||
if (!strstr(controllers, "+cpu")) {
|
||||
logit(LOG_NOTICE, "Missing CPU controller, disabling cgroup support.");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
/* Enable all controllers */
|
||||
if (fnwrite(controllers, FINIT_CGPATH "/cgroup.subtree_control"))
|
||||
if (fnwrite(controllers, FINIT_CGPATH "/cgroup.subtree_control")) {
|
||||
_pe("Failed enabling %s for %s", controllers, FINIT_CGPATH "/cgroup.subtree_control");
|
||||
goto abort;
|
||||
}
|
||||
|
||||
/* prepare cgroup.events watcher */
|
||||
fd = iwatch_init(&iw_cgroup);
|
||||
if (uev_io_init(ctx, &cgw, cgroup_events_cb, NULL, fd, UEV_READ)) {
|
||||
_pe("Failed setting up cgroup.events watcher");
|
||||
iwatch_exit(&iw_cgroup);
|
||||
close(fd);
|
||||
goto abort;
|
||||
}
|
||||
|
||||
/* Default (protected) groups, PID 1, services, and user/login processes */
|
||||
cgroup_add("init", "cpu.weight:100", 1);
|
||||
@@ -471,14 +525,12 @@ void cgroup_init(uev_ctx_t *ctx)
|
||||
cgroup_config();
|
||||
|
||||
/* Move ourselves to init (best effort, otherwise run in 'root' group */
|
||||
if (fnwrite("1", FINIT_CGPATH "/init/cgroup.procs"))
|
||||
_pe("Failed moving PID 1 to cgroup ", FINIT_CGPATH "/init");
|
||||
|
||||
/* prepare cgroup.events watcher */
|
||||
fd = iwatch_init(&iw_cgroup);
|
||||
if (uev_io_init(ctx, &cgw, cgroup_events_cb, NULL, fd, UEV_READ)) {
|
||||
_pe("Failed setting up cgroup.events watcher");
|
||||
if (fnwrite("1", FINIT_CGPATH "/init/cgroup.procs")) {
|
||||
_pe("Failed moving PID 1 to cgroup %s", FINIT_CGPATH "/init");
|
||||
uev_io_stop(&cgw);
|
||||
iwatch_exit(&iw_cgroup);
|
||||
close(fd);
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ struct cgroup {
|
||||
void cgroup_mark_all(void);
|
||||
void cgroup_cleanup (void);
|
||||
|
||||
int cgroup_add (char *name, char *cfg, int protected);
|
||||
int cgroup_add (char *name, char *cfg, int is_protected);
|
||||
int cgroup_del (char *dir);
|
||||
void cgroup_config (void);
|
||||
|
||||
|
||||
+9
-1
@@ -30,7 +30,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <search.h>
|
||||
#include <inttypes.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include <sys/sysinfo.h> /* sysinfo() */
|
||||
|
||||
#include "cgutil.h"
|
||||
@@ -49,6 +53,10 @@ uint64_t total_ram; /* From sysinfo() */
|
||||
struct cg dummy; /* empty result "NULL" */
|
||||
struct cg *list;
|
||||
|
||||
int cgroup_avail(void)
|
||||
{
|
||||
return fismnt(FINIT_CGPATH);
|
||||
}
|
||||
|
||||
char *pid_cmdline(int pid, char *buf, size_t len)
|
||||
{
|
||||
|
||||
@@ -52,6 +52,8 @@ struct cg {
|
||||
} cg_cpu;
|
||||
};
|
||||
|
||||
int cgroup_avail(void);
|
||||
|
||||
char *pid_cmdline (int pid, char *buf, size_t len);
|
||||
char *pid_comm (int pid, char *buf, size_t len);
|
||||
char *pid_cgroup (int pid, char *buf, size_t len);
|
||||
|
||||
+5
-3
@@ -86,11 +86,13 @@ int client_send(struct init_request *rq, ssize_t len)
|
||||
}
|
||||
|
||||
pfd.fd = sd;
|
||||
pfd.events = POLLIN;
|
||||
pfd.events = POLLIN | POLLERR | POLLHUP;
|
||||
if ((rc = poll(&pfd, 1, 2000)) <= 0) {
|
||||
if (rc)
|
||||
if (rc) {
|
||||
if (errno == EINTR) /* shutdown/reboot */
|
||||
goto exit;
|
||||
warn("poll(), errno %d", errno);
|
||||
else
|
||||
} else
|
||||
warnx("Timed out waiting for reply from Finit.");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
+6
-2
@@ -23,8 +23,12 @@
|
||||
|
||||
#include <ftw.h>
|
||||
#include <libgen.h>
|
||||
#include <lite/lite.h>
|
||||
#include <stdio.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "cond.h"
|
||||
@@ -273,7 +277,7 @@ static int do_assert(const char *fpath, const struct stat *sb, int tflg, struct
|
||||
|
||||
nm = strstr((char *)fpath, COND_BASE);
|
||||
if (!nm) {
|
||||
_e("Incorrect condtion path %s, cannot %sassert", fpath, set ? "re" : "de");
|
||||
_e("Incorrect condition path %s, cannot %sassert", fpath, set ? "re" : "de");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -21,8 +21,12 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <lite/lite.h>
|
||||
#include <stdio.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "cond.h"
|
||||
|
||||
+2
-1
@@ -2,7 +2,8 @@
|
||||
#define FINIT_COND_H_
|
||||
|
||||
#include <paths.h>
|
||||
#include <svc.h>
|
||||
|
||||
#include "svc.h"
|
||||
|
||||
#define COND_BASE "finit/cond"
|
||||
#define COND_PID "pid/"
|
||||
|
||||
+72
-25
@@ -28,14 +28,20 @@
|
||||
#include <string.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/resource.h>
|
||||
#include <lite/lite.h>
|
||||
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "cond.h"
|
||||
#include "iwatch.h"
|
||||
#include "private.h"
|
||||
#include "service.h"
|
||||
#include "tty.h"
|
||||
#include "helpers.h"
|
||||
@@ -80,8 +86,9 @@ fallback:
|
||||
}
|
||||
|
||||
/*
|
||||
* finit.debug = [on,off]
|
||||
* finit.show_status = [on,off]
|
||||
* finit.debug = [on,off]
|
||||
* finit.status = [on,off] (compat finit.show_status)
|
||||
* finit.status_style = [old,classic,modern]
|
||||
*/
|
||||
static void parse_finit_opts(char *opt)
|
||||
{
|
||||
@@ -109,7 +116,7 @@ static void parse_finit_opts(char *opt)
|
||||
return;
|
||||
}
|
||||
|
||||
if (string_compare(opt, "show_status")) {
|
||||
if (string_compare(opt, "status") || string_compare(opt, "show_status")) {
|
||||
show_progress(get_bool(arg, 1) ? PROGRESS_DEFAULT : PROGRESS_SILENT);
|
||||
return;
|
||||
}
|
||||
@@ -165,39 +172,55 @@ static void parse_kernel_cmdline(void)
|
||||
#define parse_kernel_cmdline()
|
||||
#endif
|
||||
|
||||
static void parse_kernel_loglevel(void)
|
||||
{
|
||||
char line[LINE_SIZE], *ptr;
|
||||
FILE *fp;
|
||||
int val;
|
||||
|
||||
fp = fopen("/proc/sys/kernel/printk", "r");
|
||||
if (!fp)
|
||||
return;
|
||||
|
||||
if (!fgets(line, sizeof(line), fp)) {
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
ptr = chomp(line);
|
||||
_d("%s", ptr);
|
||||
val = atoi(ptr);
|
||||
if (val >= 7)
|
||||
kerndebug = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Kernel gives us all non-kernel options on our cmdline
|
||||
*/
|
||||
void conf_parse_cmdline(int argc, char *argv[])
|
||||
{
|
||||
int dbg = 0;
|
||||
|
||||
for (int i = 1; i < argc; i++)
|
||||
parse_arg(argv[i]);
|
||||
|
||||
parse_kernel_cmdline();
|
||||
|
||||
log_init(dbg);
|
||||
parse_kernel_loglevel();
|
||||
}
|
||||
|
||||
static int kmod_exists(char *mod)
|
||||
{
|
||||
char buf[256];
|
||||
int found = 0;
|
||||
FILE *fp;
|
||||
char buf[256];
|
||||
size_t len;
|
||||
|
||||
for (len = 0; mod[len]; len++) {
|
||||
if (mod[len] == ' ' || mod[len] == '\t')
|
||||
break;
|
||||
}
|
||||
|
||||
fp = fopen("/proc/modules", "r");
|
||||
if (!fp)
|
||||
return 0;
|
||||
|
||||
while (!found && (fgets(buf, sizeof(buf), fp))) {
|
||||
if (!strncmp(buf, mod, len))
|
||||
while (!found && fgets(buf, sizeof(buf), fp)) {
|
||||
char *kmod = strtok(buf, " \t");
|
||||
|
||||
if (kmod && !strcmp(kmod, mod))
|
||||
found = 1;
|
||||
}
|
||||
fclose(fp);
|
||||
@@ -205,22 +228,26 @@ static int kmod_exists(char *mod)
|
||||
return found;
|
||||
}
|
||||
|
||||
static void kmod_load(char *line)
|
||||
static void kmod_load(char *mod)
|
||||
{
|
||||
char *mod;
|
||||
char module[64] = { 0 };
|
||||
char cmd[CMD_SIZE];
|
||||
|
||||
if (runlevel != 0)
|
||||
return;
|
||||
|
||||
mod = strip_line(line);
|
||||
if (kmod_exists(mod))
|
||||
/* Strip args for progress below and kmod_exists() */
|
||||
strlcpy(module, mod, sizeof(module));
|
||||
if (!strtok(module, " \t"))
|
||||
return;
|
||||
|
||||
if (kmod_exists(module))
|
||||
return;
|
||||
|
||||
strcpy(cmd, "modprobe ");
|
||||
strlcat(cmd, mod, sizeof(cmd));
|
||||
|
||||
run_interactive(cmd, "Loading kernel module %s", mod);
|
||||
run_interactive(cmd, "Loading kernel module %s", module);
|
||||
}
|
||||
|
||||
/* Convert optional "[!123456789S]" string into a bitmask */
|
||||
@@ -473,7 +500,7 @@ static void parse_static(char *line, int is_rcsd)
|
||||
|
||||
/* Kernel module to load */
|
||||
if (BOOTSTRAP && MATCH_CMD(line, "module ", x)) {
|
||||
kmod_load(x);
|
||||
kmod_load(strip_line(x));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -544,6 +571,26 @@ static void parse_static(char *line, int is_rcsd)
|
||||
cfglevel = 2; /* Fallback */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Periodic check and instability index leveler, seconds
|
||||
*/
|
||||
if (MATCH_CMD(line, "service-interval ", x)) {
|
||||
char *token = strip_line(x);
|
||||
const char *err = NULL;
|
||||
int val;
|
||||
|
||||
/* 0 min to 1 day, should check at least daily */
|
||||
val = strtonum(token, 0, 1440, &err);
|
||||
if (!err) {
|
||||
int disabled = !service_interval;
|
||||
|
||||
service_interval = val * 1000; /* to milliseconds */
|
||||
if (disabled)
|
||||
service_init();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_dynamic(char *line, struct rlimit rlimit[], char *file)
|
||||
@@ -580,7 +627,7 @@ static void parse_dynamic(char *line, struct rlimit rlimit[], char *file)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read contrl group limits */
|
||||
/* Read control group limits */
|
||||
if (MATCH_CMD(line, "cgroup ", x)) {
|
||||
conf_parse_cgroup(x);
|
||||
return;
|
||||
|
||||
+95
-51
@@ -28,12 +28,17 @@
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
#include <sysexits.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
||||
#include <termios.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include <linux/vt.h>
|
||||
|
||||
#include "finit.h"
|
||||
@@ -66,89 +71,128 @@ int complete(char *cmd, int pid)
|
||||
return status;
|
||||
}
|
||||
|
||||
int run(char *cmd)
|
||||
static int do_redirect(void)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("/dev/null", "w");
|
||||
if (fp) {
|
||||
int fd = fileno(fp);
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
|
||||
return fclose(fp);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Run 'cmd' and wait for completion. If 'log' is not NULL any output
|
||||
* from the command is logged with the given string as prefix, use "" to
|
||||
* skip. If 'log' is NULL all output is redirected to /dev/null, which
|
||||
* is what this function originally did.
|
||||
*/
|
||||
int run(char *cmd, char *log)
|
||||
{
|
||||
char *args[NUM_ARGS + 1] = { 0 };
|
||||
int status, result, i = 0;
|
||||
char *args[NUM_ARGS + 1], *arg, *backup;
|
||||
char *backup = NULL;
|
||||
pid_t pid;
|
||||
|
||||
/* We must create a copy that is possible to modify. */
|
||||
backup = arg = strdup(cmd);
|
||||
if (!arg)
|
||||
return 1; /* Failed allocating a string to be modified. */
|
||||
if (!log) {
|
||||
char *arg;
|
||||
|
||||
/* Split command line into tokens of an argv[] array. */
|
||||
args[i++] = strsep(&arg, "\t ");
|
||||
while (arg && i < NUM_ARGS) {
|
||||
/* Handle run("su -c \"dbus-daemon --system\" messagebus");
|
||||
* => "su", "-c", "\"dbus-daemon --system\"", "messagebus" */
|
||||
if (*arg == '\'' || *arg == '"') {
|
||||
char *p, delim[2] = " ";
|
||||
/* We must create a copy that is possible to modify. */
|
||||
backup = arg = strdup(cmd);
|
||||
if (!arg)
|
||||
return 1;
|
||||
|
||||
delim[0] = arg[0];
|
||||
args[i++] = arg++;
|
||||
strsep(&arg, delim);
|
||||
p = arg - 1;
|
||||
*p = *delim;
|
||||
*arg++ = 0;
|
||||
} else {
|
||||
args[i++] = strsep(&arg, "\t ");
|
||||
/* Split command line into tokens of an argv[] array. */
|
||||
args[i++] = strsep(&arg, "\t ");
|
||||
while (arg && i < NUM_ARGS) {
|
||||
/* Handle run("su -c \"dbus-daemon --system\" messagebus");
|
||||
* => "su", "-c", "\"dbus-daemon --system\"", "messagebus" */
|
||||
if (*arg == '\'' || *arg == '"') {
|
||||
char *p, delim[2] = " ";
|
||||
|
||||
delim[0] = arg[0];
|
||||
args[i++] = arg++;
|
||||
strsep(&arg, delim);
|
||||
p = arg - 1;
|
||||
*p = *delim;
|
||||
*arg++ = 0;
|
||||
} else {
|
||||
args[i++] = strsep(&arg, "\t ");
|
||||
}
|
||||
}
|
||||
}
|
||||
args[i] = NULL;
|
||||
args[i] = NULL;
|
||||
|
||||
if (i == NUM_ARGS && arg) {
|
||||
_e("Command too long: %s", cmd);
|
||||
free(backup);
|
||||
errno = EOVERFLOW;
|
||||
return 1;
|
||||
if (i == NUM_ARGS && arg) {
|
||||
_e("Command too long: %s", cmd);
|
||||
free(backup);
|
||||
errno = EOVERFLOW;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (0 == pid) {
|
||||
FILE *fp;
|
||||
int rc = EX_OSERR;
|
||||
|
||||
setsid();
|
||||
sig_unblock();
|
||||
if (!log) {
|
||||
do_redirect();
|
||||
execvp(args[0], args);
|
||||
} else {
|
||||
char *pfx = *log ? ": " : "";
|
||||
FILE *pp;
|
||||
|
||||
/* Always redirect stdio for run() */
|
||||
fp = fopen("/dev/null", "w");
|
||||
if (fp) {
|
||||
int fd = fileno(fp);
|
||||
pp = popen(cmd, "r");
|
||||
if (pp) {
|
||||
char buf[256];
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
while (fgets(buf, sizeof(buf), pp)) {
|
||||
chomp(buf);
|
||||
logit(LOG_NOTICE, "%s%s%s", log, pfx, buf);
|
||||
}
|
||||
|
||||
rc = pclose(pp);
|
||||
}
|
||||
}
|
||||
|
||||
sig_unblock();
|
||||
execvp(args[0], args);
|
||||
|
||||
_exit(1); /* Only if execv() fails. */
|
||||
_exit(rc);
|
||||
} else if (-1 == pid) {
|
||||
_pe("%s", args[0]);
|
||||
free(backup);
|
||||
_pe("%s", !log ? args[0] : cmd);
|
||||
if (backup)
|
||||
free(backup);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = complete(args[0], pid);
|
||||
if (-1 == status) {
|
||||
free(backup);
|
||||
if (backup)
|
||||
free(backup);
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = WEXITSTATUS(status);
|
||||
if (WIFEXITED(status)) {
|
||||
_d("Started %s and ended OK: %d", args[0], result);
|
||||
_d("Started '%s' and exit without signal, status: %d", cmd, result);
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
_d("Process %s terminated by signal %d", args[0], WTERMSIG(status));
|
||||
_d("Process '%s' terminated by signal %d", cmd, WTERMSIG(status));
|
||||
if (!result)
|
||||
result = 1; /* Must alert callee that the command did complete successfully.
|
||||
* This is necessary since not all programs trap signals and
|
||||
* change their return code accordingly. --Jocke */
|
||||
}
|
||||
|
||||
free(backup);
|
||||
if (backup)
|
||||
free(backup);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -182,7 +226,7 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
}
|
||||
|
||||
/* Run cmd ... */
|
||||
status = run(cmd);
|
||||
status = run(cmd, "");
|
||||
|
||||
/* Restore stderr/stdout */
|
||||
if (fp && !debug) {
|
||||
@@ -218,7 +262,6 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
|
||||
int exec_runtask(char *cmd, char *args[])
|
||||
{
|
||||
size_t i;
|
||||
char buf[1024] = "";
|
||||
char *argv[4] = {
|
||||
"sh",
|
||||
@@ -226,6 +269,7 @@ int exec_runtask(char *cmd, char *args[])
|
||||
buf,
|
||||
NULL
|
||||
};
|
||||
size_t i;
|
||||
|
||||
strlcat(buf, cmd, sizeof(buf));
|
||||
for (i = 1; args[i]; i++) {
|
||||
@@ -282,7 +326,7 @@ static void prepare_tty(char *tty, speed_t speed, char *procname, struct rlimit
|
||||
static int activate_console(int noclear, int nowait)
|
||||
{
|
||||
static const char msg[] = "\nPlease press Enter to activate this console.";
|
||||
static const char clr[] = "\r\e[2K";
|
||||
static const char clr[] = "\r\e[K";
|
||||
static const char cup[] = "\e[A";
|
||||
struct termios orig;
|
||||
char c;
|
||||
@@ -351,7 +395,7 @@ pid_t run_getty(char *tty, char *cmd, char *args[], int noclear, int nowait, str
|
||||
/* Dunno speed, tell stty() to not mess with it */
|
||||
prepare_tty(tty, B0, "getty", rlimit);
|
||||
if (activate_console(noclear, nowait)) {
|
||||
logit(LOG_INFO, "Starting external getty on %s", tty);
|
||||
logit(LOG_INFO, "Starting getty on %s", tty);
|
||||
rc = execv(cmd, args);
|
||||
}
|
||||
|
||||
|
||||
+86
-33
@@ -36,7 +36,11 @@
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h> /* umask(), mkdir() */
|
||||
#include <sys/wait.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "cgroup.h"
|
||||
@@ -61,6 +65,7 @@ int debug = 0; /* debug mode from kernel cmdline */
|
||||
int rescue = 0; /* rescue mode from kernel cmdline */
|
||||
int single = 0; /* single user mode from kernel cmdline */
|
||||
int bootstrap = 1; /* set while bootrapping (for TTYs) */
|
||||
int kerndebug = 0; /* set if /proc/sys/kernel/printk > 7 */
|
||||
char *sdown = NULL;
|
||||
char *network = NULL;
|
||||
char *hostname = NULL;
|
||||
@@ -82,7 +87,7 @@ static void banner(void)
|
||||
* similar enabled to start emptying /dev/kmsg, but for
|
||||
* our progress we want to own the console.
|
||||
*/
|
||||
if (!debug)
|
||||
if (!debug && !kerndebug)
|
||||
klogctl(6, NULL, 0);
|
||||
|
||||
/*
|
||||
@@ -117,6 +122,7 @@ static int fsck(int pass)
|
||||
while ((fs = getfsent())) {
|
||||
char cmd[80];
|
||||
struct stat st;
|
||||
int fsck_rc = 0;
|
||||
|
||||
if (fs->fs_passno != pass)
|
||||
continue;
|
||||
@@ -134,8 +140,33 @@ static int fsck(int pass)
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef FSCK_FIX
|
||||
snprintf(cmd, sizeof(cmd), "fsck -yf %s", fs->fs_spec);
|
||||
#else
|
||||
snprintf(cmd, sizeof(cmd), "fsck -a %s", fs->fs_spec);
|
||||
rc += run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec);
|
||||
#endif
|
||||
fsck_rc = run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec);
|
||||
/*
|
||||
* "failure" is defined as exiting with a return code of
|
||||
* 2 or larger. A return code of 1 indicates that filesystem
|
||||
* errors were corrected but that the boot may proceed.
|
||||
*/
|
||||
if (fsck_rc > 1) {
|
||||
char *sulogin[] = {
|
||||
_PATH_SULOGIN,
|
||||
"sulogin",
|
||||
};
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < NELEMS(sulogin); i++) {
|
||||
if (systemf(sulogin[i]))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
do_shutdown(SHUT_REBOOT);
|
||||
}
|
||||
rc += fsck_rc;
|
||||
}
|
||||
|
||||
endfsent();
|
||||
@@ -145,17 +176,31 @@ static int fsck(int pass)
|
||||
|
||||
static int fsck_all(void)
|
||||
{
|
||||
int pass, rc = 0;
|
||||
int rc = 0;
|
||||
#ifndef FAST_BOOT
|
||||
int pass;
|
||||
|
||||
for (pass = 1; pass < 10; pass++) {
|
||||
rc = fsck(pass);
|
||||
if (rc)
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Wrapper for mount(2), logs any errors to stderr */
|
||||
static void fs_mount(const char *src, const char *tgt, const char *fstype,
|
||||
unsigned long flags, const void *data)
|
||||
{
|
||||
const char *msg = !fstype ? "MS_MOVE" : "mounting";
|
||||
int rc;
|
||||
|
||||
rc = mount(src, tgt, fstype, flags, data);
|
||||
if (rc && errno != EBUSY)
|
||||
_pe("Failed %s %s on %s", msg, src, tgt);
|
||||
}
|
||||
|
||||
#ifndef SYSROOT
|
||||
/* If / is not listed in fstab, or listed as 'ro', leave it alone */
|
||||
static int fs_readonly_root(struct fstab *fs)
|
||||
@@ -207,8 +252,7 @@ static void fs_remount_root(int fsckerr)
|
||||
* XXX: Untested, in the initramfs age we should
|
||||
* probably use switch_root instead.
|
||||
*/
|
||||
if (mount(SYSROOT, "/", NULL, MS_MOVE, NULL))
|
||||
_pe("Failed %s / MS_MOVE");
|
||||
fs_mount(SYSROOT, "/", NULL, MS_MOVE, NULL);
|
||||
}
|
||||
#endif /* SYSROOT */
|
||||
|
||||
@@ -232,7 +276,7 @@ static void fs_finalize(void)
|
||||
*/
|
||||
if (!fismnt("/dev/shm")) {
|
||||
makedir("/dev/shm", 0777);
|
||||
mount("shm", "/dev/shm", "tmpfs", 0, "mode=0777");
|
||||
fs_mount("shm", "/dev/shm", "tmpfs", 0, "mode=0777");
|
||||
}
|
||||
|
||||
/* Modern systems use /dev/pts */
|
||||
@@ -250,7 +294,7 @@ static void fs_finalize(void)
|
||||
snprintf(opts, sizeof(opts), "gid=%d,mode=%d,ptmxmode=0666", gid, mode);
|
||||
|
||||
makedir("/dev/pts", 0755);
|
||||
mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, opts);
|
||||
fs_mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, opts);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -263,19 +307,19 @@ static void fs_finalize(void)
|
||||
* for /run (and optionally /run/lock).
|
||||
*/
|
||||
if (fisdir("/run") && !fismnt("/run")) {
|
||||
mount("tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0755,size=10%");
|
||||
fs_mount("tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0755,size=10%");
|
||||
|
||||
/* This prevents user DoS of /run by filling /run/lock at the expense of another tmpfs, max 5MiB */
|
||||
makedir("/run/lock", 1777);
|
||||
mount("tmpfs", "/run/lock", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0777,size=5252880");
|
||||
fs_mount("tmpfs", "/run/lock", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0777,size=5252880");
|
||||
}
|
||||
|
||||
/* Modern systems use tmpfs for /tmp */
|
||||
if (!fismnt("/tmp"))
|
||||
mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");
|
||||
fs_mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");
|
||||
}
|
||||
|
||||
static void fs_mount(void)
|
||||
static void fs_mount_all(void)
|
||||
{
|
||||
if (!rescue)
|
||||
fs_remount_root(fsck_all());
|
||||
@@ -289,7 +333,8 @@ static void fs_mount(void)
|
||||
_d("Calling extra mount hook, after mount -a ...");
|
||||
plugin_run_hooks(HOOK_MOUNT_POST);
|
||||
|
||||
run("swapon -ea");
|
||||
if (whichp("swapon"))
|
||||
run_interactive("swapon -ea", "Enabling system swap");
|
||||
|
||||
_d("Finalize, ensure common file systems are available ...");
|
||||
fs_finalize();
|
||||
@@ -299,9 +344,9 @@ static void fs_mount(void)
|
||||
* We need /proc for rs_remount_root() and conf_parse_cmdline(), /dev
|
||||
* for early multi-console, and /sys for the cgroups support. Any
|
||||
* occurrence of these file systems in /etc/fstab will replace these
|
||||
* mounts later in fs_mount()
|
||||
* mounts later in fs_mount_all()
|
||||
*
|
||||
* Ignore any mount errors with EBUSY, kernel likely alread mounted
|
||||
* Ignore any mount errors with EBUSY, kernel likely already mounted
|
||||
* the filesystem for us automatically, e.g., CONFIG_DEVTMPFS_MOUNT.
|
||||
*/
|
||||
static void fs_init(void)
|
||||
@@ -319,8 +364,6 @@ static void fs_init(void)
|
||||
umask(022);
|
||||
|
||||
for (i = 0; i < NELEMS(fs); i++) {
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* Check if already mounted, we may be running in a
|
||||
* container, or an initramfs ran before us. The
|
||||
@@ -330,9 +373,7 @@ static void fs_init(void)
|
||||
if (fismnt(fs[i].file))
|
||||
continue;
|
||||
|
||||
rc = mount(fs[i].spec, fs[i].file, fs[i].type, 0, NULL);
|
||||
if (rc && errno != EBUSY)
|
||||
_pe("Failed mounting %s on %s", fs[i].spec, fs[i].file);
|
||||
fs_mount(fs[i].spec, fs[i].file, fs[i].type, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +423,7 @@ static void finalize(void *unused)
|
||||
static void crank_worker(void *unused)
|
||||
{
|
||||
/*
|
||||
* Initalize state machine and start all bootstrap tasks
|
||||
* Initialize state machine and start all bootstrap tasks
|
||||
* NOTE: no network available!
|
||||
*/
|
||||
sm_init(&sm);
|
||||
@@ -519,17 +560,17 @@ static int telinit(int argc, char *argv[])
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct wq crank = {
|
||||
struct wq crank_work = {
|
||||
.cb = crank_worker,
|
||||
.delay = 10
|
||||
};
|
||||
struct wq bootstrap = {
|
||||
struct wq bootstrap_work = {
|
||||
.cb = bootstrap_worker,
|
||||
.delay = 100
|
||||
};
|
||||
uev_ctx_t loop;
|
||||
|
||||
/* telinit or stand-alone process monitor */
|
||||
/* user calling telinit or init */
|
||||
if (getpid() != 1)
|
||||
return telinit(argc, argv);
|
||||
|
||||
@@ -540,17 +581,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
/*
|
||||
* Parse /proc/cmdline (debug, rescue, console=, etc.)
|
||||
* Also calls log_init() to set correct log level
|
||||
*/
|
||||
conf_parse_cmdline(argc, argv);
|
||||
|
||||
/*
|
||||
* Figure out system console(s)
|
||||
* Figure out system console(s) and call log_init() to set
|
||||
* correct log level, possibly finit.debug enabled.
|
||||
*/
|
||||
console_init();
|
||||
|
||||
/*
|
||||
* Initalize event context.
|
||||
* Initialize event context.
|
||||
*/
|
||||
uev_init1(&loop, 1);
|
||||
ctx = &loop;
|
||||
@@ -597,6 +638,11 @@ int main(int argc, char *argv[])
|
||||
enable_progress(1); /* Allow progress, if enabled */
|
||||
banner();
|
||||
|
||||
if (osheading)
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "%s, entering runlevel S", osheading);
|
||||
else
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Entering runlevel S");
|
||||
|
||||
/*
|
||||
* Initial setup of signals, ignore all until we're up.
|
||||
*/
|
||||
@@ -608,13 +654,15 @@ int main(int argc, char *argv[])
|
||||
cgroup_init(&loop);
|
||||
|
||||
/* Check and mount filesystems. */
|
||||
fs_mount();
|
||||
fs_mount_all();
|
||||
|
||||
/* Bootstrap conditions, needed for hooks */
|
||||
cond_init();
|
||||
|
||||
/* Emit conditions for early hooks that ran before the
|
||||
* condition system was initialized in case anyone . */
|
||||
/*
|
||||
* Emit conditions for early hooks that ran before the condition
|
||||
* system was initialized in case anyone.
|
||||
*/
|
||||
cond_set_oneshot(plugin_hook_str(HOOK_BANNER));
|
||||
cond_set_oneshot(plugin_hook_str(HOOK_ROOTFS_UP));
|
||||
|
||||
@@ -653,10 +701,15 @@ int main(int argc, char *argv[])
|
||||
api_init(&loop);
|
||||
|
||||
_d("Starting the big state machine ...");
|
||||
schedule_work(&crank);
|
||||
schedule_work(&crank_work);
|
||||
|
||||
_d("Starting bootstrap finalize timer ...");
|
||||
schedule_work(&bootstrap);
|
||||
schedule_work(&bootstrap_work);
|
||||
|
||||
/*
|
||||
* Background service tasks
|
||||
*/
|
||||
service_init();
|
||||
|
||||
/*
|
||||
* Enter main loop to monitor /dev/initctl and services
|
||||
|
||||
+7
-1
@@ -34,7 +34,11 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include <uev/uev.h>
|
||||
|
||||
/* just in case */
|
||||
@@ -91,6 +95,7 @@
|
||||
#define INIT_CMD_SVC_QUERY 130
|
||||
#define INIT_CMD_SVC_FIND 131
|
||||
#define INIT_CMD_SVC_FIND_BYC 132
|
||||
#define INIT_CMD_SIGNAL 133
|
||||
#define INIT_CMD_NACK 254
|
||||
#define INIT_CMD_ACK 255
|
||||
|
||||
@@ -110,6 +115,7 @@ extern int debug;
|
||||
extern int rescue;
|
||||
extern int single;
|
||||
extern int bootstrap;
|
||||
extern int kerndebug;
|
||||
extern char *rcsd;
|
||||
extern char *sdown;
|
||||
extern char *network;
|
||||
|
||||
+16
-2
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h> /* LOGIN_NAME_MAX */
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@@ -33,6 +34,7 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
||||
#include <termios.h>
|
||||
#include <unistd.h> /* sysconf() */
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -42,6 +44,12 @@
|
||||
#define _PATH_LOGIN "/bin/login"
|
||||
#endif
|
||||
|
||||
#ifndef LOGIN_NAME_MIN
|
||||
#define LOGIN_NAME_MIN 64
|
||||
#endif
|
||||
|
||||
static long logname_len = 32; /* useradd(1) limit at 32 chars */
|
||||
|
||||
/*
|
||||
* Read one character from stdin.
|
||||
*/
|
||||
@@ -196,8 +204,8 @@ static int do_login(char *name)
|
||||
|
||||
static int getty(char *tty, speed_t speed, char *term, char *user)
|
||||
{
|
||||
const char cln[] = "\r\e[2K\n";
|
||||
char name[33]; /* useradd(1) limit at 32 chars */
|
||||
const char cln[] = "\r\e[K\n";
|
||||
char name[logname_len + 1]; /* +1 for NUL termination */
|
||||
pid_t sid;
|
||||
|
||||
/*
|
||||
@@ -263,6 +271,12 @@ int main(int argc, char *argv[])
|
||||
if (optind < argc)
|
||||
term = argv[optind++];
|
||||
|
||||
logname_len = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
if (logname_len == -1i)
|
||||
logname_len = LOGIN_NAME_MAX;
|
||||
if (logname_len < LOGIN_NAME_MIN)
|
||||
logname_len = LOGIN_NAME_MIN;
|
||||
|
||||
return getty(tty, atoi(speed), term, NULL);
|
||||
}
|
||||
|
||||
|
||||
+80
-60
@@ -30,12 +30,18 @@
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdarg.h>
|
||||
#include <sysexits.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "private.h"
|
||||
#include "sig.h"
|
||||
#include "util.h"
|
||||
#include "utmp-api.h"
|
||||
|
||||
@@ -53,7 +59,7 @@ static pstyle_t progress_style = PROGRESS_DEFAULT;
|
||||
#define STATUS_CLASS { \
|
||||
CHOOSE(" OK ", " OK ", "\e[1;32m"), /* Green */ \
|
||||
CHOOSE("FAIL", "FAIL", "\e[1;31m"), /* Red */ \
|
||||
CHOOSE("WARN", "WARN", "\e[1;31m"), /* Red */ \
|
||||
CHOOSE("WARN", "WARN", "\e[1;33m"), /* Yellow */ \
|
||||
CHOOSE(" \\/ ", " ⋯ ", "\e[1;33m"), /* Yellow */ \
|
||||
}
|
||||
|
||||
@@ -75,7 +81,7 @@ char *console(void)
|
||||
|
||||
void console_init(void)
|
||||
{
|
||||
ttinit();
|
||||
log_init();
|
||||
}
|
||||
|
||||
ssize_t cprintf(const char *fmt, ...)
|
||||
@@ -223,7 +229,7 @@ void print_banner(const char *heading)
|
||||
return;
|
||||
|
||||
buf[0] = 0;
|
||||
strlcat(buf, "\r\e[2K", sizeof(buf));
|
||||
strlcat(buf, "\r\e[K", sizeof(buf));
|
||||
|
||||
if (progress_style == PROGRESS_CLASSIC) {
|
||||
strlcat(buf, "\e[1m", sizeof(buf));
|
||||
@@ -308,7 +314,7 @@ void printv(const char *fmt, va_list ap)
|
||||
if (progress_style == PROGRESS_CLASSIC)
|
||||
cprintf("\r%s ", pad(buf, sizeof(buf), ".", sizeof(buf)));
|
||||
else
|
||||
cprintf("\r\e[2K%s%s", status(3), buf);
|
||||
cprintf("\r\e[K%s%s", status(3), buf);
|
||||
}
|
||||
|
||||
void print(int rc, const char *fmt, ...)
|
||||
@@ -489,27 +495,52 @@ void networking(int updown)
|
||||
|
||||
/* Debian/Ubuntu/Busybox/RH/Suse */
|
||||
if (!whichp("ifup"))
|
||||
goto done;
|
||||
goto fallback;
|
||||
|
||||
if (fexist("/etc/network/interfaces")) {
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
int rc = EX_OSERR;
|
||||
const char *cmd;
|
||||
FILE *pp;
|
||||
|
||||
setsid();
|
||||
sig_unblock();
|
||||
|
||||
if (updown)
|
||||
run("ifup -a");
|
||||
cmd = "ifup -a 2>&1";
|
||||
else if (whichp("ifquery"))
|
||||
/* Regular ifodwn supports --force but not -f */
|
||||
cmd = "ifdown -a --force 2>&1";
|
||||
else
|
||||
run("ifdown -a");
|
||||
_exit(0);
|
||||
/* Busybox ifdown support -f, but not --force */
|
||||
cmd = "ifdown -a -f 2>&1";
|
||||
|
||||
pp = popen(cmd, "r");
|
||||
if (pp) {
|
||||
char buf[256];
|
||||
|
||||
while (fgets(buf, sizeof(buf), pp))
|
||||
logit(LOG_NOTICE, "network: %s", buf);
|
||||
|
||||
rc = pclose(pp);
|
||||
}
|
||||
|
||||
_exit(rc);
|
||||
}
|
||||
cgroup_service("network", pid, NULL);
|
||||
print(pid > 0 ? 0 : 1, "%s network interfaces ...",
|
||||
updown ? "Bringing up" : "Taking down");
|
||||
|
||||
print(pid > 0 ? 0 : 1, "%s networking", updown ? "Starting" : "Stopping");
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
fallback:
|
||||
/* Fall back to bring up at least loopback */
|
||||
ifconfig("lo", "127.0.0.1", "255.0.0.0", updown);
|
||||
done:
|
||||
|
||||
/* Hooks that rely on loopback, or basic networking being up. */
|
||||
if (updown) {
|
||||
@@ -518,6 +549,44 @@ done:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Very basic, and incomplete, check if we're running in a container.
|
||||
*/
|
||||
int in_container(void)
|
||||
{
|
||||
const char *containers[] = {
|
||||
"lxc",
|
||||
"docker",
|
||||
"kubepod",
|
||||
"unshare"
|
||||
};
|
||||
const char *files[] = {
|
||||
"/run/.containerenv",
|
||||
"/.dockerenv"
|
||||
};
|
||||
static int incont = -1;
|
||||
size_t i;
|
||||
char *c;
|
||||
|
||||
if (incont > 0)
|
||||
return incont;
|
||||
|
||||
c = getenv("container");
|
||||
if (c) {
|
||||
for (i = 0; i < NELEMS(containers); i++) {
|
||||
if (!strcmp(containers[i], c))
|
||||
return incont = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NELEMS(files); i++) {
|
||||
if (!access(files[i], F_OK))
|
||||
return incont = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_GETFSENT
|
||||
static lfile_t *fstab = NULL;
|
||||
|
||||
@@ -560,55 +629,6 @@ void endfsent(void)
|
||||
}
|
||||
#endif /* HAVE_GETFSENT */
|
||||
|
||||
static int hasopt(char *opts, char *opt)
|
||||
{
|
||||
char buf[strlen(opts) + 1];
|
||||
char *ptr;
|
||||
|
||||
memcpy(buf, opts, sizeof(buf));
|
||||
ptr = strtok(buf, ",");
|
||||
while (ptr) {
|
||||
if (!strcmp(ptr, opt))
|
||||
return 1;
|
||||
|
||||
ptr = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ismnt(char *file, char *dir, char *mode)
|
||||
{
|
||||
struct mntent *mnt;
|
||||
int found = 0;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent(file, "r");
|
||||
if (!fp)
|
||||
return 0; /* Dunno, maybe not */
|
||||
|
||||
while ((mnt = getmntent(fp))) {
|
||||
if (!strcmp(mnt->mnt_dir, dir)) {
|
||||
if (mode) {
|
||||
if (hasopt(mnt->mnt_opts, mode))
|
||||
found = 1;
|
||||
} else
|
||||
found = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
endmntent(fp);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/* Requires /proc to be mounted */
|
||||
int fismnt(char *dir)
|
||||
{
|
||||
return ismnt("/proc/mounts", dir, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
|
||||
+10
-8
@@ -32,7 +32,11 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
||||
#include <termios.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include "log.h"
|
||||
|
||||
#define PROGRESS_DEFAULT PROGRESS_MODERN
|
||||
@@ -61,7 +65,7 @@ struct fstab *getfsent (void);
|
||||
|
||||
char *console (void);
|
||||
void console_init (void);
|
||||
ssize_t cprintf (const char *fmt, ...);
|
||||
ssize_t cprintf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
char *strip_line (char *line);
|
||||
|
||||
@@ -75,7 +79,7 @@ void stty (int fd, speed_t speed);
|
||||
|
||||
void print_banner (const char *heading);
|
||||
void printv (const char *fmt, va_list ap);
|
||||
void print (int action, const char *fmt, ...);
|
||||
void print (int action, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
void print_desc (char *action, char *desc);
|
||||
int print_result (int fail);
|
||||
|
||||
@@ -89,10 +93,11 @@ int mksubsys (const char *dir, mode_t mode, char *user, char *group);
|
||||
|
||||
void set_hostname (char **hostname);
|
||||
void networking (int updown);
|
||||
int in_container (void);
|
||||
|
||||
int complete (char *cmd, int pid);
|
||||
int run (char *cmd);
|
||||
int run_interactive (char *cmd, char *fmt, ...);
|
||||
int run (char *cmd, char *log);
|
||||
int run_interactive (char *cmd, char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
int exec_runtask (char *cmd, char *args[]);
|
||||
pid_t run_getty (char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[]);
|
||||
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
||||
@@ -126,9 +131,6 @@ static inline int dprint(int fd, const char *s, size_t len)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ismnt (char *file, char *dir, char *mode);
|
||||
int fismnt (char *dir);
|
||||
|
||||
#endif /* FINIT_HELPERS_H_ */
|
||||
|
||||
/**
|
||||
|
||||
+236
-92
@@ -33,7 +33,11 @@
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "client.h"
|
||||
#include "cond.h"
|
||||
@@ -47,6 +51,8 @@ struct cmd {
|
||||
char *cmd;
|
||||
struct cmd *ctx;
|
||||
int (*cb)(char *arg);
|
||||
int *cond;
|
||||
int (*cb_multiarg)(int argc, char **argv);
|
||||
};
|
||||
|
||||
int icreate = 0;
|
||||
@@ -58,6 +64,9 @@ int verbose = 0;
|
||||
int plain = 0;
|
||||
int quiet = 0;
|
||||
int runlevel = 0;
|
||||
int cgrp = 0;
|
||||
int utmp = 0;
|
||||
|
||||
int iw, pw;
|
||||
|
||||
extern int reboot_main(int argc, char *argv[]);
|
||||
@@ -152,8 +161,11 @@ static int do_log(char *svc)
|
||||
if (!svc || !svc[0])
|
||||
svc = "finit";
|
||||
|
||||
if (!fexist(logfile))
|
||||
if (!fexist(logfile)) {
|
||||
logfile = "/var/log/messages";
|
||||
if (!fexist(logfile))
|
||||
return 0; /* bail out, maybe in container */
|
||||
}
|
||||
|
||||
return systemf("cat %s | grep %s | tail -10", logfile, svc);
|
||||
}
|
||||
@@ -167,11 +179,11 @@ static int do_runlevel(char *arg)
|
||||
|
||||
if (!arg) {
|
||||
int prevlevel = 0;
|
||||
int runlevel;
|
||||
int currlevel;
|
||||
char prev;
|
||||
|
||||
runlevel = runlevel_get(&prevlevel);
|
||||
if (255 == runlevel) {
|
||||
currlevel = runlevel_get(&prevlevel);
|
||||
if (255 == currlevel) {
|
||||
printf("unknown\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -180,7 +192,7 @@ static int do_runlevel(char *arg)
|
||||
if (prev <= '0' || prev > '9')
|
||||
prev = 'N';
|
||||
|
||||
printf("%c %d\n", prev , runlevel);
|
||||
printf("%c %d\n", prev , currlevel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -267,6 +279,61 @@ static int do_restart(char *arg)
|
||||
return do_startstop(INIT_CMD_RESTART_SVC, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* do_signal - Ask finit to send a signal to a service.
|
||||
* @argv: must point to an array of strings, containing a service
|
||||
* and signal name, in that order.
|
||||
* @argc: must be 2.
|
||||
*
|
||||
* A signal can be a complete signal name such as "SIGHUP", or
|
||||
* it can be the shortest unique name, such as "HUP" (no SIG prefix).
|
||||
* It can also be a raw signal number, such as "9" (SIGKILL).
|
||||
*/
|
||||
int do_signal(int argc, char *argv[])
|
||||
{
|
||||
struct init_request rq = {
|
||||
.magic = INIT_MAGIC,
|
||||
.cmd = INIT_CMD_SVC_QUERY
|
||||
};
|
||||
int signo;
|
||||
|
||||
if (argc != 2)
|
||||
errx(1, "invalid number of arguments to signal");
|
||||
|
||||
/* Validate service name */
|
||||
strlcpy(rq.data, argv[0], sizeof(rq.data));
|
||||
if (client_send(&rq, sizeof(rq))) {
|
||||
fprintf(stderr, "No such task or service(s): %s\n\n", argv[0]);
|
||||
goto show_usage;
|
||||
}
|
||||
|
||||
/* Validate signal name (or number) */
|
||||
signo = str2sig(argv[1]);
|
||||
if (signo == -1) {
|
||||
/* Not a signal name, is it an actual signal number? */
|
||||
errno = 0;
|
||||
signo = (int)strtol(argv[1], NULL, 10);
|
||||
|
||||
/* Was it a number? Was it a signo that finit recognizes? */
|
||||
if (errno || !*(sig2str(signo))) {
|
||||
fprintf(stderr, "Not a valid signal (or signo): %s\n", argv[1]);
|
||||
goto show_usage;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reuse runlevel for signal number. */
|
||||
rq.magic = INIT_MAGIC;
|
||||
rq.cmd = INIT_CMD_SIGNAL;
|
||||
rq.runlevel = signo;
|
||||
strlcpy(rq.data, argv[0], sizeof(rq.data));
|
||||
|
||||
return client_send(&rq, sizeof(rq));
|
||||
|
||||
show_usage:
|
||||
fprintf(stderr, "Usage: initctl signal <NAME>[:ID] <S>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
|
||||
{
|
||||
const char *cond, *asserted;
|
||||
@@ -284,7 +351,7 @@ static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, st
|
||||
if (strncmp("pid/", cond, 4) == 0) {
|
||||
svc_t *svc;
|
||||
|
||||
svc= client_svc_find_by_cond(cond);
|
||||
svc = client_svc_find_by_cond(cond);
|
||||
if (!svc) {
|
||||
nm = "unknown";
|
||||
pid = 0;
|
||||
@@ -468,15 +535,12 @@ int do_suspend (char *arg) { return do_cmd(INIT_CMD_SUSPEND); }
|
||||
|
||||
int utmp_show(char *file)
|
||||
{
|
||||
static int once = 0;
|
||||
struct tm *sectm;
|
||||
struct utmp *ut;
|
||||
time_t sec;
|
||||
|
||||
int pid;
|
||||
char id[sizeof(ut->ut_id) + 1], user[sizeof(ut->ut_user) + 1], when[80];
|
||||
|
||||
if (heading) {
|
||||
static int once = 0;
|
||||
|
||||
print_header("%s%s ", once ? "\n" : "", file);
|
||||
once++;
|
||||
}
|
||||
@@ -484,7 +548,12 @@ int utmp_show(char *file)
|
||||
|
||||
setutent();
|
||||
while ((ut = getutent())) {
|
||||
char user[sizeof(ut->ut_user) + 1];
|
||||
char id[sizeof(ut->ut_id) + 1];
|
||||
struct tm *sectm;
|
||||
char when[80];
|
||||
char addr[64];
|
||||
int pid;
|
||||
|
||||
strlcpy(id, ut->ut_id, sizeof(id));
|
||||
strlcpy(user, ut->ut_user, sizeof(user));
|
||||
@@ -509,7 +578,7 @@ int utmp_show(char *file)
|
||||
|
||||
static int do_utmp(char *file)
|
||||
{
|
||||
if (!has_utmp())
|
||||
if (!utmp)
|
||||
return 1;
|
||||
|
||||
if (fexist(file))
|
||||
@@ -538,7 +607,7 @@ static int show_version(char *arg)
|
||||
* Pointer to string on the form [2345], may be up to 12 chars long,
|
||||
* plus escape sequences for highlighting current runlevel.
|
||||
*/
|
||||
char *runlevel_string(int runlevel, int levels)
|
||||
char *runlevel_string(int currlevel, int levels)
|
||||
{
|
||||
int i, pos = 1;
|
||||
static char lvl[21];
|
||||
@@ -548,7 +617,7 @@ char *runlevel_string(int runlevel, int levels)
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (ISSET(levels, i)) {
|
||||
if (!plain && runlevel == i)
|
||||
if (!plain && currlevel == i)
|
||||
pos = strlcat(lvl, "\e[1m", sizeof(lvl));
|
||||
|
||||
if (i == 0)
|
||||
@@ -556,7 +625,7 @@ char *runlevel_string(int runlevel, int levels)
|
||||
else
|
||||
lvl[pos++] = '0' + i;
|
||||
|
||||
if (!plain && runlevel == i)
|
||||
if (!plain && currlevel == i)
|
||||
pos = strlcat(lvl, "\e[0m", sizeof(lvl));
|
||||
} else {
|
||||
lvl[pos++] = '-';
|
||||
@@ -699,28 +768,47 @@ static int show_status(char *arg)
|
||||
{
|
||||
char ident[MAX_IDENT_LEN];
|
||||
char buf[512];
|
||||
int num = 0;
|
||||
svc_t *svc;
|
||||
|
||||
runlevel = runlevel_get(NULL);
|
||||
|
||||
if (arg && arg[0]) {
|
||||
while (arg && arg[0]) {
|
||||
long now = jiffies();
|
||||
char uptm[42] = "N/A";
|
||||
char grbuf[128];
|
||||
char path[256];
|
||||
struct cg *cg;
|
||||
char *group;
|
||||
char *pidfn = NULL;
|
||||
int exact = 0;
|
||||
|
||||
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
||||
svc_ident(svc, ident, sizeof(ident));
|
||||
if (string_compare(ident, arg))
|
||||
num++;
|
||||
if (string_case_compare(ident, arg))
|
||||
exact++;
|
||||
}
|
||||
|
||||
if (num > 1 && !exact)
|
||||
break;
|
||||
|
||||
svc = client_svc_find(arg);
|
||||
if (!svc)
|
||||
return 255;
|
||||
|
||||
if (quiet)
|
||||
return svc->state != SVC_RUNNING_STATE;
|
||||
if (quiet) {
|
||||
if (svc_is_runtask(svc))
|
||||
if (svc->started)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
else
|
||||
return svc->state != SVC_RUNNING_STATE;
|
||||
}
|
||||
|
||||
group = pid_cgroup(svc->pid, grbuf, sizeof(grbuf));
|
||||
snprintf(path, sizeof(path), "%s/%s", FINIT_CGPATH, group);
|
||||
cg = cg_conf(path);
|
||||
pidfn = svc->pidfile;
|
||||
if (pidfn[0] == '!')
|
||||
pidfn++;
|
||||
else if (pidfn[0] == 0)
|
||||
pidfn = "none";
|
||||
|
||||
printf(" Status : %s\n", status(svc, 1));
|
||||
printf(" Identity : %s\n", svc_ident(svc, ident, sizeof(ident)));
|
||||
@@ -729,19 +817,32 @@ static int show_status(char *arg)
|
||||
printf("Environment : %s\n", svc_environ(svc, buf, sizeof(buf)));
|
||||
printf("Condition(s): %s\n", svc_cond(svc, buf, sizeof(buf)));
|
||||
printf(" Command : %s\n", svc_command(svc, buf, sizeof(buf)));
|
||||
printf(" PID file : %s\n", svc->pidfile);
|
||||
printf(" PID file : %s\n", pidfn);
|
||||
printf(" PID : %d\n", svc->pid);
|
||||
printf(" User : %s\n", svc->username);
|
||||
printf(" Group : %s\n", svc->group);
|
||||
printf(" Uptime : %s\n", svc->pid ? uptime(now - svc->start_time, uptm, sizeof(uptm)) : uptm);
|
||||
printf(" Restarts : %d (%d/%d)\n", svc->restart_tot, svc->restart_cnt, svc->restart_max);
|
||||
printf(" Runlevels : %s\n", runlevel_string(runlevel, svc->runlevels));
|
||||
if (svc->pid > 1) {
|
||||
if (cgrp && svc->pid > 1) {
|
||||
char grbuf[128];
|
||||
char path[256];
|
||||
struct cg *cg;
|
||||
char *group;
|
||||
|
||||
group = pid_cgroup(svc->pid, grbuf, sizeof(grbuf));
|
||||
if (!group)
|
||||
goto no_cgroup; /* ... or PID doesn't exist (anymore) */
|
||||
snprintf(path, sizeof(path), "%s/%s", FINIT_CGPATH, group);
|
||||
cg = cg_conf(path);
|
||||
|
||||
printf(" Memory : %s\n", memsz(cgroup_memory(group), uptm, sizeof(uptm)));
|
||||
printf(" CGroup : %s cpu %s [%s, %s] mem [%s, %s]\n",
|
||||
group, cg->cg_cpu.set, cg->cg_cpu.weight, cg->cg_cpu.max,
|
||||
cg->cg_mem.min, cg->cg_mem.max);
|
||||
show_cgroup_tree(group, " ");
|
||||
}
|
||||
no_cgroup:
|
||||
printf("\n");
|
||||
|
||||
return do_log(svc->cmd);
|
||||
@@ -764,9 +865,11 @@ static int show_status(char *arg)
|
||||
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
||||
char *lvls;
|
||||
|
||||
printf("%-*d ", pw, svc->pid);
|
||||
|
||||
svc_ident(svc, ident, sizeof(ident));
|
||||
if (num && !string_compare(ident, arg))
|
||||
continue;
|
||||
|
||||
printf("%-*d ", pw, svc->pid);
|
||||
printf("%-*s %s ", iw, ident, status(svc, 0));
|
||||
|
||||
lvls = runlevel_string(runlevel, svc->runlevels);
|
||||
@@ -784,6 +887,30 @@ static int show_status(char *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int show_ident(char *arg)
|
||||
{
|
||||
svc_t *svc;
|
||||
|
||||
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
||||
char ident[MAX_IDENT_LEN];
|
||||
size_t len;
|
||||
char *pos;
|
||||
|
||||
svc_ident(svc, ident, sizeof(ident));
|
||||
pos = strchr(ident, ':');
|
||||
if (pos)
|
||||
len = pos - ident;
|
||||
else
|
||||
len = strlen(ident);
|
||||
if (arg && arg[0] && strncasecmp(ident, arg, len))
|
||||
continue;
|
||||
|
||||
puts(ident);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int transform(char *nm)
|
||||
{
|
||||
char *names[] = {
|
||||
@@ -833,12 +960,13 @@ static int usage(int rc)
|
||||
" -q, --quiet Silent, only return status of command\n"
|
||||
" -t, --no-heading Skip table headings\n"
|
||||
" -v, --verbose Verbose output\n"
|
||||
" -V, --version Show program version\n"
|
||||
" -h, --help This help text\n"
|
||||
"\n"
|
||||
"Commands:\n"
|
||||
" debug Toggle Finit (daemon) debug\n"
|
||||
" help This help text\n"
|
||||
" version Show Finit version\n"
|
||||
" version Show program version\n"
|
||||
"\n", prognm);
|
||||
|
||||
if (has_rcsd)
|
||||
@@ -862,10 +990,10 @@ static int usage(int rc)
|
||||
" disable <CONF> Disable .conf in %s\n", ena);
|
||||
if (has_rcsd)
|
||||
fprintf(stderr,
|
||||
" reload Reload *.conf in " FINIT_RCSD " (activate changes)\n");
|
||||
" reload Reload *.conf in " FINIT_RCSD " (activate changes)\n");
|
||||
else
|
||||
fprintf(stderr,
|
||||
" reload Reload " FINIT_CONF " (activate changes)\n");
|
||||
" reload Reload " FINIT_CONF " (activate changes)\n");
|
||||
|
||||
fprintf(stderr,
|
||||
// " reload <NAME>[:ID] Reload (SIGHUP) service by name\n"
|
||||
@@ -880,12 +1008,17 @@ static int usage(int rc)
|
||||
" stop <NAME>[:ID] Stop/Pause a running service by name\n"
|
||||
" reload <NAME>[:ID] Reload service by name (SIGHUP or restart)\n"
|
||||
" restart <NAME>[:ID] Restart (stop/start) service by name\n"
|
||||
" signal <NAME>[:ID] <S> Send signal S to service by name, with optional ID\n"
|
||||
" ident [NAME] Show matching identities for NAME, or all\n"
|
||||
" status <NAME>[:ID] Show service status, by name\n"
|
||||
" status Show status of services, default command\n"
|
||||
"\n"
|
||||
" cgroup List cgroup config overview\n"
|
||||
" ps List processes based on cgroups\n"
|
||||
" top Show top-like listing based on cgroups\n"
|
||||
" status Show status of services, default command\n");
|
||||
if (cgrp)
|
||||
fprintf(stderr,
|
||||
"\n"
|
||||
" cgroup List cgroup config overview\n"
|
||||
" ps List processes based on cgroups\n"
|
||||
" top Show top-like listing based on cgroups\n");
|
||||
fprintf(stderr,
|
||||
"\n"
|
||||
" runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot\n"
|
||||
" reboot Reboot system\n"
|
||||
@@ -893,13 +1026,11 @@ static int usage(int rc)
|
||||
" poweroff Halt and power off system\n"
|
||||
" suspend Suspend system\n");
|
||||
|
||||
if (has_utmp())
|
||||
if (utmp)
|
||||
fprintf(stderr,
|
||||
"\n"
|
||||
" utmp show Raw dump of UTMP/WTMP db\n"
|
||||
"\n");
|
||||
else
|
||||
fprintf(stderr, "\n");
|
||||
" utmp show Raw dump of UTMP/WTMP db\n");
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -918,17 +1049,31 @@ static int do_help(char *arg)
|
||||
return usage(0);
|
||||
}
|
||||
|
||||
static int cmd_cond(struct cmd *cmd)
|
||||
{
|
||||
if (!cmd || !cmd->cond)
|
||||
return 1;
|
||||
|
||||
return *cmd->cond;
|
||||
}
|
||||
|
||||
static int cmd_parse(int argc, char *argv[], struct cmd *command)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; argc > 0 && command[i].cmd; i++) {
|
||||
if (!string_match(command[i].cmd, argv[0]))
|
||||
if (!cmd_cond(&command[i]))
|
||||
continue;
|
||||
|
||||
if (!string_compare(command[i].cmd, argv[0]))
|
||||
continue;
|
||||
|
||||
if (command[i].ctx)
|
||||
return cmd_parse(argc - 1, &argv[1], command[i].ctx);
|
||||
|
||||
if (command[i].cb_multiarg)
|
||||
return command[i].cb_multiarg(argc - 1, argv + 1);
|
||||
|
||||
if (command[i].cb) {
|
||||
int rc = 0;
|
||||
|
||||
@@ -961,61 +1106,68 @@ int main(int argc, char *argv[])
|
||||
{ "quiet", 0, NULL, 'q' },
|
||||
{ "no-heading", 0, NULL, 't' },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "version", 0, NULL, 'V' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
struct cmd cond[] = {
|
||||
{ "status", NULL, do_cond_show }, /* default cmd */
|
||||
{ "dump", NULL, do_cond_dump },
|
||||
{ "set", NULL, do_cond_set },
|
||||
{ "clr", NULL, do_cond_clr },
|
||||
{ "clear", NULL, do_cond_clr },
|
||||
{ NULL, NULL, NULL }
|
||||
{ "status", NULL, do_cond_show, NULL, NULL }, /* default cmd */
|
||||
{ "dump", NULL, do_cond_dump, NULL, NULL },
|
||||
{ "set", NULL, do_cond_set, NULL, NULL },
|
||||
{ "clr", NULL, do_cond_clr, NULL, NULL },
|
||||
{ "clear", NULL, do_cond_clr, NULL, NULL },
|
||||
{ NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
struct cmd command[] = {
|
||||
{ "status", NULL, show_status }, /* default cmd */
|
||||
{ "status", NULL, show_status, NULL, NULL }, /* default cmd */
|
||||
{ "ident", NULL, show_ident, NULL, NULL },
|
||||
|
||||
{ "debug", NULL, toggle_debug },
|
||||
{ "devel", NULL, do_devel },
|
||||
{ "help", NULL, do_help },
|
||||
{ "version", NULL, show_version },
|
||||
{ "debug", NULL, toggle_debug, NULL, NULL },
|
||||
{ "devel", NULL, do_devel, NULL, NULL },
|
||||
{ "help", NULL, do_help, NULL, NULL },
|
||||
{ "version", NULL, show_version, NULL, NULL },
|
||||
|
||||
{ "list", NULL, serv_list },
|
||||
{ "ls", NULL, serv_list },
|
||||
{ "enable", NULL, serv_enable },
|
||||
{ "disable", NULL, serv_disable },
|
||||
{ "touch", NULL, serv_touch },
|
||||
{ "show", NULL, serv_show },
|
||||
{ "edit", NULL, serv_edit },
|
||||
{ "create", NULL, serv_creat },
|
||||
{ "delete", NULL, serv_delete },
|
||||
{ "reload", NULL, do_reload },
|
||||
{ "list", NULL, serv_list, NULL, NULL },
|
||||
{ "ls", NULL, serv_list, NULL, NULL },
|
||||
{ "enable", NULL, serv_enable, NULL, NULL },
|
||||
{ "disable", NULL, serv_disable, NULL, NULL },
|
||||
{ "touch", NULL, serv_touch, NULL, NULL },
|
||||
{ "show", NULL, serv_show, NULL, NULL },
|
||||
{ "edit", NULL, serv_edit, NULL, NULL },
|
||||
{ "create", NULL, serv_creat, NULL, NULL },
|
||||
{ "delete", NULL, serv_delete, NULL, NULL },
|
||||
{ "reload", NULL, do_reload, NULL, NULL },
|
||||
|
||||
{ "cond", cond, NULL },
|
||||
{ "cond", cond, NULL, NULL, NULL },
|
||||
|
||||
{ "log", NULL, do_log },
|
||||
{ "start", NULL, do_start },
|
||||
{ "stop", NULL, do_stop },
|
||||
{ "restart", NULL, do_restart },
|
||||
{ "log", NULL, do_log, NULL, NULL },
|
||||
{ "start", NULL, do_start, NULL, NULL },
|
||||
{ "stop", NULL, do_stop, NULL, NULL },
|
||||
{ "restart", NULL, do_restart, NULL, NULL },
|
||||
{ "signal", NULL, NULL, NULL, do_signal },
|
||||
|
||||
{ "cgroup", NULL, show_cgroup },
|
||||
{ "ps", NULL, show_cgps },
|
||||
{ "top", NULL, show_cgtop },
|
||||
{ "cgroup", NULL, show_cgroup, &cgrp, NULL },
|
||||
{ "ps", NULL, show_cgps, &cgrp, NULL },
|
||||
{ "top", NULL, show_cgtop, &cgrp, NULL },
|
||||
|
||||
{ "runlevel", NULL, do_runlevel },
|
||||
{ "reboot", NULL, do_reboot },
|
||||
{ "halt", NULL, do_halt },
|
||||
{ "poweroff", NULL, do_poweroff },
|
||||
{ "suspend", NULL, do_suspend },
|
||||
{ "runlevel", NULL, do_runlevel, NULL, NULL },
|
||||
{ "reboot", NULL, do_reboot, NULL, NULL },
|
||||
{ "halt", NULL, do_halt, NULL, NULL },
|
||||
{ "poweroff", NULL, do_poweroff, NULL, NULL },
|
||||
{ "suspend", NULL, do_suspend, NULL, NULL },
|
||||
|
||||
{ "utmp", NULL, do_utmp },
|
||||
{ NULL, NULL, NULL }
|
||||
{ "utmp", NULL, do_utmp, &utmp, NULL },
|
||||
{ NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
int interactive = 1, c;
|
||||
|
||||
if (transform(progname(argv[0])))
|
||||
return reboot_main(argc, argv);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "1bcdfh?pqtv", long_options, NULL)) != EOF) {
|
||||
/* Enable functionality depending on system capabilities */
|
||||
cgrp = cgroup_avail();
|
||||
utmp = has_utmp();
|
||||
|
||||
while ((c = getopt_long(argc, argv, "1bcdfh?pqtvV", long_options, NULL)) != EOF) {
|
||||
switch(c) {
|
||||
case '1':
|
||||
ionce = 1;
|
||||
@@ -1056,23 +1208,15 @@ int main(int argc, char *argv[])
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
return show_version(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (interactive)
|
||||
ttinit();
|
||||
|
||||
if (!has_utmp()) {
|
||||
/* system w/o utmp support, disable 'utmp' command */
|
||||
for (c = 0; command[c].cmd; c++) {
|
||||
if (!string_compare(command[c].cmd, "utmp"))
|
||||
continue;
|
||||
|
||||
command[c].cb = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return cmd_parse(argc - optind, &argv[optind], command);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ extern int heading; /* initctl -t */
|
||||
extern int verbose; /* initctl -v */
|
||||
extern int plain; /* initctl -p */
|
||||
|
||||
extern void print_header(const char *fmt, ...);
|
||||
extern void print_header(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
#endif /* FINIT_INITCTL_H_ */
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "iwatch.h"
|
||||
@@ -39,6 +40,9 @@ static int initialized = 0;
|
||||
|
||||
int iwatch_init(struct iwatch *iw)
|
||||
{
|
||||
socklen_t len;
|
||||
int sz;
|
||||
|
||||
if (!iw) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
@@ -51,6 +55,18 @@ int iwatch_init(struct iwatch *iw)
|
||||
_pe("Failed creating inotify descriptor");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Double the size of the socket's receive buffer to address
|
||||
* issues with lost events in some cases, e.g. bootstrap and
|
||||
* reconf of systems with lots of services.
|
||||
*/
|
||||
len = sizeof(sz);
|
||||
if (!getsockopt(iw->fd, SOL_SOCKET, SO_RCVBUF, &sz, &len)) {
|
||||
if (setsockopt(iw->fd, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)))
|
||||
_pe("Failed increasing size of inotify socket");
|
||||
}
|
||||
|
||||
initialized = 1;
|
||||
|
||||
return iw->fd;
|
||||
|
||||
+5
-1
@@ -26,7 +26,11 @@
|
||||
#define FINIT_IWATCH_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <lite/queue.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
#include <sys/inotify.h>
|
||||
|
||||
#ifndef IN_MASK_CREATE
|
||||
|
||||
+46
-6
@@ -24,6 +24,7 @@
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
@@ -37,7 +38,11 @@
|
||||
#include <linux/types.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
#include "lite/lite.h"
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "cond.h"
|
||||
#include "pid.h"
|
||||
@@ -48,6 +53,10 @@
|
||||
static int num_ac_online;
|
||||
static int num_ac;
|
||||
|
||||
static int running = 1;
|
||||
static int level;
|
||||
static int logon;
|
||||
|
||||
int debug; /* debug in other modules as well */
|
||||
|
||||
void logit(int prio, const char *fmt, ...)
|
||||
@@ -55,9 +64,9 @@ void logit(int prio, const char *fmt, ...)
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (!debug)
|
||||
if (logon)
|
||||
vsyslog(prio, fmt, ap);
|
||||
else {
|
||||
else if (prio <= level) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -175,6 +184,26 @@ static void init(void)
|
||||
sys_cond("pwr/ac", 1);
|
||||
}
|
||||
|
||||
static void set_logging(int prio)
|
||||
{
|
||||
setlogmask(LOG_UPTO(prio));
|
||||
level = prio;
|
||||
}
|
||||
|
||||
static void toggle_debug(int signo)
|
||||
{
|
||||
(void)signo;
|
||||
|
||||
debug ^= 1;
|
||||
set_logging(debug ? LOG_DEBUG : LOG_NOTICE);
|
||||
}
|
||||
|
||||
static void shut_down(int signo)
|
||||
{
|
||||
(void)signo;
|
||||
running = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Started by Finit as soon as possible when base filesystem is up,
|
||||
* modules have been probed, or insmodded from /etc/finit.conf, so by
|
||||
@@ -194,10 +223,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!debug) {
|
||||
openlog("keventd", LOG_CONS | LOG_PID, LOG_DAEMON);
|
||||
setlogmask(LOG_UPTO(LOG_NOTICE));
|
||||
openlog("keventd", LOG_PID, LOG_DAEMON);
|
||||
set_logging(LOG_NOTICE);
|
||||
logon = 1;
|
||||
}
|
||||
|
||||
signal(SIGUSR1, toggle_debug);
|
||||
signal(SIGTERM, shut_down);
|
||||
init();
|
||||
|
||||
pfd.events = POLLIN;
|
||||
@@ -212,11 +244,18 @@ int main(int argc, char *argv[])
|
||||
panic("bind failed");
|
||||
|
||||
logit(LOG_DEBUG, "Waiting for events ...");
|
||||
while (-1 != poll(&pfd, 1, -1)) {
|
||||
while (running) {
|
||||
char *path = NULL;
|
||||
int ac = 0;
|
||||
int i, len;
|
||||
|
||||
if (-1 == poll(&pfd, 1, -1)) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
len = recv(pfd.fd, buf, sizeof(buf), MSG_DONTWAIT);
|
||||
if (len == -1) {
|
||||
switch (errno) {
|
||||
@@ -231,6 +270,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
buf[len] = 0;
|
||||
logit(LOG_DEBUG, "%s", buf);
|
||||
|
||||
/* skip libusb events, focus on kernel events/changes */
|
||||
if (strncmp(buf, "change@", 7))
|
||||
|
||||
@@ -24,7 +24,11 @@
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -32,14 +36,16 @@
|
||||
#include "util.h"
|
||||
|
||||
static int up = 0;
|
||||
static int loglevel = LOG_NOTICE;
|
||||
static int loglevel = LOG_INFO;
|
||||
|
||||
void log_init(int dbg)
|
||||
void log_init(void)
|
||||
{
|
||||
ttinit();
|
||||
|
||||
if (debug)
|
||||
loglevel = LOG_DEBUG;
|
||||
else
|
||||
loglevel = LOG_NOTICE;
|
||||
loglevel = LOG_INFO;
|
||||
}
|
||||
|
||||
/* If we enabled terse mode at boot, restore to previous setting at shutdown */
|
||||
@@ -55,18 +61,29 @@ void log_exit(void)
|
||||
enable_progress(1);
|
||||
}
|
||||
|
||||
static void log_open(void)
|
||||
static int log_open(void)
|
||||
{
|
||||
int opts = LOG_PID;
|
||||
int opts;
|
||||
|
||||
closelog();
|
||||
if (up)
|
||||
return 1;
|
||||
if (access("/dev/log", W_OK))
|
||||
return 0;
|
||||
|
||||
opts = LOG_CONS | LOG_PID;
|
||||
if (debug)
|
||||
opts |= LOG_PERROR; /* LOG_CONS | */
|
||||
opts |= LOG_PERROR;
|
||||
|
||||
openlog("finit", opts, LOG_DAEMON);
|
||||
setlogmask(LOG_UPTO(loglevel));
|
||||
|
||||
up = 1;
|
||||
return up = 1;
|
||||
}
|
||||
|
||||
static void log_close(void)
|
||||
{
|
||||
closelog();
|
||||
up = 0;
|
||||
}
|
||||
|
||||
/* Toggle debug mode */
|
||||
@@ -74,12 +91,8 @@ void log_debug(void)
|
||||
{
|
||||
debug = !debug;
|
||||
|
||||
if (debug) {
|
||||
loglevel = LOG_DEBUG;
|
||||
} else {
|
||||
loglevel = LOG_NOTICE;
|
||||
ttinit();
|
||||
}
|
||||
log_close();
|
||||
log_init();
|
||||
log_open();
|
||||
|
||||
logit(LOG_NOTICE, "Debug mode %s", debug ? "enabled" : "disabled");
|
||||
@@ -91,15 +104,12 @@ void log_debug(void)
|
||||
*/
|
||||
void logit(int prio, const char *fmt, ...)
|
||||
{
|
||||
FILE *fp;
|
||||
va_list ap;
|
||||
FILE *fp;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
if (up || fexist("/dev/log")) {
|
||||
if (!up)
|
||||
log_open();
|
||||
|
||||
if (up || log_open()) {
|
||||
vsyslog(prio, fmt, ap);
|
||||
goto done;
|
||||
}
|
||||
@@ -107,9 +117,9 @@ void logit(int prio, const char *fmt, ...)
|
||||
if (LOG_PRI(prio) > loglevel)
|
||||
goto done;
|
||||
|
||||
fp = fopen("/dev/kmsg", "w");
|
||||
if (!fp) {
|
||||
if (in_container() || !(fp = fopen("/dev/kmsg", "w"))) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fputs("\n", stderr);
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -121,6 +131,7 @@ void logit(int prio, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
@@ -40,17 +40,17 @@
|
||||
* The default log level is LOG_NOTICE. To toggle LOG_DEBUG messages,
|
||||
* use `initctl debug` or add `debug` to the kernel cmdline.
|
||||
*/
|
||||
#define _d(fmt, args...) logit(LOG_DEBUG, "%s():" fmt "\n", __func__, ##args)
|
||||
#define _w(fmt, args...) logit(LOG_WARNING, "%s():" fmt "\n", __func__, ##args)
|
||||
#define _e(fmt, args...) logit(LOG_ERR, "%s():" fmt "\n", __func__, ##args)
|
||||
#define _pe(fmt, args...) logit(LOG_ERR, "%s():" fmt ": %s\n", __func__, ##args, strerror(errno))
|
||||
#define _d(fmt, args...) logit(LOG_DEBUG, "%s():" fmt, __func__, ##args)
|
||||
#define _w(fmt, args...) logit(LOG_WARNING, "%s():" fmt, __func__, ##args)
|
||||
#define _e(fmt, args...) logit(LOG_ERR, "%s():" fmt, __func__, ##args)
|
||||
#define _pe(fmt, args...) logit(LOG_ERR, "%s():" fmt ": %s", __func__, ##args, strerror(errno))
|
||||
|
||||
void log_init (int dbg);
|
||||
void log_init (void);
|
||||
void log_exit (void);
|
||||
|
||||
void log_debug (void);
|
||||
|
||||
void logit (int prio, const char *fmt, ...);
|
||||
void flog (char *file, const char *fmt, ...);
|
||||
void logit (int prio, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
void flog (char *file, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
#endif /* FINIT_LOG_H_ */
|
||||
|
||||
+5
-1
@@ -30,7 +30,11 @@
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
static const char version_info[] = PACKAGE_NAME " v" PACKAGE_VERSION;
|
||||
extern int logrotate(char *file, int num, off_t sz);
|
||||
|
||||
+5
-1
@@ -20,12 +20,16 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <lite/lite.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
static int recreate(char *path, mode_t mode, uid_t uid, gid_t gid)
|
||||
{
|
||||
|
||||
+41
-18
@@ -21,14 +21,17 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
/*
|
||||
* SysV init on Debian/Ubuntu skips these protected mount points
|
||||
*
|
||||
* It also skips anything below /proc, /sys and /run for good meausre so
|
||||
* It also skips anything below /proc, /sys and /run for good measure so
|
||||
* we do the same here. What we want is a list of non-protected tmpfs
|
||||
* and regular filesystems that can be safely unmounted before we do
|
||||
* swapoff, and remount / as read-only, respectively.
|
||||
@@ -36,7 +39,7 @@
|
||||
static int is_protected(char *dir)
|
||||
{
|
||||
size_t i;
|
||||
char *protected[] = {
|
||||
char *protected_mnts[] = {
|
||||
"/sys", "/proc",
|
||||
"/.dev", "/dev", "/dev/pts", "/dev/shm", "dev/.static/dev", "/dev/vcs",
|
||||
"/run", "/var/run",
|
||||
@@ -46,8 +49,8 @@ static int is_protected(char *dir)
|
||||
"/proc/", "/sys/", "/run/", NULL
|
||||
};
|
||||
|
||||
for (i = 0; protected[i]; i++) {
|
||||
if (!strcmp(dir, protected[i]))
|
||||
for (i = 0; protected_mnts[i]; i++) {
|
||||
if (!strcmp(dir, protected_mnts[i]))
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -59,46 +62,66 @@ static int is_protected(char *dir)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct mntent *iterator(char *fstab)
|
||||
static void iterator_end(FILE **fp)
|
||||
{
|
||||
endmntent(*fp);
|
||||
*fp = NULL;
|
||||
}
|
||||
|
||||
static struct mntent *iterator(char *fstab, FILE **fp)
|
||||
{
|
||||
static FILE *fp = NULL;
|
||||
static struct mntent *mnt;
|
||||
|
||||
if (!fp && fstab) {
|
||||
fp = setmntent(fstab, "r");
|
||||
if (!fp)
|
||||
if (!*fp && fstab) {
|
||||
*fp = setmntent(fstab, "r");
|
||||
if (!*fp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((mnt = getmntent(fp))) {
|
||||
while ((mnt = getmntent(*fp))) {
|
||||
if (is_protected(mnt->mnt_dir))
|
||||
continue;
|
||||
|
||||
return mnt;
|
||||
}
|
||||
|
||||
endmntent(fp);
|
||||
fp = NULL;
|
||||
|
||||
iterator_end(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int unmount(const char *target)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = umount(target);
|
||||
if (rc && errno != EBUSY) {
|
||||
print(2, "Failed unmounting %s, error %d: %s", target, errno, strerror(errno));
|
||||
return rc;
|
||||
}
|
||||
print(0, "Unmounting %s", target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unmount_tmpfs(void)
|
||||
{
|
||||
struct mntent *mnt;
|
||||
FILE *fp = NULL;
|
||||
|
||||
while ((mnt = iterator("/proc/mounts"))) {
|
||||
if (!strcmp("tmpfs", mnt->mnt_fsname))
|
||||
umount(mnt->mnt_dir);
|
||||
while ((mnt = iterator("/proc/mounts", &fp))) {
|
||||
if (!strcmp("tmpfs", mnt->mnt_fsname) && !unmount(mnt->mnt_dir))
|
||||
iterator_end(&fp); /* Restart iteration */
|
||||
}
|
||||
}
|
||||
|
||||
void unmount_regular(void)
|
||||
{
|
||||
struct mntent *mnt;
|
||||
FILE *fp = NULL;
|
||||
|
||||
while ((mnt = iterator("/proc/mounts"))) {
|
||||
umount(mnt->mnt_dir);
|
||||
while ((mnt = iterator("/proc/mounts", &fp))) {
|
||||
if (!unmount(mnt->mnt_dir))
|
||||
iterator_end(&fp); /* Restart iteration */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "pid.h"
|
||||
#include "svc.h"
|
||||
@@ -65,10 +69,11 @@ int pid_alive(pid_t pid)
|
||||
*/
|
||||
char *pid_get_name(pid_t pid, char *name, size_t len)
|
||||
{
|
||||
static char line[64];
|
||||
char *pname = NULL;
|
||||
char path[32];
|
||||
int ret = 1;
|
||||
FILE *fp;
|
||||
char *pname, path[32];
|
||||
static char line[64];
|
||||
|
||||
snprintf(path, sizeof(path), "/proc/%d/status", pid);
|
||||
fp = fopen(path, "r");
|
||||
@@ -109,8 +114,8 @@ char *pid_file(svc_t *svc)
|
||||
pid_t pid_file_read(const char *fn)
|
||||
{
|
||||
pid_t pid = 0;
|
||||
FILE *fp;
|
||||
char buf[42];
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(fn, "r");
|
||||
if (!fp)
|
||||
@@ -153,6 +158,11 @@ int pid_file_set(svc_t *svc, char *file, int not)
|
||||
file++;
|
||||
}
|
||||
|
||||
if (svc_is_forking(svc) && !not) {
|
||||
logit(LOG_WARNING, "Service %s is forking, adjusting to pid:!%s", svc->name, file);
|
||||
not = 1;
|
||||
}
|
||||
|
||||
pid_runpath(file, &svc->pidfile[not], sizeof(svc->pidfile) - not);
|
||||
if (not)
|
||||
svc->pidfile[0] = '!';
|
||||
@@ -166,7 +176,7 @@ int pid_file_set(svc_t *svc, char *file, int not)
|
||||
* The logic is explained below. Please note that using the first form
|
||||
* of the syntax not only creates and removes the PID file, but it also
|
||||
* calls touch to update the mtime on service_restart(), only applicable
|
||||
* to processes that accept SIGHUP. This to ensure dependant services
|
||||
* to processes that accept SIGHUP. This to ensure dependent services
|
||||
* are sent SIGCONT properly on reload, otherwise their condition would
|
||||
* never be asserted again after `initctl reload`.
|
||||
*
|
||||
@@ -195,8 +205,8 @@ int pid_file_parse(svc_t *svc, char *arg)
|
||||
|
||||
/* 'pid:' implies argument following*/
|
||||
if (!strncmp(arg, "pid:", 4)) {
|
||||
int len, not = 0;
|
||||
char path[MAX_ARG_LEN];
|
||||
int len, not = 0;
|
||||
|
||||
arg += 4;
|
||||
if ((arg[0] == '!' && arg[1] == '/') || arg[0] == '/')
|
||||
|
||||
+8
-3
@@ -26,8 +26,13 @@
|
||||
#include <dirent.h> /* readdir() et al */
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <lite/lite.h>
|
||||
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "cond.h"
|
||||
@@ -274,7 +279,7 @@ static int init_plugins(uev_ctx_t *ctx)
|
||||
* Loads a plugin from @path/@name[.so]. Note, if ".so" is missing from
|
||||
* the plugin @name it is added before attempting to load.
|
||||
*
|
||||
* It is up to the plugin itself ot register itself as a "ctor" with the
|
||||
* It is up to the plugin itself or register itself as a "ctor" with the
|
||||
* %PLUGIN_INIT macro so that plugin_register() is called automatically.
|
||||
*
|
||||
* Returns:
|
||||
|
||||
+5
-1
@@ -25,7 +25,11 @@
|
||||
#define FINIT_PLUGIN_H_
|
||||
|
||||
#include <uev/uev.h>
|
||||
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
|
||||
#include "svc.h"
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include "svc.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#define SERVICE_INTERVAL_DEFAULT 300000 /* 5 mins */
|
||||
extern int service_interval;
|
||||
|
||||
int api_init (uev_ctx_t *ctx);
|
||||
int api_exit (void);
|
||||
|
||||
|
||||
+4
-10
@@ -98,11 +98,6 @@ static void do_kill(int signo, char *msg)
|
||||
do_sleep(5);
|
||||
}
|
||||
|
||||
static void sig(int signo)
|
||||
{
|
||||
(void)signo; /* NOP */
|
||||
}
|
||||
|
||||
static int usage(int rc)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [OPTIONS]\n\n"
|
||||
@@ -164,10 +159,9 @@ int reboot_main(int argc, char *argv[])
|
||||
/* Check for any overrides */
|
||||
transform(NULL);
|
||||
|
||||
/* Catch and ignore SIGTERM on halt/poweroff */
|
||||
signal(SIGTERM, sig);
|
||||
|
||||
if (force) {
|
||||
sync();
|
||||
|
||||
switch (cmd) {
|
||||
case CMD_REBOOT:
|
||||
c = reboot(RB_AUTOBOOT);
|
||||
@@ -182,9 +176,9 @@ int reboot_main(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case CMD_SUSPEND:
|
||||
c = reboot(RB_SW_SUSPEND);
|
||||
c = suspend();
|
||||
if (c && errno == EINVAL)
|
||||
errx(1, "Kernel does not support suspend.");
|
||||
errx(1, "Kernel does not support suspend to RAM.");
|
||||
break;
|
||||
|
||||
case CMD_UNKNOWN:
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
# runlevel. Finit does not restart them when they exit.
|
||||
#
|
||||
# - run : wait for completion before continuing with next stanza
|
||||
# - task : like run but started in background, parallell with other stanzas
|
||||
# - task : like run but started in background, parallel with other stanzas
|
||||
# - service : supervised daemon, run in foreground, restarted if it crashes
|
||||
#
|
||||
# The env: is an optional path to a file with environment variables to
|
||||
|
||||
+36
-2
@@ -28,11 +28,30 @@
|
||||
#include <glob.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "client.h"
|
||||
#include "initctl.h"
|
||||
|
||||
|
||||
static int is_builtin(char *arg)
|
||||
{
|
||||
svc_t *svc;
|
||||
|
||||
svc = client_svc_find(arg);
|
||||
if (!svc)
|
||||
return 0;
|
||||
|
||||
if (svc->file[0])
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int calc_width(char *arr[], size_t len)
|
||||
{
|
||||
int width = 0;
|
||||
@@ -288,6 +307,8 @@ int serv_touch(char *arg)
|
||||
if (!fexist(fn)) {
|
||||
if (!strstr(arg, "finit.conf"))
|
||||
errx(1, "%s not available.", arg);
|
||||
if (is_builtin(arg))
|
||||
errx(1, "%s is a built-in service.", arg);
|
||||
|
||||
strlcpy(path, FINIT_CONF, sizeof(path));
|
||||
fn = path;
|
||||
@@ -307,6 +328,9 @@ int serv_show(char *arg)
|
||||
|
||||
fn = conf(path, sizeof(path), arg, 0);
|
||||
if (!fexist(fn)) {
|
||||
if (is_builtin(arg))
|
||||
errx(1, "%s is a built-in service.", arg);
|
||||
|
||||
warnx("Cannot find %s", arg);
|
||||
return 1;
|
||||
}
|
||||
@@ -341,6 +365,9 @@ static int do_edit(char *arg, int creat)
|
||||
|
||||
fn = conf(path, sizeof(path), arg, creat);
|
||||
if (!fexist(fn)) {
|
||||
if (is_builtin(arg))
|
||||
errx(1, "%s is a built-in service.", arg);
|
||||
|
||||
if (!creat) {
|
||||
warnx("Cannot find %s, use -c flag, create command, or select one of:", arg);
|
||||
return serv_list(NULL);
|
||||
@@ -367,6 +394,7 @@ int serv_edit(char *arg)
|
||||
if (!arg || !arg[0]) {
|
||||
if (!yorn("Do you want to edit %s (y/N)? ", FINIT_CONF))
|
||||
return 0;
|
||||
arg = "";
|
||||
}
|
||||
|
||||
return do_edit(arg, icreate);
|
||||
@@ -381,6 +409,9 @@ int serv_creat(char *arg)
|
||||
if (!arg || !arg[0])
|
||||
errx(1, "missing argument to create");
|
||||
|
||||
if (is_builtin(arg))
|
||||
errx(1, "%s is a built-in service.", arg);
|
||||
|
||||
/* Input from a pipe or a proper TTY? */
|
||||
if (isatty(STDIN_FILENO))
|
||||
return do_edit(arg, 1);
|
||||
@@ -416,8 +447,11 @@ int serv_delete(char *arg)
|
||||
}
|
||||
|
||||
fn = conf(buf, sizeof(buf), arg, 0);
|
||||
if (!fn)
|
||||
if (!fn) {
|
||||
if (is_builtin(arg))
|
||||
errx(1, "%s is a built-in service.", arg);
|
||||
errx(1, FINIT_RCSD " missing on system.");
|
||||
}
|
||||
|
||||
if (!fexist(fn))
|
||||
warnx("cannot find %s", fn);
|
||||
|
||||
+227
-43
@@ -26,11 +26,16 @@
|
||||
|
||||
#include <ctype.h> /* isblank() */
|
||||
#include <string.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <net/if.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include <wordexp.h>
|
||||
|
||||
#include "cgroup.h"
|
||||
@@ -51,6 +56,7 @@
|
||||
static struct wq work = {
|
||||
.cb = service_worker,
|
||||
};
|
||||
int service_interval = SERVICE_INTERVAL_DEFAULT;
|
||||
|
||||
static void svc_set_state(svc_t *svc, svc_state_t new);
|
||||
|
||||
@@ -491,6 +497,12 @@ static int service_start(svc_t *svc)
|
||||
/* Declare we're waiting for svc to create its pidfile */
|
||||
svc_starting(svc);
|
||||
|
||||
/* Increment total restarts, unless first time or non-service */
|
||||
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
|
||||
if (svc->restart_cnt || svc->restart_tot)
|
||||
svc->restart_tot++;
|
||||
}
|
||||
|
||||
/* Block SIGCHLD while forking. */
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
@@ -546,7 +558,7 @@ static int service_start(svc_t *svc)
|
||||
|
||||
for (i = 0; i < we.we_wordc; i++) {
|
||||
if (strlen(we.we_wordv[i]) >= sizeof(svc->args[i])) {
|
||||
logit(LOG_ERR, "%s: expanded arg. '%s' too long", we.we_wordv[i]);
|
||||
logit(LOG_ERR, "%s: expanded arg. '%s' too long", svc->cmd, we.we_wordv[i]);
|
||||
rc = WRDE_NOSPACE;
|
||||
goto nomem;
|
||||
}
|
||||
@@ -559,6 +571,7 @@ static int service_start(svc_t *svc)
|
||||
} else {
|
||||
i = 0;
|
||||
args[i++] = svc->cmd;
|
||||
args[i++] = svc->cmd;
|
||||
args[i++] = "start";
|
||||
}
|
||||
args[i] = NULL;
|
||||
@@ -616,10 +629,13 @@ static int service_start(svc_t *svc)
|
||||
switch (svc->type) {
|
||||
case SVC_TYPE_RUN:
|
||||
svc->status = complete(svc->cmd, pid);
|
||||
if (WIFEXITED(svc->status) && !WEXITSTATUS(svc->status))
|
||||
if (WIFEXITED(svc->status) && !WEXITSTATUS(svc->status)) {
|
||||
svc->started = 1;
|
||||
result = 0;
|
||||
else
|
||||
} else {
|
||||
svc->started = 0;
|
||||
result = 1;
|
||||
}
|
||||
svc->start_time = svc->pid = 0;
|
||||
svc->once++;
|
||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
||||
@@ -689,7 +705,7 @@ static void service_cleanup(svc_t *svc)
|
||||
utmp_set_dead(svc->pid); /* Set DEAD_PROCESS UTMP entry */
|
||||
|
||||
svc->oldpid = svc->pid;
|
||||
svc->start_time = svc->pid = 0;
|
||||
svc->starting = svc->start_time = svc->pid = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -731,7 +747,13 @@ static int service_stop(svc_t *svc)
|
||||
*/
|
||||
svc_started(svc);
|
||||
|
||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
||||
/*
|
||||
* Verify there's still something there before we send the reaper.
|
||||
*/
|
||||
if (svc->pid > 1 && !pid_alive(svc->pid)) {
|
||||
svc->pid = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!svc->desc[0])
|
||||
do_progress = 0;
|
||||
@@ -743,12 +765,17 @@ static int service_stop(svc_t *svc)
|
||||
if (svc->pid > 1) {
|
||||
/* Kill all children in the same proess group, e.g. logit */
|
||||
rc = kill(-svc->pid, svc->sighalt);
|
||||
_d("kill(-%d, %d) => rc %d", svc->pid, svc->sighalt, rc);
|
||||
_d("kill(-%d, %d) => rc %d, errno %d", svc->pid, svc->sighalt, rc, errno);
|
||||
/* PID lost or forking process never really started */
|
||||
if (rc == -1 && ESRCH == errno)
|
||||
service_cleanup(svc);
|
||||
} else
|
||||
if (rc == -1 && (errno == ESRCH || errno == ENOENT)) {
|
||||
service_cleanup(svc);
|
||||
svc_set_state(svc, SVC_HALTED_STATE);
|
||||
} else
|
||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
||||
} else {
|
||||
service_cleanup(svc);
|
||||
svc_set_state(svc, SVC_HALTED_STATE);
|
||||
}
|
||||
} else {
|
||||
char *args[] = { svc->cmd, "stop", NULL };
|
||||
pid_t pid;
|
||||
@@ -766,7 +793,7 @@ static int service_stop(svc_t *svc)
|
||||
rc = 1;
|
||||
break;
|
||||
default:
|
||||
rc = WEXITSTATUS(complete(svc->cmd, pid));
|
||||
svc_set_state(svc, SVC_STOPPING_STATE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -817,7 +844,7 @@ static int service_restart(svc_t *svc)
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Restarting %s[%d], sending SIGHUP ...",
|
||||
svc_ident(svc, NULL, 0), svc->pid);
|
||||
rc = kill(svc->pid, SIGHUP);
|
||||
if (rc == -1 && errno == ESRCH) {
|
||||
if (rc == -1 && (errno == ESRCH || errno == ENOENT)) {
|
||||
/* nobody home, reset internal state machine */
|
||||
lost = svc->pid;
|
||||
} else {
|
||||
@@ -843,7 +870,7 @@ static int service_restart(svc_t *svc)
|
||||
/**
|
||||
* service_reload_dynamic - Called on SIGHUP, 'init q' or 'initctl reload'
|
||||
*
|
||||
* This function is called when Finit has recieved SIGHUP to reload
|
||||
* This function is called when Finit has received SIGHUP to reload
|
||||
* .conf files in /etc/finit.d. It is responsible for starting,
|
||||
* stopping and reloading (forwarding SIGHUP) to processes affected.
|
||||
*/
|
||||
@@ -868,7 +895,7 @@ void service_runlevel(int newlevel)
|
||||
sm_set_runlevel(&sm, newlevel);
|
||||
sm_step(&sm);
|
||||
|
||||
if (!rescue && runlevel <= 1)
|
||||
if (!rescue && (runlevel <= 1 || runlevel == 6))
|
||||
networking(0);
|
||||
}
|
||||
|
||||
@@ -904,7 +931,7 @@ static void parse_env(svc_t *svc, char *env)
|
||||
return;
|
||||
|
||||
if (strlen(env) >= sizeof(svc->env)) {
|
||||
_e("%s: env file is too long (>%d chars)", svc->cmd, sizeof(svc->env));
|
||||
_e("%s: env file is too long (>%zu chars)", svc->cmd, sizeof(svc->env));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -928,7 +955,7 @@ static void parse_cgroup(svc_t *svc, char *cgroup)
|
||||
}
|
||||
|
||||
if (strlen(ptr) >= sizeof(svc->cgroup)) {
|
||||
_e("%s: cgroup settings too long (>%d chars)", svc->cmd, sizeof(svc->cgroup));
|
||||
_e("%s: cgroup settings too long (>%zu chars)", svc->cmd, sizeof(svc->cgroup));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -964,7 +991,7 @@ static void parse_killdelay(svc_t *svc, char *delay)
|
||||
static void parse_script(char *type, char *script, char *buf, size_t len)
|
||||
{
|
||||
if (access(script, X_OK))
|
||||
logit(LOG_WARNING, "%s: %s:%s is missing or not executable, skipping.", type, script);
|
||||
logit(LOG_WARNING, "%s:%s is missing or not executable, skipping.", type, script);
|
||||
else
|
||||
strlcpy(buf, script, len);
|
||||
}
|
||||
@@ -1079,7 +1106,7 @@ static void parse_cmdline_args(svc_t *svc, char *cmd)
|
||||
* This function is used to register commands to be run on different
|
||||
* system runlevels with optional username. The @type argument details
|
||||
* if it's service to bo monitored/respawned (daemon), a one-shot task
|
||||
* or a command that must run in sequence and not in parallell, like
|
||||
* or a command that must run in sequence and not in parallel, like
|
||||
* service and task commands do.
|
||||
*
|
||||
* The @line can optionally start with a username, denoted by an @
|
||||
@@ -1119,7 +1146,7 @@ static void parse_cmdline_args(svc_t *svc, char *cmd)
|
||||
*
|
||||
* Without the :ID syntax, Finit replaces the first service line with
|
||||
* the contents of the second. The :ID can be any string value and
|
||||
* defaults to "" (emtpy string).
|
||||
* defaults to "" (empty string).
|
||||
*
|
||||
* Returns:
|
||||
* POSIX OK(0) on success, or non-zero errno exit status on failure.
|
||||
@@ -1135,7 +1162,10 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
char *dev = NULL;
|
||||
int respawn = 0;
|
||||
int levels = 0;
|
||||
int manual = 0;
|
||||
int forking = 0, manual = 0;
|
||||
int restart_max = SVC_RESPAWN_MAX;
|
||||
int restart_tmo = 0;
|
||||
unsigned oncrash_action = SVC_ONCRASH_IGNORE;
|
||||
char *line;
|
||||
svc_t *svc;
|
||||
|
||||
@@ -1191,8 +1221,22 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
pid = cmd;
|
||||
else if (!strncasecmp(cmd, "name:", 5))
|
||||
name = cmd;
|
||||
else if (!strncasecmp(cmd, "type:forking", 10))
|
||||
forking = 1;
|
||||
else if (!strncasecmp(cmd, "manual:yes", 10))
|
||||
manual = 1;
|
||||
else if (!strncasecmp(cmd, "restart:", 8))
|
||||
restart_max = atoi(&cmd[8]);
|
||||
else if (!strncasecmp(cmd, "restarttmo:", 11)) /* compat alias */
|
||||
restart_tmo = atoi(&cmd[11]) * 1000;
|
||||
else if (!strncasecmp(cmd, "restart_sec:", 12))
|
||||
restart_tmo = atoi(&cmd[12]) * 1000;
|
||||
else if (!strncasecmp(cmd, "norestart", 9))
|
||||
restart_max = 0;
|
||||
else if (!strncasecmp(cmd, "oncrash:", 8)) {
|
||||
if (!strncasecmp(&cmd[8], "reboot", 6))
|
||||
oncrash_action = SVC_ONCRASH_REBOOT;
|
||||
}
|
||||
else if (!strncasecmp(cmd, "respawn", 7))
|
||||
respawn = 1;
|
||||
else if (!strncasecmp(cmd, "halt:", 5))
|
||||
@@ -1277,20 +1321,19 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
|
||||
if (type == SVC_TYPE_SERVICE && manual)
|
||||
svc_stop(svc);
|
||||
|
||||
svc->restart_max = restart_max;
|
||||
svc->restart_tmo = restart_tmo;
|
||||
svc->oncrash_action = oncrash_action;
|
||||
} else {
|
||||
/* update type, may have changed from service -> task */
|
||||
svc->type = type;
|
||||
|
||||
/* e.g., if missing cmd or env before */
|
||||
svc_unblock(svc);
|
||||
if (!manual)
|
||||
svc_unblock(svc);
|
||||
}
|
||||
|
||||
/* Always clear svc PID file, for now. See TODO */
|
||||
svc->pidfile[0] = 0;
|
||||
/* Decode any optional pid:/optional/path/to/file.pid */
|
||||
if (pid && svc_is_daemon(svc) && pid_file_parse(svc, pid))
|
||||
_e("Invalid 'pid' argument to service: %s", pid);
|
||||
|
||||
if (username) {
|
||||
char *ptr = strchr(username, ':');
|
||||
|
||||
@@ -1327,7 +1370,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
/* TTYs cannot be redirected */
|
||||
log = NULL;
|
||||
|
||||
/* Create name:id tuple for identiy, e.g., tty:S0 */
|
||||
/* Create name:id tuple for identity, e.g., tty:S0 */
|
||||
ptr = strrchr(svc->dev, '/');
|
||||
if (ptr)
|
||||
ptr++;
|
||||
@@ -1368,8 +1411,26 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
parse_env(svc, env);
|
||||
if (file)
|
||||
strlcpy(svc->file, file, sizeof(svc->file));
|
||||
if (respawn)
|
||||
svc->respawn = 1;
|
||||
svc->respawn = respawn;
|
||||
svc->forking = forking;
|
||||
|
||||
/* Decode any (optional) pid:/optional/path/to/file.pid */
|
||||
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
|
||||
char tmp[sizeof(svc->name) + 6]; /* pid:! + svc->name */
|
||||
|
||||
/* no pid: set, figure out a default to track this svc */
|
||||
if (!pid && forking) {
|
||||
snprintf(tmp, sizeof(tmp), "pid:!%s", svc->name);
|
||||
pid = tmp;
|
||||
logit(LOG_INFO, "%s: forking but no pid:!file set, guessing -> %s", svc->name, tmp);
|
||||
}
|
||||
|
||||
if (pid && pid_file_parse(svc, pid))
|
||||
logit(LOG_WARNING, "%s: service has invalid 'pid:' config: %s", svc->name, pid);
|
||||
|
||||
if (svc->pidfile[0] == '!')
|
||||
svc->forking = 1;
|
||||
}
|
||||
|
||||
/* Set configured limits */
|
||||
memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit));
|
||||
@@ -1448,8 +1509,10 @@ void service_monitor(pid_t lost, int status)
|
||||
}
|
||||
|
||||
/* Forking sysv/services declare themselves with pid:!/path/to/pid.file */
|
||||
if (svc_is_starting(svc) && svc_is_forking(svc))
|
||||
if (svc_is_starting(svc) && svc_is_forking(svc)) {
|
||||
svc->pid = 0; /* Expect no more activity from this one */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Terminate any children in the same proess group, e.g. logit */
|
||||
kill(-svc->pid, SIGKILL);
|
||||
@@ -1518,6 +1581,33 @@ static void service_kill_script(svc_t *svc)
|
||||
kill(-svc->pid, SIGKILL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Shared env vars for both pre: and post: scripts
|
||||
*/
|
||||
static void set_pre_post_envs(svc_t *svc, const char *type)
|
||||
{
|
||||
char buf[25 + 256] = "/etc/default:/etc/conf.d";
|
||||
const char *fn = svc_getenv(svc);
|
||||
const char *exist = "0";
|
||||
|
||||
setenv("SERVICE_TYPE", svc_typestr(svc), 1);
|
||||
setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
|
||||
setenv("SERVICE_SCRIPT_TYPE", type, 1);
|
||||
|
||||
if (fn) {
|
||||
setenv("SERVICE_ENV_FILE", fn, 1);
|
||||
if (!access(fn, R_OK))
|
||||
exist = "1";
|
||||
}
|
||||
setenv("SERVICE_ENV_FILE_EXIST", exist, 1);
|
||||
|
||||
#ifdef FINIT_SYSCONFIG
|
||||
strlcat(buf, ":", sizeof(buf));
|
||||
strlcat(buf, FINIT_SYSCONFIG, sizeof(buf));
|
||||
#endif
|
||||
setenv("SERVICE_CONF_DIR", buf, 1);
|
||||
}
|
||||
|
||||
static void service_pre_script(svc_t *svc)
|
||||
{
|
||||
svc->pid = service_fork(svc);
|
||||
@@ -1534,7 +1624,7 @@ static void service_pre_script(svc_t *svc)
|
||||
NULL
|
||||
};
|
||||
|
||||
setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
|
||||
set_pre_post_envs(svc, "pre");
|
||||
execvp(_PATH_BSHELL, argv);
|
||||
_exit(EX_OSERR);
|
||||
}
|
||||
@@ -1563,7 +1653,7 @@ static void service_post_script(svc_t *svc)
|
||||
rc = WEXITSTATUS(svc->status);
|
||||
sig = WTERMSIG(svc->status);
|
||||
|
||||
setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
|
||||
set_pre_post_envs(svc, "post");
|
||||
|
||||
if (WIFEXITED(svc->status)) {
|
||||
char val[4];
|
||||
@@ -1586,12 +1676,12 @@ static void service_post_script(svc_t *svc)
|
||||
|
||||
static void service_retry(svc_t *svc)
|
||||
{
|
||||
int timeout;
|
||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
||||
int timeout;
|
||||
|
||||
service_timeout_cancel(svc);
|
||||
if (svc->respawn) {
|
||||
_d("%s crashed, respawning ...", svc->cmd);
|
||||
_d("%s crashed/exited, respawning ...", svc->cmd);
|
||||
svc_unblock(svc);
|
||||
service_step(svc);
|
||||
return;
|
||||
@@ -1599,15 +1689,22 @@ static void service_retry(svc_t *svc)
|
||||
|
||||
if (svc->state != SVC_HALTED_STATE ||
|
||||
svc->block != SVC_BLOCK_RESTARTING) {
|
||||
*restart_cnt = 0;
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Successfully restarted crashing service %s.",
|
||||
svc_ident(svc, NULL, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
if (*restart_cnt >= SVC_RESPAWN_MAX) {
|
||||
/* Peak instability index */
|
||||
if (*restart_cnt >= svc->restart_max) {
|
||||
logit(LOG_CONSOLE | LOG_WARNING, "Service %s keeps crashing, not restarting.",
|
||||
svc_ident(svc, NULL, 0));
|
||||
svc_crashing(svc);
|
||||
*restart_cnt = 0;
|
||||
if (svc->oncrash_action == SVC_ONCRASH_REBOOT) {
|
||||
logit(LOG_ERR, "%s issuing reboot", svc->cmd);
|
||||
sync();
|
||||
kill(1, SIGTERM);
|
||||
}
|
||||
service_step(svc);
|
||||
return;
|
||||
}
|
||||
@@ -1616,12 +1713,14 @@ static void service_retry(svc_t *svc)
|
||||
|
||||
_d("%s crashed, trying to start it again, attempt %d", svc->cmd, *restart_cnt);
|
||||
logit(LOG_CONSOLE | LOG_WARNING, "Service %s[%d] died, restarting (%d/%d)",
|
||||
svc_ident(svc, NULL, 0), svc->oldpid, *restart_cnt, SVC_RESPAWN_MAX);
|
||||
svc_ident(svc, NULL, 0), svc->oldpid, *restart_cnt, svc->restart_max);
|
||||
svc_unblock(svc);
|
||||
service_step(svc);
|
||||
|
||||
/* Wait 2s for the first 5 respawns, then back off to 5s */
|
||||
timeout = ((*restart_cnt) <= (SVC_RESPAWN_MAX / 2)) ? 2000 : 5000;
|
||||
timeout = ((*restart_cnt) <= (svc->restart_max / 2)) ? 2000 : 5000;
|
||||
/* If a longer timeout was specified in the conf, use that instead. */
|
||||
timeout = max(svc->restart_tmo, timeout);
|
||||
service_timeout_after(svc, timeout, service_retry);
|
||||
}
|
||||
|
||||
@@ -1638,6 +1737,27 @@ static void svc_set_state(svc_t *svc, svc_state_t new)
|
||||
service_timeout_cancel(svc);
|
||||
service_timeout_after(svc, svc->killdelay, service_kill);
|
||||
}
|
||||
|
||||
if (svc_is_runtask(svc)) {
|
||||
char success[MAX_COND_LEN], failure[MAX_COND_LEN];
|
||||
|
||||
snprintf(success, sizeof(success), "%s/%s/success", svc_typestr(svc), svc->name);
|
||||
snprintf(failure, sizeof(failure), "%s/%s/failure", svc_typestr(svc), svc->name);
|
||||
|
||||
/* create success/failure condition when entering SVC_DONE_STATE. */
|
||||
if (*state == SVC_DONE_STATE) {
|
||||
if (svc->started)
|
||||
cond_set_oneshot(success);
|
||||
else
|
||||
cond_set_oneshot(failure);
|
||||
}
|
||||
|
||||
/* clear all conditions when entering SVC_HALTED_STATE. */
|
||||
if (*state == SVC_HALTED_STATE) {
|
||||
cond_clear(success);
|
||||
cond_clear(failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1680,14 +1800,15 @@ restart:
|
||||
|
||||
case SVC_STOPPING_STATE:
|
||||
if (!svc->pid) {
|
||||
char cond[MAX_COND_LEN];
|
||||
char condstr[MAX_COND_LEN];
|
||||
|
||||
_d("%s: stopped, cleaning up timers and conditions ...", svc->cmd);
|
||||
service_timeout_cancel(svc);
|
||||
cond_clear(mkcond(svc, cond, sizeof(cond)));
|
||||
cond_clear(mkcond(svc, condstr, sizeof(condstr)));
|
||||
|
||||
switch (svc->type) {
|
||||
case SVC_TYPE_SERVICE:
|
||||
case SVC_TYPE_SYSV:
|
||||
case SVC_TYPE_TTY:
|
||||
if (svc_has_post(svc)) {
|
||||
svc_set_state(svc, SVC_CLEANUP_STATE);
|
||||
@@ -1698,7 +1819,6 @@ restart:
|
||||
|
||||
case SVC_TYPE_TASK:
|
||||
case SVC_TYPE_RUN:
|
||||
case SVC_TYPE_SYSV:
|
||||
svc_set_state(svc, SVC_DONE_STATE);
|
||||
break;
|
||||
|
||||
@@ -1751,6 +1871,9 @@ restart:
|
||||
|
||||
if (!svc->pid) {
|
||||
if (svc_is_daemon(svc) || svc_is_tty(svc)) {
|
||||
if (svc_is_forking(svc))
|
||||
break;
|
||||
|
||||
svc_restarting(svc);
|
||||
svc_set_state(svc, SVC_HALTED_STATE);
|
||||
|
||||
@@ -1758,7 +1881,8 @@ restart:
|
||||
* Restart directly after the first crash,
|
||||
* then retry after 2 sec
|
||||
*/
|
||||
_d("delayed restart of %s", svc->cmd);
|
||||
if (!svc->respawn)
|
||||
_d("delayed restart of %s", svc->cmd);
|
||||
service_timeout_after(svc, 1, service_retry);
|
||||
break;
|
||||
}
|
||||
@@ -1774,6 +1898,7 @@ restart:
|
||||
break;
|
||||
}
|
||||
}
|
||||
service_timeout_cancel(svc);
|
||||
|
||||
cond = cond_get_agg(svc->cond);
|
||||
switch (cond) {
|
||||
@@ -1932,6 +2057,65 @@ int service_completed(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Every five¹ minutes we sweep over all services, skipping crashed or
|
||||
* otherwise no longer running ones. Decrement non-zero crash counters
|
||||
* to allow services that have started after an initial crash to slowly
|
||||
* prove themselves again as stable services. Previously this counter
|
||||
* was reset as soon as such services had stopped crashing at least once
|
||||
* per second. This new scheme allows us to catch those that rage-quit
|
||||
* immediately when we try to start them, but now also those that are
|
||||
* only slightly buggy -- when they reach their restart_max, they too
|
||||
* are marked 'crashed'.
|
||||
*
|
||||
* This does not affect the restart_tot counter, which you can see in
|
||||
* the output from 'initctl status foo', along with this instability
|
||||
* "index" in parethesis: total (cnt/max)
|
||||
*/
|
||||
static void service_interval_cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
svc_t *svc, *iter = NULL;
|
||||
|
||||
(void)arg;
|
||||
if (UEV_ERROR == events) {
|
||||
uev_timer_start(w);
|
||||
return;
|
||||
}
|
||||
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
if (svc_is_daemon(svc) || svc_is_sysv(svc)) {
|
||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
||||
|
||||
if (!svc_is_running(svc))
|
||||
continue;
|
||||
|
||||
if (*restart_cnt > 0) {
|
||||
logit(LOG_CONSOLE | LOG_DEBUG, "Aging %s instability index (%d/%d)",
|
||||
svc_ident(svc, NULL, 0), svc->restart_cnt, svc->restart_max);
|
||||
(*restart_cnt)--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
service_init();
|
||||
}
|
||||
|
||||
/*
|
||||
* The service_interval may change (conf) between invocations, so we
|
||||
* periodically reset the one-shot timer instead of using a periodic.
|
||||
*/
|
||||
void service_init(void)
|
||||
{
|
||||
static int initialized = 0;
|
||||
static uev_t watcher;
|
||||
|
||||
if (!initialized) {
|
||||
uev_timer_init(ctx, &watcher, service_interval_cb, NULL, service_interval, 0);
|
||||
initialized = 1;
|
||||
} else
|
||||
uev_timer_set(&watcher, service_interval, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
|
||||
@@ -41,6 +41,8 @@ void service_worker (void *unused);
|
||||
|
||||
int service_completed (void);
|
||||
|
||||
void service_init (void);
|
||||
|
||||
#endif /* FINIT_SERVICE_H_ */
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,9 +71,14 @@
|
||||
|
||||
#include <dirent.h>
|
||||
#include <string.h> /* strerror() */
|
||||
#include <sched.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/wait.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "cond.h"
|
||||
@@ -168,7 +173,7 @@ void unmount_regular(void);
|
||||
*
|
||||
* https://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons/
|
||||
*/
|
||||
void do_kill(int signo)
|
||||
void do_iterate_proc(int (*cb)(int, void *), void *data)
|
||||
{
|
||||
DIR *dirp;
|
||||
|
||||
@@ -187,6 +192,8 @@ void do_kill(int signo)
|
||||
pid = atoi(d->d_name);
|
||||
if (!pid)
|
||||
continue;
|
||||
if (pid == 1)
|
||||
continue;
|
||||
|
||||
snprintf(file, sizeof(file), "/proc/%s/cmdline", d->d_name);
|
||||
fp = fopen(file, "r");
|
||||
@@ -199,7 +206,11 @@ void do_kill(int signo)
|
||||
else if (file[0] == '@')
|
||||
_d("Skipping %s ...", &file[1]);
|
||||
else
|
||||
kill(pid, signo);
|
||||
if (cb(pid, data)) {
|
||||
_d("PID %d is still alive (%s)", pid, file);
|
||||
fclose(fp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
@@ -207,8 +218,61 @@ void do_kill(int signo)
|
||||
}
|
||||
}
|
||||
|
||||
static int kill_cb(int pid, void *data)
|
||||
{
|
||||
int signo = *(int *)data;
|
||||
|
||||
kill(pid, signo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int status_cb(int pid, void *data)
|
||||
{
|
||||
int *has_proc = (int *)data;
|
||||
|
||||
*has_proc = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* return value:
|
||||
* 1 - at least one process remaining
|
||||
* 0 - no processes remaining
|
||||
*/
|
||||
static int do_wait(int secs)
|
||||
{
|
||||
const int delay = 250000;
|
||||
int iterations = secs * 1000 * 1000 / delay;
|
||||
int has_proc;
|
||||
|
||||
do {
|
||||
do_usleep(delay);
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
;
|
||||
has_proc = 0;
|
||||
iterations--;
|
||||
do_iterate_proc(status_cb, &has_proc);
|
||||
}
|
||||
while (has_proc && iterations > 0);
|
||||
|
||||
return has_proc;
|
||||
}
|
||||
|
||||
void do_shutdown(shutop_t op)
|
||||
{
|
||||
struct sched_param sched_param = { .sched_priority = 99 };
|
||||
int in_cont = in_container();
|
||||
int signo = SIGTERM;
|
||||
|
||||
if (!in_cont) {
|
||||
/*
|
||||
* On a PREEMPT-RT system, Finit must run as the highest prioritized
|
||||
* RT process to ensure it completes the shutdown sequence.
|
||||
*/
|
||||
sched_setscheduler(1, SCHED_RR, &sched_param);
|
||||
}
|
||||
|
||||
if (sdown)
|
||||
run_interactive(sdown, "Calling shutdown hook: %s", sdown);
|
||||
|
||||
@@ -219,9 +283,11 @@ void do_shutdown(shutop_t op)
|
||||
* Tell remaining non-monitored processes to exit, give them
|
||||
* time to exit gracefully, 2 sec was customary, we go for 1.
|
||||
*/
|
||||
do_kill(SIGTERM);
|
||||
do_sleep(1);
|
||||
do_kill(SIGKILL);
|
||||
do_iterate_proc(kill_cb, &signo);
|
||||
if (do_wait(1)) {
|
||||
signo = SIGKILL;
|
||||
do_iterate_proc(kill_cb, &signo);
|
||||
}
|
||||
|
||||
/* Exit plugins and API gracefully */
|
||||
plugin_exit();
|
||||
@@ -231,6 +297,12 @@ void do_shutdown(shutop_t op)
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
;
|
||||
|
||||
if (in_cont) {
|
||||
if (osheading)
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "%s, shutting down container.", osheading);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/* Close all local non-console descriptors */
|
||||
for (int fd = 3; fd < 128; fd++)
|
||||
close(fd);
|
||||
@@ -251,16 +323,22 @@ void do_shutdown(shutop_t op)
|
||||
|
||||
/* Unmount any tmpfs before unmounting swap ... */
|
||||
unmount_tmpfs();
|
||||
run("swapoff -e -a");
|
||||
if (whichp("swapoff"))
|
||||
run_interactive("swapoff -a", "Disabling system swap");
|
||||
|
||||
/* ... unmount remaining regular file systems. */
|
||||
unmount_regular();
|
||||
|
||||
/* We sit on / so we must remount it ro, try all the things! */
|
||||
/*
|
||||
* We sit on / so we must remount it ro, try all the things!
|
||||
* See the following links for details:
|
||||
* - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=339023
|
||||
* - https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/29187
|
||||
*/
|
||||
sync();
|
||||
run("mount -n -o remount,ro -t dummytype dummydev /");
|
||||
run("mount -n -o remount,ro dummydev /");
|
||||
run("mount -n -o remount,ro /");
|
||||
run("mount -n -o remount,ro -t dummytype dummydev /", NULL);
|
||||
run("mount -n -o remount,ro dummydev /", NULL);
|
||||
run("mount -n -o remount,ro /", "mount");
|
||||
|
||||
/* Call mdadm to mark any RAID array(s) as clean before halting. */
|
||||
mdadm_wait();
|
||||
@@ -445,7 +523,7 @@ const char *sig_name(int signo)
|
||||
}
|
||||
|
||||
/*
|
||||
* Inital signal setup - ignore everything but SIGCHLD until we're capable of responding
|
||||
* Initial signal setup - ignore everything but SIGCHLD until we're capable of responding
|
||||
*/
|
||||
static void chld_handler(int sig, siginfo_t *info, void *ctx)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "config.h" /* Generated by configure script */
|
||||
|
||||
#include <paths.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "finit.h"
|
||||
@@ -38,6 +39,10 @@
|
||||
|
||||
sm_t sm;
|
||||
|
||||
#ifndef FINIT_NOLOGIN_PATH
|
||||
#define FINIT_NOLOGIN_PATH _PATH_NOLOGIN /* Stop user logging in. */
|
||||
#endif
|
||||
|
||||
void sm_init(sm_t *sm)
|
||||
{
|
||||
sm->state = SM_BOOTSTRAP_STATE;
|
||||
@@ -76,16 +81,16 @@ static char *sm_status(sm_state_t state)
|
||||
* Disable login in single user mode and shutdown/reboot
|
||||
*
|
||||
* Re-enable only when going from these runlevels, this way a user can
|
||||
* manage /etc/nologin manually within the other runlevels without us
|
||||
* pulling the rug from under their feet.
|
||||
* manage FINIT_NOLOGIN_PATH manually within the other runlevels without
|
||||
* us pulling the rug from under their feet.
|
||||
*/
|
||||
static void nologin(void)
|
||||
{
|
||||
if (runlevel == 1 || runlevel == 0 || runlevel == 6)
|
||||
touch("/etc/nologin");
|
||||
touch(FINIT_NOLOGIN_PATH);
|
||||
|
||||
if (prevlevel == 1 || prevlevel == 0 || prevlevel == 6)
|
||||
erase("/etc/nologin");
|
||||
erase(FINIT_NOLOGIN_PATH);
|
||||
}
|
||||
|
||||
void sm_set_runlevel(sm_t *sm, int newlevel)
|
||||
@@ -187,7 +192,7 @@ restart:
|
||||
}
|
||||
|
||||
/* Prev runlevel services stopped, call hooks before starting new runlevel ... */
|
||||
_d("All services have been stoppped, calling runlevel change hooks ...");
|
||||
_d("All services have been stopped, calling runlevel change hooks ...");
|
||||
plugin_run_hooks(HOOK_RUNLEVEL_CHANGE); /* Reconfigure HW/VLANs/etc here */
|
||||
|
||||
_d("Starting services new to this runlevel ...");
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
typedef enum {
|
||||
SM_BOOTSTRAP_STATE = 0, /* Init state, bootstrap services */
|
||||
SM_RUNNING_STATE, /* Normal state, services running */
|
||||
SM_RUNLEVEL_CHANGE_STATE, /* A runlevel change has occured */
|
||||
SM_RUNLEVEL_CHANGE_STATE, /* A runlevel change has occurred */
|
||||
SM_RUNLEVEL_WAIT_STATE, /* Waiting for all stopped runlevel processes to be halted */
|
||||
SM_RELOAD_CHANGE_STATE, /* A reload event has occured */
|
||||
SM_RELOAD_CHANGE_STATE, /* A reload event has occurred */
|
||||
SM_RELOAD_WAIT_STATE, /* Waiting for all stopped reload processes to be halted */
|
||||
} sm_state_t;
|
||||
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <sys/time.h>
|
||||
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
|
||||
#include "finit.h"
|
||||
#include "svc.h"
|
||||
@@ -252,7 +256,7 @@ svc_t *svc_named_iterator(svc_t **iter, int first, char *cmd)
|
||||
for (svc = svc_iterator(iter, first); svc; svc = svc_iterator(iter, 0)) {
|
||||
char *name = svc->name;
|
||||
|
||||
if (!strncmp(name, cmd, strlen(name)))
|
||||
if (string_compare(name, cmd))
|
||||
return svc;
|
||||
}
|
||||
|
||||
@@ -469,23 +473,23 @@ svc_t *svc_find_by_pidfile(char *fn)
|
||||
pid_t pid;
|
||||
|
||||
pid = pid_file_read(fn);
|
||||
if (pid <= 0) {
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
int v = 0;
|
||||
|
||||
if (svc->pidfile[0] == '!')
|
||||
v = 1;
|
||||
if (strcmp(&svc->pidfile[v], fn))
|
||||
continue;
|
||||
|
||||
if (pid > 1) {
|
||||
svc = svc_find_by_pid(pid);
|
||||
if (svc)
|
||||
return svc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* No PID in file, or a sysv service. So it has probably forked
|
||||
* off a chiled that we don't know about. See if we can match
|
||||
* the PID file to a service instead.
|
||||
*/
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
if (svc->pid != pid)
|
||||
int v = 0;
|
||||
|
||||
if (svc->pidfile[0] == '!')
|
||||
v = 1;
|
||||
if (strcmp(&svc->pidfile[v], fn))
|
||||
continue;
|
||||
|
||||
return svc;
|
||||
@@ -613,27 +617,6 @@ int svc_enabled(svc_t *svc)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int svc_is_unique(svc_t *svc)
|
||||
{
|
||||
svc_t *s, *iter = NULL;
|
||||
int unique = 1;
|
||||
|
||||
for (s = svc_iterator(&iter, 1); s; s = svc_iterator(&iter, 0)) {
|
||||
if (svc->type == SVC_TYPE_FREE)
|
||||
continue;
|
||||
|
||||
if (s == svc)
|
||||
continue;
|
||||
|
||||
if (s->job == svc->job) {
|
||||
unique = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return unique;
|
||||
}
|
||||
|
||||
/* break up "job:id job:id job:id ..." into several "job:id" tokens */
|
||||
static char *tokstr(char *str, size_t len)
|
||||
{
|
||||
@@ -667,7 +650,7 @@ static char *tokstr(char *str, size_t len)
|
||||
/*
|
||||
* Used by api.c (to start/stop/restart) and initctl.c (for input validation)
|
||||
*/
|
||||
int svc_parse_jobstr(char *str, size_t len, int (*found)(svc_t *), int (not_found)(char *, char *))
|
||||
int svc_parse_jobstr(char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *))
|
||||
{
|
||||
char *input, *token;
|
||||
int result = 0;
|
||||
@@ -703,11 +686,11 @@ int svc_parse_jobstr(char *str, size_t len, int (*found)(svc_t *), int (not_foun
|
||||
if (!ptr) {
|
||||
svc = svc_job_iterator(&iter, 1, job);
|
||||
if (!svc && not_found)
|
||||
result += not_found(NULL, token);
|
||||
result += not_found(NULL, token, user_data);
|
||||
|
||||
while (svc) {
|
||||
if (found)
|
||||
result += found(svc);
|
||||
result += found(svc, user_data);
|
||||
svc = svc_job_iterator(&iter, 0, job);
|
||||
}
|
||||
} else {
|
||||
@@ -716,19 +699,19 @@ int svc_parse_jobstr(char *str, size_t len, int (*found)(svc_t *), int (not_foun
|
||||
|
||||
svc = svc_find_by_jobid(job, id);
|
||||
if (!svc && not_found)
|
||||
result += not_found(token, id);
|
||||
result += not_found(token, id, user_data);
|
||||
else if (found)
|
||||
result += found(svc);
|
||||
result += found(svc, user_data);
|
||||
}
|
||||
} else {
|
||||
if (!ptr) {
|
||||
svc = svc_named_iterator(&iter, 1, token);
|
||||
if (!svc && not_found)
|
||||
result += not_found(token, id);
|
||||
result += not_found(token, id, user_data);
|
||||
|
||||
while (svc) {
|
||||
if (found)
|
||||
result += found(svc);
|
||||
result += found(svc, user_data);
|
||||
svc = svc_named_iterator(&iter, 0, token);
|
||||
}
|
||||
} else {
|
||||
@@ -737,9 +720,9 @@ int svc_parse_jobstr(char *str, size_t len, int (*found)(svc_t *), int (not_foun
|
||||
|
||||
svc = svc_find_by_nameid(token, id);
|
||||
if (!svc && not_found)
|
||||
result += not_found(token, id);
|
||||
result += not_found(token, id, user_data);
|
||||
else if (found)
|
||||
result += found(svc);
|
||||
result += found(svc, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,13 @@
|
||||
#include <sys/ipc.h> /* IPC_CREAT */
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h> /* pid_t */
|
||||
#include <lite/lite.h>
|
||||
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
# include <libite/queue.h> /* BSD sys/queue.h API */
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
# include <lite/queue.h> /* BSD sys/queue.h API */
|
||||
#endif
|
||||
#include <uev/uev.h>
|
||||
|
||||
#include "cgroup.h"
|
||||
@@ -40,7 +45,7 @@ typedef int svc_cmd_t;
|
||||
typedef enum {
|
||||
SVC_TYPE_FREE = 0, /* Free to allocate */
|
||||
SVC_TYPE_SERVICE = 1, /* Monitored, will be respawned */
|
||||
SVC_TYPE_TASK = 2, /* One-shot, runs in parallell */
|
||||
SVC_TYPE_TASK = 2, /* One-shot, runs in parallel */
|
||||
SVC_TYPE_RUN = 4, /* Like task, but wait for completion */
|
||||
SVC_TYPE_TTY = 8, /* Like service, but dedicated to TTYs */
|
||||
SVC_TYPE_SYSV = 32, /* SysV style init.d script w/ start/stop */
|
||||
@@ -70,6 +75,11 @@ typedef enum {
|
||||
SVC_BLOCK_RESTARTING,
|
||||
} svc_block_t;
|
||||
|
||||
typedef enum {
|
||||
SVC_ONCRASH_IGNORE = 0,
|
||||
SVC_ONCRASH_REBOOT = 1,
|
||||
} svc_oncrash_action_t;
|
||||
|
||||
#define MAX_ID_LEN 16
|
||||
#define MAX_ARG_LEN 64
|
||||
#define MAX_IDENT_LEN (MAX_ARG_LEN + MAX_ID_LEN + 1)
|
||||
@@ -102,7 +112,7 @@ typedef struct svc {
|
||||
struct cgroup cgroup;
|
||||
|
||||
/* Service details */
|
||||
int sighalt; /* Signal to stop prorcess, default: SIGTERM */
|
||||
int sighalt; /* Signal to stop process, default: SIGTERM */
|
||||
int killdelay; /* Delay in msec before sending SIGKILL */
|
||||
pid_t oldpid, pid;
|
||||
char pidfile[256];
|
||||
@@ -117,6 +127,7 @@ typedef struct svc {
|
||||
int starting; /* ... waiting for pidfile to be re-asserted */
|
||||
int runlevels;
|
||||
int sighup; /* This service supports SIGHUP :) */
|
||||
int forking; /* This is a service/sysv daemon that forks, wait for it ... */
|
||||
svc_block_t block; /* Reason that this service is currently stopped */
|
||||
char cond[MAX_COND_LEN];
|
||||
|
||||
@@ -127,6 +138,10 @@ typedef struct svc {
|
||||
|
||||
/* Counters */
|
||||
char once; /* run/task, (at least) once per runlevel */
|
||||
unsigned int restart_tot; /* Total restarts ever, summarized, including `initctl restart` */
|
||||
unsigned char restart_max; /* Maximum number of restarts allowed */
|
||||
int restart_tmo; /* Time required for the service to start. */
|
||||
unsigned char oncrash_action; /* Action to perform in crashed state. */
|
||||
char respawn; /* ttys, or services with `respawn`, never increment restart_cnt */
|
||||
const char restart_cnt; /* Incremented for each restart by service monitor. */
|
||||
|
||||
@@ -207,15 +222,14 @@ void svc_prune_bootstrap (void);
|
||||
|
||||
void svc_enable (svc_t *svc);
|
||||
int svc_enabled (svc_t *svc);
|
||||
int svc_is_unique (svc_t *svc);
|
||||
|
||||
int svc_parse_jobstr (char *str, size_t len, int (*found)(svc_t *), int (not_found)(char *, char *));
|
||||
int svc_parse_jobstr (char *str, size_t len, void *user_data, int (*found)(svc_t *, void *), int (not_found)(char *, char *, void *));
|
||||
|
||||
static inline int svc_is_daemon (svc_t *svc) { return svc && SVC_TYPE_SERVICE == svc->type; }
|
||||
static inline int svc_is_sysv (svc_t *svc) { return svc && SVC_TYPE_SYSV == svc->type; }
|
||||
static inline int svc_is_tty (svc_t *svc) { return svc && SVC_TYPE_TTY == svc->type; }
|
||||
static inline int svc_is_runtask (svc_t *svc) { return svc && (SVC_TYPE_RUNTASK & svc->type);}
|
||||
static inline int svc_is_forking (svc_t *svc) { return (svc_is_daemon(svc) || svc_is_sysv(svc)) && svc->pidfile[0] == '!'; }
|
||||
static inline int svc_is_forking (svc_t *svc) { return svc && svc->forking; }
|
||||
|
||||
static inline int svc_in_runlevel (svc_t *svc, int runlevel) { return svc && ISSET(svc->runlevels, runlevel); }
|
||||
static inline int svc_nohup (svc_t *svc) { return svc && (0 == svc->sighup || 0 != svc->args_dirty); }
|
||||
@@ -265,6 +279,31 @@ static inline int svc_has_cond(svc_t *svc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const char *svc_typestr(svc_t *svc)
|
||||
{
|
||||
switch (svc->type) {
|
||||
case SVC_TYPE_FREE:
|
||||
return "free";
|
||||
|
||||
case SVC_TYPE_SERVICE:
|
||||
return "service";
|
||||
|
||||
case SVC_TYPE_TASK:
|
||||
return "task";
|
||||
|
||||
case SVC_TYPE_RUN:
|
||||
return "run";
|
||||
|
||||
case SVC_TYPE_TTY:
|
||||
return "tty";
|
||||
|
||||
case SVC_TYPE_SYSV:
|
||||
return "sysv";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static inline char *svc_status(svc_t *svc)
|
||||
{
|
||||
if (!svc)
|
||||
@@ -294,7 +333,10 @@ static inline char *svc_status(svc_t *svc)
|
||||
return "unknown";
|
||||
|
||||
case SVC_DONE_STATE:
|
||||
return "done";
|
||||
if (svc->started)
|
||||
return "done";
|
||||
else
|
||||
return "failed";
|
||||
|
||||
case SVC_STOPPING_STATE:
|
||||
switch (svc->type) {
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "config.h" /* Generated by configure script */
|
||||
#include "finit.h"
|
||||
|
||||
+132
-7
@@ -24,6 +24,7 @@
|
||||
#include "config.h"
|
||||
#include <ctype.h> /* isprint() */
|
||||
#include <errno.h>
|
||||
#include <mntent.h>
|
||||
#include <regex.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -37,7 +38,11 @@
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
#include <sys/sysinfo.h> /* sysinfo() */
|
||||
#include <lite/lite.h> /* strlcat() */
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
#include "util.h"
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
@@ -177,7 +182,8 @@ int fnread(char *buf, size_t len, char *fmt, ...)
|
||||
if (!fp)
|
||||
return -1;
|
||||
|
||||
len = fread(buf, sizeof(char), len, fp);
|
||||
len = fread(buf, sizeof(char), len - 1, fp);
|
||||
buf[len] = 0;
|
||||
fclose(fp);
|
||||
|
||||
return (int)len;
|
||||
@@ -216,9 +222,9 @@ int fnwrite(char *value, char *fmt, ...)
|
||||
|
||||
int fngetint(char *path, int *val)
|
||||
{
|
||||
char buf[10];
|
||||
char buf[64];
|
||||
|
||||
if (fnread(buf, sizeof(buf), path) <= 0)
|
||||
if (fnread(buf, sizeof(buf), "%s", path) <= 0)
|
||||
return -1;
|
||||
|
||||
errno = 0;
|
||||
@@ -229,6 +235,40 @@ int fngetint(char *path, int *val)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a replacement for the non-working reboot(RB_SW_SUSPEND). It
|
||||
* checks for suspend to RAM support, assuming `mem_sleep` has a sane
|
||||
* default, e.g. 'deep' or 's2idle'. The latter should be possible to
|
||||
* select from finit.conf, but for now we go with the kernel default.
|
||||
* For more information on kernel sleep states, see:
|
||||
* https://www.kernel.org/doc/html/latest/admin-guide/pm/sleep-states.html
|
||||
*/
|
||||
int suspend(void)
|
||||
{
|
||||
char buf[80];
|
||||
char *ptr;
|
||||
|
||||
if (fnread(buf, sizeof(buf), "/sys/power/state") <= 0) {
|
||||
opnotsup:
|
||||
errno = EINVAL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
chomp(buf);
|
||||
|
||||
ptr = strtok(buf, " ");
|
||||
while (ptr) {
|
||||
if (!strcmp(ptr, "mem"))
|
||||
break;
|
||||
|
||||
ptr = strtok(NULL, " ");
|
||||
}
|
||||
if (!ptr)
|
||||
goto opnotsup;
|
||||
|
||||
return fnwrite("mem", "/sys/power/state");
|
||||
}
|
||||
|
||||
int strtobytes(char *arg)
|
||||
{
|
||||
int mod = 0, bytes;
|
||||
@@ -258,17 +298,39 @@ int strtobytes(char *arg)
|
||||
return bytes;
|
||||
}
|
||||
|
||||
char *sig2str(int sig)
|
||||
char *sig2str(int signo)
|
||||
{
|
||||
static char signame[8];
|
||||
|
||||
if (sig < 1 || sig >= (int)NELEMS(signames))
|
||||
if (signo < 1 || signo >= (int)NELEMS(signames))
|
||||
return "";
|
||||
|
||||
snprintf(signame, sizeof(signame), "/%s", signames[sig]);
|
||||
snprintf(signame, sizeof(signame), "/%s", signames[signo]);
|
||||
return signame;
|
||||
}
|
||||
|
||||
/**
|
||||
* str2sig - Translate signal name to the corresponding signal number.
|
||||
* @sig: The name of the signal
|
||||
*
|
||||
* A signal can be a complete signal name such as "SIGHUP", or
|
||||
* it can be the shortest unique name, such as "HUP" (no SIG prefix).
|
||||
*/
|
||||
int str2sig(char *sig)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!strncasecmp(sig, "SIG", 3))
|
||||
sig += 3;
|
||||
|
||||
for (i = 1; i < NELEMS(signames); ++i) {
|
||||
if (strcasecmp(sig, signames[i]) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *code2str(int code)
|
||||
{
|
||||
static char codename[20];
|
||||
@@ -291,6 +353,20 @@ void do_sleep(unsigned int sec)
|
||||
;
|
||||
}
|
||||
|
||||
void do_usleep(unsigned int usec)
|
||||
{
|
||||
struct timespec deadline;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &deadline);
|
||||
|
||||
deadline.tv_nsec += usec * 1000;
|
||||
deadline.tv_sec += deadline.tv_nsec / 1000000000;
|
||||
deadline.tv_nsec = deadline.tv_nsec % 1000000000;
|
||||
|
||||
while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline, NULL) != 0 && errno == EINTR)
|
||||
;
|
||||
}
|
||||
|
||||
/* Seconds since boot, from sysinfo() */
|
||||
long jiffies(void)
|
||||
{
|
||||
@@ -393,6 +469,55 @@ char *sanitize(char *arg, size_t len)
|
||||
return arg;
|
||||
}
|
||||
|
||||
static int hasopt(char *opts, char *opt)
|
||||
{
|
||||
char buf[strlen(opts) + 1];
|
||||
char *ptr;
|
||||
|
||||
memcpy(buf, opts, sizeof(buf));
|
||||
ptr = strtok(buf, ",");
|
||||
while (ptr) {
|
||||
if (!strcmp(ptr, opt))
|
||||
return 1;
|
||||
|
||||
ptr = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ismnt(char *file, char *dir, char *mode)
|
||||
{
|
||||
struct mntent *mnt;
|
||||
int found = 0;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent(file, "r");
|
||||
if (!fp)
|
||||
return 0; /* Dunno, maybe not */
|
||||
|
||||
while ((mnt = getmntent(fp))) {
|
||||
if (!strcmp(mnt->mnt_dir, dir)) {
|
||||
if (mode) {
|
||||
if (hasopt(mnt->mnt_opts, mode))
|
||||
found = 1;
|
||||
} else
|
||||
found = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
endmntent(fp);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/* Requires /proc to be mounted */
|
||||
int fismnt(char *dir)
|
||||
{
|
||||
return ismnt("/proc/mounts", dir, NULL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
/*
|
||||
* Called by initctl, and by finit at boot and shutdown, to
|
||||
|
||||
+18
-6
@@ -32,7 +32,6 @@
|
||||
#include <sys/reboot.h>
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#include <lite/lite.h>
|
||||
|
||||
#ifndef RB_SW_SUSPEND /* Since Linux 2.5.18, but not in GLIBC until 2.19 */
|
||||
#define RB_SW_SUSPEND 0xd000fce2
|
||||
@@ -45,26 +44,39 @@ extern char *prognm;
|
||||
|
||||
/* Define for printheader() from conio.h, used in initctl */
|
||||
#define SCREEN_WIDTH ttcols
|
||||
#include <lite/conio.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/conio.h>
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/conio.h>
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
char *progname (char *arg0);
|
||||
|
||||
char *str (char *fmt, ...);
|
||||
int fnread (char *buf, size_t len, char *fmt, ...);
|
||||
int fnwrite (char *value, char *fmt, ...);
|
||||
char *str (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
int fnread (char *buf, size_t len, char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
int fnwrite (char *value, char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
int fngetint (char *path, int *val);
|
||||
|
||||
int suspend (void);
|
||||
|
||||
int strtobytes (char *arg);
|
||||
char *sig2str (int sig);
|
||||
int str2sig (char *sig);
|
||||
char *code2str (int code);
|
||||
|
||||
void do_sleep (unsigned int sec);
|
||||
void do_usleep (unsigned int usec);
|
||||
long jiffies (void);
|
||||
char *uptime (long secs, char *buf, size_t len);
|
||||
char *memsz (uint64_t sz, char *buf, size_t len);
|
||||
|
||||
char *sanitize (char *arg, size_t len);
|
||||
|
||||
int ismnt (char *file, char *dir, char *mode);
|
||||
int fismnt (char *dir);
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
int ttinit (void);
|
||||
int ttraw (void);
|
||||
@@ -75,7 +87,7 @@ int ttcooked (void);
|
||||
#define ttcooked() 0
|
||||
#endif
|
||||
|
||||
static inline void dbg(char *fmt, ...)
|
||||
static __attribute__ ((format (printf, 1, 2))) inline void dbg(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
||||
+5
-1
@@ -26,7 +26,11 @@
|
||||
#include <time.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <lite/lite.h>
|
||||
#ifdef _LIBITE_LITE
|
||||
# include <libite/lite.h>
|
||||
#else
|
||||
# include <lite/lite.h>
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include "util.h"
|
||||
|
||||
+25
-4
@@ -1,12 +1,29 @@
|
||||
EXTRA_DIST = tenv/lib.sh tenv/exec.sh tenv/start.sh
|
||||
EXTRA_DIST += tenv/root.mk tenv/busybox-x86_64.md5
|
||||
EXTRA_DIST += tenv/chrootsetup.sh
|
||||
SUBDIRS = common tenv
|
||||
|
||||
EXTRA_DIST = skel/bin/busybox-x86_64.md5 skel/sbin/service.sh skel/bin/slay \
|
||||
skel/cdrom/.empty skel/dev/shm/.empty skel/dev/pts/.empty \
|
||||
skel/etc/inittab skel/etc/hostname skel/etc/fstab \
|
||||
skel/etc/init.d/rcS skel/etc/init.d/rcK skel/tmp/.empty \
|
||||
skel/etc/init.d/S01-service.sh skel/home/.empty \
|
||||
skel/proc/.empty skel/root/.empty skel/run/.empty \
|
||||
skel/sbin/chrootsetup.sh skel/srv/.empty skel/sys/.empty \
|
||||
skel/usr/bin/.empty skel/usr/lib/.empty skel/usr/sbin/.empty \
|
||||
skel/usr/games/.empty skel/usr/src/.empty \
|
||||
skel/usr/share/.empty skel/usr/include/.empty \
|
||||
skel/usr/local/games/.empty skel/usr/local/sbin/.empty \
|
||||
skel/usr/local/share/.empty skel/usr/local/src/.empty \
|
||||
skel/usr/local/lib/.empty skel/usr/local/bin/.empty \
|
||||
skel/usr/local/etc/.empty skel/var/.empty
|
||||
|
||||
EXTRA_DIST += setup-root.sh
|
||||
EXTRA_DIST += common/service.conf common/service.sh
|
||||
EXTRA_DIST += add-remove-dynamic-service.sh
|
||||
EXTRA_DIST += add-remove-dynamic-service-sub-config.sh
|
||||
EXTRA_DIST += start-stop-service.sh
|
||||
EXTRA_DIST += start-stop-service-sub-config.sh
|
||||
EXTRA_DIST += start-kill-service.sh
|
||||
EXTRA_DIST += start-stop-sysv.sh
|
||||
EXTRA_DIST += start-stop-serv.sh
|
||||
EXTRA_DIST += signal-service.sh
|
||||
|
||||
AM_TESTS_ENVIRONMENT = TENV_ROOT='$(abs_builddir)/tenv-root/';
|
||||
AM_TESTS_ENVIRONMENT += export TENV_ROOT;
|
||||
@@ -26,6 +43,10 @@ TESTS += add-remove-dynamic-service.sh
|
||||
TESTS += add-remove-dynamic-service-sub-config.sh
|
||||
TESTS += start-stop-service.sh
|
||||
TESTS += start-stop-service-sub-config.sh
|
||||
TESTS += start-kill-service.sh
|
||||
TESTS += start-stop-sysv.sh
|
||||
TESTS += start-stop-serv.sh
|
||||
TESTS += signal-service.sh
|
||||
|
||||
clean-local:
|
||||
-rm -rf $(builddir)/tenv-root/
|
||||
|
||||
+14
-3
@@ -1,5 +1,5 @@
|
||||
Tests
|
||||
=====
|
||||
Finit Test Suite
|
||||
================
|
||||
|
||||
Finit comes with a set of tests and a small framework for running them.
|
||||
Contributors are encouraged to write new tests when implementing features, or
|
||||
@@ -10,10 +10,16 @@ be able to be launched as PID 1. Since it's also running with it's own root
|
||||
directory it will be able to function properly without having any super user
|
||||
privileges in the host environment.
|
||||
|
||||
|
||||
Running tests
|
||||
-------------
|
||||
|
||||
To run the test suite, first [build](../doc/build.md) Finit - then simply run:
|
||||
To run the test suite, first [build](../doc/build.md) Finit, e.g:
|
||||
|
||||
./configure --prefix=/usr --exec-prefix= --sysconfdir=/etc --localstatedir=/var
|
||||
make -j9 clean all
|
||||
|
||||
Then run (parallel does not work atm):
|
||||
|
||||
make check
|
||||
|
||||
@@ -24,3 +30,8 @@ test suite, which is handy when developing new tests or debugging existing
|
||||
test. To execute an individual test, simply invoke the script containing it:
|
||||
|
||||
./test/name-of-the-test.sh
|
||||
|
||||
Another way to run a single (or more) test(s) is to define the `TESTS`
|
||||
environment variable:
|
||||
|
||||
TESTS="start-kill-service" make check
|
||||
|
||||
@@ -7,20 +7,18 @@ TEST_DIR=$(dirname "$0")
|
||||
# shellcheck source=/dev/null
|
||||
. "$TEST_DIR/tenv/lib.sh"
|
||||
|
||||
test_teardown() {
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown."
|
||||
test_teardown()
|
||||
{
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown."
|
||||
|
||||
texec rm -f "$FINIT_RCSD/service.conf"
|
||||
texec rm -f /test_assets/service.sh
|
||||
texec rm -f "$FINIT_RCSD/service.conf"
|
||||
}
|
||||
|
||||
say "Test start $(date)"
|
||||
|
||||
cp "$TEST_DIR"/common/service.sh "$TENV_ROOT"/test_assets/
|
||||
|
||||
say "Add a dynamic service in $FINIT_RCSD/service.conf"
|
||||
texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh' > $FINIT_RCSD/service.conf"
|
||||
texec sh -c "echo 'service [2345] kill:20 log service.sh -- Dyn serv' > $FINIT_RCSD/service.conf"
|
||||
|
||||
say 'Reload Finit'
|
||||
texec sh -c "initctl reload"
|
||||
|
||||
@@ -7,20 +7,18 @@ TEST_DIR=$(dirname "$0")
|
||||
# shellcheck source=/dev/null
|
||||
. "$TEST_DIR/tenv/lib.sh"
|
||||
|
||||
test_teardown() {
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown."
|
||||
test_teardown()
|
||||
{
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown."
|
||||
|
||||
texec rm -f "$FINIT_CONF"
|
||||
texec rm -f /test_assets/service.sh
|
||||
texec rm -f "$FINIT_CONF"
|
||||
}
|
||||
|
||||
say "Test start $(date)"
|
||||
|
||||
cp "$TEST_DIR"/common/service.sh "$TENV_ROOT"/test_assets/
|
||||
|
||||
say "Add a dynamic service in $FINIT_CONF"
|
||||
texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh' > $FINIT_CONF"
|
||||
texec sh -c "echo 'service [2345] kill:20 log service.sh -- Dyn service' > $FINIT_CONF"
|
||||
|
||||
say 'Reload Finit'
|
||||
texec sh -c "initctl reload"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
|
||||
/.deps/
|
||||
/serv
|
||||
@@ -0,0 +1,2 @@
|
||||
noinst_PROGRAMS = serv
|
||||
serv_SOURCES = serv.c
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Basic UNIX daemon
|
||||
*
|
||||
* Options to run in foreground and to create a PID file. When running
|
||||
* in foregrund it does not create a PID file by default.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define PROGNM "serv"
|
||||
|
||||
static void sig(int signo)
|
||||
{
|
||||
warnx("We got signal %d ...", signo);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void pidfile(char *pidfn)
|
||||
{
|
||||
char fn[80];
|
||||
pid_t pid;
|
||||
FILE *fp;
|
||||
|
||||
if (!pidfn) {
|
||||
snprintf(fn, sizeof(fn), "%s%s.pid", _PATH_VARRUN, PROGNM);
|
||||
pidfn = fn;
|
||||
}
|
||||
pid = getpid();
|
||||
warnx("Creating PID file %s with %d", pidfn, pid);
|
||||
|
||||
fp = fopen(pidfn, "w");
|
||||
if (!fp)
|
||||
exit(1);
|
||||
fprintf(fp, "%d\n", pid);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
static int usage(int rc)
|
||||
{
|
||||
FILE *fp = rc ? stderr : stdout;
|
||||
|
||||
fprintf(fp,
|
||||
"%s [-nhp] [-P FILE]\n"
|
||||
"\n"
|
||||
" -n Run in foreground\n"
|
||||
" -h Show help text (this)\n"
|
||||
" -p Create PID file despite running in foreground\n"
|
||||
" -P FILE Create PID file using FILE\n"
|
||||
"\n"
|
||||
"By default this program daemonizes itself to the background, and,\n"
|
||||
"when it's done setting up its signal handler(s), creates a PID file\n"
|
||||
"to let the rest of the system know it's done. When the program runs\n"
|
||||
"in the foreground it does not create a PID file by default.\n",
|
||||
PROGNM);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int do_background = 1;
|
||||
int do_pidfile = 1;
|
||||
char *pidfn = NULL;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "hnpP:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
return usage(0);
|
||||
case 'n':
|
||||
do_background = 0;
|
||||
do_pidfile--;
|
||||
break;
|
||||
case 'p':
|
||||
do_pidfile++;
|
||||
break;
|
||||
case 'P':
|
||||
pidfn = optarg;
|
||||
break;
|
||||
default:
|
||||
return usage(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Daemonize, fork to background etc. */
|
||||
if (do_background) {
|
||||
if (daemon(0, 1))
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Signal handlers first *then* PID file */
|
||||
signal(SIGTERM, sig);
|
||||
|
||||
/* Tell world where we are, but not if bg w/o pid file */
|
||||
if (do_pidfile == 1)
|
||||
pidfile(pidfn);
|
||||
|
||||
warnx("Entering while(1) loop");
|
||||
while (1)
|
||||
sleep(1);
|
||||
|
||||
warnx("Leaving ...");
|
||||
return 0;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
service [2345] kill:20 log /test_assets/service.sh
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
while true; do
|
||||
sleep 5
|
||||
done
|
||||
@@ -4,5 +4,14 @@ set -eu
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
make -C "$top_builddir" DESTDIR="$TENV_ROOT" install
|
||||
|
||||
mkdir -p "$TENV_ROOT/sbin/"
|
||||
cp "$top_builddir/test/common/serv" "$TENV_ROOT/sbin/"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
FINITBIN="$(pwd)/$top_builddir/src/finit" DEST="$TENV_ROOT" make -f "$srcdir/tenv/root.mk"
|
||||
|
||||
# Drop plugins we don't need in test, only causes confusing FAIL in logs.
|
||||
for plugin in tty.so urandom.so rtc.so modprobe.so hotplug.so; do
|
||||
find "$TENV_ROOT" -name $plugin -delete
|
||||
done
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# Verifies initctl can send arbitrary signals (USR1 in this case) to finit managed services
|
||||
|
||||
set -eu
|
||||
|
||||
TEST_DIR=$(dirname "$0")
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
. "$TEST_DIR/tenv/lib.sh"
|
||||
|
||||
test_teardown()
|
||||
{
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown."
|
||||
|
||||
texec rm -f "$FINIT_CONF"
|
||||
}
|
||||
|
||||
say "Test start $(date)"
|
||||
|
||||
say 'Ensure file system is cleared'
|
||||
texec rm -f /tmp/usr1.log
|
||||
|
||||
say "Add service stanza in $FINIT_CONF"
|
||||
texec sh -c "echo 'service [2345] kill:20 log service.sh -- Test service' > $FINIT_CONF"
|
||||
|
||||
say 'Reload Finit'
|
||||
texec sh -c "initctl reload"
|
||||
|
||||
say 'Send SIGUSR1 to service...'
|
||||
texec sh -c "initctl signal service.sh SIGUSR1"
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
retry 'assert "service.sh received SIGUSR" "$(texec cat /tmp/usr1.log)" = "USR1"' 10 1
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
|
||||
nm=$1
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
getpid()
|
||||
{
|
||||
initctl status "$1" |awk '/PID :/{ print $3; }'
|
||||
}
|
||||
|
||||
pid=$(getpid "$nm")
|
||||
if [ -f oldpid ]; then
|
||||
oldpid=$(cat oldpid)
|
||||
if [ "$oldpid" = "$pid" ]; then
|
||||
echo "Looks bad, wait for it ..."
|
||||
sleep 3
|
||||
pid=$(getpid "$nm")
|
||||
if [ "$oldpid" = "$pid" ]; then
|
||||
echo "Finit did not deregister old PID $oldpid vs $pid"
|
||||
initctl status "$nm"
|
||||
ps
|
||||
echo "Reloading finit ..."
|
||||
initctl reload
|
||||
sleep 1
|
||||
initctl status "$nm"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$pid" -le 1 ]; then
|
||||
sleep 3
|
||||
pid=$(getpid "$nm")
|
||||
if [ "$pid" -le 1 ]; then
|
||||
echo "Got a bad PID: $pid, aborting ..."
|
||||
ps
|
||||
sleep 1
|
||||
initctl status "$nm"
|
||||
ps
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$pid" > oldpid
|
||||
|
||||
#echo "PID $pid, kill -9 ..."
|
||||
kill -9 "$pid"
|
||||
@@ -0,0 +1 @@
|
||||
test
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
# SysV style start script for service.sh
|
||||
|
||||
DAEMON="/sbin/service.sh"
|
||||
PIDFILE="/var/run/service.pid"
|
||||
|
||||
start()
|
||||
{
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
start-stop-daemon -S -b -q -p "$PIDFILE" -x "$DAEMON"
|
||||
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
|
||||
return "$status"
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -q -p "$PIDFILE"
|
||||
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
|
||||
return "$status"
|
||||
}
|
||||
|
||||
restart()
|
||||
{
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart)
|
||||
"$1"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}, got $0 $1"
|
||||
exit 1
|
||||
esac
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user