未验证 提交 15c4de23 编写于 作者: O openharmony_ci 提交者: Gitee

!1251 codex

Merge pull request !1251 from cheng_jinsong/codex
......@@ -20,6 +20,7 @@ import argparse
import os
import sys
def decode_cfg_line(data):
data.replace('\n', '').replace('\r', '')
data = data.strip()
......@@ -30,17 +31,19 @@ def decode_cfg_line(data):
return "", ""
return strs[0].strip(), strs[1].strip()
def get_param_from_cfg(cfg_name):
dict = {}
data_dict = {}
with open(cfg_name) as afile:
data = afile.readline()
while data:
name, value = decode_cfg_line(data)
if len(name) != 0 and len(value) != 0:
dict[name] = value
print("sample file name={%s %s}"%(name, value))
data_dict[name] = value
print("sample file name={%s %s}" % (name, value))
data = afile.readline()
return dict
return data_dict
def decode_code_line(data):
data.replace('\n', '').replace('\r', '')
......@@ -53,21 +56,23 @@ def decode_code_line(data):
strs = data.split(',')
if len(strs) <= 1:
return "", ""
return strs[0].strip(), data[len(strs[0]) + 1: ].strip()
return strs[0].strip(), data[len(strs[0]) + 1:].strip()
def get_param_from_c_code(code_name):
dict = {}
data_dict = {}
with open(code_name, "r+") as afile:
data = afile.readline()
while data:
name, value = decode_code_line(data)
if len(name) != 0 and len(value) != 0:
dict[name] = value
data_dict[name] = value
data = afile.readline()
afile.truncate(0)
return dict
return data_dict
def write_map_to_code(code_name, dict):
def write_map_to_code(code_name, data_dict):
try:
with open(code_name, "w") as f:
# start with 0
......@@ -91,13 +96,13 @@ def write_map_to_code(code_name, dict):
f.write(os.linesep + os.linesep)
# write data
f.write('static Node g_paramDefCfgNodes[] = {' + os.linesep)
for name, value in dict.items():
for name, value in data_dict.items():
if (value.startswith("\"")):
str = " PARAM_MAP({0}, {1})".format(name, value)
f.write(str + os.linesep)
tmp_str = " PARAM_MAP({0}, {1})".format(name, value)
f.write(tmp_str + os.linesep)
else:
str = " PARAM_MAP({0}, \"{1}\")".format(name, value)
f.write(str + os.linesep)
tmp_str = " PARAM_MAP({0}, \"{1}\")".format(name, value)
f.write(tmp_str + os.linesep)
f.write('};' + os.linesep + os.linesep)
#end
......@@ -110,19 +115,21 @@ def write_map_to_code(code_name, dict):
f.write(os.linesep)
f.truncate()
except IOError:
print("Error: open or write file %s fail"%{code_name})
print("Error: open or write file %s fail" % {code_name})
return 0
def add_to_code_dict(code_dict, cfg_dict, high = True):
def add_to_code_dict(code_dict, cfg_dict, high=True):
for name, value in cfg_dict.items():
# check if name exit
has_key = name in code_dict #code_dict.has_key(name)
has_key = name in code_dict
if has_key and high:
code_dict[name] = value
elif not has_key:
code_dict[name] = value
return code_dict
def main():
parser = argparse.ArgumentParser(
description='A common change param.para file to h.')
......
......@@ -74,7 +74,7 @@ static void RunSandbox(const std::string &sandboxName)
static void EnterShell()
{
char *argv[] = { const_cast<char *>("sh"), NULL };
char *argv[] = { const_cast<char *>("sh"), nullptr };
char *envp[] = { nullptr };
if (execve("/system/bin/sh", argv, envp) != 0) {
std::cout << "execve sh failed! err = "<< errno << std::endl;
......
......@@ -153,15 +153,9 @@ int SwitchRoot(const char *newRoot)
}
struct stat oldRootStat = {};
if (stat("/", &oldRootStat) != 0) {
INIT_LOGE("Failed to get old root \"/\" stat");
return -1;
}
INIT_ERROR_CHECK(stat("/", &oldRootStat) == 0, return -1, "Failed to get old root \"/\" stat");
DIR *oldRoot = opendir("/");
if (oldRoot == NULL) {
INIT_LOGE("Failed to open root dir \"/\"");
return -1;
}
INIT_ERROR_CHECK(oldRoot != NULL, return -1, "Failed to open root dir \"/\"");
struct stat newRootStat = {};
if (stat(newRoot, &newRootStat) != 0) {
INIT_LOGE("Failed to get new root \" %s \" stat", newRoot);
......
......@@ -91,9 +91,11 @@ bool SetSeccompPolicyWithName(const char *filterName)
strlen(filterName) + strlen(FILTER_NAME_FORMAT) - strlen("%s"), \
FILTER_NAME_FORMAT, filterName);
PLUGIN_CHECK(rc != -1, return false, "snprintf_s faiVribleName failed");
const char *filterLibRealPath = realpath(filterLibPath, NULL);
PLUGIN_CHECK(filterLibRealPath != NULL, return false, "format filter lib real path failed");
void *handler = dlopen(filterLibPath, RTLD_LAZY);
PLUGIN_CHECK(handler != NULL, return false, "dlopen %s failed", filterLibPath);
void *handler = dlopen(filterLibRealPath, RTLD_LAZY);
PLUGIN_CHECK(handler != NULL, return false, "dlopen %s failed", filterLibRealPath);
filterPtr = (struct sock_filter *)dlsym(handler, filterVaribleName);
PLUGIN_CHECK(filterPtr != NULL, dlclose(handler);
......
......@@ -23,6 +23,7 @@
#define BUFFER_LENGTH 5
#define FD_COUNT 2
#define SLEEP_TIME 3
#define ENV_FD_HOLD_PREFIX "OHOS_FD_HOLD_"
static void SaveFds(const char *serviceName, int argc, char **argv)
......@@ -70,13 +71,13 @@ int main(int argc, char **argv)
free(fds);
outfdCount = 0;
while (1) {
sleep(3);
sleep(SLEEP_TIME);
}
}
char *files[] = {"/data/test/1", "/data/test/2"};
SaveFds("fd_holder_test", FD_COUNT, (char **)files);
while (1) {
sleep(3);
sleep(SLEEP_TIME);
}
return 0;
}
......@@ -90,7 +90,7 @@ static void *ThreadRun(void *data)
parameterCtrl->empty = 0;
const char *paramValue = (config->action == ACTION_ADD) ? "added" : "removed";
INIT_LOGI("[uevent] SystemSetParameter %s act %s", config->parameter, paramValue);
size_t len = sprintf_s(paramName, sizeof(paramName), "startup.uevent.%s", config->parameter);
int len = sprintf_s(paramName, sizeof(paramName), "startup.uevent.%s", config->parameter);
if ((len <= 0) || (SystemSetParameter(paramName, paramValue) != 0)) {
INIT_LOGE("[uevent] SystemSetParameter %s failed", config->parameter);
pthread_mutex_lock(&(parameterCtrl->parameterLock));
......
......@@ -148,7 +148,7 @@ static void HandleRequiredDynamicDeviceNodes(const struct Uevent *uevent)
return;
}
while (idx < sizeof(DYNAMIC_DEVICES)/sizeof(DYNAMIC_DEVICES[0])) {
while (idx < sizeof(DYNAMIC_DEVICES) / sizeof(DYNAMIC_DEVICES[0])) {
if (strcmp(uevent->deviceName, DYNAMIC_DEVICES[idx].dev + DEV_NODE_PATH_PREFIX_LEN) != 0) {
idx++;
continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册