]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 #include <sys/ioctl.h>
36 #include <sys/param.h>
38 #include <sys/types.h>
41 #include <lxc/lxccontainer.h>
43 #include "arguments.h"
48 lxc_log_define(lxc_console
, lxc
);
50 static int my_parser(struct lxc_arguments
*args
, int c
, char *arg
);
51 static char etoc(const char *expr
);
53 static const struct option my_longopts
[] = {
54 {"tty", required_argument
, 0, 't'},
55 {"escape", required_argument
, 0, 'e'},
59 static struct lxc_arguments my_args
= {
60 .progname
= "lxc-console",
62 --name=NAME [--tty NUMBER]\n\
64 lxc-console logs on the container with the identifier NAME\n\
67 -n, --name=NAME NAME of the container\n\
68 -t, --tty=NUMBER console tty number\n\
69 -e, --escape=PREFIX prefix for escape command\n\
70 --rcfile=FILE Load configuration file FILE\n",
71 .options
= my_longopts
,
74 .log_priority
= "ERROR",
80 static int my_parser(struct lxc_arguments
*args
, int c
, char *arg
)
84 if (lxc_safe_uint(arg
, &args
->ttynum
) < 0)
88 args
->escape
= etoc(arg
);
95 static char etoc(const char *expr
)
97 /* returns "control code" of given expression */
98 char c
= expr
[0] == '^' ? expr
[1] : expr
[0];
100 return 1 + ((c
> 'Z') ? (c
- 'a') : (c
- 'Z'));
103 int main(int argc
, char *argv
[])
106 struct lxc_container
*c
;
109 if (lxc_arguments_parse(&my_args
, argc
, argv
))
112 log
.name
= my_args
.name
;
113 log
.file
= my_args
.log_file
;
114 log
.level
= my_args
.log_priority
;
115 log
.prefix
= my_args
.progname
;
116 log
.quiet
= my_args
.quiet
;
117 log
.lxcpath
= my_args
.lxcpath
[0];
119 if (lxc_log_init(&log
))
122 c
= lxc_container_new(my_args
.name
, my_args
.lxcpath
[0]);
124 ERROR("System error loading container");
128 if (my_args
.rcfile
) {
131 if (!c
->load_config(c
, my_args
.rcfile
)) {
132 ERROR("Failed to load rcfile");
133 lxc_container_put(c
);
137 c
->configfile
= strdup(my_args
.rcfile
);
138 if (!c
->configfile
) {
139 ERROR("Out of memory setting new config filename");
140 lxc_container_put(c
);
145 if (!c
->may_control(c
)) {
146 ERROR("Insufficent privileges to control %s", my_args
.name
);
147 lxc_container_put(c
);
151 if (!c
->is_running(c
)) {
152 ERROR("%s is not running", my_args
.name
);
153 lxc_container_put(c
);
157 ret
= c
->console(c
, my_args
.ttynum
, 0, 1, 2, my_args
.escape
);
159 lxc_container_put(c
);
163 lxc_container_put(c
);