summaryrefslogtreecommitdiffstats
path: root/src/basic/env-util.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* various: move ptr indicator to return valueZbigniew Jędrzejewski-Szmek2024-06-191-1/+1
|
* env-util: also rename getenv_uint64_secure() → secure_getenv_uint64()Lennart Poettering2024-02-281-1/+1
| | | | | As in the previous commit, let's not change the order of the words compared to the underlying glibc API.
* env-util: rename getenv_bool_secure() → secure_getenv_bool()Lennart Poettering2024-02-281-1/+1
| | | | | | The glibc API is behind the wrapper is called "secure_getenv()", hence our wrapper really should keep the order too, otherwise things are just too confusing.
* env-util: minor modernizationMike Yuan2024-02-151-2/+3
|
* env-util: Add helper to store current log levelAdrian Vovk2024-02-141-0/+1
| | | | | | | | This is useful after a fork but before an exec into a binary that uses systemd's logging utilities. For example, this should be used in dbus services that fork off worker processes: currently, the log level set by the LogControl dbus API will be lost because of the exec, and the worker process will not have the correct log level set.
* env-util: drop _pure_ for strv_env_get_nMike Yuan2024-01-291-2/+2
| | | | | | This function calls getenv() internally, making it non-pure, as envvars can change between two calls even if passed arguments are the same.
* env-util: don't use strlen_ptr if known non-NULLMike Yuan2024-01-291-2/+2
|
* env-util: add new setenvf() helperLennart Poettering2024-01-081-0/+2
| | | | And convert some pieces of code over.
* env-util: add strv_env_assignf() helperLennart Poettering2023-12-211-0/+1
|
* env-util: add helper to replace env blockLuca Boccassi2023-10-121-0/+2
|
* env-file: when resolving env vars in command lines, collect list of ↵Lennart Poettering2023-06-271-4/+4
| | | | | | | | | | | 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
* env-util: make strv_env_get() a static inline wrapper around strv_env_get_n()Lennart Poettering2023-06-271-1/+4
| | | | Let's make length = SIZE_MAX also mean "call strlen()".
* env-util: introduce proper flags type ReplaceEnvFlags for replace_env()Lennart Poettering2023-06-271-7/+7
|
* env-util: introduce strv_env_assign_many()Yu Watanabe2023-03-271-0/+2
|
* sysusers: make sp_lstchg shadow field reproducibleJohannes Schauer Marin Rodrigues2022-09-021-0/+2
| | | | | If the environment variable SOURCE_DATE_EPOCH is set, use its value instead of the current time.
* env-util: drop unsetenv_erase()Lennart Poettering2022-02-221-2/+0
| | | | | | Follow-up for: e99ca1474145f7fad38bb0255d344f4ad7717ef5 Found by @grigorig: https://github.com/systemd/systemd/commit/e99ca1474145f7fad38bb0255d344f4ad7717ef5#r67071855
* env-util: replace unsetenv_erase() by new getenv_steal_erase() helperLennart Poettering2022-02-201-0/+2
| | | | | | | | The new helper combines a bunch of steps every invocation of unsetenv_erase() did so far: getenv() + strdup() + unsetenv_erase(). Let's unify this into one helper that is harder to use incorrectly. It's in inspired by TAKE_PTR() in a way: get the env var out and invalidate where it was before.
* env-util: add unsetenv_erase() helperLennart Poettering2021-08-171-0/+2
| | | | Let's unify how we remove secrets from the env block.
* basic/env-util: add a mode where we pull in the variable value from environmentZbigniew Jędrzejewski-Szmek2021-08-111-0/+1
|
* Add implicit sentinel to strv_env_merge()Zbigniew Jędrzejewski-Szmek2021-08-111-1/+2
| | | | Just to make it a tiny bit nicer to use.
* basic/env-util: add putenv_dup()Zbigniew Jędrzejewski-Szmek2021-02-221-0/+3
|
* env-util: refactor parsing helper for SYSTEMD_SYSEXT_HIERARCHIES out of sysextLuca Boccassi2021-02-171-0/+4
|
* env-util: add strv_env_pairs_get helperLuca Boccassi2021-02-171-0/+1
|
* Refactor strv_env_replace() into strv_env_replace_consume()Zbigniew Jędrzejewski-Szmek2021-02-161-1/+1
| | | | | | 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.
* basic/env-util: drop now-unused strv_env_set()Zbigniew Jędrzejewski-Szmek2021-02-161-1/+0
|
* basic/env-util: add strv_env_assign() helperZbigniew Jędrzejewski-Szmek2021-02-161-0/+1
|
* basic/env-util: add variant of strv_env_replace() that does strdup internallyZbigniew Jędrzejewski-Szmek2021-02-151-0/+1
|
* env-util: introduce env_update_systemd_exec_pid()Yu Watanabe2021-01-311-0/+2
| | | | Will be used in later commits.
* basic/env-util: add little helper to call setenv or unsetenvZbigniew Jędrzejewski-Szmek2020-11-101-0/+3
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Introduce sc_arg_max() helperZbigniew Jędrzejewski-Szmek2019-05-211-0/+7
| | | | Just a cast and an assert.
* env-util: normalize one more flags enumLennart Poettering2019-01-071-3/+3
|
* core: rework serializationLennart Poettering2018-10-261-3/+0
| | | | | | | | | | | | | | | | | Let's be more careful with what we serialize: let's ensure we never serialize strings that are longer than LONG_LINE_MAX, so that we know we can read them back with read_line(…, LONG_LINE_MAX, …) safely. In order to implement this all serialization functions are move to serialize.[ch], and internally will do line size checks. We'd rather skip a serialization line (with a loud warning) than write an overly long line out. Of course, this is just a second level protection, after all the data we serialize shouldn't be this long in the first place. While we are at it also clean up logging: while serializing make sure to always log about errors immediately. Also, (void)ify all calls we don't expect errors in (or catch errors as part of the general fflush_and_check() at the end.
* env-util: make env-util.h self containedLennart Poettering2018-07-201-0/+1
| | | | The header file references strlen(), hence it should include string.h
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-04-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* nss: use secure_getenv for behaviour-modifying booleans (#6817)Zbigniew Jędrzejewski-Szmek2017-09-141-0/+1
| | | Follow up for fe102d6ab15731a199a7ea9f38c4f68d8959f86c.
* basic: support default and alternate values for env expansionRay Strode2017-02-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes it's useful to provide a default value during an environment expansion, if the environment variable isn't already set. For instance $XDG_DATA_DIRS is suppose to default to: /usr/local/share/:/usr/share/ if it's not yet set. That means callers wishing to augment XDG_DATA_DIRS need to manually add those two values. This commit changes replace_env to support the following shell compatible default value syntax: XDG_DATA_DIRS=/foo:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share} Likewise, it's useful to provide an alternate value during an environment expansion, if the environment variable isn't already set. For instance, $LD_LIBRARY_PATH will inadvertently search the current working directory if it starts or ends with a colon, so the following is usually wrong: LD_LIBRARY_PATH=/foo/lib:${LD_LIBRARY_PATH} To address that, this changes replace_env to support the following shell compatible alternate value syntax: LD_LIBRARY_PATH=/foo/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} [zj: gate the new syntax under REPLACE_ENV_ALLOW_EXTENDED switch, so existing callers are not modified.]
* basic: add replace_env_n functionRay Strode2017-02-211-1/+5
| | | | It's like replace_env, but lets you pass in a substring.
* Allow braceless variables to be expandedZbigniew Jędrzejewski-Szmek2017-02-211-0/+1
| | | | | | | | (Only in environment.d files.) We have only basic compatibility with shell syntax, but specifying variables without using braces is probably more common, and I think a lot of people would be surprised if this didn't work.
* basic: add new merge_env_file functionRay Strode2017-02-211-2/+6
| | | | | | | | | | | | merge_env_file is a new function, that's like load_env_file, but takes a pre-existing environment as an input argument. New environment entries are merged. Variable expansion is performed. Falling back to the process environment is supported (when a flag is set). Alternatively this could be implemented as passing an additional fallback environment array, but later on we're adding another flag to allow braceless expansion, and the two flags can be combined in one arg, so there's less stuff to pass around.
* core/manager: move environment serialization out to basic/env-util.cZbigniew Jędrzejewski-Szmek2017-02-211-0/+4
| | | | | | | | | | | | | This protocol is generally useful, we might just as well reuse it for the env. generators. The implementation is changed a bit: instead of making a new strv and freeing the old one, just mutate the original. This is much faster with larger arrays, while in fact atomicity is preserved, since we only either insert the new entry or not, without being in inconsistent state. v2: - fix confusion with return value
* core/load-fragment: modify existing environment instead of copying strv over ↵Zbigniew Jędrzejewski-Szmek2016-11-051-0/+1
| | | | and over
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-0/+1
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* execute: Add new PassEnvironment= directiveFilipe Brandenburger2015-11-111-0/+1
| | | | | | | | | | | | | | | | | | | | This directive allows passing environment variables from the system manager to spawned services. Variables in the system manager can be set inside a container by passing `--set-env=...` options to systemd-spawn. Tested with an on-disk test.service unit. Tested using multiple variable names on a single line, with an empty setting to clear the current list of variables, with non-existing variables. Tested using `systemd-run -p PassEnvironment=VARNAME` to confirm it works with transient units. Confirmed that `systemctl show` will display the PassEnvironment settings. Checked that man pages are generated correctly. No regressions in `make check`.
* systemctl: add a way to explicitly request client-side unit installingLennart Poettering2015-10-311-0/+2
| | | | | | | | | | | | | | This adds support for a new environment variable SYSTEMCTL_INSTALL_CLIENT_SIDE, that ensures that systemctl executes install operations client-side instead of passing them to PID1. This is useful in debugging situations, but even beyond that. However, we don't want to make it official API, hence let's just make it an undocumented environment variable. Similar, add a second variable, SYSTEMCTL_SKIP_SYSV which allows skipping the SysV chkconfig fall-back if set. This is useful for similar reasons, and exposed as undocumented as environment variable for similar reasons, too.