summaryrefslogtreecommitdiff
path: root/src/basic/env-util.c
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+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.
* basic: use automatic cleanup moreDavid Tardon2018-05-101-8/+5
|
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-04-271-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* basic/env-util: Allow newlines in values of environment variablesFilipe Brandenburger2018-03-161-3/+3
| | | | | They are allowed by the shell and the EnvironmentFile parsing passes them through, so we should just accept them, same as we accept tabs.
* coccinelle: add reallocarray() coccinelle scriptLennart Poettering2018-03-021-1/+1
| | | | | Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.
* basic: shorten the code a bit in two placesZbigniew Jędrzejewski-Szmek2018-02-261-15/+7
| | | | gcc complains that len might be used unitialized, but afaict, this is not true.
* 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.
* basic/env-util: don't relax unesaping of serialized environment stringsLubomir Rintel2017-10-111-1/+1
| | | | We wrote them ourselves -- they shouldn't contain invalid sequences.
* basic/env-util: drop the validation when deserializing environmentLubomir Rintel2017-10-111-5/+0
| | | | | | | | | | | | | The environment variables we've serialized can quite possibly contain characters outside the set allowed by env_assignment_is_valid(). In fact, my environment seems to contain a couple of these: * TERMCAP set by screen contains a '\x7f' character * BASH_FUNC_module%% variable has a '%' character in name Strict check of environment variables name and value certainly makes sense for unit files, but not so much for deserialization of values we already had in our environment.
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-1/+1
|
* nss: use secure_getenv for behaviour-modifying booleans (#6817)Zbigniew Jędrzejewski-Szmek2017-09-141-0/+10
| | | Follow up for fe102d6ab15731a199a7ea9f38c4f68d8959f86c.
* basic/env-util: when serializing, actually use escapingZbigniew Jędrzejewski-Szmek2017-06-231-1/+1
| | | | Fixes #6152.
* manager: just warn about an invalid environment entryZbigniew Jędrzejewski-Szmek2017-06-231-1/+1
| | | | | | Apart from bugs (as in #6152), this can happen if we ever make our requirements for environment entries more stringent. As with the rest of deserialization, we should just warn and continue.
* env-util: fix memory leak (#5962)Ronny Chevalier2017-05-141-1/+3
| | | If cunescape succeeds, but the assignment is not valid, uce is not freed.
* basic/env-util: drop leftover commentZbigniew Jędrzejewski-Szmek2017-02-211-1/+1
|
* basic: support default and alternate values for env expansionRay Strode2017-02-201-3/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2/+4
| | | | It's like replace_env, but lets you pass in a substring.
* Allow braceless variables to be expandedZbigniew Jędrzejewski-Szmek2017-02-201-2/+43
| | | | | | | | (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/env-util: use _cleanup_ in replace_env()Zbigniew Jędrzejewski-Szmek2017-02-201-13/+6
|
* basic: add new merge_env_file functionRay Strode2017-02-201-5/+12
| | | | | | | | | | | | 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.
* basic: drop unnecessary strempty() call in replace_envRay Strode2017-02-201-1/+1
| | | | | | | | | | strempty() converts a NULL value to empty string, so that it can be passed on to functions that don't support NULL. replace_env calls strempty before passing its value on to strappend. strappend supports NULL just fine, though, so this commit drops the strempty call.
* basic: fix strv_env_get_n for unclean arraysRay Strode2017-02-201-1/+1
| | | | | | | If an environment array has duplicates, strv_env_get_n returns the results for the first match. This is wrong, because later entries in the environment are supposed to replace earlier entries.
* basic/env-util: drop _pure_ from static functionZbigniew Jędrzejewski-Szmek2017-02-201-1/+1
|
* env-util,fileio: immediately replace variables in load_env_file_push()Zbigniew Jędrzejewski-Szmek2017-02-201-4/+26
| | | | | | | | | | | | | | | | | | | strv_env_replace was calling env_match(), which in effect allowed multiple values for the same key to be inserted into the environment block. That's pointless, because APIs to access variables only return a single value (the latest entry), so it's better to keep the block clean, i.e. with just a single entry for each key. Add a new helper function that simply tests if the part before '=' is equal in two strings and use that in strv_env_replace. In load_env_file_push, use strv_env_replace to immediately replace the previous assignment with a matching name. Afaict, none of the callers are materially affected by this change, but it seems like some pointless work was being done, if the same value was set multiple times. We'd go through parsing and assigning the value for each entry. With this change, we handle just the last one.
* core/manager: move environment serialization out to basic/env-util.cZbigniew Jędrzejewski-Szmek2017-02-201-0/+34
| | | | | | | | | | | | | 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
* basic/env-uil: fix assertion failure in strv_env_replace (#4688)Zbigniew Jędrzejewski-Szmek2016-11-171-1/+2
| | | | | | free_and_replace sets the setcond argument to NULL (it's designed to be used with _clenaup_ macros), and we don't want that here. Fixes #4684.
* core/load-fragment: modify existing environment instead of copying strv over ↵Zbigniew Jędrzejewski-Szmek2016-11-051-0/+22
| | | | and over
* tree-wide: use mfree moreZbigniew Jędrzejewski-Szmek2016-10-161-2/+1
|
* 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: re-sort includesThomas Hindoe Paaboel Andersen2015-12-011-1/+1
| | | | | My previous patch to only include what we use accidentially placed the added inlcudes in non-sorted order.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-2/+6
| | | | | 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/+15
| | | | | | | | | | | | | | | | | | | | 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/+11
| | | | | | | | | | | | | | 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.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-1/+2
|
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-1/+2
| | | | | | | | | | | | | | string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
* basic: fix env expansion for strings leading with two dollar signsMichal Schmidt2015-10-071-1/+1
| | | | | The way to escape a literal dollar sign is to write "$$". But this does not work right if it's at the beginning of the argument. Fix it.
* strv: convert strv_split_quotes into a generic strv_split_extractRichard Maw2015-08-071-1/+1
| | | | | | | | | strv_split_extract is to strv_split_quotes as extract_first_word was to unquote_first_word. Now there's extract_first_word for extracting a single argument, extract_many_words for extracting a bounded number of arguments, and strv_split_extract for extracting an arbitrary number of arguments.
* util: change unquote_*_word to extract_*_wordRichard Maw2015-08-071-1/+1
| | | | | It now takes a separators argument, which defaults to WHITESPACE if NULL is passed.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-0/+594
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/