From 196876e52d4f9bc2665987bf11e616a127f6cdcb Mon Sep 17 00:00:00 2001
From: s_c_c <shichuchao@huawei.com>
Date: Mon, 18 Mar 2024 17:48:35 +0800
Subject: [PATCH] feat for embedded fix compile errors

---
 interfaces/innerkits/service_control/service_control.c | 10 +++++-----
 interfaces/innerkits/service_watcher/service_watcher.c |  2 +-
 services/param/linux/param_request.c                   |  9 +++++----
 services/param_service/src/le_utils.c                  |  2 ++
 services/param_service/src/main.c                      |  2 ++
 services/param_service/src/param_server.c              |  1 +
 services/param_service/src/trie_comm.c                 |  7 ++++---
 services/utils/init_utils.c                            |  2 +-
 8 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/interfaces/innerkits/service_control/service_control.c b/interfaces/innerkits/service_control/service_control.c
index 9fadec4..238d4f4 100644
--- a/interfaces/innerkits/service_control/service_control.c
+++ b/interfaces/innerkits/service_control/service_control.c
@@ -16,22 +16,22 @@
 #include "service_control.h"
 
 
-static int StartProcess(const char *name, const char *extArgv[], int extArgc)
+__attribute__((unused)) static int StartProcess(const char *name, const char *extArgv[], int extArgc)
 {
     return -1;
 }
 
-static int StopProcess(const char *serviceName)
+__attribute__((unused)) static int StopProcess(const char *serviceName)
 {
     return -1;
 }
 
-static int GetCurrentServiceStatus(const char *serviceName, ServiceStatus *status)
+__attribute__((unused)) static int GetCurrentServiceStatus(const char *serviceName, ServiceStatus *status)
 {
     return -1;
 }
 
-static int RestartProcess(const char *serviceName, const char *extArgv[], int extArgc)
+__attribute__((unused)) static int RestartProcess(const char *serviceName, const char *extArgv[], int extArgc)
 {
     return -1;
 }
@@ -46,7 +46,7 @@ int ServiceControl(const char *serviceName, int action)
     return -1;
 }
 
-static int GetProcessInfo(const char *serviceName, char *nameBuffer, char *valueBuffer, ServiceStatus status)
+__attribute__((unused)) static int GetProcessInfo(const char *serviceName, char *nameBuffer, char *valueBuffer, ServiceStatus status)
 {
     return -1;
 }
diff --git a/interfaces/innerkits/service_watcher/service_watcher.c b/interfaces/innerkits/service_watcher/service_watcher.c
index 68cef54..db6f7c0 100644
--- a/interfaces/innerkits/service_watcher/service_watcher.c
+++ b/interfaces/innerkits/service_watcher/service_watcher.c
@@ -15,7 +15,7 @@
 #include "service_watcher.h"
 #include "parameter.h"
 
-static void ServiceStateChange(const char *key, const char *value, void *context)
+__attribute__((unused)) static void ServiceStateChange(const char *key, const char *value, void *context)
 {
     return;
 }
diff --git a/services/param/linux/param_request.c b/services/param/linux/param_request.c
index 6bcd72d..afd95fe 100644
--- a/services/param/linux/param_request.c
+++ b/services/param/linux/param_request.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 
 #include "beget_ext.h"
