提交 ef2dfae1 编写于 作者: S sun_fan

init: fix codedex ..

Signed-off-by: Nsun_fan <sun_fan1@hoperun.com>
上级 be920288
......@@ -15,7 +15,6 @@
#include "dynamic_service.h"
#include <stdio.h>
#include "hilog/log.h"
#include "parameter.h"
......
......@@ -14,6 +14,7 @@
*/
#include "init_socket.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
......
......@@ -43,7 +43,7 @@ int main(int argc, char* argv[])
printf("%s", USAGE_INFO);
return 0;
}
int ret = 0;
int ret;
if (argc == REBOOT_CMD_NUMBER) {
ret = DoReboot(argv[1]);
} else {
......
......@@ -16,12 +16,13 @@
#ifndef BASE_STARTUP_INITLITE_DEVICE_H
#define BASE_STARTUP_INITLITE_DEVICE_H
#include <sys/types.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#include <sys/types.h>
#define DEV_KMSG_MINOR 11
#define DEV_NULL_MINOR 3
......
......@@ -14,6 +14,7 @@
*/
#include "init_log.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
......
......@@ -19,6 +19,13 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef OHOS_LITE
#include "hilog/log.h"
#else
#ifdef INIT_AGENT
#include "hilog/log.h"
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
......@@ -43,7 +50,6 @@ typedef enum InitLogLevel {
#endif
#ifdef OHOS_LITE
#include "hilog/log.h"
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD000719
......@@ -74,7 +80,7 @@ void SetHiLogLevel(LogLevel logLevel);
#define STARTUP_LOGI(LABEL, fmt, ...) InitLog(INIT_INFO, (FILE_NAME), (__LINE__), "<6>", fmt "\n", ##__VA_ARGS__)
#define STARTUP_LOGE(LABEL, fmt, ...) InitLog(INIT_ERROR, (FILE_NAME), (__LINE__), "<3>", fmt "\n", ##__VA_ARGS__)
#else
#include "hilog/log.h"
#define PARAM_AGENT_LOG_PATH "/data/init_agent/init_agent.log"
#define STARTUP_LOGD(LABEL, fmt, ...) \
......
......@@ -109,7 +109,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;
}
......
......@@ -403,9 +403,8 @@ static void DoCopyInernal(const char *source, const char *target)
if (dstFd >= 0) {
char buf[MAX_COPY_BUF_SIZE] = {0};
ssize_t readn = -1;
ssize_t writen = -1;
while ((readn = read(srcFd, buf, MAX_COPY_BUF_SIZE - 1)) > 0) {
writen = WriteAll(dstFd, buf, (size_t)readn);
ssize_t writen = WriteAll(dstFd, buf, (size_t)readn);
if (writen != readn) {
isSuccess = false;
break;
......@@ -499,7 +498,7 @@ static void DoMkDir(const char *cmdContent, int maxArg)
FreeCmd(ctx);
return;
}
int rc = -1;
int rc;
do {
int index = 0;
rc = mkdir(ctx->argv[index], DEFAULT_DIR_MODE);
......@@ -519,12 +518,13 @@ static void DoMkDir(const char *cmdContent, int maxArg)
break;
}
index = index + 1;
if (ctx->argv[index] != NULL) {
if (ctx->argv[index + 1] != NULL) {
rc = Chown(ctx->argv[0], ctx->argv[index], ctx->argv[index + 1]);
} else {
rc = -1;
}
if (ctx->argv[index] == NULL) {
break;
}
if (ctx->argv[index + 1] != NULL) {
rc = Chown(ctx->argv[0], ctx->argv[index], ctx->argv[index + 1]);
} else {
rc = -1;
}
}
} while (0);
......
......@@ -14,7 +14,7 @@
*/
#include "init_import.h"
#include <stdio.h>
#include <unistd.h>
#include "cJSON.h"
#include "init_cmds.h"
......
......@@ -220,8 +220,8 @@ int ServiceStart(Service *service)
service->pid = pid;
#ifndef OHOS_LITE
char paramName[PARAM_NAME_LEN_MAX] = {0};
INIT_CHECK_ONLY_ELOG(snprintf_s(paramName, PARAM_NAME_LEN_MAX, PARAM_NAME_LEN_MAX - 1, "init.svc.%s",
service->name) >= 0, "snprintf_s paramName error %d ", errno);
int ret = snprintf_s(paramName, PARAM_NAME_LEN_MAX, PARAM_NAME_LEN_MAX - 1, "init.svc.%s", service->name);
INIT_CHECK_ONLY_ELOG(ret >= 0, "snprintf_s paramName error %d ", errno);
SystemWriteParam(paramName, "running");
#endif
return SERVICE_SUCCESS;
......
......@@ -768,7 +768,9 @@ void ParseAllServices(const cJSON* fileRoot)
tmp[i].socketCfg = NULL;
}
}
(void)GetServiceOnRestart(curItem, &tmp[i]);
if (GetServiceOnRestart(curItem, &tmp[i]) == SERVICE_FAILURE) {
INIT_LOGE("Failed Get Service OnRestart service");
}
}
// Increase service counter.
RegisterServices(retServices, servArrSize);
......
......@@ -14,6 +14,7 @@
*/
#include "init_service_socket.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
......
......@@ -67,9 +67,7 @@ static long TimeDiffMs(const struct timespec* tmBefore, const struct timespec* t
int main(int argc, char **argv)
{
#ifndef OHOS_LITE
if (setenv("UV_THREADPOOL_SIZE", "1", 1) != 0) {
INIT_LOGE("set UV_THREADPOOL_SIZE error : %d.", errno);
}
INIT_CHECK_ONLY_ELOG(setenv("UV_THREADPOOL_SIZE", "1", 1) == 0, "set UV_THREADPOOL_SIZE error : %d.", errno);
CloseStdio();
OpenLogDevice();
#endif
......
......@@ -167,23 +167,33 @@ static char *FindPlatformDeviceName(char *path)
return NULL;
}
static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent, const char *partitionName)
static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent,
const char *partitionName, const char *deviceName)
{
if (linkNum > BLOCKDEVICE_LINKS - 1) {
INIT_LOGW("Too many links, ignore");
if ((linkNum > BLOCKDEVICE_LINKS - 1) || (linkNum < 0)) {
INIT_LOGW("Failed set linkNum, links ignore");
return;
}
if (parent == NULL || partitionName == NULL || deviceName == NULL) {
return;
}
links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE);
if (links[linkNum] == NULL) {
INIT_LOGE("Failed to allocate memory for link, err = %d", errno);
return;
}
// If a block device without partition name.
// For now, we will not create symbol link for it.
if (!INVALIDSTRING(partitionName)) {
links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE);
if (links[linkNum] == NULL) {
INIT_LOGE("Failed to allocate memory for link, err = %d", errno);
return;
if (snprintf_s(links[linkNum], DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
"/dev/block/platform/%s/by-name/%s", parent, partitionName) == -1) {
INIT_LOGE("Failed to build link");
}
} else if (!INVALIDSTRING(deviceName)) {
// If a device does not have a partition name, create a symbol link for it separately.
if (snprintf_s(links[linkNum], DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
"/dev/block/platform/%s/by-name/%s", parent, partitionName) == -1) {
"/dev/block/platform/%s/%s", parent, deviceName) == -1) {
INIT_LOGE("Failed to build link");
}
}
......@@ -232,7 +242,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
INIT_LOGD("Find a platform device: %s", parent);
parent = FindPlatformDeviceName(parent);
if (parent != NULL) {
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName);
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName);
}
linkNum++;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册