From d1295f54e67c348dc3a1c6a3b0b6bf239343080c Mon Sep 17 00:00:00 2001 From: Guangyao Ma Date: Wed, 28 Jul 2021 17:32:12 +0800 Subject: [PATCH] feat: kernel support O_CLOEXEC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加载so的过程中,需要设置O_CLOEXEC,如果不设置,会导致子进程继承父进程打开的所有 so文件句柄。 close #I3U81W Signed-off-by: Guangyao Ma Change-Id: I249dd34c182434fa070dcd180b6931002597a074 --- porting/liteos_a/user/ldso/dynlink.c | 4 ++-- porting/liteos_a/user_debug/ldso/dynlink.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/porting/liteos_a/user/ldso/dynlink.c b/porting/liteos_a/user/ldso/dynlink.c index 40e05220..5a780e00 100644 --- a/porting/liteos_a/user/ldso/dynlink.c +++ b/porting/liteos_a/user/ldso/dynlink.c @@ -810,7 +810,7 @@ static int path_open(const char *name, const char *s, char *buf, size_t buf_size l = strcspn(s, ":\n"); if (l-1 >= INT_MAX) return -1; if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) { - if ((fd = open(buf, O_RDONLY))>=0) return fd; // open(buf, O_RDONLY|O_CLOEXEC) + if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd; switch (errno) { case ENOENT: case ENOTDIR: @@ -1038,7 +1038,7 @@ static struct dso *load_library(const char *name, struct dso *needed_by) } if (strchr(name, '/')) { pathname = name; - fd = open(name, O_RDONLY); // open(name, O_RDONLY|O_CLOEXEC); + fd = open(name, O_RDONLY|O_CLOEXEC); } else { /* Search for the name to see if it's already loaded */ for (p=head->next; p; p=p->next) { diff --git a/porting/liteos_a/user_debug/ldso/dynlink.c b/porting/liteos_a/user_debug/ldso/dynlink.c index e311c674..92e2abf4 100644 --- a/porting/liteos_a/user_debug/ldso/dynlink.c +++ b/porting/liteos_a/user_debug/ldso/dynlink.c @@ -810,7 +810,7 @@ static int path_open(const char *name, const char *s, char *buf, size_t buf_size l = strcspn(s, ":\n"); if (l-1 >= INT_MAX) return -1; if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) { - if ((fd = open(buf, O_RDONLY))>=0) return fd; // open(buf, O_RDONLY|O_CLOEXEC) + if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd; switch (errno) { case ENOENT: case ENOTDIR: @@ -1038,7 +1038,7 @@ static struct dso *load_library(const char *name, struct dso *needed_by) } if (strchr(name, '/')) { pathname = name; - fd = open(name, O_RDONLY); // open(name, O_RDONLY|O_CLOEXEC); + fd = open(name, O_RDONLY|O_CLOEXEC); } else { /* Search for the name to see if it's already loaded */ for (p=head->next; p; p=p->next) { -- GitLab