diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index 3e9c2e1239848d62389fe3f8648281647790c486..c1407fa959321e7c9ee41804d8cecdb2e6ab46f5 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 99b9b8b41e9767f829e2e443603da43090b5a5b5..0000000000000000000000000000000000000000 --- 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 cf9b53a53f552e9cd4f7ccc58242219d96d078c6..08430186035bac9e5d368def7a2c9dbc8f70cffb 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 680f6aa513f1162677ee14968edb278fccb1d456..0000000000000000000000000000000000000000 --- 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 diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index a6cb484dcd787545aed0fa8f221a8c42f67eafb2..070d7e4d6cd1a8b1dbaa1a81ccd153f5d6f92baf 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());