Commit Graph

29 Commits

Author SHA1 Message Date
Yu Watanabe
07e8c3055d tree-wide: drop several doubled space 2023-12-25 02:13:49 +09:00
Yu Watanabe
0e7a7cd4e9 locale,firstboot: add headers to vconsole.conf
Closes #29717.
Replaces #29760.

Co-authored-by: cunshunxia <cunshunxia@tencent.com>
2023-10-31 17:15:21 +09:00
Yu Watanabe
f155cb6d75 env-util: make write_env_file() optionally take headers
This also makes write_env_file() and write_env_file_label() optionally
take dir_fd, and drop write_env_file_at().

Preparation for later commits.
2023-10-31 17:15:21 +09:00
Lennart Poettering
f331434d13 env-file: when resolving env vars in command lines, collect list of unset/invalid ones
When resolving environment variables we currently silently resolve unset
and invalid environment variables to empty strings. Let's do this
slightly less silently: log about unset and invalid env vars, but still
resolve them to an empty string.

Fixes: #27036
2023-06-27 13:49:46 +02:00
licunlong
cd93ec5ed2 basic/env-file: also change to state PRE_KEY if we see NEWLINE in state COMMENT_ESCAPE
When we see a "\" in COMMENT state, we change the state to COMMENT_ESCAPE. When we got
a new character, we reset the state to COMMENT, but this character is not dispatched.
Usually the character is NEWLINE, if so we will stay in COMMENT state until we find
the next NEWLINE.

fix: https://github.com/systemd/systemd/issues/27975
2023-06-20 14:42:44 +08:00
Frantisek Sumsal
1469386b13 env-file: use free_and_replace() 2023-05-24 13:56:22 +02:00
Yu Watanabe
06692fdb5b env-file: introduce parse_env_file_fdv() 2023-04-11 12:33:14 +09:00
Luca Boccassi
6255bbe262 env: add load_env_file_pairs_fd() 2023-03-28 10:36:01 +01:00
Lennart Poettering
b839101aac fileio: add new helper fdopen_independent()
This is a combination of fdopen() and fd_reopen(). i.e. it first reopens
the fd, and then converts that into a FILE*.

We do this at various places already manually. let's move this into a
helper call of its own.
2023-03-23 22:48:00 +00:00
Daan De Meyer
361bcb2097 env-file: Add write_env_file_at() 2023-02-20 12:43:31 +01:00
Zbigniew Jędrzejewski-Szmek
a5937dcf39 tree-wide: change initialization to use EBADF instead of EBADFD
Those fds never were, so it's not fair to say that they are in "bad state".
Let's use the shorter and more direct errno.
2022-12-19 15:00:59 +01:00
Yu Watanabe
649512b934 env-file: introduce parse_env_file_fd() 2022-12-14 20:18:58 +09:00
Yu Watanabe
dd57a22e6a env-file: several cleanups
- add missing assertions,
- rename function arguments for storing results,
- add typedef for callback.
2022-12-14 20:18:58 +09:00
David Tardon
995340074e tree-wide: use ASSERT_PTR more 2022-09-13 08:13:27 +02:00
Zbigniew Jędrzejewski-Szmek
99aad9a2b9 systemctl: fix silent failure when --root is not found
Some calls to lookup_path_init() were not followed by any log emission.
E.g.:
$ SYSTEMD_LOG_LEVEL=debug systemctl --root=/missing enable unit; echo $?
1

Let's add a helper function and use it in various places.

$ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
1
$ SYSTEMCTL_SKIP_SYSV=1 build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
Failed to enable: No such file or directory.
1

The repeated error in the second case is not very nice, but this is a niche
case and I don't think it's worth the trouble to trying to avoid it.
2022-03-29 16:17:56 +02:00
Zbigniew Jędrzejewski-Szmek
25407ad2a7 basic/env-file: make load-env-file deduplicate entries with the same key
We generally assume parsing like the shell would do it, so the last value
should win when there are repeats.
2022-03-29 16:17:56 +02: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
Zbigniew Jędrzejewski-Szmek
09f5fc66f2 basic/env-file: inline one variable declaration 2022-03-18 10:22:20 +01:00
Lennart Poettering
319a4f4bc4 alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()
We recently started making more use of malloc_usable_size() and rely on
it (see the string_erase() story). Given that we don't really support
sytems where malloc_usable_size() cannot be trusted beyond statistics
anyway, let's go fully in and rework GREEDY_REALLOC() on top of it:
instead of passing around and maintaining the currenly allocated size
everywhere, let's just derive it automatically from
malloc_usable_size().

I am mostly after this for the simplicity this brings. It also brings
minor efficiency improvements I guess, but things become so much nicer
to look at if we can avoid these allocation size variables everywhere.

Note that the malloc_usable_size() man page says relying on it wasn't
"good programming practice", but I think it does this for reasons that
don't apply here: the greedy realloc logic specifically doesn't rely on
the returned extra size, beyond the fact that it is equal or larger than
what was requested.

(This commit was supposed to be a quick patch btw, but apparently we use
the greedy realloc stuff quite a bit across the codebase, so this ends
up touching *a*lot* of code.)
2021-05-19 16:42:37 +02:00
Yu Watanabe
f5fbe71d95 tree-wide: use UINT64_MAX or friends 2021-03-05 07:10:13 +09:00
Zbigniew Jędrzejewski-Szmek
13734c75b5 Refactor strv_env_replace() into strv_env_replace_consume()
All callers of strv_env_replace() would free the argument on error.
So let's follow the same pattern as with strv_consume (and similar
naming) and unconditionally "use up" the argument.
2021-02-16 16:10:14 +01:00
Yu Watanabe
db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering
de008e537d env-file: bring our decoding of double-quoted strings in env files in line with shell
In shell, inside of double quotes only a select few chars should be
escaped. If other chars are escaped this has no effect. Correct the list
of chars that need such escaping.

Also, make sure we can read back the stuff we wrote out without loss.

Fixes: #16788
2020-09-14 11:08:43 +02:00
Zbigniew Jędrzejewski-Szmek
f6301bdc81 environment-d-generator: output logs in debug mode
Those codepaths is only used by that generator, so simply adding a few debug
log lines should be OK.

Fixes #12259.
2019-08-30 13:17:37 +02:00
Zbigniew Jędrzejewski-Szmek
41f6e627d7 Make fopen_temporary and fopen_temporary_label unlocked
This is partially a refactoring, but also makes many more places use
unlocked operations implicitly, i.e. all users of fopen_temporary().
AFAICT, the uses are always for short-lived files which are not shared
externally, and are just used within the same context. Locking is not
necessary.
2019-04-12 11:44:56 +02:00
Lennart Poettering
57d2db22de env-file: (void)ify an unlink() call 2019-03-01 12:41:32 +01:00
Louis Taylor
e768a4f032 tree-wide: use '"' instead of '\"'
The escape used previously was redundant and made things more confusing.
2019-01-17 16:46:29 +00:00
Louis Taylor
e4a8db1fbd util-lib: follow shell syntax for escape in quotes
Fixes #10659.

This changes the behaviour of parsing environment files to more closely
follow POSIX shell standards.

This has the effect that these variables defined in a file:

    VAR1='\value'
    VAR2="\value"

Are now interpreted as `\value` instead of interpreting the `\`
character and interpreting them as `value`.

For more information about the behaviour followed, see:

	http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02
2019-01-17 13:42:54 +00:00
Lennart Poettering
686d13b9f2 util-lib: split out env file parsing code into env-file.c
It's quite complex, let's split this out.

No code changes, just some file rearranging.
2018-12-02 13:22:29 +01:00