2 * Copyright 2016 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <folly/init/Init.h>
19 #include <glog/logging.h>
21 #include <folly/Singleton.h>
22 #if !defined(__APPLE__) && !defined(_WIN32)
23 #define USE_FOLLY_SYMBOLIZER 1
26 #ifdef USE_FOLLY_SYMBOLIZER
27 #include <folly/experimental/symbolizer/SignalHandler.h>
29 #include <folly/portability/GFlags.h>
33 void init(int* argc, char*** argv, bool removeFlags) {
34 #ifdef USE_FOLLY_SYMBOLIZER
35 // Install the handler now, to trap errors received during startup.
36 // The callbacks, if any, can be installed later
37 folly::symbolizer::installFatalSignalHandler();
38 #elif !defined(_WIN32)
39 google::InstallFailureSignalHandler();
42 gflags::ParseCommandLineFlags(argc, argv, removeFlags);
44 auto programName = argc && argv && *argc > 0 ? (*argv)[0] : "unknown";
45 google::InitGoogleLogging(programName);
47 #ifdef USE_FOLLY_SYMBOLIZER
48 // Don't use glog's DumpStackTraceAndExit; rely on our signal handler.
49 google::InstallFailureFunction(abort);
52 // Move from the registration phase to the "you can actually instantiate
54 folly::SingletonVault::singleton()->registrationComplete();
56 #ifdef USE_FOLLY_SYMBOLIZER
57 // Actually install the callbacks into the handler.
58 folly::symbolizer::installFatalSignalCallbacks();