1952 Commits
Author SHA1 Message Date
Joachim Nilsson 8379b4927b Fix GCC truncation warnings, too small buffers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
3.2-rc2
2020-04-12 00:33:52 +02:00
Joachim Nilsson 6a7f48970c Add cgreaper.sh to dist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-12 00:29:39 +02:00
Joachim Nilsson d797754ca8 Update ChangeLog and bump version for v3.2-rc2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 23:54:26 +02:00
Joachim Nilsson 770a79fa89 Fix #120: Redirect stdin to /dev/null for services by default
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 22:24:33 +02:00
Joachim Nilsson ff24ee3553 Fix #124: reap all children in same process group of dying parent
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 21:55:40 +02:00
Joachim Nilsson 25c194ef93 Create unique service cgroup based on name:id
We want to have unique cgroups per instance.  I.e., a DHCP client for
eth0 should have its own cgroup separate from a DHCP client for eth1.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 21:50:38 +02:00
Joachim Nilsson 91a9c83928 Send signal to every process in the same process group
When stopping a run/task/service we must send SIGTERM/KILL to all every
process in the same process group.  Otherwise we may end up with stray
processes like 'logit' when log redirection is enabled.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-08 18:00:48 +02:00
Joachim Nilsson 9b022ed7a4 Create FUNDING.yml 2020-04-04 13:56:36 +02:00
Joachim Nilsson ca3fc057f2 configure: Change semantics of 33bb6ed, logit enabled by default
The logit tool is not just used by scripts and such, when logger is
absent.  It is also used by Finit internally to redirect logging of
services to syslog and/or log file, with log rotation.

This patch reverts the default to enabled.  Someone explicitly has
to disable logit now to get less functionality.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-30 11:56:39 +02:00
Joachim Nilsson bf6e599584 Handle log redirect to syslog when logit is disabled
`--disable-logit` at configure time means redirecting stdout from a
service to a file is completely disabled.  Fallback to `logger` can
not be guaranteed to provide log file rotation, so all logs will be
sent to syslog instead.  In case logger is also missing, a simple
redirect using fork() + syslog() is used as fallback.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-30 11:53:43 +02:00
Joachim Nilsson 89c7171223 Refactor run/task/service stdout redirection after setsid() addition
This patch refactors redirect_null() and adds support for redirecting
stdout to console when 'log:console' is enabled.  This was previously
sort of the default, but with the addition of the long-sought-after
setsid() call we needed to change things.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-30 10:11:29 +02:00
Joachim Nilsson c41f3f4a06 Call setsid() by default to detach from controlling terminal
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-29 17:39:35 +02:00
Yaroslav Syrytsia 0a54a9624a Fix #123: Regression in sysv start/stop scripts
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-26 05:16:52 +01:00
Joachim Nilsson 1e238eec61 Increase MAX number of arguments to a service 32 -> 64
Usually a wrapper script is recommended, but for some use-cases it
is more efficient to just be able to use more command line args.

Example application that needs this; udhcpc

Note, we should refactor this to use a dynamically allocated array
instead of this static one.  We relied heavily on static arrays in
Finit 1, when everything had to fit i shm.  This is just legacy.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-19 07:50:36 +01:00
Joachim Nilsson 4163527006 Fix run-parts regression introduced in 9a98bff2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-09 14:29:04 +01:00
Joachim Nilsson f06e17ccc6 initctl: Widen status column a bit to fit 'stopping' state
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-05 17:51:52 +01:00
Joachim Nilsson fe41b9c4b8 Revert "plugins: pidfile: Simplify and clean up developer debug messages"
This reverts commit 69016bb8f5.
2020-03-02 07:22:15 +01:00
Joachim Nilsson 7cf3ef80db Revert "Travic-CI: Disable clang temporarily for Coverity run"
This reverts commit 27c839bc92.
2020-02-29 17:10:28 +01:00
Joachim Nilsson 69016bb8f5 plugins: pidfile: Simplify and clean up developer debug messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 17:04:27 +01:00
Joachim Nilsson f7d5b588c9 plugins: pidfile: Factor out directory handling from callback
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:52:51 +01:00
Joachim Nilsson 0ad99ce054 Fix use-after-close in service.c:redirect(), found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:42:53 +01:00
Joachim Nilsson 1176961e7b plugins: pidfile: Fix memory leak in pidfile_callback()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:40:06 +01:00
Joachim Nilsson 27c839bc92 Travic-CI: Disable clang temporarily for Coverity run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:32:05 +01:00
Joachim Nilsson 6149e93aca docs: Update documentation on svc conditions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 17:16:24 +01:00
Joachim Nilsson 4e7baa807e Fix #109: Declare PID file path to dbus-daemon in dbus plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 16:50:57 +01:00
Joachim Nilsson 54cfa74042 Fix #109: Support PID files in subdirectories to /var/run
Services, like dbus and teamd for instance, may create their PID files
in a subdirectory of /var/run (today often /run). E.g.,

   - /var/run/teamd/a1.pid    -- For aggregate A1
   - /var/run/dbus/pid
   - /var/run/lxc/foo.pid     -- For container foo

This patch adds support for dynamically adding inotify watchers to any
new subdirectory created in /var/run (discarding too deep directories).

To match services in this directory the run/task/service/sysv stanza
must contain the pid:!/path/to/pidfile.pid syntax.  This pid file name
is also used to create the condition this service asserts using the
following formula:

   svc/ + <dirname of service> + <subdir and file without .pid>

