From: 2xsec Date: Fri, 29 Jun 2018 05:54:07 +0000 (+0900) Subject: tools: lxc-console: share internal API symbols X-Git-Tag: lxc-3.1.0~225^2~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=138eda996fb0ac0106ce3e4468227c0696d9a60a;p=thirdparty%2Flxc.git tools: lxc-console: share internal API symbols Signed-off-by: 2xsec --- diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index f5ee8b17c..967bb2138 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -269,7 +269,7 @@ lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c lxc_autostart_SOURCES = tools/lxc_autostart.c tools/arguments.c lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c lxc_config_SOURCES = tools/lxc_config.c tools/arguments.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 lxc_destroy_SOURCES = tools/lxc_destroy.c tools/arguments.c tools/tool_utils.c lxc_device_SOURCES = tools/lxc_device.c tools/arguments.c tools/tool_utils.c lxc_execute_SOURCES = tools/lxc_execute.c tools/arguments.c tools/tool_utils.c diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c index 7c22a7a40..11cddd5fe 100644 --- a/src/lxc/tools/lxc_console.c +++ b/src/lxc/tools/lxc_console.c @@ -39,16 +39,20 @@ #include #include "arguments.h" -#include "tool_utils.h" +#include "log.h" +#include "utils.h" + +lxc_log_define(lxc_console, lxc); static char etoc(const char *expr) { /* returns "control code" of given expression */ char c = expr[0] == '^' ? expr[1] : expr[0]; + return 1 + ((c > 'Z') ? (c - 'a') : (c - 'Z')); } -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) { case 't': @@ -59,6 +63,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) args->escape = etoc(arg); break; } + return 0; } @@ -95,7 +100,7 @@ int main(int argc, char *argv[]) ret = lxc_arguments_parse(&my_args, argc, argv); if (ret) - return EXIT_FAILURE; + exit(EXIT_FAILURE); /* Only create log if explicitly instructed */ if (my_args.log_file || my_args.log_priority) { @@ -112,33 +117,35 @@ int main(int argc, char *argv[]) c = lxc_container_new(my_args.name, my_args.lxcpath[0]); if (!c) { - fprintf(stderr, "System error loading container\n"); + ERROR("System error loading container"); exit(EXIT_FAILURE); } if (my_args.rcfile) { c->clear_config(c); + if (!c->load_config(c, my_args.rcfile)) { - fprintf(stderr, "Failed to load rcfile\n"); + ERROR("Failed to load rcfile"); lxc_container_put(c); exit(EXIT_FAILURE); } + c->configfile = strdup(my_args.rcfile); if (!c->configfile) { - fprintf(stderr, "Out of memory setting new config filename\n"); + ERROR("Out of memory setting new config filename"); lxc_container_put(c); exit(EXIT_FAILURE); } } if (!c->may_control(c)) { - fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name); + ERROR("Insufficent privileges to control %s", my_args.name); lxc_container_put(c); exit(EXIT_FAILURE); } if (!c->is_running(c)) { - fprintf(stderr, "%s is not running\n", my_args.name); + ERROR("%s is not running", my_args.name); lxc_container_put(c); exit(EXIT_FAILURE); } @@ -148,6 +155,7 @@ int main(int argc, char *argv[]) lxc_container_put(c); exit(EXIT_FAILURE); } + lxc_container_put(c); exit(EXIT_SUCCESS); }