+#include "param_manager.h"
 
 static void ClearEnv(ParamRequestMsg* pmsg, ParamRespMsg* respmsg, int fd)
 {
@@ -48,7 +49,7 @@ static int GetClientSocket()
     struct sockaddr_un serverAddr;
 	bzero(&serverAddr, sizeof(serverAddr));
 	serverAddr.sun_family = PF_UNIX;
-	strncpy(serverAddr.sun_path, PIPE_NAME, strlen(PIPE_NAME));
+	strncpy(serverAddr.sun_path, PIPE_NAME, strlen(PIPE_NAME) + 1);
 	if (connect(cfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0) {
 		close(cfd);
 		perror("Failed to connect");
@@ -111,7 +112,7 @@ int SystemSetParameter(const char *name, const char *value)
         return -1;
     }
 
-    strncpy(pmsg->key, name, sizeof(pmsg->key));
+    strncpy(pmsg->key, name, sizeof(pmsg->key) - 1);
 	strncpy(pmsg->data, value, pmsg->datasize);
     int ret;
     struct ParamRespMsg* respmsg = StartRequest(fd, pmsg);
@@ -140,7 +141,7 @@ int SystemReadParam(const char *name, char *value, uint32_t *len)
     struct ParamRequestMsg* pmsg = GetRequestMsg(GET_PARAMETER, *len);
     BEGET_ERROR_CHECK(pmsg != NULL, close(fd);return -1, "Invalid pmsg");
 
-    strncpy(pmsg->key, name, sizeof(pmsg->key));
+    strncpy(pmsg->key, name, sizeof(pmsg->key) - 1);
     int ret;
     struct ParamRespMsg* respmsg = StartRequest(fd, pmsg);
     if (respmsg == NULL) {
@@ -178,7 +179,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
     BEGET_ERROR_CHECK(pmsg != NULL, close(fd);return -1, "Invalid pmsg");
 
     pmsg->timeout = timeout;
-    strncpy(pmsg->key, name, sizeof(pmsg->key));
+    strncpy(pmsg->key, name, sizeof(pmsg->key) - 1);
     strncpy(pmsg->data, value, sizeof(pmsg->datasize));
     struct ParamRespMsg* respmsg = StartRequest(fd, pmsg);
     if (respmsg == NULL) {
diff --git a/services/param_service/src/le_utils.c b/services/param_service/src/le_utils.c
index c4f5b69..8fa0401 100644
--- a/services/param_service/src/le_utils.c
+++ b/services/param_service/src/le_utils.c
@@ -3,6 +3,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
+#include <sys/stat.h>
+#include "securec.h"
 
 #define MAX_BUF 1024
 
diff --git a/services/param_service/src/main.c b/services/param_service/src/main.c
index 01cd47a..1daa246 100644
--- a/services/param_service/src/main.c
+++ b/services/param_service/src/main.c
@@ -6,6 +6,8 @@
 #include <sys/prctl.h>
 #include <string.h>
 #include "beget_ext.h"
+#include "trie_comm.h"
+#include "param_server.h"
 
 int main(int argc, char* argv[])
 {
diff --git a/services/param_service/src/param_server.c b/services/param_service/src/param_server.c
index 2f6b5ed..8b38d0f 100644
--- a/services/param_service/src/param_server.c
+++ b/services/param_service/src/param_server.c
@@ -17,6 +17,7 @@
 #include "param_utils.h"
 #include "trie_comm.h"
 #include "securec.h"
+#include "le_utils.h"
 
 void HandleEvent(struct EventArgs* args)
 {
diff --git a/services/param_service/src/trie_comm.c b/services/param_service/src/trie_comm.c
index 1a66d0d..fd8184a 100644
--- a/services/param_service/src/trie_comm.c
+++ b/services/param_service/src/trie_comm.c
@@ -204,7 +204,7 @@ int SetParamtoMem(const char* key, const char* value)
 	if (root == NULL || current == NULL)
 		return -1;
 
-	char* remainKey = key;
+	char* remainKey = (char *)key;
 	pthread_rwlock_wrlock(&rwlock);
 	while(1) {
 		char* subKey;
@@ -266,7 +266,7 @@ int GetParamFromMem(const char* key, char* value, uint32_t len)
 		return -1;
 
 	ParamNode* paramData;
-	char* remainKey = key;
+	char* remainKey = (char *)key;
 	pthread_rwlock_rdlock(&rwlock);
 	while (1) {
 		char* subKey;
@@ -477,7 +477,8 @@ int ParamWorkSpaceInit()
 	BEGET_ERROR_CHECK(paramWorkSpace != NULL, return -1, "failed to malloc for param workspace");
 	int fd = open(WORKSPACE_NAME, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
 	BEGET_ERROR_CHECK(fd > 0, return -1, "failed to open %s", WORKSPACE_NAME);
-	ftruncate(fd, WORKSPACE_SIZE);
+	int ret = ftruncate(fd, WORKSPACE_SIZE);
+	(void)ret;
 	paramWorkSpace->shareAddr = mmap(NULL, WORKSPACE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	BEGET_ERROR_CHECK(paramWorkSpace->shareAddr != MAP_FAILED, return -1, "failed to create mmap");
 	paramWorkSpace->rootOffest = 0;
diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c
index 733f863..8b4b2e0 100644
--- a/services/utils/init_utils.c
+++ b/services/utils/init_utils.c
@@ -49,7 +49,7 @@ float ConvertMicrosecondToSecond(int x)
 }
 
 #ifndef __LITEOS_M__
-static bool CheckDigit(const char *name)
+__attribute__((unused)) static bool CheckDigit(const char *name)
 {
     size_t nameLen = strlen(name);
     for (size_t i = 0; i < nameLen; ++i) {
-- 
2.20.1 (Apple Git-117)

