提交 09f6e68b 编写于 作者: X xionglei6

init: fix code style

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 5f00c532
......@@ -268,7 +268,7 @@ FstabItem *FindFstabItemForPath(Fstab fstab, const char *path)
char tmp[PATH_MAX] = {0};
char *dir = NULL;
if (strncpy_s(tmp, PATH_MAX -1, path, strlen(path)) != EOK) {
if (strncpy_s(tmp, PATH_MAX - 1, path, strlen(path)) != EOK) {
FSMGR_LOGE("Failed to copy path.");
return NULL;
}
......
......@@ -14,7 +14,6 @@
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
......@@ -118,7 +117,6 @@ MountStatus GetMountStatusForMountPoint(const char *mp)
return MOUNT_ERROR;
}
char buffer[FS_MANAGER_BUFFER_SIZE] = {0};
size_t n = 0;
const int expectedItems = 6;
int count = 0;
char **mountItems = NULL;
......@@ -130,7 +128,7 @@ MountStatus GetMountStatusForMountPoint(const char *mp)
return status;
}
while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
n = strlen(buffer);
size_t n = strlen(buffer);
if (buffer[n - 1] == '\n') {
buffer[n - 1] = '\0';
}
......
......@@ -69,7 +69,7 @@ static void ClearLogo(int fd)
return;
}
char buffer[8] = {0}; // logo magic number + logo size is 8
int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 -1) / BLOCK_SZIE_1;
int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 - 1) / BLOCK_SZIE_1;
if (lseek(fd, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) {
std::cout << "Failed to clean file\n";
return;
......@@ -180,7 +180,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
return;
}
int fd = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, 0644);
int fd = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
std::cout << "Failed to open " << miscDev << ", err = " << errno << std::endl;
return;
......@@ -191,7 +191,7 @@ 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, 0644);
int fd1 = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (lseek(fd1, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) {
std::cout << "Failed to seek file\n";
return;
......
......@@ -16,7 +16,6 @@
#include <errno.h>
#include <semaphore.h>
#include <stdio.h>
#include <sys/prctl.h>
#include <sys/reboot.h>
#include <unistd.h>
......
......@@ -12,9 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined OHOS_LITE && !defined __LINUX__
......
......@@ -19,7 +19,6 @@
#include <fcntl.h>
#include <net/if.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
......
......@@ -17,7 +17,6 @@
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __MUSL__
......@@ -38,8 +37,8 @@
#include "securec.h"
#ifdef WITH_SELINUX
# include "init_selinux_param.h"
# include <selinux/selinux.h>
#include "init_selinux_param.h"
#include <selinux/selinux.h>
#endif // WITH_SELINUX
#ifndef TIOCSCTTY
......@@ -172,7 +171,7 @@ static int WritePid(const Service *service)
return SERVICE_SUCCESS;
}
void SetSecon(Service * service)
void SetSecon(Service *service)
{
#ifdef WITH_SELINUX
if (*(service->secon)) {
......
......@@ -14,7 +14,6 @@
*/
#include "init_service_file.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
......
......@@ -14,10 +14,7 @@
*/
#include "init_service_manager.h"
#include <ctype.h>
#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
......@@ -378,7 +375,7 @@ static int AddServiceFile(cJSON *json, Service *service)
return SERVICE_FAILURE;
}
if (opt[SERVICE_FILE_NAME] == NULL || opt[SERVICE_FILE_FLAGS] == NULL || opt[SERVICE_FILE_PERM] == NULL ||
opt[SERVICE_FILE_UID] == NULL || opt[SERVICE_FILE_GID] == NULL) {
opt[SERVICE_FILE_UID] == NULL || opt[SERVICE_FILE_GID] == NULL) {
INIT_LOGE("Invalid file opt");
return SERVICE_FAILURE;
}
......
......@@ -14,7 +14,6 @@
*/
#include "init_service_socket.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
......
......@@ -19,7 +19,6 @@
#include <stdlib.h>
#include <string.h>
#include "init.h"
#include "init_log.h"
#include "init_utils.h"
#include "securec.h"
......
......@@ -14,7 +14,6 @@
*/
#include "init_jobs_internal.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/reboot.h>
......
......@@ -14,7 +14,6 @@
*/
#include "init_service.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
......
......@@ -13,11 +13,9 @@
* limitations under the License.
*/
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h>
#include "init_adapter.h"
#include "init_log.h"
#include "init_service_manager.h"
void ReapService(Service *service)
......
......@@ -12,12 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "init.h"
#include "init_log.h"
static const pid_t INIT_PROCESS_PID = 1;
int main(int argc, char* const argv[])
int main(int argc, char * const argv[])
{
int isSecondStage = 0;
// Number of command line parameters is 2
......
......@@ -34,7 +34,7 @@
#include "ueventd.h"
#include "ueventd_socket.h"
#ifdef WITH_SELINUX
# include <policycoreutils.h>
#include <policycoreutils.h>
#endif // WITH_SELINUX
void SystemInit(void)
......@@ -124,7 +124,7 @@ static void StartInitSecondStage(void)
}
SwitchRoot("/usr");
// Execute init second stage
char *const args[] = {
char * const args[] = {
"/bin/init",
"--second-stage",
NULL,
......
......@@ -14,12 +14,10 @@
*/
#include "init_cmds.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
......@@ -34,7 +32,6 @@
#include <linux/module.h>
#include "fs_manager/fs_manager.h"
#include "fs_manager/fs_manager_log.h"
#include "init.h"
#include "init_jobs_internal.h"
#include "init_log.h"
#include "init_param.h"
......
......@@ -13,9 +13,7 @@
* limitations under the License.
*/
#include "device.h"
#include "fs_manager/fs_manager.h"
#include "init.h"
#include "init_cmds.h"
#include "init_log.h"
#include "securec.h"
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/reboot.h>
......
......@@ -14,7 +14,6 @@
*/
#include "init_service.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h>
#include "init_adapter.h"
......
......@@ -41,7 +41,7 @@ void SetInitLogLevel(InitLogLevel logLevel)
#ifdef OHOS_LITE
static LogLevel ConvertToHiLog(InitLogLevel level)
{
switch (level) {
switch (level) {
case INIT_DEBUG:
return LOG_DEBUG;
case INIT_INFO:
......
......@@ -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;
......
......@@ -171,11 +171,10 @@ void DoCmd(const TestCmdLine *resCmd)
}
/*
** @tc.name: cmdFuncParseCmdTest_001
** @tc.desc: parse function, nullptr test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncParseCmdTest_001
* @tc.desc: parse function, nullptr test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_001, TestSize.Level0)
{
// do not crash
......@@ -183,11 +182,10 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_001, TestSize.Level0)
};
/*
** @tc.name: cmdFuncParseCmdTest_002
** @tc.desc: parse function, invalid strings test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncParseCmdTest_002
* @tc.desc: parse function, invalid strings test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_002, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -211,11 +209,10 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_002, TestSize.Level0)
}
/*
** @tc.name: cmdFuncParseCmdTest_003
** @tc.desc: parse function, cmd content empty test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncParseCmdTest_003
* @tc.desc: parse function, cmd content empty test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_003, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -229,11 +226,10 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_003, TestSize.Level0)
}
/*
** @tc.name: cmdFuncParseCmdTest_004
** @tc.desc: parse function, cmd content too long test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncParseCmdTest_004
* @tc.desc: parse function, cmd content too long test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_004, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -270,11 +266,10 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_004, TestSize.Level0)
}
/*
** @tc.name: cmdFuncParseCmdTest_005
** @tc.desc: parse function, parse success test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncParseCmdTest_005
* @tc.desc: parse function, parse success test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_005, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -302,11 +297,10 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_005, TestSize.Level0)
};
/*
** @tc.name: cmdFuncDoCmdTest_001
** @tc.desc: do cmd function, nullptr test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncDoCmdTest_001
* @tc.desc: do cmd function, nullptr test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_001, TestSize.Level0)
{
// do not crash here
......@@ -314,11 +308,10 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_001, TestSize.Level0)
}
/*
** @tc.name: cmdFuncDoCmdTest_002
** @tc.desc: do cmd function, do start fail test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncDoCmdTest_002
* @tc.desc: do cmd function, do start fail test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_002, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -334,11 +327,10 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_002, TestSize.Level0)
}
/*
** @tc.name: cmdFuncDoCmdTest_003
** @tc.desc: do cmd function, do mkdir fail test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncDoCmdTest_003
* @tc.desc: do cmd function, do mkdir fail test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_003, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -380,11 +372,10 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_003, TestSize.Level0)
}
/*
** @tc.name: cmdFuncDoCmdTest_004
** @tc.desc: do cmd function, do chmod fail test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncDoCmdTest_004
* @tc.desc: do cmd function, do chmod fail test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_004, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -437,11 +428,10 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_004, TestSize.Level0)
}
/*
** @tc.name: cmdFuncDoCmdTest_005
** @tc.desc: do cmd function, do chown fail test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncDoCmdTest_005
* @tc.desc: do cmd function, do chown fail test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_005, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -474,11 +464,10 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_005, TestSize.Level0)
}
/*
** @tc.name: cmdFuncDoCmdTest_006
** @tc.desc: do cmd function, do success test
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cmdFuncDoCmdTest_006
* @tc.desc: do cmd function, do success test
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_006, TestSize.Level0)
{
TestCmdLine curCmdLine;
......@@ -542,11 +531,10 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_006, TestSize.Level0)
}
/*
** @tc.name: cfgCheckStat_001
** @tc.desc: init.cfg file state check
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cfgCheckStat_001
* @tc.desc: init.cfg file state check
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cfgCheckStat_001, TestSize.Level0)
{
struct stat fileStat = {0};
......@@ -807,11 +795,10 @@ static void CheckJobs(const cJSON* fileRoot)
}
/*
** @tc.name: cfgCheckContent_001
** @tc.desc: init.cfg file content check
** @tc.type: FUNC
** @tc.require:
**/
* @tc.name: cfgCheckContent_001
* @tc.desc: init.cfg file content check
* @tc.type: FUNC
*/
HWTEST_F(StartupInitUTest, cfgCheckContent_001, TestSize.Level0)
{
char *fileBuf = ReadFileToBuf();
......@@ -836,7 +823,6 @@ HWTEST_F(StartupInitUTest, cfgCheckContent_001, TestSize.Level0)
* @tc.name: CreateIllegalCfg
* @tc.desc: Create illegal Config file for testing
* @tc.type: FUNC
* @tc.require:
*/
static void CreateIllegalCfg()
{
......@@ -860,7 +846,6 @@ static void CreateIllegalCfg()
* @tc.name: cmdFuncDoLoadCfgTest_001
* @tc.desc: parse function, parse success test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_001, TestSize.Level0)
{
......@@ -876,7 +861,6 @@ HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_001, TestSize.Level0)
* @tc.name: cmdFuncDoLoadCfgTest_002
* @tc.desc: fstab.cfg file fail test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_002, TestSize.Level0)
{
......@@ -916,7 +900,6 @@ HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_002, TestSize.Level0)
* @tc.name: cmdFuncDoLoadCfgTest_003
* @tc.desc: fstab.cfg file success test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_003, TestSize.Level0)
{
......@@ -965,7 +948,6 @@ HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_003, TestSize.Level0)
* @tc.name: cmdJobTest_001
* @tc.desc: job functions test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(StartupInitUTest, cmdJobTest_001, TestSize.Level0)
{
......@@ -985,7 +967,6 @@ HWTEST_F(StartupInitUTest, cmdJobTest_001, TestSize.Level0)
* @tc.name: cmdJobTest_002
* @tc.desc: job functions test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(StartupInitUTest, cmdJobTest_002, TestSize.Level0)
{
......
......@@ -34,6 +34,7 @@
// buffer size refer to kernel kobject uevent
#define UEVENT_BUFFER_SIZE (2048 + 1)
char bootDevice[CMDLINE_VALUE_LEN_MAX] = { 0 };
#define WRITE_SIZE 4
static const char *actions[] = {
[ACTION_ADD] = "add",
......@@ -232,7 +233,7 @@ static void DoTrigger(const char *ueventPath, int sockFd, char **devices, int nu
if (fd < 0) {
INIT_LOGE("Open \" %s \" failed, err = %d", ueventPath, errno);
} else {
ssize_t n = write(fd, "add\n", 4);
ssize_t n = write(fd, "add\n", WRITE_SIZE);
if (n < 0) {
INIT_LOGE("Write \" %s \" failed, err = %d", ueventPath, errno);
close(fd);
......
......@@ -17,7 +17,6 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "ueventd.h"
#define INIT_LOG_TAG "ueventd"
......
......@@ -15,7 +15,6 @@
#include <poll.h>
#include "ueventd.h"
#include "ueventd_device_handler.h"
#include "ueventd_read_cfg.h"
#include "ueventd_socket.h"
#define INIT_LOG_TAG "ueventd"
......
......@@ -204,7 +204,7 @@ int ParseUeventConfig(char *buffer)
callback = funcMapper[type].func;
return 0;
}
return callback != NULL ? callback(p) : -1;
return (callback != NULL) ? callback(p) : -1;
}
static void DoUeventConfigParse(char *buffer, size_t length)
......@@ -332,7 +332,7 @@ bool IsMatch(const char *target, const char *pattern)
while (*p == '*') {
p++;
}
return *p == '\0' ? true : false;
return (*p == '\0') ? true : false;
}
void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode)
......
......@@ -16,7 +16,6 @@
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
......@@ -66,13 +65,13 @@ int main(int argc, const char *argv[])
if (argc >= 2) { // Argument nums greater than or equal to 2.
interval = atoi(argv[1]);
}
interval = interval > 0 ? interval : DEFAULT_INTERVAL;
interval = (interval > 0) ? interval : DEFAULT_INTERVAL;
int gap = 0;
if (argc >= 3) { // Argument nums greater than or equal to 3.
gap = atoi(argv[2]); // 2 second parameter.
}
gap = gap > 0 ? gap : DEFAULT_GAP;
gap = (gap > 0) ? gap : DEFAULT_GAP;
INIT_LOGI("watchdoge started (interval %d, margin %d), fd = %d\n", interval, gap, fd);
......@@ -86,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.
先完成此消息的编辑!
想要评论请 注册