Commit Graph

75 Commits

Author SHA1 Message Date
Umut Tezduyar Lindskog db2cb23b5b core: send sigabrt on watchdog timeout to get the stacktrace
if sigabrt doesn't do the job, follow regular shutdown
routine, sigterm > sigkill.
2014-10-28 17:37:39 +01:00
Lennart Poettering f10af76de5 swap: don't add too many deps for swap files form /proc/swap 2014-10-28 17:37:06 +01:00
Lennart Poettering ddb7d6b942 swap: drop noauto/nofail bools from Swap structure
We nowadays always set them to "false" anyway, hence let's get rid of
them entirely.
2014-10-28 14:31:25 +01:00
Lennart Poettering 47cb901e38 swap: replace Discard= setting by a more generic Options= setting
For now, it's systemd itself that parses the options string, but as soon
as util-linux' swapon can take the option string directly with -o we
should pass it on unmodified.
2014-10-28 14:31:25 +01:00
Zbigniew Jędrzejewski-Szmek 3018d31238 core/swap: only make configured units part of swap.target
We used to make all .swap units either RequiredBy=swap.target or
WantedBy=swap.target. But swap.target should be the "configured swap
units", either through /etc/fstab or non-generated .swap units. It
is surprising when systemd starts treating a swap device that was
possibly temporarily enabled as a hard dependency for other units.
So do not add dependencies with swap.target for units gleaned from
/proc/swaps.

Similarly, we added dependencies for all aliases of the device name,
which clutters up the dependency graph but does not seem to bring any
value, since the status of those following units is consistent with
the main one anyway.

This should be a fix for [1], and it seems the right thing to do
anyway.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1114786
2014-10-02 00:11:36 -04:00
Zbigniew Jędrzejewski-Szmek cdc8982030 core/swap: follow the configured unit by default
Phenomenon: parameters configured in /etc/fstab for swap units are
ignored. E.g. pri= settings have no effect when systemd starts swap
units. What is even more confusing, .swap units for the name used in
/etc/fstab initially show proper values for Priority=, but after
starting them, they are re-initalized from /proc/swaps and show the -1
value from /proc/swaps.

Change swap units to follow the original configured unit. This way
proper settings are used when starting the swap.
2014-09-29 11:08:12 -04:00
Zbigniew Jędrzejewski-Szmek 4f52d3fe2d fstab-generator: properly deal with discard as non-last option
Previous code would only return correct results when discard
was the last option.

While at it, avoid incorrect behaviour for (invalid) 'pri' option
not followed by '=...', and also do not return -1 as the error code.
2014-09-29 11:08:12 -04:00
Jan Synacek 86b23b07c9 swap: introduce Discard property
Process possible "discard" values from /etc/fstab.
2014-09-29 11:08:12 -04:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Daniel Mack 9fa95f8539 exec: factor out most function arguments of exec_spawn() to ExecParameters
This way, the list of arguments to that function gets more comprehensive,
and we can get around passing lots of NULL and 0 arguments from socket.c,
swap.c and mount.c.

It also allows for splitting up the code in exec_spawn().

While at it, make ExecContext const in execute.c.
2014-09-05 12:18:57 +02:00
Zbigniew Jędrzejewski-Szmek de0671ee7f Remove unnecessary casts in printfs
No functional change expected :)
2014-05-15 15:29:58 +02:00
Lennart Poettering 6a0f1f6d5a sd-event: rework API to support CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM, too 2014-03-24 02:58:41 +01:00
Lennart Poettering 598459ceba core: rework context initialization/destruction logic
Let's automatically initialize the kill, exec and cgroup contexts of the
various unit types when the object is constructed, instead of
invididually in type-specific code.

Also, when PrivateDevices= is set, set DevicePolicy= to closed.
2014-03-19 21:06:53 +01:00
Lennart Poettering e66cf1a3f9 core: introduce new RuntimeDirectory= and RuntimeDirectoryMode= unit settings
As discussed on the ML these are useful to manage runtime directories
below /run for services.
2014-03-03 17:55:32 +01:00
Lennart Poettering 085afe36cb core: add global settings for enabling CPUAccounting=, MemoryAccounting=, BlockIOAccounting= for all units at once 2014-02-24 23:50:10 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Lennart Poettering ac84d1fb5a core: make sure to always go through both SIGTERM and SIGKILL states of units
Given that we now have KillMode=mixed where SIGTERM might kill a smaller
set than SIGKILL we need to make sure to always go explicitly throught
the SIGKILL state to get the right end result.
2014-01-29 17:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 68db7a3bd9 core: add function to tell when job will time out
Things will continue when either the job timeout
or the unit timeout is reached. Add functionality to
access that info.
2014-01-27 01:23:16 -05:00
Stefan Beller 7bb01eff62 swap: remove if/else with the same data path
This was introduced in e1770af812 (2012-02-03, swap: replace failure
boolean by result enum).

