mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-28 10:50:55 +00:00
init: fix codedex
Signed-off-by: xionglei6 <xionglei6@huawei.com>
This commit is contained in:
parent
df51f3bd80
commit
a0bef94581
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
#endif
|
||||
|
@ -291,7 +291,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");
|
||||
|
@ -226,6 +226,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()
|
||||
@ -121,10 +122,11 @@ static void TestPermission()
|
||||
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;
|
||||
int ret = SystemSetParameter(testName, "22202");
|
||||
EXPECT_EQ(ret, DAC_RESULT_FORBIDED);
|
||||
}
|
||||
paramSecurityOps->securityEncodeLabel = TestEncodeSecurityLabel;
|
||||
paramSecurityOps->securityDecodeLabel = TestDecodeSecurityLabel;
|
||||
paramSecurityOps->securityFreeLabel = TestFreeLocalSecurityLabel;
|
||||
@ -291,4 +293,4 @@ int TestCheckParamPermission(const ParamSecurityLabel *srcLabel, const ParamAudi
|
||||
int TestFreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user