提交 3c8df8bc 编写于 作者: X xionglei6

init: fix bugs

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 f416a865
......@@ -26,9 +26,10 @@
#include <vector>
#include "begetctl.h"
#include "sys_param.h"
#include "fs_manager/fs_manager.h"
#include "param_wrapper.h"
#include "shell.h"
#include "shell_utils.h"
#include "sys_param.h"
constexpr int MAX_LOGO_SIZE = 1024 * 2038;
constexpr int PARTITION_INFO_POS = 1144;
......@@ -36,11 +37,6 @@ constexpr int PARTITION_INFO_MAX_LENGTH = 256;
constexpr int BLOCK_SZIE_1 = 512;
constexpr uint64_t LOGO_MAGIC = 0XABCABCAB;
struct option g_options[] = {
{ "write_logo", required_argument, nullptr, 0 },
{ nullptr, 0, nullptr, 0 },
};
static std::string GetMiscDevicePath()
{
char miscDevice[PATH_MAX] = {0};
......@@ -113,47 +109,47 @@ static int WriteLogo(int fd, const std::string &logoPath)
}
int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 - 1) / BLOCK_SZIE_1;
if (lseek(fd, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) {
std::cout << "Failed to seek file\n";
BSH_LOGI("Failed lseek logoPath %s errno %d ", logoPath.c_str(), errno);
return -1;
}
uint32_t magic = 0;
if (read(fd, &magic, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n";
BSH_LOGI("Failed magic logoPath %s errno %d ", logoPath.c_str(), errno);
return -1;
}
if (magic == LOGO_MAGIC) {
std::cout << "Get matched magic number, logo already written\n";
BSH_LOGI("Get matched magic number, logo already written\n");
return 0;
}
struct stat st {};
magic = LOGO_MAGIC;
lseek(fd, addrOffset * BLOCK_SZIE_1, SEEK_SET);
if (write(fd, &magic, sizeof(magic)) != sizeof(magic)) {
std::cout << "Write magic number failed\n";
BSH_LOGI("Write magic number failed %d", errno);
return -1;
}
if (stat(logoPath.c_str(), &st) < 0) {
if (errno == ENOENT) {
std::cout << logoPath << " is not exist\n";
BSH_LOGI("%s is not exist", logoPath.c_str());
} else {
std::cout << "Failed to get " << logoPath << " stat\n";
BSH_LOGI("Failed to get %s stat", logoPath.c_str());
}
ClearLogo(fd);
return -1;
}
if (st.st_size < 0 || st.st_size > MAX_LOGO_SIZE) {
std::cout << "Invalid logo file with size \n";
BSH_LOGE("Invalid logo file with size ");
ClearLogo(fd);
return -1;
}
uint32_t logoSize = static_cast<uint32_t>(st.st_size);
if (write(fd, &logoSize, sizeof(logoSize)) != sizeof(logoSize)) {
std::cout << "Write logo size failed\n";
BSH_LOGE("Write logo size failed ");
ClearLogo(fd);
return -1;
}
......@@ -172,15 +168,15 @@ static void WriteLogoToMisc(const std::string &logoPath)
if (miscDev.empty()) {
return;
}
BSH_LOGI("WriteLogoToMisc miscDev %s ", miscDev.c_str());
int fd = open(miscDev.c_str(), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
std::cout << "Failed to open " << miscDev << ", err = " << errno << std::endl;
BSH_LOGI("Failed to writeLogoToMisc miscDev %s errno %d ", miscDev.c_str(), errno);
return;
}
if (WriteLogo(fd, logoPath) < 0) {
std::cout << "Write logo to " << miscDev << " failed" << std::endl;
BSH_LOGI("Failed WriteLogo miscDev %s errno %d ", miscDev.c_str(), errno);
}
close(fd);
int addrOffset = (PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH + BLOCK_SZIE_1 - 1) / BLOCK_SZIE_1;
......@@ -189,7 +185,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
return;
}
if (lseek(fd1, addrOffset * BLOCK_SZIE_1, SEEK_SET) < 0) {
std::cout << "Failed to seek file\n";
BSH_LOGI("Failed lseek miscDev %s errno %d ", miscDev.c_str(), errno);
close(fd1);
return;
}
......@@ -197,12 +193,12 @@ static void WriteLogoToMisc(const std::string &logoPath)
uint32_t magic = 0;
uint32_t size = 0;
if (read(fd1, &magic, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n";
BSH_LOGI("Failed read miscDev %s errno %d ", miscDev.c_str(), errno);
close(fd1);
return;
}
if (read(fd1, &size, sizeof(uint32_t)) != sizeof(uint32_t)) {
std::cout << "Failed to read magic number\n";
BSH_LOGI("Failed read migic miscDev %s errno %d ", miscDev.c_str(), errno);
close(fd1);
return;
}
......@@ -212,25 +208,11 @@ static void WriteLogoToMisc(const std::string &logoPath)
static int main_cmd(BShellHandle shell, int argc, char **argv)
{
int rc = -1;
int optIndex = -1;
while ((rc = getopt_long(argc, argv, "", g_options, &optIndex)) != -1) {
switch (rc) {
case 0: {
std::string optionName = g_options[optIndex].name;
if (optionName == "write_logo") {
std::string logoPath = optarg;
WriteLogoToMisc(logoPath);
}
break;
}
case '?':
std::cout << "Invalid arugment\n";
break;
default:
std::cout << "Invalid arugment\n";
break;
}
if (argc >= 2 && strcmp((char *)"--write_logo", argv[0]) == 0) { // 2 min arg
WriteLogoToMisc(argv[1]);
} else {
char *helpArgs[] = {(char *)"misc_daemon", NULL};
BShellCmdHelp(shell, 1, helpArgs);
}
return 0;
}
......
......@@ -551,15 +551,33 @@ int32_t BShellEnvRegitsterCmd(BShellHandle handle, CmdInfo *cmdInfo)
return 0;
}
static const char *GetRealCmdName(const char *name)
{
int i = 0;
int last = 0;
while (*(name + i) != '\0') {
if (*(name + i) == '/') {
last = i;
}
i++;
}
if ((last != 0) && (name + last != NULL)) {
return name + last + 1;
} else {
return name;
}
}
BShellCommand *BShellEnvGetCmd(BShellHandle handle, int32_t argc, char *argv[])
{
BSH_CHECK(handle != NULL, return NULL, "Invalid shell env");
BSH_CHECK(argc >= 1, return NULL, "Invalid argc");
BSH_LOGV("BShellEnvGetCmd %s", argv[0]);
const char *cmdName = GetRealCmdName(argv[0]);
BSH_LOGV("BShellEnvGetCmd %s cmd %s", argv[0], cmdName);
BShellEnv *shell = (BShellEnv *)handle;
BShellCommand *cmd = shell->command;
while (cmd != NULL) {
if (strcmp(cmd->name, argv[0]) != 0) {
if (strcmp(cmd->name, cmdName) != 0) {
cmd = cmd->next;
continue;
}
......@@ -571,7 +589,11 @@ BShellCommand *BShellEnvGetCmd(BShellHandle handle, int32_t argc, char *argv[])
if (cmd->multikeys[i] == NULL) {
return cmd;
}
if (strcmp(cmd->multikeys[i], argv[i]) != 0) {
char *tmp = argv[i];
if (i == 0) {
tmp = (char *)cmdName;
}
if (strcmp(cmd->multikeys[i], tmp) != 0) {
break;
}
}
......
......@@ -413,12 +413,6 @@
"cmds" : [
"write /proc/sys/kernel/perf_event_paranoid 3"
]
}, {
"name" : "boot && param:const.debuggable=1",
"condition" : "boot && const.debuggable=1",
"cmds" : [
"start console"
]
}, {
"name" : "boot && param:const.debuggable=1",
"condition" : "boot && const.debuggable=1",
......
......@@ -433,24 +433,28 @@
"services" : [{
"name" : "ueventd",
"path" : ["/system/bin/ueventd"],
"critical" : 1
"critical" : 1,
"start-mode" : "condition"
}, {
"name" : "console",
"path" : ["/system/bin/sh"],
"disabled" : 1,
"console" : 1,
"uid" : "root",
"gid" : ["shell", "log", "readproc"]
"gid" : ["shell", "log", "readproc"],
"start-mode" : "condition"
}, {
"name" : "watchdog_service",
"path" : ["/system/bin/watchdog_service", "10", "2"],
"disabled" : 1,
"uid" : "root",
"gid" : ["shell", "log", "readproc"]
"gid" : ["shell", "log", "readproc"],
"start-mode" : "condition"
}, {
"name" : "misc",
"path" : ["/system/bin/misc_daemon", "--write_logo", "/vendor/logo.rgb"],
"once" : 1
"once" : 1,
"start-mode" : "condition"
}
]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册