!57 修改L2 init

Merge pull request !57 from 熊磊/init0715
This commit is contained in:
openharmony_ci 2021-07-15 10:24:11 +00:00 committed by Gitee
commit 852ef76ca3
25 changed files with 376 additions and 350 deletions

View File

@ -31,12 +31,12 @@ static int SendCmd(int cmd, unsigned long arg)
if (fd != -1) {
int ret = ioctl(fd, cmd, arg);
if (ret == -1) {
INIT_LOGE("[Init] [ERR] %s!\n", strerror(errno));
INIT_LOGE("[Init] [ERR] %s!", strerror(errno));
}
close(fd);
return ret;
}
INIT_LOGE("[Init] [ERR] %s!\n", strerror(errno));
INIT_LOGE("[Init] [ERR] %s!", strerror(errno));
return fd;
}
@ -56,7 +56,7 @@ int NotifyInit(unsigned long event)
int SystemInitStage(QuickstartStage stage)
{
if (stage >= QS_STAGE_LIMIT || stage < QS_STAGE1) {
INIT_LOGE("[Init] the stage(%d) is not expected!\n", stage);
INIT_LOGE("[Init] the stage(%d) is not expected!", stage);
return -1;
}
return SendCmd(QUICKSTART_STAGE(stage), 0);

View File

@ -28,20 +28,20 @@ int DoReboot(const char *cmdContent)
{
char value[MAX_REBOOT_VAUE_SIZE];
if (cmdContent == NULL) {
INIT_LOGE("DoReboot api error, cmdContent is NULL.\n");
INIT_LOGE("DoReboot api error, cmdContent is NULL.");
return -1;
}
int length = strlen(cmdContent);
if (length == 0 || length > MAX_REBOOT_VAUE_SIZE) {
INIT_LOGE("DoReboot api error, cmdContent = %s, length = %d.\n", cmdContent, length);
INIT_LOGE("DoReboot api error, cmdContent = %s, length = %d.", cmdContent, length);
return -1;
}
if (snprintf_s(value, MAX_REBOOT_NAME_SIZE, MAX_REBOOT_NAME_SIZE - 1, "%s%s", "reboot,", cmdContent) < 0) {
INIT_LOGE("DoReboot api error, MAX_REBOOT_NAME_SIZE is not enough\n");
INIT_LOGE("DoReboot api error, MAX_REBOOT_NAME_SIZE is not enough");
return -1;
}
if (SystemSetParameter("sys.powerctrl", value) != 0) {
INIT_LOGE("DoReboot Api SystemSetParameter error\n");
INIT_LOGE("DoReboot Api SystemSetParameter error");
return -1;
}
return 0;

View File

@ -38,10 +38,10 @@ static int GetControlFromEnv(char *path)
if (path == NULL) {
return -1;
}
INIT_LOGI("GetControlFromEnv path is %s \n", path);
INIT_LOGI("GetControlFromEnv path is %s ", path);
const char *val = getenv(path);
if (val == NULL) {
INIT_LOGE("GetControlFromEnv val is null %d\n", errno);
INIT_LOGE("GetControlFromEnv val is null %d", errno);
return -1;
}
errno = 0;
@ -49,9 +49,9 @@ static int GetControlFromEnv(char *path)
if (errno) {
return -1;
}
INIT_LOGI("GetControlFromEnv fd is %d \n", fd);
INIT_LOGI("GetControlFromEnv fd is %d ", fd);
if (fcntl(fd, F_GETFD) < 0) {
INIT_LOGE("GetControlFromEnv errno %d \n", errno);
INIT_LOGE("GetControlFromEnv errno %d ", errno);
return -1;
}
return fd;
@ -64,23 +64,23 @@ int GetControlSocket(const char *name)
}
char path[MAX_SOCKET_ENV_PREFIX_LEN] = {0};
snprintf(path, sizeof(path), OHOS_SOCKET_ENV_PREFIX"%s", name);
INIT_LOGI("GetControlSocket path is %s \n", path);
INIT_LOGI("GetControlSocket path is %s ", path);
int fd = GetControlFromEnv(path);
if (fd < 0) {
INIT_LOGE("GetControlFromEnv fail \n");
INIT_LOGE("GetControlFromEnv fail ");
return -1;
}
struct sockaddr_un addr;
socklen_t addrlen = sizeof(addr);
int ret = getsockname(fd, (struct sockaddr*)&addr, &addrlen);
if (ret < 0) {
INIT_LOGE("GetControlSocket errno %d \n", errno);
INIT_LOGE("GetControlSocket errno %d ", errno);
return -1;
}
char sockDir[MAX_SOCKET_DIR_LEN] = {0};
snprintf(sockDir, sizeof(sockDir), OHOS_SOCKET_DIR"/%s", name);
INIT_LOGI("sockDir %s \n", sockDir);
INIT_LOGI("addr.sun_path %s \n", addr.sun_path);
INIT_LOGI("sockDir %s ", sockDir);
INIT_LOGI("addr.sun_path %s ", addr.sun_path);
if (strncmp(sockDir, addr.sun_path, strlen(sockDir)) == 0) {
return fd;
}

View File

@ -31,6 +31,7 @@ if (defined(ohos_lite)) {
"src/init_service_socket.c",
"src/init_signal_handler.c",
"src/init_utils.c",
"log/init_log.c",
"src/main.c",
]
@ -41,16 +42,17 @@ if (defined(ohos_lite)) {
"//third_party/cJSON",
"//third_party/bounds_checking_function/include",
"//base/startup/syspara_lite/interfaces/kits",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
]
cflags = [ "-Wall" ]
deps = [
"//base/startup/init_lite/initsync:initsync",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/syspara_lite/frameworks/parameter:parameter",
"//build/lite/config/component/cJSON:cjson_shared",
"//third_party/bounds_checking_function:libsec_shared",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
]
ldflags = []
if (ohos_kernel_type == "liteos_a") {

View File

@ -28,7 +28,6 @@
}, {
"name" : "init",
"cmds" : [
"start console",
"copy /proc/cmdline /dev/urandom",
"copy /system/etc/prop.default /dev/urandom",
"symlink /proc/self/fd/0 /dev/stdin",
@ -183,7 +182,6 @@
"chown system system /sys/power/state",
"chown system system /sys/power/wakeup_count",
"chmod 0660 /sys/power/state",
"chmod 0666 /dev/binder",
"start logd",
"start servicemanager",
"start hwservicemanager",
@ -543,8 +541,8 @@
"write /proc/sys/kernel/perf_event_paranoid 3"
]
}, {
"name" : "param:ro.debuggable=1",
"condition" : "ro.debuggable=1",
"name" : "boot && param:ro.debuggable=1",
"condition" : "boot && ro.debuggable=1",
"cmds" : [
"chmod 0773 /data/misc/trace",
"chmod 0775 /data/misc/wmtrace",

View File

@ -14,6 +14,8 @@ if (defined(ohos_lite)) {
static_library("init_log") {
sources = [ "init_log.c" ]
public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
include_dirs = [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits" ]
deps = [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ]
}
} else {
import("//build/ohos.gni")

View File

@ -16,6 +16,9 @@
#include "init_log.h"
#include <errno.h>
#include <fcntl.h>
#ifdef OHOS_LITE
#include "hilog/log.h"
#endif
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@ -24,12 +27,11 @@
#include "securec.h"
#define UNUSED(x) (void)(x)
#define MAX_FORMAT_SIZE 1024
#define MAX_FORMAT_SIZE 2048
#define MAX_LOG_SIZE 2048
#define BASE_YEAR 1900
static InitLogLevel g_logLevel = INIT_INFO;
static const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
void SetLogLevel(InitLogLevel logLevel)
@ -37,6 +39,32 @@ void SetLogLevel(InitLogLevel logLevel)
g_logLevel = logLevel;
}
#ifdef OHOS_LITE
static LogLevel g_hiLogLevel = LOG_INFO;
void SetHiLogLevel(LogLevel logLevel)
{
g_hiLogLevel = logLevel;
}
void InitToHiLog(const char *tag, LogLevel logLevel, const char *fmt, ...)
{
if (logLevel < g_hiLogLevel) {
return;
}
va_list list;
va_start(list, fmt);
char tmpFmt[MAX_FORMAT_SIZE];
if (vsnprintf_s(tmpFmt, MAX_FORMAT_SIZE, MAX_FORMAT_SIZE - 1, fmt, list) == -1) {
va_end(list);
return;
}
(void)HiLogPrint(LOG_CORE, logLevel, LOG_DOMAIN, tag, "%{public}s", tmpFmt);
va_end(list);
return;
}
#endif
void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int line, const char *fmt, ...)
{
if (logLevel < g_logLevel) {
@ -46,8 +74,8 @@ void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int l
time_t logTime;
time(&logTime);
struct tm *t = gmtime(&logTime);
fprintf(stdout, "[%d-%d-%d %d:%d][pid=%d][%s:%d][%s][%s] ",
(t->tm_year + BASE_YEAR), (t->tm_mon + 1), t->tm_mday, t->tm_hour, t->tm_min,
fprintf(stdout, "[%d-%d-%d %d:%d:%d][pid=%d][%s:%d][%s][%s] ",
(t->tm_year + BASE_YEAR), (t->tm_mon + 1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,
getpid(), fileName, line, tag, LOG_LEVEL_STR[logLevel]);
va_list list;
@ -55,6 +83,7 @@ void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int l
vfprintf(stdout, fmt, list);
va_end(list);
fflush(stdout);
#if 0
int fd = open("/dev/kmsg", O_WRONLY | O_CLOEXEC | O_APPEND );
if (fd < 1) {

View File

@ -34,23 +34,38 @@ typedef enum InitLogLevel {
INIT_FATAL
} InitLogLevel;
#define __FILE_NAME__ (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
#ifndef INIT_LOG_TAG
#define INIT_LOG_TAG "[Init]"
#define INIT_LOG_TAG "Init"
#endif
#ifdef OHOS_LITE
#define INIT_LOGE(format, ...) printf("%s %d: "format, __FILE_NAME__, __LINE__, ##__VA_ARGS__)
#define INIT_LOGW(format, ...) printf("%s %d: "format, __FILE_NAME__, __LINE__, ##__VA_ARGS__)
#define INIT_LOGI(format, ...) printf("%s %d: "format, __FILE_NAME__, __LINE__, ##__VA_ARGS__)
#define INIT_LOGD(format, ...) printf("%s %d: "format, __FILE_NAME__, __LINE__, ##__VA_ARGS__)
#include "hilog/log.h"
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD000719
#define INIT_LOGD(fmt, ...) InitToHiLog(INIT_LOG_TAG, LOG_DEBUG, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
#define INIT_LOGI(fmt, ...) InitToHiLog(INIT_LOG_TAG, LOG_INFO, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
#define INIT_LOGW(fmt, ...) InitToHiLog(INIT_LOG_TAG, LOG_WARN, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
#define INIT_LOGE(fmt, ...) InitToHiLog(INIT_LOG_TAG, LOG_ERROR, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
#define INIT_LOGF(fmt, ...) InitToHiLog(INIT_LOG_TAG, LOG_FATAL, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
#define STARTUP_LOGI(LABEL, fmt, ...) InitToHiLog(LABEL, LOG_INFO, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
#define STARTUP_LOGE(LABEL, fmt, ...) InitToHiLog(LABEL, LOG_ERROR, "%s : "fmt, (__FUNCTION__), ##__VA_ARGS__)
void InitToHiLog(const char *tag, LogLevel logLevel, const char *fmt, ...);
void SetHiLogLevel(LogLevel logLevel);
#else
#define INIT_LOGD(format, ...) InitLog(INIT_LOG_TAG, INIT_DEBUG, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
#define INIT_LOGI(format, ...) InitLog(INIT_LOG_TAG, INIT_INFO, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
#define INIT_LOGW(format, ...) InitLog(INIT_LOG_TAG, INIT_WARN, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
#define INIT_LOGE(format, ...) InitLog(INIT_LOG_TAG, INIT_ERROR, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
#define INIT_LOGF(format, ...) InitLog(INIT_LOG_TAG, INIT_FATAL, (__FILE_NAME__), (__LINE__), format, ##__VA_ARGS__)
#define __FILE_NAME__ (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
#define INIT_LOGD(fmt, ...) InitLog(INIT_LOG_TAG, INIT_DEBUG, (__FILE_NAME__), (__LINE__), fmt"\n", ##__VA_ARGS__)
#define INIT_LOGI(fmt, ...) InitLog(INIT_LOG_TAG, INIT_INFO, (__FILE_NAME__), (__LINE__), fmt"\n", ##__VA_ARGS__)
#define INIT_LOGW(fmt, ...) InitLog(INIT_LOG_TAG, INIT_WARN, (__FILE_NAME__), (__LINE__), fmt"\n", ##__VA_ARGS__)
#define INIT_LOGE(fmt, ...) InitLog(INIT_LOG_TAG, INIT_ERROR, (__FILE_NAME__), (__LINE__), fmt"\n", ##__VA_ARGS__)
#define INIT_LOGF(fmt, ...) InitLog(INIT_LOG_TAG, INIT_FATAL, (__FILE_NAME__), (__LINE__), fmt"\n", ##__VA_ARGS__)
#define STARTUP_LOGI(LABEL, fmt, ...) InitLog(LABEL, INIT_INFO, (__FILE_NAME__), (__LINE__), fmt "\n", ##__VA_ARGS__)
#define STARTUP_LOGE(LABEL, fmt, ...) InitLog(LABEL, INIT_ERROR, (__FILE_NAME__), (__LINE__), fmt "\n", ##__VA_ARGS__)
void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int line, const char *fmt, ...);
void SetLogLevel(InitLogLevel logLevel);
@ -67,27 +82,6 @@ void SetLogLevel(InitLogLevel logLevel);
statement; \
}
#ifdef SUPPORT_HILOG
#include "hilog/log.h"
static constexpr OHOS::HiviewDFX::HiLogLabel STARTUP_LABEL = {LOG_CORE, 0, "STARTUP"};
InitLogLevel level_;
int JudgeLevel(const InitLogLevel level) { return return; }
#define STARTUP_LOG(LEVEL, LABEL, Level, fmt, ...) \
InitLog("[Init]", LEVEL, __FILE_NAME__, (__LINE__), fmt, ##__VA_ARGS__); \
if (JudgeLevel(InitLogLevel::LEVEL)) \
OHOS::HiviewDFX::HiLog::Level(STARTUP_LABEL, "[%{public}s(%{public}d)] " fmt, \
__FILE_NAME__, __LINE__, ##__VA_ARGS__)
#else
#define STARTUP_LOG(LEVEL, LABEL, Level, fmt, ...) \
InitLog(LABEL, LEVEL, (__FILE_NAME__), (__LINE__), fmt "\n", ##__VA_ARGS__)
#endif
#define STARTUP_LOGI(LABEL, fmt, ...) STARTUP_LOG(INIT_INFO, LABEL, Info, fmt, ##__VA_ARGS__)
#define STARTUP_LOGE(LABEL, fmt, ...) STARTUP_LOG(INIT_ERROR, LABEL, Error, fmt, ##__VA_ARGS__)
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -224,7 +224,7 @@ int StartParamService()
ret = uv_pipe_bind(&pipeServer, PIPE_NAME);
PARAM_CHECK(ret == 0, return ret, "Failed to uv_pipe_bind %d %s", ret, uv_err_name(ret));
ret = chmod(PIPE_NAME, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
PARAM_CHECK(ret == 0, return ret, "Failed to chmod %s, err %d. \n", PIPE_NAME, errno);
PARAM_CHECK(ret == 0, return ret, "Failed to chmod %s, err %d. ", PIPE_NAME, errno);
ret = uv_listen((uv_stream_t*)&pipeServer, SOMAXCONN, OnConnection);
PARAM_CHECK(ret == 0, return ret, "Failed to uv_listen %d %s", ret, uv_err_name(ret));

View File

@ -32,25 +32,25 @@
void MountBasicFs()
{
if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755") != 0) {
INIT_LOGE("Mount tmpfs failed. %s\n", strerror(errno));
INIT_LOGE("Mount tmpfs failed. %s", strerror(errno));
}
#ifndef __LITEOS__
if (mkdir("/dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
INIT_LOGE("mkdir /dev/pts failed. %s\n", strerror(errno));
INIT_LOGE("mkdir /dev/pts failed. %s", strerror(errno));
}
if (mount("devpts", "/dev/pts", "devpts", 0, NULL) != 0) {
INIT_LOGE("Mount devpts failed. %s\n", strerror(errno));
INIT_LOGE("Mount devpts failed. %s", strerror(errno));
}
#endif
if (mount("proc", "/proc", "proc", 0, "hidepid=2") != 0) {
INIT_LOGE("Mount procfs failed. %s\n", strerror(errno));
INIT_LOGE("Mount procfs failed. %s", strerror(errno));
}
if (mount("sysfs", "/sys", "sysfs", 0, NULL) != 0) {
INIT_LOGE("Mount sysfs failed. %s\n", strerror(errno));
INIT_LOGE("Mount sysfs failed. %s", strerror(errno));
}
#ifndef __LITEOS__
if (mount("selinuxfs", "/sys/fs/selinux", "selinuxfs", 0, NULL) != 0) {
INIT_LOGE("Mount selinuxfs failed. %s\n", strerror(errno));
INIT_LOGE("Mount selinuxfs failed. %s", strerror(errno));
}
#endif
}
@ -58,17 +58,17 @@ void MountBasicFs()
void CreateDeviceNode()
{
if (mknod("/dev/kmsg", S_IFCHR | DEFAULT_NO_AUTHORITY_MODE, makedev(1, DEVICE_ID_ELEVNTH)) != 0) {
INIT_LOGE("Create /dev/kmsg device node failed. %s\n", strerror(errno));
INIT_LOGE("Create /dev/kmsg device node failed. %s", strerror(errno));
}
if (mknod("/dev/null", S_IFCHR | DEFAULT_RW_MODE, makedev(1, DEVICE_ID_THIRD)) != 0) {
INIT_LOGE("Create /dev/null device node failed. %s\n", strerror(errno));
INIT_LOGE("Create /dev/null device node failed. %s", strerror(errno));
}
if (mknod("/dev/random", S_IFCHR | DEFAULT_RW_MODE, makedev(1, DEVICE_ID_EIGHTH)) != 0) {
INIT_LOGE("Create /dev/random device node failed. %s\n", strerror(errno));
INIT_LOGE("Create /dev/random device node failed. %s", strerror(errno));
}
if (mknod("/dev/urandom", S_IFCHR | DEFAULT_RW_MODE, makedev(1, DEVICE_ID_NINTH)) != 0) {
INIT_LOGE("Create /dev/urandom device node failed. %s\n", strerror(errno));
INIT_LOGE("Create /dev/urandom device node failed. %s", strerror(errno));
}
}
@ -76,12 +76,12 @@ int MakeSocketDir(const char *path, mode_t mode)
{
int rc = mkdir("/dev/unix/", mode);
if (rc < 0 && errno != EEXIST) {
INIT_LOGE("Create %s failed. %d\n", path, errno);
INIT_LOGE("Create %s failed. %d", path, errno);
return -1;
}
rc = mkdir("/dev/unix/socket/", mode);
if (rc < 0 && errno != EEXIST) {
INIT_LOGE("Create %s failed. %d\n", path, errno);
INIT_LOGE("Create %s failed. %d", path, errno);
return -1;
}
return rc;

View File

@ -32,7 +32,7 @@ void RebootSystem()
{
int ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("reboot failed! syscall ret %d, err %d.\n", ret, errno);
INIT_LOGE("reboot failed! syscall ret %d, err %d.", ret, errno);
}
}
@ -40,7 +40,7 @@ int KeepCapability()
{
#if ((defined __LINUX__) || (!defined OHOS_LITE))
if (prctl(PR_SET_SECUREBITS, SECBIT_NO_SETUID_FIXUP | SECBIT_NO_SETUID_FIXUP_LOCKED)) {
INIT_LOGE("prctl PR_SET_SECUREBITS failed: %d\n", errno);
INIT_LOGE("prctl PR_SET_SECUREBITS failed: %d", errno);
return -1;
}
#endif
@ -51,7 +51,7 @@ int SetAmbientCapability(int cap)
{
#if ((defined __LINUX__) || (!defined OHOS_LITE))
if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0)) {
INIT_LOGE("prctl PR_CAP_AMBIENT failed: %d\n", errno);
INIT_LOGE("prctl PR_CAP_AMBIENT failed: %d", errno);
return -1;
}
#endif
@ -63,15 +63,15 @@ void ExecuteRcs()
#if (defined __LINUX__) && (defined NEED_EXEC_RCS_LINUX)
pid_t retPid = fork();
if (retPid < 0) {
INIT_LOGE("ExecuteRcs, fork failed! err %d.\n", errno);
INIT_LOGE("ExecuteRcs, fork failed! err %d.", errno);
return;
}
// child process
if (retPid == 0) {
INIT_LOGI("ExecuteRcs, child process id %d.\n", getpid());
INIT_LOGI("ExecuteRcs, child process id %d.", getpid());
if (execle("/bin/sh", "sh", "/etc/init.d/rcS", NULL, NULL) != 0) {
INIT_LOGE("ExecuteRcs, execle failed! err %d.\n", errno);
INIT_LOGE("ExecuteRcs, execle failed! err %d.", errno);
}
_exit(0x7f); // 0x7f: user specified
}
@ -79,14 +79,14 @@ void ExecuteRcs()
// init process
sem_t sem;
if (sem_init(&sem, 0, 0) != 0) {
INIT_LOGE("ExecuteRcs, sem_init failed, err %d.\n", errno);
INIT_LOGE("ExecuteRcs, sem_init failed, err %d.", errno);
return;
}
SignalRegWaitSem(retPid, &sem);
// wait until rcs process exited
if (sem_wait(&sem) != 0) {
INIT_LOGE("ExecuteRcs, sem_wait failed, err %d.\n", errno);
INIT_LOGE("ExecuteRcs, sem_wait failed, err %d.", errno);
}
#endif
}

View File

@ -85,7 +85,7 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
for (; i < curServ->servPerm.capsCnt; ++i) {
if (cJSON_GetArrayItem(filedJ, i) == NULL || !cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))
|| strlen(cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))) <= 0) { // check all errors
INIT_LOGE("service=%s, parse item[%d] as string, error.\n", curServ->name, i);
INIT_LOGE("service=%s, parse item[%d] as string, error.", curServ->name, i);
break;
}
char* fieldStr = cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i));
@ -99,12 +99,12 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
if (j < mapSize) {
curServ->servPerm.caps[i] = g_capStrCapNum[j].CapNum;
} else {
INIT_LOGE("service=%s, CapbilityName=%s, error.\n", curServ->name, fieldStr);
INIT_LOGE("service=%s, CapbilityName=%s, error.", curServ->name, fieldStr);
break;
}
if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) {
// resources will be released by function: ReleaseServiceMem
INIT_LOGE("service=%s, cap = %d, error.\n", curServ->name, curServ->servPerm.caps[i]);
INIT_LOGE("service=%s, cap = %d, error.", curServ->name, curServ->servPerm.caps[i]);
return SERVICE_FAILURE;
}
}
@ -121,7 +121,7 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return SERVICE_SUCCESS;
}
if (!cJSON_IsArray(filedJ)) {
INIT_LOGE("service=%s, caps is not a list, error.\n", curServ->name);
INIT_LOGE("service=%s, caps is not a list, error.", curServ->name);
return SERVICE_FAILURE;
}
// caps array does not exist, means do not need any capability
@ -130,13 +130,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return SERVICE_SUCCESS;
}
if (capsCnt > MAX_CAPS_CNT_FOR_ONE_SERVICE) {
INIT_LOGE("service=%s, too many caps[cnt %d] for one service, max is %d.\n",
INIT_LOGE("service=%s, too many caps[cnt %d] for one service, max is %d.",
curServ->name, capsCnt, MAX_CAPS_CNT_FOR_ONE_SERVICE);
return SERVICE_FAILURE;
}
curServ->servPerm.caps = (unsigned int*)malloc(sizeof(unsigned int) * capsCnt);
if (curServ->servPerm.caps == NULL) {
INIT_LOGE("GetServiceCaps, service=%s, malloc error.\n", curServ->name);
INIT_LOGE("GetServiceCaps, service=%s, malloc error.", curServ->name);
return SERVICE_FAILURE;
}
curServ->servPerm.capsCnt = capsCnt;
@ -145,13 +145,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
cJSON* capJ = cJSON_GetArrayItem(filedJ, i);
if (!cJSON_IsNumber(capJ) || cJSON_GetNumberValue(capJ) < 0) {
// resources will be released by function: ReleaseServiceMem
INIT_LOGI("service=%s, Capbility is not a number or < 0, error.\n", curServ->name);
INIT_LOGI("service=%s, Capbility is not a number or < 0, error.", curServ->name);
break;
}
curServ->servPerm.caps[i] = (unsigned int)cJSON_GetNumberValue(capJ);
if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) { // CAP_LAST_CAP = 37
// resources will be released by function: ReleaseServiceMem
INIT_LOGE("service=%s, caps = %d, error.\n", curServ->name, curServ->servPerm.caps[i]);
INIT_LOGE("service=%s, caps = %d, error.", curServ->name, curServ->servPerm.caps[i]);
return SERVICE_FAILURE;
}
}

