Compare commits

..
24 Commits
Author SHA1 Message Date
Joachim Nilsson 9d9b6b5201 Update ChangeLog and bump version for v3.2-rc3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 18:06:25 +02:00
Joachim Nilsson c0b74c5e53 Fix minor build warning for --disable-inetd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 18:06:25 +02:00
Joachim Nilsson 88a6864fd4 Relocate docs/ --> doc/, like most other projects have
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 17:53:36 +02:00
Joachim Nilsson 2b2c6aaf4e docs: Relocate GitHub specific files to .github/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 17:46:22 +02:00
Joachim Nilsson 8ed37f5fa0 Always append /ID to cond if run/task/service is declared with :ID
This patch is a follow-up to the idea introduced in 1d6737e, but this
time we make sure to always append the svc ID to conditions if their
.conf has been declared with :ID

Meaning, the following .conf:

    service :0 /sbin/teamd --config-file /etc/teamd-lag0.conf
    service :1 /sbin/teamd --config-file /etc/teamd-lag0.conf

results in the following two conditions:

    svc/sbin/teamd/0
    svc/sbin/teamd/1

With a custom 'name:foo':

    service name:lag :0 /sbin/teamd
    service name:lag :1 /sbin/teamd

the resulting conditions look even prettier:

    svc/lag/0
    svc/lag/1

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:22:29 +02:00
Joachim Nilsson 8fe4aad53e Make run/task/service :ID optional, default to zero/NULL
This patch makes the ':ID' field optional when registering non-inetd
run/taks/service etc.  It has always been optional in the .conf files,
but internally we defaulted to ':1'.

To open up for more useful conditions we now default to zero/NULL :ID,
meaning the user now *must* keep track of the :ID field if they have
multiple services with the same name.  This should already have been
an issue since such services would likely have conflicted with their
PID files (same name).  So it's unlikely to affect any user severely.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:21:28 +02:00
Joachim Nilsson 54e5fd2a78 initctl: Show :ID in process listing(s) only if non-zero
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:14:09 +02:00
Joachim Nilsson 1d6737eac1 Custom conditions include :ID; 'name:foo :bar' => svc/foo/bar
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 09:56:30 +02:00
Joachim Nilsson fa0c2f7050 Custom name:foo will now create condition svc/foo w/o path
When registering a service there is the option to set a custom PID file,
and even tell Finit to maintain that PID file in case the daemon doesn't

Until now there hasn't been a way to create custom conditions though ...

This patch leverages the new 'name:foo' argument to tas/run/services to
trigger condition 'svc/foo' (notice lack of path!) when a custom name is
set and either the default, or the custom, PID file is created.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 08:57:12 +02:00
Joachim Nilsson 70c0a38307 Provide description to built-in watchdog daemon
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 23:00:21 +02:00
Joachim Nilsson 217df432d6 Add support for 'console' as compat alias to '@console'
This patch makes it possible to declare tty's using the magic keyword 'console',
an alias for the already existing '@console' keyword, which automatically detect
valid console(s) from the console=foo kernel command line.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 22:35:32 +02:00
Joachim Nilsson cfa97253be Fix missing signal.h, required when building for uClibc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 22:34:19 +02:00
Joachim Nilsson 6462bac249 finit: /run: Follow-up to 7c8b0df7, use MS_ mount flags instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:28:48 +02:00
Joachim Nilsson b0a1d6bd61 Fix warning message when service doesn't exist: !. -> .
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson ee4768ba53 contrib: Let tty1 be available in runlevel 1 on Void and Alpine
The default runlevels are otherwise 2-5.  Usually, however, when
debugging a system you may want to have runlevel 1 (single user
level) available to log in.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson c7c0c723d6 Update TTY speed recommendations in README.md and Debian defaults
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson b7c1a2a198 Change tty default baud rate: 38400 -> 0, i.e. keep kernel default
This is a more sane default, and also what systems expect, and what
other getty implementations support.  I.e., unless specified, or set
to 0, the tty baud rate is zero -- which means do not change speed
at all.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson af45166814 src: Add critical debug messages for debugging condition handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson 1a881389b2 plugins: pidfile: Handle conditions for PID files in sub-directories
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson 6306c757a2 src: svc: Use realpath() to check if untangled file exists
The svc_find_by_pidfile() function may be called with "/run/./foo.pid",
or similar, which must be sanitized before being compared to the PID
file of each svc_t.

This patch introduce realpath() to untangle the paths and check if the
file actually exists.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson 3865ce765e src: svc: Handle case where multiple services have same PID file
Services may exist in multiple runlevels, i.e. one behavior at bootstrap
and another at runtime.  If the user does not set a specific PID file to
be used as condition finit can match the wrong svc.

This patch extends svc_find_by_pidfile() to also compare the contents of
the PID file with the PID of the registered svc_t.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson aa08221666 configure: Remove --enable-rw-rootfs detect using /etc/fstab instead
This patch removes the --enable-rw-rootfs build flag.  Like OpenRC we
now check /etc/fstab instad; if `/` is listed *and* doesn't have the
`ro` flag set, we remount / read-write.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 20:08:52 +02:00
Joachim Nilsson 7c8b0df720 finit: /run: Mount with nosuid,nodev,noexec for added security
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-15 19:28:23 +02:00
Joachim Nilsson cb802cd54e finit: devpts: Mount with recommended ptmxmode=0666
For details https://www.kernel.org/doc/Documentation/filesystems/devpts.txt

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-15 19:28:13 +02:00
36 changed files with 210 additions and 125 deletions
@@ -76,4 +76,4 @@ Bill & Ted; [be excellent to each other][conduct].
[github]: https://github.com/troglobit/finit/
[KNF]: https://en.wikipedia.org/wiki/Kernel_Normal_Form
[gitbook]: https://git-scm.com/book/ch5-2.html
[conduct]: https://github.com/troglobit/finit/blob/master/CODE-OF-CONDUCT.md
[conduct]: CODE-OF-CONDUCT.md
+18 -3
View File
@@ -20,7 +20,7 @@ Bug fix release, but also cgroups and a new progress!
* Support for tracking custom PID files, using `pid:!/path/to/foo.pid`,
useful with new `sysv` or `service` which fork to background
* Support starting run/task/services without absolute path, trust `$PATH`
* Add support for `--disable-docs` and `--disable-contrib` to speed up
* Add support for `--disable-doc` and `--disable-contrib` to speed up
builds and work around issue with massively parallel builds
* Add support for `@console` also for external getty
* Add `-b`, batch mode, for non-interactive use to `initctl`
@@ -58,6 +58,19 @@ Bug fix release, but also cgroups and a new progress!
can be enabled with `./configure --enable-auto-reload`
* Support for logging security related events, e.g., runlevel change,
star/stop or failure to start services, by Jonas Holmberg, Westermo
* Mount devtpts with recommended `ptxmode=0666`
* Mount /run tmpfs with nosuid,nodev,noexec for added security
* Support for `console` as alias for `@console` in tty stanzas
* Drop `--enable-rw-roots` configure option, use `rw` for your `/`
partition in `/etc/fstab` instead to trigger remount at boot
* Drop default tty speed (38400) and use 0 (kernel default) instead
* Make `:ID` optional for real, use NULL/zero internally and only
force :ID (numbered) for inetd services, this allows ...
* Handle use-cases where multiple services share the same PID filem
and thus the same condition path, e.g. different instances for
different runlevels. Allow custom condition path with `name:foo`
syntax, creates conditions w/o a path, and ...
* Always append `:ID` qualifier to conditions if set for a service
### Fixes
@@ -109,6 +122,8 @@ Bug fix release, but also cgroups and a new progress!
* Restore Ctrl-D and Ctrl-U support in built-in getty
* Remove service condition when service is deleted
* Fix C++ compilation issues, by Robert Andersson, Atlas Copco
* Build fixes for uClibc
* Provide service description for built-in watchdog daemon
[3.1][] - 2018-01-23
@@ -183,7 +198,7 @@ This version requires at least libuEv v2.1.0 and libite v2.0.1
possibility of running a second stage mount command before files in
`/run` and similar are created
* Skip `gdbserver` when unleashing the grim reaper at shutdown
* Distribute and install `docs/` and `contrib/` directories
* Distribute and install `doc/` and `contrib/` directories
### Fixes
@@ -246,7 +261,7 @@ distributions.
* Ensure plugins always have a default name, file name
* Reorganization, move all source files to a `src/` sub-directory
* Add support for `initctl <list|enable|disable> <SVC>`, much needed by
distributions. See [docs/distro.md](docs/distro.md) for details
distributions. See [doc/distro.md](doc/distro.md) for details
* Remove `UNUSED()` macro, mentioned here because it may have been used
by external plugin developers. Set `-Wno-unused-parameter` instead
* New table headings in `initctl`, using `top` style inverted text
+2 -2
View File
@@ -6,8 +6,8 @@ EXTRA_DIST = README.md LICENSE ChangeLog.md contrib/finit.conf
if CONTRIB
SUBDIRS += contrib
endif
if DOCS
SUBDIRS += docs
if DOC
SUBDIRS += doc
endif
# Compat hook
+30 -30
View File
@@ -3,19 +3,19 @@
* [Introduction](#introduction)
* [Features](#features)
* [Bootstrap](docs/bootstrap.md#bootstrap)
* [Bootstrap](doc/bootstrap.md#bootstrap)
* [Runlevels](#runlevels)
* [Syntax](docs/config.md#syntax)
* [Inetd](docs/inetd.md#inetd)
* [Syntax](doc/config.md#syntax)
* [Inetd](doc/inetd.md#inetd)
* [Runparts & /etc/rc.local](#runparts--etcrclocal)
* [Hooks, Callbacks & Plugins](docs/plugins.md#hooks-callbacks--plugins)
* [Hooks, Callbacks & Plugins](doc/plugins.md#hooks-callbacks--plugins)
* [Rebooting & Halting](#rebooting--halting)
* [Commands & Status](#commands--status)
* [Tips & Tricks with the kernel cmdline](docs/cmdline.md)
* [Building](docs/build.md#building)
* [Running](docs/build.md#running)
* [Recovery](docs/build.md#recovery)
* [Debugging](docs/build.md#debugging)
* [Tips & Tricks with the kernel cmdline](doc/cmdline.md)
* [Building](doc/build.md#building)
* [Running](doc/build.md#running)
* [Recovery](doc/build.md#recovery)
* [Debugging](doc/build.md#debugging)
* [Requirements](#requirements)
* [Origin & References](#origin--references)
@@ -95,21 +95,21 @@ inetd ssh/tcp@*,!eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
# Run start scripts from this directory
# runparts /etc/start.d
# Virtual consoles run BusyBox getty
tty [12345] /sbin/getty -L 115200 /dev/tty1 linux
tty [12345] /sbin/getty -L 115200 /dev/tty2 linux
tty [12345] /sbin/getty -L 115200 /dev/tty3 linux
# Virtual consoles run BusyBox getty, keep kernel default speed
tty [12345] /sbin/getty -L 0 /dev/tty1 linux
tty [12345] /sbin/getty -L 0 /dev/tty2 linux
tty [12345] /sbin/getty -L 0 /dev/tty3 linux
# Use built-in getty for serial port and USB serial
tty [12345] /dev/ttyAMA0 115200 noclear nowait
tty [12345] /dev/ttyUSB0 115200 noclear
tty [12345] /dev/ttyAMA0 noclear nowait
tty [12345] /dev/ttyUSB0 noclear
# Just give me a shell, I need to debug this embedded system!
tty [12345] @console noclear nologin
```
The `service` stanza, as well as `task`, `run`, `inetd` and others are
described in full in [docs/config.md](docs/config.md). Here's a quick
described in full in [doc/config.md](doc/config.md). Here's a quick
overview of some of the most common components needed to start a UNIX
daemon:
@@ -130,7 +130,7 @@ advanced uses as well:
service /usr/sbin/sshd -D
Dependencies are handled using [conditions](docs/conditions.md). One of
Dependencies are handled using [conditions](doc/conditions.md). One of
the most common conditions is to wait for basic networking to become
available:
@@ -171,7 +171,7 @@ Start, monitor and restart services should they fail.
**Inetd**
Finit comes with a built-in [inetd server](docs/inetd.md). No need to
Finit comes with a built-in [inetd server](doc/inetd.md). No need to
maintain a separate config file for services that you want to start on
demand.
@@ -186,7 +186,7 @@ Built-in optional inetd services:
- discard [RFC863][]
- time (rdate) [RFC868][]
For more information, see [docs/inetd.md](docs/inetd.md).
For more information, see [doc/inetd.md](doc/inetd.md).
**Getty**
@@ -197,9 +197,9 @@ waits for user input before handing over to `/bin/login`, which is
responsible for handling the actual authentication.
```conf
tty [12345] /dev/tty1 38400 nowait linux
tty [12345] /dev/ttyAMA0 115200 noclear vt100
tty [12345] /sbin/getty -L 115200 /dev/ttyAMA0 vt100
tty [12345] /dev/tty1 nowait linux
tty [12345] /dev/ttyAMA0 noclear vt100
tty [12345] /sbin/getty -L /dev/ttyAMA0 vt100
```
Users of embedded systems may want to enable automatic serial console
@@ -208,12 +208,12 @@ system uses `ttyS0`, `ttyAMA0`, `ttyMXC0`, or anything else. Finit
figures it out by querying sysfs: `/sys/class/tty/console/active`.
```conf
tty [12345] @console 115200 linux noclear
tty [12345] @console linux noclear
```
Notice the optional `noclear`, `nowait`, and `nologin` flags. The
latter is for skipping the login process entirely. For more information,
see [docs/config.md](docs/config.md#syntax).
see [doc/config.md](doc/config.md#syntax).
**Runlevels**
@@ -258,7 +258,7 @@ Extensions and functionality not purely related to what an `/sbin/init`
needs to start a system are available as a set of plugins that either
hook into the boot process or respond to various I/O.
For more information, see [docs/plugins.md](docs/plugins.md).
For more information, see [doc/plugins.md](doc/plugins.md).
**Progress**
@@ -277,7 +277,7 @@ append="init=/sbin/finit splash"
For a really nice boot, add `quiet` as well. This silences the output
from the kernel, leaving only warnings and errors. For other kernel
command line parameters, see [docs/build.md](docs/build.md#recovery).
command line parameters, see [doc/build.md](doc/build.md#recovery).
**Automatic Reload**
@@ -313,8 +313,8 @@ Right after the runlevel change when all services have started properly,
No configuration stanza in `/etc/finit.conf` is required for `rc.local`.
If it exists and is an executable shell script Finit calls it at the very
end of the boot, before calling the `HOOK_SYSTEM_UP`. See more on hooks
in [docs/plugins.md](docs/plugins.md#hooks), and about the system bootstrap
in [docs/bootstrap.md](docs/bootstrap.md).
in [doc/plugins.md](doc/plugins.md#hooks), and about the system bootstrap
in [doc/bootstrap.md](doc/bootstrap.md).
Runlevels
@@ -392,7 +392,7 @@ section.
For compatibility reasons Finit listens to the same set of signals as
BusyBox init. This is not 100% compatible with SysV init, but clearly
the more common combination for Finit. For more details, see
[docs/signals.md](docs/signals.md).
[doc/signals.md](doc/signals.md).
Finit also listens to the classic SysV init FIFO, used by `telinit`.
Support for this is implemented by the `initctl.so` plugin. Hence,
@@ -463,7 +463,7 @@ Commands:
For services *not* supporting `SIGHUP` the `<!>` notation in the .conf
file must be used to tell Finit to stop and start it on `reload` and
`runlevel` changes. If `<>` holds more [conditions](docs/conditions.md),
`runlevel` changes. If `<>` holds more [conditions](doc/conditions.md),
these will also affect how a service is maintained.
**Note:** even though it is possible to start services not belonging in
+7 -15
View File
@@ -1,4 +1,4 @@
AC_INIT(Finit, 3.2-rc2, https://github.com/troglobit/finit/issues, finit, http://troglobit.com/finit.html)
AC_INIT(Finit, 3.2-rc3, https://github.com/troglobit/finit/issues, finit, https://troglobit.com/finit.html)
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz subdir-objects])
AM_SILENT_RULES([yes])
@@ -9,7 +9,7 @@ AC_CONFIG_FILES([Makefile
contrib/alpine/Makefile contrib/alpine/finit.d/Makefile contrib/alpine/finit.d/available/Makefile
contrib/debian/Makefile contrib/debian/finit.d/Makefile contrib/debian/finit.d/available/Makefile contrib/debian/grub.d/Makefile
contrib/void/Makefile contrib/void/finit.d/Makefile contrib/void/finit.d/available/Makefile
docs/Makefile
doc/Makefile
plugins/Makefile
src/Makefile])
@@ -61,10 +61,6 @@ AC_ARG_ENABLE(auto_reload,
AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[
enable_auto_reload=no])
AC_ARG_ENABLE(rw-rootfs,
AS_HELP_STRING([--enable-rw-rootfs], [Remount / R/W at boot, usually not for embedded]),,[
enable_rw_rootfs=no])
AC_ARG_ENABLE(progress,
AS_HELP_STRING([--enable-progress], [Modern progress display at bootup]),,[
enable_progress=no])
@@ -93,9 +89,9 @@ AC_ARG_ENABLE(logrotate,
AS_HELP_STRING([--disable-logrotate], [Disable built-in rotation of /var/log/wtmp, default enabled]),,[
enable_logrotate=yes])
AC_ARG_ENABLE(docs,
AS_HELP_STRING([--disable-docs], [Disable build and install of docs section]),,[
enable_docs=yes])
AC_ARG_ENABLE(doc,
AS_HELP_STRING([--disable-doc], [Disable build and install of doc/ section]),,[
enable_doc=yes])
AC_ARG_ENABLE(contrib,
AS_HELP_STRING([--disable-contrib], [Disable build and install of contrib section]),,[
@@ -164,9 +160,6 @@ AS_IF([test "x$enable_fallback_shell" = "xyes"], [
AS_IF([test "x$enable_auto_reload" = "xyes"], [
AC_DEFINE(AUTO_RELOAD, 1, [Finit automatically does `initctl reload` on any .conf change])])
AS_IF([test "x$enable_rw_rootfs" = "xyes"], [
AC_DEFINE(REMOUNT_ROOTFS, 1, [Remount / as rw at boot])])
AS_IF([test "x$enable_progress" = "xyes"], [
AC_DEFINE(PROGRESS_STYLE, 2, [Modern bootup messages, systemd inspired])])
@@ -253,7 +246,7 @@ AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"])
AM_CONDITIONAL(INETD, [test "x$enable_inetd" = "xyes"])
AM_CONDITIONAL(WATCHDOGD, [test "x$enable_watchdog" = "xyes"])
AM_CONDITIONAL(LOGIT, [test "x$enable_logit" = "xyes"])
AM_CONDITIONAL(DOCS, [test "x$enable_docs" = "xyes"])
AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"])
AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"])
# Override default libdir, used for plugins and rescue.conf
@@ -293,7 +286,7 @@ Behavior:
Plugins...............: $plugins
Optional features:
Install docs/.........: $enable_docs
Install doc/..........: $enable_doc
Install contrib/......: $enable_contrib
Built-in inetd........: $enable_inetd
Built-in watchdogd....: $enable_watchdog
@@ -301,7 +294,6 @@ Optional features:
Scripting tool logit..: $enable_logit
Emergency shell.......: $enable_emergency_shell
Fallback shell........: $enable_fallback_shell
Remount / RW at boot..: $enable_rw_rootfs
Modern progress.......: $enable_progress
Classic progress......: $enable_progress_classic
Default console dev...: $console
+1 -1
View File
@@ -14,7 +14,7 @@ fi
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
--enable-rw-rootfs --enable-progress \
--enable-progress \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
+3 -3
View File
@@ -1,4 +1,4 @@
# Consoles to start getty on when system is up
tty /dev/tty1 noclear nowait
tty /dev/tty2 noclear nowait
tty /dev/tty3 noclear nowait
tty [12345] /dev/tty1 noclear nowait
tty [2345] /dev/tty2 noclear nowait
tty [2345] /dev/tty3 noclear nowait
+1 -1
View File
@@ -22,7 +22,7 @@ echo
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
./configure \
--enable-rw-rootfs --enable-progress \
--enable-progress \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
+3 -3
View File
@@ -1,4 +1,4 @@
# Consoles to start getty on when system is up
tty [12345] /dev/tty1 115200 vt100 noclear nowait
tty [2345] /dev/tty2 38400 linux noclear nowait
tty [2345] /dev/tty3 38400 linux noclear nowait
tty [12345] /dev/tty1 linux noclear nowait
tty [2345] /dev/tty2 linux noclear nowait
tty [2345] /dev/tty3 linux noclear nowait
+1 -1
View File
@@ -14,7 +14,7 @@ fi
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
--enable-rw-rootfs --enable-progress \
--enable-progress \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
+3 -3
View File
@@ -1,4 +1,4 @@
# Consoles to start Finit built-in getty on when system is up
tty /dev/tty1 noclear nowait
tty /dev/tty2 noclear nowait
tty /dev/tty3 noclear nowait
tty [12345] /dev/tty1 noclear nowait
tty [2345] /dev/tty2 noclear nowait
tty [2345] /dev/tty3 noclear nowait
View File
+1 -1
View File
@@ -1,4 +1,4 @@
docsdir := @docdir@/docs
docsdir := @docdir@/doc
docs_DATA = config.md conditions.md distro.md inetd.md plugins.md \
service.md signals.md svc-machine.png cmdline.md
EXTRA_DIST = $(docs_DATA)
View File
View File
+1 -1
View File
@@ -12,7 +12,7 @@ Bootstrap
9. Parse `/etc/finit.conf` and all `/etc/finit.d/*.conf` files
10. Start built-in watchdog, if enabled
11. Set hostname
12. Pivot root, or remount `/` read-write, depending on system type
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
15. Enable SysV init signals
+1 -6
View File
@@ -40,11 +40,6 @@ Below are a few of the main switches to configure:
* `--disable-inetd`: Disable the built-in inetd server.
* `--enable-rw-rootfs`: Most desktop and server systems boot with the
root file stystem read-only. With this setting Finit will remount it
as read-write early at boot so the `bootmisc.so` plugin can run.
Usually not needed on embedded systems.
* `--enable-static`: Build Finit statically. The plugins will be
built-ins (.o files) and all external libraries, except the C library
will be linked statically.
@@ -73,7 +68,7 @@ First, unpack the archive:
Then configure, build and install:
```shell
$ ./configure --enable-rw-rootfs --enable-inetd-echo-plugin \
$ ./configure --enable-inetd-echo-plugin \
--enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \
--enable-inetd-discard-plugin --enable-inetd-time-plugin \
--with-heading="Alpine Linux 3.4" --with-hostname=alpine
View File
+6 -4
View File
@@ -301,8 +301,9 @@ Syntax
`tty [LVLS] <CMD> <ARGS> [noclear] [nowait]`
The first variant of this option uses the built-in getty on the given
TTY device DEV, in the given runlevels. The DEV may be the special
keyword `@console`, which is very useful on embedded systems. Default
baud rate is `38400`.
keyword `@console`, or `console`, useful on embedded systems.
The default baud rate is 0, i.e., keep kernel default.
**Example:**
```conf
@@ -340,11 +341,12 @@ Syntax
Embedded systems may want to enable automatic `DEV` by supplying the
special `@console` device. This works regardless weather the system
uses `ttyS0`, `ttyAMA0`, `ttyMXC0`, or anything else. Finit figures
it out by querying sysfs: `/sys/class/tty/console/active`.
it out by querying sysfs: `/sys/class/tty/console/active`. The speed
can be omitted to keep the kernel default.
**Example:**
```conf
tty [12345] @console 115200 noclear vt220
tty [12345] @console noclear vt220
```
On really bare bones systems Finit offers a fallback shell, which
View File
View File
View File
View File
View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

+11 -8
View File
@@ -103,19 +103,22 @@ static int watcher_del(struct context *ctx, struct wd_entry *wde)
return 0;
}
static void update_conds(char *name, uint32_t mask)
static void update_conds(char *dir, char *name, uint32_t mask)
{
svc_t *svc;
char cond[MAX_COND_LEN];
char fn[PATH_MAX];
svc_t *svc;
_d("name: %s", name);
svc = svc_find_by_pidfile(name);
_d("Got dir: %s, name: %s, mask: %08x", dir, name, mask);
snprintf(fn, sizeof(fn), "%s/%s", dir, name);
svc = svc_find_by_pidfile(fn);
if (!svc) {
_d("pidfile: No matching svc for %s", name);
_d("pidfile: No matching svc for %s", fn);
return;
}
_d("Event %s for svc %s", name, svc->cmd);
_d("pidfile: Found svc %s for %s with pid %d", svc->name, fn, svc->pid);
mkcond(svc, cond, sizeof(cond));
if (mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) {
@@ -154,7 +157,7 @@ static void scan_for_pidfiles(struct context *ctx, char *dir, int len)
for (i = 0; i < gl.gl_pathc; i++) {
_d("scan found %s", gl.gl_pathv[i]);
update_conds(gl.gl_pathv[i], IN_CREATE);
update_conds(dir, gl.gl_pathv[i], IN_CREATE);
}
globfree(&gl);
}
@@ -246,7 +249,7 @@ static void pidfile_callback(void *arg, int fd, int events)
}
if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO))
update_conds(ev->name, ev->mask);
update_conds(wde->path, ev->name, ev->mask);
}
done:
free(buf);
+22 -4
View File
@@ -59,15 +59,21 @@ char *mkcond(svc_t *svc, char *buf, size_t len)
{
char path[256];
char *pidfile;
char *ptr;
char *ptr, *nm;
strlcpy(path, svc->cmd, sizeof(path));
ptr = rindex(path, '/');
if (ptr)
*ptr = 0;
*ptr++ = 0;
else
path[0] = 0;
/* Figure out default name used when registering service */
if (ptr)
nm = ptr;
else
nm = svc->cmd;
pidfile = pid_file(svc);
ptr = strstr(pidfile, "run");
if (ptr)
@@ -75,8 +81,14 @@ char *mkcond(svc_t *svc, char *buf, size_t len)
else
ptr = rindex(pidfile, '/');
snprintf(buf, len, "svc%s%s%s", path[0] != 0 && path[0] != '/' ? "/" : "", path, ptr);
_d("Composed condition from cmd %s (path %s) and pidfile %s => %s", svc->cmd, path, ptr, buf);
/* Custom name:foo declaration found => svc/foo instead of /svc/bin/path/pidfile-.pid */
if (strcmp(nm, svc->name)) {
snprintf(buf, len, "svc/%s", svc->name);
_d("Composed condition from svc->name %s => %s", svc->name, buf);
} else {
snprintf(buf, len, "svc%s%s%s", path[0] != 0 && path[0] != '/' ? "/" : "", path, ptr);
_d("Composed condition from cmd %s (path %s) and pidfile %s => %s", svc->cmd, path, ptr, buf);
}
/* Case: /var/run/dbus/pid */
ptr = strstr(buf, "/pid");
@@ -88,6 +100,12 @@ char *mkcond(svc_t *svc, char *buf, size_t len)
if (ptr && !strcmp(ptr, ".pid"))
*ptr = 0;
/* Always append /ID if service is declared with :ID */
if (svc->id[0]) {
strlcat(buf, "/", len);
strlcat(buf, svc->id, len);
}
_d("Creating condition => %s", buf);
return buf;
+5 -7
View File
@@ -369,15 +369,12 @@ pid_t run_getty(char *tty, char *baud, char *term, int noclear, int nowait, stru
pid = fork();
if (!pid) {
speed_t speed = B38400;
if (baud && baud[0]) {
speed = stty_parse_speed(baud);
if (B0 == speed)
logit(LOG_CRIT, "TTY %s: Invalid speed %s", tty, baud);
}
speed_t speed;
speed = stty_parse_speed(baud);
logit(LOG_INFO, "Starting built-in getty on %s, speed %u", tty, speed);
prepare_tty(tty, speed, "tty", rlimit);
if (activate_console(noclear, nowait))
_exit(getty(tty, speed, term, NULL));
}
@@ -415,6 +412,7 @@ pid_t run_getty2(char *tty, char *cmd, char *args[], int noclear, int nowait, st
dup2(fd, STDERR_FILENO);
/* Dunno speed, tell stty() to not mess with it */
logit(LOG_INFO, "Starting external getty on %s, speed %u", tty, B0);
prepare_tty(tty, B0, "getty", rlimit);
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) < 0)
+29 -9
View File
@@ -421,9 +421,9 @@ int main(int argc, char *argv[])
else if (whichp("udevadm"))
run_interactive("udevadm info --cleanup-db", "Cleaning up udev db");
/* Some systems use /dev/pts */
/* Modern systems use /dev/pts */
makedir("/dev/pts", 0755);
mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620");
mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620,ptmxmode=0666");
/*
* Some systems rely on us to both create /dev/shm and, to mount
@@ -433,14 +433,14 @@ int main(int argc, char *argv[])
*/
makedir("/dev/shm", 0755);
if (!fismnt("/dev/shm") && !ismnt("/etc/fstab", "/dev/shm"))
mount("shm", "/dev/shm", "tmpfs", 0, NULL);
mount("shm", "/dev/shm", "tmpfs", 0, "mode=0777");
/*
* New tmpfs based /run for volatile runtime data
* For details, see http://lwn.net/Articles/436012/
*/
if (fisdir("/run") && !fismnt("/run"))
mount("tmpfs", "/run", "tmpfs", MS_NODEV, "mode=0755,size=10%");
mount("tmpfs", "/run", "tmpfs", MS_NODEV | MS_NOSUID | MS_NOEXEC, "mode=0755,size=10%");
umask(022);
/* Bootstrap conditions, needed for hooks */
@@ -492,16 +492,36 @@ int main(int argc, char *argv[])
* Start bundled watchdogd as soon as possible, if enabled
*/
if (which(FINIT_LIBPATH_ "/watchdogd"))
service_register(SVC_TYPE_SERVICE, FINIT_LIBPATH_ "/watchdogd", global_rlimit, NULL);
service_register(SVC_TYPE_SERVICE, FINIT_LIBPATH_ "/watchdogd -- Finit watchdog daemon", global_rlimit, NULL);
/*
* Mount filesystems
*/
if (!rescue) {
#ifdef REMOUNT_ROOTFS
run("mount -n -o remount,rw /");
#endif
#ifdef SYSROOT
#ifndef SYSROOT
/*
* Remount / read-write if it exists in fstab is not 'ro'.
* This is what the Debian sysv initscripts does.
*/
if (setfsent()) {
struct fstab *fs;
while ((fs = getfsent())) {
if (strcmp(fs->fs_file, "/"))
continue;
if (strcmp(fs->fs_type, "ro"))
run_interactive("mount -n -o remount,rw /", "Remounting / as read-write");
break;
}
endfsent();
}
#else
/*
* XXX: Untested, in the initramfs age we should
* probably use switch_root instead.
*/
mount(SYSROOT, "/", NULL, MS_MOVE, NULL);
#endif
}
+3 -3
View File
@@ -421,9 +421,9 @@ static int show_status(char *arg)
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
char jobid[20], args[512] = "", *lvls;
// if (svc_is_unique(svc))
// snprintf(jobid, sizeof(jobid), "%d", svc->job);
// else
if (!svc->id[0])
snprintf(jobid, sizeof(jobid), "%d", svc->job);
else
snprintf(jobid, sizeof(jobid), "%d:%s", svc->job, svc->id);
printf("%-9s %8s ", jobid, svc_status(svc));
+11 -10
View File
@@ -307,7 +307,7 @@ static int service_start(svc_t *svc)
/* Don't try and start service if it doesn't exist. */
if (!whichp(svc->cmd) && !svc->inetd.cmd) {
print(1, "Service %s does not exist!", svc->cmd);
print(1, "Service %s does not exist", svc->cmd);
svc_missing(svc);
return 1;
}
@@ -827,7 +827,8 @@ static void parse_cmdline_args(svc_t *svc, char *cmd)
*
* Service conditions can be: svc/<PATH> for PID files, net/<IFNAME>/up
* and net/<IFNAME>/exists. The condition handling is further described
* docs/conditions.md.
* in doc/conditions.md, but worth mentioning here is that the condition
* name itself can be modified using the :ID and name:foo syntax.
*
* For multiple instances of the same command, e.g. multiple DHCP
* clients, the user must enter an ID, using the :ID syntax.
@@ -843,8 +844,8 @@ static void parse_cmdline_args(svc_t *svc, char *cmd)
*/
int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
{
char id_str[MAX_ID_LEN];
#ifdef INETD_ENABLED
char id_str[MAX_ID_LEN];
int forking = 0;
#endif
int levels = 0;
@@ -977,20 +978,18 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
parse_cmdline_args(svc, cmd);
goto inetd_setup;
}
if (!id) {
int n = svc_next_id_int(cmd);
if (n) {
snprintf(id_str, sizeof(id_str), "%d", n);
id = id_str;
}
/* inetd services need a unique ID, so we must always set one. */
if (!id) {
snprintf(id_str, sizeof(id_str), "%d", svc_next_id_int(cmd));
id = id_str;
}
}
recreate:
#endif
if (!id)
id = "1";
id = "";
svc = svc_find(cmd, id);
if (!svc) {
@@ -1427,11 +1426,13 @@ restart:
char name[MAX_COND_LEN];
mkcond(svc, name, sizeof(name));
_d("Reassert condition %s", name);
cond_set_path(cond_path(name), COND_ON);
}
break;
case COND_OFF:
_d("Condition for %s is off, sending SIGCONT + SIGTERM", svc->name);
kill(svc->pid, SIGCONT);
service_stop(svc);
break;
+4
View File
@@ -27,6 +27,7 @@
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
#include <termios.h>
/* B0 means; keep kernel default */
speed_t stty_parse_speed(char *baud)
{
char *ptr;
@@ -66,6 +67,9 @@ speed_t stty_parse_speed(char *baud)
{ 4000000, B4000000 },
};
if (!baud || !baud[0])
return B0;
errno = 0;
val = strtoul(baud, &ptr, 10);
if (errno || ptr == baud)
+43 -6
View File
@@ -25,6 +25,7 @@
#include <err.h>
#include <ctype.h> /* isdigit() */
#include <time.h>
#include <signal.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/time.h>
@@ -60,6 +61,7 @@ static void svc_gc(void *arg)
continue;
TAILQ_REMOVE(&gc_list, svc, link);
_d("Cleaning out %s, clearing any conditions ...", svc->name);
cond_clear(mkcond(svc, cond, sizeof(cond)));
free(svc);
}
@@ -98,7 +100,8 @@ svc_t *svc_new(char *cmd, char *id, int type)
svc->type = type;
svc->job = job;
strlcpy(svc->id, id, sizeof(svc->id));
if (id && id[0])
strlcpy(svc->id, id, sizeof(svc->id));
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
/* Default description, if missing */
@@ -376,18 +379,49 @@ svc_t *svc_find_by_nameid(char *name, char *id)
* svc_find_by_plidfile - Find an service object by its PID file
* @fn: PID file, can be absolute path or relative to /run
*
* This function is primarily used by the pidfile plugin to track the
* conditions and dependencies of services.
*
* Note, the PID file is assumed to exist so the contents can be
* compared to the the PID of a located service. There may be several
* services, in many runlevels, that use the same name for the PID file.
* So we won't know for sure until the PID is compared.
*
* Returns:
* A pointer to an &svc_t object, or %NULL if not found.
*/
svc_t *svc_find_by_pidfile(char *fn)
{
svc_t *svc, *iter = NULL;
char adjpath[strlen(fn) + 10]; /* + sizeof("/var/run/") */
char fnpath[PATH_MAX];
pid_runpath(fn, adjpath, sizeof(adjpath));
if (!realpath(adjpath, fnpath)) {
_pe("adjpath: %s, errno %d", adjpath, errno);
return NULL;
}
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
char path[MAX_ARG_LEN];
char path[PATH_MAX];
char *pidfn;
pid_t pid;
if (string_compare(pid_runpath(fn, path, sizeof(path)), pid_file(svc)))
return svc;
pidfn = pid_file(svc);
if (!pidfn || !realpath(pidfn, path)) {
if (errno != ENOENT)
_pe("pidfn: %s, errno %d", pidfn ?: "<NULL>", errno);
continue;
}
if (!string_compare(fnpath, path))
continue;
pid = pid_file_read(path);
if (svc->pid != pid)
continue;
return svc;
}
return NULL;
@@ -502,7 +536,10 @@ int svc_enabled(svc_t *svc)
return 1;
}
/* Same base service, return unique ID as an integer */
/*
* Same base service, return unique ID as an integer
* Note: intended for use with INETD services.
*/
int svc_next_id_int(char *cmd)
{
int n = 1;
@@ -519,7 +556,7 @@ int svc_next_id_int(char *cmd)
n++;
}
return 0;
return 1;
}
int svc_is_unique(svc_t *svc)
+3 -3
View File
@@ -161,7 +161,7 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
if ((!cmd && !dev) || (cmd && !dev)) {
if (args[i][0] == '[')
runlevels = line;
if (!strcmp(args[i], "@console"))
if (!strcmp(args[i], "@console") || !strcmp(args[i], "console"))
dev = args[i];
if (!strncmp(args[i], "/dev", 4))
dev = args[i];
@@ -197,7 +197,7 @@ int tty_register(char *line, struct rlimit rlimit[], char *file)
}
/* Auto-detect serial console, for embedded devices mostly */
if (!strcmp(dev, "@console")) {
if (!strcmp(dev, "@console") || !strcmp(dev, "console")) {
FILE *fp;
fp = fopen("/sys/class/tty/console/active", "r");
@@ -262,7 +262,7 @@ again:
char *arg = args[i];
/* Replace @console with actual device */
if (arg && !strcmp(arg, "@console"))
if (arg && (!strcmp(arg, "@console") || !strcmp(arg, "console")))
arg = dev;
if (arg)
entry->args[j++] = strdup(arg);