summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/lib/ipc_client.c1
-rw-r--r--src/parse_file.c41
-rw-r--r--src/setup_system.c31
3 files changed, 46 insertions, 27 deletions
diff --git a/src/lib/ipc_client.c b/src/lib/ipc_client.c
index 8c0adcf..8f8cf71 100755
--- a/src/lib/ipc_client.c
+++ b/src/lib/ipc_client.c
@@ -34,7 +34,6 @@ static int __client_open_connection(char *server, SOCKET_HANDLE* phndl)
printf("<<Client>> __client_open_connection\n");
ret = IPC_OpenClientConnection(server, phndl);
if (0 == ret) {
- printf("<<Client>> phndl->server_h = %d\n", phndl->server_h);
printf("<<Client>> phndl->client_h = %d\n", phndl->client_h);
} else {
printf("<<Client>> connection_init ERROR(%d) !!! {%s}\n", ret, SERVER);
diff --git a/src/parse_file.c b/src/parse_file.c
index ae3a67b..59ed212 100644
--- a/src/parse_file.c
+++ b/src/parse_file.c
@@ -408,17 +408,22 @@ int __get_jsonobj_from_file(struct json_object **jsonObj, char *file_name)
int __create_system_config_file(struct json_object *jsonObj, char *write_file)
{
- int ret = 0;
+ int ret = 0, rv = 0;
if (jsonObj) {
struct json_object *jsonObjVer = NULL; // extract version object
// prepare json objects
- json_object_object_get_ex(jsonObj, "version", &jsonObjVer);
- json_object_object_del(jsonObj, "wifi");
- json_object_object_del(jsonObj, "ethernet");
+ if (json_object_object_get_ex(jsonObj, "version", &jsonObjVer)) {
+ json_object_object_del(jsonObj, "wifi");
+ json_object_object_del(jsonObj, "ethernet");
- json_object_to_file_ext(write_file, jsonObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ rv = json_object_to_file_ext(write_file, jsonObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ if (rv < 0)
+ ret = -1;
+ } else {
+ ret = -1;
+ }
} else {
ret = -1;
}
@@ -428,23 +433,31 @@ int __create_system_config_file(struct json_object *jsonObj, char *write_file)
int __create_target_config_file(struct json_object *jsonObj, char *write_file)
{
- int ret = 0;
+ int ret = 0, rv = 0;
if (jsonObj) {
struct json_object *jsonObjVer = NULL; // extract version object
struct json_object *jsonObjName = NULL; // extract deviceName object
// prepare json objects
- json_object_object_get_ex(jsonObj, "version", &jsonObjVer);
- json_object_object_get_ex(jsonObj, "deviceName", &jsonObjName);
+ if (json_object_object_get_ex(jsonObj, "version", &jsonObjVer)) {
+ if (json_object_object_get_ex(jsonObj, "deviceName", &jsonObjName)) {
- // result string for target
- struct json_object *jsonObjResultTarget = json_object_new_object();
- json_object_object_add(jsonObjResultTarget, "version", jsonObjVer);
- if (jsonObjName)
- json_object_object_add(jsonObjResultTarget, "deviceName", jsonObjName);
+ // result string for target
+ struct json_object *jsonObjResultTarget = json_object_new_object();
+ json_object_object_add(jsonObjResultTarget, "version", jsonObjVer);
+ if (jsonObjName)
+ json_object_object_add(jsonObjResultTarget, "deviceName", jsonObjName);
- json_object_to_file_ext(write_file, jsonObjResultTarget, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ rv = json_object_to_file_ext(write_file, jsonObjResultTarget, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+ if (rv < 0)
+ ret = -1;
+ } else {
+ ret = -1;
+ }
+ } else {
+ ret = -1;
+ }
} else {
ret = -1;
}
diff --git a/src/setup_system.c b/src/setup_system.c
index fdff19e..e41da0b 100644
--- a/src/setup_system.c
+++ b/src/setup_system.c
@@ -167,11 +167,11 @@ static sa_error_e sa_inputfile_set_proxy_env(sa_proxy_s * proxy)
fd = open(ENVIRONMENT_PROXY_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd > 0) {
write(fd, writeBuff, strlen(writeBuff));
- close(fd);
} else {
ret = SA_ERROR_NOT_AVAILABLE;
_E("Cannot open file");
}
+ close(fd);
}
return ret;
@@ -228,11 +228,11 @@ static sa_error_e sa_inputfile_set_dockerd_opt(sa_dockerd_opt_s * opt)
fd = creat(CONFIG_DOCKERD_DAEMON_FILE, 0644);
if (fd > 0) {
write(fd, buf, strlen(buf));
- close(fd);
} else {
ret = SA_ERROR_NOT_AVAILABLE;
_E("Cannot create file");
}
+ close(fd);
if (buf != NULL)
free(buf);
@@ -355,17 +355,21 @@ void setup_user_certificates(void)
if (dir_info != NULL) {
while (dir_entry = readdir(dir_info)) {
if (__get_file_extension(dir_entry->d_name, &fileExt) == 0) {
- if (strncmp(fileExt, "crt", 3) == 0) {
- snprintf(file_name, sizeof(file_name), "%s%s", USER_CERT_DIR_PATH, dir_entry->d_name);
- if (__search_str_pattern(SYSTEM_CERT_FILE, file_name) != 0) { // un-matched file, need to be applied
- if (__apply_ca_cert_file(file_name) != 0)
- _D("File[%s]: apply error!!!", dir_entry->d_name);
- else
- _D("File[%s]: applied successfully ca-certificate!!!", dir_entry->d_name);
- } else
- _D("FILE[%s]: already applied!!!", dir_entry->d_name);
+ if (fileExt != NULL) {
+ if (strncmp(fileExt, "crt", 3) == 0) {
+ snprintf(file_name, sizeof(file_name), "%s%s", USER_CERT_DIR_PATH, dir_entry->d_name);
+ if (__search_str_pattern(SYSTEM_CERT_FILE, file_name) != 0) { // un-matched file, need to be applied
+ if (__apply_ca_cert_file(file_name) != 0)
+ _D("File[%s]: apply error!!!", dir_entry->d_name);
+ else
+ _D("File[%s]: applied successfully ca-certificate!!!", dir_entry->d_name);
+ } else {
+ _D("FILE[%s]: already applied!!!", dir_entry->d_name);
+ }
+ }
+ free(fileExt);
+ fileExt = NULL;
}
- free(fileExt);
} else
_D("File[%s]: Not valid certificate file", dir_entry->d_name);
}
@@ -617,6 +621,7 @@ int sa_get_os_info(os_info_s * os_info_h)
_D("platformVer[%s]", os_info_h->platformVer);
free(ret_buf);
+ ret_buf = NULL;
}
// get base OS version
ret = CLI_command(GET_BASEOS_VERSION_CMD, 1, &ret_buf);
@@ -628,6 +633,7 @@ int sa_get_os_info(os_info_s * os_info_h)
_D("baseOSVer[%s]", os_info_h->baseOSVer);
free(ret_buf);
+ ret_buf = NULL;
}
// get docker version
ret = CLI_command(GET_DOCKER_VERSION_CMD, 1, &ret_buf);
@@ -639,6 +645,7 @@ int sa_get_os_info(os_info_s * os_info_h)
_D("dockerVer[%s]", os_info_h->dockerVer);
free(ret_buf);
+ ret_buf = NULL;
}
}