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