View File

@ -113,18 +113,18 @@ int GetParamValue(char *symValue, char *paramValue, unsigned int paramLen)
p++;
char *right = strchr(p, '}');
if (right == NULL) {
INIT_LOGE("Invalid cfg file name, miss '}'.\n");
INIT_LOGE("Invalid cfg file name, miss '}'.");
return -1;
}
tmpLen = right - p;
if (tmpLen > MAX_PARAM_NAME_LEN) {
INIT_LOGE("Parameter name longer than %d\n", MAX_PARAM_NAME_LEN);
INIT_LOGE("Parameter name longer than %d", MAX_PARAM_NAME_LEN);
return -1;
}
INIT_CHECK_ONLY_RETURN(strncpy_s(tmpName, MAX_PARAM_NAME_LEN, p, tmpLen) == EOK, return -1);
int ret = SystemReadParam(tmpName, tmpValue, &tmpLen); // get param
if (ret != 0) {
INIT_LOGE("Failed to read parameter \" %s \"\n", tmpName);
INIT_LOGE("Failed to read parameter \" %s \"", tmpName);
return -1;
}
// change param to new string
@ -134,10 +134,10 @@ int GetParamValue(char *symValue, char *paramValue, unsigned int paramLen)
if (*tmpptr != '\0') { // copy last string
INIT_CHECK_ONLY_RETURN(strncat_s(paramValue, paramLen, tmpptr, tmpLen) == EOK, return -1);
}
INIT_LOGI("paramValue is %s \n", paramValue);
INIT_LOGI("paramValue is %s ", paramValue);
return 0;
} else {
INIT_LOGE("Invalid cfg file name, miss '{'.\n");
INIT_LOGE("Invalid cfg file name, miss '{'.");
return -1;
}
}
@ -175,7 +175,7 @@ struct CmdArgs* GetCmd(const char *cmdContent, const char *delim)
return NULL);
#endif
if (ctx->argc > MAX_CMD_NAME_LEN - 1) {
INIT_LOGE("GetCmd failed, max cmd number is 10.\n");
INIT_LOGE("GetCmd failed, max cmd number is 10.");
FreeCmd(&ctx);
return NULL;
}
@ -228,26 +228,26 @@ void ParseCmdLine(const char* cmdStr, CmdLine* resCmd)
}
if (!foundAndSucceed) {
INIT_LOGE("Cannot parse command: %s\n", cmdStr);
INIT_LOGE("Cannot parse command: %s", cmdStr);
(void)memset_s(resCmd, sizeof(*resCmd), 0, sizeof(*resCmd));
}
}
static void DoStart(const char* cmdContent)
{
INIT_LOGD("DoStart %s \n", cmdContent);
INIT_LOGD("DoStart %s ", cmdContent);
StartServiceByName(cmdContent);
}
static void DoStop(const char* cmdContent)
{
INIT_LOGD("DoStop %s \n", cmdContent);
INIT_LOGD("DoStop %s ", cmdContent);
StopServiceByName(cmdContent);
}
static void DoReset(const char* cmdContent)
{
INIT_LOGD("DoReset %s \n", cmdContent);
INIT_LOGD("DoReset %s ", cmdContent);
DoStop(cmdContent);
DoStart(cmdContent);
}
@ -263,18 +263,18 @@ static void DoCopy(const char* cmdContent)
struct stat fileStat = {0};
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc != DEFAULT_COPY_ARGS_CNT) {
INIT_LOGE("DoCopy failed.\n");
INIT_LOGE("DoCopy failed.");
goto out;
}
srcFd = open(ctx->argv[0], O_RDONLY);
INIT_ERROR_CHECK(srcFd >= 0, goto out, "copy open %s fail %d! \n", ctx->argv[0], errno);
INIT_ERROR_CHECK(stat(ctx->argv[0], &fileStat) == 0, goto out, "stat fail \n");
INIT_ERROR_CHECK(srcFd >= 0, goto out, "copy open %s fail %d! ", ctx->argv[0], errno);
INIT_ERROR_CHECK(stat(ctx->argv[0], &fileStat) == 0, goto out, "stat fail ");
mode = fileStat.st_mode;
dstFd = open(ctx->argv[1], O_WRONLY | O_TRUNC | O_CREAT, mode);
INIT_ERROR_CHECK(dstFd >= 0, goto out, "copy open %s fail %d! \n", ctx->argv[1], errno);
INIT_ERROR_CHECK(dstFd >= 0, goto out, "copy open %s fail %d! ", ctx->argv[1], errno);
while ((rdLen = read(srcFd, buf, sizeof(buf) - 1)) > 0) {
rtLen = write(dstFd, buf, rdLen);
INIT_ERROR_CHECK(rtLen == rdLen, goto out, "write %s file fail %d! \n", ctx->argv[1], errno);
INIT_ERROR_CHECK(rtLen == rdLen, goto out, "write %s file fail %d! ", ctx->argv[1], errno);
}
fsync(dstFd);
out:
@ -292,7 +292,7 @@ static void DoChown(const char* cmdContent)
// format: chown owner group /xxx/xxx/xxx
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc != 3) {
INIT_LOGE("DoChown failed.\n");
INIT_LOGE("DoChown failed.");
goto out;
}
@ -300,21 +300,21 @@ static void DoChown(const char* cmdContent)
gid_t group = (gid_t)-1;
if (isalpha(ctx->argv[0][0])) {
owner = DecodeUid(ctx->argv[0]);
INIT_ERROR_CHECK(owner != (uid_t)-1, goto out, "DoChown decode owner failed.\n");
INIT_ERROR_CHECK(owner != (uid_t)-1, goto out, "DoChown decode owner failed.");
} else {
owner = strtoul(ctx->argv[0], NULL, 0);
}
if (isalpha(ctx->argv[1][0])) {
group = DecodeUid(ctx->argv[1]);
INIT_ERROR_CHECK(group != (gid_t)-1, goto out, "DoChown decode group failed.\n");
INIT_ERROR_CHECK(group != (gid_t)-1, goto out, "DoChown decode group failed.");
} else {
group = strtoul(ctx->argv[1], NULL, 0);
}
int pathPos = 2;
if (chown(ctx->argv[pathPos], owner, group) != 0) {
INIT_LOGE("DoChown, failed for %s, err %d.\n", cmdContent, errno);
INIT_LOGE("DoChown, failed for %s, err %d.", cmdContent, errno);
}
out:
FreeCmd(&ctx);
@ -326,27 +326,27 @@ static void DoMkDir(const char* cmdContent)
// format: mkdir /xxx/xxx/xxx or mkdir /xxx/xxx/xxx mode owner group
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc < 1) {
INIT_LOGE("DoMkDir failed.\n");
INIT_LOGE("DoMkDir failed.");
goto out;
}
mode_t mode = DEFAULT_DIR_MODE;
if (mkdir(ctx->argv[0], mode) != 0 && errno != EEXIST) {
INIT_LOGE("DoMkDir, failed for %s, err %d.\n", cmdContent, errno);
INIT_LOGE("DoMkDir, failed for %s, err %d.", cmdContent, errno);
goto out;
}
if (ctx->argc > 1) {
mode = strtoul(ctx->argv[1], NULL, OCTAL_TYPE);
if (chmod(ctx->argv[0], mode) != 0) {
INIT_LOGE("DoMkDir failed for %s, err %d.\n", cmdContent, errno);
INIT_LOGE("DoMkDir failed for %s, err %d.", cmdContent, errno);
}
int ownerPos = 2;
int groupPos = 3;
char chownCmdContent[AUTHORITY_MAX_SIZE] = { 0 };
if (snprintf_s(chownCmdContent, AUTHORITY_MAX_SIZE, AUTHORITY_MAX_SIZE - 1, "%s %s %s",
ctx->argv[ownerPos], ctx->argv[groupPos], ctx->argv[0]) == -1) {
INIT_LOGE("DoMkDir snprintf failed.\n");
INIT_LOGE("DoMkDir snprintf failed.");
goto out;
}
DoChown(chownCmdContent);
@ -361,18 +361,18 @@ static void DoChmod(const char* cmdContent)
// format: chmod xxxx /xxx/xxx/xxx
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc != 2) {
INIT_LOGE("DoChmod failed.\n");
INIT_LOGE("DoChmod failed.");
goto out;
}
mode_t mode = strtoul(ctx->argv[0], NULL, OCTAL_TYPE);
if (mode == 0) {
INIT_LOGE("DoChmod, strtoul failed for %s, er %d.\n", cmdContent, errno);
INIT_LOGE("DoChmod, strtoul failed for %s, er %d.", cmdContent, errno);
goto out;
}
if (chmod(ctx->argv[1], mode) != 0) {
INIT_LOGE("DoChmod, failed for %s, err %d.\n", cmdContent, errno);
INIT_LOGE("DoChmod, failed for %s, err %d.", cmdContent, errno);
}
out:
FreeCmd(&ctx);
@ -382,20 +382,20 @@ out:
static char* CopySubStr(const char* srcStr, size_t startPos, size_t endPos)
{
if (endPos <= startPos) {
INIT_LOGE("DoMount, invalid params<%zu, %zu> for %s.\n", endPos, startPos, srcStr);
INIT_LOGE("DoMount, invalid params<%zu, %zu> for %s.", endPos, startPos, srcStr);
return NULL;
}
size_t mallocLen = endPos - startPos + 1;
char* retStr = (char*)malloc(mallocLen);
if (retStr == NULL) {
INIT_LOGE("DoMount, malloc failed! malloc size %zu, for %s.\n", mallocLen, srcStr);
INIT_LOGE("DoMount, malloc failed! malloc size %zu, for %s.", mallocLen, srcStr);
return NULL;
}
const char* copyStart = srcStr + startPos;
if (memcpy_s(retStr, mallocLen, copyStart, endPos - startPos) != EOK) {
INIT_LOGE("DoMount, memcpy_s failed for %s.\n", srcStr);
INIT_LOGE("DoMount, memcpy_s failed for %s.", srcStr);
free(retStr);
return NULL;
}
@ -440,7 +440,7 @@ static int CountSpaces(const char* cmdContent, size_t* spaceCnt, size_t* spacePo
if (cmdContent[i] == ' ') {
++(*spaceCnt);
if ((*spaceCnt) > spacePosArrLen) {
INIT_LOGE("DoMount, too many spaces, bad format for %s.\n", cmdContent);
INIT_LOGE("DoMount, too many spaces, bad format for %s.", cmdContent);
return 0;
}
spacePosArr[(*spaceCnt) - 1] = i;
@ -450,14 +450,14 @@ static int CountSpaces(const char* cmdContent, size_t* spaceCnt, size_t* spacePo
if ((*spaceCnt) < SPACES_CNT_IN_CMD_MIN || // spaces count should not less than 2(at least 3 items)
spacePosArr[0] == 0 || // should not start with space
spacePosArr[(*spaceCnt) - 1] == strLen - 1) { // should not end with space
INIT_LOGE("DoMount, bad format for %s.\n", cmdContent);
INIT_LOGE("DoMount, bad format for %s.", cmdContent);
return 0;
}
// spaces should not be adjacent
for (size_t i = 1; i < (*spaceCnt); ++i) {
if (spacePosArr[i] == spacePosArr[i - 1] + 1) {
INIT_LOGE("DoMount, bad format for %s.\n", cmdContent);
INIT_LOGE("DoMount, bad format for %s.", cmdContent);
return 0;
}
}
@ -522,7 +522,7 @@ static void DoMount(const char* cmdContent)
}
if (mountRet != 0) {
INIT_LOGE("DoMount, failed for %s, err %d.\n", cmdContent, errno);
INIT_LOGE("DoMount, failed for %s, err %d.", cmdContent, errno);
}
free(fileSysType);
@ -562,13 +562,13 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt
realPath = realpath(fileName, realPath);
int fd = open(realPath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
if (fd < 0) {
INIT_LOGE("failed to open %s: %d\n", realPath, errno);
INIT_LOGE("failed to open %s: %d", realPath, errno);
free(realPath);
return;
}
int rc = syscall(__NR_finit_module, fd, options, flags);
if (rc == -1) {
INIT_LOGE("finit_module for %s failed: %d\n", realPath, errno);
INIT_LOGE("finit_module for %s failed: %d", realPath, errno);
}
if (fd >= 0) {
close(fd);
@ -588,28 +588,28 @@ static void DoInsmod(const char *cmdContent)
size_t count = strlen(cmdContent);
if (count > OPTIONS_SIZE) {
INIT_LOGE("DoInsmod options too long, maybe lost some of options\n");
INIT_LOGE("DoInsmod options too long, maybe lost some of options");
}
line = (char *)malloc(count + 1);
if (line == NULL) {
INIT_LOGE("DoInsmod allocate memory failed.\n");
INIT_LOGE("DoInsmod allocate memory failed.");
return;
}
if (memcpy_s(line, count, cmdContent, count) != EOK) {
INIT_LOGE("DoInsmod memcpy failed\n");
INIT_LOGE("DoInsmod memcpy failed");
free(line);
return;
}
line[count] = '\0';
do {
if ((p = strtok_r(line, " ", &restPtr)) == NULL) {
INIT_LOGE("DoInsmod cannot get filename.\n");
INIT_LOGE("DoInsmod cannot get filename.");
free(line);
return;
}
fileName = p;
INIT_LOGI("DoInsmod fileName is [%s].\n", fileName);
INIT_LOGI("DoInsmod fileName is [%s].", fileName);
if ((p = strtok_r(NULL, " ", &restPtr)) == NULL) {
break;
}
@ -628,10 +628,10 @@ static void DoSetParam(const char* cmdContent)
{
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc != 2) {
INIT_LOGE("DoSetParam failed.\n");
INIT_LOGE("DoSetParam failed.");
goto out;
}
INIT_LOGE("param name: %s, value %s \n", ctx->argv[0], ctx->argv[1]);
INIT_LOGE("param name: %s, value %s ", ctx->argv[0], ctx->argv[1]);
SystemWriteParam(ctx->argv[0], ctx->argv[1]);
out:
FreeCmd(&ctx);
@ -670,15 +670,15 @@ static void DoLoadCfg(const char *path)
return;
}
INIT_LOGI("DoLoadCfg cfg file %s\n", path);
INIT_LOGI("DoLoadCfg cfg file %s", path);
if (!CheckValidCfg(path)) {
INIT_LOGE("CheckCfg file %s Failed\n", path);
INIT_LOGE("CheckCfg file %s Failed", path);
return;
}
fp = fopen(path, "r");
if (fp == NULL) {
INIT_LOGE("open cfg error = %d\n", errno);
INIT_LOGE("open cfg error = %d", errno);
return;
}
@ -714,20 +714,20 @@ static void DoWrite(const char *cmdContent)
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
int writeCmdNumber = 2;
if (ctx == NULL || ctx->argv == NULL || ctx->argc != writeCmdNumber) {
INIT_LOGE("DoWrite: invalid arguments\n");
INIT_LOGE("DoWrite: invalid arguments");
goto out;
}
int fd = open(ctx->argv[0], O_WRONLY | O_CREAT | O_NOFOLLOW | O_CLOEXEC, S_IRWXU |
S_IRGRP | S_IROTH);
if (fd == -1) {
INIT_LOGE("DoWrite: open %s failed: %d\n", ctx->argv[0], errno);
INIT_LOGE("DoWrite: open %s failed: %d", ctx->argv[0], errno);
goto out;
}
size_t ret = write(fd, ctx->argv[1], strlen(ctx->argv[1]));
if (ret < 0) {
INIT_LOGE("DoWrite: write to file %s failed: %d\n", ctx->argv[0], errno);
INIT_LOGE("DoWrite: write to file %s failed: %d", ctx->argv[0], errno);
close(fd);
goto out;
}
@ -742,13 +742,13 @@ static void DoRmdir(const char *cmdContent)
// format: rmdir path
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc != 1) {
INIT_LOGE("DoRmdir: invalid arguments\n");
INIT_LOGE("DoRmdir: invalid arguments");
goto out;
}
int ret = rmdir(ctx->argv[0]);
if (ret == -1) {
INIT_LOGE("DoRmdir: remove %s failed: %d.\n", ctx->argv[0], errno);
INIT_LOGE("DoRmdir: remove %s failed: %d.", ctx->argv[0], errno);
goto out;
}
out:
@ -768,7 +768,7 @@ static void DoSetrlimit(const char *cmdContent)
int setrlimitCmdNumber = 3;
int rlimMaxPos = 2;
if (ctx == NULL || ctx->argv == NULL || ctx->argc != setrlimitCmdNumber) {
INIT_LOGE("DoSetrlimit: invalid arguments\n");
INIT_LOGE("DoSetrlimit: invalid arguments");
goto out;
}
@ -782,12 +782,12 @@ static void DoSetrlimit(const char *cmdContent)
}
}
if (rcs == -1) {
INIT_LOGE("DoSetrlimit failed, resouces :%s not support.\n", ctx->argv[0]);
INIT_LOGE("DoSetrlimit failed, resouces :%s not support.", ctx->argv[0]);
goto out;
}
int ret = setrlimit(rcs, &limit);
if (ret) {
INIT_LOGE("DoSetrlimit failed : %d\n", errno);
INIT_LOGE("DoSetrlimit failed : %d", errno);
goto out;
}
out:
@ -800,12 +800,12 @@ static void DoRm(const char *cmdContent)
// format: rm /xxx/xxx/xxx
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL || ctx->argc != 1) {
INIT_LOGE("DoRm: invalid arguments\n");
INIT_LOGE("DoRm: invalid arguments");
goto out;
}
int ret = unlink(ctx->argv[0]);
if (ret == -1) {
INIT_LOGE("DoRm: unlink %s failed: %d.\n", ctx->argv[0], errno);
INIT_LOGE("DoRm: unlink %s failed: %d.", ctx->argv[0], errno);
goto out;
}
out:
@ -819,12 +819,12 @@ static void DoExport(const char *cmdContent)
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
int exportCmdNumber = 2;
if (ctx == NULL || ctx->argv == NULL || ctx->argc != exportCmdNumber) {
INIT_LOGE("DoExport: invalid arguments\n");
INIT_LOGE("DoExport: invalid arguments");
goto out;
}
int ret = setenv(ctx->argv[0], ctx->argv[1], 1);
if (ret != 0) {
INIT_LOGE("DoExport: set %s with %s failed: %d\n", ctx->argv[0], ctx->argv[1], errno);
INIT_LOGE("DoExport: set %s with %s failed: %d", ctx->argv[0], ctx->argv[1], errno);
goto out;
}
out:
@ -837,13 +837,13 @@ static void DoExec(const char *cmdContent)
// format: exec /xxx/xxx/xxx xxx
pid_t pid = fork();
if (pid < 0) {
INIT_LOGE("DoExec: failed to fork child process to exec \"%s\"\n", cmdContent);
INIT_LOGE("DoExec: failed to fork child process to exec \"%s\"", cmdContent);
return;
}
if (pid == 0) {
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
if (ctx == NULL || ctx->argv == NULL) {
INIT_LOGE("DoExec: invalid arguments\n");
INIT_LOGE("DoExec: invalid arguments");
_exit(0x7f);
}
#ifdef OHOS_LITE
@ -852,7 +852,7 @@ static void DoExec(const char *cmdContent)
int ret = execv(ctx->argv[0], ctx->argv);
#endif
if (ret == -1) {
INIT_LOGE("DoExec: execute \"%s\" failed: %d.\n", cmdContent, errno);
INIT_LOGE("DoExec: execute \"%s\" failed: %d.", cmdContent, errno);
}
FreeCmd(&ctx);
_exit(0x7f);
@ -867,13 +867,13 @@ static void DoSymlink(const char *cmdContent)
struct CmdArgs *ctx = GetCmd(cmdContent, " ");
int symlinkCmdNumber = 2;
if (ctx == NULL || ctx->argv == NULL || ctx->argc != symlinkCmdNumber) {
INIT_LOGE("DoSymlink: invalid arguments.\n");
INIT_LOGE("DoSymlink: invalid arguments.");
goto out;
}
int ret = symlink(ctx->argv[0], ctx->argv[1]);
if (ret != 0) {
INIT_LOGE("DoSymlink: link %s to %s failed: %d\n", ctx->argv[0], ctx->argv[1], errno);
INIT_LOGE("DoSymlink: link %s to %s failed: %d", ctx->argv[0], ctx->argv[1], errno);
goto out;
}
out:
@ -910,12 +910,12 @@ static void DoMakeNode(const char *cmdContent)
int decimal = 10;
int octal = 8;
if (ctx == NULL || ctx->argv == NULL || ctx->argc != mkNodeCmdNumber) {
INIT_LOGE("DoMakeNode: invalid arguments\n");
INIT_LOGE("DoMakeNode: invalid arguments");
goto out;
}
if (!access(ctx->argv[1], F_OK)) {
INIT_LOGE("DoMakeNode failed, path has not sexisted\n");
INIT_LOGE("DoMakeNode failed, path has not sexisted");
goto out;
}
mode_t deviceMode = GetDeviceMode(ctx->argv[deviceTypePos]);
@ -925,7 +925,7 @@ static void DoMakeNode(const char *cmdContent)
int ret = mknod(ctx->argv[0], deviceMode | authority, makedev(major, minor));
if (ret != 0) {
INIT_LOGE("DoMakeNode: path: %s failed: %d\n", ctx->argv[0], errno);
INIT_LOGE("DoMakeNode: path: %s failed: %d", ctx->argv[0], errno);
goto out;
}
out:
@ -940,14 +940,14 @@ static void DoMakeDevice(const char *cmdContent)
int makeDevCmdNumber = 2;
int decimal = 10;
if (ctx == NULL || ctx->argv == NULL || ctx->argc != makeDevCmdNumber) {
INIT_LOGE("DoMakedevice: invalid arugments\n");
INIT_LOGE("DoMakedevice: invalid arugments");
goto out;
}
unsigned int major = strtoul(ctx->argv[0], NULL, decimal);
unsigned int minor = strtoul(ctx->argv[1], NULL, decimal);
dev_t deviceId = makedev(major, minor);
if (deviceId < 0) {
INIT_LOGE("DoMakedevice \" %s \" failed :%d \n", cmdContent, errno);
INIT_LOGE("DoMakedevice \" %s \" failed :%d ", cmdContent, errno);
goto out;
}
out:
@ -962,7 +962,6 @@ void DoCmd(const CmdLine* curCmd)
if (curCmd == NULL || curCmd->name[0] == '\0') {
return;
}
// INIT_LOGE("curCmd->name:%s, curCmd->cmdContent:%s\n", curCmd->name, curCmd->cmdContent);
DoCmdByName(curCmd->name, curCmd->cmdContent);
}
@ -1013,7 +1012,7 @@ void DoCmdByName(const char *name, const char *cmdContent)
} else if (strncmp(name, "insmod ", strlen("insmod ")) == 0) {
DoInsmod(cmdContent);
} else if (strncmp(name, "trigger ", strlen("trigger ")) == 0) {
INIT_LOGD("ready to trigger job: %s\n", name);
INIT_LOGD("ready to trigger job: %s", name);
DoTriggerExec(cmdContent);
} else if (strncmp(name, "load_persist_params ", strlen("load_persist_params ")) == 0) {
LoadPersistParams();
@ -1025,7 +1024,7 @@ void DoCmdByName(const char *name, const char *cmdContent)
} else if (strncmp(name, "reboot ", strlen("reboot ")) == 0) {
DoReboot(cmdContent);
} else {
INIT_LOGE("DoCmd, unknown cmd name %s.\n", name);
INIT_LOGE("DoCmd, unknown cmd name %s.", name);
}
}

