]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc_console.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <sys/param.h>
36 #include <sys/types.h>
39 #include <sys/ioctl.h>
41 #include "../lxc/lxccontainer.h"
46 #include "arguments.h"
49 lxc_log_define(lxc_console_ui
, lxc_console
);
51 static char etoc(const char *expr
)
53 /* returns "control code" of given expression */
54 char c
= expr
[0] == '^' ? expr
[1] : expr
[0];
55 return 1 + ((c
> 'Z') ? (c
- 'a') : (c
- 'Z'));
58 static int my_parser(struct lxc_arguments
* args
, int c
, char* arg
)
61 case 't': args
->ttynum
= atoi(arg
); break;
62 case 'e': args
->escape
= etoc(arg
); break;
67 static const struct option my_longopts
[] = {
68 {"tty", required_argument
, 0, 't'},
69 {"escape", required_argument
, 0, 'e'},
73 static struct lxc_arguments my_args
= {
74 .progname
= "lxc-console",
76 --name=NAME [--tty NUMBER]\n\
78 lxc-console logs on the container with the identifier NAME\n\
81 -n, --name=NAME NAME for name of the container\n\
82 -t, --tty=NUMBER console tty number\n\
83 -e, --escape=PREFIX prefix for escape command\n",
84 .options
= my_longopts
,
91 int main(int argc
, char *argv
[])
94 struct lxc_container
*c
;
96 ret
= lxc_arguments_parse(&my_args
, argc
, argv
);
100 ret
= lxc_log_init(my_args
.name
, my_args
.log_file
, my_args
.log_priority
,
101 my_args
.progname
, my_args
.quiet
, my_args
.lxcpath
[0]);
105 c
= lxc_container_new(my_args
.name
, my_args
.lxcpath
[0]);
107 fprintf(stderr
, "System error loading container\n");
111 if (!c
->is_running(c
)) {
112 fprintf(stderr
, "%s is not running\n", my_args
.name
);
116 ret
= c
->console(c
, my_args
.ttynum
, 0, 1, 2, my_args
.escape
);