From 7424d52a885d23a965c8303ed7b83abe9ae03ff6 Mon Sep 17 00:00:00 2001 From: yaomanhai Date: Mon, 25 Apr 2022 20:23:44 +0800 Subject: [PATCH 1/2] remove unused files Signed-off-by: yaomanhai --- frameworks/libhilog/BUILD.gn | 6 +- .../socket/include/socket_server_adapter.h | 21 --- frameworks/libhilog/socket/socket_server.cpp | 2 - .../libhilog/socket/socket_server_adapter.cpp | 123 ------------------ 4 files changed, 1 insertion(+), 151 deletions(-) delete mode 100644 frameworks/libhilog/socket/include/socket_server_adapter.h delete mode 100644 frameworks/libhilog/socket/socket_server_adapter.cpp diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index 3e9c2e1..c1407fa 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -49,7 +49,6 @@ ohos_source_set("libhilog_source") { "$socket_root/socket.cpp", "$socket_root/socket_client.cpp", "$socket_root/socket_server.cpp", - "$socket_root/socket_server_adapter.cpp", ] utils_sources = [ @@ -68,10 +67,7 @@ ohos_source_set("libhilog_source") { sources += utils_sources sources += vsnprintf_sources - defines = [ - "__RECV_MSG_WITH_UCRED_", - "USING_EXISTING_SOCKET", - ] + defines = [ "__RECV_MSG_WITH_UCRED_" ] if (use_musl) { defines += [ "HILOG_USE_MUSL" ] } diff --git a/frameworks/libhilog/socket/include/socket_server_adapter.h b/frameworks/libhilog/socket/include/socket_server_adapter.h deleted file mode 100644 index 99b9b8b..0000000 --- a/frameworks/libhilog/socket/include/socket_server_adapter.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SOCKET_SERVER_ADAPTER_H -#define SOCKET_SERVER_ADAPTER_H - -int GetExistingSocketServer(const char *name, int type); - -#endif /* SOCKET_SERVER_ADAPTER_H */ diff --git a/frameworks/libhilog/socket/socket_server.cpp b/frameworks/libhilog/socket/socket_server.cpp index cf9b53a..0843018 100644 --- a/frameworks/libhilog/socket/socket_server.cpp +++ b/frameworks/libhilog/socket/socket_server.cpp @@ -24,8 +24,6 @@ #include #include -#include "socket_server_adapter.h" - extern "C" { #include "init_socket.h" } diff --git a/frameworks/libhilog/socket/socket_server_adapter.cpp b/frameworks/libhilog/socket/socket_server_adapter.cpp deleted file mode 100644 index 680f6aa..0000000 --- a/frameworks/libhilog/socket/socket_server_adapter.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef USING_EXISTING_SOCKET -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define OHOS_PROC_FD_DIR "/proc/self/fd" -#define OHOS_SOCKET_DIR "/dev/socket/" -#define OHOS_SOCKET_FILE_PREFIX "socket" - -static constexpr int DECIMAL = 10; - -static std::string GetFileNameByFd(const int fd) -{ - if (fd <= 0) { - return std::string(); - } - - std::string fdPath = "/proc/self/fd/" + std::to_string(fd); - char fileName[PATH_MAX + 1] = {0}; - - int ret = readlink(fdPath.c_str(), fileName, PATH_MAX); - if (ret < 0 || ret > PATH_MAX) { - return std::string(); - } - fileName[ret] = '\0'; - return std::string(fileName); -} - -static void GetSocketFds(std::vector &fds) -{ - struct dirent *dp = nullptr; - DIR *dir = opendir(OHOS_PROC_FD_DIR); - if (!dir) { - return; - } - - while ((dp = readdir(dir)) != nullptr) { - int fd = -1; - if (dp->d_name[0] == '.') { - continue; - } - fd = strtol(dp->d_name, nullptr, DECIMAL); - auto name = GetFileNameByFd(fd); - if (strncmp(name.c_str(), OHOS_SOCKET_FILE_PREFIX, strlen(OHOS_SOCKET_FILE_PREFIX))) { - continue; - } - if (TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD)) >= 0) { - fds.push_back(fd); - } - } - closedir(dir); -} - -static bool CheckSocketType(int fd, int type) -{ - int soType = -1; - socklen_t optlen = static_cast(sizeof(soType)); - if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &soType, &optlen)) { - return false; - } - - return (type == soType); -} - -int GetExistingSocketServer(const char *name, int type) -{ - std::vector fds; - if (name == nullptr) { - return -1; - } - - GetSocketFds(fds); - std::string socketPath(OHOS_SOCKET_DIR); - socketPath += name; - - for (auto fd : fds) { - struct sockaddr_un addr; - socklen_t addrLen = static_cast(sizeof(addr)); - - if (!CheckSocketType(fd, type)) { - continue; - } - - int ret = getsockname(fd, (struct sockaddr*)&addr, &addrLen); - if (ret < 0) { - return -1; - } - if (socketPath.compare(addr.sun_path) == 0) { - return fd; - } - } - - return -1; -} -#else -int GetExistingSocketServer(const char *name, int type) -{ - return -1; -} -#endif -- Gitee From 5d6cbc73258d11a5b2f6d4c465226afd98210c9b Mon Sep 17 00:00:00 2001 From: yaomanhai Date: Tue, 26 Apr 2022 11:23:53 +0800 Subject: [PATCH 2/2] Bugfix: msg content len calculate error, missed HilogMsg len Signed-off-by: yaomanhai --- services/hilogd/log_buffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index a6cb484..070d7e4 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -258,7 +258,7 @@ void HilogBuffer::InitBuffHead() const string tag = "HiLog"; const string msg = "========Zeroth log of type: "; const uint8_t logTypeStrLen = 10; - const size_t contentLen = tag.length() + 1 + msg.length() + 1 + logTypeStrLen; + const size_t contentLen = sizeof(HilogMsg) + tag.length() + 1 + msg.length() + 1 + logTypeStrLen; std::vector buf(contentLen, 0); HilogMsg *headMsg = reinterpret_cast(buf.data()); -- Gitee