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