Skip to content

Commit

Permalink
tools: lxc-console: share internal API symbols
Browse files Browse the repository at this point in the history
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
  • Loading branch information
2xsec authored and Christian Brauner committed Jul 2, 2018
1 parent d33cb9b commit bc46bee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lxc/Makefile.am
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions src/lxc/tools/lxc_console.c
Expand Up @@ -39,16 +39,20 @@
#include <lxc/lxccontainer.h>

#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':
Expand All @@ -59,6 +63,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
args->escape = etoc(arg);
break;
}

return 0;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -148,6 +155,7 @@ int main(int argc, char *argv[])
lxc_container_put(c);
exit(EXIT_FAILURE);
}

lxc_container_put(c);
exit(EXIT_SUCCESS);
}

0 comments on commit bc46bee

Please sign in to comment.