Commit graph

25563 commits

Author SHA1 Message Date
Lennart Poettering 8612da973d core: be more paranoid when mixing umask and fopen()
Let's be extra careful with the umask when we use simple fopen(), as this
creates files with 0777 by default.
2016-04-12 13:43:32 +02:00
Lennart Poettering 4f4afc88ec core: rework how transient unit files and property drop-ins work
With this change the logic for placing transient unit files and drop-ins
generated via "systemctl set-property" is reworked.

The latter are now placed in the newly introduced "control" unit file
directory. The fomer are now placed in the "transient" unit file directory.

Note that the properties originally set when a transient unit was created will
be written to and stay in the transient unit file directory, while later
changes are done via drop-ins.

This is preparation for a later "systemctl revert" addition, where existing
drop-ins are flushed out, but the original transient definition is restored.
2016-04-12 13:43:32 +02:00
Lennart Poettering 80b1ae32e1 core: introduce a "control" unit file directory
This patch adds a concept of a "control" unit file directory, which is supposed
to be used as place for unit file drop-ins created by "systemctl set-property"
(note that this directory is not actually hooked up to "systemctl set-property"
yet, that's coming in a later patch).

The rationale for this: previously changes made by the user and by "systemctl
set-property" were done in the same directory, which made semantics very
unclear: the changes made by "systemctl set-property" were applied instantly,
and their drop-ins only written to not lose settings on a later "systemctl
daemon-reload", while drop-ins made by the user would only be in effect after
"systemctl daemon-reload". This is particular problematic as the changes made
by "systemctl set-property" would really apply immediately without any respect
for the unit search path. This meant that using "set-property" could have an
effect that is lsot as soon as "daemon-reload" is issued, in case there was a
"later" drop-in already in place.

With this change the directories are seperated, and the "control" directory
always takes the highest priority of all, to avoid any confusion.
2016-04-12 13:43:31 +02:00
Lennart Poettering 9183df707b install: rename generator_paths() → generator_binary_paths()
This is too confusing, as this funciton returns the paths to the generator
binaries, while usually when we refer to the just the "generator path" we mean
the generated unit files. Let's clean this up.
2016-04-12 13:43:31 +02:00
Lennart Poettering 07a7864324 core: move flushing of generated unit files to path-lookup.c
It's very similar to the mkdir and trim operations for the generator dirs,
hence let's unify this at a single place.
2016-04-12 13:43:31 +02:00
Lennart Poettering d8d410f445 core: minor coding style fix 2016-04-12 13:43:31 +02:00
Lennart Poettering e46e442243 tests: make sure test-path-lookup can run even when no units are installed on test system 2016-04-12 13:43:31 +02:00
Lennart Poettering 5de344704d localed: downgrade libxkbcommon to an optional runtime dependency
Previously, libxkbcommon was a compile-time option. When enabled the localed
binary would strictly depend on it, thus pulling in libxkbcommon and its
dependencies, which are non-trivial in size.

With this change we dlopen() libxkbcommon when it is available instead. If the
library is available behaviour is as before. However, if it isn't the system is
considered "headless", i.e. without local hardware and all attempts to set the
local keyboard configuration will be refused.

This is useful for general-purpose distributions which want to support
"headless" (such as container systems) and "full" systems with the same build.
2016-04-12 13:43:31 +02:00
Lennart Poettering 198402d3c9 test: bump up log level for install root test 2016-04-12 13:43:31 +02:00
Lennart Poettering 08ce521fb2 shared: add a temporary work-around for kernel header inclusion fuck-up
See: #2864
2016-04-12 13:43:31 +02:00
Lennart Poettering 76adb5b8b5 install: unify checking whether operations may be applied to a unit file in a new function
Let's replace repeated code by a single implementation in a single function.
2016-04-12 13:43:31 +02:00
Lennart Poettering e4fca67ff0 install: introduce a new unit file state "transient"
Now, that the search path logic knows the unit path for transient units we also
can introduce an explicit unit file state "transient" that clarifies to the
user what kind of unit file he is encountering.
2016-04-12 13:43:31 +02:00
Lennart Poettering 401017e04d install: fix root prefix handling
Previously, we'd execute some operations with the root prefix applied, while
others without (which was a bug). Clean this up: all paths are now prefixed
properly with the root path, and we strip it off when necessary.

(Of course, an alternative option would be to strictly pass around paths
without the prefix prepended and only prepend it right before hitting the disk,
however, I am came to the conclusion this would result in more code.)
2016-04-12 13:43:31 +02:00
Lennart Poettering a7527131bb path-lookup: make user_runtime_dir() more generic
Let's make the suffix it appends configurable. This way we can reuse it at a second place.
2016-04-12 13:43:31 +02:00
Lennart Poettering 205dd21ecc path-lookup: clean up user_config_home() and user_runtime_dir()
Let's modernize these calls a bit.

Also, don't call them from user_dirs() anymore, as we already have both dirs in
the list a second time via the persistent_config and runtime_config function
parameters.
2016-04-12 13:43:31 +02:00
Lennart Poettering 7f8a0d7b41 update CODING_STYLE a bit 2016-04-12 13:43:31 +02:00
Lennart Poettering 5b5ad18dd9 path-lookup: stop exporting two functions
user_runtime_dir() and user_config_home() are not used externally anymore,
hence let's not export them anymore.
2016-04-12 13:43:31 +02:00
Lennart Poettering d063a52741 core: modernize manager_build_unit_patch_cache() a bit 2016-04-12 13:43:31 +02:00
Lennart Poettering 193dc81ee3 core: don't reorder drop-ins when changing properties
The drop-in order we present should actually show what we is in effect, hence
let's not reorder it when writing changes. After all, just sorting
alphabetically is going to break things, as it doesn't respect that /etc breaks
/run breaks /usr...
2016-04-12 13:43:31 +02:00
Lennart Poettering d7e0da1db2 core: don't drop transient drop-ins when loading the rest
Previously, when creating a transient unit, we'd first add the transient
drop-ins to the unit, and then normally load any other drop-ins later on top of
this, replacing the already loaded drop-ins. Let's not do this, after all the
transient drop-ins area already in effect, let's just add what we find on disk,
but not replace it.
2016-04-12 13:43:31 +02:00
Lennart Poettering a145334304 core: rework logic to drop duplicate and non-existing items from search path
Move this into a function of its own, so that we can run it after we ran the
generators, so that it takes into account removed generator dirs.
2016-04-12 13:43:30 +02:00
Lennart Poettering cd64fd5613 path-lookup: split out logic for mkdir/rmdir of generator dirs in their own functions 2016-04-12 13:43:30 +02:00
Lennart Poettering 3959135139 core: add a separate unit directory for transient units
Previously, transient units were created below the normal runtime directory
/run/systemd/system. With this change they are created in a special transient
directory /run/systemd/transient, which only contains data for transient units.

This clarifies the life-cycle of transient units, and makes clear they are
distinct from user-provided runtime units. In particular, users may now
extend transient units via /run/systemd/system, without systemd interfering
with the life-cycle of these files.

This change also adds code so that when a transient unit exits only the
drop-ins in this new directory are removed, but nothing else.

Fixes: #2139
2016-04-12 13:43:30 +02:00
Lennart Poettering 5f0a41dade path-lookup: add configured unit paths back into search path
After all, for test builds they might differ from /etc/systemd/{user|system},
hence they should be included.
2016-04-12 13:43:30 +02:00
Lennart Poettering 92dd7c4965 core: reuse manager_get_runtime_prefix() at more places 2016-04-12 13:43:30 +02:00
Lennart Poettering e4bb56c7a9 install: add root directory to LookupPaths structure
We use the root directory parameter while putting together the LookupPaths
structure, hence let's also store it in the structure as-is. That way we can
drop a parameter from half of the functions in install.c

Also, let's move the validation of the root paths into lookup_paths_init() so
that we can drop even more code from install.c
2016-04-12 13:43:30 +02:00
Lennart Poettering 32c0ed7bbb install: change in_search_path() to take a LookupPaths structure
Similar to the other calls that operate on the collected path data.
2016-04-12 13:43:30 +02:00
Lennart Poettering f4dc1e65e3 install: rename unit_file_is_generated() → path_is_generator()
This way the funciton name matches nicely our other calls path_is_config() and
path_is_runtime().
2016-04-12 13:43:30 +02:00
Lennart Poettering 385eb99634 install: be more accurate when checking whether something is runtime configuration
Let's actually check the runtime config dir, instead of just /run.
2016-04-12 13:43:30 +02:00
Lennart Poettering 21b3926840 network: hashmap_put() can fail
Let's properly handle hashmap_put() failing.
2016-04-12 13:43:30 +02:00
Lennart Poettering 2c289ea833 core: introduce MANAGER_IS_RELOADING() macro
This replaces the old function call manager_is_reloading_or_reexecuting() which
was used only at very few places. Use the new macro wherever we check whether
we are reloading. This should hopefully make things a bit more readable, given
the nature of Manager:n_reloading being a counter.
2016-04-12 13:43:30 +02:00
Lennart Poettering 463d0d1569 core: remove ManagerRunningAs enum
Previously, we had two enums ManagerRunningAs and UnitFileScope, that were
mostly identical and converted from one to the other all the time. The latter
had one more value UNIT_FILE_GLOBAL however.

Let's simplify things, and remove ManagerRunningAs and replace it by
UnitFileScope everywhere, thus making the translation unnecessary. Introduce
two new macros MANAGER_IS_SYSTEM() and MANAGER_IS_USER() to simplify checking
if we are running in one or the user context.
2016-04-12 13:43:30 +02:00
Lennart Poettering c51932be73 systemctl: port systemctl over to the new LookupPaths configuration directory fields 2016-04-12 13:43:30 +02:00
Lennart Poettering e1c5c2b0d2 install: make use of configuration directory paths in LookupPaths
Now that the LookupPaths structure contains the directory paths, let's make use
of that everywhere instead of duplicating the logic.
2016-04-12 13:43:30 +02:00
Lennart Poettering a0f84a104c core: add configuration directories to LookupPaths
Let's add a seperate fields for the directories where we place runtime and
persistent configuration, so that we can use this in install.c (to be added in
a later commit), and we store path information in the same place everywhere.
2016-04-12 13:43:30 +02:00
Lennart Poettering 7bfe3d44d0 core: when enabling a generated unit file, return a clean error
Let's be precise when the user tries to invoke an "enable" operation on a
generated unit file.
2016-04-12 13:43:29 +02:00
Lennart Poettering f413930863 core: add a new unit file state "generated"
Now that we store the generator directories in LookupPaths we can use this to
intrdouce a new unit file state called "generated", for units in these
directories.

Fixes: #2348
2016-04-12 13:43:29 +02:00
Lennart Poettering a3c4eb0710 core: rework generator dir logic, move the dirs into LookupPaths structure
A long time ago – when generators where first introduced – the directories for
them were randomly created via mkdtemp(). This was changed later so that they
use fixed name directories now. Let's make use of this, and add the genrator
dirs to the LookupPaths structure and into the unit file search path maintained
in it. This has the benefit that the generator dirs are now normal part of the
search path for all tools, and thus are shown in "systemctl list-unit-files"
too.
2016-04-12 13:43:29 +02:00
Lennart Poettering 4447e799be man: minor nspawn doc fixes 2016-04-12 13:43:29 +02:00
Lennart Poettering 1dfa3076cf core: drop SysV paths from path-lookup logic
We don't need it anymore, give that sysv-generator can determine the path on
its own now.
2016-04-12 13:43:29 +02:00
Lennart Poettering 4143c6c305 sysv-generator: don't use LookupPath logic for determining SysV paths
The sysv-generator is the only user of the SysV paths these days, let's make it
figure out the right paths on its own.

(In a subsequent commit we can then drop the same logic from LookupPath).
2016-04-12 13:43:29 +02:00
Lennart Poettering 03ce175f4c import: drop unused definition 2016-04-12 13:43:29 +02:00
Lennart Poettering 1ade1cc0bf Merge pull request #3016 from martinpitt/systemctl-enable
Install: correctly report symlink creations
2016-04-12 11:34:44 +02:00
Zbigniew Jędrzejewski-Szmek 6d10d308c6 Do not report masked units as changed (#2921)
* core/unit: extract checking of stat paths into helper function

The same code was repeated three times.

* core: treat masked files as "unchanged"

systemctl prints the "unit file changed on disk" warning
for a masked unit. I think it's better to print nothing in that
case.

When a masked unit is loaded, set mtime as 0. When checking
if a unit with mtime of 0 needs reload, check that the mask
is still in place.

* test-dnssec: fix build without gcrypt

Also reorder the test functions to follow the way they are called
from main().
2016-04-12 11:10:57 +02:00
Lukáš Nykrýn 35a6750d9e rules: set SYSTEMD_READY=0 on DM_UDEV_DISABLE_OTHER_RULES_FLAG=1 only with ADD event (#2747)
The "SYSTEMD_READY=0" will cause automatic unmount
of mountpoint that is on top of such DM device
if this is used with multipath which sets
DM_UDEV_DISABLE_OTHER_RULES_FLAG in case
we have a CHANGE event thatcomes after DM multipath
device reload when one of the paths is down or up.

See https://bugzilla.redhat.com/show_bug.cgi?id=1312011
2016-04-12 07:44:28 +02:00
Evgeny Vereshchagin dbab702a2a tests: port udev-test to log_*_errno (#3015)
SYSTEMD_LOG_LEVEL=debug test/udev-test.pl is working now
Also, fixes CID 1354602
2016-04-11 21:31:57 +02:00
Martin Pitt 3de1521427 Install: correctly report symlink creations
All callers of create_symlink(), such as install_info_symlink_wants(), expect
that to return > 0 if it actually did something, and then return that number.
unit_file_enable() uses that to determine if any action was done
(carries_install_info != 0) and if not, show a "The unit files have no
[Install] section" warning.

Return 1 instead of 0 in the two code paths of create_symlink() when the link
was created or replaced with a new value.

This fixes getting a bogus "No [Install] section" warning when enabling a unit
with full path, like "systemctl enable /some/path/myunit.service".
2016-04-11 21:03:29 +02:00
Lennart Poettering 70a399c43a Merge pull request #3014 from msekletar/nspawn-empty-machine-id-v3
nspawn: always setup machine id (v3)
2016-04-11 17:27:11 +02:00
Michal Sekletar e01ff70a77 nspawn: always setup machine id
We check /etc/machine-id of the container and if it is already populated
we use value from there, possibly ignoring value of --uuid option from
the command line. When dealing with R/O image we setup transient machine
id.

Once we determined machine id of the container, we use this value for
registration with systemd-machined and we also export it via
container_uuid environment variable.

As registration with systemd-machined is done by the main nspawn process
we communicate container machine id established by setup_machine_id from
outer child to the main process by unix domain socket. Similarly to PID
of inner child.
2016-04-11 16:43:16 +02:00
Lennart Poettering 2270dfb852 Merge pull request #3012 from martinpitt/hwdb
hwdb updates
2016-04-11 16:07:16 +02:00