Commit Graph
668 Commits
Author SHA1 Message Date
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
Tobias Waldekranz 6d84fd010e Resource limit manipulation (setrlimit)
Add support for changing the initial hard and soft resource limits for
finit and any processes it launches.

See /etc/finit.conf section in README.md for more information.
2016-04-28 09:36:22 +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 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
Joachim Nilsson 448a9e1198 Stop inetd watcher and close socket when inetd service is removed
This patch fixes a problem with lingering inet sockets when inetd
services are removed.  When removing an inetd service we must stop
the watcher and close the socket.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:27:30 +02:00
Joachim Nilsson 80624d3ff8 Revert "Do not just mark deleted SVC free, clear memory"
We cannot clear the svc_t memory because other applications may have
connected to the same shared memory.  An application may be inspecting
the current list of services (initctl) and pulling the rug from under
them could cause some really unpredicatble results.

This reverts commit 06d1e90bac.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:23:59 +02:00
Joachim Nilsson 5ea3cc0090 Reduce max backlog in listen(): 20 --> 10
Both the original MIT Athena inetd and the GNU inetutils inetd only keep
a backlog of 10 connections in listen() for TCP sockets.  This patch
adjusts the Finit hard coded default accordingly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson 7f5f8ba09d Minor grammar: "Connection" --> "connection"
When starting an inetd service in verbose mode we print a progress
message to the console appended with "Connection".  This patch simply
changes that to append with "connection" in lower case.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson efd265c9c8 Fix "broken pipe" problem for UDP inetd services
This patch fixes several issues related to the problem of launching
UDP inetd services:

- Make sure to disable O_NONBLOCK on the socket before passing it to
  the inetd service, that's what is expected.  This goes for both UDP
  and TCP (accepted) connections -- there is no guarantee even for TCP
  sockets that they do *not* inherit the parent socket's flags.
- Mark the UDP inetd parent's SVC as busy and stop its watcher before
  starting the child task to service the connection.  The watcher must
  be stopped or multiple child tasks may be spawned!
- Only copy the most relevant parts to the UDP task.  In particular
  must *not* copy the libuEv watcher data to the task!
- With the child task done and the parent inetd service unblocked we
  must restore O_NONBLOCK to the socket before restarting the watcher