E.g., the case of teamd (above) gives condition 'svc/usr/bin/teamd/a1'

The special case of dbus is interesting, since it may not be a special
case, but rather the norm for services using a subdirectory.  It is
handled as follows; when a new subdirectory is detected, the directory
is scanned for files matching *.pid.  Matching files follow the teamd
case.  The directory is also scanned for 'pid', which then gives us the
condition 'svc/usr/bin/dbus'

One last example, illustrated by lxc-start, where we want to track the
condition for the LXC container foo.  The service stanza:

   service pid:!/run/lxc/foo.pid lxc-start -n foo -F -p /run/lxc/foo.pid -- Container foo

This command has no leading path so the condition is composed entirely
from the PID file location:

   svc/  + '' + lxc/foo => svc/lxc/foo

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 16:39:53 +01:00
Joachim Nilsson 97ce0aa519 Rename local variable shadowing variable in outer scope
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 14:36:14 +01:00
Joachim Nilsson e72b61c9c9 Minor, fix dead EeePC fastinit link and adjust distro ordering
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-27 23:08:20 +01:00
Joachim Nilsson b66069278f Support for a custom kill:DELAY, default 3 sec
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 18:49:47 +01:00
Joachim Nilsson 1192506d43 Support for custom halt:signal, default SIGTERM
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 18:28:02 +01:00
Joachim Nilsson decdc1560a Support for monitoring forking services/sysv daemons
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 14:10:47 +01:00
Joachim Nilsson f6372de6a9 New function pid_file_read(), returns PID from a pid file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:40:44 +01:00
Joachim Nilsson 9052248127 Check for an actual /proc file, not directory, in pid_alive()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:40:18 +01:00
Joachim Nilsson 6ab9c8fad6 Allow services to be started without absolute path, trust $PATH
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:39:17 +01:00
Joachim Nilsson 619bd03551 Drop old comment related to service plugins (now removed)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:38:50 +01:00
Joachim Nilsson e301877b16 Follow-up to 12d14aa, configurable auto-reload of .conf files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:13:06 +01:00
Joachim Nilsson 3b67afe480 Change semantics for SysV start/stop scripts
If a start/stop script returns OK we classify it as 'started' and leave
it in running state, despite having collected its PID.  This way we can
track what scripts need to be called with 'stop' when changing to a
runlevel they are not declared for.

Also, clean up related debug messages from earlier commit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:35:15 +01:00
Joachim Nilsson 9a9a9f4bfe Remove old blocking (!) waitpid() call in service_start()
Remnant from when processes were collected in service_start(), now all
handled by service_monitor() from SIGCHLD and service_step().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:32:04 +01:00
Joachim Nilsson f38299bfca Redirect stdout/stderr according to .conf when stopping SysV service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:31:21 +01:00
Joachim Nilsson 99901782ff Factor out stdout/stderr redirection to from service_start()
This new function can then be used also by service_stop(), e.g. for SysV
start/stop scripts.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:30:00 +01:00
Joachim Nilsson 912a336997 Only show [ OK ] startup/status if run tasks exit normally
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 07:52:36 +01:00
Joachim Nilsson c3eca9fe8f Save process exit status to svc_t
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 07:23:06 +01:00
Joachim Nilsson 225510a270 Remove gratuitous newline when finit stops its own log service
This patch fixes an annoying thing when typing reboot/shutdown/poweroff
that caused an extra newline to be printed before displaying services
stopping.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-30 18:29:45 +01:00
Joachim Nilsson 4389fbd8bc Merge pull request #122 from jackuess/fix-inaccurate-sleep
Switch to using nanosleep in favour of sleep
2020-01-30 18:01:46 +01:00
Jacques de Laval 920382518f Switch to using nanosleep in favour of sleep
The remaining sleep time returned by sleep is not accurate enough to be
used as a means to achieve "signal safe"-sleep. nanosleep can be used
in similar fashion instead and is granular enough for our purposes.

This issue was identified during reboot, when Finit is bombarded with
SIGCHLD, aborting the sleep that we do to give daemons a chance to shut
down gracefully. The total delay ended up being less than a second when
in fact two seconds were the intended delay.
2020-01-30 15:39:46 +01:00
Joachim Nilsson 997a699b7e Add more debug logs for /etc/finit.d*/ inotify and exec_runtask()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-22 15:48:56 +01:00
Joachim Nilsson 21db27ee75 Minor, coding style cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-22 15:48:42 +01:00
Joachim Nilsson fa0c63070c Add support for starting/stopping SysV init scripts
This patch adds initial support for starting a SysV init script in a
runlevel, and stopping it when leaving a runlevel.

    sysv [LVLS] <COND> /path/to/script.sh -- Optional Description

The SysV /etc/inittab file, which may use /etc/init.d, or /etc/rcN.d,
is still not supported.  A separate plugin would be required for this,
see the documentation for more information.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-22 15:45:08 +01:00
Joachim Nilsson 9bfc9092b8 Document new mdules-load and modprobe plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-15 22:53:24 +01:00
Joachim Nilsson 1c6464a7a8 Add support for cold plugging devices, auto-loading of modules
This patch adds a new plugin to Finit called modprobe.  It probes in
/sys/devices after modalias files and then calls 'modprobe -ab' for
each alias listed.

For hot-plugging we recommend adding the following to /etc/mdev.conf

  $MODALIAS=.*	root:root	0660	@modprobe -b "$MODALIAS"

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-12 20:00:47 +01:00