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