加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0005-fix-previous-commit-refactoring-preload-module.patch 2.58 KB
一键复制 编辑 原始数据 按行查看 历史
From 6a5bb82feba31762f6c977e618bcee47a5f06d26 Mon Sep 17 00:00:00 2001
From: yanan-rock <yanan@huawei.com>
Date: Sun, 14 May 2023 15:02:58 -0400
Subject: [PATCH] fix previous commit "refactoring preload module"
Signed-off-by: yanan-rock <yanan@huawei.com>
---
src/lstack/core/lstack_init.c | 26 --------------------------
src/lstack/core/lstack_preload.c | 25 ++++++++++++++++++++++++-
2 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c
index 53bc541..406a0b8 100644
--- a/src/lstack/core/lstack_init.c
+++ b/src/lstack/core/lstack_init.c
@@ -118,29 +118,6 @@ static int32_t check_process_conflict(void)
return 0;
}
-static int32_t check_preload_bind_proc(void)
-{
- char proc_path[PATH_MAX] = {0};
-
- if (!g_preload_info.preload_switch) {
- return 0;
- }
-
- if (readlink("/proc/self/exe", proc_path, PATH_MAX - 1) <= 0) {
- return -1;
- }
-
- char *proc_name = strrchr(proc_path, '/');
- if (!proc_name) {
- return -1;
- }
-
- if (strncmp(++proc_name, g_preload_info.env_procname, PATH_MAX) == 0) {
- return 0;
- }
- return -1;
-}
-
__attribute__((destructor)) void gazelle_network_exit(void)
{
if (posix_api != NULL && !posix_api->ues_posix) {
@@ -262,9 +239,6 @@ __attribute__((constructor)) void gazelle_network_init(void)
if (preload_info_init() < 0) {
return;
}
- if (check_preload_bind_proc() < 0) {
- return;
- }
/* Read configure from lstack.cfg */
if (cfg_init() != 0) {
diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c
index 9fc5819..e04f49b 100644
--- a/src/lstack/core/lstack_preload.c
+++ b/src/lstack/core/lstack_preload.c
@@ -26,6 +26,29 @@ struct lstack_preload {
};
static struct lstack_preload g_preload_info = {0};
+static int32_t preload_check_bind_proc(void)
+{
+ char proc_path[PATH_MAX] = {0};
+
+ if (!g_preload_info.preload_switch) {
+ return 0;
+ }
+
+ if (readlink("/proc/self/exe", proc_path, PATH_MAX - 1) <= 0) {
+ return -1;
+ }
+
+ char *proc_name = strrchr(proc_path, '/');
+ if (!proc_name) {
+ return -1;
+ }
+
+ if (strncmp(++proc_name, g_preload_info.env_procname, PATH_MAX) == 0) {
+ return 0;
+ }
+ return -1;
+}
+
static int32_t preload_info_init(void)
{
char *enval = NULL;
@@ -51,5 +74,5 @@ static int32_t preload_info_init(void)
g_preload_info.preload_switch = 1;
LSTACK_PRE_LOG(LSTACK_INFO, "LD_PRELOAD ok\n");
- return 0;
+ return preload_check_bind_proc();
}
--
2.23.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化