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

!387 在dlopen libhidebug.so前检查文件是否存在

Merge pull request !387 from hw_mzyan/master
...@@ -184,18 +184,29 @@ static void DoExec(const struct CmdArgs *ctx) ...@@ -184,18 +184,29 @@ static void DoExec(const struct CmdArgs *ctx)
INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, _exit(0x7f), INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, _exit(0x7f),
"DoExec: invalid arguments to exec \"%s\"", ctx->argv[0]); "DoExec: invalid arguments to exec \"%s\"", ctx->argv[0]);
#ifdef SUPPORT_PROFILER_HIDEBUG #ifdef SUPPORT_PROFILER_HIDEBUG
void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY); do {
if (handle == NULL) { if (access("/system/lib/libhidebug.so", F_OK) != 0) {
INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror()); INIT_LOGE("access failed, errno = %d\n", errno);
return; break;
} }
bool (* initParam)(); void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY);
initParam = (bool (*)())dlsym(handle, "InitEnvironmentParam"); if (handle == NULL) {
if (initParam == NULL) { INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror());
INIT_LOGE("Failed to dlsym InitEnvironmentParam, %s\n", dlerror()); break;
return; }
} bool (* initParam)();
(*initParam)(ctx->argv[0]); initParam = (bool (*)())dlsym(handle, "InitEnvironmentParam");
if (initParam == NULL) {
INIT_LOGE("Failed to dlsym InitEnvironmentParam, %s\n", dlerror());
dlclose(handle);
break;
}
bool ret = (*initParam)(ctx->argv[0]);
if (!ret) {
INIT_LOGE("init parameters failed.\n");
}
dlclose(handle);
} while (0);
#endif #endif
int ret = execv(ctx->argv[0], ctx->argv); int ret = execv(ctx->argv[0], ctx->argv);
if (ret == -1) { if (ret == -1) {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <string.h> #include <string.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <unistd.h>
#include "init_group_manager.h" #include "init_group_manager.h"
#include "init.h" #include "init.h"
...@@ -87,18 +88,29 @@ int ServiceExec(const Service *service) ...@@ -87,18 +88,29 @@ int ServiceExec(const Service *service)
} }
INIT_CHECK_ONLY_ELOG(unsetenv("UV_THREADPOOL_SIZE") == 0, "set UV_THREADPOOL_SIZE error : %d.", errno); INIT_CHECK_ONLY_ELOG(unsetenv("UV_THREADPOOL_SIZE") == 0, "set UV_THREADPOOL_SIZE error : %d.", errno);
#ifdef SUPPORT_PROFILER_HIDEBUG #ifdef SUPPORT_PROFILER_HIDEBUG
void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY); do {
if (handle == NULL) { if (access("/system/lib/libhidebug.so", F_OK) != 0) {
INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror()); INIT_LOGE("access failed, errno = %d\n", errno);
return SERVICE_FAILURE; break;
} }
bool (* initParam)(); void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY);
initParam = (bool (*)())dlsym(handle, "InitEnvironmentParam"); if (handle == NULL) {
if (initParam == NULL) { INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror());
INIT_LOGE("Failed to dlsym InitEnvironmentParam, %s\n", dlerror()); break;
return SERVICE_FAILURE; }
} bool (* initParam)();
(*initParam)(service->name); initParam = (bool (*)())dlsym(handle, "InitEnvironmentParam");
if (initParam == NULL) {
INIT_LOGE("Failed to dlsym InitEnvironmentParam, %s\n", dlerror());
dlclose(handle);
break;
}
bool ret = (*initParam)(service->name);
if (!ret) {
INIT_LOGE("init parameters failed.\n");
}
dlclose(handle);
} while (0);
#endif #endif
// L2 Can not be reset env // L2 Can not be reset env
if (service->extraArgs.argv != NULL && service->extraArgs.count > 0) { if (service->extraArgs.argv != NULL && service->extraArgs.count > 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册