View File

@ -32,11 +32,10 @@ static int ExtractCfgFile(char **cfgFile, char *content)
}
size_t cfgFileLen = strlen(content) + MAX_PARAM_VALUE_LEN + 1;
if ((*cfgFile = malloc(cfgFileLen)) == NULL) {
INIT_LOGW("Failed to allocate memory to import cfg file. err = %d\n", errno);
INIT_LOGW("Failed to allocate memory to import cfg file. err = %d", errno);
return -1;
}
int ret = GetParamValue(content, *cfgFile, cfgFileLen);
return ret;
return GetParamValue(content, *cfgFile, cfgFileLen);
}
#endif
@ -52,18 +51,18 @@ void ParseAllImports(cJSON *root)
for (int i = 0; i < importAttrSize; i++) {
cJSON *importItem = cJSON_GetArrayItem(importAttr, i);
if (!cJSON_IsString(importItem)) {
INIT_LOGE("Invalid type of import item. should be string\n");
INIT_LOGE("Invalid type of import item. should be string");
return;
}
char *importContent = cJSON_GetStringValue(importItem);
if (importContent == NULL) {
INIT_LOGE("cannot get import config file\n");
INIT_LOGE("cannot get import config file");
return;
}
// Only OHOS L2 support parameter.
#ifndef OHOS_LITE
if (ExtractCfgFile(&cfgFile, importContent) < 0) {
INIT_LOGW("Failed to import from %s\n", importContent);
INIT_LOGW("Failed to import from %s", importContent);
if (cfgFile != NULL) {
free(cfgFile);
cfgFile = NULL;
@ -73,12 +72,12 @@ void ParseAllImports(cJSON *root)
#else
cfgFile = importContent;
#endif
INIT_LOGI("Import %s...\n", cfgFile);
INIT_LOGI("Import %s...", cfgFile);
ParseInitCfg(cfgFile);
// Do not forget to free memory.
free(cfgFile);
cfgFile = NULL;
}
INIT_LOGD("parse import file done\n");
INIT_LOGD("parse import file done");
return;
}

View File

@ -39,16 +39,16 @@ static int g_jobCnt = 0;
void DumpAllJobs()
{
INIT_LOGD("Ready to dump all jobs:\n");
INIT_LOGD("Ready to dump all jobs:");
for (int i = 0; i < g_jobCnt; i++) {
INIT_LOGD("\tjob name: %s\n", g_jobs[i].name);
INIT_LOGD("\tlist all commands:\n");
INIT_LOGD("\tjob name: %s", g_jobs[i].name);
INIT_LOGD("\tlist all commands:");
for (int j = 0; j < g_jobs[i].cmdLinesCnt; j++) {
INIT_LOGD("\t\tcommand name : %s, command options: %s\n",
INIT_LOGD("\t\tcommand name : %s, command options: %s",
g_jobs[i].cmdLines[j].name, g_jobs[i].cmdLines[j].cmdContent);
}
}
INIT_LOGD("To dump all jobs finished\n");
INIT_LOGD("To dump all jobs finished");
}
static int GetJobName(const cJSON* jobItem, Job* resJob)
@ -59,7 +59,7 @@ static int GetJobName(const cJSON* jobItem, Job* resJob)
}
if (memcpy_s(resJob->name, MAX_JOB_NAME_LEN, jobNameStr, strlen(jobNameStr)) != EOK) {
INIT_LOGE("Get job name \"%s\" failed\n", jobNameStr);
INIT_LOGE("Get job name \"%s\" failed", jobNameStr);
return 0;
}
resJob->name[strlen(jobNameStr)] = '\0';
@ -69,33 +69,33 @@ static int GetJobName(const cJSON* jobItem, Job* resJob)
static void ParseJob(const cJSON* jobItem, Job* resJob)
{
if (!GetJobName(jobItem, resJob)) {
INIT_LOGE("get JobName failed\n");
INIT_LOGE("get JobName failed");
(void)memset_s(resJob, sizeof(*resJob), 0, sizeof(*resJob));
return;
}
cJSON* cmdsItem = cJSON_GetObjectItem(jobItem, CMDS_ARR_NAME_IN_JSON);
if (!cJSON_IsArray(cmdsItem)) {
INIT_LOGE("job %s is not an arrary\n", resJob->name);
INIT_LOGE("job %s is not an arrary", resJob->name);
return;
}
int cmdLinesCnt = cJSON_GetArraySize(cmdsItem);
if (cmdLinesCnt <= 0) { // empty job, no cmd
INIT_LOGE("empty job \"%s\"\n", resJob->name);
INIT_LOGE("empty job \"%s\"", resJob->name);
return;
}
INIT_LOGD("job = %s, cmdLineCnt = %d\n", resJob->name, cmdLinesCnt);
INIT_LOGD("job = %s, cmdLineCnt = %d", resJob->name, cmdLinesCnt);
if (cmdLinesCnt > MAX_CMD_CNT_IN_ONE_JOB) {
INIT_LOGE("ParseAllJobs, too many cmds[cnt %d] in one job, it should not exceed %d.\n",
INIT_LOGE("ParseAllJobs, too many cmds[cnt %d] in one job, it should not exceed %d.",
cmdLinesCnt, MAX_CMD_CNT_IN_ONE_JOB);
return;
}
resJob->cmdLines = (CmdLine*)malloc(cmdLinesCnt * sizeof(CmdLine));
if (resJob->cmdLines == NULL) {
INIT_LOGE("allocate memory for command line failed\n");
INIT_LOGE("allocate memory for command line failed");
return;
}
@ -115,32 +115,32 @@ static void ParseJob(const cJSON* jobItem, Job* resJob)
void ParseAllJobs(const cJSON* fileRoot)
{
if (fileRoot == NULL) {
INIT_LOGE("ParseAllJobs, input fileRoot is NULL!\n");
INIT_LOGE("ParseAllJobs, input fileRoot is NULL!");
return;
}
cJSON* jobArr = cJSON_GetObjectItemCaseSensitive(fileRoot, JOBS_ARR_NAME_IN_JSON);
if (!cJSON_IsArray(jobArr)) {
INIT_LOGE("ParseAllJobs, job item is not array!\n");
INIT_LOGE("ParseAllJobs, job item is not array!");
return;
}
int jobArrSize = cJSON_GetArraySize(jobArr);
if (jobArrSize <= 0 || jobArrSize > MAX_JOBS_COUNT) {
INIT_LOGE("ParseAllJobs, jobs count %d is invalid, should be positive and not exceeding %d.\n",
INIT_LOGE("ParseAllJobs, jobs count %d is invalid, should be positive and not exceeding %d.",
jobArrSize, MAX_JOBS_COUNT);
return;
}
Job* retJobs = (Job*)realloc(g_jobs, sizeof(Job) * (g_jobCnt + jobArrSize));
if (retJobs == NULL) {
INIT_LOGE("ParseAllJobs, malloc failed! job arrSize %d.\n", jobArrSize);
INIT_LOGE("ParseAllJobs, malloc failed! job arrSize %d.", jobArrSize);
return;
}
Job* tmp = retJobs + g_jobCnt;
if (memset_s(tmp, sizeof(Job) * jobArrSize, 0, sizeof(Job) * jobArrSize) != EOK) {
INIT_LOGE("ParseAllJobs, memset_s failed.\n");
INIT_LOGE("ParseAllJobs, memset_s failed.");
free(retJobs);
retJobs = NULL;
return;
@ -157,11 +157,11 @@ void ParseAllJobs(const cJSON* fileRoot)
void DoJob(const char* jobName)
{
if (jobName == NULL) {
INIT_LOGE("DoJob, input jobName NULL!\n");
INIT_LOGE("DoJob, input jobName NULL!");
return;
}
INIT_LOGD("Call job with name %s\n", jobName);
INIT_LOGD("Call job with name %s", jobName);
for (int i = 0; i < g_jobCnt; ++i) {
if (strncmp(jobName, g_jobs[i].name, strlen(g_jobs[i].name)) == 0) {
CmdLine* cmdLines = g_jobs[i].cmdLines;

View File

@ -60,13 +60,13 @@ static void ParseInitCfgContents(cJSON *root)
void ParseInitCfg(const char *configFile)
{
if (configFile == NULL || *configFile == '\0') {
INIT_LOGE("Invalid config file\n");
INIT_LOGE("Invalid config file");
return;
}
char *fileBuf = ReadFileToBuf(configFile);
if (fileBuf == NULL) {
INIT_LOGE("Read %s failed\n", configFile);
INIT_LOGE("Read %s failed", configFile);
return;
}
cJSON* fileRoot = cJSON_Parse(fileBuf);
@ -74,7 +74,7 @@ void ParseInitCfg(const char *configFile)
fileBuf = NULL;
if (fileRoot == NULL) {
INIT_LOGE("InitReadCfg, parse failed! please check file %s format.\n", configFile);
INIT_LOGE("InitReadCfg, parse failed! please check file %s format.", configFile);
return;
}
ParseInitCfgContents(fileRoot);
@ -87,14 +87,14 @@ static void ReadCfgs(const char *dirPath)
{
DIR *pDir = opendir(dirPath);
if (pDir == NULL) {
INIT_LOGE("ParseCfgs open cfg dir :%s failed.%d\n", dirPath, errno);
INIT_LOGE("ParseCfgs open cfg dir :%s failed.%d", dirPath, errno);
return;
}
struct dirent *dp;
while ((dp = readdir(pDir)) != NULL) {
char fileName[FILE_NAME_MAX_SIZE];
if (snprintf_s(fileName, FILE_NAME_MAX_SIZE, FILE_NAME_MAX_SIZE - 1, "%s/%s", dirPath, dp->d_name) == -1) {
INIT_LOGE("ParseCfgs snprintf_s failed.\n");
INIT_LOGE("ParseCfgs snprintf_s failed.");
closedir(pDir);
return;
}
@ -103,7 +103,7 @@ static void ReadCfgs(const char *dirPath)
if (strstr(dp->d_name, ".cfg") == NULL) {
continue;
}
INIT_LOGI("ReadCfgs :%s from %s success.\n", fileName, dirPath);
INIT_LOGI("ReadCfgs :%s from %s success.", fileName, dirPath);
ParseInitCfg(fileName);
}
}
@ -127,7 +127,7 @@ void InitReadCfg()
#endif
ParseInitCfg(INIT_CONFIGURATION_FILE);
ParseOtherCfgs();
INIT_LOGI("Parse init config file done.\n");
INIT_LOGI("Parse init config file done.");
DumpAllServices();
// DumpAllJobs();

View File

@ -46,7 +46,7 @@ static bool RBMiscWriteUpdaterMessage(const char *path, struct RBMiscUpdateMessa
size_t ret = fwrite(boot, sizeof(struct RBMiscUpdateMessage), 1, fp);
if (ret < 0) {
INIT_LOGE("write to misc failed\n");
INIT_LOGE("write to misc failed");
fclose(fp);
return false;
}
@ -80,7 +80,7 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
const char *mountFile = "/proc/mounts";
FILE *fp = fopen(mountFile, "r");
if (fp == NULL) {
INIT_LOGE("DoReboot %s can't open.\n", mountPoint);
INIT_LOGE("DoReboot %s can't open.", mountPoint);
return 1;
}
@ -103,19 +103,19 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
void DoReboot(const char *value)
{
if (value == NULL) {
INIT_LOGE("DoReboot value = NULL\n");
INIT_LOGE("DoReboot value = NULL");
return;
}
INIT_LOGI("DoReboot value = %s\n", value);
INIT_LOGI("DoReboot value = %s", value);
if (strlen(value) > MAX_VALUE_LENGTH) {
INIT_LOGE("DoReboot reboot value error, value = %s.\n", value);
INIT_LOGE("DoReboot reboot value error, value = %s.", value);
return;
}
const char *valueData = NULL;
if (strncmp(value, "reboot,", strlen("reboot,")) != 0) {
INIT_LOGE("DoReboot reboot value = %s, must started with reboot ,error.\n", value);
INIT_LOGE("DoReboot reboot value = %s, must started with reboot ,error.", value);
return;
} else {
valueData = value + strlen("reboot,");
@ -124,26 +124,26 @@ void DoReboot(const char *value)
&& strncmp(valueData, "updater:", strlen("updater:")) != 0
&& strncmp(valueData, "updater", strlen("updater")) != 0
&& strncmp(valueData, "NoArgument", strlen("NoArgument")) != 0) {
INIT_LOGE("DoReboot value = %s, parameters error.\n", value);
INIT_LOGE("DoReboot value = %s, parameters error.", value);
return;
}
StopAllServicesBeforeReboot();
if (GetMountStatusForMountPoint("/vendor")) {
if (umount("/vendor") != 0) {
INIT_LOGE("DoReboot umount vendor failed! errno = %d.\n", errno);
INIT_LOGE("DoReboot umount vendor failed! errno = %d.", errno);
}
}
if (GetMountStatusForMountPoint("/data")) {
if (umount("/data") != 0) {
INIT_LOGE("DoReboot umount data failed! errno = %d.\n", errno);
INIT_LOGE("DoReboot umount data failed! errno = %d.", errno);
}
}
// "shutdown"
if (strncmp(valueData, "shutdown", strlen("shutdown")) == 0) {
int ret = reboot(RB_POWER_OFF);
if (ret != 0) {
INIT_LOGE("DoReboot reboot(RB_POWER_OFF) failed! syscall ret %d, err %d.\n", ret, errno);
INIT_LOGE("DoReboot reboot(RB_POWER_OFF) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
@ -152,7 +152,7 @@ void DoReboot(const char *value)
struct RBMiscUpdateMessage msg;
bool ret = RBMiscReadUpdaterMessage(miscFile, &msg);
if(!ret) {
INIT_LOGE("DoReboot RBMiscReadUpdaterMessage error.\n");
INIT_LOGE("DoReboot RBMiscReadUpdaterMessage error.");
return;
}
const int commandSize = 12;
@ -162,41 +162,41 @@ void DoReboot(const char *value)
if (strlen(valueData) > strlen("updater:") && strncmp(valueData, "updater:", strlen("updater:")) == 0) {
const char *p = valueData + strlen("updater:");
if (snprintf(msg.update, MAX_UPDATE_SIZE, "%s", p) > MAX_UPDATE_SIZE) {
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error\n");
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error");
return;
}
msg.update[MAX_UPDATE_SIZE - 1] = 0;
ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if(true != ret) {
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error\n");
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error");
return;
}
ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("DoReboot updater: reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.\n", ret, errno);
INIT_LOGE("DoReboot updater: reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
if (strlen(valueData) == strlen("updater") && strncmp(valueData, "updater", strlen("updater")) == 0) {
ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if(true != ret) {
INIT_LOGE("DoReboot updater RBMiscWriteUpdaterMessage error\n");
INIT_LOGE("DoReboot updater RBMiscWriteUpdaterMessage error");
return;
}
ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("DoReboot updater reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.\n", ret, errno);
INIT_LOGE("DoReboot updater reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
if (strlen(valueData) == strlen("NoArgument") && strncmp(valueData, "NoArgument", strlen("NoArgument")) == 0) {
ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("DoReboot updater: reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.\n", ret, errno);
INIT_LOGE("DoReboot updater: reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
INIT_LOGE("DoReboot value = %s, error.\n", value);
INIT_LOGE("DoReboot value = %s, error.", value);
return;
}

View File

@ -79,13 +79,13 @@ static int SetPerms(const Service *service)
}
if (setgroups(service->servPerm.gIDCnt, service->servPerm.gIDArray) != 0) {
INIT_LOGE("SetPerms, setgroups failed. errno = %d, gIDCnt=%d\n", errno, service->servPerm.gIDCnt);
INIT_LOGE("SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt);
return SERVICE_FAILURE;
}
if (service->servPerm.uID != 0) {
if (setuid(service->servPerm.uID) != 0) {
INIT_LOGE("setuid of service: %s failed, uid = %d\n", service->name, service->servPerm.uID);
INIT_LOGE("setuid of service: %s failed, uid = %d", service->name, service->servPerm.uID);
return SERVICE_FAILURE;
}
}
@ -113,7 +113,7 @@ static int SetPerms(const Service *service)
}
if (capset(&capHeader, capData) != 0) {
INIT_LOGE("capset faild for service: %s, error: %d\n", service->name, errno);
INIT_LOGE("capset faild for service: %s, error: %d", service->name, errno);
return SERVICE_FAILURE;
}
for (unsigned int i = 0; i < service->servPerm.capsCnt; ++i) {
@ -121,7 +121,7 @@ static int SetPerms(const Service *service)
return SetAllAmbientCapability();
}
if (SetAmbientCapability(service->servPerm.caps[i]) != 0) {
INIT_LOGE("SetAmbientCapability faild for service: %s\n", service->name);
INIT_LOGE("SetAmbientCapability faild for service: %s", service->name);
return SERVICE_FAILURE;
}
}
@ -140,7 +140,7 @@ static void OpenConsole()
dup2(fd, 2);
close(fd);
} else {
INIT_LOGE("Open /dev/console failed. err = %d\n", errno);
INIT_LOGE("Open /dev/console failed. err = %d", errno);
}
return;
}
@ -148,15 +148,15 @@ static void OpenConsole()
int ServiceStart(Service *service)
{
if (service == NULL) {
INIT_LOGE("start service failed! null ptr.\n");
INIT_LOGE("start service failed! null ptr.");
return SERVICE_FAILURE;
}
if (service->pid > 0) {
INIT_LOGI("service : %s had started already.\n", service->name);
INIT_LOGI("service : %s had started already.", service->name);
return SERVICE_SUCCESS;
}
if (service->attribute & SERVICE_ATTR_INVALID) {
INIT_LOGE("start service %s invalid.\n", service->name);
INIT_LOGE("start service %s invalid.", service->name);
return SERVICE_FAILURE;
}
@ -164,7 +164,7 @@ int ServiceStart(Service *service)
service->attribute &= (~(SERVICE_ATTR_NEED_RESTART | SERVICE_ATTR_NEED_STOP));
if (stat(service->pathArgs[0], &pathStat) != 0) {
service->attribute |= SERVICE_ATTR_INVALID;
INIT_LOGE("start service %s invalid, please check %s.\n",\
INIT_LOGE("start service %s invalid, please check %s.",\
service->name, service->pathArgs[0]);
return SERVICE_FAILURE;
}
@ -172,10 +172,10 @@ int ServiceStart(Service *service)
int pid = fork();
if (pid == 0) {
if (service->socketCfg != NULL) { // start socket service
INIT_LOGI("Create socket \n");
INIT_LOGI("Create socket ");
ret = DoCreateSocket(service->socketCfg);
if (ret < 0) {
INIT_LOGE("DoCreateSocket failed. \n");
INIT_LOGE("DoCreateSocket failed. ");
_exit(0x7f); // 0x7f: user specified
}
}
@ -184,13 +184,13 @@ int ServiceStart(Service *service)
}
// permissions
if (SetPerms(service) != SERVICE_SUCCESS) {
INIT_LOGE("service %s exit! set perms failed! err %d.\n", service->name, errno);
INIT_LOGE("service %s exit! set perms failed! err %d.", service->name, errno);
_exit(0x7f); // 0x7f: user specified
}
char pidString[MAX_PID_STRING_LENGTH]; // writepid
pid_t childPid = getpid();
if (snprintf(pidString, MAX_PID_STRING_LENGTH, "%d", childPid) <= 0) {
INIT_LOGE("start service writepid sprintf failed.\n");
INIT_LOGE("start service writepid sprintf failed.");
_exit(0x7f); // 0x7f: user specified
}
for (int i = 0; i < MAX_WRITEPID_FILES; i++) {
@ -199,33 +199,33 @@ int ServiceStart(Service *service)
}
FILE *fd = fopen(service->writepidFiles[i], "wb");
if (fd == NULL) {
INIT_LOGE("start service writepidFiles %s invalid.\n", service->writepidFiles[i]);
INIT_LOGE("start service writepidFiles %s invalid.", service->writepidFiles[i]);
continue;
}
if (fwrite(pidString, 1, strlen(pidString), fd) != strlen(pidString)) {
INIT_LOGE("start service writepid error.file:%s pid:%s\n", service->writepidFiles[i], pidString);
INIT_LOGE("start service writepid error.file:%s pid:%s", service->writepidFiles[i], pidString);
}
fclose(fd);
INIT_LOGE("ServiceStart writepid filename=%s, childPid=%s, ok\n", service->writepidFiles[i],
INIT_LOGE("ServiceStart writepid filename=%s, childPid=%s, ok", service->writepidFiles[i],
pidString);
}
INIT_LOGI("service->name is %s \n", service->name);
INIT_LOGI("service->name is %s ", service->name);
#ifndef OHOS_LITE
// L2 Can not be reset env
if (execv(service->pathArgs[0], service->pathArgs) != 0) {
INIT_LOGE("service %s execve failed! err %d.\n", service->name, errno);
INIT_LOGE("service %s execve failed! err %d.", service->name, errno);
}
#else
char* env[] = {"LD_LIBRARY_PATH=/storage/app/libs", NULL};
if (execve(service->pathArgs[0], service->pathArgs, env) != 0) {
INIT_LOGE("service %s execve failed! err %d.\n", service->name, errno);
INIT_LOGE("service %s execve failed! err %d.", service->name, errno);
}
#endif
_exit(0x7f); // 0x7f: user specified
} else if (pid < 0) {
INIT_LOGE("start service %s fork failed!\n", service->name);
INIT_LOGE("start service %s fork failed!", service->name);
return SERVICE_FAILURE;
}
@ -233,7 +233,7 @@ int ServiceStart(Service *service)
#ifndef OHOS_LITE
char paramName[PARAM_NAME_LEN_MAX] = {0};
if (snprintf_s(paramName, PARAM_NAME_LEN_MAX, PARAM_NAME_LEN_MAX - 1, "init.svc.%s", service->name) < 0) {
INIT_LOGE("snprintf_s paramName error %d \n", errno);
INIT_LOGE("snprintf_s paramName error %d ", errno);
}
SystemWriteParam(paramName, "running");
#endif
@ -243,7 +243,7 @@ int ServiceStart(Service *service)
int ServiceStop(Service *service)
{
if (service == NULL) {
INIT_LOGE("stop service failed! null ptr.\n");
INIT_LOGE("stop service failed! null ptr.");
return SERVICE_FAILURE;
}
@ -254,17 +254,17 @@ int ServiceStop(Service *service)
}
if (kill(service->pid, SIGKILL) != 0) {
INIT_LOGE("stop service %s pid %d failed! err %d.\n", service->name, service->pid, errno);
INIT_LOGE("stop service %s pid %d failed! err %d.", service->name, service->pid, errno);
return SERVICE_FAILURE;
}
#ifndef OHOS_LITE
char paramName[PARAM_NAME_LEN_MAX] = {0};
if (snprintf_s(paramName, PARAM_NAME_LEN_MAX, PARAM_NAME_LEN_MAX - 1, "init.svc.%s", service->name) < 0) {
INIT_LOGE("snprintf_s paramName error %d \n", errno);
INIT_LOGE("snprintf_s paramName error %d ", errno);
}
SystemWriteParam(paramName, "stopping");
#endif
INIT_LOGI("stop service %s, pid %d.\n", service->name, service->pid);
INIT_LOGI("stop service %s, pid %d.", service->name, service->pid);
return SERVICE_SUCCESS;
}
@ -283,7 +283,7 @@ void CheckCritical(Service *service)
} else {
++service->criticalCrashCnt;
if (service->criticalCrashCnt > CRITICAL_CRASH_COUNT_LIMIT) {
INIT_LOGE("reap critical service %s, crash too many times! Need reboot!\n", service->name);
INIT_LOGE("reap critical service %s, crash too many times! Need reboot!", service->name);
RebootSystem();
}
}
@ -292,13 +292,13 @@ void CheckCritical(Service *service)
static int ExecRestartCmd(const Service *service)
{
INIT_LOGI("ExecRestartCmd \n");
INIT_LOGI("ExecRestartCmd ");
if ((service == NULL) || (service->onRestart == NULL) || (service->onRestart->cmdLine == NULL)) {
return SERVICE_FAILURE;
}
for (int i = 0; i < service->onRestart->cmdNum; i++) {
INIT_LOGI("SetOnRestart cmdLine->name %s cmdLine->cmdContent %s \n", service->onRestart->cmdLine[i].name,
INIT_LOGI("SetOnRestart cmdLine->name %s cmdLine->cmdContent %s ", service->onRestart->cmdLine[i].name,
service->onRestart->cmdLine[i].cmdContent);
DoCmd(&service->onRestart->cmdLine[i]);
}
@ -310,7 +310,7 @@ static int ExecRestartCmd(const Service *service)
void ServiceReap(Service *service)
{
if (service == NULL) {
INIT_LOGE("reap service failed! null ptr.\n");
INIT_LOGE("reap service failed! null ptr.");
return;
}
@ -318,12 +318,12 @@ void ServiceReap(Service *service)
#ifndef OHOS_LITE
char paramName[PARAM_NAME_LEN_MAX] = {0};
if (snprintf_s(paramName, PARAM_NAME_LEN_MAX, PARAM_NAME_LEN_MAX - 1, "init.svc.%s", service->name) < 0) {
INIT_LOGE("snprintf_s paramName error %d \n", errno);
INIT_LOGE("snprintf_s paramName error %d ", errno);
}
SystemWriteParam(paramName, "stopped");
#endif
if (service->attribute & SERVICE_ATTR_INVALID) {
INIT_LOGE("ServiceReap service %s invalid.\n", service->name);
INIT_LOGE("ServiceReap service %s invalid.", service->name);
return;
}
@ -357,7 +357,7 @@ void ServiceReap(Service *service)
} else {
++service->crashCnt;
if (service->crashCnt > CRASH_COUNT_LIMIT) {
INIT_LOGE("reap service %s, crash too many times!\n", service->name);
INIT_LOGE("reap service %s, crash too many times!", service->name);
return;
}
}
@ -368,12 +368,12 @@ void ServiceReap(Service *service)
if (service->onRestart != NULL) {
ret = ExecRestartCmd(service);
if (ret != SERVICE_SUCCESS) {
INIT_LOGE("SetOnRestart fail \n");
INIT_LOGE("SetOnRestart fail ");
}
}
ret = ServiceStart(service);
if (ret != SERVICE_SUCCESS) {
INIT_LOGE("reap service %s start failed!\n", service->name);
INIT_LOGE("reap service %s start failed!", service->name);
}
service->attribute &= (~SERVICE_ATTR_NEED_RESTART);

View File

@ -40,17 +40,16 @@ static int g_servicesCnt = 0;
void DumpAllServices()
{
INIT_LOGD("Ready to dump all services:\n");
INIT_LOGD("total service number: %d\n", g_servicesCnt);
INIT_LOGD("Ready to dump all services:");
INIT_LOGD("total service number: %d", g_servicesCnt);
for (int i = 0; i < g_servicesCnt; i++) {
INIT_LOGD("\tservice name: [%s]\n", g_services[i].name);
INIT_LOGD("\tservice name: [%s]", g_services[i].name);
INIT_LOGD("\tpath :");
for (int j = 0; j < g_services[i].pathArgsCnt; j++) {
INIT_LOGD(" %s", g_services[i].pathArgs[j]);
}
INIT_LOGD("\n");
}
INIT_LOGD("Dump all services finished\n");
INIT_LOGD("Dump all services finished");
}
void RegisterServices(Service* services, int servicesCnt)
@ -97,18 +96,18 @@ static int GetServiceName(const cJSON* curArrItem, Service* curServ)
{
char* fieldStr = cJSON_GetStringValue(cJSON_GetObjectItem(curArrItem, "name"));
if (fieldStr == NULL) {
INIT_LOGE("GetServiceName cJSON_GetStringValue error\n");
INIT_LOGE("GetServiceName cJSON_GetStringValue error");
return SERVICE_FAILURE;
}
size_t strLen = strlen(fieldStr);
if (strLen == 0 || strLen > MAX_SERVICE_NAME) {
INIT_LOGE("GetServiceName strLen = %d, error\n", strLen);
INIT_LOGE("GetServiceName strLen = %d, error", strLen);
return SERVICE_FAILURE;
}
if (memcpy_s(curServ->name, MAX_SERVICE_NAME, fieldStr, strLen) != EOK) {
INIT_LOGE("GetServiceName memcpy_s error\n");
INIT_LOGE("GetServiceName memcpy_s error");
return SERVICE_FAILURE;
}
curServ->name[strLen] = '\0';
@ -161,7 +160,7 @@ static int GetWritepidStrings(const cJSON *curArrItem, Service *curServ)
}
if (writepidCnt > MAX_WRITEPID_FILES) {
INIT_LOGE("GetWritepidStrings, too many writepid[cnt %d] for one service, should not exceed %d.\n",
INIT_LOGE("GetWritepidStrings, too many writepid[cnt %d] for one service, should not exceed %d.",
writepidCnt, MAX_WRITEPID_FILES);
return SERVICE_FAILURE;
}
@ -169,7 +168,7 @@ static int GetWritepidStrings(const cJSON *curArrItem, Service *curServ)
for (int i = 0; i < writepidCnt; ++i) {
if (!cJSON_GetArrayItem(filedJ, i) || !cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))
|| strlen(cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))) <= 0) { // check all errors
INIT_LOGE("GetWritepidStrings, parse item[%d] error.\n", i);
INIT_LOGE("GetWritepidStrings, parse item[%d] error.", i);
return SERVICE_FAILURE;
}
@ -177,11 +176,11 @@ static int GetWritepidStrings(const cJSON *curArrItem, Service *curServ)
size_t strLen = strlen(fieldStr);
curServ->writepidFiles[i] = (char *)malloc(sizeof(char) * strLen + 1);
if (curServ->writepidFiles[i] == NULL) {
INIT_LOGE("GetWritepidStrings, malloc item[%d] error.\n", i);
INIT_LOGE("GetWritepidStrings, malloc item[%d] error.", i);
return SERVICE_FAILURE;
}
if (memcpy_s(curServ->writepidFiles[i], strLen + 1, fieldStr, strLen) != EOK) {
INIT_LOGE("GetWritepidStrings, memcpy_s error.\n");
INIT_LOGE("GetWritepidStrings, memcpy_s error.");
return SERVICE_FAILURE;
}
curServ->writepidFiles[i][strLen] = '\0';
@ -199,7 +198,7 @@ static int GetGidOneItem(const cJSON *curArrItem, Service *curServ) // gi
curServ->servPerm.gIDCnt = 1;
curServ->servPerm.gIDArray = (gid_t *)malloc(sizeof(gid_t));
if (curServ->servPerm.gIDArray == NULL) {
INIT_LOGE("GetGidOneItem, can't malloc, error.\n");
INIT_LOGE("GetGidOneItem, can't malloc, error.");
return SERVICE_FAILURE;
}
@ -207,7 +206,7 @@ static int GetGidOneItem(const cJSON *curArrItem, Service *curServ) // gi
char* fieldStr = cJSON_GetStringValue(filedJ);
gid_t gID = DecodeUid(fieldStr);
if (gID == (gid_t)(-1)) {
INIT_LOGE("GetGidOneItem, DecodeUid %s error.\n", fieldStr);
INIT_LOGE("GetGidOneItem, DecodeUid %s error.", fieldStr);
return SERVICE_FAILURE;
}
curServ->servPerm.gIDArray[0] = gID;
@ -217,14 +216,14 @@ static int GetGidOneItem(const cJSON *curArrItem, Service *curServ) // gi
if (cJSON_IsNumber(filedJ)) {
gid_t gID = (int)cJSON_GetNumberValue(filedJ);
if (gID < 0) {
INIT_LOGE("GetGidOneItem, gID = %d error.\n", gID);
INIT_LOGE("GetGidOneItem, gID = %d error.", gID);
return SERVICE_FAILURE;
}
curServ->servPerm.gIDArray[0] = gID;
return SERVICE_SUCCESS;
}
INIT_LOGE("GetGidOneItem, this gid is neither a string nor a number, error.\n");
INIT_LOGE("GetGidOneItem, this gid is neither a string nor a number, error.");
return SERVICE_FAILURE;
}
@ -237,14 +236,14 @@ static int GetGidArray(const cJSON *curArrItem, Service *curServ) // gid
}
if (gIDCnt > NGROUPS_MAX + 1) {
INIT_LOGE("GetGidArray, too many gids[cnt %d] for one service, should not exceed %d.\n",
INIT_LOGE("GetGidArray, too many gids[cnt %d] for one service, should not exceed %d.",
gIDCnt, NGROUPS_MAX + 1);
return SERVICE_FAILURE;
}
curServ->servPerm.gIDArray = (gid_t *)malloc(sizeof(gid_t) * gIDCnt);
if (curServ->servPerm.gIDArray == NULL) {
INIT_LOGE("GetGidArray malloc error\n");
INIT_LOGE("GetGidArray malloc error");
return SERVICE_FAILURE;
}
curServ->servPerm.gIDCnt = gIDCnt;
@ -252,13 +251,13 @@ static int GetGidArray(const cJSON *curArrItem, Service *curServ) // gid
for (; i < gIDCnt; ++i) {
if (cJSON_GetArrayItem(filedJ, i) == NULL || !cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))
|| strlen(cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))) <= 0) { // check all errors
INIT_LOGE("GetGidArray, parse item[%d] as string, error.\n", i);
INIT_LOGE("GetGidArray, parse item[%d] as string, error.", i);
break;
}
char* fieldStr = cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i));
gid_t gID = DecodeUid(fieldStr);
if ((gID) == (gid_t)(-1)) {
INIT_LOGE("GetGidArray, DecodeUid item[%d] error.\n", i);
INIT_LOGE("GetGidArray, DecodeUid item[%d] error.", i);
return SERVICE_FAILURE;
}
curServ->servPerm.gIDArray[i] = gID;
@ -268,12 +267,12 @@ static int GetGidArray(const cJSON *curArrItem, Service *curServ) // gid
}
for (i = 0; i < gIDCnt; ++i) {
if (cJSON_GetArrayItem(filedJ, i) == NULL || !cJSON_IsNumber(cJSON_GetArrayItem(filedJ, i))) {
INIT_LOGE("GetGidArray, parse item[%d] as number, error.\n", i);
INIT_LOGE("GetGidArray, parse item[%d] as number, error.", i);
break;
}
gid_t gID = (int)cJSON_GetNumberValue(cJSON_GetArrayItem(filedJ, i));
if (gID < 0) {
INIT_LOGE("GetGidArray gID = %d, error\n", gID);
INIT_LOGE("GetGidArray gID = %d, error", gID);
break;
}
curServ->servPerm.gIDArray[i] = gID;
@ -286,19 +285,19 @@ static int GetServicePathAndArgs(const cJSON* curArrItem, Service* curServ)
{
cJSON* pathItem = cJSON_GetObjectItem(curArrItem, "path");
if (!cJSON_IsArray(pathItem)) {
INIT_LOGE("GetServicePathAndArgs path item not found or not a array\n");
INIT_LOGE("GetServicePathAndArgs path item not found or not a array");
return SERVICE_FAILURE;
}
int arrSize = cJSON_GetArraySize(pathItem);
if (arrSize <= 0 || arrSize > MAX_PATH_ARGS_CNT) { // array size invalid
INIT_LOGE("GetServicePathAndArgs arrSize = %d, error\n", arrSize);
INIT_LOGE("GetServicePathAndArgs arrSize = %d, error", arrSize);
return SERVICE_FAILURE;
}
curServ->pathArgs = (char**)malloc((arrSize + 1) * sizeof(char*));
if (curServ->pathArgs == NULL) {
INIT_LOGE("GetServicePathAndArgs malloc 1 error\n");
INIT_LOGE("GetServicePathAndArgs malloc 1 error");
return SERVICE_FAILURE;
}
for (int i = 0; i < arrSize + 1; ++i) {
@ -311,16 +310,16 @@ static int GetServicePathAndArgs(const cJSON* curArrItem, Service* curServ)
if (curParam == NULL || strlen(curParam) > MAX_ONE_ARG_LEN) {
// resources will be released by function: ReleaseServiceMem
if (curParam == NULL) {
INIT_LOGE("GetServicePathAndArgs curParam == NULL, error\n");
INIT_LOGE("GetServicePathAndArgs curParam == NULL, error");
} else {
INIT_LOGE("GetServicePathAndArgs strlen = %d, error\n", strlen(curParam));
INIT_LOGE("GetServicePathAndArgs strlen = %d, error", strlen(curParam));
}
return SERVICE_FAILURE;
}
if (i == 0 && IsForbidden(curParam)) {
// resources will be released by function: ReleaseServiceMem
INIT_LOGE("GetServicePathAndArgs i == 0 && IsForbidden, error\n");
INIT_LOGE("GetServicePathAndArgs i == 0 && IsForbidden, error");
return SERVICE_FAILURE;
}
@ -328,13 +327,13 @@ static int GetServicePathAndArgs(const cJSON* curArrItem, Service* curServ)
curServ->pathArgs[i] = (char*)malloc(paramLen + 1);
if (curServ->pathArgs[i] == NULL) {
// resources will be released by function: ReleaseServiceMem
INIT_LOGE("GetServicePathAndArgs i == 0 && IsForbidden, error\n");
INIT_LOGE("GetServicePathAndArgs i == 0 && IsForbidden, error");
return SERVICE_FAILURE;
}
if (memcpy_s(curServ->pathArgs[i], paramLen + 1, curParam, paramLen) != EOK) {
// resources will be released by function: ReleaseServiceMem
INIT_LOGE("GetServicePathAndArgs malloc 2 error.\n");
INIT_LOGE("GetServicePathAndArgs malloc 2 error.");
return SERVICE_FAILURE;
}
curServ->pathArgs[i][paramLen] = '\0';
@ -354,7 +353,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
}
if (!cJSON_IsNumber(filedJ)) {
INIT_LOGE("GetServiceNumber, %s is null or is not a number, error.\n", targetField);
INIT_LOGE("GetServiceNumber, %s is null or is not a number, error.", targetField);
return SERVICE_FAILURE;
}
@ -362,7 +361,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
// important value allow < 0
if (strncmp(targetField, IMPORTANT_STR_IN_CFG, strlen(IMPORTANT_STR_IN_CFG)) != 0) {
if (value < 0) {
INIT_LOGE("GetServiceNumber, value = %d, error.\n", value);
INIT_LOGE("GetServiceNumber, value = %d, error.", value);
return SERVICE_FAILURE;
}
}
@ -391,7 +390,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
curServ->attribute |= SERVICE_ATTR_CONSOLE;
}
} else {
INIT_LOGE("GetServiceNumber, item = %s, not expected, error.\n", targetField);
INIT_LOGE("GetServiceNumber, item = %s, not expected, error.", targetField);
return SERVICE_FAILURE;
}
return SERVICE_SUCCESS;
@ -408,7 +407,7 @@ static int GetUidStringNumber(const cJSON *curArrItem, Service *curServ)
char* fieldStr = cJSON_GetStringValue(filedJ);
int uID = DecodeUid(fieldStr);
if (uID < 0) {
INIT_LOGE("GetUidStringNumber, DecodeUid %s error.\n", fieldStr);
INIT_LOGE("GetUidStringNumber, DecodeUid %s error.", fieldStr);
return SERVICE_FAILURE;
}
curServ->servPerm.uID = uID;
@ -418,20 +417,19 @@ static int GetUidStringNumber(const cJSON *curArrItem, Service *curServ)
if (cJSON_IsNumber(filedJ)) {
int uID = (int)cJSON_GetNumberValue(filedJ);
if (uID < 0) {
INIT_LOGE("GetUidStringNumber, uID = %d error.\n", uID);
INIT_LOGE("GetUidStringNumber, uID = %d error.", uID);
return SERVICE_FAILURE;
}
curServ->servPerm.uID = uID;
return SERVICE_SUCCESS;
}
INIT_LOGE("GetUidStringNumber, this uid is neither a string nor a number, error.\n");
INIT_LOGE("GetUidStringNumber, this uid is neither a string nor a number, error.");
return SERVICE_FAILURE;
}
static int ParseServiceSocket(char **opt, const int optNum, struct ServiceSocket *sockopt)
{
INIT_LOGI("ParseServiceSocket\n");
if (optNum != SOCK_OPT_NUMS) {
return -1;
}
@ -502,7 +500,6 @@ static void FreeServiceSocket(struct ServiceSocket *sockopt)
}
static int GetServiceSocket(const cJSON* curArrItem, Service* curServ)
{
INIT_LOGI("GetServiceSocket \n");
cJSON* filedJ = cJSON_GetObjectItem(curArrItem, "socket");
if (!cJSON_IsArray(filedJ)) {
return SERVICE_FAILURE;
@ -544,7 +541,6 @@ static int GetServiceSocket(const cJSON* curArrItem, Service* curServ)
static int GetServiceOnRestart(const cJSON* curArrItem, Service* curServ)
{
INIT_LOGI("GetServiceOnRestart \n");
cJSON* filedJ = cJSON_GetObjectItem(curArrItem, "onrestart");
if (!cJSON_IsArray(filedJ)) {
return SERVICE_FAILURE;
@ -600,7 +596,7 @@ static int CheckServiceKeyName(const cJSON* curService)
if(i < keyListSize) {
child = child->next;
} else {
INIT_LOGE("CheckServiceKeyName, key name %s is not found. error.\n", child->string);
INIT_LOGE("CheckServiceKeyName, key name %s is not found. error.", child->string);
return SERVICE_FAILURE;
}
}
@ -612,20 +608,20 @@ void ParseAllServices(const cJSON* fileRoot)
int servArrSize = 0;
cJSON* serviceArr = GetArrItem(fileRoot, &servArrSize, SERVICES_ARR_NAME_IN_JSON);
if (serviceArr == NULL) {
INIT_LOGE("ParseAllServices, get array %s failed.\n", SERVICES_ARR_NAME_IN_JSON);
INIT_LOGE("ParseAllServices, get array %s failed.", SERVICES_ARR_NAME_IN_JSON);
return;
}
INIT_LOGI("servArrSize is %d \n", servArrSize);
INIT_LOGI("servArrSize is %d ", servArrSize);
if (servArrSize > MAX_SERVICES_CNT_IN_FILE) {
INIT_LOGE("ParseAllServices, too many services[cnt %d] detected, should not exceed %d.\n",
INIT_LOGE("ParseAllServices, too many services[cnt %d] detected, should not exceed %d.",
servArrSize, MAX_SERVICES_CNT_IN_FILE);
return;
}
Service* retServices = (Service*)realloc(g_services, sizeof(Service) * (g_servicesCnt + servArrSize));
if (retServices == NULL) {
INIT_LOGE("ParseAllServices, realloc for %s arr failed! %d.\n", SERVICES_ARR_NAME_IN_JSON, servArrSize);
INIT_LOGE("ParseAllServices, realloc for %s arr failed! %d.", SERVICES_ARR_NAME_IN_JSON, servArrSize);
return;
}
// Skip already saved services,
@ -662,19 +658,19 @@ void ParseAllServices(const cJSON* fileRoot)
INIT_LOGE("ParseAllServices, parse information for service %s failed. ", tmp[i].name);
continue;
} else {
INIT_LOGD("ParseAllServices ParseAllServices Service[%d] name=%s, uid=%d, critical=%d, disabled=%d\n",
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);
}
if (GetServiceSocket(curItem, &tmp[i]) != SERVICE_SUCCESS) {
INIT_LOGE("GetServiceSocket fail \n");
INIT_LOGE("GetServiceSocket fail ");
if (tmp[i].socketCfg != NULL) {
FreeServiceSocket(tmp[i].socketCfg);
tmp[i].socketCfg = NULL;
}
}
if (GetServiceOnRestart(curItem, &tmp[i]) != SERVICE_SUCCESS) {
INIT_LOGE("GetServiceOnRestart fail \n");
INIT_LOGE("GetServiceOnRestart fail ");
}
}
// Increase service counter.
@ -701,12 +697,12 @@ void StartServiceByName(const char* servName)
// find service by name
int servIdx = FindServiceByName(servName);
if (servIdx < 0) {
INIT_LOGE("StartServiceByName, cannot find service %s.\n", servName);
INIT_LOGE("StartServiceByName, cannot find service %s.", servName);
return;
}
if (ServiceStart(&g_services[servIdx]) != SERVICE_SUCCESS) {
INIT_LOGE("StartServiceByName, service %s start failed!\n", g_services[servIdx].name);
INIT_LOGE("StartServiceByName, service %s start failed!", g_services[servIdx].name);
}
return;
@ -717,12 +713,12 @@ void StopServiceByName(const char* servName)
// find service by name
int servIdx = FindServiceByName(servName);
if (servIdx < 0) {
INIT_LOGE("StopServiceByName, cannot find service %s.\n", servName);
INIT_LOGE("StopServiceByName, cannot find service %s.", servName);
return;
}
if (ServiceStop(&g_services[servIdx]) != SERVICE_SUCCESS) {
INIT_LOGE("StopServiceByName, service %s start failed!\n", g_services[servIdx].name);
INIT_LOGE("StopServiceByName, service %s start failed!", g_services[servIdx].name);
}
return;
@ -732,7 +728,7 @@ void StopAllServices()
{
for (int i = 0; i < g_servicesCnt; i++) {
if (ServiceStop(&g_services[i]) != SERVICE_SUCCESS) {
INIT_LOGE("StopAllServices, service %s stop failed!\n", g_services[i].name);
INIT_LOGE("StopAllServices, service %s stop failed!", g_services[i].name);
}
}
}
@ -742,7 +738,7 @@ void StopAllServicesBeforeReboot()
for (int i = 0; i < g_servicesCnt; i++) {
g_services[i].attribute |= SERVICE_ATTR_INVALID;
if (ServiceStop(&g_services[i]) != SERVICE_SUCCESS) {
INIT_LOGE("StopAllServicesBeforeReboot, service %s stop failed!\n", g_services[i].name);
INIT_LOGE("StopAllServicesBeforeReboot, service %s stop failed!", g_services[i].name);
}
}
}

View File

@ -39,7 +39,7 @@ static int CreateSocket(struct ServiceSocket *sockopt)
}
sockopt->sockFd = socket(PF_UNIX, sockopt->type, 0);
if (sockopt->sockFd < 0) {
INIT_LOGE("socket fail %d \n", errno);
INIT_LOGE("socket fail %d ", errno);
return -1;
}
@ -49,9 +49,9 @@ static int CreateSocket(struct ServiceSocket *sockopt)
snprintf(addr.sun_path, sizeof(addr.sun_path), HOS_SOCKET_DIR"/%s",
sockopt->name);
if (access(addr.sun_path, F_OK)) {
INIT_LOGE("%s already exist, remove it\n", addr.sun_path);
INIT_LOGE("%s already exist, remove it", addr.sun_path);
if (unlink(addr.sun_path) != 0) {
INIT_LOGE("ulink fail err %d \n", errno);
INIT_LOGE("ulink fail err %d ", errno);
}
}
if (sockopt->passcred) {
@ -64,7 +64,7 @@ static int CreateSocket(struct ServiceSocket *sockopt)
}
if (bind(sockopt->sockFd, (struct sockaddr *)&addr, sizeof(addr))) {
INIT_LOGE("Create socket for service %s failed: %d\n", sockopt->name, errno);
INIT_LOGE("Create socket for service %s failed: %d", sockopt->name, errno);
unlink(addr.sun_path);
close(sockopt->sockFd);
return -1;
@ -73,17 +73,17 @@ static int CreateSocket(struct ServiceSocket *sockopt)
if (lchown(addr.sun_path, sockopt->uid, sockopt->gid)) {
unlink(addr.sun_path);
close(sockopt->sockFd);
INIT_LOGE("lchown fail %d \n", errno);
INIT_LOGE("lchown fail %d ", errno);
return -1;
}
if (fchmodat(AT_FDCWD, addr.sun_path, sockopt->perm, AT_SYMLINK_NOFOLLOW)) {
unlink(addr.sun_path);
close(sockopt->sockFd);
INIT_LOGE("fchmodat fail %d \n", errno);
INIT_LOGE("fchmodat fail %d ", errno);
return -1;
}
INIT_LOGI("CreateSocket success \n");
INIT_LOGI("CreateSocket success ");
return sockopt->sockFd;
}
@ -95,7 +95,7 @@ static int SetSocketEnv(int fd, char *name)
snprintf(val, sizeof(val), "%d", fd);
int ret = setenv(pubName, val, 1);
if (ret < 0) {
INIT_LOGE("setenv fail %d \n", errno);
INIT_LOGE("setenv fail %d ", errno);
return -1;
}
fcntl(fd, F_SETFD, 0);

View File

@ -45,7 +45,7 @@ static void CheckWaitPid(pid_t sigPID)
{
if (g_waitPid == sigPID && g_waitSem != NULL) {
if (sem_post(g_waitSem) != 0) {
INIT_LOGE("CheckWaitPid, sem_post failed, errno %d.\n", errno);
INIT_LOGE("CheckWaitPid, sem_post failed, errno %d.", errno);
}
g_waitPid = -1;
g_waitSem = NULL;
@ -64,7 +64,7 @@ static void SigHandler(int sig)
if (sigPID <= 0) {
break;
}
INIT_LOGI("SigHandler, SIGCHLD received, sigPID = %d.\n", sigPID);
INIT_LOGI("SigHandler, SIGCHLD received, sigPID = %d.", sigPID);
#ifdef __LINUX__
CheckWaitPid(sigPID);
#endif /* __LINUX__ */
@ -73,7 +73,7 @@ static void SigHandler(int sig)
break;
}
case SIGTERM: {
INIT_LOGI("SigHandler, SIGTERM received.\n");
INIT_LOGI("SigHandler, SIGTERM received.");
StopAllServices();
break;
}
@ -84,7 +84,7 @@ static void SigHandler(int sig)
exit(0);
break;
default:
INIT_LOGI("SigHandler, unsupported signal %d.\n", sig);
INIT_LOGI("SigHandler, unsupported signal %d.", sig);
break;
}
}
@ -116,18 +116,18 @@ void SignalInitModule()
ret |= uv_signal_init(uv_default_loop(), &g_sigtermHandler);
ret |= uv_signal_init(uv_default_loop(), &g_sigintHandler);
if (ret != 0) {
INIT_LOGW("initialize signal handler failed\n");
INIT_LOGW("initialize signal handler failed");
return;
}
if (uv_signal_start(&g_sigchldHandler, UVSignalHandler, SIGCHLD) != 0) {
INIT_LOGW("start SIGCHLD handler failed\n");
INIT_LOGW("start SIGCHLD handler failed");
}
if (uv_signal_start(&g_sigtermHandler, UVSignalHandler, SIGTERM) != 0) {
INIT_LOGW("start SIGTERM handler failed\n");
INIT_LOGW("start SIGTERM handler failed");
}
if (uv_signal_start(&g_sigintHandler, UVSignalHandler, SIGINT) != 0) {
INIT_LOGW("start SIGTERM handler failed\n");
INIT_LOGW("start SIGTERM handler failed");
}
}
#endif

View File

@ -91,17 +91,17 @@ char* ReadFileToBuf(const char *configFile)
do {
if (stat(configFile, &fileStat) != 0 ||
fileStat.st_size <= 0 || fileStat.st_size > MAX_JSON_FILE_LEN) {
INIT_LOGE("Unexpected config file \" %s \", check if it exist. if exist, check file size\n", configFile);
INIT_LOGE("Unexpected config file \" %s \", check if it exist. if exist, check file size", configFile);
break;
}
fd = fopen(configFile, "r");
if (fd == NULL) {
INIT_LOGE("Open %s failed. err = %d\n", configFile, errno);
INIT_LOGE("Open %s failed. err = %d", configFile, errno);
break;
}
buffer = (char*)malloc(fileStat.st_size + 1);
if (buffer == NULL) {
INIT_LOGE("Failed to allocate memory for config file, err = %d\n", errno);
INIT_LOGE("Failed to allocate memory for config file, err = %d", errno);
break;
}
@ -135,7 +135,7 @@ int SplitString(char *srcPtr, char **dstPtr, int maxNum)
dstPtr[i] = "\0";
int num = i;
for (int j = 0; j < num; j++) {
INIT_LOGI("dstPtr[%d] is %s \n", j, dstPtr[j]);
INIT_LOGI("dstPtr[%d] is %s ", j, dstPtr[j]);
}
return num;
}
@ -154,7 +154,7 @@ void WaitForFile(const char *source, unsigned int maxCount)
count++;
} while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (count < maxCount));
if (count == maxCount) {
INIT_LOGE("wait for file:%s failed after %f.\n", source, maxCount * CONVERT_MICROSEC_TO_SEC(waitTime));
INIT_LOGE("wait for file:%s failed after %f.", source, maxCount * CONVERT_MICROSEC_TO_SEC(waitTime));
}
return;
}

View File

@ -12,14 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef OHOS_DEBUG
#include <errno.h>
#include <time.h>
#endif // OHOS_DEBUG
@ -45,10 +44,10 @@ static void PrintSysInfo()
#ifdef OHOS_LITE
const char* sysInfo = GetVersionId();
if (sysInfo != NULL) {
INIT_LOGE("%s\n", sysInfo);
INIT_LOGE("%s", sysInfo);
return;
}
INIT_LOGE("main, GetVersionId failed!\n");
INIT_LOGE("main, GetVersionId failed!");
#endif
}
@ -66,6 +65,12 @@ static long TimeDiffMs(struct timespec* tmBefore, struct timespec* tmAfter)
int main(int argc, char * const argv[])
{
#ifndef OHOS_LITE
if(setenv("UV_THREADPOOL_SIZE", "1", 1) != 0) {
INIT_LOGE("set UV_THREADPOOL_SIZE error : %d.", errno);
}
#endif
#ifdef OHOS_DEBUG
struct timespec tmEnter;
if (clock_gettime(CLOCK_REALTIME, &tmEnter) != 0) {
@ -74,7 +79,7 @@ int main(int argc, char * const argv[])
#endif // OHOS_DEBUG
if (getpid() != INIT_PROCESS_PID) {
INIT_LOGE("main, current process id is %d not %d, failed!\n", getpid(), INIT_PROCESS_PID);
INIT_LOGE("main, current process id is %d not %d, failed!", getpid(), INIT_PROCESS_PID);
return 0;
}
@ -94,7 +99,7 @@ int main(int argc, char * const argv[])
#ifdef OHOS_DEBUG
struct timespec tmSysInfo;
if (clock_gettime(CLOCK_REALTIME, &tmSysInfo) != 0) {
INIT_LOGE("main, after sysinfo, get time failed! err %d.\n", errno);
INIT_LOGE("main, after sysinfo, get time failed! err %d.", errno);
}
#endif // OHOS_DEBUG
@ -104,7 +109,7 @@ int main(int argc, char * const argv[])
#ifdef OHOS_DEBUG
struct timespec tmRcs;
if (clock_gettime(CLOCK_REALTIME, &tmRcs) != 0) {
INIT_LOGE("main, after rcs, get time failed! err %d.\n", errno);
INIT_LOGE("main, after rcs, get time failed! err %d.", errno);
}
#endif // OHOS_DEBUG
// 5. read configuration file and do jobs
@ -112,17 +117,17 @@ int main(int argc, char * const argv[])
#ifdef OHOS_DEBUG
struct timespec tmCfg;
if (clock_gettime(CLOCK_REALTIME, &tmCfg) != 0) {
INIT_LOGE("main, get time failed! err %d.\n", errno);
INIT_LOGE("main, get time failed! err %d.", errno);
}
#endif // OHOS_DEBUG
// 6. keep process alive
#ifdef OHOS_DEBUG
INIT_LOGI("main, time used: sigInfo %ld ms, rcs %ld ms, cfg %ld ms.\n", \
INIT_LOGI("main, time used: sigInfo %ld ms, rcs %ld ms, cfg %ld ms.", \
TimeDiffMs(&tmEnter, &tmSysInfo), TimeDiffMs(&tmSysInfo, &tmRcs), TimeDiffMs(&tmRcs, &tmCfg));
#endif
INIT_LOGI("main, entering wait.\n");
INIT_LOGI("main, entering wait.");
#ifndef OHOS_LITE
StartParamService();
#endif

View File

@ -149,7 +149,7 @@ void Trigger(const char *sysPath)
static void RetriggerUevent()
{
if (access(g_trigger, F_OK) == 0) {
INIT_LOGI("Skip trigger uevent, alread done\n");
INIT_LOGI("Skip trigger uevent, alread done");
return;
}
Trigger("/sys/class");
@ -159,7 +159,7 @@ static void RetriggerUevent()
if (fd >= 0) {
close(fd);
}
INIT_LOGI("Re-trigger uevent done\n");
INIT_LOGI("Re-trigger uevent done");
}
static void UeventSockInit()
@ -177,7 +177,7 @@ static void UeventSockInit()
int sockfd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
if (sockfd < 0) {
INIT_LOGE("Create socket failed. %d\n", errno);
INIT_LOGE("Create socket failed. %d", errno);
return;
}
@ -185,7 +185,7 @@ static void UeventSockInit()
setsockopt(sockfd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
if (bind(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
INIT_LOGE("Bind socket failed. %d\n", errno);
INIT_LOGE("Bind socket failed. %d", errno);
close(sockfd);
return;
}
@ -289,7 +289,7 @@ static int MakeDir(const char *path, mode_t mode)
{
int rc = mkdir(path, mode);
if (rc < 0 && errno != EEXIST) {
INIT_LOGE("Create %s failed. %d\n", path, errno);
INIT_LOGE("Create %s failed. %d", path, errno);
}
return rc;
}
@ -353,7 +353,7 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent)
p = strdup(uevent->partitionName);
CheckValidPartitionName(p);
if (strcmp(uevent->partitionName, p)) {
INIT_LOGI("Linking partition '%s' as '%s'\n", uevent->partitionName, p);
INIT_LOGI("Linking partition '%s' as '%s'", uevent->partitionName, p);
}
if (asprintf(&links[linkNum], "%s/by-name/%s", linkPath, p) > 0) {
linkNum++;
@ -385,23 +385,23 @@ struct DevPermissionMapper {
gid_t gid;
};
struct DevPermissionMapper g_devMapper[] = {
struct DevPermissionMapper DEV_MAPPER[] = {
{"/dev/binder", 0666, 0, 0}
};
static void AdjustDevicePermission(const char *devPath)
{
for (unsigned int i = 0; i < sizeof(g_devMapper) / sizeof(struct DevPermissionMapper); ++i) {
if (strcmp(devPath, g_devMapper[i].devName) == 0) {
if (chmod(g_devMapper[i].devName, g_devMapper[i].devMode) != 0) {
INIT_LOGE("AdjustDevicePermission, failed for %s, err %d.\n", g_devMapper[i].devName, errno);
for (unsigned int i = 0; i < sizeof(DEV_MAPPER) / sizeof(struct DevPermissionMapper); ++i) {
if (strcmp(devPath, DEV_MAPPER[i].devName) == 0) {
if (chmod(devPath, DEV_MAPPER[i].devMode) != 0) {
INIT_LOGE("AdjustDevicePermission, failed for %s, err %d.", devPath, errno);
return;
}
if (chown(g_devMapper[i].devName, g_devMapper[i].uid, g_devMapper[i].gid) != 0) {
INIT_LOGE("AdjustDevicePermission, failed for %s, err %d.\n", g_devMapper[i].devName, errno);
if (chown(devPath, DEV_MAPPER[i].uid, DEV_MAPPER[i].gid) != 0) {
INIT_LOGE("AdjustDevicePermission, failed for %s, err %d.", devPath, errno);
return;
}
INIT_LOGI("AdjustDevicePermission :%s success\n", g_devMapper[i].devName);
INIT_LOGI("AdjustDevicePermission :%s success", devPath);
}
}
}
@ -417,7 +417,7 @@ static void MakeDevice(const char *devPath, const char *path, int block, int maj
setegid(gid);
if (mknod(devPath, mode, dev) != 0) {
if (errno != EEXIST) {
INIT_LOGE("Make device node[%d, %d] failed. %d\n", major, minor, errno);
INIT_LOGE("Make device node[%d, %d] failed. %d", major, minor, errno);
}
}
AdjustDevicePermission(devPath);
@ -440,7 +440,7 @@ int MkdirRecursive(const char *pathName, mode_t mode)
continue;
}
if ((unsigned int)width > sizeof(buf) - 1) {
INIT_LOGE("path too long for MkdirRecursive\n");
INIT_LOGE("path too long for MkdirRecursive");
return -1;
}
if (memcpy_s(buf, width, pathName, width) != 0) {
@ -491,11 +491,11 @@ static void MakeLink(const char *oldPath, const char *newPath)
buf[width] = 0;
int ret = MkdirRecursive(buf, DEFAULT_DIR_MODE);
if (ret) {
INIT_LOGE("Failed to create directory %s: %s (%d)\n", buf, strerror(errno), errno);
INIT_LOGE("Failed to create directory %s: %s (%d)", buf, strerror(errno), errno);
}
ret = symlink(oldPath, newPath);
if (ret && errno != EEXIST) {
INIT_LOGE("Failed to symlink %s to %s: %s (%d)\n", oldPath, newPath, strerror(errno), errno);
INIT_LOGE("Failed to symlink %s to %s: %s (%d)", oldPath, newPath, strerror(errno), errno);
}
}
@ -566,7 +566,7 @@ static void AddPlatformDevice(const char *path)
name += DEV_PLAT_FORM;
}
}
INIT_LOGI("adding platform device %s (%s)\n", name, path);
INIT_LOGI("adding platform device %s (%s)", name, path);
struct PlatformNode *bus = calloc(1, sizeof(struct PlatformNode));
if (!bus) {
return;
@ -586,7 +586,7 @@ static void RemovePlatformDevice(const char *path)
for (node = (&g_platformNames)->prev; node != &g_platformNames; node = node->prev) {
bus = (struct PlatformNode *)(((char*)(node)) - offsetof(struct PlatformNode, list));
if (!strcmp(path, bus->path)) {
INIT_LOGI("removing platform device %s\n", bus->name);
INIT_LOGI("removing platform device %s", bus->name);
free(bus->path);
ListRemove(node);
free(bus);
@ -723,7 +723,7 @@ static void HandleDeviceEvent(struct Uevent *event, char *devpath, int len, cons
links = GetCharacterDeviceSymlinks(event);
if (!devpath[0]) {
if (snprintf_s(devpath, len, len - 1, "%s%s", base, name) == -1) {
INIT_LOGE("snprintf_s err \n");
INIT_LOGE("snprintf_s err ");
goto err;
}
}
@ -834,7 +834,7 @@ void UeventInit()
int main(const int argc, const char **argv)
{
INIT_LOGI("Uevent demo starting...\n");
INIT_LOGI("Uevent demo starting...");
UeventInit();
return 0;
}

View File

@ -34,6 +34,7 @@ if (defined(ohos_lite)) {
"//third_party/cJSON",
"//third_party/bounds_checking_function/include",
"//base/startup/syspara_lite/interfaces/kits",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
]
sources = [
@ -49,15 +50,16 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/services/src/init_signal_handler.c",
"//base/startup/init_lite/services/src/init_utils.c",
"//base/startup/init_lite/services/src/init_reboot.c",
"//base/startup/init_lite/services/log/init_log.c",
"cmd_func_test.cpp",
]
deps = [
"//base/startup/init_lite/initsync:initsync",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/syspara_lite/frameworks/parameter:parameter",
"//build/lite/config/component/cJSON:cjson_shared",
"//third_party/bounds_checking_function:libsec_shared",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
]
if (ohos_kernel_type == "liteos_a") {
include_dirs += [