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

!506 Fix: appspawn归一化

Merge pull request !506 from 熊磊/init_0411
......@@ -32,7 +32,7 @@
#define DOREBOOT_PARAM "reboot.ut"
#endif
int DoReboot(const char *option)
int DoReboot_(const char *option)
{
char value[MAX_REBOOT_OPTION_SIZE];
int ret = 0;
......@@ -63,3 +63,25 @@ int DoReboot(const char *option)
BEGET_ERROR_CHECK(ret == 0, return -1, "Set parameter to trigger reboot command \" %s \" failed", value);
return 0;
}
int DoReboot(const char *option)
{
// check if param set ok
const int maxCount = 10;
int count = 0;
DoReboot_(option);
while (count < maxCount) {
usleep(100 * 1000); // 100 * 1000 wait 100ms
char result[10] = {0}; // 10 stop len
uint32_t len = sizeof(result);
int ret = SystemGetParameter(STARTUP_DEVICE_CTL, result, &len);
if (ret == 0 && strcmp(result, DEVICE_CMD_STOP) == 0) {
BEGET_LOGE("Success to reboot system");
return 0;
}
count++;
DoReboot_(option);
}
BEGET_LOGE("Failed to reboot system");
return 0;
}
......@@ -44,6 +44,22 @@
"src-path" : "/data",
"sandbox-path" : "/data",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
"src-path" : "/system/fonts",
"sandbox-path" : "/system/fonts",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
"src-path" : "/config",
"sandbox-path" : "/config",
"sandbox-flags" : [ "bind", "rec" ]
}, {
"src-path" : "/sys_prod",
"sandbox-path" : "/sys_prod",
"sandbox-flags" : [ "bind", "rec" ]
}, {
"src-path" : "/storage",
"sandbox-path" : "/storage",
"sandbox-flags" : [ "bind", "rec", "private" ]
}
],
"mount-bind-files" : [{
......
......@@ -48,6 +48,22 @@
"src-path" : "/data",
"sandbox-path" : "/data",
"sandbox-flags" : [ "bind", "rec" ]
}, {
"src-path" : "/system/fonts",
"sandbox-path" : "/system/fonts",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
"src-path" : "/config",
"sandbox-path" : "/config",
"sandbox-flags" : [ "bind", "rec" ]
}, {
"src-path" : "/sys_prod",
"sandbox-path" : "/sys_prod",
"sandbox-flags" : [ "bind", "rec" ]
}, {
"src-path" : "/storage",
"sandbox-path" : "/storage",
"sandbox-flags" : [ "bind", "rec", "private" ]
}
],
"mount-bind-files": [{
......
......@@ -59,6 +59,8 @@ void HashMapRemove(HashMapHandle handle, const void *key);
HashNode *HashMapGet(HashMapHandle handle, const void *key);
HashNode *HashMapFind(HashMapHandle handle,
int hashCode, const void *key, HashKeyCompare keyCompare);
void HashMapTraverse(HashMapHandle handle, void (*hashNodeTraverse)(const HashNode *node, const void *context),
const void *context);
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -259,13 +259,15 @@ static int BindCpuCore(Service *service)
return SERVICE_SUCCESS;
}
static void ClearEnvironment(void)
static void ClearEnvironment(Service *service)
{
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigaddset(&mask, SIGTERM);
sigprocmask(SIG_UNBLOCK, &mask, NULL);
if (strcmp(service->name, "appspawn") != 0) {
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigaddset(&mask, SIGTERM);
sigprocmask(SIG_UNBLOCK, &mask, NULL);
}
return;
}
......@@ -297,7 +299,7 @@ int ServiceStart(Service *service)
DoJobNow(service->serviceJobs.jobsName[JOB_ON_START]);
}
ClearEnvironment();
ClearEnvironment(service);
if (!IsOnDemandService(service)) {
INIT_ERROR_CHECK(CreateServiceSocket(service) >= 0, return SERVICE_FAILURE,
......
......@@ -781,8 +781,7 @@ int ParseOneService(const cJSON *curItem, Service *service)
INIT_CHECK_RETURN_VALUE(curItem != NULL && service != NULL, SERVICE_FAILURE);
int ret = 0;
#ifdef WITH_SELINUX
ret = GetStringItem(curItem, SECON_STR_IN_CFG, service->secon, MAX_SECON_LEN);
INIT_CHECK_ONLY_ELOG(ret == 0, "GetServiceSecon %s section not found, skip", SECON_STR_IN_CFG);
(void)GetStringItem(curItem, SECON_STR_IN_CFG, service->secon, MAX_SECON_LEN);
#endif // WITH_SELINUX
ret = GetServiceArgs(curItem, "path", MAX_PATH_ARGS_CNT, &service->pathArgs);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get path for service %s", service->name);
......@@ -944,8 +943,10 @@ void StopAllServices(int flags, const char **exclude, int size,
int (*filter)(const Service *service, const char **exclude, int size))
{
Service *service = GetServiceByName("appspawn");
if (((SERVICE_ATTR_NEEDWAIT & flags) == SERVICE_ATTR_NEEDWAIT) && service != NULL && service->pid != 0) {
if (service != NULL && service->pid != -1) { // notify appspawn stop
kill(service->pid, SIGTERM);
waitpid(service->pid, 0, 0);
service->pid = -1;
}
InitGroupNode *node = GetNextGroupNode(NODE_TYPE_SERVICES, NULL);
......
......@@ -100,6 +100,7 @@ typedef int (*LE_IncommingConntect)(const LoopHandle loopHandle, const TaskHandl
typedef struct {
LE_BaseInfo baseInfo;
char *server;
int socketId;
LE_DisConntectComplete disConntectComplete;
LE_IncommingConntect incommingConntect;
LE_SendMessageComplete sendMessageComplete;
......
......@@ -33,7 +33,7 @@ static LE_STATUS HandleSignalEvent_(const LoopHandle loop, const TaskHandle task
}
struct signalfd_siginfo fdsi;
ssize_t s = read(GetSocketFd(task), &fdsi, sizeof(fdsi));
LE_CHECK(s == sizeof(fdsi), return LE_FAILURE, "Failed to read sign");
LE_CHECK(s == sizeof(fdsi), return LE_FAILURE, "Failed to read sign %d %d", s, errno);
SignalTask *sigTask = (SignalTask *)task;
if (sigTask->processSignal) {
sigTask->processSignal(&fdsi);
......
......@@ -164,8 +164,11 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
LE_CHECK(info->incommingConntect != NULL, return LE_INVALID_PARAM,
"Invalid parameters incommingConntect %s", info->server);
int fd = CreateSocket(info->baseInfo.flags, info->server);
LE_CHECK(fd > 0, return LE_FAILURE, "Failed to create socket %s", info->server);
int fd = info->socketId;
if (info->socketId <= 0) {
fd = CreateSocket(info->baseInfo.flags, info->server);
LE_CHECK(fd > 0, return LE_FAILURE, "Failed to create socket %s", info->server);
}
EventLoop *loop = (EventLoop *)loopHandle;
StreamServerTask *task = (StreamServerTask *)CreateTask(loopHandle, fd, &info->baseInfo,
......
......@@ -113,7 +113,6 @@ void HashMapRemove(HashMapHandle handle, const void *key)
while (node != NULL) {
int ret = tab->keyCompare(node, key);
if (ret == 0) {
INIT_LOGV("HashMapRemove tableId %d hashCode %d node %p", tab->tableId, hashCode, node);
if (node == tab->buckets[hashCode]) {
tab->buckets[hashCode] = node->next;
} else {
......@@ -173,4 +172,19 @@ HashNode *HashMapFind(HashMapHandle handle,
"Invalid hashcode %d %d", tab->maxBucket, hashCode);
INIT_LOGV("HashMapGet tableId %d hashCode %d", tab->tableId, hashCode);
return GetHashNodeByKey(tab, tab->buckets[hashCode], key, keyCompare);
}
\ No newline at end of file
}
void HashMapTraverse(HashMapHandle handle, void (*hashNodeTraverse)(const HashNode *node, const void *context),
const void *context)
{
INIT_ERROR_CHECK(handle != NULL && hashNodeTraverse != NULL, return, "Invalid param");
HashTab *tab = (HashTab *)handle;
for (int i = 0; i < tab->maxBucket; i++) {
HashNode *node = tab->buckets[i];
while (node != NULL) {
HashNode *next = node->next;
hashNodeTraverse(node, context);
node = next;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册