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>
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>
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>
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>
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>
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>
`--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>
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>
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>
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>
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>
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>
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>