Commit graph

203 commits

Author SHA1 Message Date
Lennart Poettering 7f110ff9b8 conf: enforce UTF8 validty everywhere
we need to make sure that configuration data we expose via the bus ends
up in using getting an assert(). Even though configuration data is only
parsed from trusted sources we should be more careful with what we read.
2012-03-12 22:22:21 +01:00
Lennart Poettering 6bda96a023 socket: rename 'broken' failure result to 'failed-permanent' on order not to introduce new terminology 2012-03-06 01:29:29 +01:00
Michal Schmidt c2f3480897 socket: fail the socket if the service keeps dying on start
If the service reaches the start limit, mark the sockets that activate
it as failed (with the result code 'service-broken').
This way the sockets won't act as tarpits for clients connecting to
them.
2012-03-05 22:47:54 +01:00
Lennart Poettering 02c4ef9c35 service: imply NotifyAccess=main if WatchdogSec= is used 2012-02-09 21:11:25 +01:00
Michael Olbrich 4b9397474f service: add StartLimitInterval/StartLimitBurst/StartLimitAction 2012-02-09 21:01:29 +01:00
Lennart Poettering 353e12c2f4 service: ignore SIGPIPE by default 2012-02-09 03:18:04 +01:00
Michael Olbrich 6e0bcc980b service: set WATCHDOG_USEC environmen variable 2012-02-08 17:11:06 +01:00
Michael Olbrich bb242b7b52 service: introduce WatchdogSec and hook up the watchdog with the existing failure logic 2012-02-08 17:10:38 +01:00
Lennart Poettering cfc4eb4cba socket: replace failure boolean by enum 2012-02-03 05:06:03 +01:00
Lennart Poettering f42806df7d service: replace "failure" boolean by enum, and export it
This should give admins more useful hints why a service failed.
2012-02-03 05:06:03 +01:00
Michael Olbrich a6927d7ffc service: add watchdog timestamp
This patch adds WatchdogTimestamp[Monotonic] to the systemd service
D-Bus API. The timestamp is updated to the current time when the
service calls 'sd_nofity("WATCHDOG=1\n")'.
Using a timestamp instead of an 'alive' flag has two advantages:
1. No timeout is needed to define when a service is no longer alive.
   This simplifies both configuration (no timeout value) and
   implementation (no timeout event).
2. It is more robust. A 'dead' service might not be detected should
    systemd 'forget' to reset an 'alive' flag. It is much less likely
    to get a valid new timestamp if a service died.
2012-02-01 19:29:19 +01:00
Michal Schmidt 3e52541ef5 service: add missing pid file unwatch in the destructor
The pid file watch could outlive the service unit if a daemon-reload
request came at the right time. The inotify event would then be
delivered to who knows where.

Fix it by unwatching in the service destructor.

Further changes will be needed to preserve the state of the pid file
watch across daemon-reload. For now let's just fix the crash observed
by Jóhann Guðmundsson:
Assertion 's->state == SERVICE_START || s->state == SERVICE_START_POST'
failed at src/service.c:2609, function service_fd_event().  Aborting

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=783118
2012-01-20 00:51:56 +01:00
Michal Schmidt 595ed347a8 unit: use safe downcasts, remove pointless casts
Always use the macros for downcasting.
Remove a few obviously pointless casts.
2012-01-16 13:34:42 +01:00
Michal Schmidt 1124fe6f01 unit: use the UNIT() macro consistently
The UNIT() macro upcasts from specific unit types to the base Unit.
Use it everywhere, rather than accessing the 'meta' member directly.
2012-01-16 13:34:42 +01:00
Michal Schmidt ac155bb885 unit: remove union Unit
Now that objects of all unit types are allocated the exact amount of
memory they need, the Unit union has lost its purpose. Remove it.

"Unit" is a more natural name for the base unit class than "Meta", so
rename Meta to Unit.

Access to members of the base class gets simplified.
2012-01-16 13:34:42 +01:00
Michal Schmidt 7d17cfbc46 unit: reduce heap usage for unit objects
The storage of the unit objects on the heap is currently not very
efficient. For every unit object we allocate a chunk of memory as large
as the biggest unit type, although there are significant differences in
the units' real requirements.
pahole shows the following sizes of structs:
488  Target
496  Snapshot
512  Device
528  Path
560  Timer
576  Automount
1080 Socket
1160 Swap
1168 Service
1280 Mount

Usually there aren't many targets or snapshots in the system, but Device
is one of the most common unit types and for every one we waste
1280 - 512 = 768 bytes.

Fix it by allocating only the right amount for the given unit type.
On my machine (x86_64, with 39 LVM volumes) this decreases systemd's
USS (unique set size) by more than 300 KB.
2012-01-16 13:34:42 +01:00
Lennart Poettering 8f53a7b8ea service: brutally slaughter processes that are running in the cgroup when we enter START_PRE and START 2012-01-11 02:52:34 +01:00
Lennart Poettering 57020a3abf unit: properly update references to units which are merged
When we merge units that some kind of object points to, those pointers
might become invalidated, and needs to be updated. Introduce a UnitRef
struct which links up all the unit references, to ensure corrected
references.

