1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2017 Zbigniew Jędrzejewski-Szmek
8 #include "conf-files.h"
13 #include "path-lookup.h"
15 static int environment_dirs(char ***ret
) {
16 _cleanup_strv_free_
char **dirs
= NULL
;
17 _cleanup_free_
char *c
= NULL
;
20 dirs
= strv_split_nulstr(CONF_PATHS_NULSTR("environment.d"));
24 /* ~/.config/systemd/environment.d */
25 r
= sd_path_home(SD_PATH_USER_CONFIGURATION
, "environment.d", &c
);
29 r
= strv_extend_front(&dirs
, c
);
33 *ret
= TAKE_PTR(dirs
);
37 static int load_and_print(void) {
38 _cleanup_strv_free_
char **dirs
= NULL
, **files
= NULL
, **env
= NULL
;
42 r
= environment_dirs(&dirs
);
46 r
= conf_files_list_strv(&files
, ".conf", NULL
, 0, (const char **) dirs
);
50 /* This will mutate the existing environment, based on the presumption
51 * that in case of failure, a partial update is better than none. */
53 STRV_FOREACH(i
, files
) {
54 r
= merge_env_file(&env
, NULL
, *i
);
59 STRV_FOREACH(i
, env
) {
61 _cleanup_free_
char *q
= NULL
;
66 q
= shell_maybe_quote(t
+ 1, ESCAPE_BACKSLASH
);
70 printf("%.*s=%s\n", (int) (t
- *i
), *i
, q
);
76 int main(int argc
, char *argv
[]) {
79 log_parse_environment();
83 log_error("This program takes no arguments.");
89 log_error_errno(r
, "Failed to load environment.d: %m");
91 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;