#include <pthread.h>
#include <sys/types.h>
#include <sys/inotify.h>
+#include <sys/stat.h>
+
#include <fcntl.h>
#include <json.h>
#include <errno.h>
#define ENVIRONMENT_PROXY_FILE "/etc/dockzen/environment"
#define CONFIG_DOCKERD_DAEMON_FILE "/etc/docker/daemon.json"
+#define CONFIG_DOCKERD_FOLDER "/etc/docker"
#define FLAG_FILE_SYSTEM "/opt/etc/setup-adaptor/system_executed"
#define FLAG_FILE_ETH "/opt/etc/setup-adaptor/ethernet_executed"
return -1;
}
- opt->count = json_object_array_length(inputObj);;
+ opt->count = json_object_array_length(inputObj);
if (opt->count > 0) {
- for (ulIndex = 0; ulIndex < opt->count; ulIndex++) {
- registryObj = json_object_array_get_idx(inputObj, ulIndex);
- if (registryObj != NULL) {
- value = json_object_get_string(registryObj);
- _D("value[%d]: %s\n", ulIndex, value);
- if (value != NULL) {
- opt->insecureRegistries[ulIndex] = (char *) malloc(sizeof(char) * 255 + 1);
- if (opt->insecureRegistries[ulIndex] != NULL) {
- memcpy(opt->insecureRegistries[ulIndex], value, strlen(value)+1);
- _D("insecure [%d]: %s", ulIndex, opt->insecureRegistries[ulIndex]);
- } else {
- ret = -1;
- _E("malloc failed for insecureRegistires");
- break;
+ opt->insecureRegistries = (char **) malloc(sizeof(char *) * opt->count);
+ if (opt->insecureRegistries != NULL) {
+ for (ulIndex = 0; ulIndex < opt->count; ulIndex++) {
+ registryObj = json_object_array_get_idx(inputObj, ulIndex);
+ if (registryObj != NULL) {
+ value = json_object_get_string(registryObj);
+ _D("value[%d]: %s\n", ulIndex, value);
+ if (value != NULL) {
+ opt->insecureRegistries[ulIndex] = (char *) malloc(strlen(value) + 1);
+ if (opt->insecureRegistries[ulIndex] != NULL) {
+ memcpy(opt->insecureRegistries[ulIndex], value, strlen(value) + 1);
+ _D("insecure [%d]: %s", ulIndex, opt->insecureRegistries[ulIndex]);
+ } else {
+ ret = -1;
+ _E("malloc failed for insecureRegistries second");
+ break;
+ }
}
}
}
+ } else {
+ ret = -1;
+ _E("malloc failed for inscureRegistries first");
}
}
setupConfig->systemData->dockerdOpt = (sa_dockerd_opt_s *) malloc(sizeof(sa_dockerd_opt_s));
if (setupConfig->systemData->dockerdOpt != NULL)
ret = __parse_system_insecure_registries(arrayObj, setupConfig->systemData->dockerdOpt);
- else
+ else {
_E("malloc failed setupConfig->systemData->dockerdOpt");
+ ret = -1;
+ }
} else {
_E("The type of insecure registries is wrong");
ret = -1;
if (system->dockerdOpt->insecureRegistries[i] != NULL)
free(system->dockerdOpt->insecureRegistries[i]);
}
+
+ if (system->dockerdOpt->insecureRegistries != NULL)
+ free(system->dockerdOpt->insecureRegistries);
+
free(system->dockerdOpt);
}
int len = 0;
int buf_len = 0;
sa_error_e ret = SA_ERROR_NONE;
+ struct stat sb = {0,};
char *buf = NULL;
// make string to write in daemon.json
buf_len = __create_dockerd_opt(opt, &buf);
if (buf_len > 0) {
+ // check folder
+ if (stat(CONFIG_DOCKERD_FOLDER, &sb) == -1) {
+ _D("/etc/docker Folder Create");
+ mkdir(CONFIG_DOCKERD_FOLDER, 0644);
+ }
+
//write data into file
- fd = open(CONFIG_DOCKERD_DAEMON_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ 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 open file");
+ _E("Cannot create file");
}
if (buf != NULL)