提交 d510c9cd 编写于 作者: S sun_fan

init: fix codedex ...

Signed-off-by: Nsun_fan <sun_fan1@hoperun.com>
上级 ed5f1d2c
......@@ -74,9 +74,8 @@ int main(int argc, char **argv)
#ifdef OHOS_DEBUG
struct timespec tmEnter;
if (clock_gettime(CLOCK_REALTIME, &tmEnter) != 0) {
INIT_LOGE("main, enter, get time failed! err %d.\n", errno);
}
INIT_CHECK_ONLY_ELOG(clock_gettime(CLOCK_REALTIME, &tmEnter) == 0,
"main, enter, get time failed! err %d.\n", errno);
#endif // OHOS_DEBUG
if (getpid() != INIT_PROCESS_PID) {
......@@ -96,25 +95,21 @@ int main(int argc, char **argv)
#ifdef OHOS_DEBUG
struct timespec tmSysInfo;
if (clock_gettime(CLOCK_REALTIME, &tmSysInfo) != 0) {
INIT_LOGE("main, after sysinfo, get time failed! err %d.", errno);
}
INIT_CHECK_ONLY_ELOG(clock_gettime(CLOCK_REALTIME, &tmSysInfo) == 0,
"main, after sysinfo, get time failed! err %d.", errno);
#endif // OHOS_DEBUG
ExecuteRcs();
#ifdef OHOS_DEBUG
struct timespec tmRcs;
if (clock_gettime(CLOCK_REALTIME, &tmRcs) != 0) {
INIT_LOGE("main, after rcs, get time failed! err %d.", errno);
}
INIT_CHECK_ONLY_ELOG(clock_gettime(CLOCK_REALTIME, &tmRcs) == 0,
"main, after rcs, get time failed! err %d.", errno);
#endif // OHOS_DEBUG
InitReadCfg();
#ifdef OHOS_DEBUG
struct timespec tmCfg;
if (clock_gettime(CLOCK_REALTIME, &tmCfg) != 0) {
INIT_LOGE("main, get time failed! err %d.", errno);
}
INIT_CHECK_ONLY_ELOG(clock_gettime(CLOCK_REALTIME, &tmCfg) == 0, "main, get time failed! err %d.", errno);
#endif // OHOS_DEBUG
#ifdef OHOS_DEBUG
......
......@@ -159,7 +159,7 @@ size_t WriteAll(int fd, const char *buffer, size_t size)
const char *p = buffer;
size_t left = size;
ssize_t written = -1;
ssize_t written;
while (left > 0) {
do {
......@@ -245,6 +245,6 @@ int StringToInt(const char *str, int defaultValue)
}
errno = 0;
int value = (int)strtoul(str, NULL, DECIMAL_BASE);
return errno != 0 ? defaultValue : value;
return ((errno != 0) ? defaultValue : value);
}
......@@ -14,6 +14,7 @@
*/
#include "ueventd.h"
#include <dirent.h>
#include <limits.h>
#include <fcntl.h>
......@@ -205,7 +206,7 @@ static void DoTrigger(const char *ueventPath, int sockFd)
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", strlen("add\n"));
if (n < 0) {
INIT_LOGE("Write \" %s \" failed, err = %d", ueventPath, errno);
close(fd);
......@@ -222,31 +223,33 @@ static void DoTrigger(const char *ueventPath, int sockFd)
static void Trigger(const char *path, int sockFd)
{
DIR *dir = opendir(path);
if (dir != NULL) {
struct dirent *dirent = NULL;
while ((dirent = readdir(dir)) != NULL) {
if (dirent->d_name[0] == '.') {
continue;
}
if (dirent->d_type == DT_DIR) {
char pathBuffer[PATH_MAX];
if (snprintf_s(pathBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, dirent->d_name) == -1) {
continue;
}
Trigger(pathBuffer, sockFd);
} else {
if (!strcmp(dirent->d_name, "uevent")) {
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);
continue;
}
DoTrigger(ueventBuffer, sockFd);
}
}
}
closedir(dir);
if (dir == NULL) {
return;
}
struct dirent *dirent = NULL;
while ((dirent = readdir(dir)) != NULL) {
if (dirent->d_name[0] == '.') {
continue;
}
if (dirent->d_type == DT_DIR) {
char pathBuffer[PATH_MAX];
if (snprintf_s(pathBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, dirent->d_name) == -1) {
continue;
}
Trigger(pathBuffer, sockFd);
} else {
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);
continue;
}
DoTrigger(ueventBuffer, sockFd);
}
}
closedir(dir);
}
static void RetriggerUevent(int sockFd)
......@@ -263,7 +266,6 @@ int main(int argc, char **argv)
{
char *ueventdConfigs[] = {"/etc/ueventd.config", NULL};
int i = 0;
int ret = -1;
while (ueventdConfigs[i] != NULL) {
ParseUeventdConfigFile(ueventdConfigs[i++]);
}
......@@ -280,7 +282,7 @@ int main(int argc, char **argv)
while (1) {
pfd.revents = 0;
ret = poll(&pfd, 1, -1);
int ret = poll(&pfd, 1, -1);
if (ret <= 0) {
continue;
}
......
......@@ -174,7 +174,7 @@ static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent
INIT_LOGW("Failed set linkNum, links ignore");
return;
}
if (parent == NULL || partitionName == NULL || deviceName == NULL) {
if (parent == NULL) {
return;
}
links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE);
......@@ -230,22 +230,24 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
// Reverse walk through sysPath, and check subystem file under each directory.
char *parent = dirname(sysPath);
while (parent != NULL && !STRINGEQUAL(parent, "/") && !STRINGEQUAL(parent, ".")) {
char subsystem[SYSPATH_SIZE];
char subsystem[SYSPATH_SIZE] = {0};
if (snprintf_s(subsystem, SYSPATH_SIZE, SYSPATH_SIZE - 1, "%s/subsystem", parent) == -1) {
INIT_LOGE("Failed to build subsystem path for device \" %s \"", uevent->syspath);
return NULL;
}
char bus[PATH_MAX] = {0};
if (Realpath(subsystem, bus, sizeof(bus)) != NULL) {
if (STRINGEQUAL(bus, "/sys/bus/platform")) {
INIT_LOGD("Find a platform device: %s", parent);
parent = FindPlatformDeviceName(parent);
if (parent != NULL) {
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName);
}
linkNum++;
if (Realpath(subsystem, bus, sizeof(bus)) == NULL) {
parent = dirname(parent);
continue;
}
if (STRINGEQUAL(bus, "/sys/bus/platform")) {
INIT_LOGD("Find a platform device: %s", parent);
parent = FindPlatformDeviceName(parent);
if (parent != NULL) {
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName, uevent->deviceName);
}
linkNum++;
}
parent = dirname(parent);
}
......@@ -302,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
......
......@@ -13,17 +13,12 @@
* limitations under the License.
*/
#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.
// Implement it later.
INIT_LOGI("Firmware handler not implemented yet.");
}
......@@ -16,17 +16,16 @@
#include "ueventd_read_cfg.h"
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "init_utils.h"
#include "list.h"
#include "ueventd_utils.h"
#include "securec.h"
#include "ueventd_utils.h"
#define INIT_LOG_TAG "ueventd"
#include "init_log.h"
......@@ -292,7 +291,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)
......@@ -418,7 +417,7 @@ void ChangeSysAttributePermissions(const char *sysPath)
if (config == NULL) {
return;
}
char sysAttr[SYSPATH_SIZE] = {};
char sysAttr[SYSPATH_SIZE] = {0};
if (config->sysPath != NULL && config->attr != NULL) {
if (snprintf_s(sysAttr, SYSPATH_SIZE, SYSPATH_SIZE - 1, "/sys%s/%s", config->sysPath, config->attr) == -1) {
INIT_LOGE("Failed to build sys attribute for sys path %s, attr: %s", config->sysPath, config->attr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册