提交 0cbac6f4 编写于 作者: O openharmony_ci 提交者: Gitee

!187 代码整改

Merge pull request !187 from 熊磊/startup_init_lite1213
......@@ -92,7 +92,7 @@ static void WriteLogToFile(FILE *fp, const char *fileName, int line, const char
char fullLogMsg[LOG_BUFFER_MAX];
if (snprintf_s(fullLogMsg, LOG_BUFFER_MAX, LOG_BUFFER_MAX - 1, "[%s:%d][%s] %s",
fileName == NULL ? "" : fileName, line, "fs_manager", fmt) == -1) {
(fileName == NULL) ? "" : fileName, line, "fs_manager", fmt) == -1) {
return;
}
(void)fprintf(fp, "%s", fullLogMsg);
......
......@@ -106,8 +106,8 @@ void ReleaseFstabItem(FstabItem *item)
free(item->mountOptions);
item->mountOptions = NULL;
}
free(item);
item = NULL;
}
}
......@@ -179,7 +179,7 @@ static int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts)
return 0;
} while (0);
free(item);
ReleaseFstabItem(item);
item = NULL;
return -1;
}
......
......@@ -44,7 +44,7 @@ static int main_cmd(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 {
......
......@@ -199,6 +199,9 @@ static void WriteLogoToMisc(const std::string &logoPath)
close(fd);
int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 - 1) / BLOCK_SZIE_1;
int fd1 = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd1 < 0) {
return;
}
if (lseek(fd1, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) {
std::cout << "Failed to seek file\n";
close(fd1);
......@@ -209,10 +212,12 @@ static void WriteLogoToMisc(const std::string &logoPath)
uint32_t size = 0;
if (read(fd1, &magic, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n";
close(fd1);
return;
}
if (read(fd1, &size, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n";
close(fd1);
return;
}
......
......@@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "init_service.h"
#include <errno.h>
#include <fcntl.h>
......@@ -32,6 +31,7 @@
#include "init_adapter.h"
#include "init_cmds.h"
#include "init_log.h"
#include "init_service.h"
#include "init_service_socket.h"
#include "init_utils.h"
#include "securec.h"
......@@ -322,7 +322,7 @@ void ServiceReap(Service *service)
}
}
int ret = 0;
int ret;
if (service->restartArg != NULL) {
ret = ExecRestartCmd(service);
INIT_CHECK_ONLY_ELOG(ret == SERVICE_SUCCESS, "Failed to exec restartArg for %s", service->name);
......
......@@ -238,7 +238,7 @@ static int GetUid(cJSON *json, uid_t *uid)
static int GetServiceGids(const cJSON *curArrItem, Service *curServ)
{
int gidCount = 0;
int gidCount;
cJSON *arrItem = cJSON_GetObjectItemCaseSensitive(curArrItem, GID_STR_IN_CFG);
if (!cJSON_IsArray(arrItem)) {
gidCount = 1;
......@@ -327,7 +327,7 @@ static int AddServiceSocket(cJSON *json, Service *service)
if (sockopt->uid == (uid_t)-1 || sockopt->gid == (uid_t)-1) {
free(sockopt);
sockopt = NULL;
INIT_LOGE("Invalid uid %d or gid %d", sockopt->uid, sockopt->gid);
INIT_LOGE("Invalid uid or gid");
return SERVICE_FAILURE;
}
sockopt->passcred = false;
......@@ -401,7 +401,7 @@ static int AddServiceFile(cJSON *json, Service *service)
if (fileOpt->uid == (uid_t)-1 || fileOpt->gid == (gid_t)-1) {
free(fileOpt);
fileOpt = NULL;
INIT_LOGE("Invalid uid %d or gid %d", fileOpt->uid, fileOpt->gid);
INIT_LOGE("Invalid uid or gid");
return SERVICE_FAILURE;
}
fileOpt->fd = -1;
......
......@@ -38,7 +38,7 @@ static void DoExec(const struct CmdArgs *ctx)
}
if (pid == 0) {
if (ctx == NULL || ctx->argv[0] == NULL) {
INIT_LOGE("DoExec: invalid arguments for :%s", ctx->argv[0]);
INIT_LOGE("DoExec: invalid arguments");
_exit(0x7f);
}
int ret = execve(ctx->argv[0], ctx->argv, NULL);
......
......@@ -43,7 +43,7 @@ int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, u
{
INIT_CHECK_RETURN_VALUE((symValue != NULL) && (paramValue != NULL) && (paramLen != 0), -1);
char tmpName[PARAM_NAME_LEN_MAX] = { 0 };
int ret = 0;
int ret;
uint32_t curr = 0;
char *start = (char *)symValue;
char *end = (char *)symValue + symLen;
......
......@@ -21,8 +21,8 @@
int MountRequriedPartitions(const Fstab *fstab)
{
INIT_ERROR_CHECK(fstab != NULL, return -1, "Failed fstab is NULL");
int rc = -1;
int rc;
INIT_LOGI("Mount required partitions");
rc = MountAllWithFstab(fstab, 1);
return rc;
}
\ No newline at end of file
}
......@@ -59,17 +59,17 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage
INIT_CHECK_RETURN_VALUE(realPath != NULL, -1);
int ret = 0;
FILE *fp = fopen(realPath, "rb");
free(realPath);
realPath = NULL;
if (fp != NULL) {
size_t readLen = fread(boot, 1, sizeof(struct RBMiscUpdateMessage), fp);
(void)fclose(fp);
INIT_ERROR_CHECK(readLen > 0, ret = -1, "Failed to read misc for reboot");
} else {
ret = -1;
INIT_LOGE("Failed to open %s", path);
}
free(realPath);
realPath = NULL;
(void)fclose(fp);
return ret;
}
......
......@@ -14,6 +14,7 @@
*/
#include "init_log.h"
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
......@@ -162,4 +163,4 @@ void InitLog(const char *outFileName, InitLogLevel logLevel, const char *kLevel,
fclose(outfile);
return;
}
#endif
\ No newline at end of file
#endif
......@@ -241,7 +241,7 @@ int ParamTaskSendMsg(const ParamTaskPtr stream, const ParamMessage *msg)
LibuvStreamTask *worker = (LibuvStreamTask *)stream;
req->buf = uv_buf_init((char *)msg, msg->msgSize);
int ret = uv_write(&req->writer, (uv_stream_t *)&worker->stream.pipe, &req->buf, 1, OnWriteResponse);
PARAM_CHECK(ret >= 0, LibuvFreeMsg(stream, msg);
PARAM_CHECK(ret >= 0, LibuvFreeMsg(stream, msg); free(req);
return -1, "Failed to uv_write2 ret %s", uv_strerror(ret));
#endif
return 0;
......
......@@ -243,9 +243,12 @@ void WatcherManager::RunLoop()
const int32_t RECV_BUFFER_MAX = 5 * 1024;
std::vector<char> buffer(RECV_BUFFER_MAX, 0);
bool retry = false;
ssize_t recvLen = 0;
while (!stop_) {
int fd = GetServerFd(retry);
ssize_t recvLen = recv(fd, buffer.data(), RECV_BUFFER_MAX, 0);
if (fd >= 0) {
recvLen = recv(fd, buffer.data(), RECV_BUFFER_MAX, 0);
}
if (stop_) {
break;
}
......@@ -291,7 +294,7 @@ int WatcherManager::GetServerFd(bool retry)
do {
serverFd_ = socket(PF_UNIX, SOCK_STREAM, 0);
int flags = fcntl(serverFd_, F_GETFL, 0);
(void)fcntl(serverFd_, F_SETFL, flags & ~ O_NONBLOCK);
(void)fcntl(serverFd_, F_SETFL, flags & ~O_NONBLOCK);
ret = ConntectServer(serverFd_, CLIENT_PIPE_NAME);
if (ret == 0) {
break;
......
......@@ -143,7 +143,7 @@ HWTEST_F(CmdsUnitTest, TestCommonCopy, TestSize.Level1)
HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1)
{
const char *testFile1 = "/data/init_ut/test_dir0/test_file_write1";
int fd = open(testFile1, O_RDWR | O_CREAT);
int fd = open(testFile1, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
ASSERT_GE(fd, 0);
DoCmdByName("write ", "/data/init_ut/test_dir0/test_file_write1 aaa");
......@@ -221,7 +221,7 @@ HWTEST_F(CmdsUnitTest, TestGetCmdLinesFromJson, TestSize.Level1)
cJSON *cmdsItem1 = cJSON_GetArrayItem(cmdsItem, 0);
ASSERT_NE(nullptr, cmdsItem1);
CmdLines **cmdLines = (CmdLines **)calloc(1, 1);
CmdLines **cmdLines = (CmdLines **)calloc(1, sizeof(CmdLines *));
ASSERT_NE(nullptr, cmdLines);
int ret = GetCmdLinesFromJson(cmdsItem1, cmdLines);
EXPECT_EQ(ret, -1);
......
......@@ -49,7 +49,7 @@ HWTEST_F(ServiceFileUnitTest, TestServiceFile, TestSize.Level1)
if (strncpy_s(fileOpt->fileName, strlen(fileName) + 1, fileName, strlen(fileName)) != 0) {
free(fileOpt);
fileOpt = nullptr;
ASSERT_TRUE(1);
FAIL();
}
CreateServiceFile(fileOpt);
int ret = GetControlFile("/data/filetest");
......
......@@ -21,6 +21,7 @@
#include "init_service_manager.h"
#include "init_service_socket.h"
#include "init_unittest.h"
#include "init_utils.h"
#include "securec.h"
using namespace testing::ext;
......@@ -226,6 +227,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
ret = SetImportantValue(service, "", invalidImportantValue, 1);
EXPECT_EQ(ret, -1);
if (service != nullptr) {
FreeStringVector(service->pathArgs.argv, service->pathArgs.count);
free(service);
service = nullptr;
}
......
......@@ -97,7 +97,8 @@ static void TestParamTraversal()
u_int32_t len = PARAM_BUFFER_SIZE;
SystemGetParameterValue(handle, ((char *)value) + PARAM_BUFFER_SIZE, &len);
printf("$$$$$$$$Param %s=%s \n", (char *)value, ((char *)value) + PARAM_BUFFER_SIZE);
}, nullptr);
},
nullptr);
}
static void TestPersistParam()
......@@ -117,14 +118,16 @@ static void TestPermission()
{
const char *testName = "persist.111.ffff.bbbb.cccc.dddd.eeee.55555";
char tmp[PARAM_BUFFER_SIZE] = { 0 };
int ret;
// 允许本地校验
ParamSecurityOps *paramSecurityOps = &GetClientParamWorkSpace()->paramSecurityOps;
paramSecurityOps->securityCheckParamPermission = TestCheckParamPermission;
g_testPermissionResult = DAC_RESULT_FORBIDED;
GetClientParamWorkSpace()->securityLabel->flags = LABEL_CHECK_FOR_ALL_PROCESS;
int ret = SystemSetParameter(testName, "22202");
EXPECT_EQ(ret, DAC_RESULT_FORBIDED);
if ((GetClientParamWorkSpace() != nullptr) && (GetClientParamWorkSpace()->securityLabel != nullptr)) {
GetClientParamWorkSpace()->securityLabel->flags = LABEL_CHECK_FOR_ALL_PROCESS;
ret = SystemSetParameter(testName, "22202");
EXPECT_EQ(ret, DAC_RESULT_FORBIDED);
}
paramSecurityOps->securityEncodeLabel = TestEncodeSecurityLabel;
paramSecurityOps->securityDecodeLabel = TestDecodeSecurityLabel;
paramSecurityOps->securityFreeLabel = TestFreeLocalSecurityLabel;
......@@ -291,4 +294,4 @@ int TestCheckParamPermission(const ParamSecurityLabel *srcLabel, const ParamAudi
int TestFreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
{
return 0;
}
\ No newline at end of file
}
......@@ -262,7 +262,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName);
}
linkNum++;
if (STRINGEQUAL(parent, bootDevice)) {
if ((parent != NULL) && STRINGEQUAL(parent, bootDevice)) {
BuildBootDeviceSymbolLink(links, linkNum, uevent->partitionName);
linkNum++;
}
......
......@@ -85,7 +85,7 @@ int main(int argc, const char *argv[])
if (ret) {
INIT_LOGE("Failed to get timeout\n");
} else {
interval = (timeoutGet > gap) ? timeoutGet - gap : 1;
interval = (timeoutGet > gap) ? (timeoutGet - gap) : 1;
}
while (1) {
ioctl(fd, WDIOC_KEEPALIVE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册