Esempio n. 1
0
static int cmporder(const void *p1, const void *p2) {
	struct lxc_container *c1 = *(struct lxc_container **)p1;
	struct lxc_container *c2 = *(struct lxc_container **)p2;

	int c1_order = get_config_integer(c1, "lxc.start.order");
	int c2_order = get_config_integer(c2, "lxc.start.order");

	if (c1_order == c2_order)
		return strcmp(c1->name, c2->name);
	else
		return (c1_order - c2_order);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    int count = 0;
    int i = 0;
    int ret = 0;
    struct lxc_container **containers = NULL;
    struct lxc_list *cmd_groups_list = NULL;
    struct lxc_list *c_groups_list = NULL;
    struct lxc_list *it, *next;
    char *const default_start_args[] = {
        "/sbin/init",
        '\0',
    };

    if (lxc_arguments_parse(&my_args, argc, argv))
        return 1;

    count = list_defined_containers(NULL, NULL, &containers);

    if (count < 0)
        return 1;

    qsort(&containers[0], count, sizeof(struct lxc_container *), cmporder);

    if (my_args.groups && !my_args.all)
        cmd_groups_list = get_list((char*)my_args.groups, ",");

    for (i = 0; i < count; i++) {
        struct lxc_container *c = containers[i];

        if (!c->may_control(c)) {
            lxc_container_put(c);
            continue;
        }

        if (get_config_integer(c, "lxc.start.auto") != 1) {
            lxc_container_put(c);
            continue;
        }

        if (!my_args.all) {
            /* Filter by group */
            c_groups_list = get_config_list(c, "lxc.group");

            ret = lists_contain_common_entry(cmd_groups_list, c_groups_list);

            if (c_groups_list) {
                lxc_list_for_each_safe(it, c_groups_list, next) {
                    lxc_list_del(it);
                    free(it->elem);
                    free(it);
                }
                free(c_groups_list);
            }

            if (ret == 0) {
                lxc_container_put(c);
                continue;
            }
        }