未验证 提交 ce642737 编写于 作者: O openharmony_ci 提交者: Gitee

!874 Support check duplicate so name for system app

Merge pull request !874 from yinchuang/support_same_so
......@@ -24,6 +24,7 @@ extern "C" {
/* create flags for dlns_create */
#define CREATE_INHERIT_DEFAULT 0x1
#define CREATE_INHERIT_CURRENT 0x2
#define LOCAL_NS_PREFERED 0x4 /* Use app's library when app's library has same name as system library. */
int dlclose(void *);
char *dlerror(void);
......
......@@ -1714,6 +1714,18 @@ static struct dso *search_dso_by_fstat(const struct stat *st, const ns_t *ns, ui
}
return NULL;
}
static inline int app_has_same_name_so(const char *so_name, const ns_t *ns)
{
int fd = -1;
/* Only check system app. */
if (((ns->flag & LOCAL_NS_PREFERED) != 0) && ns->lib_paths) {
char tmp_buf[PATH_MAX+1];
fd = path_open(so_name, ns->lib_paths, tmp_buf, sizeof tmp_buf);
}
return fd;
}
/* Find loaded so by name */
static struct dso *find_library_by_name(const char *name, const ns_t *ns, bool check_inherited)
{
......@@ -1727,7 +1739,12 @@ static struct dso *find_library_by_name(const char *name, const ns_t *ns, bool c
for (size_t i = 0; i < ns->ns_inherits->num; i++){
ns_inherit * inherit = ns->ns_inherits->inherits[i];
p = search_dso_by_name(name, inherit->inherited_ns);
if (p && is_sharable(inherit, name)) return p;
if (p && is_sharable(inherit, name)) {
if (app_has_same_name_so(name, ns) != -1) {
return NULL;
}
return p;
}
}
}
return NULL;
......@@ -3387,6 +3404,7 @@ int dlns_create2(Dl_namespace *dlns, const char *lib_path, int flags)
return ENOMEM;
}
ns_set_name(ns, dlns->name);
ns_set_flag(ns, flags);
ns_add_dso(ns, get_default_ns()->ns_dsos->dsos[0]); /* add main app to this namespace*/
nslist_add_ns(ns); /* add ns to list*/
ns_set_lib_paths(ns, lib_path);
......
......@@ -602,3 +602,12 @@ bool is_sharable(ns_inherit *inherit, const char *lib_name)
LD_LOGD("is_sharable shared_libs not config, return true.");
return true;
}
void ns_set_flag(ns_t *ns, int flag)
{
if (!ns) {
return;
}
ns->flag = flag;
LD_LOGD("ns_set_flag ns[%{public}s] flag:%{public}d.", ns->ns_name, ns->flag);
}
\ No newline at end of file
......@@ -47,6 +47,7 @@ typedef struct _namespace_t_ {
strlist *allowed_libs; /* when separated, allowed library names splited by ':'. */
dsolist *ns_dsos; /* dso list in this namespace */
struct _ns_inherit_list_ *ns_inherits; /* inherit list in this namespace */
int flag;
} ns_t;
/* define namespace list */
typedef struct _namespaces_list_ {
......@@ -83,6 +84,7 @@ void ns_set_allowed_libs(ns_t *ns, const char *allowed_libs);
void ns_add_dso(ns_t *ns, struct dso *dso);
void nslist_add_ns(ns_t *ns);
void ns_add_inherit(ns_t *ns,ns_t *inherited, const char *shared_libs);
void ns_set_flag(ns_t *ns, int flag);
/* get default namespace */
ns_t *get_default_ns();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册