Commit graph

72 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek ac097c841e Remove a bunch of unused variables
gcc does not warn about those, because of the _cleanup_ usage.
clang is smarter here.
2017-11-01 23:06:44 +01:00
Lennart Poettering 4aa1d31c89 Merge pull request #6974 from keszybz/clean-up-defines
Clean up define definitions
2017-10-04 19:25:30 +02:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Zbigniew Jędrzejewski-Szmek d2561cfdf7 install: consider globally enabled units as "enabled" for the user
We would not consider symlinks in /etc/systemd/user/*.{wants,requires}/
towards the user unit being "enabled", because the symlinks were not
located in "config" paths. But this is confusing to users, since those units
are clearly enabled and will be started. So let's muddle the definition of
enablement a bit to include the paths only accessible to root when looking for
enabled user units.

Fixes #4432.
2017-09-22 18:40:26 +02:00
Zbigniew Jędrzejewski-Szmek 23115a607e path-lookup: fix minor memleak
Introduced in a1f31f4715.
2017-09-19 20:14:22 +02:00
Zbigniew Jędrzejewski-Szmek a1f31f4715 core/manager: when running in test mode, use a temp dir for generated stuff
When running through systemd-analyze verify or with --test, we would
not run generators (environment or unit). But at the end, we would nuke
the generator dirs anyway.

Simplify things by actually running generators of both types, but redirecting
their output to a temporary directory. This has the advantage that we test more
code, and the verification is more complete.

Since now we are not touching the real generator directories, we also don't
delete them, which fixes #5609.
2017-09-14 19:41:24 +02:00
Lennart Poettering a4dde27d73 Merge pull request #5131 from keszybz/environment-generators
Environment generators
2017-02-21 11:11:44 +01:00
Zbigniew Jędrzejewski-Szmek f63c4aabb2 environment-generator: new generator to peruse environment.d
Why the strange name: the prefix is necessary to follow our own advice that
environment generators should have numerical prefixes. I also put -d- in the
name because otherwise the name was very easy to mistake with
systemd.environment-generator. This additional letter clarifies that this
on special generator that supports environment.d files.
2017-02-20 18:49:14 -05:00
Lennart Poettering c3c7eb7d7d path-lookup: if $HOME can be determined but $XDG_RUNTIME_DIR can't, is it
So far, if either $HOME or $XDG_RUNTIME_DIR is not set we wouldn't use
either, and fail acquire_config_dirs() and acquire_control_dirs() in
their entireties. With this change, let's make use of the variables we
can acquire, and don't bother with the other.

Specifically this means: in both acquire_config_dirs() and
acquire_control_dirs() handle ENXIO from user_config_dir() and
user_runtime_dir() directly, instead of propagating it up and handling
it in the caller.
2017-02-10 15:18:23 +01:00
Lennart Poettering b9418b053a path-lookup: drop redundant strv_isempty() check
If the strv is empty, then strv_extend_strv_concat() is a NOP anyway,
and hence there is no reason to guard for this explicitly.
2017-02-10 15:17:18 +01:00
Lennart Poettering c49970743e path-lookup: try harder acquiring them $HOME of a user
Let's use get_home_dir() for figuring out the home directory, so that
there's a good chance we succeed figuring out unit locations even if
$HOME isn't set.

Fixes: #5260
2017-02-10 15:16:11 +01:00
Thomas H. P. Andersen fcd574d4c1 path-lookup: use correct cleanup function for strv (#5007) 2017-01-03 21:02:39 +01:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Torstein Husebø 61233823aa treewide: fix typos and remove accidental repetition of words 2016-07-11 16:18:43 +02:00
Lennart Poettering 8f1e0ad415 path-lookup: optimize a common strv copy operation away
Follow-up for:

https://github.com/systemd/systemd/pull/3033#discussion_r59689398
2016-04-22 16:06:20 +02:00
Zbigniew Jędrzejewski-Szmek e215d211d2 shared/path-lookup: fix leak
CID #1354671: char **l would be leaked.

Also rename l to paths, to make the code easier to read,
and do strv deduplication immediately when extending. No need to allocate
strings to remove them a few lines down.
2016-04-13 21:10:33 -04:00
Zbigniew Jędrzejewski-Szmek 81d621034b tree-wide: remove useless NULLs from strjoina
The coccinelle patch didn't work in some places, I have no idea why.
2016-04-13 08:56:44 -04:00
Lennart Poettering 4943d14306 systemctl: don't confuse sysv code with generated units
The SysV compat code checks whether there's a native unit file before looking
for a SysV init script. Since the newest rework generated units will show up in
the unit path, and hence the checks ended up assuming that there always was a
native unit file for each init script: the generated one.

With this change the generated unit file directory is suppressed from the
search path when this check is done, to avoid the confusion.
2016-04-12 13:43:32 +02:00
Lennart Poettering a69b4fb0f8 path-lookup: move generator_binary_paths() to end of file
Let's keep the code that manipulates LookupPaths together, and move
generator_binary_paths() to the end of the .h and .c files, since it is not
strictly related to that.
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 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 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 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 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 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 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 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 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
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Thomas Hindoe Paaboel Andersen a8fbdf5424 shared: include what we use
The next step of a general cleanup of our includes. This one mostly
adds missing includes but there are a few removals as well.
2015-12-06 13:49:33 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 0f47436510 util-lib: get_current_dir_name() can return errors other than ENOMEM
get_current_dir_name() can return a variety of errors, not just ENOMEM,
hence don't blindly turn its errors to ENOMEM, but return correct errors
in path_make_absolute_cwd().

This trickles down into a couple of other functions, some of which
receive unrelated minor fixes too with this commit.
2015-10-24 23:03:49 +02:00
Lennart Poettering e287086b8a ask-password: add support for caching passwords in the kernel keyring
This adds support for caching harddisk passwords in the kernel keyring
if it is available, thus supporting caching without Plymouth being
around.

This is also useful for hooking up "gdm-auto-login" with the collected
boot-time harddisk password, in order to support gnome keyring
passphrase unlocking via the HDD password, if it is the same.

Any passwords added to the kernel keyring this way have a timeout of
2.5min at which time they are purged from the kernel.
2015-10-07 12:26:14 +02:00
Lennart Poettering 6796073e33 tree-wide: make use of the fact that strv_free() returns NULL
Another Coccinelle patch.
2015-09-09 23:05:58 +02:00
Lennart Poettering b2c23da8ce core: rename SystemdRunningAs to ManagerRunningAs
It's primarily just a property of the Manager object after all, and we
try to refer to PID 1 as "manager" instead of "systemd", hence let's to
stick to this here too.
2015-05-11 22:51:49 +02:00
Zbigniew Jędrzejewski-Szmek a8ffe6fbcb sysv-generator: initialize LookupPaths just once
With debugging on, sysv-generator would print the full set of
lookup paths for *every* sysv script.

While at it, pass LookupPaths as a pointer in sysv-generator,
and constify it everywhere.
2015-03-14 23:03:21 -04:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Zbigniew Jędrzejewski-Szmek 33e1e5a756 path-lookup: allow /run to override /etc in generator search
Generators are different than unit files: they are never automatically
generated, so there's no point in allowing /etc to override /run. On
the other hand, overriding /etc might be useful in some cases.
2015-01-11 18:17:33 -05:00
Zbigniew Jędrzejewski-Szmek e801700e9a Implement masking and overriding of generators
Sometimes it is necessary to stop a generator from running. Either
because of a bug, or for testing, or some other reason. The only way
to do that would be to rename or chmod the generator binary, which is
inconvenient and does not survive upgrades. Allow masking and
overriding generators similarly to units and other configuration
files.

For the systemd instance, masking would be more common, rather than
overriding generators. For the user instances, it may also be useful
for users to have generators in $XDG_CONFIG_HOME to augment or
override system-wide generators.

Directories are searched according to the usual scheme (/usr/lib,
/usr/local/lib, /run, /etc), and files with the same name in higher
priority directories override files with the same name in lower
priority directories. Empty files and links to /dev/null mask a given
name.

https://bugs.freedesktop.org/show_bug.cgi?id=87230
2015-01-11 18:17:33 -05:00
Ivan Shapovalov 60d27f1916 path-lookup, systemctl: export lookup_paths_init_from_scope() from shared/install.c and use it 2015-01-05 11:13:30 -05:00