This just removes unneeded lines of code, no functional change.
2014-01-05 00:43:22 -05:00
Lennart Poettering 09812eb764 sd-daemon: introduce sd_watchdog_enabled() for parsing $WATCHDOG_USEC
Also, introduce a new environment variable named $WATCHDOG_PID which
cotnains the PID of the process that is supposed to send the keep-alive
events. This is similar how $LISTEN_FDS and $LISTEN_PID work together,
and protects against confusing processes further down the process tree
due to inherited environment.
2013-12-22 22:19:03 +01:00
Lennart Poettering aec8de63b1 core: no need to list properties for PropertiesChanged messages anymore
Since the vtable includes this information anyway, let's just use that
2013-12-22 03:50:52 +01:00
Zbigniew Jędrzejewski-Szmek df41aaf9a2 Remove some unused variables 2013-11-28 14:37:11 -05:00
Lennart Poettering 613b411c94 service: add the ability for units to join other unit's PrivateNetwork= and PrivateTmp= namespaces 2013-11-27 20:28:48 +01:00
Lennart Poettering 9670d583d3 swap: always track the current real device node of all swap devices, even when not active
This way, we can avoid executing two /bin/swapon jobs to be dispatched
for the same swap device if it is configured for two different paths.

Previously we were just tracking the device nodes of active swap
devices, which would not allow us to recognize the identity of two swap
devices before they are active.

https://bugs.freedesktop.org/show_bug.cgi?id=69835
2013-11-25 22:10:22 +01:00
Lennart Poettering 290837072b core: set some event source priorities to enforce dispatching order 2013-11-25 17:40:53 +01:00
Lennart Poettering 5bcb0f2ba0 swap: split state machine state ACTIVATING into two
We expect the event on /proc/swaps before we expect the SIGCHILD,
reflect this in the state machine.
2013-11-25 17:40:53 +01:00
Lennart Poettering 718db96199 core: convert PID 1 to libsystemd-bus
This patch converts PID 1 to libsystemd-bus and thus drops the
dependency on libdbus. The only remaining code using libdbus is a test
case that validates our bus marshalling against libdbus' marshalling,
and this dependency can be turned off.

This patch also adds a couple of things to libsystem-bus, that are
necessary to make the port work:

- Synthesizing of "Disconnected" messages when bus connections are
  severed.

- Support for attaching multiple vtables for the same interface on the
  same path.

This patch also fixes the SetDefaultTarget() and GetDefaultTarget() bus
calls which used an inappropriate signature.

As a side effect we will now generate PropertiesChanged messages which
carry property contents, rather than just invalidation information.
2013-11-20 20:52:36 +01:00
Oleksii Shevchuk 1f19a534ea Configurable Timeouts/Restarts default values
https://bugs.freedesktop.org/show_bug.cgi?id=71132

Patch adds DefaultTimeoutStartSec, DefaultTimeoutStopSec, DefaultRestartSec
configuration options to manager configuration file.
2013-11-05 19:57:22 +01:00
Lennart Poettering 71fda00f32 list: make our list macros a bit easier to use by not requring type spec on each invocation
We can determine the list entry type via the typeof() gcc construct, and
so we should to make the macros much shorter to use.
2013-10-14 06:11:19 +02:00
Lennart Poettering a57f7e2c82 core: rework how we match mount units against each other
Previously to automatically create dependencies between mount units we
matched every mount unit agains all others resulting in O(n^2)
complexity. On setups with large amounts of mount units this might make
things slow.

This change replaces the matching code to use a hashtable that is keyed
by a path prefix, and points to a set of units that require that path to
be around. When a new mount unit is installed it is hence sufficient to
simply look up this set of units via its own file system paths to know
which units to order after itself.

This patch also changes all unit types to only create automatic mount
dependencies via the RequiresMountsFor= logic, and this is exposed to
the outside to make things more transparent.

With this change we still have some O(n) complexities in place when
handling mounts, but that's currently unavoidable due to kernel APIs,
and still substantially better than O(n^2) as before.

https://bugs.freedesktop.org/show_bug.cgi?id=69740
2013-09-26 20:20:30 +02:00
Lennart Poettering 13b84ec7df cgroup: if we do a cgroup operation then do something on all supported controllers
Previously we did operations like attach, trim or migrate only on the
controllers that were enabled for a specific unit. With this changes we
will now do them for all supproted controllers, and fall back to all
possible prefix paths if the specified paths do not exist.

This fixes issues if a controller is being disabled for a unit where it
was previously enabled, and makes sure that all processes stay as "far
down" the tree as groups exist.
2013-09-25 03:38:17 +02:00
Zbigniew Jędrzejewski-Szmek 9fb3675e7e Use first partition in /proc/swaps for hibernation test
It seems that the kernel uses the first configured partition
for hibernation. If it is too full, hibernation will fail. Test
that directly.
2013-09-17 16:44:38 -04:00
Tom Gundersen 4e82fe5213 swap: create .wants symlink to 'auto' swap devices
As we load unit files lazily, we need to make sure something pulls in swap
units that should be started automatically, otherwise the default dependencies
will never be applied.

This partially reinstates code removed in
commit 64347fc2b9.

Also don't order swap devices after swap.target when they are 'nofail'.
2013-09-16 01:11:52 +02:00
Tom Gundersen 90060fa660 swap: fix reverse dependencies
Make sure swap.target correctly requires/wants the swap units.

This fixes https://bugs.freedesktop.org/show_bug.cgi?id=69291.

Reported-by: Hussam Al-Tayeb
2013-09-13 14:48:29 +02:00
Tom Gundersen 64347fc2b9 swap: handle nofail/noauto in core 2013-09-11 14:43:24 +02:00
Tom Gundersen b56a422a91 swap: backing device should unconditionally want swap unit
There is no need to restrict this to only the 'nofail' case. In the '!nofail'
case the unit is already wanted by swap.target, so this is not a functional change.
2013-09-11 14:40:59 +02:00
Lennart Poettering 74c964d369 dbus: hookup runtime property changes for mouns, services, sockets, swaps too 2013-06-27 23:21:21 +02:00
Lennart Poettering 4ad490007b core: general cgroup rework
Replace the very generic cgroup hookup with a much simpler one. With
this change only the high-level cgroup settings remain, the ability to
set arbitrary cgroup attributes is removed, so is support for adding
units to arbitrary cgroup controllers or setting arbitrary paths for
them (especially paths that are different for the various controllers).

This also introduces a new -.slice root slice, that is the parent of
system.slice and friends. This enables easy admin configuration of
root-level cgrouo properties.

This replaces DeviceDeny= by DevicePolicy=, and implicitly adds in
/dev/null, /dev/zero and friends if DeviceAllow= is used (unless this is
turned off by DevicePolicy=).
2013-06-27 04:17:34 +02:00
Lennart Poettering a016b9228f core: add new .slice unit type for partitioning systems
In order to prepare for the kernel cgroup rework, let's introduce a new
unit type to systemd, the "slice". Slices can be arranged in a tree and
are useful to partition resources freely and hierarchally by the user.

Each service unit can now be assigned to one of these slices, and later
on login users and machines may too.

Slices translate pretty directly to the cgroup hierarchy, and the
various objects can be assigned to any of the slices in the tree.
2013-06-17 21:36:51 +02:00
Zbigniew Jędrzejewski-Szmek 44a6b1b680 Add __attribute__((const, pure, format)) in various places
I'm assuming that it's fine if a _const_ or _pure_ function
calls assert. It is assumed that the assert won't trigger,
and even if it does, it can only trigger on the first call
with a given set of parameters, and we don't care if the
compiler moves the order of calls.
2013-05-02 22:52:09 -04:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Michal Sekletar c17ec25e4d core: reuse the same /tmp, /var/tmp and inaccessible dir
All Execs within the service, will get mounted the same
/tmp and /var/tmp directories, if service is configured with
PrivateTmp=yes. Temporary directories are cleaned up by service
itself in addition to systemd-tmpfiles. Directory which is mounted
as inaccessible is created at runtime in /run/systemd.
2013-03-15 22:56:40 -04:00
Michal Schmidt 814cc56212 core: single unit_kill implementation for all unit types
There are very few differences in the implementations of the kill method in the
unit types that have one. Let's unify them.

This does not yet unify unit_kill() with unit_kill_context().
2013-03-13 17:21:53 +01:00
Lennart Poettering cd2086fe65 core: unify kill code of mount, service, socket, swap units 2013-01-26 05:53:30 +01:00
Lennart Poettering 71645acac2 unit: optionally allow making cgroup attribute changes persistent 2013-01-19 01:02:30 +01:00
Zbigniew Jędrzejewski-Szmek 66870f90de systemd: use unit logging macros 2013-01-06 13:52:48 -05:00
Lennart Poettering 36697dc019 timer: implement calendar time events 2012-11-23 21:37:58 +01:00
Olivier Brunel b61e88162a swap: fix swap behaviour with symlinks
Starting a swap unit pointing to (What) a symlink (e.g. /dev/mapper/swap
or /dev/disk/by-uuid/...) would have said unit marked active, following
the one using the "actual" device (/dev/{dm-1,sda3}), but that new unit
would be seen as inactive.
Since all requests to stop swap units would follow/redirect to it,
and it is seen inactive, nothing would be done (swapoff never called).

This is because this unit would be treated twice in
swap_process_new_swap, the second call to swap_add_one causing it to
eventually be marked inactive.
2012-10-29 09:04:25 +00:00
Zbigniew Jędrzejewski-Szmek 646134dc0d swap: modernize style 2012-10-29 09:03:56 +00:00