| 1252 | } |
| 1253 | |
| 1254 | int main(int argc, char *argv[]) |
| 1255 | { |
| 1256 | struct lightningd *ld; |
| 1257 | int connectd_gossipd_fd; |
| 1258 | int stop_fd; |
| 1259 | struct timers *timers; |
| 1260 | const char *stop_response; |
| 1261 | struct htlc_in_map *unconnected_htlcs_in; |
| 1262 | int sigchld_rfd; |
| 1263 | struct io_conn *sigchld_conn = NULL; |
| 1264 | int exit_code = 0; |
| 1265 | char **orig_argv, **args_to_scrub; |
| 1266 | const char *recover_secret = NULL; |
| 1267 | bool try_reexec; |
| 1268 | size_t num_channels; |
| 1269 | |
| 1270 | /*~ What happens in strange locales should stay there. */ |
| 1271 | setup_locale(); |
| 1272 | |
| 1273 | /*~ This handles --dev-debug-self really early, which we otherwise ignore */ |
| 1274 | daemon_developer_mode(argv); |
| 1275 | |
| 1276 | /*~ This sets up SIGCHLD to make sigchld_rfd readable. */ |
| 1277 | sigchld_rfd = setup_sig_handlers(); |
| 1278 | |
| 1279 | /*~ This checks that the system-installed libraries (usually |
| 1280 | * dynamically linked) actually are compatible with the ones we |
| 1281 | * compiled with. |
| 1282 | * |
| 1283 | * The header itself is auto-generated every time the version of the |
| 1284 | * installed libraries changes, as we had an sqlite3 version update |
| 1285 | * which broke people, and "make" didn't think there was any work to |
| 1286 | * do, so rebuilding didn't fix it. */ |
| 1287 | check_linked_library_versions(); |
| 1288 | |
| 1289 | /*~ Every daemon calls this in some form: the hooks are for dumping |
| 1290 | * backtraces when we crash (if supported on this platform). */ |
| 1291 | daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit); |
| 1292 | |
| 1293 | /*~ We enable trace as early as possible, but it uses support functions |
| 1294 | * (particularly if we're avoid entropy) so do it after daemon_setup. */ |
| 1295 | trace_span_start("lightningd/startup", argv); |
| 1296 | |
| 1297 | /*~ There's always a battle between what a constructor like this |
| 1298 | * should do, and what should be added later by the caller. In |
| 1299 | * general, because we use valgrind heavily for testing, we prefer not |
| 1300 | * to initialize unused fields which we expect the caller to set: |
| 1301 | * valgrind will warn us if we make decisions based on uninitialized |
| 1302 | * variables. */ |
| 1303 | ld = new_lightningd(NULL); |
| 1304 | ld->state = LD_STATE_INITIALIZING; |
| 1305 | log_info(ld->log, "%s", version()); |
| 1306 | |
| 1307 | /*~ Note the use of notleak() since our leak-detector can't find |
| 1308 | * orig_argv on the stack. */ |
| 1309 | orig_argv = notleak(reexec_args(ld, argc, argv)); |
| 1310 | |
| 1311 | /* Figure out where our subdaemons are first. */ |
nothing calls this directly
no test coverage detected