summaryrefslogtreecommitdiff
path: root/src/basic/env-util.h
Commit message (Collapse)AuthorAgeFilesLines
* env-util: introduce strv_env_assign_many()Yu Watanabe2023-03-281-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-211-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-02-011-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-201-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-201-1/+5
| | | | It's like replace_env, but lets you pass in a substring.
* Allow braceless variables to be expandedZbigniew Jędrzejewski-Szmek2017-02-201-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-201-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-201-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.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-0/+49
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/