When a UDP inetd service connection is handled we create a child task
to service the request, meanwhile we block the parent service.  There
was a problem with blocking the parent since we called inetd_stop(),
which both did a shutdown() and close() of the socket ... this patch
introduces separate handling of blocked (busy) inetd services in the
inetd_stop() function and also make sure to handle restarting the
parent watcher in inetd_start() when the child task is done.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson 7e91cb4afc Minor log message improvements
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson 9a03adce5a Do not assume new fd is 0, dup2() with fd instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 10:54:31 +02:00
Joachim Nilsson 06d1e90bac Do not just mark deleted SVC free, clear memory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 10:53:20 +02:00
Joachim Nilsson 439d9df122 Set CLOEXEC flag to prevent leaking descriptors
Both the new initctl API and the new pidfile watcher plugin failed to
set CLOEXEC on their sockets.  This caused forked-off and exec()'d
children to inherit all these descriptors.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 10:52:39 +02:00
Joachim Nilsson da76cf4f75 Check return value from strtok(), may be NULL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:58:46 +02:00
Joachim Nilsson a2177a8063 Fix GCC warning for signed vs unsigned comparison
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:58:13 +02:00
Joachim Nilsson cfa155deae Minor cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:57:48 +02:00
Joachim Nilsson e7832e2ca7 FTBFS followup issue #24
Add missing return keyword to inline function svc_is_starting()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:56:13 +02:00
Joachim Nilsson 4ae5c54f45 Assert svc condition only when PID file has been created/updated
This patch prevents too early start of services depending on other
services.  E.g, if service B depends on A then we must wait for A to
signal that it is ready before we allow B to start -- in a Finit based
system A does this by creating, or touching (updating mtime), its PID
file.  Services (like A) that support SIGHUP should call utime(), or
utimensat(), on the PID file at the end of their SIGHUP handler.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:14:48 +02:00
Joachim Nilsson cef4b5761a initctl: Only show service name, not path, with plain show
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-16 13:06:47 +01:00
Tobias Waldekranz 2555fe8e96 inetd: Flush existing filters on reload
Flush any existing filter rules when a configuration file is
updated. Otherwise filters are simply appended to the old
configuration which can cause finit to accept connections on
interfaces that are blocked in the new configuration.
2016-02-19 12:53:39 +01:00
Tobias Waldekranz c41016ef32 Only default to SIGHUP support on daemons
When parsing a service configuration, only default to SIGHUP support
if the service is a daemon. inetd services must be stop/started on
change.
2016-02-19 12:50:24 +01:00
Tobias Waldekranz c6055031b8 Avoid unnecessary restarts of services that do not support SIGHUP
When a service's condition transitions to `flux`, put it in the
waiting state, even if it does not support SIGHUP. That way, if the
condition returns to `on` we can simply SIGCONT it. If it goes to
`off` it will still be stop/started as before.
2016-02-05 13:45:06 +01:00
Tobias Waldekranz e8d699c194 Mark inetd services as clean on dynamic reload
When reloading dynamic services, inetd services deleted marker was not
being cleaned. This caused finit to stop and start all inetd services
at every other reload.
2016-01-28 14:52:49 +01:00
Tobias Waldekranz 80273555c5 Do all service transitions in a helper function
This eases development, since it makes it easy to set a breakpoint on
a specific state transition.
2016-01-28 13:44:27 +01:00
Tobias Waldekranz 6ece4b8fa3 inetd: Re-integrate the inetd subsystem into the new service model
This patch introduces a new service type called SVC_TYPE_INETD_CONN,
which represents a running inetd connection. These are handled in much
the same way as tasks. I.e. they are considered one-time jobs, with
the difference that they are removed upon completion.
2016-01-15 10:07:15 +01:00
Tobias Waldekranz 0beb566e45 git: Ignore Emacs backup files 2016-01-13 16:02:46 +01:00
Tobias Waldekranz c641a1374e Do not ignore updated services when cleaning up removed ones
When cleaning up removed services, the assumption was made that if a
service was not 'removed', it was 'clean'. In reality, it could also
be 'updated', which was then overwritten, causing services not being
restarted. Don't do that.

As a future precaution, make the dirty field const, only allowing
updates from accessor methods.
2016-01-13 15:14:27 +01:00
Tobias Waldekranz 171d611b14 Improve service state machine debug messages
In addition to logging state transitions, also log the parameters that
might trigger a transition.
2016-01-13 15:09:04 +01:00
Tobias Waldekranz 02eb68f46c Ensure that a service has stopped before taking any further action
During documentation of the state machine, some theoretical problems
where discovered that could have lead finit to spawn a new instance of
a daemon before the previous one had been collected.

Now a service will always go through the STOPPING state when leaving
RUNNING. This ensures that the PID has been collected before any calls
to service_start.

...documenting your work is, apparently, not a bad idea. :)
2016-01-07 11:00:52 +01:00
Tobias Waldekranz 7fe4c3355f doc: Add service state machine documentation 2016-01-07 11:00:51 +01:00
Joachim Nilsson 5b28fed321 Audit.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 21:11:27 +01:00
Tobias Waldekranz aa1da0e9f2 doc: Add documentation for conditions 2016-01-05 17:24:31 +01:00
Tobias Waldekranz 2232aea0f7 Dynamically manage service states based on user defined conditions
Old event system has been replaced with a more generic condition
concept. The idea is that finit plugins may provide arbitrary
conditions that services may specify as dependencies that they require
to run.

