提交 ae827657 编写于 作者: L lanxueyuan 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/startup_init_lite into fix-codestyle-check

...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "init_cmds.h" #include "init_cmds.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#endif #endif
#include "init_service_manager.h" #include "init_service_manager.h"
#include "securec.h" #include "securec.h"
...@@ -326,7 +328,6 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt ...@@ -326,7 +328,6 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt
{ {
int fd = -1; int fd = -1;
char options[OPTIONS_SIZE] = {0}; char options[OPTIONS_SIZE] = {0};
if (flags == 0) { // '-f' option if (flags == 0) { // '-f' option
if (restPtr != NULL && secondPtr != NULL) { // Reset arugments, combine then all. if (restPtr != NULL && secondPtr != NULL) { // Reset arugments, combine then all.
if (snprintf_s(options, sizeof(options), OPTIONS_SIZE -1, "%s %s", secondPtr, restPtr) == -1) { if (snprintf_s(options, sizeof(options), OPTIONS_SIZE -1, "%s %s", secondPtr, restPtr) == -1) {
...@@ -339,9 +340,14 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt ...@@ -339,9 +340,14 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt
} }
} else { // Only restPtr is option } else { // Only restPtr is option
if (restPtr != NULL) { if (restPtr != NULL) {
strncpy_s(options, OPTIONS_SIZE - 1, restPtr, strlen(restPtr)); if (strncpy_s(options, OPTIONS_SIZE - 1, restPtr, strlen(restPtr)) != 0) {
goto out;
}
} }
} }
if (!fileName) {
goto out;
}
fd = open(fileName, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); fd = open(fileName, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
if (fd < 0) { if (fd < 0) {
printf("[Init] failed to open %s: %d\n", fileName, errno); printf("[Init] failed to open %s: %d\n", fileName, errno);
...@@ -352,7 +358,7 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt ...@@ -352,7 +358,7 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt
printf("[Init] finit_module for %s failed: %d\n", fileName, errno); printf("[Init] finit_module for %s failed: %d\n", fileName, errno);
} }
out: out:
if (fd > 0) { if (fd >= 0) {
close(fd); close(fd);
} }
return; return;
...@@ -379,12 +385,14 @@ static void DoInsmod(const char *cmdContent) ...@@ -379,12 +385,14 @@ static void DoInsmod(const char *cmdContent)
if (memcpy_s(line, count, cmdContent, count) != EOK) { if (memcpy_s(line, count, cmdContent, count) != EOK) {
printf("[Init] memcpy failed\n"); printf("[Init] memcpy failed\n");
free(line);
return; return;
} }
line[count] = '\0'; line[count] = '\0';
do { do {
if ((p = strtok_r(line, " ", &restPtr)) == NULL) { if ((p = strtok_r(line, " ", &restPtr)) == NULL) {
printf("[Init] debug, cannot get filename\n"); printf("[Init] debug, cannot get filename\n");
free(line);
return; return;
} }
fileName = p; fileName = p;
......
...@@ -152,7 +152,7 @@ static void RetriggerUevent() ...@@ -152,7 +152,7 @@ static void RetriggerUevent()
Trigger("/sys/block"); Trigger("/sys/block");
Trigger("/sys/devices"); Trigger("/sys/devices");
int fd = open(g_trigger, O_WRONLY | O_CREAT | O_CLOEXEC, DEFAULT_MODE); int fd = open(g_trigger, O_WRONLY | O_CREAT | O_CLOEXEC, DEFAULT_MODE);
if (fd > 0) { if (fd >= 0) {
close(fd); close(fd);
} }
printf("Re-trigger uevent done\n"); printf("Re-trigger uevent done\n");
...@@ -220,7 +220,7 @@ ssize_t ReadUevent(int fd, void *buf, size_t len) ...@@ -220,7 +220,7 @@ ssize_t ReadUevent(int fd, void *buf, size_t len)
if (uid != 0) { if (uid != 0) {
goto out; goto out;
} }
if (addr.nl_groups == 0 || addr.nl_pid != 0) { if (addr.nl_groups == 0 || addr.nl_pid != 0) {
/* ignoring non-kernel or unicast netlink message */ /* ignoring non-kernel or unicast netlink message */
goto out; goto out;
...@@ -344,7 +344,8 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent) ...@@ -344,7 +344,8 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent)
if (!links) { if (!links) {
return NULL; return NULL;
} }
if (snprintf_s(linkPath, sizeof(linkPath), sizeof(linkPath), "/dev/block/%s/%s", type, device) == -1) { if (snprintf_s(linkPath, sizeof(linkPath), sizeof(linkPath) - 1, "/dev/block/%s/%s", type, device) == -1) {
free(links);
return NULL; return NULL;
} }
if (uevent->partitionName) { if (uevent->partitionName) {
...@@ -514,7 +515,7 @@ static void HandleBlockDevice(struct Uevent *event) ...@@ -514,7 +515,7 @@ static void HandleBlockDevice(struct Uevent *event)
if (strlen(name) > MAX_DEVICE_LEN) { // too long if (strlen(name) > MAX_DEVICE_LEN) { // too long
return; return;
} }
if (snprintf_s(devpath, sizeof(devpath), sizeof(devpath), "%s/%s", base, name) == -1) { if (snprintf_s(devpath, sizeof(devpath), sizeof(devpath) - 1, "%s/%s", base, name) == -1) {
return; return;
} }
MakeDir(base, DEFAULT_DIR_MODE); MakeDir(base, DEFAULT_DIR_MODE);
...@@ -537,10 +538,14 @@ static void AddPlatformDevice(const char *path) ...@@ -537,10 +538,14 @@ static void AddPlatformDevice(const char *path)
} }
printf("adding platform device %s (%s)\n", name, path); printf("adding platform device %s (%s)\n", name, path);
struct PlatformNode *bus = calloc(1, sizeof(struct PlatformNode)); struct PlatformNode *bus = calloc(1, sizeof(struct PlatformNode));
if (!bus) {
return;
}
bus->path = strdup(path); bus->path = strdup(path);
bus->pathLen = pathLen; bus->pathLen = pathLen;
bus->name = bus->path + (name - path); bus->name = bus->path + (name - path);
ListAddTail(&g_platformNames, &bus->list); ListAddTail(&g_platformNames, &bus->list);
return;
} }
static void RemovePlatformDevice(const char *path) static void RemovePlatformDevice(const char *path)
...@@ -661,7 +666,7 @@ static int HandleUsbDevice(const struct Uevent *event, char *devpath, int len) ...@@ -661,7 +666,7 @@ static int HandleUsbDevice(const struct Uevent *event, char *devpath, int len)
* see drivers/base/core.c * see drivers/base/core.c
*/ */
char *p = devpath; char *p = devpath;
if (snprintf_s(devpath, len, len, "/dev/%s", event->deviceName) == -1) { if (snprintf_s(devpath, len, len - 1, "/dev/%s", event->deviceName) == -1) {
return -1; return -1;
} }
/* skip leading /dev/ */ /* skip leading /dev/ */
...@@ -702,13 +707,21 @@ static void HandleDeviceEvent(struct Uevent *event, char *devpath, int len, cons ...@@ -702,13 +707,21 @@ static void HandleDeviceEvent(struct Uevent *event, char *devpath, int len, cons
char **links = NULL; char **links = NULL;
links = GetCharacterDeviceSymlinks(event); links = GetCharacterDeviceSymlinks(event);
if (!devpath[0]) { if (!devpath[0]) {
if (snprintf_s(devpath, len, len, "%s%s", base, name) == -1) { if (snprintf_s(devpath, len, len - 1, "%s%s", base, name) == -1) {
printf("[Init] snprintf_s err \n"); printf("[Init] snprintf_s err \n");
return; goto err;
} }
} }
HandleDevice(event, devpath, 0, links); HandleDevice(event, devpath, 0, links);
return; return;
err:
if (links) {
for (int i = 0; links[i]; i++) {
free(links[i]);
}
free(links);
}
return;
} }
static void HandleGenericDevice(struct Uevent *event) static void HandleGenericDevice(struct Uevent *event)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册