INIT_LIST_HEAD(&new->procs);
new->hooks_version = 0;
for (i = 0; i < NUM_LXC_HOOKS; i++)
- lxc_list_init(&new->hooks[i]);
+ INIT_LIST_HEAD(&new->hooks[i]);
lxc_list_init(&new->groups);
INIT_LIST_HEAD(&new->state_clients);
new->lsm_aa_profile = NULL;
static bool verify_start_hooks(struct lxc_conf *conf)
{
char path[PATH_MAX];
- struct lxc_list *it;
+ struct string_entry *hook;
- lxc_list_for_each (it, &conf->hooks[LXCHOOK_START]) {
+ list_for_each_entry(hook, &conf->hooks[LXCHOOK_START], head) {
int ret;
- char *hookname = it->elem;
+ char *hookname = hook->val;
ret = strnprintf(path, sizeof(path), "%s%s",
conf->rootfs.path ? conf->rootfs.mount : "",
int run_lxc_hooks(const char *name, char *hookname, struct lxc_conf *conf,
char *argv[])
{
- struct lxc_list *it;
int which;
+ struct string_entry *entry;
for (which = 0; which < NUM_LXC_HOOKS; which ++) {
if (strequal(hookname, lxchook_names[which]))
if (which >= NUM_LXC_HOOKS)
return -1;
- lxc_list_for_each (it, &conf->hooks[which]) {
+ list_for_each_entry(entry, &conf->hooks[which], head) {
int ret;
- char *hook = it->elem;
+ char *hook = entry->val;
ret = run_script_argv(name, conf->hooks_version, "lxc", hook,
hookname, argv);
int lxc_clear_hooks(struct lxc_conf *c, const char *key)
{
- struct lxc_list *it, *next;
const char *k = NULL;
bool all = false, done = false;
+ struct string_entry *entry, *nentry;
if (strequal(key, "lxc.hook"))
all = true;
for (int i = 0; i < NUM_LXC_HOOKS; i++) {
if (all || strequal(k, lxchook_names[i])) {
- lxc_list_for_each_safe (it, &c->hooks[i], next) {
- lxc_list_del(it);
- free(it->elem);
- free(it);
+ list_for_each_entry_safe(entry, nentry, &c->hooks[i], head) {
+ list_del(&entry->head);
+ free(entry->val);
+ free(entry);
}
- lxc_list_init(&c->hooks[i]);
-
+ INIT_LIST_HEAD(&c->hooks[i]);
done = true;
}
}
struct {
unsigned int hooks_version;
- struct lxc_list hooks[NUM_LXC_HOOKS];
+ struct list_head hooks[NUM_LXC_HOOKS];
};
char *lsm_aa_profile;
static int add_hook(struct lxc_conf *lxc_conf, int which, __owns char *hook)
{
__do_free char *val = hook;
- struct lxc_list *hooklist;
+ __do_free struct string_entry *entry;
- hooklist = lxc_list_new();
- if (!hooklist)
+ entry = zalloc(sizeof(struct string_entry));
+ if (!entry)
return ret_errno(ENOMEM);
- hooklist->elem = move_ptr(val);
- lxc_list_add_tail(&lxc_conf->hooks[which], hooklist);
+ entry->val = move_ptr(val);
+ list_add_tail(&entry->head, &lxc_conf->hooks[which]);
+ move_ptr(entry);
return 0;
}
{
char *subkey;
int len, fulllen = 0, found = -1;
- struct lxc_list *it;
+ struct string_entry *entry;
int i;
subkey = strchr(key, '.');
else
memset(retv, 0, inlen);
- lxc_list_for_each(it, &c->hooks[found]) {
- strprint(retv, inlen, "%s\n", (char *)it->elem);
+ list_for_each_entry(entry, &c->hooks[found], head) {
+ strprint(retv, inlen, "%s\n", entry->val);
}
return fulllen;
goto out;
}
- if (conf && !lxc_list_empty(&conf->hooks[LXCHOOK_DESTROY])) {
+ if (conf && !list_empty(&conf->hooks[LXCHOOK_DESTROY])) {
/* Start of environment variable setup for hooks */
if (setenv("LXC_NAME", c->name, 1))
SYSERROR("Failed to set environment variable for container name");
{
__do_free char *cpath = NULL;
int i, len, ret;
- struct lxc_list *it;
+ struct string_entry *entry;
len = strlen(oldc->config_path) + strlen(oldc->name) + 3;
- cpath = must_realloc(NULL, len);
+ cpath = malloc(len);
+ if (!cpath)
+ return ret_errno(ENOMEM);
+
ret = strnprintf(cpath, len, "%s/%s/", oldc->config_path, oldc->name);
if (ret < 0)
return -1;
- for (i=0; i<NUM_LXC_HOOKS; i++) {
- lxc_list_for_each(it, &c->lxc_conf->hooks[i]) {
- char *hookname = it->elem;
- char *fname = strrchr(hookname, '/');
+ for (i = 0; i < NUM_LXC_HOOKS; i++) {
+ list_for_each_entry(entry, &c->lxc_conf->hooks[i], head) {
+ __do_free char *hookname = NULL;
+ char *fname, *new_hook;
char tmppath[PATH_MAX];
- if (!fname) /* relative path - we don't support, but maybe we should */
+
+ fname = strrchr(hookname, '/');
+ if (!fname)
return 0;
- if (!strnequal(hookname, cpath, len - 1)) {
- /* this hook is public - ignore */
+ /* If this hook is public - ignore. */
+ if (!strnequal(hookname, cpath, len - 1))
continue;
- }
/* copy the script, and change the entry in confile */
ret = strnprintf(tmppath, sizeof(tmppath), "%s/%s/%s",
if (ret < 0)
return -1;
- ret = copy_file(it->elem, tmppath);
+ ret = copy_file(entry->val, tmppath);
if (ret < 0)
return -1;
- free(it->elem);
+ new_hook = strdup(tmppath);
+ if (!new_hook)
+ return syserror("out of memory copying hook path");
- it->elem = strdup(tmppath);
- if (!it->elem) {
- ERROR("out of memory copying hook path");
- return -1;
- }
+ hookname = move_ptr(entry->val);
+ entry->val = move_ptr(new_hook);
}
}
if (!clone_update_unexp_hooks(c->lxc_conf, oldc->config_path,
- c->config_path, oldc->name, c->name)) {
- ERROR("Error saving new hooks in clone");
- return -1;
+ c->config_path, oldc->name, c->name)) {
+ return syserror_ret(-1, "Error saving new hooks in clone");
}
do_lxcapi_save_config(c, NULL);
return 0;
}
-
static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c)
{
char newpath[PATH_MAX];
bdev->dest = strdup(lxc_storage_get_path(bdev->src, bdev->type));
}
- if (!lxc_list_empty(&conf->hooks[LXCHOOK_CLONE])) {
+ if (!list_empty(&conf->hooks[LXCHOOK_CLONE])) {
/* Start of environment variable setup for hooks */
if (c0->name && setenv("LXC_SRC_NAME", c0->name, 1))
SYSERROR("failed to set environment variable for source container name");