提交 ddb6d830 编写于 作者: Z zhang-junxi66

Signed-off-by: zhang-junxi66 <zhangjunxi1@huawei.com>

Merge branch 'master' of gitee.com:zhang-junxi66/startup_init_lite

# Conflicts:
#	services/etc/group
#	services/etc/passwd
......@@ -297,4 +297,43 @@ if (defined(ohos_lite)) {
part_name = "init"
}
ohos_static_library("libbegetutil_static") {
sources = [ "//base/startup/init_lite/services/log/init_log.c" ]
sources += syspara_sources
sources += [ "syspara/param_wrapper.cpp" ]
defines = [
"INIT_AGENT",
"INIT_FILE",
"_GNU_SOURCE",
]
if (target_cpu == "arm64") {
defines += [ "SUPPORT_64BIT" ]
}
include_dirs = [
"./include",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/interfaces/innerkits/include/syspara",
"//base/startup/init_lite/interfaces/innerkits/syspara",
]
deps = [
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/openssl:libcrypto_shared",
]
external_deps = [
"hilog_native:libhilog_base",
"utils_base:utils",
]
part_name = "init"
}
}
......@@ -271,7 +271,7 @@ static int hookTraversalProc(ListNode *node, void *cookie)
if ((args != NULL) && (args->preHook != NULL)) {
args->preHook(&hookInfo);
}
hookInfo.retVal = hookItem->hook(hookInfo.stage, hookItem->prio, args->cookie);
hookInfo.retVal = hookItem->hook(hookInfo.stage, hookItem->prio, hookInfo.cookie);
if ((args != NULL) && (args->postHook != NULL)) {
args->postHook(&hookInfo);
}
......
......@@ -22,6 +22,7 @@
#include <dirent.h>
#include <linux/limits.h>
#include "beget_ext.h"
#include "list.h"
#include "securec.h"
#include "modulemgr.h"
......@@ -127,11 +128,13 @@ static void *moduleInstall(MODULE_ITEM *module, int argc, const char *argv[])
return NULL;
}
}
BEGET_LOGV("moduleInstall path %s", path);
currentInstallArgs = &(module->moduleMgr->installArgs);
handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
currentInstallArgs = NULL;
if (handle == NULL) {
BEGET_LOGE("moduleInstall path %s fail %d", path, errno);
}
return handle;
}
......
......@@ -231,8 +231,13 @@ const char *GetBuildTime(void)
const char *GetSerial(void)
{
static const char *ohos_serial = NULL;
return GetProperty("ohos.boot.sn", &ohos_serial);
static char ohos_serial[PARAM_VALUE_LEN_MAX] = {0};
uint32_t len = PARAM_VALUE_LEN_MAX;
int ret = SystemGetParameter("ohos.boot.sn", ohos_serial, &len);
if (ret != 0) {
return NULL;
}
return ohos_serial;
}
int GetDevUdid(char *udid, int size)
......
......@@ -72,6 +72,7 @@ dscreen:x:3054:
daudio:x:3055:
dhardware:x:3056:
installs:x:3060:
huks_server:x:3510:
dms:x:5522:
update:x:6666:
charger:x:6667:
......@@ -86,7 +87,7 @@ useriam:x:1088:
backup:x:1089:
storage_manager:1090:
net_manager:x:1099:
edm:x:3051:
account:x:3058:
download:x:3815:
pasteboard:x:3816:
wallpaper:x:3817:
......
......@@ -174,7 +174,8 @@
"mkdir /data/system 0775 system system",
"mkdir /data/system/dropbox 0700 system system",
"mkdir /data/system/heapdump 0700 system system",
"mkdir /data/system/users 0775 system system",
"mkdir /data/system/users 0750 account account",
"mkdir /data/system/access_token 0770 access_token access_token",
"mkdir /data/system_de 0770 system system",
"mkdir /data/system_ce 0770 system system",
"mkdir /data/misc_de 01771 system misc",
......
......@@ -163,7 +163,8 @@
"mkdir /data/system 0775 system system",
"mkdir /data/system/dropbox 0700 system system",
"mkdir /data/system/heapdump 0700 system system",
"mkdir /data/system/users 0775 system system",
"mkdir /data/system/users 0750 account account",
"mkdir /data/system/access_token 0770 access_token access_token",
"mkdir /data/system_de 0770 system system",
"mkdir /data/system_ce 0770 system system",
"mkdir /data/misc_de 01771 system misc",
......
......@@ -73,6 +73,7 @@ dscreen:x:3054:3054:::/bin/false
daudio:x:3055:3055:::/bin/false
dhardware:x:3056:3056:::/bin/false
installs:x:3060:3060:::/bin/false
huks_server:x:3510:3510:::/bin/false
dms:x:5522:5522:::/bin/false
dbms:x:6000:6000:::/bin/false
update:x:6666:6666:::/bin/false
......@@ -88,7 +89,7 @@ useriam:x:1088:1088:::/bin/false
backup:x:1089:1089:::/bin/false
storage_manager:x:1090:1090:::/bin/false
net_manager:x:1099:1099:::/bin/false
edm:x:3051:3051:::/bin/false
account:x:3058:3058:::/bin/false
download:x:3815:3815:::/bin/false
pasteboard:x:3816:3816:::/bin/false
wallpaper:x:3817:3817:::/bin/false
......
......@@ -268,7 +268,7 @@ static int BindCpuCore(Service *service)
static void ClearEnvironment(Service *service)
{
if (strcmp(service->name, "appspawn") != 0) {
if (strcmp(service->name, "appspawn") != 0 && strcmp(service->name, "nwebspawn") != 0) {
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
......
......@@ -274,7 +274,8 @@ static int GetServiceArgs(const cJSON *argJson, const char *name, int maxCount,
args->argv[i] = NULL;
}
// ServiceArgs have a variety of uses, some requiring a NULL ending, some not
if (strcmp(name, D_CAPS_STR_IN_CFG) != 0) {
if (strcmp(name, D_CAPS_STR_IN_CFG) != 0 && strcmp(name, "permission_acls") != 0 &&
strcmp(name, "permission") != 0) {
args->count = count + 1;
} else {
args->count = count;
......@@ -611,7 +612,8 @@ static int CheckServiceKeyName(const cJSON *curService)
char *cfgServiceKeyList[] = {
"name", "path", "uid", "gid", "once", "importance", "caps", "disabled",
"writepid", "critical", "socket", "console", "file", "ondemand",
"d-caps", "apl", "jobs", "start-mode", "end-mode", "cpucore", "secon", "sandbox"
"d-caps", "apl", "jobs", "start-mode", "end-mode", "cpucore", "secon", "sandbox",
"permission", "permission_acls"
};
INIT_CHECK_RETURN_VALUE(curService != NULL, SERVICE_FAILURE);
cJSON *child = curService->child;
......
......@@ -29,7 +29,8 @@ enum INIT_BOOTSTAGE {
INIT_PRE_PARAM_SERVICE = 10,
INIT_PRE_PARAM_LOAD = 20,
INIT_PRE_CFG_LOAD = 30,
INIT_POST_CFG_LOAD = 40
INIT_POST_PERSIST_PARAM_LOAD = 40,
INIT_POST_CFG_LOAD = 50
};
inline int InitAddGlobalInitHook(int prio, OhosHook hook)
......@@ -57,6 +58,10 @@ inline int InitAddPostCfgLoadHook(int prio, OhosHook hook)
return HookMgrAdd(NULL, INIT_POST_CFG_LOAD, prio, hook);
}
inline int InitAddPostPersistParamLoadHook(int prio, OhosHook hook)
{
return HookMgrAdd(NULL, INIT_POST_PERSIST_PARAM_LOAD, prio, hook);
}
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -25,7 +25,7 @@ int InitModuleMgrInstall(const char *moduleName)
}
if (defaultModuleMgr == NULL) {
defaultModuleMgr = ModuleMgrCreate(moduleName);
defaultModuleMgr = ModuleMgrCreate("init");
}
if (defaultModuleMgr == NULL) {
return -1;
......@@ -43,8 +43,11 @@ static int ModuleMgrCmdInstall(int id, const char *name, int argc, const char **
{
INIT_ERROR_CHECK(argv != NULL && argc >= 1, return -1, "Invalid install parameter");
int ret;
ret = ModuleMgrInstall(NULL, argv[0], argc-1, argv+1);
INIT_ERROR_CHECK(ret == 0, return ret, "Install module %s fail", argv[0]);
if (defaultModuleMgr == NULL) {
defaultModuleMgr = ModuleMgrCreate("init");
}
ret = ModuleMgrInstall(defaultModuleMgr, argv[0], argc-1, argv+1);
INIT_ERROR_CHECK(ret == 0, return ret, "Install module %s fail errno %d", argv[0], ret);
return 0;
}
......
......@@ -253,6 +253,8 @@ static void BootStateChange(const char *content)
}
if (strcmp("post-init", content) == 0) {
StartAllServices(START_MODE_NARMAL);
// Destroy all hooks
HookMgrDestroy(NULL);
return;
}
}
......@@ -358,9 +360,6 @@ void SystemConfig(void)
INIT_LOGI("Parse init config file done.");
HookMgrExecute(NULL, INIT_POST_CFG_LOAD, (void *)&args);
// Destroy all hooks
HookMgrDestroy(NULL);
// dump config
#if defined(OHOS_SERVICE_DUMP)
AddCmdExecutor("display", SystemDump);
......
......@@ -29,8 +29,9 @@
#include <sys/sysmacros.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/module.h>
#include "bootstage.h"
#include "fs_manager/fs_manager.h"
#include "init_jobs_internal.h"
#include "init_log.h"
......@@ -178,8 +179,9 @@ static void DoSetParam(const struct CmdArgs *ctx)
static void DoLoadPersistParams(const struct CmdArgs *ctx)
{
INIT_LOGV("load persist params : %s", ctx->argv[0]);
INIT_LOGV("LoadPersistParams");
LoadPersistParams();
HookMgrExecute(NULL, INIT_POST_PERSIST_PARAM_LOAD, NULL);
}
static void DoTriggerCmd(const struct CmdArgs *ctx)
......
......@@ -264,14 +264,45 @@ static int DoBootchartStop(void)
return 0;
}
static int DoBootchartCmd(int id, const char *name, int argc, const char **argv)
{
PLUGIN_LOGI("DoBootchartCmd argc %d %s", argc, name);
PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter");
if (strcmp(argv[0], "start") == 0) {
return DoBootchartStart();
} else if (strcmp(argv[0], "stop") == 0) {
return DoBootchartStop();
}
return 0;
}
static int32_t g_executorId = -1;
static int BootchartInit(void)
{
if (g_executorId == -1) {
g_executorId = AddCmdExecutor("bootchart", DoBootchartCmd);
PLUGIN_LOGI("BootchartInit executorId %d", g_executorId);
}
return 0;
}
static void BootchartExit(void)
{
PLUGIN_LOGI("BootchartExit executorId %d", g_executorId);
if (g_executorId != -1) {
RemoveCmdExecutor("bootchart", g_executorId);
}
}
MODULE_CONSTRUCTOR(void)
{
PLUGIN_LOGI("DoBootchartStart now ...");
DoBootchartStart();
BootchartInit();
}
MODULE_DESTRUCTOR(void)
{
PLUGIN_LOGI("DoBootchartStop now ...");
DoBootchartStop();
BootchartExit();
}
......@@ -34,5 +34,5 @@ static int bootchartEarlyHook(int stage, int prio, void *cookie)
MODULE_CONSTRUCTOR(void)
{
// Depends on parameter service
InitAddPreCfgLoadHook(0, bootchartEarlyHook);
InitAddPostPersistParamLoadHook(0, bootchartEarlyHook);
}
......@@ -69,12 +69,28 @@ ohos_executable("server") {
part_name = "init"
}
ohos_executable("ondemandTest") {
sources = [ "sa_service_ondemand_test.cpp" ]
external_deps = [
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"utils_base:utils",
]
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
group("exectest") {
if (control_test) {
deps = [
":client",
":fd_holder_test",
":fd_holder_test.cfg",
":ondemandTest",
":server",
]
}
......
......@@ -69,6 +69,9 @@ int main(int argc, char **argv)
}
free(fds);
outfdCount = 0;
while (1) {
pause();
}
}
char *files[] = {"/data/test/1", "/data/test/2"};
SaveFds("fd_holder_test", FD_COUNT, (char **)files);
......
......@@ -12,7 +12,6 @@
"path" : ["/system/bin/fd_holder_test", "save", "fd_holder_test", "/data/test/1", "/data/test/2"],
"uid" : "root",
"gid" : "system",
"once" : 1
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "system_ability_load_callback_stub.h"
using namespace OHOS;
using namespace std;
class OnDemandLoadCallback : public SystemAbilityLoadCallbackStub {
public:
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject>& remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
};
void OnDemandLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const sptr<IRemoteObject>& remoteObject)
{
cout << "OnLoadSystemAbilitySuccess systemAbilityId:" << systemAbilityId << " IRemoteObject result:" <<
((remoteObject != nullptr) ? "succeed" : "failed") << endl;
}
void OnDemandLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
cout << "OnLoadSystemAbilityFail systemAbilityId:" << systemAbilityId << endl;
}
int main(int argc, char *argv[])
{
std::map<string, int> saService = {
{"updater_sa", UPDATE_DISTRIBUTED_SERVICE_ID},
{"softbus_server", SOFTBUS_SERVER_SA_ID},
};
int parameterNum = 2;
if ((argc != parameterNum) || (argv[1] == nullptr)) {
cout << "Invaild parameter" << endl;
}
const string name = argv[1];
int abilityId = 0;
std::map<string, int>::iterator item = saService.find(name);
if (item != saService.end()) {
cout << "sa service name " << item->first << "ability id " << item->second << endl;
abilityId = item->second;
} else {
cout << "Invaild sa service name" << endl;
return 0;
}
sptr<OnDemandLoadCallback> loadCallback_ = new OnDemandLoadCallback();
sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sm == nullptr) {
cout << "GetSystemAbilityManager samgr object null!" << endl;
return 0;
}
int32_t result = sm->LoadSystemAbility(abilityId, loadCallback_);
if (result != ERR_OK) {
cout << "systemAbilityId:" << abilityId << " load failed, result code:" << result << endl;
return 0;
}
return 0;
}
......@@ -153,7 +153,6 @@ public:
if (serverTask_ == nullptr) {
return;
}
((StreamServerTask *)serverTask_)->base.handleEvent(LE_GetDefaultLoop(), serverTask_, Event_Write);
((StreamServerTask *)serverTask_)->base.handleEvent(LE_GetDefaultLoop(), serverTask_, Event_Read);
uint64_t eventId = 0;
......@@ -170,7 +169,7 @@ public:
BufferHandle handle = LE_CreateBuffer(LE_GetDefaultLoop(), 1 + sizeof(eventId));
LE_Buffer *buffer = (LE_Buffer *)handle;
AddBuffer((StreamTask *)client, buffer);
((StreamConnectTask *)client)->stream.base.handleEvent(LE_GetDefaultLoop(), (TaskHandle)(&client), Event_Write);
((StreamConnectTask *)client)->stream.base.handleEvent(LE_GetDefaultLoop(), (TaskHandle)(client), Event_Write);
ParamMessage *request = (ParamMessage *)CreateParamMessage(MSG_SET_PARAM, "name", sizeof(ParamMessage));
((StreamConnectTask *)client)->recvMessage(LE_GetDefaultLoop(), reinterpret_cast<uint8_t *>(request),
......@@ -179,7 +178,7 @@ public:
LE_Buffer *next = nullptr;
LE_Buffer *nextBuff = GetNextBuffer((StreamTask *)client, next);
if (nextBuff != nullptr) {
LE_FreeBuffer(LE_GetDefaultLoop(), (TaskHandle)&client, nextBuff);
LE_FreeBuffer(LE_GetDefaultLoop(), (TaskHandle)client, nextBuff);
}
ParamWatcher *watcher = (ParamWatcher *)ParamGetTaskUserData(client);
PARAM_CHECK(watcher != nullptr, return, "Failed to get watcher");
......
......@@ -49,24 +49,7 @@ static void PollUeventdSocketTimeout(int ueventSockFd)
int main(int argc, char **argv)
{
char *vendorConfig = NULL;
do {
char hardware[CMDLINE_VALUE_LEN_MAX] = {0};
unsigned int buffLen = (unsigned int)CMDLINE_VALUE_LEN_MAX;
int ret = SystemReadParam("ohos.boot.hardware", hardware, &buffLen);
if (ret != 0) {
INIT_LOGE("Failed to get hardware parameter value");
break;
}
char configFile[PATH_MAX] = {0};
ret = snprintf_s(configFile, PATH_MAX, PATH_MAX -1, "/vendor/etc/ueventd.%s.config", hardware);
if (ret < 0) {
INIT_LOGE("Failed to format vendor config file path");
break;
}
vendorConfig = configFile;
} while (0);
char *ueventdConfigs[] = {"/etc/ueventd.config", vendorConfig, NULL};
char *ueventdConfigs[] = {"/etc/ueventd.config", "/vendor/etc/ueventd.config", NULL};
int i = 0;
while (ueventdConfigs[i] != NULL) {
ParseUeventdConfigFile(ueventdConfigs[i++]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册