Commit Graph

30967 Commits

Author SHA1 Message Date
Lennart Poettering c2288ade1e bus-unit-util: slightly tweak log output for unknown props
Pretty:

        Unknown assignment Foo=bar.

Prettier:

        Unknown assignment: Foo=bar
2017-11-29 20:12:26 +01:00
Lennart Poettering f53bddf308 run: rearrange error handling when adding unit properties
Let's always leave logging to the call that actually added the fields to
the bus message. This way we don't get duplicate logging whenver
bus_append_unit_property_assignment() ends up being called, which does
all its logging on its own (and probably should do, as it can output
much more precise errors).
2017-11-29 20:12:26 +01:00
Lennart Poettering 147fe484c1 bus-unit-util: add proper MemorySwapMax= serialization
Fixes: #7505
2017-11-29 20:12:26 +01:00
Lennart Poettering 66a892ae3d core: accept MemorySwapMax= properties that are scaled, too
Let's do what we already do for MemoryMax= and friends for
MemorySwapMax= too.
2017-11-29 20:12:26 +01:00
Lennart Poettering 421eaea0d1 tty-ask-password-agent: drop NULL sentinel
found by coccinelle
2017-11-29 20:12:26 +01:00
Lennart Poettering 2d0bc68450 coccinelle: add a run-coccinelle.sh script that runs all scripts
One day we should start running something like this as part of CI so
that non-well-formed commits are not even accepted...
2017-11-29 20:12:26 +01:00
Lennart Poettering a2d61f0746 coccinelle: fix IN_SET/!IN_SET scripts, and apply some changes it found
IN_SET only works for constant values, hence clarify that. Moreover, we
declared a statement "s" we never made use of. Drop it.

Also, for both scripts, let's support 10 items. More causes spatch to
die with "Stack overflow" for me.
2017-11-29 20:12:26 +01:00
Lennart Poettering 7b943bb7e3 tree-wide: use strv_isempty() instead of strv_length() == 0
It's a lot faster in many cases, since it's O(1) rather than O(n).
2017-11-29 12:41:08 +01:00
Lennart Poettering 5716965132 bus-unit-util: properly serialize EnvironmentFile= empty assignment
In that case we need to generate an empty array.
2017-11-29 12:34:12 +01:00
Lennart Poettering 7ae8162f29 tests: fix description of TEST-14-MACHINE-ID
It used the same description as TEST-01, and that's hardly helpful.
2017-11-29 12:34:12 +01:00
Lennart Poettering 50fb00b707 core: use safe_fclose() where we can 2017-11-29 12:34:12 +01:00
Lennart Poettering 7d7a99ac9f fileio: document why fileio-label.c and fileio.c are two different modules 2017-11-29 12:34:12 +01:00
Lennart Poettering 91d2f19594 documentation: add document listing all unit file settings also supported for transient units
Unfortunately, there are far too many properties currently not
accessible to transient units. The first step to opening them all up is
to figure out which ones they are.
2017-11-29 12:34:12 +01:00
Lennart Poettering f6c66be1dc core: open up all ExecXYZ= fields of service units to transient units
Fixes: #7400
2017-11-29 12:34:12 +01:00
Lennart Poettering 45639f1be5 core: never remove "transient" and "control" directories from unit search path
This changes the unit search path logic to never drop the transient and
control directories from the unit search path. This is necessary as we
add new entries to both during runtime, due to the "systemctl
set-property" and transient unit logic.

Previously, the "transient" directory was created during early boot to
deal with this, but the "control" directories were not covered like
that. Creating the control directories early at boot is not possible
however, as /etc might be read-only then, and we do define a persistent
control directory. Hence, let's create these dirs on-demand when we need
them, and make sure the search path clean-up logic never drops them from
the search path even if they are initially missing.

(Also, always create these paths properly labelled)
2017-11-29 12:34:12 +01:00
Lennart Poettering 45a7b16bae core: don't reference rescue/emergency targets in --user mode
They are only defined for system mode, hence let's not check for them in
--user mode.