At the same time, drop configured_sockets in the Service object, and
replace it by proper UNIT_TRIGGERS resp. UNIT_TRIGGERED_BY dependencies,
which allow us to simplify a lot of code.
2012-01-06 23:08:54 +01:00
Lennart Poettering 73aa0c00df service: add dependencies on configured sockets 2012-01-06 19:23:03 +01:00
Lennart Poettering 706343f492 journal: introduce log target 'journal' for executed processes 2012-01-06 02:48:38 +01:00
Michal Schmidt 18d01523c8 service: use 'syslog+console' for sysv_console
The default output to 'tty' for SysV service was making it hard to debug
problems because error messages were missing from syslog.
2011-12-16 17:40:41 +01:00
Michal Schmidt 2096e009a7 service: stop the service if ExecStartPost ends with a failure
The handling of failures in ExecStartPost is inconsistent. If the
command times out, the service is stopped. But if the command exits
with a failure, the service keeps running.

It makes more sense to stop the service when ExecStartPost fails.
If this behaviour is not desired, the ExecStartPost command can be
prefixed with "-".
2011-12-03 23:10:12 +01:00
Michal Schmidt 3a11183858 service: handle services with racy daemonization gracefully
There are a lot of forking daemons that do not exactly follow the
initialization steps as described in daemon(7). It is common that they
do not bother waiting in the parent process for the child to write the
PID file before exiting. The daemons' developers often do not perceive
this as a bug and they're unwilling to change.

Currently systemd warns about the missing PID file and falls back to
guessing the main PID. Being not quite deterministic, the guess can be
wrong with bad consequences. If the guessing is disabled, determinism is
achieved at the cost of losing the ability of noticing when the main
process of the service dies.

As long as it does not negatively affect properly written services,
systemd should strive for compatibility even with services with racy
daemonization. It is possible to provide determinism _and_ main process
supervision to them.

If the PID file is not there, rather than guessing and considering the
service running immediately after getting the SIGCHLD from the ExecStart
(or ExecStartPost) process, we can keep the service in the activating
state for a bit longer. We can use inotify to wait for the PID file to
appear. Only when it finally does appear and we read a valid PID from
it, we'll move the service to the running state. If the PID file never
appears, the usual timeout kicks in and the service fails.
2011-12-03 21:50:27 +01:00
Michal Schmidt c5419d4239 service: don't warn if the pidfile still exists after SIGCHLD
A service that drops its privileges may not be able to remove it when it
exits. The stale pidfile is not a problem as long as the service
carefully recognizes it on its next start.

systemd would produce a warning after the service exits:
  PID ... read from file ... does not exist. Your service or init
  script might be broken.

Silence the warning in this case. Still warn if this error is detected
when loading the pidfile after service start.

Noticed by Miroslav Lichvar in
 https://bugzilla.redhat.com/show_bug.cgi?id=752396
2011-11-10 10:18:08 +01:00
Dexter Morgan 6fdae8a6a4 Add Mageia support
This patch adds support for the Mageia Linux distribution:
 http://www.mageia.org/

Mageia is a fork of Mandriva although some divergence has already occured
and thus inclusion of these changes upstream allow us to (hopefully)
migrate more rapidly to the new standard approaches systemd offers.
Indeed, we already use the preferred mechanism of OS identification via
the /etc/os-release file rather than a distro specific variation.

This patch mostly mirrors the patch added previously for Mandriva
support. In addition to those original authors, this patch was mostly
written by Dexter Morgan with help from Colin Guthrie and Eugeni Dodonov.
2011-11-02 02:16:39 +01:00
Tollef Fog Heen e51db373c2 service: Drop rcN.d runlevels from SysV services that also exist in rcS.d
Services which claim to start in both rcN.d and rcS.d generate
loops which for some reason seems to usually end up with dbus not
starting and the whole machine being quite unhappy. We now rather
assume that if a service can be started in rcS, it should not also
start in rcN.d.

Fixes Debian bug #637037
2011-10-17 21:02:42 +02:00
Lennart Poettering 1835f23c2a service: don't try to guess PID for SysV services anymore
As it turns out there are quite a number of SysV services too broken to
make the guessing work: instead of returning in the parent only after
the child is fully initialized they return immediately. The effect is
that the guessing in systemd might happen too early, at a time where the
final main process doesn't exist yet.

