MCPcopy Create free account
hub / github.com/ElementsProject/lightning / gather_file_configvars

Function gather_file_configvars

common/configdir.c:55–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55static struct configvar **gather_file_configvars(const tal_t *ctx,
56 enum configvar_src src,
57 const char *filename,
58 bool must_exist,
59 char **setconfig_file,
60 size_t include_depth)
61{
62 char *contents, **lines;
63 struct configvar **cvs = tal_arr(ctx, struct configvar *, 0);
64
65 contents = grab_file_str(tmpctx, filename);
66
67 /* The default config doesn't have to exist, but if the config was
68 * specified on the command line it has to exist. */
69 if (!contents) {
70 if (must_exist)
71 err(1, "Opening and reading %s", filename);
72 return cvs;
73 }
74
75 /* First .setconfig file is used for setconfig command */
76 if (setconfig_file
77 && *setconfig_file == NULL
78 && strends(filename, ".setconfig")) {
79 *setconfig_file = tal_strdup(ctx, filename);
80 }
81
82 /* Break into lines. */
83 lines = tal_strsplit(contents, contents, "\r\n", STR_EMPTY_OK);
84 for (size_t i = 0; i < tal_count(lines) - 1; i++) {
85 /* Comments & blank lines*/
86 if (strstarts(lines[i], "#") || streq(lines[i], ""))
87 continue;
88
89 if (strstarts(lines[i], "include ")) {
90 const char *included = lines[i] + strlen("include ");
91 struct configvar **sub;
92
93 if (include_depth > 100)
94 errx(1, "Include loop with %s and %s", filename, included);
95
96 /* If relative, it's relative to current config file */
97 sub = gather_file_configvars(NULL,
98 src,
99 path_join(tmpctx,
100 take(path_dirname(NULL, filename)),
101 included),
102 true,
103 setconfig_file,
104 include_depth + 1);
105 cvs = configvar_join(ctx, take(cvs), take(sub));
106 continue;
107 }
108
109 tal_arr_expand(&cvs,
110 configvar_new(cvs, src, filename, i+1, lines[i]));
111 }
112 return cvs;

Callers 1

initial_config_optsFunction · 0.85

Calls 8

grab_file_strFunction · 0.85
errFunction · 0.85
strendsFunction · 0.85
errxFunction · 0.85
path_joinFunction · 0.85
path_dirnameFunction · 0.85
configvar_joinFunction · 0.85
configvar_newFunction · 0.85

Tested by

no test coverage detected