Follow-up for #7433
2017-11-29 12:34:12 +01:00
Lennart Poettering 0126c8f3f6 core: minor simplification 2017-11-29 12:34:12 +01:00
Lennart Poettering fbc5883523 path-lookup: LookupPathsFlags are a flags type, hence define it like one
We shouldn't rely on C's incremental assignment of values of enums for
bit fields. That'll work only between the first two flags, but for
everything following will break horrible. Hence, let's avoid any
ambiguity here, and let's clearly define the flags as shifts of 1.
2017-11-29 12:34:12 +01:00
Lennart Poettering e9f4aabd80 systemctl: reword "needs-reload" message a bit
This message is displayed either when the unit file itself is newer than
what is loaded, but also when any of the drop-ins is newer. Say so in
the message, in order not to confuse the user unnecessarily.
2017-11-29 12:34:12 +01:00
Lennart Poettering 721060d446 core: allow changing the description for units dynamically at runtime
This makes "systemctl set-property foobar.service Description=waldo"
work.

See: #7245
2017-11-29 12:34:12 +01:00
Lennart Poettering e74f76ca86 tree-wide: generate SD_BUS_ERROR_INVALID_ARGS when we get invalid arguments on bus calls
Let's make sure that when we return a D-Bus error, we return a native
one, if we generate it ourselves, and use errno-based error
synthetization only if we received an errno ourselves. Yes, this makes
things slightly longer, but is highly misleading as we propagate D-Bus
errors, and not errnos to the client.
2017-11-29 12:34:12 +01:00
Lennart Poettering 2e59b241ca core: add proper escaping to writing of drop-ins/transient unit files
This majorly refactors the transient unit file and drop-in writing
logic, so that we properly C-escape and specifier-escape (% → %%)
everything we write out, so that when we read it back again, specifiers
are parsed that aren't supposed to be parsed.

This renames unit_write_drop_in() and friends by unit_write_setting().
The name change is supposed to clarify that the functions are not only
used to write drop-in files, but also transient unit files.

The previous "mode" parameter to this function is replaced by a more
generic "flags", which knows additional flags for implicit C-style and
specifier escaping before writing things out. This can cover most
properties where either form of escaping is defined. For the cases where
this isn't sufficient, we add helpers unit_escape_setting() and
unit_concat_strv() for escaping individual strings or strvs properly.

While we are at it, we also prettify generation of transient unit files:
we try to reduce the number of section headers written out: previously
we'd write the right section header our for each setting. With this
change we do so only if the setting lives in a different section than
the one before.

(This should also be considered preparation for when we add proper APIs
to systemd to write normal, persistant unit files through the bus API)
2017-11-29 12:34:12 +01:00
Lennart Poettering ddd59d0c7f logind: fix sysfs change trigger code
We can't create files in sysfs, hence don't bother. Also if we ignore
the return value, do so explicitly by casting to void.
2017-11-29 12:32:57 +01:00
Lennart Poettering 98bad05e75 generators: be more careful when writing unit settings that support specifier expansion
Let's always escape strings we receive from the user before writing them
out to unit file settings that suppor specifier expansion, so that user
strings are transported as-is.
2017-11-29 12:32:57 +01:00
Lennart Poettering b238be1e0d core: enable specifier expansion for What=/Where=/Type=/SourcePath= too
Using specifiers in these settings isn't particularly useful by itself,
but it unifies behaviour a bit. It's kinda surprising that What= in
mount units resolves specifies, but Where= does not. Hence let's add
that too. Also, it's surprising Where=/What= in mount units behaves
differently than in automount and swap units, hence resolve specifiers
there too. Then, Type= in mount units is nowadays an arbitrary,
sometimes non-trivial string (think fuse!), hence let's also expand
specifiers there, to match the rest of the mount settings.

This has the benefit that when writing code that generates unit files,
less care has to be taken to check whether escaping of specifiers is
necessary or not: broadly everything that takes arbitrary user strings
now does specifier expansion, while enums/numerics/booleans do not.
2017-11-29 12:32:57 +01:00
Lennart Poettering 6c5def2ff2 core: process C-style escapes in UnsetEnvironment=
We process C-style escapes in Environment=, hence we should process it
in UnsetEnvironment= too, as the latter accepts assignments much like
the former, including arbitrary values specified by the user.
2017-11-29 12:32:56 +01:00
Lennart Poettering 613613f1ee core: use config_parse_unit_string_printf() for decoding RebootArgument=
All other cases where we accept a reboot argument are decoded with
config_parse_unit_string_printf() rather than
config_parse_unit_path_printf(), and that's really the only thing what
makes sense here, hence adjust this here, too.
2017-11-29 12:32:56 +01:00
Lennart Poettering 35838def32 CODING_STYLE: document the order in which unescaping + specifier expansion should be done 2017-11-29 12:32:56 +01:00
Lennart Poettering 36444d2213 specifier: unify specifier implementations for user-related specifiers
The code in install-printf.c and unit-printf.c for these is pretty much
the same and very generic. Let's move this all over to the generic
specifier.c, and share the implementations.
2017-11-29 12:32:56 +01:00
Lennart Poettering e82f30d17f specifier: add helper for escaping '%' characters to avoid making them subject for expansion
This is ultimately just a wrapper around strreplace(), but it makes
things a bit more self-descriptive.
2017-11-29 12:32:56 +01:00
Lennart Poettering 9d73565ac0 string-util: update strreplace() a bit, use GREEDY_REALLOC() 2017-11-29 12:32:56 +01:00
Lennart Poettering 6171b8225f core: drop specifier expansion when parsing transient dbus properties
Specifier expansion (much like C escape handling) should be a helper for
writing unit files, but should be nothing we do on programatic APIs. For
those, the client can do the necessary replacements anyway, and we
really should be careful with doing such string processing of data we
get via lower level programmatic APIs.

