From 2fb5adab25cd0f0a74b20f5b6fcb88c23cfcc192 Mon Sep 17 00:00:00 2001 From: ligongshao Date: Tue, 12 Mar 2024 15:31:04 +0800 Subject: [PATCH 1/2] for process in pid namespace, function getproctid() returns tid outside the sandbox. Signed-off-by: ligongshao --- frameworks/libhilog/hilog_printf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/libhilog/hilog_printf.cpp b/frameworks/libhilog/hilog_printf.cpp index cc79daa..23e0dca 100644 --- a/frameworks/libhilog/hilog_printf.cpp +++ b/frameworks/libhilog/hilog_printf.cpp @@ -317,7 +317,7 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int pthread_threadid_np(NULL, &tid); header.tid = static_cast(tid); #else - header.tid = static_cast(syscall(SYS_gettid)); + header.tid = static_cast(getproctid()); #endif header.domain = domain; -- Gitee From 647220fbf8f339f53f377a23c5ff8ac29a16a7af Mon Sep 17 00:00:00 2001 From: ligongshao Date: Fri, 15 Mar 2024 15:14:06 +0800 Subject: [PATCH 2/2] hilog tid for pid namespace process Signed-off-by: ligongshao Change-Id: Ibd9c8bc9d1baffea02afea34fc8cfc5b56cb1f84 --- frameworks/libhilog/BUILD.gn | 3 +++ frameworks/libhilog/hilog_printf.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index e3bb1be..d483ad3 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -92,6 +92,9 @@ template("libhilog_source") { cflags_cc = [ "-std=c++17" ] defines += [ "__LINUX__" ] } else { + if (platform == "ohos") { + defines += [ "__OHOS__" ] + } defines = [ "__RECV_MSG_WITH_UCRED_" ] if (use_musl) { defines += [ "HILOG_USE_MUSL" ] diff --git a/frameworks/libhilog/hilog_printf.cpp b/frameworks/libhilog/hilog_printf.cpp index cc79daa..e30f248 100644 --- a/frameworks/libhilog/hilog_printf.cpp +++ b/frameworks/libhilog/hilog_printf.cpp @@ -316,6 +316,8 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int uint64_t tid; pthread_threadid_np(NULL, &tid); header.tid = static_cast(tid); +#elif defined(__OHOS__) + header.tid = static_cast(getproctid()); #else header.tid = static_cast(syscall(SYS_gettid)); #endif -- Gitee