By turning this off we won't try to detect the main pid anymore, with
the effect that all processes of the service in question are considered
equally likely to be the main process.
2011-10-11 20:21:06 +02:00
Lennart Poettering 4e2b0f9b14 service: fix up std output/error before we add dependencies to the bridge socket 2011-09-23 17:42:21 +02:00
Lennart Poettering 8ea913b2ea coverity: fix a couple of bugs found by coverity 2011-09-23 01:45:34 +02:00
Michal Schmidt 5375410bb2 service: warn if a service fails to write its PID file
Warn if a service promises to write a PID file (using 'PIDFile=' in the
unit file or '# pidfile:' in SysV header), but fails to keep the
promise.

This warning will likely trigger also for the forking services with a
racy daemonization, which exit the original process before the PID file
is written.
2011-09-22 13:18:52 +02:00
Lennart Poettering 4dfc092a71 service: if StandardInput=socket and StandardOutput=inherit imply socket for output, don't imply default output
This is useful for inetd-style per-connection services, so that they
again can simply specify StandardOutput=socket to connect all three fds
to the socket.
2011-09-22 03:29:51 +02:00
Michal Schmidt 13230d5d3c service: minor change in service_load_pid_file return value
Return 0 only if the PID was really loaded. If no PIDFile= is defined,
return -ENOENT.

Only one caller cares about the return value of this function and this
change makes the usage nicer.
2011-09-21 02:25:17 +02:00
Michal Schmidt db01f8b3f8 service: handle forking services that move to a new PID
When some forking daemons receive a SIGHUP, they re-execute themselves
and consequently change to a new main PID. As long as they update the
PID file in the right order (before exiting the old PID), we can detect
that and avoid killing them.
2011-09-21 00:57:41 +02:00
Lennart Poettering 00ca7f0782 service: drop broken support for X-Interactive fields in LSB headers
The logic never worked since reading from the boot console is useless
when a service is started after boot. Hence drop this half-baked code,
since we now have a place document incompatibilities like this.

http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities
2011-09-20 01:33:48 +02:00
Miklos Vajna 240fc26e03 service: all rcS.d scripts have been converted on Frugalware 2011-08-24 02:14:10 +02:00
Lennart Poettering ab1f063390 exec: optionally apply cgroup attributes to the cgroups we create 2011-08-20 00:22:02 +02:00
Frederic Crozat de3910a324 service: parse insserv.conf and plugs its system facilities into systemd. 2011-08-02 01:37:48 +02:00
Lennart Poettering 44d9105692 util: use join() instead of asprintf() as an optimization 2011-08-01 02:39:22 +02:00
Lennart Poettering 70132bd042 util: various optimizations, using join() 2011-08-01 01:55:31 +02:00
Lennart Poettering f975e971ac load-fragment: speed up parsing by using a perfect hash table with configuration settings built by gperf 2011-08-01 00:43:05 +02:00
Lennart Poettering a17204af0e unit: use ESRCH as error when we don't find anybody to kill 2011-07-13 19:59:28 +02:00
Lennart Poettering 3611581ebd service: properly handle who argument on D-Bus kill calls 2011-07-12 04:05:33 +02:00
Lennart Poettering a755605296 manager: merge serialization and desrialization counter into one, and increase it when reexecuting
Instead of having individual counters n_serializing and n_deserializing
have a single one n_reloading, which should be sufficient.

Set n_reloading when we are about to go down for reexecution to avoid
cgroup trimming when we free the units for reexecution.
2011-07-06 00:47:42 +02:00
Michal Schmidt f878830392 service: 'pidfile:' in SysV chkconfig header implies a real daemon
The presence of the chkconfig "pidfile:" header in the initscript is an
excellent indication that it's not a oneshot script (like iptables),
but a real daemon (like httpd).
2011-07-05 10:17:42 +02:00
Lennart Poettering b1bc08e599 manager: don't even think of enumerating sysv services in user instances 2011-07-01 23:53:44 +02:00
Lennart Poettering 5f4b19f4bc service: check whether sysv scripts where changed 2011-06-21 19:29:45 +02:00
Lennart Poettering 8d0e38a2b9 dbus: introduce UnsetAndSetEnvironment() 2011-06-21 19:29:45 +02:00
Lennart Poettering ab5c3e3ff1 english: s/_per_/_by_/ 2011-06-21 19:29:44 +02:00
Lennart Poettering 6ea832a207 exec: hangup/reset/deallocate VTs in gettys
Explicitly disconnect all clients from a VT when a getty starts/finishes
(requires TIOCVHANGUP, available in 2.6.29).

Explicitly deallocate getty VTs in order to flush scrollback buffer.

Explicitly reset terminals to a defined state before spawning getty.
2011-05-18 01:07:36 +02:00
Koen Kooi 1bd8b8184e build-sys: Angstrom support
This commit consists of the initial work to include Angstrom as a ported
distribution for systemd.

Angstrom tries to follow the debian way as much as possible, but deviates
where it doesn't make sense for 'embedded'.
2011-05-09 23:50:23 +02:00