Commit Graph
236 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek d8a91c6b9f shared/conf-parser: use chase() in config_parse_many_files()
The function was partially implementing chroot lookups. It would be given
file names that were prefixed with the chroot, so it would mostly work.
But if any of those files were symlinks, fopen() would do the wrong thing.

Also we don't need locking.

So give 'root' as the argument and use chase_and_fopen_unlocked() to get
proper chroot-aware lookups.

The only place where config_parse_many() is called with root is is repart.c.
So this is a follow-up for e594a3b154 and
34f2fd5096.
2024-03-07 18:49:44 +01:00
Zbigniew Jędrzejewski-Szmek e5abff372d shared/conf-parser: collapse pkgdir and conf_file args into one
This essentially reverts 5656cdfeea. I find it
much easier to understand what is going on when the
path-relative-to-the-search-path is passed in full, instead of being constructed
from two parts, with one of the parts being implicit in some places.

Also, we call 'systemd-analyze cat-config <path>' with <path> with the same
meaning, so this makes the internal and external APIs more consistent.
2024-03-07 18:49:44 +01:00
Antonio Alvarez Feijoo 0fa25bd5f4 conf-parser: fix OOM check 2024-01-30 12:46:24 +00:00
Yu Watanabe 4207f6c05d network/route-nexthop: make GatewayOnLink= support an empty string
And invalidate the route section if an invalid string is specified.
2024-01-12 09:44:03 +09:00
Yu Watanabe 967cd1712c Merge pull request #30867 from dtardon/udev-conf-dropins
Allow dropins for udev.conf
2024-01-12 06:37:23 +09:00
David Tardon 5656cdfeea conf-parser: generalize config_parse_config_file() 2024-01-11 13:24:32 +09:00
Luca Boccassi d6b39152a9 Merge pull request #30717 from yuwata/network-ref-unref
network: introduce address_ref() and friends
2024-01-10 19:34:48 +00:00
Yu Watanabe 9aa3c07947 network/route-metric: invalidate [Route] section if an invalid string is specified
Follow-up for 18c4c5d84f.
2024-01-07 14:04:00 +09:00
Yu Watanabe 18c4c5d84f network/route: make the route section invalid when an invalid MTUBytes= is specified
We usually set the invalid flag for a section if a setting in the section has
an invalid value. Let's also do the same thing for MTUBytes= in [Route].
2024-01-04 23:18:28 +09:00
Yu Watanabe b46d1694c4 conf-parser: expose config_section_{hash,compare}_func()
They will be used in later commits.
2024-01-04 04:58:36 +09:00
Yu Watanabe c01a5c0527 siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake.

This also introduce in_addr_hash_func().

No functional change, just refactoring.
2023-12-25 15:38:59 +09:00
Mike Yuan 0ca66adfcc conf-parser: only read the first found main config file
Follow-up for 93f1da4556
and 8ea288db01

Before the offending commits, we only read the first found
main config file. If the main config file is symlinked to/as
a drop-in, we should break instead of continuing, for it to
be read later.
2023-11-22 17:44:54 +00:00
Mike Yuan 8ea288db01 conf-parser: remove unused condition
Follow-up for 9ac2f3c4d2

config_parse() returns 0 only on ENOENT, which can
never happen since we pass the FILE stream.
2023-11-13 10:32:38 +00:00
Mike Yuan 9ac2f3c4d2 conf-parser: pin seen config files
Follow-up for 93f1da4556

Addresses https://github.com/systemd/systemd/commit/93f1da45566d064f4f053b37bbac2813631f58b1#r132152321
2023-11-13 05:11:26 +09:00
Yu Watanabe 62c9beaa2c conf-parser: inline variable declaration 2023-11-13 00:46:34 +09:00
Lennart Poettering b71a721fbc parse-util: add parse_tristate() and use it everywhere
We parse tristates all the time, let's add an explicit parser for them.
2023-11-02 04:52:16 +09:00
Zbigniew Jędrzejewski-Szmek 851cdffd1b network: use a common helper to parse bounded ranges
This compresses repetetive code and makes it easier to add new options
in networkd. The formatting of error messages becomes uniform. The
error message always specifies the rvalue literally, instead of using
a "descriptive name". This makes the message much easier to handle for
the user.

