1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "conf-files.h"
10 #include "path-lookup.h"
12 static int environment_dirs(char ***ret
) {
13 _cleanup_strv_free_
char **dirs
= NULL
;
14 _cleanup_free_
char *c
= NULL
;
17 dirs
= strv_new(CONF_PATHS_USR("environment.d"), NULL
);
21 /* ~/.config/systemd/environment.d */
22 r
= sd_path_home(SD_PATH_USER_CONFIGURATION
, "environment.d", &c
);
26 r
= strv_extend_front(&dirs
, c
);
30 *ret
= TAKE_PTR(dirs
);
34 static int load_and_print(void) {
35 _cleanup_strv_free_
char **dirs
= NULL
, **files
= NULL
, **env
= NULL
;
39 r
= environment_dirs(&dirs
);
43 r
= conf_files_list_strv(&files
, ".conf", NULL
, 0, (const char **) dirs
);
47 /* This will mutate the existing environment, based on the presumption
48 * that in case of failure, a partial update is better than none. */
50 STRV_FOREACH(i
, files
) {
51 r
= merge_env_file(&env
, NULL
, *i
);
56 STRV_FOREACH(i
, env
) {
58 _cleanup_free_
char *q
= NULL
;
63 q
= shell_maybe_quote(t
+ 1, ESCAPE_BACKSLASH
);
67 printf("%.*s=%s\n", (int) (t
- *i
), *i
, q
);
73 int main(int argc
, char *argv
[]) {
76 log_parse_environment();
80 log_error("This program takes no arguments.");
86 log_error_errno(r
, "Failed to load environment.d: %m");
88 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;