- Increase size of resulting path buffer, unlikely a real problem
- Check return value from snprintf() to detect errors and truncation
- Add logit() function wrapper to initctl, maps to _e()/_d()/_pe()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Allows the service/task name derived from the binary to be
overridden with a custom name.
Example:
service name:dhcpd [2] /usr/sbin/udhcpd -f -- DHCP Server
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
When a process, that has been sent SIGTERM by us, takes a full 3 sec to
terminate, the event loop may have both the SIGCHLD event (where we do
the svc_del()) and the 3 sec timeout event to send SIGKILL in its event
cache.
When we call svc_del() it releases the svc_t memory, which can then be
dereferenced by the SIGKILL timer callback and we're doomed.
There are two fixes to this; 1) the event loop, that uses epoll_wait(),
can set maxevents=1 (instead of today's 10). The kernel will then drop
the SIGKILL timer event before it's delivered to the userspace process.
2) we can postpone deleting the svc_t to a "later stage" when all events
in the event cache have been processed.
This patch implements (2). A later patch will use uev_init1(ctx, 1) to
ensure the event cache handles only one event at a time.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Do not restart a inetd service if the listening interface is changed.
Only bring down established connection which are no longer allowed,
i.e. do not touch already allowed established connections.
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
This is the first patch in a series to add support for
log:/path/to/logfile,priority:facility.level,tag:ident
In this patch support for 'priority:' and 'tag:', log file support
coming later.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch adds support for creating, and removing, a PID file for
programs (services) that for some reason does not create one. With
Finit this is very useful since it allows us to use our condition
support even for "broken" daemons.
To enable this for a service, use the following syntax:
service pid[:[/path/to/]file[.pid]] /path/to/daemon
I.e., `pid` is a required argument if you want to enable the feature,
but the rest is optional:
pid --> /run/`basename $CMD`.pid
pid:file --> /run/file.pid
pid:file.dip --> /run/file.dip
pid:/mnt/k --> /mnt/k.pid
pid:/mnt/k.foo --> /mnt/k.foo
There is an additional feature with this patch. For daemons that run
with a different identiy one usually wants to create the PID file with
that identity, e.g.:
service inadyn -I dyn -- Dyn.com DDNS client
service inadyn -I freedns -- FreeDNS DDNS client
Here inadyn will look for /etc/dyn.conf and create /run/dyn.pid, and
/etc/freedns.conf and create /run/freedns.pid, respetively. While Finit
will in both cases assume the PID file is /run/inadyn.pid ... err fail!
To get out of this mess the `pid` argument can be used to tell Finit
what the real PID file the daemon creates is called:
service pid:!dyn inadyn -I dyn -- Dyn.com DDNS client
service pid:!freedns inadyn -I freedns -- FreeDNS DDNS client
The same composition rules listed above applies also to the `!` variant.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The service_step() function may call svc_del() on an svc from the
service_monitor(), so we need a way to tell the latter that it no
longer can dereference the pointer.
This regression is limited to v3.1, due to the introduction of the
new non-shared-memory store of svc_t.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
In f3669c7 the difference between static and dynamic services was
removed. This led to a regression in handling internally created
services for, e.g., dbus-daemon and udevd, mentioned in issue #90.
This patch introduces a "protected" flag for svc_t to prevent the
mark-and-sweep handling of regularly loaded services.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Until now Finit has used mtime to determine if a file has been changed,
or simply touched to request reload, when `initctl reload` is called.
Using mtime for this purpose is a monumentally bad idea since time can
be changed at any point: a user may adjust the time, NTP continously
tunes the clock, and time stamps are stored as the walltime. So if we
compare timestamps against the last time we (booted or) did reload, we
would miss .conf file changes.
This patch replaces the mtime mistake with an inotify watcher for the
following files: /etc/finit.d/*.conf, /etc/finit.d/available/*.conf,
and /etc/finit.conf. All file changes between (bootstraps and) calls
to `initctl reload` are tracked, like the mtime backend it replaces.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This is a prelude to a major behavioral change. The difference between
a static and dynamic service will be removed in Finit v3.1. This means
all .conf files, including /etc/finit.conf, will be re-read on reload.
However, not all configuration directives will be re-read, some will
only be applicable at bootstrap, i.e. runlevel S.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This change removes a long standing kernel requirement and architectural
mishap in the design of Finit v1. It is no longer necessary to include
CONFIG_SYSVIPC in the kernel to use Finit and its command line tool
initctl. It is also no longer possible to connect to the internals of
PID 1 using shmat(), the initctl tool has already been updated to use
the domain socket API.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch adds a 'once' counter to the svc_t for run/task jobs. This
counter is incremented when Finit calls service_start() and is reset on
runlevel changes.
Also, at the end of a runlevel each run/task have their state reset to
SVC_HALTED_STATE so they can be launched again for the new runlevel, if
so declared.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch extends the existing rlimit implementation to support setting
limits per service, run/task, inetd, and tty.
Use rlimit in /etc/finit.conf to change the global setting, which is
then inherited to each /etc/finit.d/*.conf. For each .conf file the
rlimit is reinitialized to the global finit.conf settings.
Also, add `unlimited` keyword, to replace the now deprecated `infinity`
keyword. The latter is however kept, for compatibility with previous
releases, for the foreseeable future.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().
This patch fixes a problem in condition parsing for very long
PID filenames which might be truncated in internal buffers
causing a mismatch in Finit condition tracking.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch extends the capabilities of task and run .conf stanzas by
enabling pipes and redirects.
Example:
task [s] echo "foo" | cat >/tmp/bar
run [s] echo "$HOME" >/tmp/secret
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The generic term for a non-running service is blocked, but a service may
be blocked for several different reasons. When a user stops a service
with `initctl stop` the intuitive expected output from `initctl show` is
"stopped" not "blocked".
When the user later restarts the service with `initctl start` it may of
course be blocked due to wrong runlevel or a missing condition. As can
be expected from the service's configuration.
The rest of the patch refactors the internal API names a bit to reflect
this change.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>