I opted to add just one parser, and wrap it with inline functions to proxy
the type. This is less verbose than copying functions for each type
separately, and the compiler should be able to get rid of the inline wrapper
almost entirely.

asserts are reordered to use the same order as the parameter list.
This makes the code easier to read.

No functional change intended, apart from the difference in error message
formatting.
2023-09-22 08:16:47 +02:00
Mike Yuan 93f1da4556 conf-parser: parse main config first only if not symlinked to/as drop-in
Otherwise we'll skip parsing main config directly.

Replaces #27152
Replaces #28956:
chase() is an overkill for determining whether
two files are the same. We only need to check
if the inodes are the same.
2023-09-08 16:25:12 +02:00
Yu Watanabe e63c6e9ffa conf-parser: introduce ordered_hashmap_by_section_find_unused_line() 2023-09-08 12:55:44 +09:00
Yu Watanabe d9171a230d conf-parser: check overflow in hashmap_find_free_section_line()
Also, this also renames the function, and makes it optionally takes
a filename.
2023-09-08 12:55:44 +09:00
Yu Watanabe 08ca764d0a conf-parser: modernize config_section_new()
- add assertions,
- rename argument to store result.
2023-09-08 12:55:44 +09:00
Zbigniew Jędrzejewski-Szmek aea3f594db various: use id128_from_string_not_null()
No functional change. In config_parse_address_generation_type() we would set
the output parameter and then say it's ignored, so it _looked_ like an error in
the code, but the variable was always initialized to SD_ID128_NULL anyway, so
the code was actually fine.
2023-09-02 14:16:25 +03:00
Zbigniew Jędrzejewski-Szmek da89046643 tree-wide: "<n>bit" → "<n>-bit"
In some places, "<n> bits" is used when more appropriate.
2023-07-02 11:10:12 +01:00
Mike Yuan 35c0e3444d conf-parser: move config_get_dropin_files to conf-files 2023-05-21 15:46:25 +08:00
Daan De Meyer 947f59ba2b conf-parser: Add root argument to config_parse_many() 2023-05-12 17:52:32 +02:00
Franck Bui 07e0ffc823 conf: replace config_parse_many_nulstr() with config_parse_config_file()
All daemons use a similar scheme to read their main config files and theirs
drop-ins. The main config files are always stored in /etc/systemd directory and
it's easy enough to construct the name of the drop-in directories based on the
name of the main config file.

Hence the new helper does that internally, which allows to reduce and simplify
the args passed previously to config_parse_many_nulstr().

Besides the overall code simplification it results:

  16 files changed, 87 insertions(+), 159 deletions(-)

