| 2009 | #endif /* DEVELOPER */ |
| 2010 | |
| 2011 | int main(int argc, char *argv[]) |
| 2012 | { |
| 2013 | setup_locale(); |
| 2014 | |
| 2015 | struct daemon *daemon; |
| 2016 | |
| 2017 | /* Common subdaemon setup code. */ |
| 2018 | subdaemon_setup(argc, argv); |
| 2019 | |
| 2020 | /* Allocate and set up our simple top-level structure. */ |
| 2021 | daemon = tal(NULL, struct daemon); |
| 2022 | daemon->connection_counter = 1; |
| 2023 | peer_htable_init(&daemon->peers); |
| 2024 | memleak_add_helper(daemon, memleak_daemon_cb); |
| 2025 | list_head_init(&daemon->connecting); |
| 2026 | timers_init(&daemon->timers, time_mono()); |
| 2027 | daemon->gossip_store_fd = -1; |
| 2028 | |
| 2029 | /* stdin == control */ |
| 2030 | daemon->master = daemon_conn_new(daemon, STDIN_FILENO, recv_req, NULL, |
| 2031 | daemon); |
| 2032 | tal_add_destructor(daemon->master, master_gone); |
| 2033 | |
| 2034 | /* This tells the status_* subsystem to use this connection to send |
| 2035 | * our status_ and failed messages. */ |
| 2036 | status_setup_async(daemon->master); |
| 2037 | |
| 2038 | /* Don't leave around websocketd zombies. Technically not portable, |
| 2039 | * but OK for Linux and BSD, so... */ |
| 2040 | signal(SIGCHLD, SIG_IGN); |
| 2041 | |
| 2042 | /* This streams gossip to and from gossipd */ |
| 2043 | daemon->gossipd = daemon_conn_new(daemon, GOSSIPCTL_FD, |
| 2044 | recv_gossip, NULL, |
| 2045 | daemon); |
| 2046 | |
| 2047 | /* Set up ecdh() function so it uses our HSM fd, and calls |
| 2048 | * status_failed on error. */ |
| 2049 | ecdh_hsmd_setup(HSM_FD, status_failed); |
| 2050 | |
| 2051 | for (;;) { |
| 2052 | struct timer *expired; |
| 2053 | io_loop(&daemon->timers, &expired); |
| 2054 | timer_expired(expired); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | /*~ Getting bored? This was a pretty simple daemon! |
| 2059 | * |
nothing calls this directly
no test coverage detected