]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc_restart.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2010
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
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
29 #include <sys/types.h>
38 #include "arguments.h"
40 lxc_log_define(lxc_restart_ui
, lxc_restart
);
42 static struct lxc_list defines
;
44 static int my_checker(const struct lxc_arguments
* args
)
46 if ((!args
->statefile
) && (args
->statefd
== -1)) {
47 lxc_error(args
, "no statefile specified");
51 if ((args
->statefile
) && (args
->statefd
!= -1)) {
52 lxc_error(args
, "--statefile AND --statefd abnormally set");
59 static int my_parser(struct lxc_arguments
* args
, int c
, char* arg
)
62 case 'S': args
->statefile
= arg
; break;
63 case 'f': args
->rcfile
= arg
; break;
64 case 'p': args
->flags
= LXC_FLAG_PAUSE
; break;
65 case 's': return lxc_config_define_add(&defines
, arg
);
68 fd
= lxc_arguments_str_to_int(args
, arg
);
80 static const struct option my_longopts
[] = {
81 {"statefile", required_argument
, 0, 'S'},
82 {"statefd", required_argument
, 0, 'd'},
83 {"rcfile", required_argument
, 0, 'f'},
84 {"pause", no_argument
, 0, 'p'},
85 {"define", required_argument
, 0, 's'},
89 static struct lxc_arguments my_args
= {
90 .progname
= "lxc-restart",
92 --name=NAME --statefile FILE\n\
94 lxc-restart restarts from FILE the NAME container\n\
97 -n, --name=NAME NAME for name of the container\n\
98 -p, --pause do not unfreeze the container after the restart\n\
99 -S, --statefile=FILE read the container state from this file, or\n\
100 -d, --statefd=FD read the container state from this file descriptor\n\
101 -f, --rcfile=FILE Load configuration file FILE\n\
102 -s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
103 .options
= my_longopts
,
105 .checker
= my_checker
,
110 int main(int argc
, char *argv
[])
115 struct lxc_conf
*conf
;
117 lxc_list_init(&defines
);
122 if (lxc_arguments_parse(&my_args
, argc
, argv
))
125 if (lxc_log_init(my_args
.name
, my_args
.log_file
, my_args
.log_priority
,
126 my_args
.progname
, my_args
.quiet
))
129 /* rcfile is specified in the cli option */
131 rcfile
= (char *)my_args
.rcfile
;
135 rc
= asprintf(&rcfile
, LXCPATH
"/%s/config", my_args
.name
);
137 SYSERROR("failed to allocate memory");
141 /* container configuration does not exist */
142 if (access(rcfile
, F_OK
)) {
148 conf
= lxc_conf_init();
150 ERROR("failed to initialize configuration");
154 if (rcfile
&& lxc_config_read(rcfile
, conf
)) {
155 ERROR("failed to read configuration file");
159 if (lxc_config_define_load(&defines
, conf
))
162 if (my_args
.statefd
!= -1)
163 sfd
= my_args
.statefd
;
165 #define OPEN_READ_MODE O_RDONLY | O_CLOEXEC | O_LARGEFILE
166 if (my_args
.statefile
) {
167 sfd
= open(my_args
.statefile
, OPEN_READ_MODE
, 0);
169 ERROR("'%s' open failure : %m", my_args
.statefile
);
174 ret
= lxc_restart(my_args
.name
, sfd
, conf
, my_args
.flags
);
176 if (my_args
.statefile
)