In order to accomodate this, the service management has been
redesigned to use a state machine.
2016-01-05 15:01:58 +01:00
Tobias Waldekranz 7a3408c173 Optionally skip stripping binaries during install-exec
One may wish to build and install with debug symbols intact, so allow
overriding the arguments sent to install.
2016-01-05 14:50:13 +01:00
Tobias Waldekranz af7b6c17cb Correctly parse service configuration stanzas containing slashes
Parser would erroneously interpret an event specification containing
slashes as an inet service/proto specification.

E.g. "<net/gw>" was interpreted as port "<net" using protocol "gw>".
2016-01-05 14:50:13 +01:00
Joachim Nilsson a822a7657c Update ChangeLog and bump version for v2.4 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2.4
2015-12-04 19:15:48 +01:00
Joachim Nilsson e46271c1a9 Revert change in v2.3 listing stopped services as "paused"
Stopped services are now (again) listed as "stopped" and halted
services, due to a runlevel change, are listed as "halted". Several
users complained that this change was just not intuitive. I agreee.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-04 19:05:35 +01:00
Joachim Nilsson 1028725079 Add support for 'initctl show dropbear:2'
By popular request, this patch adds support for querying status of a
single service.  The syntax is similar to that of stop/start/reload.

Both `initctl show ...` and `initctl status ...` is supported.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-03 20:05:25 +01:00
Joachim Nilsson ed5ee667ae [Patch 2/2]: Make sure to start/SIGHUP services when none were stopped
When no services were stopped we must ensure to start/SIGHUP any new or
SIGHUP:able services as the last pass of the `initctl reload` cycle.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-02 13:06:16 +01:00
Joachim Nilsson 4c3e053041 [Patch 1/2]: System reconfiguration causing system freeze
This patch fixes a hang when performing a system reconfiguration using
`initctl reload`, `SIGHUP` or running `(f)init q`, which caused Finit
to wait for SIGHUP:able services to stop.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-02 13:02:40 +01:00
Joachim Nilsson a5c5a5c644 Allow debug mode to override terse mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-01 22:36:16 +01:00
Joachim Nilsson fa3a97366c Update Debugging section, all interesting stuff is in configure now
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-01 22:30:08 +01:00
Joachim Nilsson 5b3e3da7ff Attempt to clarify how BusyBox getty works wrt. the TTY device path
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-01 22:24:21 +01:00
Joachim Nilsson 59d96f264d Reenable verbose mode at reboot, if disabled at boot
This patch reenables verbose mode at shutdown/reboot, if it was disabled
at boot.  This allows the user to see the output from the `urandom.so`
and `hwclock.so` plugins at reboot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-30 22:31:48 +01:00
Joachim Nilsson 7027cbc439 Enforce terse mode after boot, if verbose is disabled
The urandom.so plugin uncovered that `print_desc()` does not honor the
`verbose` flag.  At runtime `print_desc()` et al should no be displaying
anyting when we finit operates in terse mode.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-30 19:45:27 +01:00
Joachim Nilsson 8218fff7e5 Update ChangeLog and bump version for v2.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2.3
2015-11-28 13:59:47 +01:00
Joachim Nilsson 263e23a0df initctl: Support for stop/start services by name:id
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 21:22:05 +01:00
Joachim Nilsson 1f88e1ff8a Refactor svc_status() used by 'initctl show'
Leverage new svc_t states in initctl status/show output.  Also, ensure
different svc_t types have correct start state.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 20:51:04 +01:00
Joachim Nilsson b4ccc8b008 Clean up bootstrap-only tasks when leaving bootstrap 'S' runlevel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 20:22:24 +01:00
Joachim Nilsson 8df2b7b6e9 service_stop_dynamic(): Skip already stopped and HALT removed services
new postponed stop handling tried to reload already stopped and removed
services.  We should of course skip already stopped services and halt
those that have been removed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 19:13:39 +01:00