mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-23 16:20:00 +00:00
Merge branch 'master' of gitee.com:openharmony/startup_init into 1010
Signed-off-by: duxianzhi <duxianzhi@huawei.com>
This commit is contained in:
commit
72138e5529
@ -28,6 +28,7 @@ namespace OHOS {
|
||||
namespace device_info {
|
||||
|
||||
static const int DEVINFO_SAID = 3902;
|
||||
static const int DEVICEINFO_LOAD_SA_TIMEOUT_MS = 5000;
|
||||
|
||||
DeviceInfoKits::DeviceInfoKits() {}
|
||||
|
||||
|
@ -48,7 +48,6 @@ private:
|
||||
return deathRecipient_;
|
||||
}
|
||||
|
||||
static const int DEVICEINFO_LOAD_SA_TIMEOUT_MS = 5000;
|
||||
void LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock);
|
||||
sptr<IDeviceInfo> GetService(std::unique_lock<std::mutex> &lock);
|
||||
std::mutex lock_;
|
||||
|
@ -140,11 +140,7 @@ int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts, const char *sepa
|
||||
char *rest = NULL;
|
||||
FstabItem *item = NULL;
|
||||
char *p = NULL;
|
||||
|
||||
if (separator == NULL || *separator == '\0') {
|
||||
BEGET_LOGE("Invalid separator for parsing fstab");
|
||||
return -1;
|
||||
}
|
||||
BEGET_ERROR_CHECK(separator != NULL && *separator != '\0', return -1, "Invalid separator for parsing fstab");
|
||||
|
||||
if ((item = (FstabItem *)calloc(1, sizeof(FstabItem))) == NULL) {
|
||||
errno = ENOMEM;
|
||||
@ -153,29 +149,21 @@ int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts, const char *sepa
|
||||
}
|
||||
|
||||
do {
|
||||
if ((p = strtok_r(str, separator, &rest)) == NULL) {
|
||||
BEGET_LOGE("Failed to parse block device.");
|
||||
break;
|
||||
}
|
||||
BEGET_ERROR_CHECK((p = strtok_r(str, separator, &rest)) != NULL, break, "Failed to parse block device.");
|
||||
item->deviceName = strdup(p);
|
||||
BEGET_ERROR_CHECK(item->deviceName != NULL, break, "strdup deviceName failed.");
|
||||
|
||||
if ((p = strtok_r(NULL, separator, &rest)) == NULL) {
|
||||
BEGET_LOGE("Failed to parse mount point.");
|
||||
break;
|
||||
}
|
||||
BEGET_ERROR_CHECK((p = strtok_r(NULL, separator, &rest)) != NULL, break, "Failed to parse mount point.");
|
||||
item->mountPoint = strdup(p);
|
||||
BEGET_ERROR_CHECK(item->mountPoint != NULL, break, "strdup mountPoint failed.");
|
||||
|
||||
if ((p = strtok_r(NULL, separator, &rest)) == NULL) {
|
||||
BEGET_LOGE("Failed to parse fs type.");
|
||||
break;
|
||||
}
|
||||
BEGET_ERROR_CHECK((p = strtok_r(NULL, separator, &rest)) != NULL, break, "Failed to parse fs type.");
|
||||
item->fsType = strdup(p);
|
||||
BEGET_ERROR_CHECK(item->fsType != NULL, break, "strdup fsType failed.");
|
||||
|
||||
if ((p = strtok_r(NULL, separator, &rest)) == NULL) {
|
||||
BEGET_LOGE("Failed to parse mount options.");
|
||||
break;
|
||||
}
|
||||
BEGET_ERROR_CHECK((p = strtok_r(NULL, separator, &rest)) != NULL, break, "Failed to parse mount options.");
|
||||
item->mountOptions = strdup(p);
|
||||
BEGET_ERROR_CHECK(item->mountOptions != NULL, break, "strdup mountOptions failed.");
|
||||
|
||||
if ((p = strtok_r(NULL, separator, &rest)) == NULL) {
|
||||
BEGET_LOGE("Failed to parse fs manager flags.");
|
||||
|
@ -111,6 +111,13 @@ int LoadDefaultParams(const char *fileName, uint32_t mode);
|
||||
*/
|
||||
int LoadPersistParams(void);
|
||||
|
||||
/**
|
||||
* Init 接口
|
||||
* 加载加密目录下持久化参数。
|
||||
*
|
||||
*/
|
||||
int LoadPrivatePersistParams(void);
|
||||
|
||||
/**
|
||||
* Init 接口
|
||||
* 设置参数,主要用于其他进程使用,通过管道修改参数
|
||||
|
@ -52,7 +52,11 @@ static void DelayedUninstall(const IdleHandle taskHandle, void *context)
|
||||
|
||||
void AutorunModuleMgrUnInstall(const char *moduleName)
|
||||
{
|
||||
LE_DelayProc(LE_GetDefaultLoop(), DelayedUninstall, (void *)strdup(moduleName));
|
||||
void *context = (void *)strdup(moduleName);
|
||||
if (context == NULL) {
|
||||
return;
|
||||
}
|
||||
LE_DelayProc(LE_GetDefaultLoop(), DelayedUninstall, context);
|
||||
}
|
||||
|
||||
static void InitModuleDump(const MODULE_INFO *moduleInfo)
|
||||
|
@ -201,7 +201,7 @@ static void ScanModules(MODULE_MGR *moduleMgr, const char *path)
|
||||
BEGET_LOGV("Scan module with name '%s'", path);
|
||||
DIR *dir = opendir(path);
|
||||
BEGET_CHECK(dir != NULL, return);
|
||||
char *moduleName = malloc(PATH_MAX);
|
||||
char *moduleName = calloc(PATH_MAX, sizeof(char));
|
||||
while (moduleName != NULL) {
|
||||
struct dirent *file = readdir(dir);
|
||||
if (file == NULL) {
|
||||
|
@ -103,7 +103,7 @@ INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder
|
||||
uint32_t len = 0;
|
||||
int ret = SystemGetParameter(key, NULL, &len);
|
||||
if (ret == 0 && len > 0) {
|
||||
char *res = (char *)malloc(len + 1);
|
||||
char *res = (char *)calloc(1, len + 1);
|
||||
BEGET_CHECK(res != NULL, return NULL);
|
||||
ret = SystemGetParameter(key, res, &len);
|
||||
if (ret != 0) {
|
||||
|
@ -53,7 +53,7 @@ const char* DeviceInfo::CjGetDeviceType()
|
||||
|
||||
const char* DeviceInfo::CjGetUdid()
|
||||
{
|
||||
char* udid = static_cast<char*>(malloc(UDID_LEN));
|
||||
char* udid = static_cast<char*>(calloc(1, UDID_LEN));
|
||||
if (udid == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ static void WriteLogoContent(int fd, const std::string &logoPath, uint32_t size)
|
||||
std::cout << "cannot find pic file\n";
|
||||
return;
|
||||
}
|
||||
char *buffer = reinterpret_cast<char *>(malloc(size));
|
||||
char *buffer = reinterpret_cast<char *>(calloc(1, size));
|
||||
if (buffer == nullptr) {
|
||||
(void)fclose(rgbFile);
|
||||
return;
|
||||
|
@ -486,8 +486,8 @@ static int32_t BShellParamCmdShell(BShellHandle shell, int32_t argc, char *argv[
|
||||
SetInitLogLevel(INIT_INFO);
|
||||
pid_t pid = 0;
|
||||
if (args.cloneFlg) {
|
||||
char *childStack = (char *)malloc(STACK_SIZE);
|
||||
BSH_CHECK(childStack != NULL, return -1, "malloc failed");
|
||||
char *childStack = (char *)calloc(1, STACK_SIZE);
|
||||
BSH_CHECK(childStack != NULL, return -1, "calloc failed");
|
||||
pid = clone(ExecFunc, childStack + STACK_SIZE, CLONE_NEWPID | CLONE_NEWNS | SIGCHLD, (void *)&args);
|
||||
free(childStack);
|
||||
} else {
|
||||
|
@ -132,6 +132,7 @@ int32_t BShellEnvOutputPrompt(BShellHandle handle, const char *prompt)
|
||||
}
|
||||
} else {
|
||||
shell->prompt = strdup(prompt);
|
||||
BSH_CHECK(shell->prompt != NULL, return BSH_INVALID_PARAM, "strdup prompt failed.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -418,6 +419,7 @@ int32_t BShellEnvInit(BShellHandle *handle, const BShellInfo *info)
|
||||
shell->shellState = BSH_IN_NORMAL;
|
||||
shell->input = info->input;
|
||||
shell->prompt = strdup(info->prompt);
|
||||
BSH_CHECK(shell->prompt != NULL, return BSH_INVALID_PARAM, "Failed to strdup prompt");
|
||||
shell->command = NULL;
|
||||
shell->param = NULL;
|
||||
shell->keyHandle = NULL;
|
||||
|
@ -131,6 +131,7 @@
|
||||
"mkdir /data/chipset/el1 0711 root root",
|
||||
"mkdir /data/chipset/el1/public 0711 root root",
|
||||
"mkdir /data/chipset/el2 0711 root root",
|
||||
"load_private_persist_params ",
|
||||
"init_main_user ",
|
||||
"mkdir /data/app/el1/0 0711 root root",
|
||||
"mkdir /data/app/el1/0/base 0711 root root",
|
||||
|
@ -29,7 +29,7 @@ const.build.product=default
|
||||
const.product.hardwareversion=default
|
||||
const.product.bootloader.version=bootloader
|
||||
const.product.cpu.abilist=default
|
||||
const.product.software.version=OpenHarmony 5.0.2.46
|
||||
const.product.software.version=OpenHarmony 5.0.2.49
|
||||
const.product.incremental.version=default
|
||||
const.product.firstapiversion=1
|
||||
const.product.build.type=default
|
||||
|
@ -13,4 +13,4 @@
|
||||
const.ohos.version.security_patch=2024/10/01
|
||||
const.ohos.releasetype=Canary1
|
||||
const.ohos.apiversion=14
|
||||
const.ohos.fullname=OpenHarmony-5.0.2.46
|
||||
const.ohos.fullname=OpenHarmony-5.0.2.49
|
@ -14,4 +14,4 @@
|
||||
const.ohos.releasetype=Canary1
|
||||
const.ohos.apiversion=14
|
||||
const.ohos.version.security_patch=2024/10/01
|
||||
const.ohos.fullname=OpenHarmony-5.0.2.46
|
||||
const.ohos.fullname=OpenHarmony-5.0.2.49
|
@ -106,7 +106,7 @@ const struct CmdArgs *GetCmdArg(const char *cmdContent, const char *delim, int a
|
||||
INIT_WARNING_CHECK(argsCount <= SPACES_CNT_IN_CMD_MAX, argsCount = SPACES_CNT_IN_CMD_MAX,
|
||||
"Too much arguments for command, max number is %d", SPACES_CNT_IN_CMD_MAX);
|
||||
struct CmdArgs *ctx = (struct CmdArgs *)calloc(1, sizeof(struct CmdArgs) + sizeof(char *) * (argsCount + 1));
|
||||
INIT_ERROR_CHECK(ctx != NULL, return NULL, "Failed to malloc memory for arg");
|
||||
INIT_ERROR_CHECK(ctx != NULL, return NULL, "Failed to calloc memory for arg");
|
||||
ctx->argc = 0;
|
||||
const char *p = cmdContent;
|
||||
const char *end = cmdContent + strlen(cmdContent);
|
||||
|
@ -202,8 +202,8 @@ static void DropCapability(const Service *service)
|
||||
{
|
||||
#ifndef OHOS_LITE
|
||||
int invalidCnt = CAP_LAST_CAP - service->servPerm.capsCnt + 1;
|
||||
unsigned int *caps = (unsigned int *)malloc(sizeof(unsigned int) * invalidCnt);
|
||||
INIT_ERROR_CHECK(caps != NULL, return, "malloc caps failed! error:%d", errno);
|
||||
unsigned int *caps = (unsigned int *)calloc(invalidCnt, sizeof(unsigned int));
|
||||
INIT_ERROR_CHECK(caps != NULL, return, "calloc caps failed! error:%d", errno);
|
||||
|
||||
GetInvalidCaps(service, caps);
|
||||
for (int i = 0; i < invalidCnt; i++) {
|
||||
@ -360,7 +360,7 @@ static int PublishHoldFds(Service *service)
|
||||
ret = snprintf_s((char *)fdBuffer + pos, sizeof(fdBuffer) - pos, sizeof(fdBuffer) - 1, "%d ", fd);
|
||||
INIT_ERROR_CHECK(ret >= 0, return INIT_EFORMAT,
|
||||
"Service error %d %s, failed to format fd for publish", ret, service->name);
|
||||
pos += ret;
|
||||
pos += (size_t)ret;
|
||||
}
|
||||
fdBuffer[pos - 1] = '\0'; // Remove last ' '
|
||||
INIT_LOGI("Service %s publish fd [%s]", service->name, fdBuffer);
|
||||
@ -712,13 +712,13 @@ static bool CalculateCrashTime(Service *service, int crashTimeLimit, int crashCo
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &curTime);
|
||||
struct timespec crashTime = {service->firstCrashTime, 0};
|
||||
if (service->crashCnt == 0) {
|
||||
service->firstCrashTime = curTime.tv_sec;
|
||||
service->firstCrashTime = (uint32_t)curTime.tv_sec;
|
||||
++service->crashCnt;
|
||||
if (service->crashCnt == crashCountLimit) {
|
||||
return false;
|
||||
}
|
||||
} else if (IntervalTime(&crashTime, &curTime) > crashTimeLimit) {
|
||||
service->firstCrashTime = curTime.tv_sec;
|
||||
} else if (IntervalTime(&crashTime, &curTime) > (uint32_t)crashTimeLimit) {
|
||||
service->firstCrashTime = (uint32_t)curTime.tv_sec;
|
||||
service->crashCnt = 1;
|
||||
} else {
|
||||
++service->crashCnt;
|
||||
|
@ -40,6 +40,9 @@
|
||||
#include "bootstage.h"
|
||||
#endif
|
||||
|
||||
#define VALUE_ATTR_CONSOLE 1
|
||||
#define VALUE_ATTR_KMSG 2
|
||||
|
||||
// All service processes that init will fork+exec.
|
||||
static ServiceSpace g_serviceSpace = { 0 };
|
||||
static const int CRITICAL_DEFAULT_CRASH_TIME = 240;
|
||||
@ -861,9 +864,9 @@ static int SetConsoleValue(Service *service, const char *attrName, int value, in
|
||||
UNUSED(attrName);
|
||||
UNUSED(flag);
|
||||
INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "Set service attr failed! null ptr.");
|
||||
if (value == 1) {
|
||||
if (value == VALUE_ATTR_CONSOLE) {
|
||||
service->attribute |= SERVICE_ATTR_CONSOLE;
|
||||
} if (value == 2) {
|
||||
} else if (value == VALUE_ATTR_KMSG) {
|
||||
service->attribute |= SERVICE_ATTR_KMSG;
|
||||
}
|
||||
return SERVICE_SUCCESS;
|
||||
|
@ -185,6 +185,12 @@ static void DoLoadPersistParams(const struct CmdArgs *ctx)
|
||||
{
|
||||
INIT_LOGV("LoadPersistParams");
|
||||
LoadPersistParams();
|
||||
}
|
||||
|
||||
static void DoLoadPrivatePersistParams(const struct CmdArgs *ctx)
|
||||
{
|
||||
INIT_LOGV("LoadPersistParams");
|
||||
LoadPrivatePersistParams();
|
||||
HookMgrExecute(GetBootStageHookMgr(), INIT_POST_PERSIST_PARAM_LOAD, NULL, NULL);
|
||||
}
|
||||
|
||||
@ -575,6 +581,7 @@ static const struct CmdTable g_cmdTable[] = {
|
||||
{ "insmod ", 1, 10, 1, DoInsmod },
|
||||
{ "setparam ", 2, 2, 0, DoSetParam },
|
||||
{ "load_persist_params ", 0, 1, 0, DoLoadPersistParams },
|
||||
{ "load_private_persist_params ", 0, 1, 0, DoLoadPrivatePersistParams },
|
||||
{ "load_param ", 1, 2, 0, DoLoadDefaultParams },
|
||||
{ "load_access_token_id ", 0, 1, 0, DoLoadAccessTokenId },
|
||||
{ "ifup ", 1, 1, 1, DoIfup },
|
||||
|
@ -133,7 +133,8 @@ static void StartSecondStageInit(long long uptime)
|
||||
|
||||
char buf[64];
|
||||
uptime = GetUptimeInMicroSeconds(NULL);
|
||||
snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, "%lld", uptime);
|
||||
INIT_CHECK_ONLY_ELOG(snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, "%lld", uptime) >= 0,
|
||||
"snprintf_s uptime to buf failed");
|
||||
// Execute init second stage
|
||||
char * const args[] = {
|
||||
"/bin/init",
|
||||
|
@ -47,4 +47,4 @@ int GetBootModeFromMisc(void)
|
||||
return GROUP_CHARGE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -54,7 +54,7 @@ static void LogToFile(const char *logFile, const char *tag, const char *info)
|
||||
}
|
||||
(void)fprintf(outfile, "[%s.%ld][pid=%d %d][%s]%s \n", dateTime, curr.tv_nsec, getpid(), gettid(), tag, info);
|
||||
(void)fflush(outfile);
|
||||
fclose(outfile);
|
||||
(void)fclose(outfile);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -43,7 +43,7 @@ static void DoAsyncEvent_(const LoopHandle loopHandle, AsyncEventTask *asyncTask
|
||||
free(buffer);
|
||||
#ifdef LOOP_DEBUG
|
||||
clock_gettime(CLOCK_MONOTONIC, &(endTime));
|
||||
diff = (long long)((endTime.tv_sec - startTime.tv_sec) * MILLION_MICROSECOND);
|
||||
diff = (long long)(endTime.tv_sec - startTime.tv_sec) * MILLION_MICROSECOND;
|
||||
if (endTime.tv_nsec > startTime.tv_nsec) {
|
||||
diff += (endTime.tv_nsec - startTime.tv_nsec) / THOUSAND_MILLISECOND; // 1000 ms
|
||||
} else {
|
||||
@ -63,8 +63,10 @@ void LE_DoAsyncEvent(const LoopHandle loopHandle, const TaskHandle taskHandle)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static LE_STATUS HandleAsyncEvent_(const LoopHandle loopHandle, const TaskHandle taskHandle, uint32_t oper)
|
||||
{
|
||||
LE_CHECK(loopHandle != NULL && taskHandle != NULL, return LE_INVALID_PARAM, "Invalid parameters");
|
||||
LE_LOGV("HandleAsyncEvent_ fd: %d oper 0x%x", GetSocketFd(taskHandle), oper);
|
||||
EventLoop *loop = (EventLoop *)loopHandle;
|
||||
AsyncEventTask *asyncTask = (AsyncEventTask *)taskHandle;
|
||||
|
@ -30,7 +30,7 @@ static LE_STATUS HandleSendMsg_(const LoopHandle loopHandle,
|
||||
LE_Buffer *buffer = GetFirstBuffer(stream);
|
||||
while (buffer) {
|
||||
int ret = write(GetSocketFd(taskHandle), buffer->data, buffer->dataSize);
|
||||
if (ret < buffer->dataSize) {
|
||||
if (ret < 0 || (size_t)ret < buffer->dataSize) {
|
||||
LE_LOGE("HandleSendMsg_ fd:%d send data size %d %d, err:%d", GetSocketFd(taskHandle),
|
||||
buffer->dataSize, ret, errno);
|
||||
}
|
||||
|
@ -33,11 +33,11 @@
|
||||
#include <policycoreutils.h>
|
||||
#endif
|
||||
|
||||
static int GetBootEventEnable(void)
|
||||
static int GetBootSwitchEnable(const char *paramName)
|
||||
{
|
||||
char bootEventOpen[6] = ""; // 6 is length of bool value
|
||||
uint32_t len = sizeof(bootEventOpen);
|
||||
SystemReadParam("persist.init.bootevent.enable", bootEventOpen, &len);
|
||||
SystemReadParam(paramName, bootEventOpen, &len);
|
||||
if (strcmp(bootEventOpen, "true") == 0 || strcmp(bootEventOpen, "1") == 0) {
|
||||
return 1;
|
||||
}
|
||||
@ -195,9 +195,9 @@ static int BootEventTraversal(ListNode *node, void *root)
|
||||
{
|
||||
static int start = 0;
|
||||
BOOT_EVENT_PARAM_ITEM *item = (BOOT_EVENT_PARAM_ITEM *)node;
|
||||
double forkTime = item->timestamp[BOOTEVENT_FORK].tv_sec * MSECTONSEC +
|
||||
double forkTime = (double)item->timestamp[BOOTEVENT_FORK].tv_sec * MSECTONSEC +
|
||||
(double)item->timestamp[BOOTEVENT_FORK].tv_nsec / USTONSEC;
|
||||
double readyTime = item->timestamp[BOOTEVENT_READY].tv_sec * MSECTONSEC +
|
||||
double readyTime = (double)item->timestamp[BOOTEVENT_READY].tv_sec * MSECTONSEC +
|
||||
(double)item->timestamp[BOOTEVENT_READY].tv_nsec / USTONSEC;
|
||||
double durTime = readyTime - forkTime;
|
||||
if (item->pid == 0) {
|
||||
@ -243,7 +243,7 @@ static int CreateBootEventFile(const char *file, mode_t mode)
|
||||
|
||||
static int SaveServiceBootEvent()
|
||||
{
|
||||
INIT_CHECK(GetBootEventEnable(), return 0);
|
||||
INIT_CHECK(GetBootSwitchEnable("persist.init.bootuptrace.enable"), return 0);
|
||||
|
||||
int ret = CreateBootEventFile(BOOTEVENT_OUTPUT_PATH "bootup.trace", S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
INIT_CHECK_RETURN_VALUE(ret == 0, -1);
|
||||
@ -270,7 +270,7 @@ static int SaveServiceBootEvent()
|
||||
|
||||
static void ReportSysEvent(void)
|
||||
{
|
||||
INIT_CHECK(GetBootEventEnable(), return);
|
||||
INIT_CHECK(GetBootSwitchEnable("persist.init.bootevent.enable"), return);
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
InitModuleMgrInstall("eventmodule");
|
||||
InitModuleMgrUnInstall("eventmodule");
|
||||
@ -310,8 +310,10 @@ static void WriteBooteventSysParam(const char *paramName)
|
||||
|
||||
uptime = GetUptimeInMicroSeconds(NULL);
|
||||
|
||||
snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, "%lld", uptime);
|
||||
snprintf_s(name, sizeof(name), sizeof(name) - 1, "ohos.boot.time.%s", paramName);
|
||||
INIT_CHECK_ONLY_ELOG(snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, "%lld", uptime) >= 0,
|
||||
"snprintf_s buf failed");
|
||||
INIT_CHECK_ONLY_ELOG(snprintf_s(name, sizeof(name), sizeof(name) - 1, "ohos.boot.time.%s", paramName) >= 0,
|
||||
"snprintf_s name failed");
|
||||
SystemWriteParam(name, buf);
|
||||
}
|
||||
|
||||
@ -435,10 +437,11 @@ static void AddReservedBooteventsByFile(const char *name)
|
||||
INIT_LOGI("Got priv-app bootevent: %s", buf);
|
||||
AddBootEventItemByName(buf);
|
||||
}
|
||||
fclose(file);
|
||||
(void)fclose(file);
|
||||
}
|
||||
|
||||
static void AddReservedBootevents(void) {
|
||||
static void AddReservedBootevents(void)
|
||||
{
|
||||
CfgFiles *files = GetCfgFiles("etc/init/priv_app.bootevents");
|
||||
for (int i = MAX_CFG_POLICY_DIRS_CNT - 1; files && i >= 0; i--) {
|
||||
if (files->paths[i]) {
|
||||
|
@ -26,6 +26,41 @@
|
||||
#include "securec.h"
|
||||
|
||||
#define BUFF_SIZE 256
|
||||
#define POWEROFF_REASON_DEV_PATH "/proc/poweroff_reason"
|
||||
|
||||
static int WritePowerOffReason(const char* reason)
|
||||
{
|
||||
PLUGIN_CHECK(reason != NULL, return -1, "WritePowerOffReason: reason is NULL\n");
|
||||
PLUGIN_CHECK(access(POWEROFF_REASON_DEV_PATH, F_OK) == 0, return -1,
|
||||
"WritePowerOffReason: access %s failed, errno = %d, %s\n",
|
||||
POWEROFF_REASON_DEV_PATH, errno, strerror(errno));
|
||||
int fd = open(POWEROFF_REASON_DEV_PATH, O_RDWR);
|
||||
PLUGIN_CHECK(fd > 0, return -1, "WritePowerOffReason: errno = %d, %s\n", errno, strerror(errno));
|
||||
int writeBytes = strlen(reason);
|
||||
int ret = write(fd, reason, writeBytes);
|
||||
PLUGIN_CHECK(ret == writeBytes, writeBytes = -1, "WritePowerOffReason: write poweroff reason failed\n");
|
||||
close(fd);
|
||||
return writeBytes;
|
||||
}
|
||||
|
||||
static void ParseRebootReason(const char *name, int argc, const char **argv)
|
||||
{
|
||||
char str[BUFF_SIZE] = {0};
|
||||
int len = sizeof(str);
|
||||
char *tmp = str;
|
||||
int ret;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
ret = sprintf_s(tmp, len - 1, "%s ", argv[i]);
|
||||
if (ret <= 0) {
|
||||
PLUGIN_LOGW("ParseRebootReason: sprintf_s arg %s failed!", argv[i]);
|
||||
break;
|
||||
}
|
||||
len -= ret;
|
||||
tmp += ret;
|
||||
}
|
||||
ret = WritePowerOffReason(str);
|
||||
PLUGIN_CHECK(ret >= 0, return, "ParseRebootReason: write poweroff reason failed\n");
|
||||
}
|
||||
|
||||
PLUGIN_STATIC int DoRoot_(const char *jobName, int type)
|
||||
{
|
||||
@ -43,9 +78,7 @@ PLUGIN_STATIC int DoRoot_(const char *jobName, int type)
|
||||
static int DoReboot(int id, const char *name, int argc, const char **argv)
|
||||
{
|
||||
UNUSED(id);
|
||||
UNUSED(name);
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
// clear misc
|
||||
(void)UpdateMiscMessage(NULL, "reboot", NULL, NULL);
|
||||
return DoRoot_("reboot", RB_AUTOBOOT);
|
||||
@ -54,25 +87,7 @@ static int DoReboot(int id, const char *name, int argc, const char **argv)
|
||||
static int DoRebootPanic(int id, const char *name, int argc, const char **argv)
|
||||
{
|
||||
UNUSED(id);
|
||||
char str[BUFF_SIZE] = {0};
|
||||
int ret = sprintf_s(str, sizeof(str) - 1, "panic caused by %s:", name);
|
||||
if (ret <= 0) {
|
||||
PLUGIN_LOGW("DoRebootPanic sprintf_s name %s failed!", name);
|
||||
}
|
||||
|
||||
int len = ret > 0 ? (sizeof(str) - ret) : sizeof(str);
|
||||
char *tmp = str + (sizeof(str) - len);
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
ret = sprintf_s(tmp, len - 1, " %s", argv[i]);
|
||||
if (ret <= 0) {
|
||||
PLUGIN_LOGW("DoRebootPanic sprintf_s arg %s failed!", argv[i]);
|
||||
break;
|
||||
} else {
|
||||
len -= ret;
|
||||
tmp += ret;
|
||||
}
|
||||
}
|
||||
PLUGIN_LOGI("DoRebootPanic %s", str);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
if (InRescueMode() == 0) {
|
||||
PLUGIN_LOGI("Don't panic in resuce mode!");
|
||||
return 0;
|
||||
@ -98,10 +113,8 @@ static int DoRebootPanic(int id, const char *name, int argc, const char **argv)
|
||||
PLUGIN_STATIC int DoRebootShutdown(int id, const char *name, int argc, const char **argv)
|
||||
{
|
||||
UNUSED(id);
|
||||
UNUSED(name);
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter");
|
||||
ParseRebootReason(name, argc, argv);
|
||||
// clear misc
|
||||
(void)UpdateMiscMessage(NULL, "reboot", NULL, NULL);
|
||||
const size_t len = strlen("reboot,");
|
||||
@ -126,6 +139,7 @@ static int DoRebootUpdater(int id, const char *name, int argc, const char **argv
|
||||
PLUGIN_LOGI("DoRebootUpdater argc %d %s", argc, name);
|
||||
PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter");
|
||||
PLUGIN_LOGI("DoRebootUpdater argv %s", argv[0]);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
int ret = UpdateMiscMessage(argv[0], "updater", "updater:", "boot_updater");
|
||||
if (ret == 0) {
|
||||
return DoRoot_("reboot", RB_AUTOBOOT);
|
||||
@ -139,6 +153,7 @@ PLUGIN_STATIC int DoRebootFlashed(int id, const char *name, int argc, const char
|
||||
PLUGIN_LOGI("DoRebootFlashed argc %d %s", argc, name);
|
||||
PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter");
|
||||
PLUGIN_LOGI("DoRebootFlashd argv %s", argv[0]);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
int ret = UpdateMiscMessage(argv[0], "flash", "flash:", "boot_flash");
|
||||
if (ret == 0) {
|
||||
return DoRoot_("reboot", RB_AUTOBOOT);
|
||||
@ -149,9 +164,7 @@ PLUGIN_STATIC int DoRebootFlashed(int id, const char *name, int argc, const char
|
||||
PLUGIN_STATIC int DoRebootCharge(int id, const char *name, int argc, const char **argv)
|
||||
{
|
||||
UNUSED(id);
|
||||
UNUSED(name);
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
int ret = UpdateMiscMessage(NULL, "charge", "charge:", "boot_charge");
|
||||
if (ret == 0) {
|
||||
return DoRoot_("reboot", RB_AUTOBOOT);
|
||||
@ -162,20 +175,18 @@ PLUGIN_STATIC int DoRebootCharge(int id, const char *name, int argc, const char
|
||||
static int DoRebootSuspend(int id, const char *name, int argc, const char **argv)
|
||||
{
|
||||
UNUSED(id);
|
||||
UNUSED(name);
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
return DoRoot_("suspend", RB_AUTOBOOT);
|
||||
}
|
||||
|
||||
PLUGIN_STATIC int DoRebootOther(int id, const char *name, int argc, const char **argv)
|
||||
{
|
||||
UNUSED(id);
|
||||
UNUSED(name);
|
||||
PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter argc %d", argc);
|
||||
const char *cmd = strstr(argv[0], "reboot,");
|
||||
PLUGIN_CHECK(cmd != NULL, return -1, "Invalid parameter argc %s", argv[0]);
|
||||
PLUGIN_LOGI("DoRebootOther argv %s", argv[0]);
|
||||
ParseRebootReason(name, argc, argv);
|
||||
// clear misc
|
||||
(void)UpdateMiscMessage(NULL, "reboot", NULL, NULL);
|
||||
DoJobNow("reboot");
|
||||
|
@ -94,7 +94,7 @@ static char *ReadFile(const char *path)
|
||||
PLUGIN_CHECK(fd != NULL, return NULL, "Failed to fopen path %s", path);
|
||||
char *buffer = NULL;
|
||||
do {
|
||||
buffer = (char*)malloc((size_t)(fileStat.st_size + 1));
|
||||
buffer = (char*)calloc((size_t)(fileStat.st_size + 1), sizeof(char));
|
||||
PLUGIN_CHECK(buffer != NULL, break, "Failed to alloc memory for path %s", path);
|
||||
if (fread(buffer, fileStat.st_size, 1, fd) != 1) {
|
||||
PLUGIN_LOGE("Failed to read file %s errno:%d", path, errno);
|
||||
@ -342,7 +342,7 @@ static bool ClearTrace(void)
|
||||
static void DumpCompressedTrace(int traceFd, int outFd)
|
||||
{
|
||||
int flush = Z_NO_FLUSH;
|
||||
uint8_t *inBuffer = malloc(CHUNK_SIZE);
|
||||
uint8_t *inBuffer = calloc(1, CHUNK_SIZE);
|
||||
PLUGIN_CHECK(inBuffer != NULL, return, "Error: couldn't allocate buffers\n");
|
||||
uint8_t *outBuffer = malloc(CHUNK_SIZE);
|
||||
PLUGIN_CHECK(outBuffer != NULL, free(inBuffer);
|
||||
@ -428,7 +428,7 @@ static bool MarkOthersClockSync(void)
|
||||
FILE *file = fopen(realPath, "wt+");
|
||||
PLUGIN_CHECK(file != NULL, return false, "Error: opening %s, errno: %d", TRACE_MARKER_PATH, errno);
|
||||
do {
|
||||
int64_t realtime = (int64_t)((rts.tv_sec * nanoSeconds + rts.tv_nsec) / nanoToMill);
|
||||
int64_t realtime = ((int64_t)rts.tv_sec * nanoSeconds + rts.tv_nsec) / nanoToMill;
|
||||
float parentTs = (float)((((float)mts.tv_sec) * nanoSeconds + mts.tv_nsec) / nanoToSecond);
|
||||
int ret = fprintf(file, "trace_event_clock_sync: realtime_ts=%" PRId64 "\n", realtime);
|
||||
PLUGIN_CHECK(ret > 0, break, "Warning: writing clock sync marker, errno: %d", errno);
|
||||
|
@ -236,7 +236,7 @@ static int DacGetParamSecurityLabel(const char *path)
|
||||
PARAM_LOGV("DacGetParamSecurityLabel %s ", path);
|
||||
DIR *pDir = opendir(path);
|
||||
PARAM_CHECK(pDir != NULL, return -1, "Read dir :%s failed.%d", path, errno);
|
||||
char *fileName = malloc(MAX_BUF_SIZE);
|
||||
char *fileName = calloc(1, MAX_BUF_SIZE);
|
||||
PARAM_CHECK(fileName != NULL, closedir(pDir);
|
||||
return -1, "Failed to malloc for %s", path);
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "param_manager.h"
|
||||
#include "param_persist.h"
|
||||
#include "param_utils.h"
|
||||
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
|
||||
#if !(defined __LITEOFS_A__ || defined __LITEOS_M__)
|
||||
#include "trigger_manager.h"
|
||||
#endif
|
||||
|
||||
@ -33,39 +33,84 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const
|
||||
bool clearFactoryPersistParams = *(bool*)context;
|
||||
uint32_t dataIndex = 0;
|
||||
int mode = 0;
|
||||
|
||||
if (!clearFactoryPersistParams) {
|
||||
mode |= LOAD_PARAM_PERSIST;
|
||||
return WriteParam(name, value, &dataIndex, mode);
|
||||
}
|
||||
int result = 0;
|
||||
do {
|
||||
if (!clearFactoryPersistParams) {
|
||||
mode |= LOAD_PARAM_PERSIST;
|
||||
result = WriteParam(name, value, &dataIndex, mode);
|
||||
break;
|
||||
}
|
||||
|
||||
char persetValue[PARAM_VALUE_LEN_MAX] = {0};
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemReadParam(name, persetValue, &len);
|
||||
if (ret != 0) {
|
||||
mode |= LOAD_PARAM_PERSIST;
|
||||
return WriteParam(name, value, &dataIndex, mode);
|
||||
}
|
||||
char persetValue[PARAM_VALUE_LEN_MAX] = {0};
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemReadParam(name, persetValue, &len);
|
||||
if (ret != 0) {
|
||||
mode |= LOAD_PARAM_PERSIST;
|
||||
result = WriteParam(name, value, &dataIndex, mode);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((strcmp(persetValue, value) != 0)) {
|
||||
PARAM_LOGI("%s value is different, preset value is:%s, persist value is:%s", name, persetValue, value);
|
||||
mode |= LOAD_PARAM_PERSIST;
|
||||
return WriteParam(name, value, &dataIndex, mode);
|
||||
if ((strcmp(persetValue, value) != 0)) {
|
||||
PARAM_LOGI("%s value is different, preset value is:%s, persist value is:%s", name, persetValue, value);
|
||||
mode |= LOAD_PARAM_PERSIST;
|
||||
result = WriteParam(name, value, &dataIndex, mode);
|
||||
}
|
||||
} while (0);
|
||||
#if !(defined __LITEOFS_A__ || defined __LITEOS_M__)
|
||||
if (result == 0) {
|
||||
PostParamTrigger(EVENT_TRIGGER_PARAM_WATCH, name, value);
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
static bool IsPrivateParam(const char *param)
|
||||
{
|
||||
const char *privatePersistParams[] = {
|
||||
"persist.sys.data.dataextpath",
|
||||
"persist.sys.radio.vendorlib.path",
|
||||
"persist.sys.default_ime",
|
||||
"persist.sys.usb.config",
|
||||
"persist.hdc.daemon.cancel",
|
||||
"persist.hdc.daemon.auth_result",
|
||||
"persist.hdc.client.hostname",
|
||||
"persist.hdc.client.pubkey_sha256",
|
||||
"persist.kernel.bundle_name.clouddrive",
|
||||
"persist.kernel.bundle_name.photos",
|
||||
"persist.kernel.bundle_name.filemanager",
|
||||
};
|
||||
int size = sizeof(privatePersistParams) / sizeof(char*);
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (strcmp(param, privatePersistParams[i]) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int LoadOnePublicPersistParam_(const uint32_t *context, const char *name, const char *value)
|
||||
{
|
||||
if (IsPrivateParam(name)) {
|
||||
PARAM_LOGI("%s is private, ignore", name);
|
||||
return 0;
|
||||
}
|
||||
return LoadOnePersistParam_(context, name, value);
|
||||
}
|
||||
|
||||
static void LoadPersistParam_(const bool clearFactoryPersistParams, const char *fileName,
|
||||
char *buffer, uint32_t buffSize)
|
||||
char *buffer, uint32_t buffSize, bool isFullLoad)
|
||||
{
|
||||
FILE *fp = fopen(fileName, "r");
|
||||
PARAM_WARNING_CHECK(fp != NULL, return, "No valid persist parameter file %s", fileName);
|
||||
|
||||
int ret = 0;
|
||||
uint32_t paramNum = 0;
|
||||
while (fgets(buffer, buffSize, fp) != NULL) {
|
||||
buffer[buffSize - 1] = '\0';
|
||||
int ret = SplitParamString(buffer, NULL, 0, LoadOnePersistParam_, (uint32_t*)&clearFactoryPersistParams);
|
||||
if (isFullLoad) {
|
||||
ret = SplitParamString(buffer, NULL, 0, LoadOnePersistParam_, (uint32_t*)&clearFactoryPersistParams);
|
||||
} else {
|
||||
ret = SplitParamString(buffer, NULL, 0, LoadOnePublicPersistParam_, (uint32_t*)&clearFactoryPersistParams);
|
||||
}
|
||||
PARAM_CHECK(ret == 0, continue, "Failed to set param %d %s", ret, buffer);
|
||||
paramNum++;
|
||||
}
|
||||
@ -73,9 +118,43 @@ static void LoadPersistParam_(const bool clearFactoryPersistParams, const char *
|
||||
PARAM_LOGI("LoadPersistParam from file %s paramNum %d", fileName, paramNum);
|
||||
}
|
||||
|
||||
static int LoadPersistParam(void)
|
||||
static bool GetPersistFilePath(char **path, char **tmpPath, int fileType)
|
||||
{
|
||||
bool isFullLoad = true;
|
||||
if (InUpdaterMode() == 1) {
|
||||
*path = "/param/persist_parameters";
|
||||
*tmpPath = "/param/tmp_persist_paramters";
|
||||
return isFullLoad;
|
||||
}
|
||||
if (fileType == PUBLIC_PERSIST_FILE) {
|
||||
if (access(PARAM_PERSIST_SAVE_PATH, F_OK) == 0 && access(PARAM_PUBLIC_PERSIST_SAVE_PATH, F_OK) != 0) {
|
||||
int ret = rename(PARAM_PERSIST_SAVE_PATH, PARAM_PUBLIC_PERSIST_SAVE_PATH);
|
||||
if (ret != 0) {
|
||||
PARAM_LOGE("rename failed %s", PARAM_PERSIST_SAVE_PATH);
|
||||
}
|
||||
} else {
|
||||
CheckAndCreateDir(PARAM_PUBLIC_PERSIST_SAVE_PATH);
|
||||
isFullLoad = false;
|
||||
}
|
||||
*path = PARAM_PUBLIC_PERSIST_SAVE_PATH;
|
||||
*tmpPath = PARAM_PUBLIC_PERSIST_SAVE_TMP_PATH;
|
||||
return isFullLoad;
|
||||
}
|
||||
if (access(PARAM_OLD_PERSIST_SAVE_PATH, F_OK) == 0 && access(PARAM_PRIVATE_PERSIST_SAVE_PATH, F_OK) != 0) {
|
||||
int ret = rename(PARAM_OLD_PERSIST_SAVE_PATH, PARAM_PRIVATE_PERSIST_SAVE_PATH);
|
||||
if (ret != 0) {
|
||||
PARAM_LOGE("rename failed %s", PARAM_OLD_PERSIST_SAVE_PATH);
|
||||
}
|
||||
} else {
|
||||
CheckAndCreateDir(PARAM_PRIVATE_PERSIST_SAVE_PATH);
|
||||
}
|
||||
*path = PARAM_PRIVATE_PERSIST_SAVE_PATH;
|
||||
*tmpPath = PARAM_PRIVATE_PERSIST_SAVE_TMP_PATH;
|
||||
return isFullLoad;
|
||||
}
|
||||
|
||||
static int LoadPersistParam(int fileType)
|
||||
{
|
||||
CheckAndCreateDir(PARAM_PERSIST_SAVE_PATH);
|
||||
bool clearFactoryPersistParams = false;
|
||||
char value[PARAM_VALUE_LEN_MAX] = {0};
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
@ -85,16 +164,16 @@ static int LoadPersistParam(void)
|
||||
clearFactoryPersistParams = true;
|
||||
}
|
||||
const uint32_t buffSize = PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10; // 10 max len
|
||||
char *buffer = malloc(buffSize);
|
||||
char *buffer = calloc(1, buffSize);
|
||||
PARAM_CHECK(buffer != NULL, return -1, "Failed to alloc");
|
||||
|
||||
int updaterMode = InUpdaterMode();
|
||||
char *tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters";
|
||||
LoadPersistParam_(clearFactoryPersistParams, tmpPath, buffer, buffSize);
|
||||
tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters";
|
||||
LoadPersistParam_(clearFactoryPersistParams, tmpPath, buffer, buffSize);
|
||||
char *tmpPath = "";
|
||||
char *path = "";
|
||||
bool isFullLoad = GetPersistFilePath(&path, &tmpPath, fileType);
|
||||
LoadPersistParam_(clearFactoryPersistParams, path, buffer, buffSize, isFullLoad);
|
||||
LoadPersistParam_(clearFactoryPersistParams, tmpPath, buffer, buffSize, isFullLoad);
|
||||
free(buffer);
|
||||
if (clearFactoryPersistParams && access(PARAM_PERSIST_SAVE_PATH, F_OK) == 0) {
|
||||
if (clearFactoryPersistParams) {
|
||||
FILE *fp = fopen(PERSIST_PARAM_FIXED_FLAGS, "w");
|
||||
PARAM_CHECK(fp != NULL, return -1, "create file %s fail error %d", PERSIST_PARAM_FIXED_FLAGS, errno);
|
||||
(void)fclose(fp);
|
||||
@ -105,12 +184,24 @@ static int LoadPersistParam(void)
|
||||
static int SavePersistParam(const char *name, const char *value)
|
||||
{
|
||||
ParamMutexPend(&g_saveMutex);
|
||||
char *path = (InUpdaterMode() == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters";
|
||||
FILE *fp = fopen(path, "a+");
|
||||
int ret = -1;
|
||||
if (fp != NULL) {
|
||||
ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
(void)fclose(fp);
|
||||
if (InUpdaterMode() == 1) {
|
||||
char *path = "/param/persist_parameters";
|
||||
FILE *fp = fopen(path, "a+");
|
||||
if (fp != NULL) {
|
||||
ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
(void)fclose(fp);
|
||||
}
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
return ret;
|
||||
}
|
||||
const char *path[PERSIST_HANDLE_MAX] = { PARAM_PUBLIC_PERSIST_SAVE_PATH, PARAM_PRIVATE_PERSIST_SAVE_PATH };
|
||||
for (int i = 0; i < PERSIST_HANDLE_MAX; i++) {
|
||||
FILE *fp = fopen(path[i], "a+");
|
||||
if (fp != NULL) {
|
||||
ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
(void)fclose(fp);
|
||||
}
|
||||
}
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
if (ret <= 0) {
|
||||
@ -122,42 +213,79 @@ static int SavePersistParam(const char *name, const char *value)
|
||||
static int BatchSavePersistParamBegin(PERSIST_SAVE_HANDLE *handle)
|
||||
{
|
||||
ParamMutexPend(&g_saveMutex);
|
||||
char *path = (InUpdaterMode() == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters";
|
||||
unlink(path);
|
||||
FILE *fp = fopen(path, "w");
|
||||
if (fp == NULL) {
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_LOGE("Open file %s fail error %d", path, errno);
|
||||
return -1;
|
||||
if (InUpdaterMode() == 1) {
|
||||
char *path = "/param/tmp_persist_parameters";
|
||||
unlink(path);
|
||||
FILE *fp = fopen(path, "w");
|
||||
if (fp == NULL) {
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_LOGE("Open file %s fail error %d", path, errno);
|
||||
return -1;
|
||||
}
|
||||
handle[0] = (PERSIST_SAVE_HANDLE)fp;
|
||||
return 0;
|
||||
}
|
||||
const char *path[PERSIST_HANDLE_MAX] = {
|
||||
PARAM_PUBLIC_PERSIST_SAVE_TMP_PATH,
|
||||
PARAM_PRIVATE_PERSIST_SAVE_TMP_PATH
|
||||
};
|
||||
for (int i = 0; i < PERSIST_HANDLE_MAX; i++) {
|
||||
unlink(path[i]);
|
||||
FILE *fp = fopen(path[i], "w");
|
||||
if (fp == NULL) {
|
||||
PARAM_LOGE("Open file %s fail error %d", path[i], errno);
|
||||
} else {
|
||||
handle[i] = (PERSIST_SAVE_HANDLE)fp;
|
||||
}
|
||||
}
|
||||
*handle = (PERSIST_SAVE_HANDLE)fp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle, const char *name, const char *value)
|
||||
static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle[], const char *name, const char *value)
|
||||
{
|
||||
FILE *fp = (FILE *)handle;
|
||||
int ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
PARAM_LOGV("BatchSavePersistParam %s=%s", name, value);
|
||||
int ret = 0;
|
||||
for (int i = 0; i < PERSIST_HANDLE_MAX; i++) {
|
||||
FILE *fp = (FILE*)handle[i];
|
||||
if (fp != NULL) {
|
||||
ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
PARAM_CHECK(ret > 0, return -1, "Batchsavepersistparam fail, error %d", errno);
|
||||
}
|
||||
}
|
||||
return (ret > 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle)
|
||||
static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle[])
|
||||
{
|
||||
int ret;
|
||||
FILE *fp = (FILE *)handle;
|
||||
(void)fflush(fp);
|
||||
(void)fsync(fileno(fp));
|
||||
(void)fclose(fp);
|
||||
if (InUpdaterMode() == 0) {
|
||||
unlink(PARAM_PERSIST_SAVE_PATH);
|
||||
ret = rename(PARAM_PERSIST_SAVE_TMP_PATH, PARAM_PERSIST_SAVE_PATH);
|
||||
} else {
|
||||
int ret = 0;
|
||||
if (InUpdaterMode() == 1) {
|
||||
FILE *fp = (FILE *)handle[0];
|
||||
(void)fflush(fp);
|
||||
(void)fsync(fileno(fp));
|
||||
(void)fclose(fp);
|
||||
unlink("/param/persist_parameters");
|
||||
ret = rename("/param/tmp_persist_parameters", "/param/persist_parameters");
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
return;
|
||||
}
|
||||
const char *tmpPath[PERSIST_HANDLE_MAX] = {
|
||||
PARAM_PUBLIC_PERSIST_SAVE_TMP_PATH,
|
||||
PARAM_PRIVATE_PERSIST_SAVE_TMP_PATH
|
||||
};
|
||||
const char *path[PERSIST_HANDLE_MAX] = {
|
||||
PARAM_PUBLIC_PERSIST_SAVE_PATH,
|
||||
PARAM_PRIVATE_PERSIST_SAVE_PATH
|
||||
};
|
||||
for (int i = 0; i < PERSIST_HANDLE_MAX; i++) {
|
||||
if (handle[i] != NULL) {
|
||||
FILE *fp = (FILE *)handle[i];
|
||||
(void)fflush(fp);
|
||||
(void)fsync(fileno(fp));
|
||||
(void)fclose(fp);
|
||||
}
|
||||
unlink(path[i]);
|
||||
ret = rename(tmpPath[i], path[i]);
|
||||
}
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
|
||||
}
|
||||
|
||||
int RegisterPersistParamOps(PersistParamOps *ops)
|
||||
|
@ -85,6 +85,7 @@ INIT_LOCAL_API ParamSecurityLabel *GetParamSecurityLabel()
|
||||
INIT_LOCAL_API int SplitParamString(char *line, const char *exclude[], uint32_t count,
|
||||
int (*result)(const uint32_t *context, const char *name, const char *value), const uint32_t *context)
|
||||
{
|
||||
PARAM_CHECK(line != NULL, return 0, "Empty line");
|
||||
// Skip spaces
|
||||
char *name = line;
|
||||
while (isspace(*name) && (*name != '\0')) {
|
||||
|
@ -48,6 +48,7 @@ STATIC_INLINE ParamTrieNode *FindSubTrie(const WorkSpace *workSpace,
|
||||
} else {
|
||||
ret = memcmp(subTrie->key, key, keyLen);
|
||||
if (ret == 0) {
|
||||
PARAM_CHECK(matchLabel != NULL, return NULL, "Invalid matchLabel");
|
||||
*matchLabel = (subTrie->labelIndex != 0) ? subTrie->labelIndex : *matchLabel;
|
||||
return subTrie;
|
||||
}
|
||||
|
@ -306,6 +306,7 @@ INIT_LOCAL_API uint32_t AddParamNode(WorkSpace *workSpace, uint8_t type,
|
||||
|
||||
INIT_LOCAL_API void SaveIndex(uint32_t *index, uint32_t offset)
|
||||
{
|
||||
PARAM_ONLY_CHECK(index != NULL, return);
|
||||
*index = offset;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "param_osadp.h"
|
||||
#define PUBLIC_PERSIST_FILE 0
|
||||
#define PRIVATE_PERSIST_FILE 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@ -34,11 +36,18 @@ typedef struct {
|
||||
} PersistAdpContext;
|
||||
|
||||
typedef struct {
|
||||
#if defined(__LITEOS_M__) || defined(__LITEOS_A__) || defined(__LINUX__)
|
||||
int (*load)(void);
|
||||
int (*save)(const char *name, const char *value);
|
||||
int (*batchSaveBegin)(PERSIST_SAVE_HANDLE *handle);
|
||||
int (*batchSave)(PERSIST_SAVE_HANDLE handle, const char *name, const char *value);
|
||||
void (*batchSaveEnd)(PERSIST_SAVE_HANDLE handle);
|
||||
#else
|
||||
int (*load)(int fileType);
|
||||
int (*batchSaveBegin)(PERSIST_SAVE_HANDLE *handle);
|
||||
int (*batchSave)(PERSIST_SAVE_HANDLE handle[], const char *name, const char *value);
|
||||
void (*batchSaveEnd)(PERSIST_SAVE_HANDLE handle[]);
|
||||
#endif
|
||||
int (*save)(const char *name, const char *value);
|
||||
} PersistParamOps;
|
||||
|
||||
int RegisterPersistParamOps(PersistParamOps *ops);
|
||||
|
@ -81,6 +81,13 @@ typedef enum {
|
||||
#define PARAM_STORAGE_PATH STARTUP_INIT_UT_PATH "/dev/__parameters__"
|
||||
#define PARAM_PERSIST_SAVE_PATH DATA_PATH "persist_parameters"
|
||||
#define PARAM_PERSIST_SAVE_TMP_PATH DATA_PATH "tmp_persist_parameters"
|
||||
#define PRIVATE_DATA_PATH STARTUP_INIT_UT_PATH "/data/service/el1/public/startup/parameters/"
|
||||
#define PARAM_OLD_PERSIST_SAVE_PATH PRIVATE_DATA_PATH "persist_parameters"
|
||||
#define PARAM_PUBLIC_PERSIST_SAVE_PATH DATA_PATH "public_persist_parameters"
|
||||
#define PARAM_PUBLIC_PERSIST_SAVE_TMP_PATH DATA_PATH "tmp_public_persist_parameters"
|
||||
#define PARAM_PRIVATE_PERSIST_SAVE_PATH PRIVATE_DATA_PATH "private_persist_parameters"
|
||||
#define PARAM_PRIVATE_PERSIST_SAVE_TMP_PATH PRIVATE_DATA_PATH "tmp_private_persist_parameters"
|
||||
#define PERSIST_HANDLE_MAX 2
|
||||
|
||||
#define WORKSPACE_FLAGS_INIT 0x01
|
||||
#define WORKSPACE_FLAGS_LOADED 0x02
|
||||
|
@ -42,7 +42,6 @@ param_include_dirs = [
|
||||
]
|
||||
|
||||
param_service_sources = [
|
||||
"//base/startup/init/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init/services/param/linux/param_message.c",
|
||||
"//base/startup/init/services/param/linux/param_msgadp.c",
|
||||
"//base/startup/init/services/param/linux/param_service.c",
|
||||
@ -69,6 +68,8 @@ if (defined(ohos_lite)) {
|
||||
defines = []
|
||||
sources = param_service_sources
|
||||
sources += param_trigger_sources
|
||||
sources +=
|
||||
[ "//base/startup/init/services/param/liteos/param_persistadp.c" ]
|
||||
include_dirs = param_include_dirs
|
||||
include_dirs += [
|
||||
"//base/security/selinux_adapter/interfaces/policycoreutils/include",
|
||||
@ -113,6 +114,8 @@ if (defined(ohos_lite)) {
|
||||
ohos_static_library("param_init") {
|
||||
sources = param_service_sources
|
||||
sources += param_trigger_sources
|
||||
sources +=
|
||||
[ "//base/startup/init/services/param/adapter/param_persistadp.c" ]
|
||||
include_dirs = param_include_dirs
|
||||
public_configs = [ ":exported_header_files" ]
|
||||
defines = [
|
||||
|
@ -286,7 +286,8 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
|
||||
timeout = 1;
|
||||
#endif
|
||||
int fd = GetClientSocket(timeout);
|
||||
PARAM_CHECK(fd >= 0, return fd, "SystemWaitParameter failed! name is:%s, the errNum is:%d", name, ret);
|
||||
PARAM_CHECK(fd >= 0, free(request);
|
||||
return fd, "SystemWaitParameter failed! name is:%s, the errNum is:%d", name, ret);
|
||||
ret = StartRequest(fd, request, timeout);
|
||||
close(fd);
|
||||
free(request);
|
||||
|
@ -91,7 +91,7 @@ static_library("param_init_lite") {
|
||||
|
||||
if (ohos_kernel_type == "liteos_a") {
|
||||
sources += [
|
||||
"//base/startup/init/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init/services/param/liteos/param_persistadp.c",
|
||||
"//base/startup/init/services/param/liteos/param_service.c",
|
||||
"//base/startup/init/services/param/manager/param_persist.c",
|
||||
]
|
||||
@ -123,7 +123,7 @@ static_library("param_client_lite") {
|
||||
|
||||
if (ohos_kernel_type == "liteos_a") {
|
||||
sources +=
|
||||
[ "//base/startup/init/services/param/adapter/param_persistadp.c" ]
|
||||
[ "//base/startup/init/services/param/liteos/param_persistadp.c" ]
|
||||
defines += [
|
||||
"__LITEOS_A__",
|
||||
"WORKSPACE_AREA_NEED_MUTEX",
|
||||
|
@ -136,7 +136,7 @@ static int LoadPersistParam(void)
|
||||
uint32_t fileSize = 0;
|
||||
int ret = ParamFileStat(path, &fileSize);
|
||||
PARAM_CHECK(ret == 0, break, "Failed to get file state %s", path);
|
||||
buffer = malloc(fileSize);
|
||||
buffer = calloc(fileSize, sizeof(char));
|
||||
PARAM_CHECK(buffer != NULL, break, "Failed to get file");
|
||||
ret = ParamFileRead(fd, buffer, fileSize);
|
||||
PARAM_CHECK(ret >= 0, break, "Failed to read file %s", path);
|
||||
|
135
services/param/liteos/param_persistadp.c
Normal file
135
services/param/liteos/param_persistadp.c
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <errno.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "init_utils.h"
|
||||
#include "param_manager.h"
|
||||
#include "param_persist.h"
|
||||
#include "param_utils.h"
|
||||
|
||||
// for linux, no mutex
|
||||
static ParamMutex g_saveMutex = {};
|
||||
|
||||
static int LoadOnePersistParam_(const uint32_t *context, const char *name, const char *value)
|
||||
{
|
||||
UNUSED(context);
|
||||
uint32_t dataIndex = 0;
|
||||
return WriteParam(name, value, &dataIndex, 0);
|
||||
}
|
||||
|
||||
static void LoadPersistParam_(const char *fileName, char *buffer, uint32_t buffSize)
|
||||
{
|
||||
FILE *fp = fopen(fileName, "r");
|
||||
PARAM_WARNING_CHECK(fp != NULL, return, "No valid persist parameter file %s", fileName);
|
||||
|
||||
uint32_t paramNum = 0;
|
||||
while (fgets(buffer, buffSize, fp) != NULL) {
|
||||
buffer[buffSize - 1] = '\0';
|
||||
int ret = SplitParamString(buffer, NULL, 0, LoadOnePersistParam_, NULL);
|
||||
PARAM_CHECK(ret == 0, continue, "Failed to set param %d %s", ret, buffer);
|
||||
paramNum++;
|
||||
}
|
||||
(void)fclose(fp);
|
||||
PARAM_LOGI("LoadPersistParam from file %s paramNum %d", fileName, paramNum);
|
||||
}
|
||||
|
||||
static int LoadPersistParam(void)
|
||||
{
|
||||
CheckAndCreateDir(PARAM_PERSIST_SAVE_PATH);
|
||||
const uint32_t buffSize = PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10; // 10 max len
|
||||
char *buffer = malloc(buffSize);
|
||||
PARAM_CHECK(buffer != NULL, return -1, "Failed to alloc");
|
||||
|
||||
int updaterMode = InUpdaterMode();
|
||||
char *tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters";
|
||||
LoadPersistParam_(tmpPath, buffer, buffSize);
|
||||
tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters";
|
||||
LoadPersistParam_(tmpPath, buffer, buffSize);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SavePersistParam(const char *name, const char *value)
|
||||
{
|
||||
ParamMutexPend(&g_saveMutex);
|
||||
char *path = (InUpdaterMode() == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters";
|
||||
FILE *fp = fopen(path, "a+");
|
||||
int ret = -1;
|
||||
if (fp != NULL) {
|
||||
ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
(void)fclose(fp);
|
||||
}
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
if (ret <= 0) {
|
||||
PARAM_LOGE("Failed to save persist param %s", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int BatchSavePersistParamBegin(PERSIST_SAVE_HANDLE *handle)
|
||||
{
|
||||
ParamMutexPend(&g_saveMutex);
|
||||
char *path = (InUpdaterMode() == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters";
|
||||
unlink(path);
|
||||
FILE *fp = fopen(path, "w");
|
||||
if (fp == NULL) {
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_LOGE("Open file %s fail error %d", path, errno);
|
||||
return -1;
|
||||
}
|
||||
*handle = (PERSIST_SAVE_HANDLE)fp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle, const char *name, const char *value)
|
||||
{
|
||||
FILE *fp = (FILE *)handle;
|
||||
int ret = fprintf(fp, "%s=%s\n", name, value);
|
||||
PARAM_LOGV("BatchSavePersistParam %s=%s", name, value);
|
||||
return (ret > 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle)
|
||||
{
|
||||
int ret;
|
||||
FILE *fp = (FILE *)handle;
|
||||
(void)fflush(fp);
|
||||
(void)fsync(fileno(fp));
|
||||
(void)fclose(fp);
|
||||
if (InUpdaterMode() == 0) {
|
||||
unlink(PARAM_PERSIST_SAVE_PATH);
|
||||
ret = rename(PARAM_PERSIST_SAVE_TMP_PATH, PARAM_PERSIST_SAVE_PATH);
|
||||
} else {
|
||||
unlink("/param/persist_parameters");
|
||||
ret = rename("/param/tmp_persist_parameters", "/param/persist_parameters");
|
||||
}
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
|
||||
}
|
||||
|
||||
int RegisterPersistParamOps(PersistParamOps *ops)
|
||||
{
|
||||
ParamMutexCreate(&g_saveMutex);
|
||||
PARAM_CHECK(ops != NULL, return -1, "Invalid ops");
|
||||
ops->save = SavePersistParam;
|
||||
ops->load = LoadPersistParam;
|
||||
ops->batchSaveBegin = BatchSavePersistParamBegin;
|
||||
ops->batchSave = BatchSavePersistParam;
|
||||
ops->batchSaveEnd = BatchSavePersistParamEnd;
|
||||
return 0;
|
||||
}
|
@ -98,15 +98,20 @@ static int BatchSavePersistParam(void)
|
||||
g_persistWorkSpace.persistParamOps.batchSaveEnd == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__LITEOS_M__) || defined(__LITEOS_A__) || defined(__LINUX__)
|
||||
PERSIST_SAVE_HANDLE handle;
|
||||
int ret = g_persistWorkSpace.persistParamOps.batchSaveBegin(&handle);
|
||||
PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_NAME, "Failed to save persist");
|
||||
#if defined(__LITEOS_M__) || defined(__LITEOS_A__)
|
||||
const char *prefix = "";
|
||||
#else
|
||||
const char *prefix = PARAM_PERSIST_PREFIX;
|
||||
#endif
|
||||
#else
|
||||
PERSIST_SAVE_HANDLE handle[PERSIST_HANDLE_MAX] = { NULL, NULL };
|
||||
int ret = g_persistWorkSpace.persistParamOps.batchSaveBegin(handle);
|
||||
const char *prefix = PARAM_PERSIST_PREFIX;
|
||||
#endif
|
||||
PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_NAME, "Failed to save persist");
|
||||
// walk and save persist param
|
||||
WorkSpace *workSpace = GetNextWorkSpace(NULL);
|
||||
while (workSpace != NULL) {
|
||||
@ -228,6 +233,7 @@ int LoadPersistParams(void)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#if defined(__LITEOS_M__) || defined(__LITEOS_A__) || defined(__LINUX__)
|
||||
if (g_persistWorkSpace.persistParamOps.load != NULL) {
|
||||
(void)g_persistWorkSpace.persistParamOps.load();
|
||||
PARAM_SET_FLAG(g_persistWorkSpace.flags, WORKSPACE_FLAGS_LOADED);
|
||||
@ -242,6 +248,39 @@ int LoadPersistParams(void)
|
||||
ParamTimerCreate(&g_persistWorkSpace.saveTimer, TimerCallbackForSave, NULL);
|
||||
ParamTimerStart(g_persistWorkSpace.saveTimer, PARAM_MUST_SAVE_PARAM_DIFF * MS_UNIT, MS_UNIT);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
if (g_persistWorkSpace.persistParamOps.load != NULL) {
|
||||
(void)g_persistWorkSpace.persistParamOps.load(PUBLIC_PERSIST_FILE);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LoadPrivatePersistParams(void)
|
||||
{
|
||||
#if !(defined(__LITEOS_M__) || defined(__LITEOS_A__) || defined(__LINUX__))
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
if (PARAM_TEST_FLAG(g_persistWorkSpace.flags, WORKSPACE_FLAGS_LOADED)) {
|
||||
PARAM_LOGE("Persist param has been loaded");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (g_persistWorkSpace.persistParamOps.load != NULL) {
|
||||
(void)g_persistWorkSpace.persistParamOps.load(PRIVATE_PERSIST_FILE);
|
||||
PARAM_SET_FLAG(g_persistWorkSpace.flags, WORKSPACE_FLAGS_LOADED);
|
||||
}
|
||||
// save new persist param
|
||||
int ret = BatchSavePersistParam();
|
||||
PARAM_CHECK(ret == 0, return ret, "Failed to load persist param");
|
||||
// for liteos-a, start time to check in init
|
||||
#ifdef PARAM_SUPPORT_CYCLE_CHECK
|
||||
PARAM_LOGV("LoadPersistParams start check time ");
|
||||
if (g_persistWorkSpace.saveTimer == NULL) {
|
||||
ParamTimerCreate(&g_persistWorkSpace.saveTimer, TimerCallbackForSave, NULL);
|
||||
ParamTimerStart(g_persistWorkSpace.saveTimer, PARAM_MUST_SAVE_PARAM_DIFF * MS_UNIT, MS_UNIT);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
@ -366,7 +366,7 @@ static int LoadParamFromImport(const char *fileName, void *context)
|
||||
}
|
||||
|
||||
const int buffSize = PATH_MAX;
|
||||
char *buffer = malloc(buffSize);
|
||||
char *buffer = calloc(buffSize, sizeof(char));
|
||||
PARAM_CHECK(buffer != NULL, (void)fclose(fp);
|
||||
return -1, "Failed to alloc memory");
|
||||
|
||||
@ -395,7 +395,7 @@ static int LoadDefaultParam_(const char *fileName, uint32_t mode,
|
||||
}
|
||||
|
||||
const int buffSize = PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10; // 10 max len
|
||||
char *buffer = malloc(buffSize);
|
||||
char *buffer = calloc(buffSize, sizeof(char));
|
||||
PARAM_CHECK(buffer != NULL, (void)fclose(fp);
|
||||
return -1, "Failed to alloc memory");
|
||||
|
||||
|
@ -31,7 +31,7 @@ int CalculatorInit(LogicCalculator *calculator, int dataNumber, int dataUnit, in
|
||||
if (needCondition) {
|
||||
dataSize += MAX_DATA_BUFFER_MAX;
|
||||
}
|
||||
calculator->data = (char *)malloc(dataSize);
|
||||
calculator->data = (char *)calloc(1, dataSize);
|
||||
PARAM_CHECK(calculator->data != NULL, return -1, "Failed to malloc for calculator");
|
||||
calculator->dataNumber = dataNumber;
|
||||
calculator->endIndex = 0;
|
||||
|
@ -202,7 +202,7 @@ static TriggerNode *AddWatchTrigger_(const TriggerWorkSpace *workSpace,
|
||||
|
||||
static void DelWatchTrigger_(const TriggerWorkSpace *workSpace, TriggerNode *trigger)
|
||||
{
|
||||
PARAM_CHECK(workSpace != NULL, return, "Param is null");
|
||||
PARAM_CHECK(workSpace != NULL && trigger != NULL, return, "Param is null");
|
||||
TriggerHeader *triggerHead = GetTriggerHeader(workSpace, trigger->type);
|
||||
PARAM_CHECK(triggerHead != NULL, return, "Failed to get header %d", trigger->type);
|
||||
OH_ListRemove(&trigger->node);
|
||||
@ -501,6 +501,7 @@ static void DumpJobTrigger_(const TriggerWorkSpace *workSpace, const TriggerNode
|
||||
|
||||
static void DumpWatchTrigger_(const TriggerWorkSpace *workSpace, const TriggerNode *trigger)
|
||||
{
|
||||
PARAM_CHECK(trigger != NULL, return, "Empty trigger");
|
||||
const WatchNode *node = (const WatchNode *)trigger;
|
||||
PARAM_DUMP("trigger flags: 0x%08x \n", trigger->flags);
|
||||
PARAM_DUMP("trigger condition: %s \n", trigger->condition);
|
||||
@ -509,6 +510,7 @@ static void DumpWatchTrigger_(const TriggerWorkSpace *workSpace, const TriggerNo
|
||||
|
||||
static void DumpWaitTrigger_(const TriggerWorkSpace *workSpace, const TriggerNode *trigger)
|
||||
{
|
||||
PARAM_CHECK(trigger != NULL, return, "Empty trigger");
|
||||
const WaitNode *node = (const WaitNode *)trigger;
|
||||
PARAM_DUMP("trigger flags: 0x%08x \n", trigger->flags);
|
||||
PARAM_DUMP("trigger name: %s \n", GetTriggerName(trigger));
|
||||
|
@ -169,7 +169,7 @@ void PostParamTrigger(int type, const char *name, const char *value)
|
||||
uint32_t bufferSize = strlen(name) + strlen(value) + 1 + 1 + 1;
|
||||
PARAM_CHECK(bufferSize < (PARAM_CONST_VALUE_LEN_MAX + PARAM_NAME_LEN_MAX + 1 + 1 + 1),
|
||||
return, "bufferSize is longest %d", bufferSize);
|
||||
char *buffer = (char *)malloc(bufferSize);
|
||||
char *buffer = (char *)calloc(1, bufferSize);
|
||||
PARAM_CHECK(buffer != NULL, return, "Failed to alloc memory for param %s", name);
|
||||
int ret = sprintf_s(buffer, bufferSize - 1, "%s=%s", name, value);
|
||||
PARAM_CHECK(ret > EOK, free(buffer);
|
||||
|
@ -139,7 +139,7 @@ char *ReadFileToBuf(const char *configFile)
|
||||
INIT_LOGE("Open %s failed. err = %d", configFile, errno);
|
||||
break;
|
||||
}
|
||||
buffer = (char*)malloc((size_t)(fileStat.st_size + 1));
|
||||
buffer = (char*)calloc((size_t)(fileStat.st_size + 1), sizeof(char));
|
||||
if (buffer == NULL) {
|
||||
INIT_LOGE("Failed to allocate memory for config file, err = %d", errno);
|
||||
break;
|
||||
@ -350,7 +350,7 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
|
||||
items = expand;
|
||||
}
|
||||
size_t len = strlen(p);
|
||||
items[count] = (char *)malloc(len + 1);
|
||||
items[count] = (char *)calloc(len + 1, sizeof(char));
|
||||
INIT_CHECK(items[count] != NULL, FreeStringVector(items, count);
|
||||
return NULL);
|
||||
if (strncpy_s(items[count], len + 1, p, len) != EOK) {
|
||||
@ -358,7 +358,6 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
|
||||
FreeStringVector(items, count);
|
||||
return NULL;
|
||||
}
|
||||
items[count][len] = '\0';
|
||||
count++;
|
||||
p = strtok_r(NULL, del, &rest);
|
||||
}
|
||||
@ -368,7 +367,7 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
|
||||
|
||||
long long InitDiffTime(INIT_TIMING_STAT *stat)
|
||||
{
|
||||
long long diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000); // 1000000 1000ms
|
||||
long long diff = (long long)(stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000; // 1000000 1000ms
|
||||
if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
|
||||
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) / BASE_MS_UNIT;
|
||||
} else {
|
||||
@ -835,6 +834,6 @@ long long GetUptimeInMicroSeconds(const struct timespec *uptime)
|
||||
#define SECOND_TO_MICRO_SECOND (1000000)
|
||||
#define MICRO_SECOND_TO_NANOSECOND (1000)
|
||||
|
||||
return (long long)((uptime->tv_sec * SECOND_TO_MICRO_SECOND) +
|
||||
(uptime->tv_nsec / MICRO_SECOND_TO_NANOSECOND));
|
||||
return ((long long)uptime->tv_sec * SECOND_TO_MICRO_SECOND) +
|
||||
(uptime->tv_nsec / MICRO_SECOND_TO_NANOSECOND);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ int GetSysParam(const char* key, char* value, unsigned int len)
|
||||
if (!IsValidKey(key) || (value == NULL) || (len > MAX_GET_VALUE_LEN)) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
char* keyPath = (char *)malloc(MAX_KEY_PATH + 1);
|
||||
char* keyPath = (char *)calloc(1, MAX_KEY_PATH + 1);
|
||||
if (keyPath == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
@ -108,7 +108,7 @@ int SetSysParam(const char* key, const char* value)
|
||||
if (!IsValidKey(key) || !IsValidValue(value, MAX_VALUE_LEN)) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
char* keyPath = (char *)malloc(MAX_KEY_PATH + 1);
|
||||
char* keyPath = (char *)calloc(1, MAX_KEY_PATH + 1);
|
||||
if (keyPath == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ static args_vector GetArgs(const std::vector<int> &sizes)
|
||||
{
|
||||
args_vector args;
|
||||
for (int size : sizes) {
|
||||
args.push_back( {size} );
|
||||
args.push_back({size});
|
||||
}
|
||||
return args;
|
||||
}
|
||||
@ -199,7 +199,7 @@ static args_vector GetArgs(const std::vector<int> &sizes, int value)
|
||||
{
|
||||
args_vector args;
|
||||
for (int size : sizes) {
|
||||
args.push_back( {size, value} );
|
||||
args.push_back({size, value});
|
||||
}
|
||||
return args;
|
||||
}
|
||||
@ -208,7 +208,7 @@ static args_vector GetArgs(const std::vector<int> &sizes, int value1, int value2
|
||||
{
|
||||
args_vector args;
|
||||
for (int size : sizes) {
|
||||
args.push_back( {size, value1, value2} );
|
||||
args.push_back({size, value1, value2});
|
||||
}
|
||||
return args;
|
||||
}
|
||||
@ -218,7 +218,7 @@ static args_vector GetArgs(const std::vector<int> &sizes, const std::vector<int>
|
||||
args_vector args;
|
||||
for (int size : sizes) {
|
||||
for (int limit : limits) {
|
||||
args.push_back( {size, limit, value} );
|
||||
args.push_back({size, limit, value});
|
||||
}
|
||||
}
|
||||
return args;
|
||||
|
@ -3484,6 +3484,94 @@ ohos_fuzztest("LoadParamFromCmdLineFuzzTest") {
|
||||
defines = [ "STARTUP_INIT_TEST" ]
|
||||
}
|
||||
|
||||
ohos_fuzztest("CheckAndCreatFileFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//base/startup/init/test/fuzztest/checkandcreatfile_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//base/startup/init/interfaces/innerkits/include",
|
||||
"//base/startup/init/test/fuzztest/utils/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/startup/init/services/param:parameter",
|
||||
"//base/startup/init/services/utils:libinit_utils",
|
||||
]
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "checkandcreatfile_fuzzer/checkandcreatfile_fuzzer.cpp" ]
|
||||
|
||||
defines = [ "STARTUP_INIT_TEST" ]
|
||||
}
|
||||
|
||||
ohos_fuzztest("WriteAllFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//base/startup/init/test/fuzztest/writeall_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//base/startup/init/interfaces/innerkits/include",
|
||||
"//base/startup/init/test/fuzztest/utils/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/startup/init/services/param:parameter",
|
||||
"//base/startup/init/services/utils:libinit_utils",
|
||||
]
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "writeall_fuzzer/writeall_fuzzer.cpp" ]
|
||||
|
||||
defines = [ "STARTUP_INIT_TEST" ]
|
||||
}
|
||||
|
||||
ohos_fuzztest("SplitStringFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//base/startup/init/test/fuzztest/splitstring_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//base/startup/init/interfaces/innerkits/include",
|
||||
"//base/startup/init/test/fuzztest/utils/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/startup/init/services/param:parameter",
|
||||
"//base/startup/init/services/utils:libinit_utils",
|
||||
]
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "splitstring_fuzzer/splitstring_fuzzer.cpp" ]
|
||||
|
||||
defines = [ "STARTUP_INIT_TEST" ]
|
||||
}
|
||||
|
||||
##############################################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
@ -3495,6 +3583,7 @@ group("fuzztest") {
|
||||
":AddWatcherFuzzTest",
|
||||
":BuildControlMessageFuzzTest",
|
||||
":ChangeSysAttributePermissionsFuzzTest",
|
||||
":CheckAndCreatFileFuzzTest",
|
||||
":CmdClientInitFuzzTest",
|
||||
":CmdServiceProcessDelClientFuzzTest",
|
||||
":DecodeGidFuzzTest",
|
||||
@ -3606,6 +3695,7 @@ group("fuzztest") {
|
||||
":ServiceWatchForStatusFuzzTest",
|
||||
":SetParameterCFuzzTest",
|
||||
":SetParameterCppFuzzTest",
|
||||
":SplitStringFuzzTest",
|
||||
":StartServiceByTimerFuzzTest",
|
||||
":StopServiceTimerFuzzTest",
|
||||
":SysCheckParamExistFuzzTest",
|
||||
@ -3615,6 +3705,7 @@ group("fuzztest") {
|
||||
":UmountAllWithFstabFileFuzzTest",
|
||||
":WaitParameterFuzzTest",
|
||||
":WatchParameterFuzzTest",
|
||||
":WriteAllFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "init_utils.h"
|
||||
#include <string>
|
||||
#include "checkandcreatfile_fuzzer.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool FuzzCheckAndCreatFile(const uint8_t* data, size_t size)
|
||||
{
|
||||
std::string str(reinterpret_cast<const char*>(data), size);
|
||||
int ret = CheckAndCreatFile(str.c_str(), 0777);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::FuzzCheckAndCreatFile(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifndef TEST_FUZZTEST_CHECK_AND_CREAT_FILE_FUZZER_H
|
||||
#define TEST_FUZZTEST_CHECK_AND_CREAT_FILE_FUZZER_H
|
||||
#include "fuzz_utils.h"
|
||||
#define FUZZ_PROJECT_NAME "checkandcreatfile_fuzzer"
|
||||
#endif
|
16
test/fuzztest/checkandcreatfile_fuzzer/corpus/init
Normal file
16
test/fuzztest/checkandcreatfile_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
FUZZ
|
25
test/fuzztest/checkandcreatfile_fuzzer/project.xml
Normal file
25
test/fuzztest/checkandcreatfile_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>100</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
16
test/fuzztest/splitstring_fuzzer/corpus/init
Normal file
16
test/fuzztest/splitstring_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
FUZZ
|
25
test/fuzztest/splitstring_fuzzer/project.xml
Normal file
25
test/fuzztest/splitstring_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>100</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
44
test/fuzztest/splitstring_fuzzer/splitstring_fuzzer.cpp
Normal file
44
test/fuzztest/splitstring_fuzzer/splitstring_fuzzer.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "init_utils.h"
|
||||
#include <string>
|
||||
#include "splitstring_fuzzer.h"
|
||||
|
||||
#define MAX_STR_NUMS 20
|
||||
|
||||
namespace OHOS {
|
||||
bool FuzzSplitString(const uint8_t* data, size_t size)
|
||||
{
|
||||
std::string str(reinterpret_cast<const char*>(data), size);
|
||||
char *opt[MAX_STR_NUMS] = {NULL};
|
||||
char *srcPtr = strdup(str.c_str());
|
||||
int ret = SplitString(srcPtr, " ", opt, MAX_STR_NUMS);
|
||||
if (ret != 0) {
|
||||
free(srcPtr);
|
||||
return false;
|
||||
};
|
||||
free(srcPtr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::FuzzSplitString(data, size);
|
||||
return 0;
|
||||
}
|
20
test/fuzztest/splitstring_fuzzer/splitstring_fuzzer.h
Normal file
20
test/fuzztest/splitstring_fuzzer/splitstring_fuzzer.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifndef TEST_FUZZTEST_CHECK_AND_CREAT_FILE_FUZZER_H
|
||||
#define TEST_FUZZTEST_CHECK_AND_CREAT_FILE_FUZZER_H
|
||||
#include "fuzz_utils.h"
|
||||
#define FUZZ_PROJECT_NAME "splitstring_fuzzer"
|
||||
#endif
|
@ -47,7 +47,7 @@ namespace OHOS {
|
||||
if (size > PARAM_CONST_VALUE_LEN_MAX + PARAM_NAME_LEN_MAX) {
|
||||
return true;
|
||||
}
|
||||
cookie->data = static_cast<char *>(malloc(size));
|
||||
cookie->data = static_cast<char *>(calloc(1, size));
|
||||
if (cookie->data == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
16
test/fuzztest/writeall_fuzzer/corpus/init
Normal file
16
test/fuzztest/writeall_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
FUZZ
|
25
test/fuzztest/writeall_fuzzer/project.xml
Normal file
25
test/fuzztest/writeall_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>100</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
45
test/fuzztest/writeall_fuzzer/writeall_fuzzer.cpp
Normal file
45
test/fuzztest/writeall_fuzzer/writeall_fuzzer.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "init_utils.h"
|
||||
#include <string>
|
||||
#include "writeall_fuzzer.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool FuzzGetParameterFromCmdLine(const uint8_t* data, size_t size)
|
||||
{
|
||||
CheckAndCreateDir("/data/init_fuzztest/FuzzTestData");
|
||||
int fd = open("/data/init_fuzztest/FuzzTestData", O_CREAT | O_RDWR, 0777);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
std::string str(reinterpret_cast<const char*>(data), size);
|
||||
size_t ret = WriteAll(fd, str.c_str(), size);
|
||||
if (ret == 0) {
|
||||
close(fd);
|
||||
return false;
|
||||
};
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::FuzzGetParameterFromCmdLine(data, size);
|
||||
return 0;
|
||||
}
|
20
test/fuzztest/writeall_fuzzer/writeall_fuzzer.h
Normal file
20
test/fuzztest/writeall_fuzzer/writeall_fuzzer.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifndef TEST_FUZZTEST_GET_PARAMETER_FROM_CMD_LINE_FUZZER_H
|
||||
#define TEST_FUZZTEST_GET_PARAMETER_FROM_CMD_LINE_FUZZER_H
|
||||
#include "fuzz_utils.h"
|
||||
#define FUZZ_PROJECT_NAME "writeall_fuzzer"
|
||||
#endif
|
@ -17,142 +17,8 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <linux/in.h>
|
||||
#include <linux/socket.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include "le_streamtask.c"
|
||||
#include "loop_systest.h"
|
||||
#include "loop_event.h"
|
||||
#include "le_socket.h"
|
||||
#include "le_task.h"
|
||||
#include "list.h"
|
||||
|
||||
#define TASKINFO \
|
||||
uint32_t flags; \
|
||||
union { \
|
||||
int fd; \
|
||||
} taskId
|
||||
|
||||
typedef struct {
|
||||
TASKINFO;
|
||||
} TaskId;
|
||||
|
||||
typedef struct LiteTask_ {
|
||||
TASKINFO;
|
||||
HashNode hashNode;
|
||||
LE_Close close;
|
||||
DumpTaskInfo dumpTaskInfo;
|
||||
HandleTaskEvent handleEvent;
|
||||
HandleTaskClose innerClose;
|
||||
uint16_t userDataOffset;
|
||||
uint16_t userDataSize;
|
||||
} BaseTask;
|
||||
|
||||
typedef struct {
|
||||
BaseTask base;
|
||||
LE_IncommingConnect incommingConnect;
|
||||
char server[0];
|
||||
} StreamServerTask;
|
||||
|
||||
typedef struct MyTask_ {
|
||||
TaskHandle task;
|
||||
struct ListNode item;
|
||||
int ptyFd;
|
||||
pid_t pid;
|
||||
} MyTask;
|
||||
|
||||
static LoopHandle g_loop = NULL;
|
||||
|
||||
static int HandleServerEvent(const LoopHandle loopHandle, const TaskHandle serverTask, uint32_t oper)
|
||||
{
|
||||
printf("HandleServerEvent_ fd %d oper 0x%x \n", GetSocketFd(serverTask), oper);
|
||||
if (!LE_TEST_FLAGS(oper, EVENT_READ)) {
|
||||
return LE_FAILURE;
|
||||
}
|
||||
|
||||
StreamServerTask *server = (StreamServerTask *)serverTask;
|
||||
if (server->incommingConnect == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = server->incommingConnect(loopHandle, serverTask);
|
||||
if (ret != 0) {
|
||||
printf("HandleServerEvent_ fd %d do not accept socket \n", GetSocketFd(serverTask));
|
||||
}
|
||||
|
||||
EventLoop *loop = (EventLoop *)loopHandle;
|
||||
loop->modEvent(loop, (const BaseTask *)serverTask, EVENT_READ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void HandleStreamTaskClose(const LoopHandle loopHandle, const TaskHandle taskHandle)
|
||||
{
|
||||
BaseTask *task = (BaseTask *)taskHandle;
|
||||
DelTask((EventLoop *)loopHandle, task);
|
||||
CloseTask(loopHandle, task);
|
||||
if (task->taskId.fd > 0) {
|
||||
printf("HandleStreamTaskClose::close fd:%d \n", task->taskId.fd);
|
||||
close(task->taskId.fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpStreamServerTaskInfo(const TaskHandle task)
|
||||
{
|
||||
if (task == nullptr) {
|
||||
printf("Dump empty task \n");
|
||||
return;
|
||||
}
|
||||
BaseTask *baseTask = dynamic_cast<BaseTask *>(task);
|
||||
StreamServerTask *serverTask = dynamic_cast<StreamServerTask *>(baseTask);
|
||||
|
||||
printf("\tfd: %d \n", serverTask->base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "ServerTask");
|
||||
if (strlen(serverTask->server) > 0) {
|
||||
printf("\t Server socket:%s \n", serverTask->server);
|
||||
} else {
|
||||
printf("\t Server socket:%s \n", "NULL");
|
||||
}
|
||||
}
|
||||
|
||||
static int IncommingConnect(const LoopHandle loop, const TaskHandle server)
|
||||
{
|
||||
TaskHandle client = NULL;
|
||||
LE_StreamInfo info = {};
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
info.baseInfo.flags = TASK_STREAM | TASK_PIPE | TASK_CONNECT;
|
||||
#else
|
||||
info.baseInfo.flags = TASK_STREAM | TASK_PIPE | TASK_CONNECT | TASK_TEST;
|
||||
#endif
|
||||
info.baseInfo.close = OnClose;
|
||||
info.baseInfo.userDataSize = sizeof(MyTask);
|
||||
info.disConnectComplete = NULL;
|
||||
info.sendMessageComplete = NULL;
|
||||
info.recvMessage = CmdOnRecvMessage;
|
||||
int ret = LE_AcceptStreamClient(g_loop, server, &client, &info);
|
||||
if (ret != 0) {
|
||||
printf("Failed accept stream \n");
|
||||
return -1;
|
||||
}
|
||||
MyTask *agent = (MyTask *)LE_GetUserData(client);
|
||||
if (agent == nullptr) {
|
||||
printf("Invalid agent \n");
|
||||
return -1;
|
||||
}
|
||||
agent->task = client;
|
||||
OH_ListInit(&agent->item);
|
||||
ret = SendMessage(g_loop, agent->task, "connect success.");
|
||||
if (ret != 0) {
|
||||
printf("Failed send msg \n");
|
||||
return -1;
|
||||
}
|
||||
OH_ListAddTail(&g_cmdService.head, &agent->item);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -182,29 +48,6 @@ int main()
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
LoopHandle loopHandle = LE_GetDefaultLoop();
|
||||
EventLoop *loop = (EventLoop *)loopHandle;
|
||||
StreamServerTask *task = (StreamServerTask *)CreateTask(loopHandle, fd, &baseInfo,
|
||||
sizeof(StreamServerTask) + strlen(server) + 1);
|
||||
if (task == nullptr) {
|
||||
printf("Failed to create task \n");
|
||||
close(fd);
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
||||
+ TaskHandle *taskHandle = NULL;
|
||||
task->base.handleEvent = HandleServerEvent;
|
||||
task->base.innerClose = HandleStreamTaskClose;
|
||||
task->base.dumpTaskInfo = DumpStreamServerTaskInfo;
|
||||
task->incommingConnect = incommingConnect;
|
||||
loop->addEvent(loop, (const BaseTask *)task, EVENT_READ);
|
||||
int ret = memcpy_s(task->server, strlen(server) + 1, server, strlen(server) + 1);
|
||||
if (ret != 0) {
|
||||
printf("Failed to copy server name %s", server);
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
||||
*taskHandle = (TaskHandle)task;
|
||||
EventLoop *loop = (EventLoop *)LE_GetDefaultLoop();
|
||||
}
|
@ -16,8 +16,8 @@
|
||||
#ifndef LOOP_SYSTEST_H
|
||||
#define LOOP_SYSTEST_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "loop_event.h"
|
||||
@ -30,7 +30,6 @@
|
||||
#endif
|
||||
|
||||
#define SOCKET_NAME "looptest"
|
||||
#define INIT_CONTROL_SOCKET_PATH "/dev/unix/socket/init_control_fd"
|
||||
#if defined(__MUSL__)
|
||||
#define SOCKET_DIR BASEDIR "/dev/unix/socket"
|
||||
#else
|
||||
@ -138,50 +137,4 @@ typedef struct {
|
||||
struct ListNode msgBlocks; // 保存实际的消息数据
|
||||
} ReqMsgNode;
|
||||
|
||||
typedef struct SpawnTime {
|
||||
int minTime;
|
||||
int maxTime;
|
||||
} SpawnTime;
|
||||
|
||||
typedef enum {
|
||||
MODE_FOR_APP_SPAWN,
|
||||
MODE_FOR_NWEB_SPAWN,
|
||||
MODE_FOR_APP_COLD_RUN,
|
||||
MODE_FOR_NWEB_COLD_RUN,
|
||||
MODE_FOR_NATIVE_SPAWN,
|
||||
MODE_FOR_CJAPP_SPAWN,
|
||||
MODE_INVALID
|
||||
} RunMode;
|
||||
|
||||
typedef struct {
|
||||
char *longProcName;
|
||||
uint32_t longProcNameLen;
|
||||
uint32_t sandboxNsFlags;
|
||||
int wdgOpened;
|
||||
RunMode mode;
|
||||
#ifndef OHOS_LITE
|
||||
int32_t preforkFd[2];
|
||||
int32_t parentToChildFd[2];
|
||||
char *propertyBuffer;
|
||||
int isPrefork;
|
||||
pid_t reservedPid;
|
||||
int enablePerfork;
|
||||
#endif
|
||||
} MgrContent;
|
||||
|
||||
typedef struct {
|
||||
MgrContent content;
|
||||
TaskHandle server;
|
||||
SignalHandle sigHandler;
|
||||
pid_t servicePid;
|
||||
struct ListNode appQueue; // save app pid and name
|
||||
uint32_t diedAppCount;
|
||||
uint32_t flags;
|
||||
struct ListNode diedQueue; // save app pid and name
|
||||
struct timespec perLoadStart;
|
||||
struct timespec perLoadEnd;
|
||||
struct ListNode extData;
|
||||
struct SpawnTime spawnTime;
|
||||
} AppMgr;
|
||||
|
||||
#endif
|
@ -36,24 +36,9 @@
|
||||
#include "le_task.h"
|
||||
#include "list.h"
|
||||
|
||||
#define MAX_MSG_LEN 128
|
||||
#define RETRY_TIME (200 * 1000) // 200 * 1000 wait 200ms CONNECT_RETRY_DELAY = 200 * 1000
|
||||
#define MAX_RETRY_SEND_COUNT 2 // 2 max retry count CONNECT_RETRY_MAX_TIMES = 2;
|
||||
|
||||
typedef struct Message_ {
|
||||
uint32_t magic;
|
||||
uint32_t msgType;
|
||||
uint32_t msgLen;
|
||||
uint32_t msgId;
|
||||
uint32_t tlvCount;
|
||||
char buffer[MAX_MSG_LEN];
|
||||
} Message;
|
||||
|
||||
typedef struct {
|
||||
Message msgHdr;
|
||||
Result result;
|
||||
} ResponseMsg;
|
||||
|
||||
typedef Agent_ {
|
||||
TaskHandle task;
|
||||
WatcherHandle input;
|
||||
|
@ -24,30 +24,11 @@
|
||||
#include "le_task.h"
|
||||
#include "list.h"
|
||||
|
||||
#define SLEEP_DURATION 3000 // us
|
||||
#define EXIT_TIMEOUT 1000000 // us
|
||||
#define APP_STATE_IDLE 1
|
||||
#define APP_STATE_SPAWNING 2
|
||||
#define APP_MAX_TIME 3000000
|
||||
|
||||
typedef void (* CallbackControlProcess)(uint16_t type, const char *serviceCmd, const void *context);
|
||||
|
||||
static Message *g_message = NULL;
|
||||
CallbackControlProcess g_controlFunc = NULL;
|
||||
|
||||
typedef struct {
|
||||
uint16_t tlvLen;
|
||||
uint16_t tlvType;
|
||||
} Tlv;
|
||||
|
||||
typedef enum {
|
||||
ACTION_SANDBOX = 0,
|
||||
ACTION_DUMP,
|
||||
ACTION_MODULEMGR,
|
||||
ACTION_SPAWNTIME,
|
||||
ACTION_MAX
|
||||
} ActionType;
|
||||
|
||||
typedef struct {
|
||||
uint16_t tlvLen; // 对齐后的长度
|
||||
uint16_t tlvType;
|
||||
@ -88,7 +69,6 @@ typedef struct MsgNode_ {
|
||||
} MsgNode;
|
||||
|
||||
static MyService g_service = NULL;
|
||||
static AppMgr *g_appMgr = NULL;
|
||||
|
||||
int MakeDirRec(const char *path, mode_t mode, int lastPath)
|
||||
{
|
||||
@ -192,39 +172,14 @@ static int CreateTcpServer(TaskHandle *server, const char *name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DeleteMsg(MsgNode *msgNode)
|
||||
{
|
||||
if (msgNode == NULL) {
|
||||
return;
|
||||
}
|
||||
if (msgNode->buffer) {
|
||||
free(msgNode->buffer);
|
||||
msgNode->buffer = NULL;
|
||||
}
|
||||
if (msgNode->tlvOffset) {
|
||||
free(msgNode->tlvOffset);
|
||||
msgNode->tlvOffset = NULL;
|
||||
}
|
||||
free(msgNode);
|
||||
}
|
||||
|
||||
static void WaitMsgCompleteTimeOut(const TimerHandle taskHandle, void *context)
|
||||
{
|
||||
MyTask *task = (MyTask *)context;
|
||||
printf("Long time no msg complete so close connectionId: %u \n", connection->connectionId);
|
||||
DeleteMsg(connection->receiverCtx.incompleteMsg);
|
||||
connection->receiverCtx.incompleteMsg = NULL;
|
||||
LE_CloseStreamTask(LE_GetDefaultLoop(), connection->stream);
|
||||
}
|
||||
|
||||
static inline int StartTimerForCheckMsg(MyTask *task)
|
||||
{
|
||||
if (task->receiverCtx.timer != NULL) {
|
||||
if (connection->receiverCtx.timer != NULL) {
|
||||
return 0;
|
||||
}
|
||||
int ret = LE_CreateTimer(LE_GetDefaultLoop(), &task->receiverCtx.timer, WaitMsgCompleteTimeOut, task);
|
||||
int ret = LE_CreateTimer(LE_GetDefaultLoop(), &connection->receiverCtx.timer, WaitMsgCompleteTimeOut, connection);
|
||||
if (ret == 0) {
|
||||
ret = LE_StartTimer(LE_GetDefaultLoop(), task->receiverCtx.timer, MAX_WAIT_MSG_COMPLETE, 1);
|
||||
ret = LE_StartTimer(LE_GetDefaultLoop(), connection->receiverCtx.timer, MAX_WAIT_MSG_COMPLETE, 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -382,45 +337,6 @@ static int MsgRebuild(MsgNode *message, const Message *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AppMgr *CreateMessage()
|
||||
{
|
||||
if (g_appMgr != NULL) {
|
||||
return g_appMgr;
|
||||
}
|
||||
AppMgr *appMgr = (AppMgr *)calloc(1, sizeof(AppMgr));
|
||||
if (appMgr == NULL) {
|
||||
printf("Failed to alloc memory \n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
appMgr->content.longProcName = NULL;
|
||||
appMgr->content.longProcNameLen = 0;
|
||||
appMgr->content.mode = mode;
|
||||
appMgr->content.sandboxNsFlags = 0;
|
||||
appMgr->content.wdgOpened = 0;
|
||||
appMgr->servicePid = getpid();
|
||||
appMgr->server = NULL;
|
||||
appMgr->sigHandler = NULL;
|
||||
OH_ListInit(&appMgr->appQueue);
|
||||
OH_ListInit(&appMgr->diedQueue);
|
||||
appMgr->diedAppCount = 0;
|
||||
OH_ListInit(&appMgr->extData);
|
||||
g_appMgr = appMgr;
|
||||
g_appMgr->spawnTime.minTime = APP_MAX_TIME;
|
||||
g_appMgr->spawnTime.maxTime = 0;
|
||||
return appMgr;
|
||||
}
|
||||
|
||||
AppMgr *GetAppMgr(void)
|
||||
{
|
||||
return g_appMgr;
|
||||
}
|
||||
|
||||
MgrContent *GetMgrContent(void)
|
||||
{
|
||||
return g_appMgr == NULL ? NULL : &g_appMgr->content;
|
||||
}
|
||||
|
||||
int GetMsgFromBuffer(const uint8_t *buffer, uint32_t bufferLen,
|
||||
Message **outMsg, uint32_t *msgRecvLen, uint32_t *reminder)
|
||||
{
|
||||
@ -485,29 +401,14 @@ int DecodeMsg(Message * message)
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int IsNWebMode(const AppMgr *content)
|
||||
{
|
||||
return (content != NULL) &&
|
||||
(content->content.mode == MODE_FOR_NWEB_SPAWN || content->content.mode == MODE_FOR_NWEB_COLD_RUN);
|
||||
}
|
||||
|
||||
int ProcessTerminationStatusMsg(const MsgNode *message, Result *result)
|
||||
{
|
||||
if (message == NULL || result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (!IsNWebMode(g_appMgr)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
result->result = -1;
|
||||
result->pid = 0;
|
||||
pid_t *pid = (pid_t *)GetMsgInfo(message, TLV_RENDER_TERMINATION_INFO);
|
||||
if (pid == NULL) {
|
||||
return -1;
|
||||
}
|
||||
// get render process termination status, only nwebspawn need this logic.
|
||||
result->pid = *pid;
|
||||
result->result = GetProcessTerminationStatus(*pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -622,19 +523,6 @@ void *GetMsgExtInfo(const MsgNode *message, const char *name, uint32_t *len)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MsgNode *CreateMsg(void)
|
||||
{
|
||||
MsgNode *message = (MsgNode *)calloc(1, sizeof(MsgNode));
|
||||
if (message == NULL) {
|
||||
printf("Failed to create message \n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
message->buffer = NULL;
|
||||
message->tlvOffset = NULL;
|
||||
return message;
|
||||
}
|
||||
|
||||
MsgNode *RebuildMsgNode(MsgNode *message, Process *info)
|
||||
{
|
||||
#ifdef DEBUG_BEGETCTL_BOOT
|
||||
@ -831,98 +719,6 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceInit(const char *socketPath, CallbackControlProcess func, LoopHandle loop)
|
||||
{
|
||||
if ((socketPath == NULL) || (func == NULL) || (loop == NULL)) {
|
||||
BEGET_LOGE("[control_fd] Invalid parameter");
|
||||
return;
|
||||
}
|
||||
OH_ListInit(&g_cmdService.head);
|
||||
LE_StreamServerInfo info = {};
|
||||
info.baseInfo.flags = TASK_STREAM | TASK_SERVER | TASK_PIPE;
|
||||
info.server = (char *)socketPath;
|
||||
info.socketId = -1;
|
||||
info.baseInfo.close = NULL;
|
||||
info.disConnectComplete = NULL;
|
||||
info.incommingConnect = CmdOnIncommingConnect;
|
||||
info.sendMessageComplete = NULL;
|
||||
info.recvMessage = NULL;
|
||||
g_controlFunc = func;
|
||||
if (g_controlFdLoop == NULL) {
|
||||
g_controlFdLoop = loop;
|
||||
}
|
||||
(void)LE_CreateStreamServer(g_controlFdLoop, &g_cmdService.serverTask, &info);
|
||||
}
|
||||
|
||||
void ProcessControl(uint16_t type, const char *serviceCmd, const void *context)
|
||||
{
|
||||
if ((type >= ACTION_MAX) || (serviceCmd == NULL)) {
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case ACTION_SANDBOX :
|
||||
ProcessSandboxControlFd(type, serviceCmd);
|
||||
break;
|
||||
case ACTION_DUMP :
|
||||
ProcessDumpServiceControlFd(type, serviceCmd);
|
||||
break;
|
||||
case ACTION_MODULEMGR :
|
||||
ProcessModuleMgrControlFd(type, serviceCmd);
|
||||
break;
|
||||
default :
|
||||
printf("Unknown control fd type. \n")
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Init(const char *socketPath)
|
||||
{
|
||||
ServiceInit(socketPath, ProcessControl, LE_GetDefaultLoop());
|
||||
return;
|
||||
}
|
||||
|
||||
void TestApp()
|
||||
{
|
||||
int testNum = 0;
|
||||
int ret = scanf_s("%d", &testNum);
|
||||
if (ret <= 0) {
|
||||
printf("input error \n");
|
||||
return;
|
||||
}
|
||||
|
||||
char name[128];
|
||||
char context[128];
|
||||
for (int i = 0; i < testNum; ++i) {
|
||||
printf("请输入要测试的应用名称:(sandbox, dump, moudlemgr) \n");
|
||||
ret = scanf_s("%s", name, sizeof(name));
|
||||
if (ret <= 0) {
|
||||
printf("input error \n");
|
||||
return;
|
||||
}
|
||||
|
||||
int app = -1;
|
||||
if (strcmp(name, "sandbox") == 0) {
|
||||
app = ACTION_SANDBOX;
|
||||
} else if (strcmp(name, "dump") == 0) {
|
||||
app = ACTION_DUMP;
|
||||
} else if (strcmp(name, "modulemgr") == 0) {
|
||||
app = ACTION_MODULEMGR;
|
||||
} else {
|
||||
printf("input error \n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("请输入对应的应用输入参数:\n");
|
||||
ret = scanf_s("%s", context, sizeof(context));
|
||||
if (ret <= 0) {
|
||||
printf("input error \n");
|
||||
return;
|
||||
}
|
||||
|
||||
g_controlFunc(app, context, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *const argv[])
|
||||
{
|
||||
printf("main argc: %d \n", argc);
|
||||
@ -952,8 +748,5 @@ int main(int argc, char *const argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
Init(INIT_CONTROL_SOCKET_PATH);
|
||||
TestApp();
|
||||
|
||||
return 0;
|
||||
}
|
@ -17,187 +17,9 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <linux/in.h>
|
||||
#include <linux/socket.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include "le_streamtask.c"
|
||||
#include "loop_systest.h"
|
||||
#include "loop_event.h"
|
||||
#include "le_socket.h"
|
||||
#include "le_task.h"
|
||||
#include "list.h"
|
||||
|
||||
static LE_STATUS HandleEvent(const LoopHandle loopHandle, const TaskHandle handle, uint32_t oper)
|
||||
{
|
||||
StreamConnectTask *task = (StreamConnectTask *)handle;
|
||||
printf("HandleEvent fd:%d oper 0x%x \n", GetSocketFd(handle), oper);
|
||||
|
||||
LE_STATUS status = LE_SUCCESS;
|
||||
if (LE_TEST_FLAGS(oper, EVENT_WRITE)) {
|
||||
status = HandleSendMsg(loopHandle, handle, task->sendMessageComplete);
|
||||
}
|
||||
if (LE_TEST_FLAGS(oper, EVENT_READ)) {
|
||||
status = HandleRecvMsg(loopHandle, handle, task->recvMessage, task->handleRecvMsg);
|
||||
}
|
||||
if (LE_TEST_FLAGS(oper, EVENT_ERROR)) {
|
||||
if (task->disConnectComplete) {
|
||||
task->disConnectComplete(handle);
|
||||
}
|
||||
LE_CloseStreamTask(loopHandle, handle);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static LE_STATUS HandleSendMsg(const LoopHandle loopHandle,
|
||||
const TaskHandle taskHandle, const LE_SendMessageComplete complete)
|
||||
{
|
||||
EventLoop *loop = (EventLoop *)loopHandle;
|
||||
StreamTask *task = (StreamTask *)taskHandle;
|
||||
LE_Buffer *buffer = GetFirstBuffer(task);
|
||||
while (buffer) {
|
||||
int ret = write(GetSocketFd(taskHandle), buffer->data, buffer->dataSize);
|
||||
if (ret < buffer->dataSize) {
|
||||
printf("fd:%d size %d, err:%d \n", GetSocketFd(taskHandle), buffer->dataSize, errno);
|
||||
}
|
||||
printf("HandleSendMsg fd:%d send data size %d %d \n", GetSocketFd(taskHandle), buffer->dataSize, ret);
|
||||
buffer->result = (ret == (int)buffer->dataSize) ? 0 : errno;
|
||||
if (complete != NULL) {
|
||||
complete(taskHandle, buffer);
|
||||
}
|
||||
FreeBuffer(loopHandle, task, buffer);
|
||||
buffer = GetFirstBuffer(task);
|
||||
}
|
||||
if (IsBufferEmpty(task)) {
|
||||
printf("HandleSendMsg fd:%d empty wait read \n", GetSocketFd(taskHandle));
|
||||
loop->modEvent(loop, (const BaseTask *)taskHandle, EVENT_READ);
|
||||
return LE_SUCCESS;
|
||||
}
|
||||
return LE_SUCCESS;
|
||||
}
|
||||
|
||||
static LE_STATUS HandleClientEvent(const LoopHandle loopHandle, const TaskHandle handle, uint32_t oper)
|
||||
{
|
||||
StreamClientTask *client = (StreamClientTask *)handle;
|
||||
printf("HandleClientEvent fd:%d oper 0x%x \n", GetSocketFd(handle), oper);
|
||||
|
||||
LE_STATUS status = LE_SUCCESS;
|
||||
if (LE_TEST_FLAGS(oper, EVENT_WRITE)) {
|
||||
if (client->connected == 0 && client->connectComplete) {
|
||||
client->connectComplete(handle);
|
||||
}
|
||||
client->connected = 1;
|
||||
status = HandleSendMsg(loopHandle, handle, client->sendMessageComplete);
|
||||
}
|
||||
if (LE_TEST_FLAGS(oper, EVENT_READ)) {
|
||||
status = HandleRecvMsg(loopHandle, handle, client->recvMessage, client->handleRecvMsg);
|
||||
}
|
||||
if (status == LE_DIS_CONNECTED) {
|
||||
if (client->disConnectComplete) {
|
||||
client->disConnectComplete(handle);
|
||||
}
|
||||
client->connected = 0;
|
||||
LE_CloseStreamTask(loopHandle, handle);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static void HandleTaskClose(const LoopHandle loopHandle, const TaskHandle taskHandle)
|
||||
{
|
||||
BaseTask *baseTask = (BaseTask *)taskHandle;
|
||||
printf("HandleTaskClose::DelTask \n");
|
||||
DelTask((EventLoop *)loopHandle, baseTask);
|
||||
|
||||
printf("HandleTaskClose::DCloseTask \n");
|
||||
CloseTask(loopHandle, task);
|
||||
|
||||
if (baseTask->taskId.fd > 0) {
|
||||
printf("HandleTaskClose fd: %d \n", ask->taskId.fd);
|
||||
close(baseTask->taskId.fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpConnectTaskInfo(const TaskHandle task)
|
||||
{
|
||||
if (task == NULL) {
|
||||
printf("task is null \n");
|
||||
return;
|
||||
}
|
||||
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
StreamConnectTask *connectTask = (StreamConnectTask *)baseTask;
|
||||
TaskHandle taskHandle = (TaskHandle)connectTask;
|
||||
printf("\tfd: %d \n", connectTask->stream.base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "ConnectTask");
|
||||
printf("\t ServiceInfo: \n");
|
||||
|
||||
struct ucred cred = {-1, -1, -1};
|
||||
socklen_t credSize = sizeof(struct ucred);
|
||||
if (getsockopt(LE_GetSocketFd(taskHandle), SOL_SOCKET, SO_PEERCRED, &cred, &credSize) == 0) {
|
||||
printf("\t Service Pid: %d \n", cred.pid);
|
||||
printf("\t Service Uid: %d \n", cred.uid);
|
||||
printf("\t Service Gid: %d \n", cred.gid);
|
||||
} else {
|
||||
printf("\t Service Pid: %s \n", "NULL");
|
||||
printf("\t Service Uid: %s \n", "NULL");
|
||||
printf("\t Service Gid: %s \n", "NULL");
|
||||
}
|
||||
}
|
||||
|
||||
int AcceptClient(const LoopHandle loopHandle, const TaskHandle server,
|
||||
TaskHandle *taskHandle, const LE_StreamInfo *info)
|
||||
{
|
||||
if (loopHandle == NULL || info == NULL) {
|
||||
printf("Invalid parameters \n");
|
||||
return -1;
|
||||
}
|
||||
if (server == NULL || taskHandle == NULL) {
|
||||
printf("Invalid parameters \n");
|
||||
return -1;
|
||||
}
|
||||
if (info->recvMessage == NULL) {
|
||||
printf("Invalid parameters recvMessage \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fd = -1;
|
||||
if ((info->baseInfo.flags & TASK_TEST) != TASK_TEST) {
|
||||
fd = AcceptSocket(GetSocketFd(server), info->baseInfo.flags);
|
||||
if (fd <= 0) {
|
||||
printf("Failed to accept socket %d \n", GetSocketFd(server));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
StreamConnectTask *task = (StreamConnectTask *)CreateTask(
|
||||
loopHandle, fd, &info->baseInfo, sizeof(StreamConnectTask));
|
||||
if (task == NULL) {
|
||||
printf("Failed to create task %d \n", GetSocketFd(server));
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
task->stream.base.handleEvent = HandleEvent;
|
||||
task->stream.base.innerClose = HandleTaskClose;
|
||||
task->stream.base.dumpTaskInfo = DumpConnectTaskInfo;
|
||||
task->disConnectComplete = info->disConnectComplete;
|
||||
task->sendMessageComplete = info->sendMessageComplete;
|
||||
task->serverTask = (StreamServerTask *)server;
|
||||
task->handleRecvMsg = info->handleRecvMsg;
|
||||
task->recvMessage = info->recvMessage;
|
||||
|
||||
OH_ListInit(&task->stream.buffHead);
|
||||
LoopMutexInit(&task->stream.mutex);
|
||||
if ((info->baseInfo.flags & TASK_TEST) != TASK_TEST) {
|
||||
EventLoop *loop = (EventLoop *)loopHandle;
|
||||
loop->addEvent(loop, (const BaseTask *)task, EVENT_READ);
|
||||
}
|
||||
*taskHandle = (TaskHandle)task;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -208,10 +30,10 @@ int main()
|
||||
int type;
|
||||
std::string path;
|
||||
if (socket_type == "pipe") {
|
||||
type = TASK_STREAM | TASK_PIPE |TASK_SERVER;
|
||||
type = TASK_STREAM | TASK_PIPE |TASK_SERVER | TASK_TEST;
|
||||
path = "/data/testpipe";
|
||||
} else if (socket_type == "tcp") {
|
||||
type = TASK_STREAM | TASK_TCP |TASK_SERVER;
|
||||
type = TASK_STREAM | TASK_TCP |TASK_SERVER | TASK_TEST;
|
||||
path = "127.0.0.1:7777";
|
||||
} else {
|
||||
printf("输入有误,请输入pipe或者tcp!");
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "control_fd.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class ControlfdUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(ControlfdUnitTest, Init_CmdServiceInit_001, TestSize.Level0)
|
||||
{
|
||||
char *socketPath = "dev/test";
|
||||
CallbackControlFdProcess callback;
|
||||
LoopHandle loopHandle;
|
||||
CmdServiceInit(socketPath, callback, loopHandle);
|
||||
}
|
||||
|
||||
HWTEST_F(ControlfdUnitTest, Init_CmdClientInit_001, TestSize.Level1)
|
||||
{
|
||||
char *socketPath = "dev/test";
|
||||
CallbackControlFdProcess callback;
|
||||
uint16_t type = 0;
|
||||
const char *cmd;
|
||||
CmdClientInit(socketPath, type, cmd, callback);
|
||||
}
|
||||
|
||||
HWTEST_F(ControlfdUnitTest, Init_CmdServiceProcessDelClient_001, TestSize.Level1)
|
||||
{
|
||||
pid_t pid = 0;
|
||||
CmdServiceProcessDelClient(pid);
|
||||
}
|
||||
|
||||
HWTEST_F(ControlfdUnitTest, Init_CmdServiceProcessDestroyClient_001, TestSize.Level1)
|
||||
{
|
||||
CmdServiceProcessDestroyClient();
|
||||
}
|
||||
|
||||
HWTEST_F(ControlfdUnitTest, Init_InitPtyInterface_001, TestSize.Level1)
|
||||
{
|
||||
CmdAgent *agent;
|
||||
uint16_t type;
|
||||
const char *cmd;
|
||||
CallbackSendMsgProcess callback;
|
||||
int ret = InitPtyInterface(agent, type, cmd, callback);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
} // namespace init_ut
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "fd_holder_internal.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class Fd_HolderUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(Fd_HolderUnitTest, Init_BuildControlMessage_001, TestSize.Level0)
|
||||
{
|
||||
struct msghdr *msghdr;
|
||||
int *fds;
|
||||
int fdCount = 0;
|
||||
bool sendUcred = true;
|
||||
int ret = BuildControlMessage(msghdr, fds, fdCount, sendUcred);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(Fd_HolderUnitTest, Init_BuildControlMessage_001, TestSize.Level0)
|
||||
{
|
||||
int sock;
|
||||
struct iovec iovec;
|
||||
size_t *outFdCount;
|
||||
bool nonblock;
|
||||
pid_t *requestPid;
|
||||
ReceiveFds(sock, iovec iovec, outFdCount, nonblock, requestPid);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "erofs_overlay_common.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class ErofsOverlayUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(ErofsOverlayUnitTest, Init_IsOverlayEnable_001, TestSize.Level0)
|
||||
{
|
||||
bool ret = IsOverlayEnable();
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsOverlayUnitTest, Init_CheckIsExt4_001, TestSize.Level0)
|
||||
{
|
||||
const char *dev;
|
||||
uint64_t offset;
|
||||
bool ret = CheckIsExt4(dev, offset);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsOverlayUnitTest, Init_CheckIsErofs_001, TestSize.Level0)
|
||||
{
|
||||
const char *dev;
|
||||
bool ret = CheckIsErofs(dev);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "erofs_mount_overlay.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class ErofsMountUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(ErofsMountUnitTest, Init_DoMountOverlayDevice_001, TestSize.Level0)
|
||||
{
|
||||
FstabItem *item;
|
||||
int ret = DoMountOverlayDevice(item);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsMountUnitTest, Init_MountExt4Device_001, TestSize.Level0)
|
||||
{
|
||||
const char *dev;
|
||||
const char *mnt;
|
||||
bool isFirstMount = true;
|
||||
int ret = MountExt4Device(dev, mnt, isFirstMount);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "erofs_overlay_common.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class ErofsRemountUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(ErofsRemountUnitTest, Init_GetRemountResult_001, TestSize.Level0)
|
||||
{
|
||||
int ret = GetRemountResult();
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsRemountUnitTest, Init_CheckIsExt4_001, TestSize.Level0)
|
||||
{
|
||||
bool result = true;
|
||||
SetRemountResultFlag(result);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsRemountUnitTest, Init_RemountOverlay_001, TestSize.Level0)
|
||||
{
|
||||
int ret = RemountOverlay();
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsRemountUnitTest, Init_MountOverlayOne_001, TestSize.Level0)
|
||||
{
|
||||
const char *mnt;
|
||||
int ret = MountOverlayOne(mnt);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsRemountUnitTest, Init_OverlayRemountVendorPre_001, TestSize.Level0)
|
||||
{
|
||||
OverlayRemountVendorPre();
|
||||
}
|
||||
|
||||
HWTEST_F(ErofsRemountUnitTest, Init_OverlayRemountVendorPost_001, TestSize.Level0)
|
||||
{
|
||||
OverlayRemountVendorPost();
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "fs_dm.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class FsDmUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(FsDmUnitTest, Init_FsDmInitDmDev_001, TestSize.Level0)
|
||||
{
|
||||
char *devPath = "test";
|
||||
bool useSocket = true;
|
||||
int ret = FsDmInitDmDev(devPath, useSocket);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(FsDmUnitTest, Init_FsDmCreateDevice_001, TestSize.Level0)
|
||||
{
|
||||
char **dmDevPath = "test";
|
||||
const char *devName = "test";
|
||||
DmVerityTarget *target;
|
||||
int ret = FsDmCreateDevice(dmDevPath, devName, target);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(FsDmUnitTest, Init_FsDmRemoveDevice_001, TestSize.Level0)
|
||||
{
|
||||
const char *devName = "test";
|
||||
int ret = FsDmRemoveDevice(devName);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(FsDmUnitTest, Init_FsDmCreateLinearDevice_001, TestSize.Level0)
|
||||
{
|
||||
const char *devName = "test";
|
||||
char *dmBlkName = "test";
|
||||
uint64_t dmBlkNameLen = 0;
|
||||
DmVerityTarget *target;
|
||||
int ret = FsDmCreateLinearDevice(devName, dmBlkName, dmBlkNameLen, target);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "fs_hvb.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace init_ut {
|
||||
class HookUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp(void) {};
|
||||
void TearDown(void) {};
|
||||
};
|
||||
|
||||
HWTEST_F(HookUnitTest, Init_HookMgrAdd_001, TestSize.Level0)
|
||||
{
|
||||
HOOK_MGR *hookMgr;
|
||||
int stage = 0;
|
||||
int prio = 0;
|
||||
OhosHook hook;
|
||||
int ret = HookMgrAdd(hookMgr, stage, prio, hook);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(HookUnitTest, Init_HookMgrAddEx_001, TestSize.Level0)
|
||||
{
|
||||
HOOK_MGR *hookMgr;
|
||||
const HOOK_INFO *hookInfo;
|
||||
int ret = HookMgrAddEx(hookMgr, hookInfo);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(HookUnitTest, Init_HookMgrDel_001, TestSize.Level0)
|
||||
{
|
||||
HOOK_MGR *hookMgr;
|
||||
int stage;
|
||||
OhosHook hook;
|
||||
HookMgrDel(hookMgr, stage, hook);
|
||||
}
|
||||
|
||||
HWTEST_F(HookUnitTest, Init_HookMgrExecute_001, TestSize.Level0)
|
||||
{
|
||||
HOOK_MGR *hookMgr;
|
||||
int stage;
|
||||
void *executionContext;
|
||||
const HOOK_EXEC_OPTIONS *extraArgs;
|
||||
int ret = HookMgrExecute(hookMgr, stage, executionContext, extraArgs);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(HookUnitTest, Init_HookMgrTraversal_001, TestSize.Level0)
|
||||
{
|
||||
HOOK_MGR *hookMgr;
|
||||
void *traversalCookie;
|
||||
OhosHookTraversal traversal;
|
||||
HookMgrTraversal(HOOK_MGR *hookMgr, void *traversalCookie, OhosHookTraversal traversal);
|
||||
}
|
||||
}
|
@ -139,10 +139,10 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
sources += init_common_sources
|
||||
sources += [
|
||||
"//base/startup/init/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init/services/param/liteos/param_client.c",
|
||||
"//base/startup/init/services/param/liteos/param_litedac.c",
|
||||
"//base/startup/init/services/param/liteos/param_osadp.c",
|
||||
"//base/startup/init/services/param/liteos/param_persistadp.c",
|
||||
"//base/startup/init/services/param/liteos/param_service.c",
|
||||
]
|
||||
|
||||
@ -222,12 +222,12 @@ if (defined(ohos_lite)) {
|
||||
sources += init_common_sources
|
||||
sources += [
|
||||
"//base/startup/init/services/param/adapter/param_dac.c",
|
||||
"//base/startup/init/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init/services/param/linux/param_message.c",
|
||||
"//base/startup/init/services/param/linux/param_msgadp.c",
|
||||
"//base/startup/init/services/param/linux/param_osadp.c",
|
||||
"//base/startup/init/services/param/linux/param_request.c",
|
||||
"//base/startup/init/services/param/linux/param_service.c",
|
||||
"//base/startup/init/services/param/liteos/param_persistadp.c",
|
||||
"//base/startup/init/services/param/trigger/trigger_checker.c",
|
||||
"//base/startup/init/services/param/trigger/trigger_manager.c",
|
||||
"//base/startup/init/services/param/trigger/trigger_processor.c",
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
[device]
|
||||
# <device name> <mode> <uid> <gid> <parameter>
|
||||
/dev/bus/usb/* 0660 3023 3023
|
||||
/dev/null 0666 0 0
|
||||
/dev/binder 0666 0 0
|
||||
/dev/hwbinder 0666 0 0
|
||||
|
@ -66,6 +66,7 @@ typedef enum SUBYSTEM {
|
||||
} SUBSYSTEMTYPE;
|
||||
|
||||
#define CMDLINE_VALUE_LEN_MAX 512
|
||||
#define PROCESS_NAME_MAX_LENGTH 1024
|
||||
#define UEVENTD_POLL_TIME (5 * 60 * 1000)
|
||||
#define UEVENTD_FLAG "/dev/.ueventd_trigger_done"
|
||||
|
||||
|
@ -72,7 +72,7 @@ static void *ThreadRun(void *data)
|
||||
struct timeval now = {0};
|
||||
const long timeout = 5000; // wait time 5000ms
|
||||
gettimeofday(&now, NULL);
|
||||
long nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000; // 1000 unit 1000000 unit nsec
|
||||
long long nsec = (long long)now.tv_usec * 1000 + (timeout % 1000) * 1000000; // 1000 unit 1000000 unit nsec
|
||||
abstime.tv_sec = now.tv_sec + nsec / 1000000000 + timeout / 1000; // 1000 unit 1000000000 unit nsec
|
||||
abstime.tv_nsec = nsec % 1000000000; // 1000000000 unit nsec
|
||||
pthread_cond_timedwait(&(parameterCtrl->hasData), &(parameterCtrl->lock), &abstime);
|
||||
|
@ -150,6 +150,9 @@ static int UeventdEarlyBoot(void)
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
if (name == NULL || strlen(name) > PROCESS_NAME_MAX_LENGTH) {
|
||||
return ;
|
||||
}
|
||||
printf("Usage: %s [OPTION]\n"
|
||||
"Listening kernel uevent to create device node.\n"
|
||||
"It will read configs from {/,/system,/chipset}/etc/ueventd.config.\n\n"
|
||||
|
Loading…
Reference in New Issue
Block a user