1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <condition_variable>
17 #include <csignal>
18 #include <cstdlib>
19 #include <memory>
20 #include <mutex>
21 #include <thread>
22
23 #include "crash_validator.h"
24 #include "ipc_skeleton.h"
25
26 static std::shared_ptr<OHOS::HiviewDFX::CrashValidator> g_validator = nullptr;
SigIntHandler()27 static void SigIntHandler()
28 {
29 constexpr time_t breakTime = 5;
30 static time_t lastHandleTime = 0;
31 auto now = time(nullptr);
32 if (now - lastHandleTime < breakTime) {
33 raise(SIGTERM);
34 } else {
35 if (g_validator != nullptr) {
36 g_validator->Dump(1);
37 }
38 }
39 lastHandleTime = now;
40 }
41
main(int argc,char * argv[])42 int main(int argc, char *argv[])
43 {
44 g_validator = std::make_shared<OHOS::HiviewDFX::CrashValidator>();
45 g_validator->InitSysEventListener();
46 sigset_t waitMask;
47 sigemptyset(&waitMask);
48 sigaddset(&waitMask, SIGINT);
49 pthread_sigmask(SIG_SETMASK, &waitMask, nullptr);
50 int sig = 0;
51 int ret = -1;
52 do {
53 ret = sigwait(&waitMask, &sig);
54 SigIntHandler();
55 } while (ret == 0);
56 return 0;
57 }
58