Faster onDestroy
[folly.git] / folly / init / Init.cpp
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <folly/init/Init.h>
17 #include <folly/Singleton.h>
18 #include <folly/experimental/symbolizer/SignalHandler.h>
19
20 #include <glog/logging.h>
21 #include <gflags/gflags.h>
22
23 namespace folly {
24
25 void init(int* argc, char*** argv, bool removeFlags) {
26   // Install the handler now, to trap errors received during startup.
27   // The callbacks, if any, can be installed later
28   folly::symbolizer::installFatalSignalHandler();
29
30   google::ParseCommandLineFlags(argc, argv, removeFlags);
31
32   auto programName = argc && argv && *argc > 0 ? (*argv)[0] : "unknown";
33   google::InitGoogleLogging(programName);
34
35   // Don't use glog's DumpStackTraceAndExit; rely on our signal handler.
36   google::InstallFailureFunction(abort);
37
38   // Move from the registration phase to the "you can actually instantiate
39   // things now" phase.
40   folly::SingletonVault::singleton()->registrationComplete();
41
42   // Actually install the callbacks into the handler.
43   folly::symbolizer::installFatalSignalCallbacks();
44 }
45 } //!folly