mirror of
https://github.com/openharmony/startup_init_lite.git
synced 2026-07-20 01:13:32 -04:00
@@ -12,8 +12,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef BASE_STARTUP_INITLITE_IMPORT_H
|
||||
#define BASE_STARTUP_INITLITE_IMPORT_H
|
||||
#include "cJSON.h"
|
||||
void ParseAllImports(cJSON *root);
|
||||
#endif
|
||||
|
||||
#ifndef BASE_STARTUP_INITLITE_IMPORT_H
|
||||
#define BASE_STARTUP_INITLITE_IMPORT_H
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
void ParseAllImports(cJSON *root);
|
||||
|
||||
#endif
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
#define MAX_SOCK_NAME_LEN 16
|
||||
#define SOCK_OPT_NUMS 6
|
||||
enum SockOptionTab
|
||||
{
|
||||
enum SockOptionTab {
|
||||
SERVICE_SOCK_NAME = 0,
|
||||
SERVICE_SOCK_TYPE,
|
||||
SERVICE_SOCK_PERM,
|
||||
@@ -34,8 +33,7 @@ enum SockOptionTab
|
||||
};
|
||||
|
||||
struct ServiceSocket;
|
||||
struct ServiceSocket
|
||||
{
|
||||
struct ServiceSocket {
|
||||
char *name; // service name
|
||||
int type; // socket type
|
||||
uid_t uid; // uid
|
||||
|
||||
@@ -41,7 +41,6 @@ typedef enum {
|
||||
PARAM_CODE_NOT_INIT
|
||||
} PARAM_CODE;
|
||||
|
||||
#define IS_READY_ONLY(name) strncmp((name), "ro.", strlen("ro.")) == 0
|
||||
#define LABEL_STRING_LEN 128
|
||||
|
||||
#ifdef STARTUP_LOCAL
|
||||
@@ -75,16 +74,16 @@ typedef enum {
|
||||
}
|
||||
|
||||
#define futex(addr1, op, val, rel, addr2, val3) \
|
||||
syscall(SYS_futex, addr1, op, val, rel, addr2, val3)
|
||||
syscall(SYS_futex, addr1, op, val, rel, addr2, val3)
|
||||
#define futex_wait_always(addr1) \
|
||||
syscall(SYS_futex, addr1, FUTEX_WAIT, *(int*)(addr1), 0, 0, 0)
|
||||
syscall(SYS_futex, addr1, FUTEX_WAIT, *(int*)(addr1), 0, 0, 0)
|
||||
#define futex_wake_single(addr1) \
|
||||
syscall(SYS_futex, addr1, FUTEX_WAKE, 1, 0, 0, 0)
|
||||
syscall(SYS_futex, addr1, FUTEX_WAKE, 1, 0, 0, 0)
|
||||
|
||||
typedef struct UserCred {
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
} UserCred;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -129,12 +129,10 @@ int AddParam(WorkSpace *workSpace, const char *name, const char *value)
|
||||
TrieDataNode *node = AddTrieDataNode(workSpace, name, strlen(name));
|
||||
PARAM_CHECK(node != NULL, return PARAM_CODE_REACHED_MAX, "Failed to add node");
|
||||
DataEntry *entry = (DataEntry *)GetTrieNode(workSpace, &node->dataIndex);
|
||||
//PARAM_LOGI("AddParam entry %p", entry);
|
||||
if (entry == NULL) {
|
||||
u_int32_t offset = AddData(workSpace, name, strlen(name), value, strlen(value));
|
||||
PARAM_CHECK(offset > 0, return PARAM_CODE_REACHED_MAX, "Failed to allocate name %s", name);
|
||||
SaveIndex(&node->dataIndex, offset);
|
||||
//PARAM_LOGI("AddParam entry %p %u", entry, offset);
|
||||
}
|
||||
atomic_store_explicit(&workSpace->area->serial,
|
||||
atomic_load_explicit(&workSpace->area->serial, memory_order_relaxed) + 1, memory_order_release);
|
||||
@@ -161,7 +159,6 @@ int UpdateParam(WorkSpace *workSpace, u_int32_t *dataIndex, const char *name, co
|
||||
if (ret != 0) {
|
||||
PARAM_LOGE("Failed to update param value %s %s", name, value);
|
||||
}
|
||||
//PARAM_LOGI("UpdateParam entry %p", entry);
|
||||
atomic_store_explicit(&entry->serial, serial + 1, memory_order_release);
|
||||
futex_wake(&entry->serial, INT_MAX);
|
||||
atomic_store_explicit(&workSpace->area->serial,
|
||||
@@ -196,7 +193,6 @@ int WriteParamWithCheck(ParamWorkSpace *workSpace,
|
||||
PARAM_CHECK(ret == 0, return ret, "Illegal param name %s", name);
|
||||
TrieDataNode *info = FindTrieDataNode(&workSpace->paramSpace, name, strlen(name), 1);
|
||||
ret = CanWriteParam(workSpace, srcLabel, info, name, value);
|
||||
//PARAM_LOGI("WriteParamWithCheck info %p", info);
|
||||
PARAM_CHECK(ret == 0, return ret, "Permission to write param %s", name);
|
||||
return WriteParam(&workSpace->paramSpace, name, value);
|
||||
}
|
||||
@@ -209,7 +205,6 @@ int WriteParam(WorkSpace *workSpace, const char *name, const char *value)
|
||||
TrieDataNode *node = FindTrieDataNode(workSpace, name, strlen(name), 0);
|
||||
int ret = CheckParamValue(workSpace, node, name, value);
|
||||
PARAM_CHECK(ret == 0, return ret, "Invalid value %s %s", name, value);
|
||||
//PARAM_LOGI("WriteParamWithCheck node %p", node);
|
||||
if (node != NULL && node->dataIndex != 0) {
|
||||
return UpdateParam(workSpace, &node->dataIndex, name, value);
|
||||
}
|
||||
@@ -228,13 +223,12 @@ int ReadParamWithCheck(ParamWorkSpace *workSpace, const char *name, ParamHandle
|
||||
*handle = 0;
|
||||
// 取最长匹配
|
||||
TrieDataNode *paramInfo = FindTrieDataNode(&workSpace->paramSpace, name, strlen(name), 1);
|
||||
int ret = CanReadParam(workSpace, paramInfo == NULL ? 0 : paramInfo->labelIndex, name);
|
||||
int ret = CanReadParam(workSpace, (paramInfo == NULL) ? 0 : paramInfo->labelIndex, name);
|
||||
PARAM_CHECK(ret == 0, return ret, "Permission to read param %s", name);
|
||||
|
||||
// 查找结点
|
||||
TrieDataNode *node = FindTrieDataNode(&workSpace->paramSpace, name, strlen(name), 0);
|
||||
if (node != NULL && node->dataIndex != 0) {
|
||||
//PARAM_LOGI("ReadParamWithCheck trie %p dataIndex %u name %s", node, node->dataIndex, name);
|
||||
*handle = node->dataIndex;
|
||||
return 0;
|
||||
}
|
||||
@@ -296,7 +290,7 @@ int CheckControlParamPerms(ParamWorkSpace *workSpace,
|
||||
PARAM_CHECK(srcLabel != NULL && name != NULL && value != NULL,
|
||||
return PARAM_CODE_INVALID_PARAM, "Invalid param");
|
||||
|
||||
char * ctrlName[] = {
|
||||
char *ctrlName[] = {
|
||||
"ctl.start", "ctl.stop", "ctl.restart"
|
||||
};
|
||||
size_t size1 = strlen("ctl.") + strlen(value);
|
||||
@@ -318,7 +312,7 @@ int CheckControlParamPerms(ParamWorkSpace *workSpace,
|
||||
legacyName[n] = '\0';
|
||||
|
||||
TrieDataNode *node = FindTrieDataNode(&workSpace->paramSpace, legacyName, strlen(legacyName), 1);
|
||||
int ret = CheckMacPerms(workSpace, srcLabel, legacyName, node == NULL ? 0 : node->labelIndex);
|
||||
int ret = CheckMacPerms(workSpace, srcLabel, legacyName, (node == NULL) ? 0 : node->labelIndex);
|
||||
if (ret == 0) {
|
||||
free(legacyName);
|
||||
return 0;
|
||||
@@ -330,7 +324,7 @@ int CheckControlParamPerms(ParamWorkSpace *workSpace,
|
||||
PARAM_CHECK(n > 0, free(legacyName); return PARAM_CODE_INVALID_PARAM, "Failed to snprintf value");
|
||||
|
||||
TrieDataNode *node = FindTrieDataNode(&workSpace->paramSpace, name, strlen(name), 1);
|
||||
int ret = CheckMacPerms(workSpace, srcLabel, name, node == NULL ? 0 : node->labelIndex);
|
||||
int ret = CheckMacPerms(workSpace, srcLabel, name, (node == NULL) ? 0 : node->labelIndex);
|
||||
free(legacyName);
|
||||
return ret;
|
||||
}
|
||||
@@ -369,7 +363,10 @@ int CheckParamName(const char *name, int info)
|
||||
|
||||
int CheckParamValue(WorkSpace *workSpace, const TrieDataNode *node, const char *name, const char *value)
|
||||
{
|
||||
if (IS_READY_ONLY(name)) {
|
||||
if (node == NULL || name == NULL || value == NULL) {
|
||||
return PARAM_CODE_INVALID_VALUE;
|
||||
}
|
||||
if (strncmp((name), "ro.", strlen("ro.")) == 0) {
|
||||
if (node != NULL && node->dataIndex != 0) {
|
||||
PARAM_LOGE("Read-only param was already set %s", name);
|
||||
return PARAM_CODE_READ_ONLY_PROPERTY;
|
||||
@@ -397,7 +394,7 @@ int CheckMacPerms(ParamWorkSpace *workSpace,
|
||||
} else {
|
||||
ret = selinux_check_access(srcLabel, "u:object_r:default_prop:s0", "param_service", "set", &auditData);
|
||||
}
|
||||
return ret == 0 ? 0 : PARAM_CODE_PERMISSION_DENIED;
|
||||
return ((ret == 0) ? 0 : PARAM_CODE_PERMISSION_DENIED);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
@@ -409,11 +406,11 @@ int CanWriteParam(ParamWorkSpace *workSpace,
|
||||
PARAM_CHECK(workSpace != NULL && name != NULL && value != NULL && srcLabel != NULL,
|
||||
return PARAM_CODE_INVALID_PARAM, "Invalid param");
|
||||
|
||||
if (strncmp(name, "ctl.", strlen("ctl.")) == 0) { // 处理ctrl TODO
|
||||
if (strncmp(name, "ctl.", strlen("ctl.")) == 0) {
|
||||
return CheckControlParamPerms(workSpace, srcLabel, name, value);
|
||||
}
|
||||
|
||||
int ret = CheckMacPerms(workSpace, srcLabel, name, node == NULL ? 0 : node->labelIndex);
|
||||
int ret = CheckMacPerms(workSpace, srcLabel, name, (node == NULL) ? 0 : node->labelIndex);
|
||||
PARAM_CHECK(ret == 0, return ret, "SELinux permission check failed");
|
||||
return 0;
|
||||
}
|
||||
@@ -425,7 +422,11 @@ int CanReadParam(ParamWorkSpace *workSpace, u_int32_t labelIndex, const char *na
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
ParamAuditData auditData;
|
||||
auditData.name = name;
|
||||
UserCred cr = {.pid = 0, .uid = 0, .gid = 0};
|
||||
UserCred cr = {
|
||||
.pid = 0,
|
||||
.uid = 0,
|
||||
.gid = 0
|
||||
};
|
||||
auditData.cr = &cr;
|
||||
|
||||
int ret = 0;
|
||||
@@ -433,9 +434,9 @@ int CanReadParam(ParamWorkSpace *workSpace, u_int32_t labelIndex, const char *na
|
||||
if (node != 0) { // 已经存在label
|
||||
ret = selinux_check_access(&workSpace->context, node->key, "param_service", "read", &auditData);
|
||||
} else {
|
||||
ret = selinux_check_access(&workSpace->context, "selinux_check_access", "file", "read", &auditData);
|
||||
ret = selinux_check_access(&workSpace->context, "selinux_check_access", "file", "read", &auditData);
|
||||
}
|
||||
return ret == 0 ? 0 : PARAM_CODE_PERMISSION_DENIED;
|
||||
return (ret == 0) ? 0 : PARAM_CODE_PERMISSION_DENIED;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@@ -19,15 +19,14 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "init_utils.h"
|
||||
#include "sys_param.h"
|
||||
#include "param_manager.h"
|
||||
|
||||
@@ -85,7 +84,7 @@ int InitWorkSpace_(WorkSpace *workSpace, int mode, int prot, u_int32_t spaceSize
|
||||
PARAM_LOGD("InitWorkSpace %s ", workSpace->fileName);
|
||||
CheckAndCreateDir(workSpace->fileName);
|
||||
|
||||
int fd = open(workSpace->fileName, mode, 00777); //0444);
|
||||
int fd = open(workSpace->fileName, mode, 00777);
|
||||
PARAM_CHECK(fd >= 0, return PARAM_CODE_INVALID_NAME,
|
||||
"Open file %s fail error %s", workSpace->fileName, strerror(errno));
|
||||
|
||||
@@ -175,7 +174,7 @@ TrieNode *GetTrieNode(WorkSpace *workSpace, NODE_INDEX *index)
|
||||
if (index == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
u_int32_t offset = *index; // atomic_load_explicit(¤t->children, memory_order_relaxed);
|
||||
u_int32_t offset = *index;
|
||||
if (offset == 0 || offset > workSpace->area->dataSize) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -194,7 +193,6 @@ u_int32_t GetTrieNodeOffset(WorkSpace *workSpace, const TrieNode *current)
|
||||
|
||||
void SaveIndex(NODE_INDEX *index, u_int32_t offset)
|
||||
{
|
||||
// atomic_store_explicit(¤t->children, new_offset, memory_order_release);
|
||||
*index = offset;
|
||||
}
|
||||
|
||||
@@ -246,7 +244,7 @@ TrieDataNode *AddTrieDataNode(WorkSpace *workSpace, const char *key, u_int32_t k
|
||||
if (!subKeyLen) {
|
||||
return NULL;
|
||||
}
|
||||
u_int32_t offset = subKey == NULL ? strlen(key) : subKey - key;
|
||||
u_int32_t offset = ((subKey == NULL) ? strlen(key) : (subKey - key));
|
||||
|
||||
if (current->child != 0) { // 如果child存在,则检查是否匹配
|
||||
TrieDataNode *next = (TrieDataNode*)GetTrieNode(workSpace, ¤t->child);
|
||||
@@ -344,7 +342,7 @@ TrieDataNode *FindTrieDataNode(WorkSpace *workSpace, const char *key, u_int32_t
|
||||
if (!subKeyLen) {
|
||||
return matchPrefix ? matchNode : NULL;
|
||||
}
|
||||
u_int32_t offset = subKey == NULL ? strlen(key) : subKey - key;
|
||||
u_int32_t offset = ((subKey == NULL) ? strlen(key) : (subKey - key));
|
||||
|
||||
if (current->child != 0) { // 如果child存在,则检查是否匹配
|
||||
TrieDataNode *next = (TrieDataNode*)GetTrieNode(workSpace, ¤t->child);
|
||||
@@ -462,7 +460,6 @@ u_int32_t AddData(WorkSpace *workSpace, const char *key, u_int32_t keyLen, const
|
||||
realLen += keyLen + PARAM_VALUE_LEN_MAX;
|
||||
}
|
||||
realLen = (realLen + 0x03) & (~0x03);
|
||||
//PARAM_LOGI("AddData realLen %u %u %u", realLen, keyLen, valueLen);
|
||||
PARAM_CHECK((workSpace->area->currOffset + realLen) < workSpace->area->dataSize, return 0,
|
||||
"Failed to allocate currOffset %d, dataSize %d", workSpace->area->currOffset, workSpace->area->dataSize);
|
||||
|
||||
@@ -478,7 +475,6 @@ u_int32_t AddData(WorkSpace *workSpace, const char *key, u_int32_t keyLen, const
|
||||
node->data[keyLen + 1 + valueLen] = '\0';
|
||||
u_int32_t offset = workSpace->area->currOffset;
|
||||
workSpace->area->currOffset += realLen;
|
||||
//PARAM_LOGI("AddData node %p %u %d", node, offset, gettid());
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,6 @@ static int ProcessParamTraversal(WorkSpace *workSpace, TrieNode *node, void *coo
|
||||
}
|
||||
ret = GetDataValue(entry, persistContext->buffer + MAX_BUFF, MAX_BUFF);
|
||||
if (ret == 0) { // 只支持新建
|
||||
//PARAM_LOGI("Insert new persist param from normal param %s %s",
|
||||
// persistContext->buffer, persistContext->buffer + MAX_BUFF);
|
||||
ret = AddParam(persistContext->persistWorkSpace, persistContext->buffer, persistContext->buffer + MAX_BUFF);
|
||||
}
|
||||
PARAM_CHECK(ret == 0, return ret, "Failed to add persist param");
|
||||
@@ -82,8 +80,6 @@ static int ProcessPersistPropertTraversal(WorkSpace *workSpace, TrieNode *node,
|
||||
PARAM_CHECK(ret == 0, return ret, "GetDataName failed");
|
||||
ret = GetDataValue(entry, persistContext->buffer + MAX_BUFF, MAX_BUFF);
|
||||
if (ret == 0) {
|
||||
//PARAM_LOGI("update normal param %s %s from persist param %u",
|
||||
// persistContext->buffer, persistContext->buffer + MAX_BUFF, current->dataIndex);
|
||||
ret = WriteParam(persistContext->workSpace, persistContext->buffer, persistContext->buffer + MAX_BUFF);
|
||||
}
|
||||
PARAM_CHECK(ret == 0, return ret, "Failed to add persist param");
|
||||
|
||||
@@ -109,7 +109,7 @@ static int ProcessParamSet(RequestMsg *msg)
|
||||
PARAM_CHECK(msg != NULL, return PARAM_CODE_INVALID_PARAM, "Failed to check param");
|
||||
|
||||
SubStringInfo info[3];
|
||||
int ret = GetSubStringInfo(msg->content, msg->contentSize, '=', info, sizeof(info)/sizeof(info[0]));
|
||||
int ret = GetSubStringInfo(msg->content, msg->contentSize, '=', info, sizeof(info)/sizeof(info[0]));
|
||||
PARAM_CHECK(ret >= 2, return ret, "Failed to get name from content %s", msg->content);
|
||||
|
||||
PARAM_LOGD("ProcessParamSet name %s value: %s", info[0].value, info[1].value);
|
||||
|
||||
@@ -174,7 +174,7 @@ static int ComputeSubCondition(LogicCalculator *calculator, LogicData *data, con
|
||||
u_int32_t len = SUPPORT_DATA_BUFFER_MAX;
|
||||
ret = SystemReadParam(calculator->conditionName, calculator->readContent, &len);
|
||||
if (ret == 0 && (strcmp(calculator->conditionContent, "*") == 0 ||
|
||||
strcmp(calculator->conditionContent, calculator->readContent) == 0)) {
|
||||
strcmp(calculator->conditionContent, calculator->readContent) == 0)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,14 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "init_cmds.h"
|
||||
#include "init_utils.h"
|
||||
#include "trigger_checker.h"
|
||||
|
||||
#define LABEL "Trigger"
|
||||
@@ -94,7 +93,7 @@ u_int32_t AddCommand(TriggerWorkSpace *workSpace, TriggerNode *trigger, const ch
|
||||
{
|
||||
PARAM_CHECK(workSpace != NULL && trigger != NULL, return 0, "list is null");
|
||||
u_int32_t size = sizeof(CommandNode) + strlen(cmdName) + 1;
|
||||
size += (content == NULL) ? 1 : strlen(content) + 1;
|
||||
size += ((content == NULL) ? 1 : (strlen(content) + 1));
|
||||
size = (size + 0x03) & (~0x03);
|
||||
PARAM_CHECK((workSpace->area->currOffset + size) < workSpace->area->dataSize,
|
||||
return 0, "Not enough memory for cmd %u %u", size, workSpace->area->currOffset);
|
||||
@@ -148,7 +147,7 @@ u_int32_t AddTrigger(TriggerWorkSpace *workSpace, int type, const char *name, co
|
||||
if (type == TRIGGER_BOOT && condition == NULL) {
|
||||
tmpCond = name;
|
||||
}
|
||||
u_int32_t conditionSize = (tmpCond == NULL) ? 1 : strlen(tmpCond) + 1 + CONDITION_EXTEND_LEN;
|
||||
u_int32_t conditionSize = ((tmpCond == NULL) ? 1 : (strlen(tmpCond) + 1 + CONDITION_EXTEND_LEN));
|
||||
conditionSize = (conditionSize + 0x03) & (~0x03);
|
||||
PARAM_CHECK((workSpace->area->currOffset + sizeof(TriggerNode) + conditionSize) < workSpace->area->dataSize,
|
||||
return -1, "Not enough memory for cmd");
|
||||
@@ -252,7 +251,6 @@ int ParseTrigger(TriggerWorkSpace *workSpace, cJSON *triggerItem)
|
||||
} else {
|
||||
offset = AddCommand(workSpace, trigger, matchCmd, cmdLineStr + matchLen);
|
||||
}
|
||||
//PARAM_LOGE("AddCommand %u %s %u", offset, cmdLineStr, workSpace->area->currOffset);
|
||||
PARAM_CHECK(offset > 0, continue, "Failed to add command %s", cmdLineStr);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -44,7 +44,6 @@ static int DoCmdExecute(TriggerNode *trigger, const char *cmdName, const char *c
|
||||
|
||||
static int DoTiggerCheckResult(TriggerNode *trigger, u_int32_t triggerIndex)
|
||||
{
|
||||
// 已经在队列中了,则不执行 TODO
|
||||
if (TRIGGER_NODE_IN_QUEUE(trigger)) {
|
||||
PARAM_LOGI("DoTiggerExecute trigger %s has been waiting execute", trigger->name);
|
||||
return 0;
|
||||
|
||||
@@ -112,7 +112,7 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
|
||||
return SERVICE_FAILURE;
|
||||
}
|
||||
}
|
||||
int ret = i == curServ->servPerm.capsCnt ? SERVICE_SUCCESS : SERVICE_FAILURE;
|
||||
int ret = ((i == curServ->servPerm.capsCnt) ? SERVICE_SUCCESS : SERVICE_FAILURE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,6 @@ void ParseAllImports(cJSON *root)
|
||||
free(cfgFile);
|
||||
cfgFile = NULL;
|
||||
}
|
||||
INIT_LOGD("parse import file done");
|
||||
INIT_LOGD("parse import file done");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
#define CMDS_ARR_NAME_IN_JSON "cmds"
|
||||
#define MAX_JOBS_COUNT 100
|
||||
|
||||
// static const char* g_supportedJobs[] = {
|
||||
// "pre-init",
|
||||
// "init",
|
||||
// "post-init",
|
||||
// };
|
||||
|
||||
static Job* g_jobs = NULL;
|
||||
static int g_jobCnt = 0;
|
||||
|
||||
@@ -168,8 +162,6 @@ void DoJob(const char* jobName)
|
||||
for (int j = 0; j < g_jobs[i].cmdLinesCnt; ++j) {
|
||||
DoCmd(&(cmdLines[j]));
|
||||
}
|
||||
// Walk through all jobs
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ static void ParseInitCfgContents(cJSON *root)
|
||||
INIT_LOGE("ParseInitCfgContents root is NULL");
|
||||
return;
|
||||
}
|
||||
// parse services
|
||||
// parse services
|
||||
ParseAllServices(root);
|
||||
#ifdef OHOS_LITE
|
||||
// parse jobs
|
||||
|
||||
@@ -227,6 +227,5 @@ void DoReboot(const char *value)
|
||||
INIT_LOGE("DoReboot value = %s, error.", value);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ int ServiceStart(Service *service)
|
||||
continue;
|
||||
}
|
||||
if (fwrite(pidString, 1, strlen(pidString), fd) != strlen(pidString)) {
|
||||
INIT_LOGE("start service writepid error.file:%s pid:%s", service->writepidFiles[i], pidString);
|
||||
INIT_LOGE("start service writepid error.file:%s pid:%s", service->writepidFiles[i], pidString);
|
||||
}
|
||||
free(realPath);
|
||||
realPath = NULL;
|
||||
|
||||
@@ -158,7 +158,6 @@ static int IsForbidden(const char* fieldStr)
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: move this function to common files
|
||||
static cJSON* GetArrItem(const cJSON* fileRoot, int* arrSize, const char* arrName)
|
||||
{
|
||||
cJSON* arrItem = cJSON_GetObjectItemCaseSensitive(fileRoot, arrName);
|
||||
@@ -308,7 +307,7 @@ static int GetGidArray(const cJSON *curArrItem, Service *curServ) // gid
|
||||
}
|
||||
curServ->servPerm.gIDArray[i] = gID;
|
||||
}
|
||||
int ret = i == gIDCnt ? SERVICE_SUCCESS : SERVICE_FAILURE;
|
||||
int ret = ((i == gIDCnt) ? SERVICE_SUCCESS : SERVICE_FAILURE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -486,9 +485,9 @@ static int ParseServiceSocket(char **opt, const int optNum, struct ServiceSocket
|
||||
return -1;
|
||||
}
|
||||
sockopt->type =
|
||||
strncmp(opt[SERVICE_SOCK_TYPE], "stream", strlen(opt[SERVICE_SOCK_TYPE])) == 0 ? SOCK_STREAM :
|
||||
(strncmp(opt[SERVICE_SOCK_TYPE], "dgram", strlen(opt[SERVICE_SOCK_TYPE])) == 0 ? SOCK_DGRAM : SOCK_SEQPACKET);
|
||||
|
||||
((strncmp(opt[SERVICE_SOCK_TYPE], "stream", strlen(opt[SERVICE_SOCK_TYPE])) == 0) ? SOCK_STREAM :
|
||||
((strncmp(opt[SERVICE_SOCK_TYPE], "dgram", strlen(opt[SERVICE_SOCK_TYPE])) == 0) ? SOCK_DGRAM :
|
||||
SOCK_SEQPACKET));
|
||||
if (opt[SERVICE_SOCK_PERM] == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -512,7 +511,8 @@ static int ParseServiceSocket(char **opt, const int optNum, struct ServiceSocket
|
||||
if (opt[SERVICE_SOCK_SETOPT] == NULL) {
|
||||
return -1;
|
||||
}
|
||||
sockopt->passcred = strncmp(opt[SERVICE_SOCK_SETOPT], "passcred", strlen(opt[SERVICE_SOCK_SETOPT])) == 0 ? true : false;
|
||||
sockopt->passcred = (strncmp(opt[SERVICE_SOCK_SETOPT], "passcred",
|
||||
strlen(opt[SERVICE_SOCK_SETOPT])) == 0) ? true : false;
|
||||
if (opt[SERVICE_SOCK_NAME] == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -717,8 +717,8 @@ void ParseAllServices(const cJSON* fileRoot)
|
||||
continue;
|
||||
} else {
|
||||
INIT_LOGD("ParseAllServices ParseAllServices Service[%d] name=%s, uid=%d, critical=%d, disabled=%d",
|
||||
i, tmp[i].name, tmp[i].servPerm.uID, tmp[i].attribute & SERVICE_ATTR_CRITICAL ? 1 : 0,
|
||||
tmp[i].attribute & SERVICE_ATTR_DISABLED ? 1 : 0);
|
||||
i, tmp[i].name, tmp[i].servPerm.uID, (tmp[i].attribute & SERVICE_ATTR_CRITICAL) ? 1 : 0,
|
||||
(tmp[i].attribute & SERVICE_ATTR_DISABLED) ? 1 : 0);
|
||||
}
|
||||
if (GetServiceSocket(curItem, &tmp[i]) != SERVICE_SUCCESS) {
|
||||
if (tmp[i].socketCfg != NULL) {
|
||||
@@ -828,4 +828,3 @@ void ReapServiceByPID(int pid)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ char* ReadFileToBuf(const char *configFile)
|
||||
|
||||
int SplitString(char *srcPtr, char **dstPtr, int maxNum)
|
||||
{
|
||||
if ((!srcPtr) || (!dstPtr)){
|
||||
if ((!srcPtr) || (!dstPtr)) {
|
||||
return -1;
|
||||
}
|
||||
char *buf = NULL;
|
||||
|
||||
+15
-15
@@ -224,27 +224,27 @@ static void Trigger(const char *path, int sockFd)
|
||||
DIR *dir = opendir(path);
|
||||
if (dir != NULL) {
|
||||
struct dirent *dirent = NULL;
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
if (dirent->d_name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
if (dirent->d_type == DT_DIR) {
|
||||
char pathBuffer[PATH_MAX];
|
||||
if (snprintf_s(pathBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, dirent->d_name) == -1) {
|
||||
continue;
|
||||
}
|
||||
Trigger(pathBuffer, sockFd);
|
||||
} else {
|
||||
if (!strcmp(dirent->d_name, "uevent")) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
if (dirent->d_name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
if (dirent->d_type == DT_DIR) {
|
||||
char pathBuffer[PATH_MAX];
|
||||
if (snprintf_s(pathBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, dirent->d_name) == -1) {
|
||||
continue;
|
||||
}
|
||||
Trigger(pathBuffer, sockFd);
|
||||
} else {
|
||||
if (!strcmp(dirent->d_name, "uevent")) {
|
||||
char ueventBuffer[PATH_MAX];
|
||||
if (snprintf_s(ueventBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, "uevent") == -1) {
|
||||
INIT_LOGW("Cannnot build uevent path under %s", path);
|
||||
continue;
|
||||
}
|
||||
DoTrigger(ueventBuffer, sockFd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ueventd_device_handler.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <stdbool.h>
|
||||
@@ -104,7 +105,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode,
|
||||
INIT_LOGE("Create path \" %s \" failed", devicePath);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
GetDeviceNodePermissions(deviceNode, &uid, &gid, &mode);
|
||||
mode |= isBlock ? S_IFBLK : S_IFCHR;
|
||||
dev_t dev = makedev(major, minor);
|
||||
@@ -120,7 +121,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode,
|
||||
if (symLinks) {
|
||||
CreateSymbolLinks(deviceNode, symLinks);
|
||||
}
|
||||
// No matter what result the symbol links returns,
|
||||
// No matter what result the symbol links returns,
|
||||
// as long as create device node done, just returns success.
|
||||
rc = 0;
|
||||
return rc;
|
||||
@@ -163,7 +164,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
|
||||
// For block device under one platform device.
|
||||
// check subsystem file under directory, see if it links to bus/platform.
|
||||
// For now, only support platform device.
|
||||
char sysPath[SYSPATH_SIZE] = {};
|
||||
char sysPath[SYSPATH_SIZE] = {};
|
||||
if (snprintf_s(sysPath, SYSPATH_SIZE, SYSPATH_SIZE - 1, "/sys%s", uevent->syspath) == -1) {
|
||||
INIT_LOGE("Failed to build sys path for device %s", uevent->syspath);
|
||||
return NULL;
|
||||
@@ -207,7 +208,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
|
||||
if (!INVALIDSTRING(uevent->partitionName)) {
|
||||
if (snprintf_s(links[linkNum], DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
|
||||
"/dev/block/platform/%s/by-name/%s", parent, uevent->partitionName) == -1) {
|
||||
INIT_LOGE("Failed to build link");
|
||||
INIT_LOGE("Failed to build link");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -270,7 +271,6 @@ static const char *GetDeviceName(char *sysPath, const char *deviceName)
|
||||
}
|
||||
if (deviceName != NULL && deviceName[0] != '\0') {
|
||||
// if device name reported by kernel includes '/', skip it.
|
||||
// TODO: use entire device name reported by kernel
|
||||
devName = basename((char *)deviceName);
|
||||
char *p = strrchr(deviceName, '/');
|
||||
if (p != NULL) { // device name includes slash
|
||||
@@ -381,10 +381,10 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent)
|
||||
}
|
||||
INIT_LOGD("HandleOtherDeviceEvent, devPath = %s, devName = %s", devPath, devName);
|
||||
|
||||
// For usb devices, should take care of it specially.
|
||||
// if usb devices report DEVNAME, just create device node.
|
||||
// otherwise, create deviceNode with bus number and device number.
|
||||
if (STRINGEQUAL(uevent->subsystem, "usb")) {
|
||||
// For usb devices, should take care of it specially.
|
||||
// if usb devices report DEVNAME, just create device node.
|
||||
// otherwise, create deviceNode with bus number and device number.
|
||||
if (STRINGEQUAL(uevent->subsystem, "usb")) {
|
||||
if (uevent->deviceName != NULL) {
|
||||
if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, "/dev/%s", uevent->deviceName) == -1) {
|
||||
INIT_LOGE("Make device file for device [%d : %d]", uevent->major, uevent->minor);
|
||||
@@ -396,19 +396,19 @@ void HandleOtherDeviceEvent(const struct Uevent *uevent)
|
||||
INIT_LOGE("usb device with invalid bus number or device number");
|
||||
return;
|
||||
}
|
||||
if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
|
||||
if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
|
||||
"/dev/bus/usb/%03d/%03d", uevent->busNum, uevent->devNum) == -1) {
|
||||
INIT_LOGE("Make usb device node for device [%d : %d]", uevent->busNum, uevent->devNum);
|
||||
INIT_LOGE("Make usb device node for device [%d : %d]", uevent->busNum, uevent->devNum);
|
||||
}
|
||||
}
|
||||
} else if (STARTSWITH(uevent->subsystem, "usb")) {
|
||||
// Other usb devies, do not handle it.
|
||||
return;
|
||||
} else {
|
||||
} else if (STARTSWITH(uevent->subsystem, "usb")) {
|
||||
// Other usb devies, do not handle it.
|
||||
return;
|
||||
} else {
|
||||
if (snprintf_s(deviceNode, DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1, "%s/%s", devPath, devName) == -1) {
|
||||
INIT_LOGE("Make device file for device [%d : %d]", uevent->major, uevent->minor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
HandleDeviceNode(uevent, deviceNode, false);
|
||||
}
|
||||
HandleDeviceNode(uevent, deviceNode, false);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,5 @@
|
||||
|
||||
void HandleFimwareDeviceEvent(const struct Uevent *uevent)
|
||||
{
|
||||
// TODO, implement it later.
|
||||
INIT_LOGI("Firmware handler not implemented yet.");
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ int ParseUeventConfig(char *buffer)
|
||||
callback = funcMapper[type].func;
|
||||
return 0;
|
||||
}
|
||||
return callback != NULL ? callback(p) : -1;
|
||||
return (callback != NULL) ? callback(p) : -1;
|
||||
}
|
||||
|
||||
static void DoUeventConfigParse(char *buffer)
|
||||
@@ -361,11 +361,11 @@ void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_
|
||||
*uid = config->uid;
|
||||
*gid = config->gid;
|
||||
*mode = config->mode;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
void ChangeSysAttributePermissions(const char *sysPath)
|
||||
@@ -380,7 +380,7 @@ void ChangeSysAttributePermissions(const char *sysPath)
|
||||
ForEachListEntry(&g_sysDevices, node) {
|
||||
config = ListEntry(node, struct SysUdevConf, list);
|
||||
if (STRINGEQUAL(config->sysPath, sysPath)) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ int UeventdSocketInit()
|
||||
addr.nl_groups = 0xffffffff;
|
||||
|
||||
sockfd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);
|
||||
|
||||
if (sockfd < 0) {
|
||||
INIT_LOGE("Create socket failed, err = %d", errno);
|
||||
return -1;
|
||||
|
||||
@@ -78,5 +78,5 @@ int StringToInt(const char *str, int defaultValue)
|
||||
}
|
||||
errno = 0;
|
||||
int value = strtoul(str, NULL, DECIMALISM);
|
||||
return errno != 0 ? defaultValue : value;
|
||||
return (errno != 0) ? defaultValue : value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user