init: fix codedex

Signed-off-by: sun_fan <sun_fan1@hoperun.com>
This commit is contained in:
sun_fan 2021-10-15 19:23:39 +08:00
parent f88b96f4be
commit 8d948a8b02
20 changed files with 105 additions and 92 deletions

View File

@ -13,16 +13,11 @@
* limitations under the License.
*/
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <limits.h>
#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <sys/mount.h>
@ -33,6 +28,12 @@ extern "C" {
#include "init_utils.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
struct FsManagerFlags {
char *name;
unsigned int flags;
@ -238,14 +239,14 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
}
// If one line in fstab file parsed with a failure. just give a warning
// and skip it.
printf("[fs_manager][warning] Cannot parse file \" %s \" at line %u. skip it\n", file, ln);
printf("[fs_manager][warning] Cannot parse file \" %s \" at line %zu. skip it\n", file, ln);
continue;
}
}
if (line != NULL) {
free(line);
}
fclose(fp);
(void)fclose(fp);
fp = NULL;
return fstab;
}
@ -312,7 +313,8 @@ static const struct MountFlags mountFlags[] = {
{ "defaults", 0 },
};
static bool IsDefaultMountFlags(const char *str) {
static bool IsDefaultMountFlags(const char *str)
{
bool isDefault = false;
if (str != NULL) {
@ -340,11 +342,11 @@ static unsigned long ParseDefaultMountFlag(const char *str)
return flags;
}
unsigned long GetMountFlags(char *mountFlags, char *fsSpecificData, size_t fsSpecificDataSize)
unsigned long GetMountFlags(char *flags, char *fsSpecificData, size_t fsSpecificDataSize)
{
unsigned long flags = 0;
if (mountFlags == NULL || fsSpecificData == NULL) {
if (flags == NULL || fsSpecificData == NULL) {
return 0;
}
@ -356,7 +358,7 @@ unsigned long GetMountFlags(char *mountFlags, char *fsSpecificData, size_t fsSpe
// If the item configured in fstab contains flag over than 15,
// @SplitStringExt can handle it and parse them all. but the parse function will drop it.
const int maxCount = 15;
char **flagsVector = SplitStringExt(mountFlags, ",", &flagCount, maxCount);
char **flagsVector = SplitStringExt(flags, ",", &flagCount, maxCount);
if (flagsVector == NULL || flagCount == 0) {
// No flags or something wrong in SplitStringExtjust return.

View File

@ -13,11 +13,6 @@
* limitations under the License.
*/
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -33,7 +28,15 @@ extern "C" {
#include "init_utils.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#define FS_MANAGER_BUFFER_SIZE 512
#define BLOCK_SIZE_BUFFER (64)
bool IsSupportedFilesystem(const char *fsType)
{
static const char *supportedFilesystem[] = {"ext4", "f2fs", NULL};
@ -84,7 +87,6 @@ int DoFormat(const char *devPath, const char *fsType)
return -1;
}
int ret = 0;
#define BLOCK_SIZE_BUFFER (64)
char blockSizeBuffer[BLOCK_SIZE_BUFFER] = {0};
if (strcmp(fsType, "ext4") == 0) {
const unsigned int blockSize = 4096;
@ -106,7 +108,6 @@ int DoFormat(const char *devPath, const char *fsType)
char **argv = (char **)formatCmds;
ret = ExecCommand(argc, argv);
}
#undef BLOCK_SIZE_BUFFER
return ret;
}
@ -148,7 +149,7 @@ MountStatus GetMountStatusForMountPoint(const char *mp)
} else if (feof(fp) > 0) {
status = MOUNT_UMOUNTED;
}
fclose(fp);
(void)fclose(fp);
fp = NULL;
return status;
}
@ -260,7 +261,7 @@ int UmountAllWithFstabFile(const char *fstabFile)
Fstab *fstab = NULL;
if ((fstab = ReadFstabFromFile(fstabFile, false)) == NULL) {
printf("[fs_manager][error] Read fstab file \" %s \" failed\n", fstabFile);
return -1;;
return -1;
}
FstabItem *item = NULL;

View File

@ -16,12 +16,13 @@
#ifndef STARTUP_FS_MANAGER_H
#define STARTUP_FS_MANAGER_H
#include <stdbool.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#include <stdbool.h>
/* Fs manager flags definition */
#define FS_MANAGER_CHECK 0x00000001
@ -65,7 +66,7 @@ int MountOneItem(FstabItem *item);
MountStatus GetMountStatusForMountPoint(const char *mp);
int MountAllWithFstabFile(const char *file, bool required);
int UmountAllWithFstabFile(const char *file);
unsigned long GetMountFlags(char *mountFlags, char *fsSpecificFlags, size_t fsSpecificFlagSize);
unsigned long GetMountFlags(char *flags, char *fsSpecificFlags, size_t fsSpecificFlagSize);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -15,5 +15,7 @@
#ifndef INIT_SWITCH_ROOT_H
#define INIT_SWITCH_ROOT_H
int SwitchRoot(const char *newRoot);
#endif // INIT_SWITCH_ROOT_H

View File

@ -37,7 +37,7 @@ void SystemInit(void)
void LogInit(void)
{
return;
}
void SystemPrepare(void)

View File

@ -12,11 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "init_cmds.h"
#include <stdlib.h>
#include <string.h>
#include "init.h"
#include "init_cmds.h"
#include "init_log.h"
#include "init_utils.h"
#include "securec.h"

View File

@ -20,6 +20,7 @@ static const pid_t INIT_PROCESS_PID = 1;
int main(int argc, char* const argv[])
{
int isSecondStage = 0;
// Number of command line parameters is 2
if (argc == 2 && (strcmp(argv[1], "--second-stage") == 0)) {
isSecondStage = 1;
}

View File

@ -32,13 +32,13 @@
#include <sys/wait.h>
#include <unistd.h>
#include "fs_manager/fs_manager.h"
#include "init.h"
#include "init_jobs.h"
#include "init_log.h"
#include "init_param.h"
#include "init_service_manager.h"
#include "init_utils.h"
#include "fs_manager/fs_manager.h"
#include "securec.h"
int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, unsigned int paramLen)

View File

@ -54,7 +54,9 @@ static void FreeOldRoot(DIR *dir, dev_t dev)
if (S_ISDIR(st.st_mode)) {
int fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
isDir = true;
if (fd >= 0) {
if (fd < 0) {
continue;
}
DIR *subDir = fdopendir(fd);
if (subDir != NULL) {
FreeOldRoot(subDir, dev);
@ -64,7 +66,6 @@ static void FreeOldRoot(DIR *dir, dev_t dev)
}
}
}
}
if (unlinkat(dfd, de->d_name, isDir ? AT_REMOVEDIR : 0) < 0) {
INIT_LOGE("Failed to unlink %s, err = %d", de->d_name, errno);
}

View File

@ -20,6 +20,14 @@
#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
extern "C" {
@ -45,7 +53,6 @@ void SetInitLogLevel(InitLogLevel logLevel);
#endif
#ifdef OHOS_LITE
#include "hilog/log.h"
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD000719
@ -79,7 +86,6 @@ void InitToHiLog(InitLogLevel logLevel, const char *fmt, ...);
#define LABEL "ParamAgent"
#endif
#include "hilog/log.h"
#define PARAM_AGENT_LOG_PATH "/data/init_agent/init_agent.log"
#define STARTUP_LOGD(LABEL, fmt, ...) \

View File

@ -314,7 +314,7 @@ int ParamTimerStart(ParamTaskPtr timer, uint64_t timeout, uint64_t repeat)
return -1;
}
int ParamServiceStart()
int ParamServiceStart(void)
{
if (uv_default_loop() == NULL) {
return -1;

View File

@ -112,7 +112,7 @@ static void ExeuteCmdParamRead(int argc, char *argv[], int start)
SystemSetParameter("test.randrom.test.start", "1");
char buffer[PARAM_NAME_LEN_MAX] = {0};
printf("SystemGetParameter start \n");
srand((unsigned)time(NULL));
(void)srand((unsigned)time(NULL));
while (1) {
int wait = rand() / READ_DURATION + READ_DURATION; // 100ms
uint32_t size = PARAM_NAME_LEN_MAX;
@ -170,17 +170,6 @@ int RunParamCommand(int argc, char *argv[])
space->securityLabel->cred.gid = testUid;
}
#endif
if ((strcmp(argv[0], "./paramset") == 0) || (strcmp(argv[0], "paramset") == 0)) {
if (argc == (MIN_ARGC + 1)) {
ExeuteCmdParamSet(argc, argv, 1);
} else {
printf("param set key value \n");
}
return 0;
} else if ((strcmp(argv[0], "./paramget") == 0) || (strcmp(argv[0], "paramget") == 0)) {
ExeuteCmdParamSet(argc, argv, 1);
return 0;
}
if (argc < MIN_ARGC) {
printf("usage: \n");
for (size_t i = 0; i < sizeof(paramCmds) / sizeof(paramCmds[0]); i++) {

View File

@ -104,7 +104,7 @@ typedef struct {
} ParamStreamInfo;
int ParamServiceStop(void);
int ParamServiceStart();
int ParamServiceStart(void);
int ParamTaskClose(ParamTaskPtr stream);
int ParamServerCreate(ParamTaskPtr *server, const ParamStreamInfo *info);

View File

@ -43,7 +43,7 @@ static void AddTestTrigger(const TriggerWorkSpace *workSpace)
static void TestTimerCallback(ParamTaskPtr timer, void *context)
{
srand((unsigned)time(NULL));
(void)srand((unsigned)time(NULL));
char buffer[32] = { 0 };
static int index = 0;
index++;
@ -54,7 +54,7 @@ static void TestTimerCallback(ParamTaskPtr timer, void *context)
int count = 0;
while (count < MAX_COUNT) {
int wait = rand() / READ_DURATION + READ_DURATION; // 100ms
sprintf_s(buffer, sizeof(buffer), "%u", value);
(void)sprintf_s(buffer, sizeof(buffer), "%u", value);
PARAM_LOGI("set param name: %s, value %s", TEST_PARAM_NAME, buffer);
SystemWriteParam(TEST_PARAM_NAME, buffer);
usleep(wait);

View File

@ -73,7 +73,10 @@ private:
DISALLOW_COPY_AND_MOVE(DeathRecipient);
void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
};
sptr<IRemoteObject::DeathRecipient> GetDeathRecipient() { return deathRecipient_; }
sptr<IRemoteObject::DeathRecipient> GetDeathRecipient()
{
return deathRecipient_;
}
private:
void SetParamWatcher(const std::string &keyPrefix, ParamWatcherKitPtr watcher);

View File

@ -173,7 +173,7 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
int count = 0;
while (p != NULL) {
if (count > itemCounts - 1) {
itemCounts += (itemCounts / 2) + 1;
itemCounts += (itemCounts / 2) + 1; // Request to increase the original memory by half.
INIT_LOGD("Too many items,expand size");
char **expand = (char **)(realloc(items, sizeof(char *) * itemCounts));
if (expand == NULL) {

View File

@ -221,8 +221,13 @@ static void DoTrigger(const char *ueventPath, int sockFd)
static void Trigger(const char *path, int sockFd)
{
if (path == NULL) {
return;
}
DIR *dir = opendir(path);
if (dir != NULL) {
if (dir == NULL) {
return;
}
struct dirent *dirent = NULL;
while ((dirent = readdir(dir)) != NULL) {
if (dirent->d_name[0] == '.') {
@ -235,7 +240,9 @@ static void Trigger(const char *path, int sockFd)
}
Trigger(pathBuffer, sockFd);
} else {
if (!strcmp(dirent->d_name, "uevent")) {
if (strcmp(dirent->d_name, "uevent") != 0) {
continue;
}
char ueventBuffer[PATH_MAX];
if (snprintf_s(ueventBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, "uevent") == -1) {
INIT_LOGW("Cannnot build uevent path under %s", path);
@ -244,10 +251,8 @@ static void Trigger(const char *path, int sockFd)
DoTrigger(ueventBuffer, sockFd);
}
}
}
closedir(dir);
}
}
static void RetriggerUevent(int sockFd)
{

View File

@ -304,7 +304,7 @@ static const char *GetDeviceName(char *sysPath, const char *deviceName)
}
if (deviceName != NULL && deviceName[0] != '\0') {
// if device name reported by kernel includes '/', skip it.
// TODO: use entire device name reported by kernel
// use entire device name reported by kernel
devName = basename((char *)deviceName);
char *p = strrchr(deviceName, '/');
if (p != NULL) { // device name includes slash

View File

@ -13,17 +13,17 @@
* limitations under the License.
*/
#include "ueventd_firmware_handler.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "ueventd_firmware_handler.h"
#include "ueventd.h"
#define INIT_LOG_TAG "ueventd"
#include "init_log.h"
void HandleFimwareDeviceEvent(const struct Uevent *uevent)
{
// TODO, implement it later.
INIT_LOGI("Firmware handler not implemented yet.");
}