提交 f935364b 编写于 作者: O openharmony_ci 提交者: Gitee

!25 updater init

Merge pull request !25 from chengjinsong/updater_0429
......@@ -13,12 +13,12 @@
* limitations under the License.
*/
#include <errno.h>
#include <sys/sysmacros.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define DEFAULT_RW_MODE 0666
#define DEFAULT_NO_AUTHORITY_MODE 0600
......
......@@ -14,6 +14,7 @@
*/
#include "init_cmds.h"
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
......@@ -24,10 +25,11 @@
#include <sys/stat.h>
#include <unistd.h>
#ifndef OHOS_LITE
#include <sys/syscall.h>
#include <fcntl.h>
#include <linux/module.h>
#include <sys/syscall.h>
#endif
#include "init_service_manager.h"
#include "securec.h"
......@@ -326,7 +328,6 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt
{
int fd = -1;
char options[OPTIONS_SIZE] = {0};
if (flags == 0) { // '-f' option
if (restPtr != NULL && secondPtr != NULL) { // Reset arugments, combine then all.
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
}
} else { // Only restPtr is option
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);
if (fd < 0) {
printf("[Init] failed to open %s: %d\n", fileName, errno);
......@@ -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);
}
out:
if (fd > 0) {
if (fd >= 0) {
close(fd);
}
return;
......@@ -379,12 +385,14 @@ static void DoInsmod(const char *cmdContent)
if (memcpy_s(line, count, cmdContent, count) != EOK) {
printf("[Init] memcpy failed\n");
free(line);
return;
}
line[count] = '\0';
do {
if ((p = strtok_r(line, " ", &restPtr)) == NULL) {
printf("[Init] debug, cannot get filename\n");
free(line);
return;
}
fileName = p;
......
......@@ -13,21 +13,22 @@
* limitations under the License.
*/
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/netlink.h>
#include <poll.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <poll.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <ctype.h>
#include <signal.h>
#include <dirent.h>
#include <linux/netlink.h>
#include <unistd.h>
#include "list.h"
#include "securec.h"
......@@ -152,7 +153,7 @@ static void RetriggerUevent()
Trigger("/sys/block");
Trigger("/sys/devices");
int fd = open(g_trigger, O_WRONLY | O_CREAT | O_CLOEXEC, DEFAULT_MODE);
if (fd > 0) {
if (fd >= 0) {
close(fd);
}
printf("Re-trigger uevent done\n");
......@@ -220,7 +221,7 @@ ssize_t ReadUevent(int fd, void *buf, size_t len)
if (uid != 0) {
goto out;
}
if (addr.nl_groups == 0 || addr.nl_pid != 0) {
/* ignoring non-kernel or unicast netlink message */
goto out;
......@@ -344,7 +345,8 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent)
if (!links) {
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;
}
if (uevent->partitionName) {
......@@ -514,7 +516,7 @@ static void HandleBlockDevice(struct Uevent *event)
if (strlen(name) > MAX_DEVICE_LEN) { // too long
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;
}
MakeDir(base, DEFAULT_DIR_MODE);
......@@ -537,10 +539,14 @@ static void AddPlatformDevice(const char *path)
}
printf("adding platform device %s (%s)\n", name, path);
struct PlatformNode *bus = calloc(1, sizeof(struct PlatformNode));
if (!bus) {
return;
}
bus->path = strdup(path);
bus->pathLen = pathLen;
bus->name = bus->path + (name - path);
ListAddTail(&g_platformNames, &bus->list);
return;
}
static void RemovePlatformDevice(const char *path)
......@@ -661,7 +667,7 @@ static int HandleUsbDevice(const struct Uevent *event, char *devpath, int len)
* see drivers/base/core.c
*/
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;
}
/* skip leading /dev/ */
......@@ -702,13 +708,21 @@ static void HandleDeviceEvent(struct Uevent *event, char *devpath, int len, cons
char **links = NULL;
links = GetCharacterDeviceSymlinks(event);
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");
return;
goto err;
}
}
HandleDevice(event, devpath, 0, links);
return;
err:
if (links) {
for (int i = 0; links[i]; i++) {
free(links[i]);
}
free(links);
}
return;
}
static void HandleGenericDevice(struct Uevent *event)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册