]>
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>
37 #include "arguments.h"
39 lxc_log_define(lxc_restart_ui
, lxc_restart
);
41 static struct lxc_list defines
;
43 static int my_checker(const struct lxc_arguments
* args
)
45 if ((!args
->statefile
) && (args
->statefd
== -1)) {
46 lxc_error(args
, "no statefile specified");
50 if ((args
->statefile
) && (args
->statefd
!= -1)) {
51 lxc_error(args
, "--statefile AND --statefd abnormally set");
58 static int my_parser(struct lxc_arguments
* args
, int c
, char* arg
)
61 case 'S': args
->statefile
= arg
; break;
62 case 'f': args
->rcfile
= arg
; break;
63 case 'p': args
->flags
= LXC_FLAG_PAUSE
; break;
64 case 's': return lxc_config_define_add(&defines
, arg
);
67 fd
= lxc_arguments_str_to_int(args
, arg
);
79 static const struct option my_longopts
[] = {
80 {"statefile", required_argument
, 0, 'S'},
81 {"statefd", required_argument
, 0, 'd'},
82 {"rcfile", required_argument
, 0, 'f'},
83 {"pause", no_argument
, 0, 'p'},
84 {"define", required_argument
, 0, 's'},
88 static struct lxc_arguments my_args
= {
89 .progname
= "lxc-restart",
91 --name=NAME --statefile FILE\n\
93 lxc-restart restarts from FILE the NAME container\n\
96 -n, --name=NAME NAME for name of the container\n\
97 -p, --pause do not unfreeze the container after the restart\n\
98 -S, --statefile=FILE read the container state from this file, or\n\
99 -d, --statefd=FD read the container state from this file descriptor\n\
100 -f, --rcfile=FILE Load configuration file FILE\n\
101 -s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
102 .options
= my_longopts
,
104 .checker
= my_checker
,
109 int main(int argc
, char *argv
[])
114 struct lxc_conf
*conf
;
116 lxc_list_init(&defines
);
118 if (lxc_arguments_parse(&my_args
, argc
, argv
))
121 if (lxc_log_init(my_args
.log_file
, my_args
.log_priority
,
122 my_args
.progname
, my_args
.quiet
))
125 /* rcfile is specified in the cli option */
127 rcfile
= (char *)my_args
.rcfile
;
129 if (!asprintf(&rcfile
, LXCPATH
"/%s/config", my_args
.name
)) {
130 SYSERROR("failed to allocate memory");
134 /* container configuration does not exist */
135 if (access(rcfile
, F_OK
)) {
141 conf
= lxc_conf_init();
143 ERROR("failed to initialize configuration");
147 if (rcfile
&& lxc_config_read(rcfile
, conf
)) {
148 ERROR("failed to read configuration file");
152 if (lxc_config_define_load(&defines
, conf
))
155 if (my_args
.statefd
!= -1)
156 sfd
= my_args
.statefd
;
158 #define OPEN_READ_MODE O_RDONLY | O_CLOEXEC | O_LARGEFILE
159 if (my_args
.statefile
) {
160 sfd
= open(my_args
.statefile
, OPEN_READ_MODE
, 0);
162 ERROR("'%s' open failure : %m", my_args
.statefile
);
167 ret
= lxc_restart(my_args
.name
, sfd
, conf
, my_args
.flags
);
169 if (my_args
.statefile
)