Commit Graph
104 Commits
Author SHA1 Message Date
Mattias Walström a95df9d64b svc: The timestamp should have subsecond resolution
When finit completes quicker than one second it will
not find if any configurations has been changed.

Signed-off-by: Mattias Walström <mattias.walstrom@westermo.se>
2017-01-11 16:28:03 +01:00
Joachim Nilsson f95cd38ddb Refactor #ifndef INETD_DISABLED --> #ifdef INETD_ENABLED
This patch changes the confusing logic in all #ifndef INETD_DISABLED
statements to instead be #ifdef INETD_ENABLED, which is quite a bit
more readable.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-30 13:34:31 +01:00
Joachim Nilsson 8def97a465 Add missing ctype.h header for whitespace stripper
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-08 01:37:56 +01:00
Joachim Nilsson 7bbc0847b1 Unblock udp/wait parent inetd service on child exit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-07 23:31:54 +01:00
Joachim Nilsson 88dc3f0061 Strip leading whitespace from service -- description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-07 22:09:51 +01:00
Joachim Nilsson 02e69932ae Fix inetd regression introduced in 10b72f1
This patch allows all services to go from READY -> RUNNING, this to
prevent started inetd connections from being treated as "stubborn"
and inadvertently killing them off after a few seconds.

The same actually applies to run/task applications.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-07 21:51:54 +01:00
Joachim Nilsson 829ff0b9f7 Fix #51: Catching SIGSEGV not needed anymore
This patch fixes issue #51 by reverting b4b63d3, which is not needed
anymore since service callbacks have been removed from Finit3.

The `sig_unblock()` function, called for each forked off child, should
now be balanced with caught signals.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-27 17:28:15 +01:00
Joachim Nilsson 4a71f19c40 Code cleanup and improved svc abstraction
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-01 16:00:20 +01:00
Joachim Nilsson e38eb7cbd5 Minor: relocate code to get rid of #ifdefs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:25:58 +02:00
Joachim Nilsson c3b7530b98 Reenable terse mode at shutdown/reboot
Now that we change runlevel at shutdown/reboot, we also need to restore
terse mode before calling the shutdown hooks, like before.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:02:18 +02:00
Joachim Nilsson 5fc3a0a3b9 Move HOOK_SHUTDOWN so it runs right before runlevel change
The shutdown hook is supposed to run right before services start
receiving SIGTERM.  Change due to previous refactor.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-16 23:06:17 +02:00
Joachim Nilsson 5cc98f6e53 inetd: List service/proto in error message
Improve error when failing to register an inetd service.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-26 21:41:28 +02:00
Joachim Nilsson 7ab963a576 Remove eXecutable flag from source files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 23:00:06 +02:00
Joachim Nilsson 51830e0f5b Merge branch 'usr/wkz/timeout' of https://github.com/westermo/finit into westermo-usr/wkz/timeout 2016-09-13 21:53:26 +02:00
Joachim Nilsson 5a3397419f Remove support for service callback plugins
This patch removes the now heavily outdated (and non-working) support
for callback plugins.  I.e. plugins that attach themselves to services
listed in /etc/finit.conf and can be queried to determine if a service
should be started or stopped.

The Finit3 support for adding/removing services at runtime with plain
text *.conf files in /etc/finit.d and `initctl reload`, this old, and
rather cumbersome service callback feature, is not longer supported.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 21:20:06 +02:00
Tobias Waldekranz 10b72f1d7f service: kill stubborn services, wait before restart
Add support for registering callbacks to be called after a given
timeout.

Use this to implement forceful termination of services that refuse to
terminate upon receiving a SIGTERM. If the service PID is not collected
within 3 seconds, send a SIGKILL to it.

Also, rework restarting of crashing services. When a service crashes for
the first time, try to restart it immediately. If it crashes again, wait
a few seconds before trying again. Just as before, if it continues to
crash, block the service.
2016-09-13 20:26:28 +02:00
Joachim Nilsson 6b237b7b00 Refactor abstraction of svc blocking state
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-12 19:30:48 +02:00
Joachim Nilsson 4b4572de4d Minor refactor of error/debug messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-08 17:11:27 +02:00
Joachim Nilsson 2e7bee9f84 Fix #36: Don't delete inetd on failed registration
This patch fixes to root cause to issue #36, reported by Markus Svilans.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:22:50 +02:00
Joachim Nilsson 88d8ab67c9 Add _w() for developer warning logs
Adjust debug levels slightly and add _w() macro for LOG_WARNING,
useful when having /dev/kmsg as backend.  The latter outputs any
log <= LOG_ERR to console as well.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:15:41 +02:00
Markus Svilans 308ae609c4 Fix #35: Build fails with --disable-inetd
This patch fixes a build problem when configured without inetd support.

Signed-off-by: Markus Svilans <msvilans@aeonyx.ca>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-31 16:30:04 +02:00
Joachim Nilsson d670e7d3e8 Clean up logging, log to stderr until syslogd has started
This patch removes internal logging macros and adds support for logging
to stderr until a syslogd is up and running, i.e. /dev/log appears.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-18 01:18:31 +02:00
Joachim Nilsson 5bab329178 UTMP: Only account for getty processes
This patch removes accounting for all processes to instead implement the
traditional SysV getty accounting.  (Telnet/SSH et al maintain their own
accounding for UTMP.)

