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

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

Merge pull request !388 from hw_mzyan/OpenHarmony-3.1-Release
......@@ -14,6 +14,7 @@
*/
#include "init_cmds.h"
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
......@@ -180,6 +181,31 @@ static void DoExec(const struct CmdArgs *ctx)
if (pid == 0) {
INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, _exit(0x7f),
"DoExec: invalid arguments to exec \"%s\"", ctx->argv[0]);
#ifdef SUPPORT_PROFILER_HIDEBUG
do {
if (access("/system/lib/libhidebug.so", F_OK) != 0) {
INIT_LOGE("access failed, errno = %d\n", errno);
break;
}
void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY);
if (handle == NULL) {
INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror());
break;
}
bool (* initParam)();
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
int ret = execv(ctx->argv[0], ctx->argv);
if (ret == -1) {
INIT_LOGE("DoExec: execute \"%s\" failed: %d.", ctx->argv[0], errno);
......
......@@ -19,6 +19,7 @@
#include <string.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <unistd.h>
#include "init_group_manager.h"
#include "init.h"
......@@ -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);
#ifdef SUPPORT_PROFILER_HIDEBUG
void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY);
if (handle == NULL) {
INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror());
return SERVICE_FAILURE;
}
bool (* initParam)();
initParam = (bool (*)())dlsym(handle, "InitEnvironmentParam");
if (initParam == NULL) {
INIT_LOGE("Failed to dlsym InitEnvironmentParam, %s\n", dlerror());
return SERVICE_FAILURE;
}
(*initParam)(service->name);
do {
if (access("/system/lib/libhidebug.so", F_OK) != 0) {
INIT_LOGE("access failed, errno = %d\n", errno);
break;
}
void* handle = dlopen("/system/lib/libhidebug.so", RTLD_LAZY);
if (handle == NULL) {
INIT_LOGE("Failed to dlopen libhidebug.so, %s\n", dlerror());
break;
}
bool (* initParam)();
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
// L2 Can not be reset env
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.
先完成此消息的编辑!
想要评论请 注册