提交 9aba3b3a 编写于 作者: O openharmony_ci 提交者: Gitee

!202 fix: codedex

Merge pull request !202 from 熊磊/init1225
...@@ -28,13 +28,11 @@ static struct CMD_LIST_ST *m_cmdList = NULL; ...@@ -28,13 +28,11 @@ static struct CMD_LIST_ST *m_cmdList = NULL;
int BegetCtlCmdAdd(const char *name, BegetCtlCmdPtr cmd) int BegetCtlCmdAdd(const char *name, BegetCtlCmdPtr cmd)
{ {
struct CMD_LIST_ST *item;
if (name == NULL) { if (name == NULL) {
return -1; return -1;
} }
item = (struct CMD_LIST_ST *)malloc(sizeof(struct CMD_LIST_ST)); struct CMD_LIST_ST *item = (struct CMD_LIST_ST *)malloc(sizeof(struct CMD_LIST_ST));
if (item == NULL) { if (item == NULL) {
return -1; return -1;
} }
...@@ -83,7 +81,6 @@ static void BegetCtlUsage(const char *command) ...@@ -83,7 +81,6 @@ static void BegetCtlUsage(const char *command)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
const struct CMD_LIST_ST *cmd;
const char *last = strrchr(argv[0], '/'); const char *last = strrchr(argv[0], '/');
// Get the first ending command name // Get the first ending command name
...@@ -101,7 +98,7 @@ int main(int argc, char **argv) ...@@ -101,7 +98,7 @@ int main(int argc, char **argv)
} }
// Match the command // Match the command
cmd = BegetCtlCmdFind(last); const struct CMD_LIST_ST *cmd = BegetCtlCmdFind(last);
if (cmd == NULL) { if (cmd == NULL) {
BegetCtlUsage(last); BegetCtlUsage(last);
return 0; return 0;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <stropts.h> #include <stropts.h>
#endif #endif
#include <sys/capability.h> #include <sys/capability.h>
#include <sys/ioctl.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
...@@ -72,8 +73,8 @@ static int SetPerms(const Service *service) ...@@ -72,8 +73,8 @@ static int SetPerms(const Service *service)
"SetPerms, setgid for %s failed. %d", service->name, errno); "SetPerms, setgid for %s failed. %d", service->name, errno);
} }
if (service->servPerm.gIDCnt > 1) { if (service->servPerm.gIDCnt > 1) {
INIT_ERROR_CHECK(setgroups(service->servPerm.gIDCnt - 1, &service->servPerm.gIDArray[1]) == 0, INIT_ERROR_CHECK(setgroups(service->servPerm.gIDCnt - 1, (const gid_t *)&service->servPerm.gIDArray[1]) == 0,
return SERVICE_FAILURE, return SERVICE_FAILURE,
"SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt); "SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt);
} }
if (service->servPerm.uID != 0) { if (service->servPerm.uID != 0) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
#include <strings.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/uio.h> #include <sys/uio.h>
...@@ -34,7 +35,7 @@ ...@@ -34,7 +35,7 @@
static int GetSocketAddr(struct sockaddr_un *addr, const char *name) static int GetSocketAddr(struct sockaddr_un *addr, const char *name)
{ {
bzero(addr, sizeof(struct sockaddr_un)); (void)memset_s(addr, sizeof(struct sockaddr_un), 0x0, sizeof(struct sockaddr_un));
addr->sun_family = AF_UNIX; addr->sun_family = AF_UNIX;
size_t addrLen = sizeof(addr->sun_path); size_t addrLen = sizeof(addr->sun_path);
int ret = snprintf_s(addr->sun_path, addrLen, addrLen - 1, HOS_SOCKET_DIR "/%s", name); int ret = snprintf_s(addr->sun_path, addrLen, addrLen - 1, HOS_SOCKET_DIR "/%s", name);
......
...@@ -48,16 +48,16 @@ static int RBMiscWriteUpdaterMessage(const char *path, const struct RBMiscUpdate ...@@ -48,16 +48,16 @@ static int RBMiscWriteUpdaterMessage(const char *path, const struct RBMiscUpdate
INIT_CHECK_RETURN_VALUE(realPath != NULL, -1); INIT_CHECK_RETURN_VALUE(realPath != NULL, -1);
int ret = 0; int ret = 0;
FILE *fp = fopen(realPath, "rb+"); FILE *fp = fopen(realPath, "rb+");
free(realPath);
realPath = NULL;
if (fp != NULL) { if (fp != NULL) {
size_t writeLen = fwrite(boot, sizeof(struct RBMiscUpdateMessage), 1, fp); size_t writeLen = fwrite(boot, sizeof(struct RBMiscUpdateMessage), 1, fp);
INIT_ERROR_CHECK(writeLen == 1, ret = -1, "Failed to write misc for reboot"); INIT_ERROR_CHECK(writeLen == 1, ret = -1, "Failed to write misc for reboot");
(void)fclose(fp);
} else { } else {
ret = -1; ret = -1;
INIT_LOGE("Failed to open %s", path); INIT_LOGE("Failed to open %s", path);
} }
free(realPath);
realPath = NULL;
(void)fclose(fp);
return ret; return ret;
} }
......
...@@ -265,7 +265,7 @@ void WaitForFile(const char *source, unsigned int maxCount) ...@@ -265,7 +265,7 @@ void WaitForFile(const char *source, unsigned int maxCount)
unsigned int maxCountTmp = maxCount; unsigned int maxCountTmp = maxCount;
INIT_ERROR_CHECK(maxCountTmp <= WAIT_MAX_COUNT, maxCountTmp = WAIT_MAX_COUNT, "WaitForFile max time is 5s"); INIT_ERROR_CHECK(maxCountTmp <= WAIT_MAX_COUNT, maxCountTmp = WAIT_MAX_COUNT, "WaitForFile max time is 5s");
struct stat sourceInfo = {}; struct stat sourceInfo = {};
const unsigned int waitTime = 500000; unsigned int waitTime = 500000;
unsigned int count = 0; unsigned int count = 0;
do { do {
usleep(waitTime); usleep(waitTime);
......
...@@ -37,9 +37,11 @@ const std::string TEST_DRI = ROOT_DIR + "StartInitTestDir"; ...@@ -37,9 +37,11 @@ const std::string TEST_DRI = ROOT_DIR + "StartInitTestDir";
const std::string TEST_FILE = TEST_DRI + "/test.txt"; const std::string TEST_FILE = TEST_DRI + "/test.txt";
const std::string TEST_CFG_ILLEGAL = TEST_DRI + "/illegal.cfg"; const std::string TEST_CFG_ILLEGAL = TEST_DRI + "/illegal.cfg";
const std::string TEST_PROC_MOUNTS = "/proc/mounts"; const std::string TEST_PROC_MOUNTS = "/proc/mounts";
#ifndef USE_EMMC_STORAGE
const uid_t TEST_FILE_UID = 999; const uid_t TEST_FILE_UID = 999;
const gid_t TEST_FILE_GID = 999; const gid_t TEST_FILE_GID = 999;
const mode_t TEST_FILE_MODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; const mode_t TEST_FILE_MODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
#endif
// init.cfg releated // init.cfg releated
const std::string CFG_FILE = "/etc/init.cfg"; const std::string CFG_FILE = "/etc/init.cfg";
......
...@@ -103,7 +103,7 @@ HWTEST_F(CmdsUnitTest, TestCommonChmod, TestSize.Level1) ...@@ -103,7 +103,7 @@ HWTEST_F(CmdsUnitTest, TestCommonChmod, TestSize.Level1)
{ {
const char *testFile = "/data/init_ut/test_dir0/test_file0"; const char *testFile = "/data/init_ut/test_dir0/test_file0";
const mode_t testMode = S_IRWXU | S_IRWXG | S_IRWXO; const mode_t testMode = S_IRWXU | S_IRWXG | S_IRWXO;
int fd = open(testFile, O_CREAT | O_WRONLY); int fd = open(testFile, O_CREAT | O_WRONLY, testMode);
ASSERT_GE(fd, 0); ASSERT_GE(fd, 0);
DoCmdByName("chmod ", "777 /data/init_ut/test_dir0/test_file0"); DoCmdByName("chmod ", "777 /data/init_ut/test_dir0/test_file0");
struct stat info; struct stat info;
......
...@@ -133,13 +133,13 @@ static void HandleUeventRequired(const struct Uevent *uevent, char **devices, in ...@@ -133,13 +133,13 @@ static void HandleUeventRequired(const struct Uevent *uevent, char **devices, in
if (uevent->partitionName == NULL) { if (uevent->partitionName == NULL) {
INIT_LOGI("Match with %s for %s", devices[i], uevent->syspath); INIT_LOGI("Match with %s for %s", devices[i], uevent->syspath);
deviceName = strstr(devices[i], "/dev/block"); deviceName = strstr(devices[i], "/dev/block");
if (deviceName != NULL) { INIT_INFO_CHECK(deviceName != NULL, continue,
deviceName += sizeof("/dev/block") - 1; "device %s not match \"/dev/block\".", devices[i]);
if (strstr(uevent->syspath, deviceName) != NULL) { deviceName += sizeof("/dev/block") - 1;
HandleBlockDeviceEvent(uevent); INIT_INFO_CHECK(strstr(uevent->syspath, deviceName) != NULL, continue,
break; "uevent->syspath %s not match deviceName %s", uevent->syspath, deviceName);
} HandleBlockDeviceEvent(uevent);
} break;
} else if (strstr(devices[i], uevent->partitionName) != NULL) { } else if (strstr(devices[i], uevent->partitionName) != NULL) {
INIT_LOGI("Handle block device partitionName %s", uevent->partitionName); INIT_LOGI("Handle block device partitionName %s", uevent->partitionName);
HandleBlockDeviceEvent(uevent); HandleBlockDeviceEvent(uevent);
......
...@@ -41,7 +41,7 @@ static void WaitAtStartup(const char *source) ...@@ -41,7 +41,7 @@ static void WaitAtStartup(const char *source)
{ {
unsigned int count = 0; unsigned int count = 0;
struct stat sourceInfo; struct stat sourceInfo;
const unsigned int waitTime = 500000; unsigned int waitTime = 500000;
do { do {
usleep(waitTime); usleep(waitTime);
count++; count++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册