• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef DFX_FAULTLOGGERD_H
16 #define DFX_FAULTLOGGERD_H
17 
18 #include <cinttypes>
19 #include <map>
20 
21 #include "faultloggerd_client.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 class FaultLoggerDaemon {
26 public:
27     FaultLoggerDaemon();
~FaultLoggerDaemon()28     ~FaultLoggerDaemon() {};
29     int32_t StartServer();
30     bool InitEnvironment();
31     int32_t CreateFileForRequest(int32_t type, int32_t pid, uint64_t time, bool debugFlag) const;
32 
33 private:
34     void AddEvent(int32_t epollFd, int32_t addFd, uint32_t event);
35     void DelEvent(int32_t epollFd, int32_t delFd, uint32_t event);
36     void HandleAccept(int32_t epollFd, int32_t socketFd);
37     void HandleRequest(int32_t epollFd, int32_t connectionFd);
38 
39     void RemoveTempFileIfNeed();
40     void HandleDefaultClientRequest(int32_t connectionFd, const FaultLoggerdRequest* request);
41     void HandleLogFileDesClientRequest(int32_t connectionFd, const FaultLoggerdRequest* request);
42     void HandlePrintTHilogClientRequest(int32_t const connectionFd, FaultLoggerdRequest* request);
43     FaultLoggerCheckPermissionResp SecurityCheck(int32_t connectionFd, FaultLoggerdRequest* request);
44     void HandlePermissionRequest(int32_t connectionFd, FaultLoggerdRequest* request);
45     void HandleSdkDumpRequest(int32_t connectionFd, FaultLoggerdRequest* request);
46     void HandlePipeFdClientRequest(int32_t connectionFd, FaultLoggerdRequest* request);
47     bool CheckRequestCredential(int32_t connectionFd, FaultLoggerdRequest* request);
48     bool CreateSockets();
49     bool CreateEventFd();
50     void CleanupSockets();
51     void WaitForRequest();
52     void CleanupEventFd();
53 
54 private:
55     int32_t defaultSocketFd_ = -1;
56     int32_t crashSocketFd_ = -1;
57     int32_t eventFd_ = -1;
58     std::map<int32_t, int32_t> connectionMap_;
59 };
60 } // namespace HiviewDFX
61 } // namespace OHOS
62 #endif
63