From 6044171563d0b7424f4c4c7d6c81f63d9e6e614d Mon Sep 17 00:00:00 2001 From: pandx Date: Thu, 24 Oct 2024 21:02:02 +0800 Subject: [PATCH] refine platform func. --- platform/platform_init.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index ba2e678..f3b6898 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -206,13 +206,14 @@ void PlatformInit::SystemInfoInit() { //从配置文件中读取json数据 if (ifileOut.is_open()) { zlog_info(zbt, "open %s", SYSTEMINFOFILE); + } else { + zlog_error(zbt, "fail to open:%s", SYSTEMINFOFILE); + return; } - if (!recvReader.parse(ifileOut, Systeminfo, false)) { - if (ifileOut.is_open()) { - ifileOut.close(); - } else { - return; - } + if (!recvReader.parse(ifileOut, Systeminfo, false)) { + ifileOut.close(); + zlog_error(zbt, "fail to parse:%s", SYSTEMINFOFILE); + return; } ifileOut.close(); @@ -231,10 +232,22 @@ void PlatformInit::SystemInfoInit() { void PlatformInit::UserInit() { std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName"); + int ret = 0; if (userName.length() == 0) { - WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin"); - WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "adminPassword", "njchaos"); - WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", ""); + ret = WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin"); + if (ret != 0) { + return; + } + + ret = WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "adminPassword", "njchaos"); + if (ret != 0) { + return; + } + + ret = WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", ""); + if (ret != 0) { + return; + } } } @@ -318,11 +331,15 @@ void PlatformInit::EquipIpInit(std::string eth) { // flag = 1; } #ifdef IMX6UL_GATEWAY - + zlog_info(zbt, "system reboot by reboot system call"); + system("sync"); + sleep(1); system("reboot"); + #endif #ifdef G2UL_GATEWAY + zlog_info(zbt, "network restart by systemctl call"); system("systemctl restart systemd-networkd.service"); #endif }