提交 ed6d0341 编写于 作者: C cheng_jinsong 提交者: chengjinsong2

Merge branch 'master' of gitee.com:openharmony/startup_init into 0525_codeCkeck

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
{
"name": "@ohos/startup_init",
"name": "@ohos/init",
"description": "ohos init process",
"homePage": "https://gitee.com/openharmony",
"version": "3.1",
......
......@@ -16,7 +16,7 @@ if (!defined(ohos_lite)) {
import("//build/ohos/sa_profile/sa_profile.gni")
ohos_sa_profile("device_info_profile") {
sources = [ "etc/3902.xml" ]
sources = [ "etc/3902.json" ]
part_name = "init"
}
......
{
"process": "deviceinfoservice",
"systemability": [
{
"name": 3902,
"libpath": "libdeviceinfoservice.z.so",
"run-on-create": true,
"distributed": false,
"dump_level": 1
}
]
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
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.
-->
<info>
<process>deviceinfoservice</process>
<systemability>
<name>3902</name>
<libpath>libdeviceinfoservice.z.so</libpath>
<run-on-create>true</run-on-create>
<distributed>false</distributed>
<dump-level>1</dump-level>
</systemability>
</info>
\ No newline at end of file
{
"services" : [{
"name" : "deviceinfoservice",
"path" : ["/system/bin/sa_main", "/system/profile/deviceinfoservice.xml"],
"path" : ["/system/bin/sa_main", "/system/profile/deviceinfoservice.json"],
"uid" : "deviceinfo",
"gid" : ["deviceinfo", "shell"],
"ondemand" : true,
......
......@@ -173,6 +173,7 @@ static napi_value GetSync(napi_env env, napi_callback_info info)
napi_valuetype valuetype0 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
NAPI_ASSERT(env, valuetype0 == napi_string, "Wrong argument type. Numbers expected.");
napi_valuetype valuetype1 = napi_null;
if (argc == ARGC_NUMBER) {
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
......
......@@ -270,16 +270,13 @@ static napi_value GetSync(napi_env env, napi_callback_info info)
PARAM_JS_LOGV("JSApp get status: %d, key: '%s', value: '%s', defValue: '%s'.",
ret, keyBuf.data(), value.data(), defValue.data());
napi_value napiValue = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, value.data(), strlen(value.data()), &napiValue));
if (ret < 0) {
if (ret == SYSPARAM_NOT_FOUND) {
return napiValue;
}
napi_throw(env, BusinessErrorCreate(env, ret));
return nullptr;
}
napi_value napiValue = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, value.data(), strlen(value.data()), &napiValue));
return napiValue;
}
......@@ -294,35 +291,29 @@ static void GetCallbackWork(napi_env env, StorageAsyncContextPtr asyncContext)
std::vector<char> value(MAX_VALUE_LENGTH, 0);
asyncContext->status = GetParameter(asyncContext->key,
(asyncContext->valueLen == 0) ? nullptr : asyncContext->value, value.data(), MAX_VALUE_LENGTH);
asyncContext->getValue = std::string(value.begin(), value.end());
if (asyncContext->status == 0) {
asyncContext->getValue = "";
} else if (asyncContext->status > 0) {
asyncContext->getValue = std::string(value.begin(), value.end());
}
},
[](napi_env env, napi_status status, void *data) {
StorageAsyncContext *asyncContext = reinterpret_cast<StorageAsyncContext *>(data);
napi_value result[ARGC_NUMBER] = { 0 };
if (asyncContext->status > 0) {
if (asyncContext->status >= 0) {
napi_get_undefined(env, &result[0]);
napi_create_string_utf8(env,
asyncContext->getValue.c_str(), strlen(asyncContext->getValue.c_str()), &result[1]);
} else {
if (asyncContext->status == SYSPARAM_NOT_FOUND) {
napi_get_undefined(env, &result[0]);
napi_create_string_utf8(env,
asyncContext->getValue.c_str(), strlen(asyncContext->getValue.c_str()), &result[1]);
} else {
result[0] = BusinessErrorCreate(env, asyncContext->status);
napi_get_undefined(env, &result[1]);
}
result[0] = BusinessErrorCreate(env, asyncContext->status);
napi_get_undefined(env, &result[1]);
}
if (asyncContext->deferred) {
if (asyncContext->status > 0) {
napi_resolve_deferred(env, asyncContext->deferred, result[1]);
} else {
if (asyncContext->status == SYSPARAM_NOT_FOUND) {
napi_resolve_deferred(env, asyncContext->deferred, result[1]);
} else {
napi_reject_deferred(env, asyncContext->deferred, result[0]);
}
napi_reject_deferred(env, asyncContext->deferred, result[0]);
}
} else {
napi_value callback = nullptr;
......
......@@ -59,7 +59,6 @@ static int SetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv)
BShellCmdHelp(shell, 1, helpArgs);
return 0;
}
const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
errno = 0;
unsigned int level = strtoul(argv[1], 0, 10); // 10 is decimal
if (errno != 0) {
......@@ -67,6 +66,7 @@ static int SetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv)
return -1;
}
if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) {
const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
int ret = HandleCmd(shell, "setloglevel", argc - 1, &argv[1]);
if (ret != 0) {
printf("Failed to set log level %s. \n", logLevelStr[level]);
......@@ -81,9 +81,9 @@ static int SetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv)
static int32_t GetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv)
{
const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
int level = GetIntParameter(INIT_DEBUG_LEVEL, (int)INIT_ERROR);
if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) {
const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
printf("Init log level: %s \n", logLevelStr[level]);
}
return 0;
......
......@@ -433,7 +433,7 @@ static int32_t CheckTraceStatus(void)
return (-errno);
}
char data[1024];
char data[1024] = { 0 };
ssize_t dataNum = read(fd, data, sizeof(data));
if (close(fd) < 0) {
INIT_LOGE("lldb: close fd error: %{public}d", errno);
......
......@@ -47,7 +47,6 @@ static int CreateFile(ServiceFile *file)
int fd = open(path, file->flags | O_CREAT, file->perm);
INIT_ERROR_CHECK(fd >= 0, return -1, "Failed open %s, err=%d ", path, errno);
close(fd);
fd = -1;
INIT_CHECK_ONLY_ELOG(chmod(path, file->perm) >= 0, "Failed chmod err=%d", errno);
INIT_CHECK_ONLY_ELOG(chown(path, file->uid, file->gid) >= 0, "Failed chown err=%d", errno);
file->fd = open(path, file->flags);
......
{
"name": "@ohos/startup_init_lite",
"name": "@ohos/init_lite",
"description": "ohos init lite process",
"homePage": "https://gitee.com/openharmony",
"version": "3.1",
......
......@@ -118,7 +118,6 @@ static void EnableDevKmsg(void)
char *kmsgStatus = "on";
write(fd, kmsgStatus, strlen(kmsgStatus) + 1);
close(fd);
fd = -1;
return;
}
......@@ -141,6 +140,9 @@ static char **GetRequiredDevices(Fstab fstab, int *requiredNum)
}
item = item->next;
}
if (num == 0) {
return NULL;
}
char **devices = (char **)calloc(num, sizeof(char *));
INIT_ERROR_CHECK(devices != NULL, return NULL, "Failed calloc err=%d", errno);
......
......@@ -130,7 +130,6 @@ static void DoIfup(const struct CmdArgs *ctx)
"DoIfup failed to do ioctl with command \"SIOCSIFFLAGS\", err = %d", errno);
}
close(fd);
fd = -1;
}
// format insmod <ko name> [-f] [options]
......
......@@ -57,7 +57,7 @@ void NotifyServiceChange(Service *service, int status)
"%s.%s.pid", STARTUP_SERVICE_CTL, service->name);
INIT_ERROR_CHECK(ret > 0, return, "Failed to format service pid name %s.", service->name);
ret = snprintf_s(statusStr, sizeof(statusStr), sizeof(statusStr) - 1,
"%u", (service->pid == -1) ? 0 : service->pid);
"%d", (service->pid == -1) ? 0 : service->pid);
INIT_ERROR_CHECK(ret > 0, return, "Failed to format service pid %s.", service->name);
SystemWriteParam(paramName, statusStr);
}
......
......@@ -154,6 +154,7 @@ int SwitchRoot(const char *newRoot)
struct stat newRootStat = {};
if (stat(newRoot, &newRootStat) != 0) {
INIT_LOGE("Failed to get new root \" %s \" stat", newRoot);
FreeRootDir(oldRoot, oldRootStat.st_dev);
return -1;
}
......
......@@ -59,7 +59,7 @@ def get_item_content(name_nr_table, arch_nr_table):
syscall_name_dict.get('arm').remove(func_name)
else:
content = '{}{};arm64\n'.format(content, func_name)
if not syscall_name_dict.get('arm'):
if syscall_name_dict.get('arm'):
content = '{}{};arm\n'.format(content, ';arm\n'.join(
[func_name for func_name in syscall_name_dict.get('arm')]))
......
......@@ -67,7 +67,7 @@ def get_lib_path(elf_path, elf_name, cmd_extra):
grep_unstrip = ' | grep unstripped | grep -v _x64 {}'.format(cmd_extra)
if elf_name == 'libc++.so':
grep_unstrip = ''
grep_unstrip = '| grep aarch64-linux'
cmd = 'find {} -name {}{}'.format(elf_path, elf_name, grep_unstrip)
result_list = os.popen(cmd).read().split('\n')
result = result_list[0].strip()
......@@ -281,9 +281,9 @@ def get_function_name_nr_table(src_syscall_path):
def collect_concrete_syscall(args):
if args.target_cpu == 'arm64':
arch_str = 'aarch64'
arch_str = 'aarch64-linux'
elif args.target_cpu == 'arm':
arch_str = 'arm'
arch_str = 'arm-linux'
libc_path = get_lib_path(args.src_elf_path, 'libc.so', ' | grep ' + arch_str)
libc_asm_path = generate_libc_asm(args.target_cpu, libc_path, '.')
......
......@@ -61,6 +61,8 @@ def remove_head_zero(addr):
def line_find_syscall_nr(line, nr_set, nr_last):
nr = nr_last
is_find_nr = False
is_find_svc = True
if ';' in line:
nr_tmp, is_digit = gen_policy.str_convert_to_int(line[line.find('0x'):])
else:
......
......@@ -134,8 +134,7 @@ static bool GetFilterFileByName(const char *filterName, char *filterLibRealPath,
static int GetSeccompPolicy(const char *filterName, int **handler,
const char *filterLibRealPath, struct sock_fprog *prog)
{
if (filterName == NULL || filterLibRealPath == NULL || \
handler == NULL || prog == NULL) {
if (filterName == NULL || filterLibRealPath == NULL || handler == NULL || prog == NULL) {
return INPUT_ERROR;
}
......@@ -155,8 +154,9 @@ static int GetSeccompPolicy(const char *filterName, int **handler,
if (rc == -1) {
return RETURN_ERROR;
}
policyHanlder = dlopen(filterLibRealPath, RTLD_LAZY);
char realPath[PATH_MAX] = { 0 };
realpath(filterLibRealPath, realPath);
policyHanlder = dlopen(realPath, RTLD_LAZY);
if (policyHanlder == NULL) {
return RETURN_NULL;
}
......
......@@ -54,7 +54,7 @@ static int TraversalEvent(ListNode *node, void *root)
return 0;
}
EventArgs *args = (EventArgs *)root;
int len = GetServiceName(item->paramName, args->buffer + args->currLen, args->bufferLen - args->currLen);
uint32_t len = GetServiceName(item->paramName, args->buffer + args->currLen, args->bufferLen - args->currLen);
PLUGIN_CHECK(len > 0 && ((len + args->currLen) < args->bufferLen), return -1,
"Failed to format service name %s", item->paramName);
args->currLen += len;
......
......@@ -215,7 +215,7 @@ static bool SetTraceTagsEnabled(uint64_t tags)
{
TraceWorkspace *workspace = GetTraceWorkspace();
PLUGIN_CHECK(workspace != NULL, return false, "Failed to get trace workspace");
int len = sprintf_s((char *)workspace->buffer, sizeof(workspace->buffer), "%" PRId64 "", tags);
int len = sprintf_s((char *)workspace->buffer, sizeof(workspace->buffer), "%" PRIu64 "", tags);
PLUGIN_CHECK(len > 0, return false, "Failed to format tags %" PRId64 "", tags);
return SystemWriteParam(TRACE_TAG_PARAMETER, workspace->buffer) == 0;
}
......@@ -346,10 +346,11 @@ static void DumpCompressedTrace(int traceFd, int outFd)
return, "Error: couldn't allocate buffers\n");
z_stream zs = {};
int ret = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY); // 16 8 bit
int ret = 0;
deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY); // 16 8 bit
do {
// read data
zs.avail_in = TEMP_FAILURE_RETRY(read(traceFd, inBuffer, CHUNK_SIZE));
zs.avail_in = (uInt)TEMP_FAILURE_RETRY(read(traceFd, inBuffer, CHUNK_SIZE));
PLUGIN_CHECK(zs.avail_in >= 0, break, "Error: reading trace, errno: %d\n", errno);
flush = zs.avail_in == 0 ? Z_FINISH : Z_NO_FLUSH;
zs.next_in = inBuffer;
......@@ -359,7 +360,7 @@ static void DumpCompressedTrace(int traceFd, int outFd)
ret = deflate(&zs, flush);
PLUGIN_CHECK(ret != Z_STREAM_ERROR, break, "Error: deflate trace, errno: %d\n", errno);
size_t have = CHUNK_SIZE - zs.avail_out;
size_t bytesWritten = TEMP_FAILURE_RETRY(write(outFd, outBuffer, have));
size_t bytesWritten = (size_t)TEMP_FAILURE_RETRY(write(outFd, outBuffer, have));
if (bytesWritten < have) {
PLUGIN_LOGE("Error: writing deflated trace, errno: %d\n", errno);
flush = Z_FINISH; // finish
......@@ -426,9 +427,9 @@ static bool MarkOthersClockSync(void)
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(len > 0, break, "Warning: writing clock sync marker, errno: %d", errno);
PLUGIN_CHECK(ret > 0, break, "Warning: writing clock sync marker, errno: %d", errno);
ret = fprintf(file, "trace_event_clock_sync: parent_ts=%f\n", parentTs);
PLUGIN_CHECK(len > 0, break, "Warning: writing clock sync marker, errno: %d", errno);
PLUGIN_CHECK(ret > 0, break, "Warning: writing clock sync marker, errno: %d", errno);
} while (0);
(void)fclose(file);
return true;
......
......@@ -59,10 +59,10 @@ static int InitParamSecurity(ParamWorkSpace *workSpace,
RegisterSecurityOpsPtr registerOps, ParamSecurityType type, int isInit, int op)
{
PARAM_CHECK(workSpace != NULL && type < PARAM_SECURITY_MAX, return -1, "Invalid param");
int ret = registerOps(&workSpace->paramSecurityOps[type], isInit);
registerOps(&workSpace->paramSecurityOps[type], isInit);
PARAM_CHECK(workSpace->paramSecurityOps[type].securityInitLabel != NULL,
return -1, "Invalid securityInitLabel");
ret = workSpace->paramSecurityOps[type].securityInitLabel(&workSpace->securityLabel, isInit);
int ret = workSpace->paramSecurityOps[type].securityInitLabel(&workSpace->securityLabel, isInit);
PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_NAME, "Failed to init security");
ParamSecurityOps *paramSecurityOps = GetParamSecurityOps(type);
......@@ -165,7 +165,7 @@ INIT_INNER_API int InitParamWorkSpace(int onlyRead, const PARAM_WORKSPACE_OPS *o
ret = AddWorkSpace(WORKSPACE_NAME_DEF_SELINUX, WORKSPACE_INDEX_BASE, onlyRead, PARAM_WORKSPACE_DEF);
PARAM_CHECK(ret == 0, return -1, "Failed to add default workspace");
// add dac workspace
ret = AddWorkSpace(WORKSPACE_NAME_DAC, WORKSPACE_INDEX_DAC, onlyRead, PARAM_WORKSPACE_SMALL);
ret = AddWorkSpace(WORKSPACE_NAME_DAC, WORKSPACE_INDEX_DAC, onlyRead, PARAM_WORKSPACE_DAC);
PARAM_CHECK(ret == 0, return -1, "Failed to add dac workspace");
#endif
if (onlyRead == 0) {
......@@ -187,9 +187,9 @@ INIT_INNER_API int InitParamWorkSpace(int onlyRead, const PARAM_WORKSPACE_OPS *o
} else {
ret = OpenWorkSpace(WORKSPACE_INDEX_DAC, onlyRead);
PARAM_CHECK(ret == 0, return -1, "Failed to open dac workspace");
#ifdef PARAM_SUPPORT_SELINUX // load security label and create workspace
ret = OpenWorkSpace(WORKSPACE_INDEX_BASE, onlyRead);
PARAM_CHECK(ret == 0, return -1, "Failed to open default workspace");
#ifdef PARAM_SUPPORT_SELINUX // load security label and create workspace
ParamSecurityOps *ops = GetParamSecurityOps(PARAM_SECURITY_SELINUX);
if (ops != NULL && ops->securityGetLabel != NULL) {
ops->securityGetLabel(NULL);
......@@ -461,16 +461,9 @@ static int GetParamLabelInfo(const char *name, ParamLabelIndex *labelIndex, Para
PARAM_CHECK(dacSpace != NULL && dacSpace->area != NULL,
return DAC_RESULT_FORBIDED, "Invalid workSpace for %s", name);
*node = BaseFindTrieNode(dacSpace, name, strlen(name), &labelIndex->dacLabelIndex);
ParamSecurityNode *securityNode = (ParamSecurityNode *)GetTrieNode(dacSpace, labelIndex->dacLabelIndex);
if ((securityNode == NULL) || (securityNode->selinuxIndex == 0) ||
(securityNode->selinuxIndex == INVALID_SELINUX_INDEX)) {
labelIndex->workspace = GetWorkSpaceByName(name);
PARAM_CHECK(labelIndex->workspace != NULL, return DAC_RESULT_FORBIDED, "Invalid workSpace for %s", name);
} else if (securityNode->selinuxIndex < g_paramWorkSpace.maxLabelIndex) {
labelIndex->workspace = g_paramWorkSpace.workSpace[securityNode->selinuxIndex];
PARAM_CHECK(labelIndex->workspace != NULL, return DAC_RESULT_FORBIDED,
"Invalid workSpace for %s %d", name, securityNode->selinuxIndex);
}
labelIndex->workspace = GetWorkSpaceByName(name);
PARAM_CHECK(labelIndex->workspace != NULL, return DAC_RESULT_FORBIDED, "Invalid workSpace for %s", name);
labelIndex->selinuxLabelIndex = labelIndex->workspace->spaceIndex;
return 0;
}
......@@ -514,7 +507,7 @@ STATIC_INLINE int DacCheckGroupPermission(const ParamSecurityLabel *srcLabel, ui
return DAC_RESULT_FORBIDED;
}
gid_t gids[64] = { 0 }; // max gid number
const uint32_t gidNumber = g_paramWorkSpace.ops.getServiceGroupIdByPid(
const uint32_t gidNumber = (uint32_t)g_paramWorkSpace.ops.getServiceGroupIdByPid(
srcLabel->cred.pid, gids, sizeof(gids) / sizeof(gids[0]));
for (uint32_t index = 0; index < gidNumber; index++) {
PARAM_LOGV("DacCheckGroupPermission gid %u", gids[index]);
......
......@@ -91,10 +91,15 @@ extern "C" {
#define PARAM_WORKSPACE_MAX (80 * 1024)
#define PARAM_WORKSPACE_SMALL (1024 * 10)
#define PARAM_WORKSPACE_DEF (1024 * 30)
#define PARAM_WORKSPACE_DAC (1024 * 20)
#endif // __LITEOS_A__
#endif // __LITEOS_M__
#endif // STARTUP_INIT_TEST
#ifndef PARAM_WORKSPACE_DAC
#define PARAM_WORKSPACE_DAC PARAM_WORKSPACE_SMALL
#endif
// support futex
#ifndef __NR_futex
#define PARAM_NR_FUTEX 202 /* syscall number */
......
{
"services" : [{
"name" : "param_watcher",
"path" : ["/system/bin/sa_main", "/system/profile/param_watcher.xml"],
"path" : ["/system/bin/sa_main", "/system/profile/param_watcher.json"],
"uid" : "paramwatcher",
"start-mode" : "boot",
"gid" : ["paramwatcher", "shell"],
......
......@@ -10,7 +10,7 @@
# 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.
service param_watcher /system/bin/sa_main /system/profile/param_watcher.xml
service param_watcher /system/bin/sa_main /system/profile/param_watcher.json
class z_core
user system
group system shell
......
......@@ -213,6 +213,9 @@ void WatcherManager::SendLocalChange(const std::string &keyPrefix, uint32_t remo
struct Context context = {buffer.data(), remoteWatcherId, keyPrefix, this};
// walk watcher
SystemTraversalParameter("", [](ParamHandle handle, void *cookie) {
if (cookie == nullptr) {
return;
}
struct Context *context = (struct Context *)(cookie);
SystemGetParameterName(handle, context->buffer, PARAM_NAME_LEN_MAX);
if (!FilterParam(context->buffer, context->keyPrefix)) {
......@@ -222,6 +225,9 @@ void WatcherManager::SendLocalChange(const std::string &keyPrefix, uint32_t remo
uint32_t size = PARAM_CONST_VALUE_LEN_MAX;
SystemGetParameterValue(handle, context->buffer + PARAM_NAME_LEN_MAX, &size);
auto remoteWatcher = context->watcherManagerPtr->GetRemoteWatcher(context->remoteWatcherId);
if (remoteWatcher == nullptr) {
return;
}
remoteWatcher->ProcessParameterChange(
context->keyPrefix, context->buffer, context->buffer + PARAM_NAME_LEN_MAX);
}, reinterpret_cast<void *>(&context));
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
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.
-->
<info>
<process>param_watcher</process>
<systemability>
<name>3901</name>
<libpath>libparam_watcher.z.so</libpath>
<run-on-create>true</run-on-create>
<distributed>false</distributed>
<dump-level>1</dump-level>
</systemability>
</info>
......@@ -14,7 +14,7 @@
import("//build/ohos/sa_profile/sa_profile.gni")
ohos_sa_profile("param_watcher_profile") {
sources = [ "3901.xml" ]
sources = [ "param_watcher.json" ]
part_name = "init"
}
{
"process": "param_watcher",
"systemability": [
{
"name": 3901,
"libpath": "libparam_watcher.z.so",
"run-on-create": true,
"distributed": false,
"dump_level": 1
}
]
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ namespace OHOS {
char *rest = nullptr;
std::string str(reinterpret_cast<const char*>(data), size);
ParamHandle handle = (ParamHandle)strtoul(str.c_str(), &rest, BASE);
if (!GetParameterCommitId(handle)) {
if ((handle < BASE) && (!GetParameterCommitId(handle))) {
result = true;
}
return result;
......
......@@ -28,7 +28,7 @@ namespace OHOS {
char *rest = nullptr;
std::string str(reinterpret_cast<const char*>(data), size);
ParamHandle handle = (ParamHandle)strtoul(str.c_str(), &rest, BASE);
if (!GetParameterValue(handle, buffer, len)) {
if ((handle < BASE) && (!GetParameterValue(handle, buffer, len))) {
result = true;
}
return result;
......
......@@ -40,7 +40,7 @@ namespace OHOS {
CloseStdout();
Cookie instance = {0, nullptr};
Cookie *cookie = &instance;
if (size <= 0) {
if (size == 0) {
return false;
}
if (size > PARAM_CONST_VALUE_LEN_MAX + PARAM_NAME_LEN_MAX) {
......
......@@ -113,7 +113,6 @@ HWTEST_F(CmdsUnitTest, TestCommonChmod, TestSize.Level1)
DoCmdByName("chmod ", "777 /data/init_ut/test_dir0/test_file001");
close(fd);
fd = -1;
}
HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1)
......@@ -129,7 +128,6 @@ HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1)
int ret = access(testFile2, F_OK);
EXPECT_EQ(ret, 0);
close(fd);
fd = -1;
// abnormal
DoCmdByName("copy ", "/data/init_ut/test_dir0/test_file_copy1 /data/init_ut/test_dir0/test_file_copy1");
DoCmdByName("copy ", "/data/init_ut/test_dir0/test_file_copy11 /data/init_ut/test_dir0/test_file_copy1");
......@@ -156,7 +154,6 @@ HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1)
int length = read(fd, buffer, bufLen - 1);
EXPECT_EQ(length, strlen("aaa"));
close(fd);
fd = -1;
// abnormal
DoCmdByName("write ", "/data/init_ut/test_dir0/test_file_write2 aaa 2");
}
......
......@@ -654,13 +654,13 @@ int __attribute__((weak))SymlinkStub(const char * oldpath, const char * newpath)
int PrctlStub(int option, ...)
{
static int count = 0;
static int count1 = 0;
if (option == PR_SET_SECUREBITS) {
static int count = 0;
count++;
return (count % g_testRandom == 1) ? 0 : -1;
}
if (option == PR_CAP_AMBIENT) {
static int count1 = 0;
count1++;
return (count1 % g_testRandom == 1) ? 0 : -1;
}
......@@ -733,7 +733,6 @@ ParamLabelIndex *TestGetParamLabelIndex(const char *name)
if (paramWorkspace == nullptr) {
return &labelIndex;
}
labelIndex.workspace = paramWorkspace->workSpace[0];
#ifdef PARAM_SUPPORT_SELINUX
if (paramWorkspace->selinuxSpace.getParamLabelIndex == nullptr) {
return &labelIndex;
......
......@@ -42,5 +42,4 @@ void HandleFimwareDeviceEvent(const struct Uevent *uevent)
char *endCode = "-1";
(void)write(fd, "-1", strlen(endCode));
close(fd);
fd = -1;
}
......@@ -242,7 +242,6 @@ void ParseUeventdConfigFile(const char *file)
if (fstat(fd, &st) < 0) {
INIT_LOGE("Failed to get file stat. err = %d", errno);
close(fd);
fd = -1;
return;
}
......@@ -252,7 +251,6 @@ void ParseUeventdConfigFile(const char *file)
if (buffer == NULL) {
INIT_LOGE("Failed to malloc memory. err = %d", errno);
close(fd);
fd = -1;
return;
}
......@@ -261,7 +259,6 @@ void ParseUeventdConfigFile(const char *file)
free(buffer);
buffer = NULL;
close(fd);
fd = -1;
return;
}
......@@ -270,7 +267,6 @@ void ParseUeventdConfigFile(const char *file)
free(buffer);
buffer = NULL;
close(fd);
fd = -1;
}
// support '*' to match all characters
......
......@@ -55,6 +55,30 @@ static void WaitAtStartup(const char *source)
return;
}
#ifdef WDIOC_SETPRETIMEOUT
int GetWatcherDogCfg(int interval, int timeoutGet, int fd)
{
int preTimeout = 0;
int preTimeoutGet = 0;
preTimeout = timeoutGet - PRETIMEOUT_GAP; // ensure pretimeout smaller then timeout
if (preTimeout > 0) {
int ret = ioctl(fd, WDIOC_SETPRETIMEOUT, &preTimeout);
if (ret) {
INIT_LOGE("Failed to set pretimeout to %d\n", preTimeout);
}
ret = ioctl(fd, WDIOC_GETPRETIMEOUT, &preTimeoutGet);
if (ret) {
INIT_LOGE("Failed to get pretimeout\n");
}
}
if (preTimeoutGet > 0 && preTimeoutGet < interval) {
interval = preTimeoutGet / PRETIMEOUT_DIV;
}
return interval;
}
#endif
int main(int argc, const char *argv[])
{
WaitAtStartup("/dev/watchdog");
......@@ -87,11 +111,6 @@ int main(int argc, const char *argv[])
int timeoutSet = interval + gap;
int timeoutGet = 0;
#ifdef WDIOC_SETPRETIMEOUT
int preTimeout = 0;
int preTimeoutGet = 0;
#endif
int ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeoutSet);
if (ret) {
INIT_LOGE("Failed to set timeout to %d\n", timeoutSet);
......@@ -106,21 +125,7 @@ int main(int argc, const char *argv[])
}
#ifdef WDIOC_SETPRETIMEOUT
preTimeout = timeoutGet - PRETIMEOUT_GAP; // ensure pretimeout smaller then timeout
if (preTimeout > 0) {
ret = ioctl(fd, WDIOC_SETPRETIMEOUT, &preTimeout);
if (ret) {
INIT_LOGE("Failed to set pretimeout to %d\n", preTimeout);
}
ret = ioctl(fd, WDIOC_GETPRETIMEOUT, &preTimeoutGet);
if (ret) {
INIT_LOGE("Failed to get pretimeout\n");
}
}
if (preTimeoutGet > 0 && preTimeoutGet < interval) {
interval = preTimeoutGet / PRETIMEOUT_DIV;
}
interval = GetWatcherDogCfg(interval, timeoutGet, fd);
#endif
while (1) {
......@@ -128,6 +133,5 @@ int main(int argc, const char *argv[])
sleep(interval);
}
close(fd);
fd = -1;
return -1;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册