From 727c2fb7c0ae78f8e6befed56afd5f270273d450 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Mon, 18 Apr 2022 15:13:33 +0800 Subject: [PATCH] init: fix L1 export Signed-off-by: xionglei6 --- services/init/lite/init_service.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/services/init/lite/init_service.c b/services/init/lite/init_service.c index 35522a07..a2e291df 100644 --- a/services/init/lite/init_service.c +++ b/services/init/lite/init_service.c @@ -1,4 +1,4 @@ -/* +* * Copyright (c) 2020-2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,16 +67,20 @@ int ServiceExec(const Service *service) INIT_ERROR_CHECK(service != NULL && service->pathArgs.count > 0, return SERVICE_FAILURE, "Exec service failed! null ptr."); INIT_LOGI("service->name is %s ", service->name); - char *env[] = { "LD_LIBRARY_PATH=/storage/app/libs", NULL, NULL }; - char sockEnv[MAX_ENV_NAME] = {0}; + char sockEnvName[MAX_ENV_NAME] = {0}; + char sockEnvValue[MAX_ENV_NAME] = {0}; if (service->socketCfg != NULL) { - INIT_ERROR_CHECK(snprintf_s(sockEnv, sizeof(sockEnv), sizeof(sockEnv) - 1, "OHOS_SOCKET_%s=%d", - service->socketCfg->name, service->socketCfg->sockFd) != -1, - return SERVICE_FAILURE, "format socket env failed!"); - env[1] = sockEnv; + INIT_ERROR_CHECK(snprintf_s(sockEnvName, MAX_ENV_NAME, MAX_ENV_NAME - 1, "OHOS_SOCKET_%s", + service->socketCfg->name) != -1, + return SERVICE_FAILURE, "format socket env name failed!"); + INIT_ERROR_CHECK(snprintf_s(sockEnvValue, MAX_ENV_NAME, MAX_ENV_NAME - 1, "%d", + service->socketCfg->sockFd) != -1, + return SERVICE_FAILURE, "format socket env value failed!"); } - if (execve(service->pathArgs.argv[0], service->pathArgs.argv, env) != 0) { - INIT_LOGE("service %s execve failed! err %d.", service->name, errno); + INIT_CHECK_ONLY_ELOG(setenv(sockEnvName, sockEnvValue, 1) == 0, "DoExport: set %s with %s failed: %d", + sockEnvName, sockEnvValue, errno); + if (execv(service->pathArgs.argv[0], service->pathArgs.argv) != 0) { + INIT_LOGE("service %s execv failed! err %d.", service->name, errno); return errno; } return SERVICE_SUCCESS; -- GitLab