We currently do specifier expansion only for the env var transient unit
APIs, no other properties do this. Let's remove it here too, to be fully
systematic.

Yes, in a way this is API breakage, but then again this API isn't
documented yet, and an outlier, hence let's clear this up now, before it
is too late.
2017-11-29 12:32:53 +01:00
Yu Watanabe 3235b4e70c
Merge pull request #7492 from keszybz/coverity-fixes
A few more cleanups based on coverity and valgrind
2017-11-29 12:50:49 +09:00
Zbigniew Jędrzejewski-Szmek ae34a10bac udev/collect: use _cleanup_ in one more place
This doesn't make the code pretty, but it at least makes it a tiny bit shorter.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 3176084ff2 udev/collect: remove dead conditional
Coverity rightly says that 'word' is assigned to 'ptr', and 'word'
was assigned from 'ptr' (yikes) right after a non-null check.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 2504834861 journal: avoid undefined behaviour in float division by 0.0
Coverity says that's undefined. I'm pretty sure we always would get a nan, but
let's avoid (formally) undefined behaviour since that can cause compilers to do
strange things.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek b921fcb2ac networkd: fix memleak of Rules
This was the issue mentioned in 93f9da6e0a.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek f916819053 journal: use new helpers with journal_file_close
journal_file_close_set() is not necessary anymore.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 1599f593d6 journal-remote: add helper function and use hashmap_free_with_destructor 2017-11-28 21:34:46 +01:00
Zbigniew Jędrzejewski-Szmek 6dd1c36839 cryptsetup-generator: add helper function and use hashmap_free_with_destructor 2017-11-28 21:34:41 +01:00
Zbigniew Jędrzejewski-Szmek 39ab16e397 coredump: fix typo and use hashmap_free_with_destructor 2017-11-28 21:34:34 +01:00
Zbigniew Jędrzejewski-Szmek e85b096b43 machine-image: convert image_hashmap_free() to an static inline helper 2017-11-28 21:30:43 +01:00
Zbigniew Jędrzejewski-Szmek 224b0e7ad0 Add set/hashmap helpers for non-trivial freeing and use where straighforward
A macro is needed because otherwise we couldn't ensure type safety.
Some simple tests are included.
No functional change intended.
2017-11-28 21:30:30 +01:00
Zbigniew Jędrzejewski-Szmek ec1d290903 Use hashmap_free_free where appropriate 2017-11-28 21:26:37 +01:00
Zbigniew Jędrzejewski-Szmek 5c4912ea61
Merge pull request #7490 from yuwata/test-basic
add more tests for basic functions
2017-11-28 18:15:30 +01:00
Susant Sahani fbdb6605b5 networkd: Add comment for setting_mtu #7460 (#7489)
Follow up #7460
2017-11-28 17:24:52 +01:00
Lennart Poettering 4de8d3f59e
Merge pull request #7486 from keszybz/coverity-fixes
Fixes for issues spotted by coverity (and some cleanups)
2017-11-28 15:04:11 +01:00
Yu Watanabe 23cc81e7c2 test-cap-list: add more tests about capability_set_{from,to}_string() 2017-11-28 22:17:00 +09:00
Yu Watanabe 4c1a95fd84 test: move tests about cap_list_cap() from test-cap-list to test-capability 2017-11-28 22:14:54 +09:00
Yu Watanabe db4bd5bd62 cap-list: check range of numeric value 2017-11-28 22:06:34 +09:00