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

Function main

lightningd/lightningd.c:1167–1580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1165}
1166
1167int main(int argc, char *argv[])
1168{
1169 struct lightningd *ld;
1170 int connectd_gossipd_fd;
1171 int stop_fd;
1172 struct timers *timers;
1173 const char *stop_response;
1174 struct htlc_in_map *unconnected_htlcs_in;
1175 int sigchld_rfd;
1176 struct io_conn *sigchld_conn = NULL;
1177 int exit_code = 0;
1178 char **orig_argv;
1179 bool try_reexec;
1180 size_t num_channels;
1181
1182 /*~ What happens in strange locales should stay there. */
1183 setup_locale();
1184
1185 /*~ This handles --dev-debug-self really early, which we otherwise ignore */
1186 daemon_developer_mode(argv);
1187
1188 /*~ This sets up SIGCHLD to make sigchld_rfd readable. */
1189 sigchld_rfd = setup_sig_handlers();
1190
1191 /*~ This checks that the system-installed libraries (usually
1192 * dynamically linked) actually are compatible with the ones we
1193 * compiled with.
1194 *
1195 * The header itself is auto-generated every time the version of the
1196 * installed libraries changes, as we had an sqlite3 version update
1197 * which broke people, and "make" didn't think there was any work to
1198 * do, so rebuilding didn't fix it. */
1199 check_linked_library_versions();
1200
1201 /*~ Every daemon calls this in some form: the hooks are for dumping
1202 * backtraces when we crash (if supported on this platform). */
1203 daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit);
1204
1205 /*~ We enable trace as early as possible, but it uses support functions
1206 * (particularly if we're avoid entropy) so do it after daemon_setup. */
1207 trace_span_start("lightningd/startup", argv);
1208
1209 /*~ There's always a battle between what a constructor like this
1210 * should do, and what should be added later by the caller. In
1211 * general, because we use valgrind heavily for testing, we prefer not
1212 * to initialize unused fields which we expect the caller to set:
1213 * valgrind will warn us if we make decisions based on uninitialized
1214 * variables. */
1215 ld = new_lightningd(NULL);
1216 ld->state = LD_STATE_INITIALIZING;
1217 log_info(ld->log, "%s", version());
1218
1219 /*~ We store an copy of our arguments before parsing mangles them, so
1220 * we can re-exec if versions of subdaemons change. Note the use of
1221 * notleak() since our leak-detector can't find orig_argv on the
1222 * stack. */
1223 orig_argv = notleak(tal_arr(ld, char *, argc + 1));
1224 for (size_t i = 1; i < argc; i++)

Callers

nothing calls this directly

Calls 15

setup_localeFunction · 0.85
daemon_developer_modeFunction · 0.85
setup_sig_handlersFunction · 0.85
daemon_setupFunction · 0.85
new_lightningdFunction · 0.85
log_infoClass · 0.85
versionFunction · 0.85
path_joinFunction · 0.85
path_cwdFunction · 0.85
default_featuresFunction · 0.85
trace_span_endFunction · 0.85

Tested by

no test coverage detected