John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 1 | #include "aos/init.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 2 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 3 | #include <sched.h> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 4 | #include <sys/mman.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 5 | #include <sys/resource.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | #include <sys/types.h> |
7 | #include <unistd.h> | ||||
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame^] | 8 | |
9 | #include <cerrno> | ||||
10 | #include <cstdio> | ||||
11 | #include <cstdlib> | ||||
12 | #include <cstring> | ||||
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 13 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 14 | #include "aos/realtime.h" |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 15 | #include "gflags/gflags.h" |
16 | #include "glog/logging.h" | ||||
Brian Silverman | 4048662 | 2014-12-30 17:38:55 -0800 | [diff] [blame] | 17 | |
Austin Schuh | 707c835 | 2020-03-15 14:27:25 -0700 | [diff] [blame] | 18 | DEFINE_bool(coredump, false, "If true, write core dumps on failure."); |
19 | |||||
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 20 | namespace aos { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 21 | namespace { |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 22 | bool initialized = false; |
Austin Schuh | 3d4d5df | 2015-10-17 15:51:41 -0700 | [diff] [blame] | 23 | } // namespace |
24 | |||||
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 25 | bool IsInitialized() { return initialized; } |
26 | |||||
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 27 | void InitGoogle(int *argc, char ***argv) { |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 28 | CHECK(!IsInitialized()) << "Only initialize once."; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 29 | FLAGS_logtostderr = true; |
30 | google::InitGoogleLogging((*argv)[0]); | ||||
31 | gflags::ParseCommandLineFlags(argc, argv, true); | ||||
32 | google::InstallFailureSignalHandler(); | ||||
Austin Schuh | 6228825 | 2020-11-18 23:26:04 -0800 | [diff] [blame] | 33 | |
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 34 | if (FLAGS_coredump) { |
35 | WriteCoreDumps(); | ||||
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 36 | } |
37 | |||||
Austin Schuh | 094d09b | 2020-11-20 23:26:52 -0800 | [diff] [blame] | 38 | RegisterMallocHook(); |
39 | initialized = true; | ||||
Brian Silverman | e4d8b28 | 2015-12-24 13:44:48 -0800 | [diff] [blame] | 40 | } |
41 | |||||
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 42 | } // namespace aos |