2 This file is part of systemd.
4 Copyright 2017 Zbigniew Jędrzejewski-Szmek
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "conf-files.h"
27 #include "path-lookup.h"
29 static int environment_dirs(char ***ret
) {
30 _cleanup_strv_free_
char **dirs
= NULL
;
31 _cleanup_free_
char *c
= NULL
;
34 dirs
= strv_split_nulstr(CONF_PATHS_NULSTR("environment.d"));
38 /* ~/.config/systemd/environment.d */
39 r
= sd_path_home(SD_PATH_USER_CONFIGURATION
, "environment.d", &c
);
43 r
= strv_extend_front(&dirs
, c
);
52 static int load_and_print(void) {
53 _cleanup_strv_free_
char **dirs
= NULL
, **files
= NULL
, **env
= NULL
;
57 r
= environment_dirs(&dirs
);
61 r
= conf_files_list_strv(&files
, ".conf", NULL
, 0, (const char **) dirs
);
65 /* This will mutate the existing environment, based on the presumption
66 * that in case of failure, a partial update is better than none. */
68 STRV_FOREACH(i
, files
) {
69 r
= merge_env_file(&env
, NULL
, *i
);
74 STRV_FOREACH(i
, env
) {
76 _cleanup_free_
char *q
= NULL
;
81 q
= shell_maybe_quote(t
+ 1, ESCAPE_BACKSLASH
);
85 printf("%.*s=%s\n", (int) (t
- *i
), *i
, q
);
91 int main(int argc
, char *argv
[]) {
94 log_parse_environment();
98 log_error("This program takes no arguments.");
102 r
= load_and_print();
104 log_error_errno(r
, "Failed to load environment.d: %m");
106 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;