提交 32001591 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!35 utils: add prefix for utils function

Merge pull request !35 from lifeng_isula/master_fix_util
......@@ -31,7 +31,7 @@ Buffer *buffer_alloc(size_t initial_size)
return NULL;
}
buf = util_common_calloc_s(sizeof(Buffer));
buf = lcr_util_common_calloc_s(sizeof(Buffer));
if (buf == NULL) {
return NULL;
}
......@@ -104,7 +104,7 @@ static int buffer_grow(Buffer *buf, size_t minimum_size)
return -1;
}
tmp = util_common_calloc_s(new_size);
tmp = lcr_util_common_calloc_s(new_size);
if (tmp == NULL) {
ERROR("Out of memory");
return -1;
......
......@@ -40,7 +40,7 @@ static int files_limit_checker(const char *value)
long long limit = 0;
int ret = 0;
ret = util_safe_llong(value, &limit);
ret = lcr_util_safe_llong(value, &limit);
if (ret) {
ret = -1;
}
......@@ -75,7 +75,7 @@ static int check_console_log_filesize(const char *value)
return ret;
}
if (parse_byte_size_string(value, &tmp) == 0 && tmp >= min) {
if (lcr_parse_byte_size_string(value, &tmp) == 0 && tmp >= min) {
ret = 0;
}
......@@ -94,7 +94,7 @@ static int check_oom_score_adj(const char *value)
return ret;
}
if (util_safe_int(value, &tmp) == 0 && tmp >= min && tmp <= max) {
if (lcr_util_safe_int(value, &tmp) == 0 && tmp >= min && tmp <= max) {
ret = 0;
}
lcr_set_error_message(LCR_ERR_RUNTIME, "Invalid value %s, range for oom score adj is [%d, %d]", value, min, max);
......@@ -110,7 +110,7 @@ static int check_console_log_filerotate(const char *value)
return ret;
}
if (util_safe_uint(value, &tmp) == 0) {
if (lcr_util_safe_uint(value, &tmp) == 0) {
ret = 0;
}
......@@ -124,7 +124,7 @@ static int check_rootfs_mount(const char *value)
return -1;
}
if (!dir_exists(value)) {
if (!lcr_util_dir_exists(value)) {
lcr_set_error_message(LCR_ERR_RUNTIME, "Container rootfs mount path '%s' is not exist", value);
return -1;
}
......@@ -273,18 +273,18 @@ struct lcr_list *create_lcr_list_node(const char *key, const char *value)
struct lcr_list *node = NULL;
lcr_config_item_t *entry = NULL;
node = util_common_calloc_s(sizeof(*node));
node = lcr_util_common_calloc_s(sizeof(*node));
if (node == NULL) {
return NULL;
}
entry = util_common_calloc_s(sizeof(*entry));
entry = lcr_util_common_calloc_s(sizeof(*entry));
if (entry == NULL) {
free(node);
return NULL;
}
entry->name = util_strdup_s(key);
entry->name = lcr_util_strdup_s(key);
entry->value = util_strdup_s(value);
entry->value = lcr_util_strdup_s(value);
node->elem = entry;
return node;
......@@ -434,7 +434,7 @@ static int trans_oci_process_init_groups(const oci_runtime_spec_process *proc, s
}
size_t total_len = (LCR_NUMSTRLEN64 + 1) * proc->user->additional_gids_len;
char *gids = util_common_calloc_s(total_len);
char *gids = lcr_util_common_calloc_s(total_len);
if (gids == NULL) {
goto out;
}
......@@ -539,7 +539,7 @@ static int trans_oci_process_env_and_cap(const oci_runtime_spec_process *proc, s
size_t i;
for (i = 0; i < proc->env_len; i++) {
char *replaced = util_string_replace(" ", SPACE_MAGIC_STR, proc->env[i]);
char *replaced = lcr_util_string_replace(" ", SPACE_MAGIC_STR, proc->env[i]);
if (replaced == NULL) {
ERROR("memory allocation error");
goto out;
......@@ -590,7 +590,7 @@ static int trans_oci_process_prlimit(const oci_runtime_spec_process *proc, struc
char buf_key[30] = { 0 };
char buf_value[60] = { 0 };
size_t j;
char *type = util_strdup_s(lr->type);
char *type = lcr_util_strdup_s(lr->type);
// Lower case type,eg. RLIMIT_NOFILE -> RLIMIT_nofile
for (j = strlen("RLIMIT_"); j < strlen(type); j++) {
......@@ -699,7 +699,7 @@ struct lcr_list *trans_oci_process(const oci_runtime_spec_process *proc)
{
struct lcr_list *conf = NULL;
conf = util_common_calloc_s(sizeof(struct lcr_list));
conf = lcr_util_common_calloc_s(sizeof(struct lcr_list));
if (conf == NULL) {
return NULL;
}
......@@ -770,7 +770,7 @@ static int trans_oci_root_rootfs_options(const oci_runtime_spec_root *root, stru
int nret;
if (is_root_readonly(root)) {
value = util_strdup_s("ro");
value = lcr_util_strdup_s("ro");
}
if ((linux != NULL) && linux->rootfs_propagation != NULL) {
......@@ -781,7 +781,7 @@ static int trans_oci_root_rootfs_options(const oci_runtime_spec_root *root, stru
goto out;
}
newsize = strlen(linux->rootfs_propagation) + strlen(value) + APPEND_COMMA_END_SIZE;
nret = mem_realloc((void **)&tmpvalue, newsize, value, strlen(value));
nret = lcr_mem_realloc((void **)&tmpvalue, newsize, value, strlen(value));
if (nret < 0) {
ERROR("Out of memory");
goto out;
......@@ -793,7 +793,7 @@ static int trans_oci_root_rootfs_options(const oci_runtime_spec_root *root, stru
goto out;
}
} else {
value = util_strdup_s(linux->rootfs_propagation);
value = lcr_util_strdup_s(linux->rootfs_propagation);
}
}
......@@ -815,7 +815,7 @@ struct lcr_list *trans_oci_root(const oci_runtime_spec_root *root, const oci_run
{
struct lcr_list *conf = NULL;
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -887,12 +887,12 @@ static char *trans_mount_to_lxc_options(const defs_mount *mount)
lxc_options = isdir ? ",create=dir" : ",create=file";
prefix = util_string_join(",", (const char **)mount->options, mount->options_len);
prefix = lcr_util_string_join(",", (const char **)mount->options, mount->options_len);
if (prefix == NULL) {
prefix = util_strdup_s("defaults");
prefix = lcr_util_strdup_s("defaults");
}
result = util_string_append(lxc_options, prefix);
result = lcr_util_string_append(lxc_options, prefix);
free(prefix);
return result;
......@@ -926,15 +926,15 @@ static char *get_mount_readmode_options(const defs_mount *mount, const char *typ
if (is_mount_type_cgroup(type)) {
if (readonly) {
options = util_strdup_s("ro:force");
options = lcr_util_strdup_s("ro:force");
} else {
options = util_strdup_s("rw:force");
options = lcr_util_strdup_s("rw:force");
}
} else {
if (readonly) {
options = util_strdup_s("ro");
options = lcr_util_strdup_s("ro");
} else {
options = util_strdup_s("rw");
options = lcr_util_strdup_s("rw");
}
}
......@@ -996,12 +996,12 @@ static struct lcr_list *trans_mount_entry_to_lxc(const defs_mount *mount)
char *replaced_dest = NULL;
int ret;
char *replaced_source = util_string_replace(" ", SPACE_MAGIC_STR, mount->source);
char *replaced_source = lcr_util_string_replace(" ", SPACE_MAGIC_STR, mount->source);
if (replaced_source == NULL) {
ERROR("memory allocation error");
goto err_out;
}
replaced_dest = util_string_replace(" ", SPACE_MAGIC_STR, mount->destination);
replaced_dest = lcr_util_string_replace(" ", SPACE_MAGIC_STR, mount->destination);
if (replaced_dest == NULL) {
ERROR("memory allocation error");
free(replaced_source);
......@@ -1117,7 +1117,7 @@ struct lcr_list *trans_oci_mounts(const oci_runtime_spec *c)
bool system_container = is_system_container(c);
bool external_rootfs = is_external_rootfs(c);
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -1169,7 +1169,7 @@ static int trans_one_oci_id_mapping(struct lcr_list *conf, const char *typ, cons
if (nret < 0 || (size_t)nret >= sizeof(subid)) {
return -1;
}
nret = util_atomic_write_file(path, subid);
nret = lcr_util_atomic_write_file(path, subid);
if (nret < 0) {
return -1;
}
......@@ -1208,7 +1208,7 @@ static struct lcr_list *trans_oci_id_mapping(const oci_runtime_config_linux *l)
struct lcr_list *conf = NULL;
int nret = 0;
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -1852,7 +1852,7 @@ static struct lcr_list *trans_oci_resources(const oci_runtime_config_linux_resou
{
struct lcr_list *conf = NULL;
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -1912,7 +1912,7 @@ static char *trans_oci_namespace_to_lxc(const char *typ)
for (p = namespaces_map; p != NULL && p->ns_name != NULL; p++) {
if (strcmp(typ, p->ns_name) == 0) {
return util_strdup_s(p->lxc_name);
return lcr_util_strdup_s(p->lxc_name);
}
}
return NULL;
......@@ -1926,7 +1926,7 @@ static struct lcr_list *trans_oci_namespaces(const oci_runtime_config_linux *l)
size_t i;
oci_runtime_defs_linux_namespace_reference *ns = NULL;
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -1970,7 +1970,7 @@ static struct lcr_list *trans_oci_mask_ro_paths(const oci_runtime_config_linux *
size_t i;
char *path = NULL;
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -2020,7 +2020,7 @@ static struct lcr_list *trans_oci_linux_devices(const oci_runtime_config_linux *
oci_runtime_defs_linux_device *device = NULL;
char buf_value[POPULATE_DEVICE_SIZE] = { 0 };
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -2089,15 +2089,15 @@ static inline bool is_seccomp_action_errno(const char *value)
static char *seccomp_trans_action(const char *action)
{
if (is_seccomp_action_kill(action)) {
return util_strdup_s("kill");
return lcr_util_strdup_s("kill");
} else if (is_seccomp_action_trap(action)) {
return util_strdup_s("trap");
return lcr_util_strdup_s("trap");
} else if (is_seccomp_action_allow(action)) {
return util_strdup_s("allow");
return lcr_util_strdup_s("allow");
} else if (is_seccomp_action_trace(action)) {
return util_strdup_s("trace 1");
return lcr_util_strdup_s("trace 1");
} else if (is_seccomp_action_errno(action)) {
return util_strdup_s("errno 1");
return lcr_util_strdup_s("errno 1");
}
return NULL;
......@@ -2164,11 +2164,11 @@ static char *get_hostarch(void)
for (i = 0; i < len; i++) {
if (i == 0 || i == 1 || i == 2) {
if (strcmp(uts.machine, arch_type[i].arch) == 0) {
return util_strdup_s(arch_type[i].value);
return lcr_util_strdup_s(arch_type[i].value);
}
} else {
if (strncmp(uts.machine, arch_type[i].arch, (size_t)(arch_type[i].num)) == 0) {
return util_strdup_s(arch_type[i].value);
return lcr_util_strdup_s(arch_type[i].value);
}
}
}
......@@ -2209,7 +2209,7 @@ static char *seccomp_trans_arch(const char *arch)
if (strcmp(arch_type[i].arch, "SCMP_ARCH_AUTO") == 0) {
return get_hostarch();
} else if (strcmp(arch, arch_type[i].arch) == 0) {
return util_strdup_s(arch_type[i].value);
return lcr_util_strdup_s(arch_type[i].value);
}
}
return NULL;
......@@ -2320,7 +2320,7 @@ static struct lcr_list *trans_oci_linux_sysctl(const json_map_string_string *sys
struct lcr_list *node = NULL;
size_t i;
conf = util_common_calloc_s(sizeof(*conf));
conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -2457,7 +2457,7 @@ struct lcr_list *trans_oci_linux(const oci_runtime_config_linux *l, char **secco
int ret = 0;
struct lcr_list *tmp = NULL;
struct lcr_list *conf = util_common_calloc_s(sizeof(*conf));
struct lcr_list *conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -2532,7 +2532,7 @@ struct lcr_list *trans_annotations(const json_map_string_string *anno)
size_t len;
int ret = 0;
struct lcr_list *conf = util_common_calloc_s(sizeof(*conf));
struct lcr_list *conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......@@ -2606,7 +2606,7 @@ static int add_needed_net_conf(struct lcr_list *conf)
/* get needed lxc conf */
struct lcr_list *get_needed_lxc_conf()
{
struct lcr_list *conf = util_common_calloc_s(sizeof(*conf));
struct lcr_list *conf = lcr_util_common_calloc_s(sizeof(*conf));
if (conf == NULL) {
return NULL;
}
......
......@@ -67,7 +67,7 @@ void lcr_set_error_message(lcr_errno_t errcode, const char *format, ...)
return;
}
g_lcr_error.errcode = errcode;
g_lcr_error.errmsg = util_strdup_s(errbuf);
g_lcr_error.errmsg = lcr_util_strdup_s(errbuf);
}
void lcr_try_set_error_message(lcr_errno_t errcode, const char *format, ...)
......@@ -88,7 +88,7 @@ void lcr_try_set_error_message(lcr_errno_t errcode, const char *format, ...)
return;
}
g_lcr_error.errcode = errcode;
g_lcr_error.errmsg = util_strdup_s(errbuf);
g_lcr_error.errmsg = lcr_util_strdup_s(errbuf);
}
void lcr_append_error_message(lcr_errno_t errcode, const char *format, ...)
......@@ -107,7 +107,7 @@ void lcr_append_error_message(lcr_errno_t errcode, const char *format, ...)
return;
}
g_lcr_error.errcode = errcode;
result = util_string_append(g_lcr_error.errmsg, errbuf);
result = lcr_util_string_append(g_lcr_error.errmsg, errbuf);
if (result == NULL) {
g_lcr_error.errcode = LCR_ERR_MEMOUT;
return;
......
......@@ -118,15 +118,15 @@ struct lcr_container_info *lcr_container_info_get(const char *name, const char *
run_flag = (strcmp(st, "STOPPED") != 0);
/* Now it makes sense to allocate memory */
info = util_common_calloc_s(sizeof(*info));
info = lcr_util_common_calloc_s(sizeof(*info));
if (info == NULL) {
nret = -1;
goto put_and_finish;
}
info->init = -1;
info->running = run_flag;
info->name = util_strdup_s(name);
info->state = util_strdup_s(st);
info->name = lcr_util_strdup_s(name);
info->state = lcr_util_strdup_s(st);
if (run_flag) {
info->init = c->init_pid(c);
}
......@@ -204,7 +204,7 @@ static int create_partial(const struct lxc_container *c)
// $lxcpath + '/' + $name + '/partial' + \0
len = strlen(c->config_path) + strlen(c->name) + 10;
char *path = util_common_calloc_s(len);
char *path = lcr_util_common_calloc_s(len);
if (path == NULL) {
ERROR("Out of memory in create_partial");
return -1;
......@@ -216,7 +216,7 @@ static int create_partial(const struct lxc_container *c)
goto out_free;
}
fd = util_open(path, O_RDWR | O_CREAT | O_EXCL, DEFAULT_SECURE_FILE_MODE);
fd = lcr_util_open(path, O_RDWR | O_CREAT | O_EXCL, DEFAULT_SECURE_FILE_MODE);
if (fd < 0) {
SYSERROR("Error creating partial file: %s", path);
goto out_free;
......@@ -251,7 +251,7 @@ static void remove_partial(const struct lxc_container *c)
// $lxcpath + '/' + $name + '/partial' + \0
len = strlen(c->config_path) + strlen(c->name) + 10;
char *path = util_common_calloc_s(len);
char *path = lcr_util_common_calloc_s(len);
if (path == NULL) {
ERROR("Out of memory in remove_partial");
return;
......@@ -371,7 +371,7 @@ static bool wait_start_pid(pid_t pid, int rfd, const char *name, const char *pat
ssize_t size_read = 0;
char buffer[BUFSIZ] = { 0 };
ret = wait_for_pid(pid);
ret = lcr_wait_for_pid(pid);
if (ret == 0) {
return true;
}
......@@ -1036,7 +1036,7 @@ static char *lcr_get_config_item(struct lxc_container *c, const char *key, bool
goto out;
}
cret = util_common_calloc_s((len + 1) * sizeof(char));
cret = lcr_util_common_calloc_s((len + 1) * sizeof(char));
if (cret == NULL) {
ERROR("Out of memory");
goto out;
......@@ -1079,7 +1079,7 @@ static bool lcr_get_console_config_items(struct lxc_container *c, struct lcr_con
if (item == NULL) {
DEBUG("Log rotate is NULL");
} else {
if (util_safe_uint(item, &trotate) == 0) {
if (lcr_util_safe_uint(item, &trotate) == 0) {
config->log_rotate = trotate;
} else {
ERROR("trans to uint failed");
......@@ -1226,7 +1226,7 @@ int lcr_log_init(const char *name, const char *file, const char *priority, const
lconf.priority = priority ? priority : "ERROR";
} else {
/* File has prefix "fifo:", */
full_path = util_string_split_prefix(pre_len, file);
full_path = lcr_util_string_split_prefix(pre_len, file);
lconf.file = full_path;
lconf.driver = "fifo";
lconf.priority = priority;
......
......@@ -55,7 +55,7 @@ static inline void add_array_elem(char **array, size_t total, size_t *pos, const
if (*pos + 1 >= total - 1) {
return;
}
array[*pos] = util_strdup_s(elem);
array[*pos] = lcr_util_strdup_s(elem);
*pos += 1;
}
......@@ -507,10 +507,10 @@ void do_lcr_state(struct lxc_container *c, struct lcr_container_state *lcs)
clear_error_message(&g_lcr_error);
(void)memset(lcs, 0x00, sizeof(struct lcr_container_state));
lcs->name = util_strdup_s(c->name);
lcs->name = lcr_util_strdup_s(c->name);
state = c->state(c);
lcs->state = state ? util_strdup_s(state) : util_strdup_s("-");
lcs->state = state ? lcr_util_strdup_s(state) : lcr_util_strdup_s("-");
if (c->is_running(c)) {
lcs->init = c->init_pid(c);
......@@ -549,7 +549,7 @@ static void execute_lxc_attach(const char *name, const char *path, const struct
size_t j = 0;
size_t args_len = PARAM_NUM;
if (util_check_inherited(true, -1) != 0) {
if (lcr_util_check_inherited(true, -1) != 0) {
COMMAND_ERROR("Close inherited fds failed");
exit(EXIT_FAILURE);
}
......@@ -560,7 +560,7 @@ static void execute_lxc_attach(const char *name, const char *path, const struct
exit(EXIT_FAILURE);
}
params = util_common_calloc_s(args_len * sizeof(char *));
params = lcr_util_common_calloc_s(args_len * sizeof(char *));
if (params == NULL) {
COMMAND_ERROR("Out of memory");
exit(EXIT_FAILURE);
......@@ -661,7 +661,7 @@ bool do_attach(const char *name, const char *path, const struct lcr_exec_request
}
if (pid == (pid_t)0) {
if (util_null_stdfds() < 0) {
if (lcr_util_null_stdfds() < 0) {
COMMAND_ERROR("Failed to close fds");
exit(EXIT_FAILURE);
}
......@@ -676,7 +676,7 @@ bool do_attach(const char *name, const char *path, const struct lcr_exec_request
close(pipefd[1]);
status = wait_for_pid_status(pid);
status = lcr_wait_for_pid_status(pid);
if (status < 0) {
ERROR("Failed to wait lxc-attach");
goto close_out;
......@@ -707,7 +707,7 @@ void execute_lxc_start(const char *name, const char *path, const struct lcr_star
char *params[PARAM_NUM] = { NULL };
size_t i = 0;
if (util_check_inherited(true, -1) != 0) {
if (lcr_util_check_inherited(true, -1) != 0) {
COMMAND_ERROR("Close inherited fds failed");
}
......
......@@ -73,7 +73,7 @@ static int realloc_annotations(oci_runtime_spec *oci_spec, size_t new_lens)
}
if (!oci_spec->annotations) {
oci_spec->annotations = util_common_calloc_s(sizeof(json_map_string_string));
oci_spec->annotations = lcr_util_common_calloc_s(sizeof(json_map_string_string));
if (!oci_spec->annotations) {
ERROR("Out of memory");
nret = -1;
......@@ -88,7 +88,7 @@ static int realloc_annotations(oci_runtime_spec *oci_spec, size_t new_lens)
}
new_size = (oci_spec->annotations->len + new_lens) * sizeof(char *);
old_size = oci_spec->annotations->len * sizeof(char *);
nret = mem_realloc((void **)&fkey, new_size, oci_spec->annotations->keys, old_size);
nret = lcr_mem_realloc((void **)&fkey, new_size, oci_spec->annotations->keys, old_size);
if (nret) {
ERROR("Failed to realloc memory for files limit variables");
nret = -1;
......@@ -96,7 +96,7 @@ static int realloc_annotations(oci_runtime_spec *oci_spec, size_t new_lens)
}
oci_spec->annotations->keys = fkey;
nret = mem_realloc((void **)&fval, new_size, oci_spec->annotations->values, old_size);
nret = lcr_mem_realloc((void **)&fval, new_size, oci_spec->annotations->values, old_size);
if (nret) {
ERROR("Failed to realloc memory for files limit variables");
nret = -1;
......@@ -123,7 +123,7 @@ static int make_annotations(oci_runtime_spec *container, const struct lxc_contai
goto out;
}
fpos = (int)(anno->len - 1);
anno->keys[fpos] = util_strdup_s("log.console.file");
anno->keys[fpos] = lcr_util_strdup_s("log.console.file");
anno->values[fpos] = NULL;
}
......@@ -136,14 +136,14 @@ static int make_annotations(oci_runtime_spec *container, const struct lxc_contai
if (anno->values[fpos]) {
free(anno->values[fpos]);
}
anno->values[fpos] = util_strdup_s(default_path);
anno->values[fpos] = lcr_util_strdup_s(default_path);
}
if (strcmp("none", anno->values[fpos]) == 0) {
DEBUG("Disable console log.");
ret = 0;
goto out;
}
if (util_ensure_path(&realpath, anno->values[fpos])) {
if (lcr_util_ensure_path(&realpath, anno->values[fpos])) {
ERROR("Invalid log path: %s, error: %s.", anno->values[fpos], strerror(errno));
goto out;
}
......@@ -351,7 +351,7 @@ static int lcr_spec_write_seccomp_line(int fd, const char *seccomp)
len = strlen("lxc.seccomp.profile") + 3 + strlen(seccomp) + 1;
line = util_common_calloc_s(len * sizeof(char));
line = lcr_util_common_calloc_s(len * sizeof(char));
if (line == NULL) {
ERROR("Out of memory");
goto cleanup;
......@@ -389,13 +389,13 @@ static char *lcr_save_seccomp_file(const char *bundle, const char *seccomp_conf)
goto cleanup;
}
nret = util_ensure_path(&real_seccomp, seccomp);
nret = lcr_util_ensure_path(&real_seccomp, seccomp);
if (nret < 0) {
ERROR("Failed to ensure path %s", seccomp);
goto cleanup;
}
fd = util_open(real_seccomp, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE);
fd = lcr_util_open(real_seccomp, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE);
if (fd == -1) {
SYSERROR("Create file %s failed", real_seccomp);
goto cleanup;
......@@ -426,7 +426,7 @@ static struct lcr_container_info *info_new(struct lcr_container_info **info, siz
length = (*size + 1) * sizeof(struct lcr_container_info);
nret = mem_realloc((void **)&n, length, (void *)(*info), (*size) * sizeof(struct lcr_container_info));
nret = lcr_mem_realloc((void **)&n, length, (void *)(*info), (*size) * sizeof(struct lcr_container_info));
if (nret < 0) {
return NULL;
}
......@@ -592,8 +592,8 @@ int lcr_containers_info_get(const char *lcrpath, struct lcr_container_info **inf
goto put_container;
}
in->running = run_flag;
in->name = util_strdup_s(name);
in->state = util_strdup_s(st);
in->name = lcr_util_strdup_s(name);
in->state = lcr_util_strdup_s(st);
if (run_flag) {
in->init = c->init_pid(c);
}
......@@ -671,7 +671,7 @@ struct lcr_list *lcr_oci2lcr(const struct lxc_container *c, oci_runtime_spec *co
{
struct lcr_list *lcr_conf = NULL;
lcr_conf = util_common_calloc_s(sizeof(*lcr_conf));
lcr_conf = lcr_util_common_calloc_s(sizeof(*lcr_conf));
if (lcr_conf == NULL) {
goto out_free;
}
......@@ -722,13 +722,13 @@ static int lcr_open_config_file(const char *bundle)
goto out;
}
nret = util_ensure_path(&real_config, config);
nret = lcr_util_ensure_path(&real_config, config);
if (nret < 0) {
ERROR("Failed to ensure path %s", config);
goto out;
}
fd = util_open(real_config, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE);
fd = lcr_util_open(real_config, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE);
if (fd == -1) {
ERROR("Create file %s failed, %s", real_config, strerror(errno));
lcr_set_error_message(LCR_ERR_RUNTIME, "Create file %s failed, %s", real_config, strerror(errno));
......@@ -756,7 +756,7 @@ static char *escape_string_encode(const char *src)
return NULL;
}
dst = util_common_calloc_s(2 * len + 1);
dst = lcr_util_common_calloc_s(2 * len + 1);
if (dst == NULL) {
ERROR("Out of memory");
return NULL;
......@@ -814,7 +814,7 @@ static int lcr_spec_write_config(int fd, const struct lcr_list *lcr_conf)
goto cleanup;
}
len = strlen(item->name) + 3 + strlen(item->value) + 1;
line = util_common_calloc_s(len);
line = lcr_util_common_calloc_s(len);
if (line == NULL) {
ERROR("Out of memory");
goto cleanup;
......@@ -866,7 +866,7 @@ char *lcr_get_bundle(const char *lcrpath, const char *name)
/* bundle = lcrpath + '/' + name + '\0' */
len = strlen(lcrpath) + strlen(name) + 2;
bundle = util_common_calloc_s(len);
bundle = lcr_util_common_calloc_s(len);
if (bundle == NULL) {
ERROR("Out of memory");
goto cleanup;
......@@ -961,12 +961,12 @@ static int lcr_write_file(const char *path, const char *data, size_t len)
return -1;
}
if (util_ensure_path(&real_path, path) < 0) {
if (lcr_util_ensure_path(&real_path, path) < 0) {
ERROR("Failed to ensure path %s", path);
goto out_free;
}
fd = util_open(real_path, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE);
fd = lcr_util_open(real_path, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE);
if (fd == -1) {
ERROR("Create file %s failed", real_path);
lcr_set_error_message(LCR_ERR_RUNTIME, "Create file %s failed", real_path);
......
......@@ -28,7 +28,7 @@ struct lcr_list;
#define SAFE_MALLOC(P, size, ret) \
do { \
(P) = util_common_calloc_s((size)); \
(P) = lcr_util_common_calloc_s((size)); \
if ((P) == NULL) { \
ERROR("Out of memory"); \
(ret) = false; \
......
......@@ -52,7 +52,7 @@ void engine_set_log_prefix(const char *prefix)
}
free(g_engine_log_prefix);
g_engine_log_prefix = util_strdup_s(prefix);
g_engine_log_prefix = lcr_util_strdup_s(prefix);
}
/* engine free log prefix */
......@@ -100,7 +100,7 @@ static int open_fifo(const char *fifo_path)
return nret;
}
fifo_fd = util_open(fifo_path, O_RDWR | O_NONBLOCK, 0);
fifo_fd = lcr_util_open(fifo_path, O_RDWR | O_NONBLOCK, 0);
if (fifo_fd == -1) {
COMMAND_ERROR("Open fifo %s failed: %s", fifo_path, strerror(errno));
return -1;
......@@ -185,11 +185,11 @@ int engine_log_enable(const struct engine_log_config *log)
}
free(g_engine_log_module);
g_engine_log_module = util_strdup_s(log->name);
g_engine_log_module = lcr_util_strdup_s(log->name);
full_path = util_strdup_s(log->file);
full_path = lcr_util_strdup_s(log->file);
nret = util_build_dir(full_path);
nret = lcr_util_build_dir(full_path);
if (nret != 0) {
COMMAND_ERROR("failed to create dir for log file");
goto out;
......@@ -262,7 +262,7 @@ static char *parse_timespec_to_human()
return NULL;
}
return util_strdup_s(date_time);
return lcr_util_strdup_s(date_time);
}
/* use to add log to driver */
......
此差异已折叠。
......@@ -154,55 +154,40 @@ extern "C" {
{ SIGRTMAX - 1, "RTMAX-1" }, { SIGRTMAX, "RTMAX" }, \
}
bool file_exists(const char *path);
bool dir_exists(const char *path);
int wait_for_pid(pid_t pid);
int wait_for_pid_status(pid_t pid);
char *util_string_join(const char *sep, const char **parts, size_t len);
int util_mkdir_p(const char *dir, mode_t mode);
int lcr_wait_for_pid(pid_t pid);
int lcr_wait_for_pid_status(pid_t pid);
char *lcr_util_string_join(const char *sep, const char **parts, size_t len);
char **lcr_string_split_and_trim(const char *str, char _sep);
void lcr_free_array(void **array);
int lcr_grow_array(void ***array, size_t *capacity, size_t new_size, size_t capacity_increment);
size_t lcr_array_len(void **array);
int mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize);
bool util_valid_cmd_arg(const char *arg);
int util_safe_ullong(const char *numstr, unsigned long long *converted);
int util_safe_strtod(const char *numstr, double *converted);
int util_safe_uint(const char *numstr, unsigned int *converted);
int parse_byte_size_string(const char *s, int64_t *converted);
bool util_dir_exists(const char *path);
int util_ensure_path(char **confpath, const char *path);
int util_recursive_rmdir(const char *dirpath, int recursive_depth);
char *util_string_replace(const char *needle, const char *replacement, const char *haystack);
int util_open(const char *filename, int flags, mode_t mode);
FILE *util_fopen(const char *filename, const char *mode);
void *util_common_calloc_s(size_t size);
int util_safe_int(const char *numstr, int *converted);
int util_check_inherited(bool closeall, int fd_to_ignore);
char *util_string_append(const char *post, const char *pre);
char *util_string_split_prefix(size_t prefix_len, const char *file);
int util_build_dir(const char *name);
ssize_t util_write_nointr(int fd, const void *buf, size_t count);
ssize_t util_read_nointr(int fd, void *buf, size_t count);
void util_free_array(char **array);
int util_sig_parse(const char *signame);
bool util_valid_signal(int sig);
size_t util_array_len(char **array);
const char *str_skip_str(const char *str, const char *skip);
int util_array_append(char ***array, const char *element);
int util_safe_llong(const char *numstr, long long *converted);
char *util_strdup_s(const char *src);
int util_null_stdfds(void);
bool util_copy_file(const char *src_file, const char *dst_file, mode_t mode);
bool util_write_file(const char *filepath, const char *content, size_t len, bool add_newline, mode_t mode);
int util_atomic_write_file(const char *filepath, const char *content);
int lcr_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize);
int lcr_util_safe_strtod(const char *numstr, double *converted);
int lcr_util_safe_uint(const char *numstr, unsigned int *converted);
int lcr_parse_byte_size_string(const char *s, int64_t *converted);
bool lcr_util_dir_exists(const char *path);
int lcr_util_ensure_path(char **confpath, const char *path);
int lcr_util_recursive_rmdir(const char *dirpath, int recursive_depth);
char *lcr_util_string_replace(const char *needle, const char *replacement, const char *haystack);
int lcr_util_open(const char *filename, int flags, mode_t mode);
void *lcr_util_common_calloc_s(size_t size);
int lcr_util_safe_int(const char *numstr, int *converted);
int lcr_util_check_inherited(bool closeall, int fd_to_ignore);
char *lcr_util_string_append(const char *post, const char *pre);
char *lcr_util_string_split_prefix(size_t prefix_len, const char *file);
int lcr_util_build_dir(const char *name);
ssize_t lcr_util_write_nointr(int fd, const void *buf, size_t count);
ssize_t lcr_util_read_nointr(int fd, void *buf, size_t count);
size_t lcr_util_array_len(char **array);
int lcr_util_safe_llong(const char *numstr, long long *converted);
char *lcr_util_strdup_s(const char *src);
int lcr_util_null_stdfds(void);
int lcr_util_atomic_write_file(const char *filepath, const char *content);
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册