mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-27 09:48:32 +00:00
lxccontainer: fail when container can't be loaded
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
89ad5d7bf0
commit
4a0d9c9972
@ -2318,29 +2318,6 @@ static bool array_contains(char ***names, char *cname, int size)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool remove_from_array(char ***names, char *cname, int size)
|
|
||||||
{
|
|
||||||
char **result;
|
|
||||||
|
|
||||||
result = get_from_array(names, cname, size);
|
|
||||||
if (result) {
|
|
||||||
size_t i = result - *names;
|
|
||||||
char **newnames;
|
|
||||||
|
|
||||||
free(*result);
|
|
||||||
memmove(*names + i, *names + i + 1, (size - i - 1) * sizeof(char *));
|
|
||||||
|
|
||||||
newnames = realloc(*names, (size - 1) * sizeof(char *));
|
|
||||||
if (!newnames)
|
|
||||||
return ret_set_errno(true, ENOMEM);
|
|
||||||
|
|
||||||
*names = newnames;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **do_lxcapi_get_interfaces(struct lxc_container *c)
|
static char **do_lxcapi_get_interfaces(struct lxc_container *c)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -5602,14 +5579,11 @@ int list_active_containers(const char *lxcpath, char ***nret,
|
|||||||
|
|
||||||
c = lxc_container_new(p, lxcpath);
|
c = lxc_container_new(p, lxcpath);
|
||||||
if (!c) {
|
if (!c) {
|
||||||
INFO("Container %s:%s is running but could not be loaded",
|
INFO("Container %s:%s is running but could not be loaded", lxcpath, p);
|
||||||
lxcpath, p);
|
|
||||||
|
|
||||||
remove_from_array(&ct_name, p, ct_name_cnt--);
|
|
||||||
if (is_hashed)
|
if (is_hashed)
|
||||||
free(p);
|
free(p);
|
||||||
|
|
||||||
continue;
|
goto free_cret_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_hashed)
|
if (is_hashed)
|
||||||
@ -5664,9 +5638,8 @@ out:
|
|||||||
int list_all_containers(const char *lxcpath, char ***nret,
|
int list_all_containers(const char *lxcpath, char ***nret,
|
||||||
struct lxc_container ***cret)
|
struct lxc_container ***cret)
|
||||||
{
|
{
|
||||||
int i, ret, active_cnt, ct_cnt, ct_list_cnt;
|
int active_cnt, ct_cnt, ct_list_cnt, ret;
|
||||||
char **active_name;
|
char **active_name = NULL, **ct_name = NULL;
|
||||||
char **ct_name = NULL;
|
|
||||||
struct lxc_container **ct_list = NULL;
|
struct lxc_container **ct_list = NULL;
|
||||||
|
|
||||||
ct_cnt = list_defined_containers(lxcpath, &ct_name, NULL);
|
ct_cnt = list_defined_containers(lxcpath, &ct_name, NULL);
|
||||||
@ -5679,67 +5652,67 @@ int list_all_containers(const char *lxcpath, char ***nret,
|
|||||||
goto free_ct_name;
|
goto free_ct_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < active_cnt; i++) {
|
ret = -EINVAL;
|
||||||
if (!array_contains(&ct_name, active_name[i], ct_cnt)) {
|
for (int i = 0; i < active_cnt; i++) {
|
||||||
if (!add_to_array(&ct_name, active_name[i], ct_cnt)) {
|
if (array_contains(&ct_name, active_name[i], ct_cnt))
|
||||||
ret = -1;
|
continue;
|
||||||
|
|
||||||
|
if (!add_to_array(&ct_name, active_name[i], ct_cnt))
|
||||||
goto free_active_name;
|
goto free_active_name;
|
||||||
}
|
|
||||||
|
|
||||||
ct_cnt++;
|
ct_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_disarm(active_name[i]);
|
if (cret) {
|
||||||
}
|
ct_list_cnt = 0;
|
||||||
|
for (int i = 0; i < ct_cnt; i++) {
|
||||||
free_disarm(active_name);
|
__put_lxc_container struct lxc_container *c = NULL;
|
||||||
active_cnt = 0;
|
|
||||||
|
|
||||||
for (i = 0, ct_list_cnt = 0; i < ct_cnt && cret; i++) {
|
|
||||||
struct lxc_container *c;
|
|
||||||
|
|
||||||
c = lxc_container_new(ct_name[i], lxcpath);
|
c = lxc_container_new(ct_name[i], lxcpath);
|
||||||
if (!c) {
|
if (!c) {
|
||||||
WARN("Container %s:%s could not be loaded", lxcpath, ct_name[i]);
|
WARN("Container %s:%s could not be loaded", lxcpath, ct_name[i]);
|
||||||
remove_from_array(&ct_name, ct_name[i], ct_cnt--);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!add_to_clist(&ct_list, c, ct_list_cnt, false)) {
|
|
||||||
lxc_container_put(c);
|
|
||||||
ret = -1;
|
|
||||||
goto free_ct_list;
|
goto free_ct_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!add_to_clist(&ct_list, c, ct_list_cnt, false))
|
||||||
|
goto free_ct_list;
|
||||||
|
|
||||||
ct_list_cnt++;
|
ct_list_cnt++;
|
||||||
|
move_ptr(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cret)
|
|
||||||
*cret = ct_list;
|
*cret = ct_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < active_cnt; i++)
|
||||||
|
free(active_name[i]);
|
||||||
|
free(active_name);
|
||||||
|
|
||||||
if (nret) {
|
if (nret) {
|
||||||
*nret = ct_name;
|
*nret = ct_name;
|
||||||
} else {
|
} else {
|
||||||
ret = ct_cnt;
|
for (int i = 0; i < ct_cnt; i++)
|
||||||
goto free_ct_name;
|
free(ct_name[i]);
|
||||||
|
free(ct_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ct_cnt;
|
return ct_cnt;
|
||||||
|
|
||||||
free_ct_list:
|
free_ct_list:
|
||||||
for (i = 0; i < ct_list_cnt; i++)
|
for (int i = 0; i < ct_list_cnt; i++)
|
||||||
lxc_container_put(ct_list[i]);
|
lxc_container_put(ct_list[i]);
|
||||||
free(ct_list);
|
free(ct_list);
|
||||||
|
|
||||||
free_active_name:
|
free_active_name:
|
||||||
for (i = 0; i < active_cnt; i++)
|
for (int i = 0; i < active_cnt; i++)
|
||||||
free(active_name[i]);
|
free(active_name[i]);
|
||||||
free(active_name);
|
free(active_name);
|
||||||
|
|
||||||
free_ct_name:
|
free_ct_name:
|
||||||
for (i = 0; i < ct_cnt; i++)
|
for (int i = 0; i < ct_cnt; i++)
|
||||||
free(ct_name[i]);
|
free(ct_name[i]);
|
||||||
free(ct_name);
|
free(ct_name);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user