TODO: WTMP support

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-17 18:43:49 +02:00
Joachim Nilsson 2718c709aa UTMP: Add support for INIT_PROCESS & DEAD_PROCESS
Services started by Finit are now properly accounted for in UTMP.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 00:58:00 +02:00
Joachim Nilsson 57514130fc Starting service as @user chdir() to their $HOME
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:39 +02:00
Joachim Nilsson 2216923343 Minor whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 11:43:09 +02:00
Joachim Nilsson ac834cfa1c I am the reaper of lost children ...
... but let's keep it quiet, OK?

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 01:16:51 +02:00
Joachim Nilsson a7e52914d2 Set a default description for all services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 00:08:56 +02:00
Joachim Nilsson fcfbd57ca8 With 'log' keyword, always log process name
Do not tag log messages with service description, but use process name.
Possibly add :ID later to denote instance if multiple instances exist.

Also, add priority daemon.info log level.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 19:59:27 +02:00
Joachim Nilsson 7b00969f6c Merge remote-tracking branch 'origin/inetd-plugins'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 20:25:36 +02:00
Joachim Nilsson 7dfdc2395b Add protection against UDP inetd looping attacks
This patch adds protection against a common inetd attack vector wherein
the reply port to UDP inetd services is forged to an internal inetd
service port.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 17:27:37 +02:00
Joachim Nilsson 2b74fb0e93 Minor cleanup and corrections for new terminology
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 15:51:57 +02:00
Joachim Nilsson 88a4ebf9e7 Use <> instead of "" for external header includes
Libraries and system headers should be included with <> instead of "".
This makes a great difference for the automatic dependency tracking.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 15:32:36 +02:00
Joachim Nilsson 33ccff7733 Audit ad2bafb: cleanup of stale pid files
Make sure to check return value of remove(), it may actually signal
something useful.  Log useful errors.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:46:25 +02:00
Joachim Nilsson 00e5a8f5d9 Audit ec25051: service logging support
- Must check return value from open(), found by Coverity Scan
- Minor refactor (and cleanup) to reduce code complexity

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:38:46 +02:00
Joachim Nilsson cc15d3f77b Merge branch 'finit-sm' of https://github.com/westermo/finit into westermo-finit-sm
Hand merged conflicts in the following files:
	Makefile
	finit.h
	service.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 19:48:08 +02:00
Jonas Johansson ad2bafbfe8 services: remove .pid file for (careless) died processes
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-20 09:08:38 +02:00
Jonas Johansson c5fad8e659 services: do not start services before all stopped processes has been halted
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-19 14:46:59 +02:00
Jonas Johansson 29315090f9 sm: handle reload event
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-18 10:40:01 +02:00
Jonas Johansson 60df2043ac sm: handle runlevel change
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-18 10:18:40 +02:00
Jonas Johansson 364f3bbafb finit: add finit state machine
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-16 15:17:02 +02:00
Joachim Nilsson 110ee220e7 Merge pull request #29 from westermo/wmo/2.4
Allow debugging of inetd service's arguments
2016-04-26 11:04:47 +02:00
Joachim Nilsson f29dff691f Allow debugging of inetd service's arguments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 11:02:32 +02:00
Joachim Nilsson a1e6febc4f Merge pull request #28 from westermo/wmo/2.4
Westermo fixes for services changing type at runtime

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:38:41 +02:00
Joachim Nilsson df1fbbc996 Handle type change from inetd to service
When a service changes type from inetd to a regular daemon we must make
sure to first deregister the currently running inetd service properly.

Example: a system boots up with httpd.conf as an inetd service, so Finit
   opens a socket 0.0.0.0:80 pending connections to start `httpd -i`.
   After a while a user changes httpd.conf to be a regular service and
   calls `initctl reload`.  Without this patch the socket will remain
   open and prevent httpd from opening and binding to the same port.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:30:00 +02:00
Patrick Stewart 0ba8df5c2d Change stdin member of svc to stdin_fd
'stdin' is a macro in stdio.h, so it shouldn't be used as a member name. GLIBC happens to have "#define stdin stdin", but other libcs don't.
2016-04-13 22:09:05 +01:00
Patrick Stewart ec2505191b Add service logging
Adds an extra 'log' parameter to services that routes STDOUT and STDERR to syslog.
Uses a PTY rather than a pipe, as this prevents log messages hanging around in a buffer indefinitely.
2016-04-13 22:09:05 +01:00
Patrick Stewart 3de9e4e5db Fix potential race condition/hang for SVC_TYPE_RUN services
In service_start() the SIGCHLD handler is reenabled before calling complete(), so the service could be reaped by the SIGCHLD handler leaving service_start() waiting forever
Also remove code that duplicates sig_unblock()
2016-04-13 22:09:05 +01:00
Joachim Nilsson 1f1c2e0466 Replace verbose and kernel quiet modes with silent and quiet
This patch replaces the verbose and kernel-quiet runtime options with
a (hopefully) more useful quiet and silent modes of operation.

By default Finit progressively shows all services it starts at boot, but
when boot has completed and services are started/restarted Finit prints
nothing.  If `--disable-quiet` is given all started/restared/stoppping
messages are shown even after boot.

However, if `--enable-silent` is given Finit is completely silent even
at boot, no progress is shown, until the first service is started, which
on most systems is login.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 00:50:37 +02:00
Joachim Nilsson 4efdc4fe19 Merge pull request #25 from westermo/wmo/2.4
Westermo fixes to Finit3
2016-04-10 20:08:25 +02:00