2020-08-24 05:13:32 +00:00
|
|
|
#include<Boss/Main.hpp>
|
2020-09-07 21:50:38 +08:00
|
|
|
#include<Boss/open_rpc_socket.hpp>
|
2020-08-24 02:28:40 +00:00
|
|
|
#include<Ev/Io.hpp>
|
|
|
|
|
#include<Ev/start.hpp>
|
2020-09-07 21:50:38 +08:00
|
|
|
#include<Net/Fd.hpp>
|
2020-08-24 02:28:40 +00:00
|
|
|
#include<iostream>
|
2020-09-07 10:36:27 +08:00
|
|
|
#include<memory>
|
2020-08-24 02:28:40 +00:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
Ev::Io<int> io_main(int argc, char **argv) {
|
2020-08-24 05:13:32 +00:00
|
|
|
auto arg_vec = std::vector<std::string>();
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
|
arg_vec.push_back(std::string(argv[i]));
|
|
|
|
|
}
|
2020-09-07 10:36:27 +08:00
|
|
|
auto main_obj = std::make_shared<Boss::Main>(
|
2020-09-07 21:50:38 +08:00
|
|
|
arg_vec, std::cin, std::cout, std::cerr,
|
|
|
|
|
Boss::open_rpc_socket
|
2020-09-07 10:36:27 +08:00
|
|
|
);
|
2020-09-07 11:33:35 +08:00
|
|
|
return main_obj->run().then([main_obj](int ec) {
|
2020-09-07 10:36:27 +08:00
|
|
|
/* Ensures main_obj is alive! */
|
2020-09-07 11:33:35 +08:00
|
|
|
return Ev::lift(ec);
|
2020-08-24 03:13:12 +00:00
|
|
|
});
|
2020-08-24 02:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-08-22 14:33:01 +00:00
|
|
|
|
|
|
|
|
int main (int argc, char **argv) {
|
2022-05-01 11:17:32 +08:00
|
|
|
/* For some reason, doing a direct Ev::start(io_main(argc, argv));
|
|
|
|
|
* results in a crash under an edge-case condition.
|
|
|
|
|
* This edge-case condition is if data is immediately fed to
|
|
|
|
|
* the stdin of clboss.
|
|
|
|
|
* You can tickle it (reverting to Ev::start(io_main(argc, argv))
|
|
|
|
|
* and recompiling first) with this:
|
|
|
|
|
*
|
|
|
|
|
* echo '{"id": 0, "method": "getmanifest", "params": {}}' | ./clboss
|
|
|
|
|
*
|
|
|
|
|
* Note that if you just invoke clboss and input the above text
|
|
|
|
|
* manually, it will work perfectly fine, since most humans have
|
|
|
|
|
* reflex times measurable in dozens or hundreds of milliseconds.
|
|
|
|
|
*
|
|
|
|
|
* This does not normally happen in the usual case since the
|
|
|
|
|
* lightningd usually takes a bit of time before it actually
|
|
|
|
|
* emits the getmanifest call, and that is sufficient for the
|
|
|
|
|
* bug to leave the edge-case condition.
|
|
|
|
|
* On the other hand, a Sufficiently Fast (TM) processor might
|
|
|
|
|
* re-tickle this bug someday in the future even when run on
|
|
|
|
|
* some lightningd.
|
|
|
|
|
*
|
|
|
|
|
* This may be a bug in the C++ library or GCC itself, not
|
|
|
|
|
* CLBOSS.
|
|
|
|
|
* Why?
|
|
|
|
|
* Because the crash reports an error somewhere in the guts of
|
|
|
|
|
* malloc, and if you run clboss through valgrind, it does not
|
|
|
|
|
* crash even with the direct Ev::start(io_main(argc, argv)).
|
|
|
|
|
* valgrind works by replacing the malloc implementation, so ---
|
|
|
|
|
*/
|
|
|
|
|
auto code = io_main(argc, argv);
|
|
|
|
|
return Ev::start(code);
|
2020-08-22 14:33:01 +00:00
|
|
|
}
|