• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "event_log_catcher.h"
16 
17 #include <string>
18 
19 #include <climits>
20 #include <fcntl.h>
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 
25 #include "securec.h"
26 
27 #include "common_utils.h"
28 #include "defines.h"
29 #include "file_util.h"
30 #include "hiview_logger.h"
31 namespace OHOS {
32 namespace HiviewDFX {
33 DEFINE_LOG_LABEL(0xD002D01, "EventLogger-EventLogCatcher");
34 namespace {
35     constexpr char SED_EXEC_PATH[] = "/system/bin/sed";
36     constexpr size_t BLOCK_COUNT = 1;
37 }
38 
GetName() const39 std::string EventLogCatcher::GetName() const
40 {
41     return name_;
42 }
43 
GetLogSize() const44 int EventLogCatcher::GetLogSize() const
45 {
46     return logSize_;
47 };
48 
SetLogSize(int size)49 void EventLogCatcher::SetLogSize(int size)
50 {
51     logSize_ = size;
52 }
53 
Initialize(const std::string & strParam1 __UNUSED,int intParam1 __UNUSED,int intParam2 __UNUSED)54 bool EventLogCatcher::Initialize(const std::string &strParam1 __UNUSED, int intParam1 __UNUSED, int intParam2 __UNUSED)
55 {
56     useStreamFilter_ = CommonUtils::IsSpecificCmdExist(SED_EXEC_PATH);
57     catcherStartTime_ = time(nullptr);
58     return true;
59 }
60 
Catch(int fd __UNUSED,int jsonFd __UNUSED)61 int EventLogCatcher::Catch(int fd __UNUSED, int jsonFd __UNUSED)
62 {
63     return 0;
64 }
65 
Stop()66 void EventLogCatcher::Stop()
67 {
68     needStop_ = true;
69 }
70 
GetDescription() const71 std::string EventLogCatcher::GetDescription() const
72 {
73     return description_;
74 }
75 
GetFdSize(int32_t fd)76 int EventLogCatcher::GetFdSize(int32_t fd)
77 {
78     struct stat fileStat;
79     if (fstat(fd, &fileStat) == -1) {
80         return 0;
81     }
82     return fileStat.st_size;
83 }
84 } // namespace HiviewDFX
85 } // namespace OHOS
86