提交 d1295f54 编写于 作者: G Guangyao Ma

feat: kernel support O_CLOEXEC

加载so的过程中,需要设置O_CLOEXEC,如果不设置,会导致子进程继承父进程打开的所有
so文件句柄。

close #I3U81W
Signed-off-by: NGuangyao Ma <guangyao.ma@outlook.com>
Change-Id: I249dd34c182434fa070dcd180b6931002597a074
上级 713e746b
......@@ -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) {
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册