it allows to identify clearly the locations in the code where configuration
files are parsed.
2023-03-14 03:31:21 +09:00
Daan De Meyer 12e2b70f9b nulstr-util: Declare NULSTR_FOREACH() iterator inline 2022-11-11 16:31:32 +01:00
Zbigniew Jędrzejewski-Szmek 28db6fbff1 Rename def.h to constants.h
The name "def.h" originates from before the rule of "no needless abbreviations"
was established. Let's rename the file to clarify that it contains a collection
of various semi-related constants.
2022-11-08 18:21:10 +01:00
David Tardon 995340074e tree-wide: use ASSERT_PTR more 2022-09-13 08:13:27 +02:00
Michal Sekletar 4ee8176fe3 core/load-fragment: move config_parse_sec_fix_0 to src/shared 2022-08-23 11:00:20 +02:00
Richard Phibel ead3a3fc87 config-parser: Add list of drop-in files as return argument of config_parse_many
This will be used to save the list of drop-in files for each partition
2022-08-12 12:48:29 +02:00
Yu Watanabe acfbd71ccc udev: save stats of all udev rules file
The mtime of directory is not updated when an existing rule file is
changed. Hence, paths_check_timestamp() is not reliable.
2022-07-23 15:05:22 +09:00
Yu Watanabe 3f4dfd9d87 conf-parser: add a boolean flag for config_get_stats_by_path() to control if drop-in configs are checked
Preparation for later commits.
2022-07-23 15:03:48 +09:00
Zbigniew Jędrzejewski-Szmek 2034c8b883 tree-wide: drop de-constifying casts for strv iteration
When the the iterator variable is declared automatically, it "inherits" the
const/non-const status from the argument. We don't need to cast a const
table to non-const. If we had a programming error and tried to modify the
string, the compiler could now catch this.
2022-05-08 22:47:50 +02:00
Yu Watanabe bdb2d3c688 udev: check stats of .link files and their drop-in files
Fixes #23128.
2022-05-03 10:26:22 +02:00
Zbigniew Jędrzejewski-Szmek c3eaba2d3d Move path_simplify_and_warn() to new shared/parse-helpers.c
This is a high-level function, and it belongs in libsystemd-shared. This way we
don't end up linking a separate copy into various binaries. It would even end
up in libsystemd, where it is not needed. (Maybe it'd be removed in some
optimization phase, but it's better to not rely on that.)

$ grep -l -r -a 'path is not absolute%s' build/
build/libnss_systemd.so.2
build/pam_systemd_home.so
build/test-dlopen
build/src/basic/libbasic.a.p/path-util.c.o
build/src/basic/libbasic.a
build/src/shared/libsystemd-shared-249.so
build/test-bus-error
build/libnss_mymachines.so.2
build/pam_systemd.so
build/libnss_resolve.so.2
build/libnss_myhostname.so.2
build/libsystemd.so.0.32.0
build/libudev.so.1.7.2

$ grep -l -r -a 'path is not absolute%s' build/
build/src/shared/libsystemd-shared-251.a.p/parse-helpers.c.o
build/src/shared/libsystemd-shared-251.a
build/src/shared/libsystemd-shared-251.so

No functional change.
2022-04-07 18:25:55 +02:00
Yu Watanabe 798931160e tree-wide: add a space after if, switch, for, and while 2022-04-01 22:48:42 +09:00
Yu Watanabe de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Yu Watanabe fa787a13e2 conf-parser: introduce config_parse_dns_name() and config_parse_hostname()
This makes nspawn refuse hostnames which are invalid DNS domain names.
2022-03-10 14:47:19 +09:00
Yu Watanabe e289ce7f67 conf-parser: introduce CONFIG_PARSE_STRING_ASCII flag
When the flag is set, the string which contains non-ascii characters
will be refused.
2022-03-10 14:43:48 +09:00
Yu Watanabe 3f87eaa5d8 conf-parser: merge config_parse_string() and config_parse_safe_string()
This also makes unsafe strings escaped when logged. Otherwise,
journalctl may not show the log message unless '--all' is specified.
2022-03-10 14:43:43 +09:00
Lennart Poettering 65a0ede2ed conf-parser: add specific parser for PID values 2022-02-09 10:17:37 +01:00
Lennart Poettering 0b95409928 conf-parser: update config_item_*_lookup() to follow modern coding style
Let's rename the return parameters ret_xyz, and always initialize them
if we return >= 0, as per our current coding style.
2022-02-09 10:17:23 +01:00
Lennart Poettering cec7f09dc8 conf-parser: refuse section headers with control characters early, just in case 2022-02-09 10:17:20 +01:00
Lennart Poettering 73a4ac8a75 conf-parser: minor refactorings/modernizations 2022-02-09 10:17:17 +01:00
Lennart Poettering deec0b6dd5 conf-parser: use _cleanup_free_ where appropriate 2022-02-09 10:17:13 +01:00
Lennart Poettering 2d17d699bb conf-parse: add generic config_parse_safe_string() helper
This helper is just like config_parse_string() but does some superficial
checks for control characters and quotes.

In most cases we currently use config_parse_string() we probably want to
use config_parse_safe_string() for safety reasons.
2022-02-09 10:16:42 +01:00
Yu Watanabe 307fe3cdf2 network: rename NetworkConfigSection -> ConfigSection
And move it and relevant functions to conf-parser.[ch].
2022-01-19 14:57:59 +09:00
Thomas Blume 6e8791a042 systemd-coredump: allow setting external core size to infinity
Make it compatible to the ulimit setting: unlimited
2021-11-19 09:23:52 +01:00
Yu Watanabe 99628f363b conf-parser: introduce config_parse_hw_addr() and config_parse_hw_addrs() 2021-11-09 21:39:09 +09:00