Commit 1cd7db65 by 2xsec

tools: lxc-autostart: share internal API symbols

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent 1b36d9e9
...@@ -266,7 +266,7 @@ LDADD=liblxc.la @CAP_LIBS@ @GNUTLS_LIBS@ @SELINUX_LIBS@ @SECCOMP_LIBS@ ...@@ -266,7 +266,7 @@ LDADD=liblxc.la @CAP_LIBS@ @GNUTLS_LIBS@ @SELINUX_LIBS@ @SECCOMP_LIBS@
if ENABLE_TOOLS if ENABLE_TOOLS
lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c
lxc_autostart_SOURCES = tools/lxc_autostart.c tools/arguments.c tools/tool_utils.c lxc_autostart_SOURCES = tools/lxc_autostart.c tools/arguments.c
lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c
lxc_config_SOURCES = tools/lxc_config.c tools/arguments.c tools/tool_utils.c lxc_config_SOURCES = tools/lxc_config.c tools/arguments.c tools/tool_utils.c
lxc_console_SOURCES = tools/lxc_console.c tools/arguments.c tools/tool_utils.c lxc_console_SOURCES = tools/lxc_console.c tools/arguments.c tools/tool_utils.c
......
...@@ -27,14 +27,17 @@ ...@@ -27,14 +27,17 @@
#include <lxc/lxccontainer.h> #include <lxc/lxccontainer.h>
#include "arguments.h" #include "arguments.h"
#include "tool_list.h" #include "list.h"
#include "tool_utils.h" #include "log.h"
#include "utils.h"
lxc_log_define(lxc_autostart, lxc);
static struct lxc_list *accumulate_list(char *input, char *delimiter, struct lxc_list *str_list); static struct lxc_list *accumulate_list(char *input, char *delimiter, struct lxc_list *str_list);
struct lxc_list *cmd_groups_list = NULL; struct lxc_list *cmd_groups_list = NULL;
static int my_parser(struct lxc_arguments* args, int c, char* arg) static int my_parser(struct lxc_arguments *args, int c, char *arg)
{ {
switch (c) { switch (c) {
case 'k': case 'k':
...@@ -101,48 +104,26 @@ Options:\n\ ...@@ -101,48 +104,26 @@ Options:\n\
.timeout = 60, .timeout = 60,
}; };
int list_contains_entry( char *str_ptr, struct lxc_list *p1 ) { static int list_contains_entry(char *str_ptr, struct lxc_list *p1) {
struct lxc_list *it1; struct lxc_list *it1;
/* /*
* If the entry is NULL or the empty string and the list * If the entry is NULL or the empty string and the list
* is NULL, we have a match * is NULL, we have a match
*/ */
if (! p1 && ! str_ptr) if (!p1 && !str_ptr)
return 1;
if (! p1 && ! *str_ptr)
return 1; return 1;
if (!p1) if (!p1 && !(*str_ptr))
return 0;
lxc_list_for_each(it1, p1) {
if (strcmp(it1->elem, str_ptr) == 0)
return 1;
}
return 0;
}
int lists_contain_common_entry(struct lxc_list *p1, struct lxc_list *p2) {
struct lxc_list *it1;
struct lxc_list *it2;
if (!p1 && !p2)
return 1; return 1;
if (!p1) if (!p1)
return 0; return 0;
if (!p2)
return 0;
lxc_list_for_each(it1, p1) { lxc_list_for_each(it1, p1) {
lxc_list_for_each(it2, p2) { if (!strncmp(it1->elem, str_ptr, strlen(it1->elem)))
if (strcmp(it1->elem, it2->elem) == 0)
return 1; return 1;
} }
}
return 0; return 0;
} }
...@@ -167,6 +148,11 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter, ...@@ -167,6 +148,11 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter,
workstr_list = str_list; workstr_list = str_list;
if (!workstr_list) { if (!workstr_list) {
workstr_list = malloc(sizeof(*workstr_list)); workstr_list = malloc(sizeof(*workstr_list));
if (!workstr_list) {
free(workstr);
return NULL;
}
lxc_list_init(workstr_list); lxc_list_init(workstr_list);
} }
...@@ -185,9 +171,9 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter, ...@@ -185,9 +171,9 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter,
*/ */
if (list_contains_entry(workptr, workstr_list)) { if (list_contains_entry(workptr, workstr_list)) {
if (*workptr) if (*workptr)
fprintf(stderr, "Duplicate group \"%s\" in list - ignoring\n", workptr); ERROR("Duplicate group \"%s\" in list - ignoring", workptr);
else else
fprintf(stderr, "Duplicate NULL group in list - ignoring\n"); ERROR("Duplicate NULL group in list - ignoring");
} else { } else {
worklist = malloc(sizeof(*worklist)); worklist = malloc(sizeof(*worklist));
if (!worklist) if (!worklist)
...@@ -218,6 +204,9 @@ static struct lxc_list *get_list(char *input, char *delimiter) ...@@ -218,6 +204,9 @@ static struct lxc_list *get_list(char *input, char *delimiter)
struct lxc_list *workstr_list; struct lxc_list *workstr_list;
workstr_list = malloc(sizeof(*workstr_list)); workstr_list = malloc(sizeof(*workstr_list));
if (!workstr_list)
return NULL;
lxc_list_init(workstr_list); lxc_list_init(workstr_list);
workstr = strdup(input); workstr = strdup(input);
...@@ -260,7 +249,7 @@ static struct lxc_list *get_config_list(struct lxc_container *c, char *key) ...@@ -260,7 +249,7 @@ static struct lxc_list *get_config_list(struct lxc_container *c, char *key)
return NULL; return NULL;
value = (char *)malloc(sizeof(char) * len + 1); value = (char *)malloc(sizeof(char) * len + 1);
if (value == NULL) if (!value)
return NULL; return NULL;
if (c->get_config_item(c, key, value, len + 1) != len) { if (c->get_config_item(c, key, value, len + 1) != len) {
...@@ -289,7 +278,7 @@ static int get_config_integer(struct lxc_container *c, char *key) ...@@ -289,7 +278,7 @@ static int get_config_integer(struct lxc_container *c, char *key)
return 0; return 0;
value = (char *)malloc(sizeof(char) * len + 1); value = (char *)malloc(sizeof(char) * len + 1);
if (value == NULL) if (!value)
return 0; return 0;
if (c->get_config_item(c, key, value, len + 1) != len) { if (c->get_config_item(c, key, value, len + 1) != len) {
...@@ -314,7 +303,7 @@ static int cmporder(const void *p1, const void *p2) ...@@ -314,7 +303,7 @@ static int cmporder(const void *p1, const void *p2)
int c2_order = get_config_integer(c2, "lxc.start.order"); int c2_order = get_config_integer(c2, "lxc.start.order");
if (c1_order == c2_order) if (c1_order == c2_order)
return strcmp(c1->name, c2->name); return strncmp(c1->name, c2->name, strlen(c1->name));
return (c1_order - c2_order); return (c1_order - c2_order);
} }
...@@ -372,7 +361,7 @@ int main(int argc, char *argv[]) ...@@ -372,7 +361,7 @@ int main(int argc, char *argv[])
qsort(&containers[0], count, sizeof(struct lxc_container *), cmporder); qsort(&containers[0], count, sizeof(struct lxc_container *), cmporder);
if (cmd_groups_list && my_args.all) if (cmd_groups_list && my_args.all)
fprintf(stderr, "Specifying -a (all) with -g (groups) doesn't make sense. All option overrides.\n"); ERROR("Specifying -a (all) with -g (groups) doesn't make sense. All option overrides.");
/* We need a default cmd_groups_list even for the -a /* We need a default cmd_groups_list even for the -a
* case in order to force a pass through the loop for * case in order to force a pass through the loop for
...@@ -404,27 +393,28 @@ int main(int argc, char *argv[]) ...@@ -404,27 +393,28 @@ int main(int argc, char *argv[])
/* We're done with this container */ /* We're done with this container */
if ( lxc_container_put(c) > 0 ) if ( lxc_container_put(c) > 0 )
containers[i] = NULL; containers[i] = NULL;
continue; continue;
} }
if (!my_args.ignore_auto && if (!my_args.ignore_auto &&
get_config_integer(c, "lxc.start.auto") != 1) { get_config_integer(c, "lxc.start.auto") != 1) {
/* We're done with this container */ /* We're done with this container */
if ( lxc_container_put(c) > 0 ) if (lxc_container_put(c) > 0)
containers[i] = NULL; containers[i] = NULL;
continue; continue;
} }
if (!my_args.all) { if (!my_args.all) {
/* Filter by group */ /* Filter by group */
if( ! c_groups_lists[i] ) { if (!c_groups_lists[i]) {
/* Now we're loading up a container's groups */ /* Now we're loading up a container's groups */
c_groups_lists[i] = get_config_list(c, "lxc.group"); c_groups_lists[i] = get_config_list(c, "lxc.group");
} }
ret = list_contains_entry(cmd_group->elem, c_groups_lists[i]); ret = list_contains_entry(cmd_group->elem, c_groups_lists[i]);
if (ret == 0) {
if ( ret == 0 ) {
/* Not in the target group this pass so /* Not in the target group this pass so
* leave in the list for subsequent * leave in the list for subsequent
* passes. * passes.
...@@ -445,10 +435,8 @@ int main(int argc, char *argv[]) ...@@ -445,10 +435,8 @@ int main(int argc, char *argv[])
} }
else { else {
if (!c->shutdown(c, my_args.timeout)) { if (!c->shutdown(c, my_args.timeout)) {
if (!c->stop(c)) { if (!c->stop(c))
fprintf(stderr, "Error shutting down container: %s\n", c->name); ERROR("Error shutting down container: %s", c->name);
fflush(stderr);
}
} }
} }
} }
...@@ -460,10 +448,8 @@ int main(int argc, char *argv[]) ...@@ -460,10 +448,8 @@ int main(int argc, char *argv[])
fflush(stdout); fflush(stdout);
} }
else { else {
if (!c->stop(c)) { if (!c->stop(c))
fprintf(stderr, "Error killing container: %s\n", c->name); ERROR("Error killing container: %s", c->name);
fflush(stderr);
}
} }
} }
} else if (my_args.reboot) { } else if (my_args.reboot) {
...@@ -475,10 +461,8 @@ int main(int argc, char *argv[]) ...@@ -475,10 +461,8 @@ int main(int argc, char *argv[])
fflush(stdout); fflush(stdout);
} }
else { else {
if (!c->reboot(c)) { if (!c->reboot(c))
fprintf(stderr, "Error rebooting container: %s\n", c->name); ERROR("Error rebooting container: %s", c->name);
fflush(stderr);
}
else else
sleep(get_config_integer(c, "lxc.start.delay")); sleep(get_config_integer(c, "lxc.start.delay"));
} }
...@@ -492,10 +476,8 @@ int main(int argc, char *argv[]) ...@@ -492,10 +476,8 @@ int main(int argc, char *argv[])
fflush(stdout); fflush(stdout);
} }
else { else {
if (!c->start(c, 0, NULL)) { if (!c->start(c, 0, NULL))
fprintf(stderr, "Error starting container: %s\n", c->name); ERROR("Error starting container: %s", c->name);
fflush(stderr);
}
else else
sleep(get_config_integer(c, "lxc.start.delay")); sleep(get_config_integer(c, "lxc.start.delay"));
} }
...@@ -507,9 +489,10 @@ int main(int argc, char *argv[]) ...@@ -507,9 +489,10 @@ int main(int argc, char *argv[])
* then we're done with this container... We can dump any * then we're done with this container... We can dump any
* c_groups_list and the container itself. * c_groups_list and the container itself.
*/ */
if ( lxc_container_put(c) > 0 ) if (lxc_container_put(c) > 0)
containers[i] = NULL; containers[i] = NULL;
if ( c_groups_lists ) {
if (c_groups_lists) {
toss_list(c_groups_lists[i]); toss_list(c_groups_lists[i]);
c_groups_lists[i] = NULL; c_groups_lists[i] = NULL;
} }
...@@ -527,7 +510,7 @@ int main(int argc, char *argv[]) ...@@ -527,7 +510,7 @@ int main(int argc, char *argv[])
} }
free(c_groups_lists); free(c_groups_lists);
toss_list( cmd_groups_list ); toss_list(cmd_groups_list);
free(containers); free(containers);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment