[Bugfix][T106BUG-208] fix ntp_sync_time return value wrong & optimize the use of "system()" function

Only Configure:No
Affected branch:master
Affected module:systime
Is it affected on both ZXIC and MTK: Yes
Self-test: Yes
Doc Update: No

Change-Id: Ic14500cee8643e5d3d18d55e677a6d939c126f7e
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
index 4109b21..690c0d0 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
@@ -36,14 +36,14 @@
 #define NTP_ALREADY_ENABLE 1

 #define NTP_ALREADY_DISABLE 2

 

-#define OPEN_ERROR 7

+#define SYSTEM_FUNC_FAILED 7

 #define ERROR_PARA 8

 

 #ifdef MOBILETEK_TARGET_PLATFORM_T106

 #define NTP_RESTART_BUF "/etc/init.d/sntp restart"

 #define NTP_STOP_BUF "/etc/init.d/sntp stop"

 #define NTP_START_BUF "/etc/init.d/sntp start"

-#define PGREP_NTP_DARMON "pgrep -x /usr/bin/sntp"

+#define PGREP_NTP_DARMON "pgrep sntp"

 

 #else

 #define NTP_RESTART_BUF "systemctl restart ntpd"

@@ -54,7 +54,7 @@
 #endif

 

 #ifdef MOBILETEK_TARGET_PLATFORM_T106

-    typedef int (*sc_rtc_time_get_cb)(unsigned int src_id, unsigned long ulsec);

+typedef int (*sc_rtc_time_get_cb)(unsigned int src_id, unsigned long ulsec);

 extern int sc_rtc_timer_init(void);

 extern int sc_rtc_timer_uninit(void);

 extern int sc_rtc_time_set(int srcid);

@@ -79,7 +79,13 @@
     LYINFLOG("RTC time now is: %d-%d-%d,%d:%d:%d\n",

              rtc_time.tm_year + 1900, rtc_time.tm_mon + 1, rtc_time.tm_mday, rtc_time.tm_hour, rtc_time.tm_min, rtc_time.tm_sec);

     snprintf(command, sizeof(command), "date --set=\'@%lu\' ", ulsec);

-    system(command);

+    int ret = system(command);

+    if (ret != 0)

+    {

+        printf("Function system(\"%s\") failed.", command);

+        sync_from_rtc_cb_flag = 0;

+        return SYSTEM_FUNC_FAILED;

+    }

     sync_from_rtc_cb_flag = 0;

     return 0;

 }

@@ -279,7 +285,12 @@
 

     // set systime

     snprintf(cmd_buf, sizeof(cmd_buf), "date -s %s+%s", date, time);

-    system(cmd_buf);

+    int ret = system(cmd_buf);

+    if (ret != 0)

+    {

+        printf("Function system(\"%s\") failed.", cmd_buf);

+        return SYSTEM_FUNC_FAILED;

+    }

     return 0;

 }

 

@@ -287,7 +298,7 @@
 {

     LYLOGSET(LOG_LEVEL);

     LYLOGEINIT(USER_LOG_TAG);

-    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    LYDBGLOG("[%s][%d] enter.\n", __func__, __LINE__);

     if (enable != 0 && enable != 1)

     {

         LYERRLOG("Parameter error! Only 0/1 allowed.\n");

@@ -298,13 +309,21 @@
     {

         if (enable)

         {

-            system(NTP_RESTART_BUF);

-            return NTP_ALREADY_ENABLE;

+            ret = system(NTP_RESTART_BUF);

+            if (ret != 0)

+            {

+                printf("Function system(\"%s\") failed.", NTP_RESTART_BUF);

+                return SYSTEM_FUNC_FAILED;

+            }

         }

         else

         {

-            system(NTP_STOP_BUF);

-            return SYNC_TIME_SUCCESS;

+            ret = system(NTP_STOP_BUF);

+            if (ret != 0)

+            {

+                printf("Function system(\"%s\") failed.", NTP_STOP_BUF);

+                return SYSTEM_FUNC_FAILED;

+            }

         }

     }

     else

@@ -314,14 +333,15 @@
             // Only one time source is allowed to run simultaneously.

             modem_time_enable(0);

             gnss_time_enable(0);

-            system(NTP_START_BUF);

-            return SYNC_TIME_SUCCESS;

-        }

-        else

-        {

-            return NTP_ALREADY_DISABLE;

+            ret = system(NTP_START_BUF);

+            if (ret != 0)

+            {

+                printf("Function system(\"%s\") failed.", NTP_START_BUF);

+                return SYSTEM_FUNC_FAILED;

+            }

         }

     }

+    return SYNC_TIME_SUCCESS;

 }

 

 int modem_time_enable(int enable)