Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
ad3ac5e0
Commit
ad3ac5e0
authored
Nov 19, 2009
by
Michel Normand
Committed by
Daniel Lezcano
Nov 19, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change C/R api
Change Checkpoint / Restart API Signed-off-by:
Michel Normand
<
normand@fr.ibm.com
>
Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
55237dfa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
61 deletions
+48
-61
arguments.h
src/lxc/arguments.h
+1
-2
checkpoint.c
src/lxc/checkpoint.c
+1
-1
lxc.h
src/lxc/lxc.h
+16
-13
lxc_checkpoint.c
src/lxc/lxc_checkpoint.c
+12
-34
lxc_restart.c
src/lxc/lxc_restart.c
+16
-10
restart.c
src/lxc/restart.c
+2
-1
No files found.
src/lxc/arguments.h
View file @
ad3ac5e0
...
@@ -47,8 +47,7 @@ struct lxc_arguments {
...
@@ -47,8 +47,7 @@ struct lxc_arguments {
const
char
*
statefile
;
const
char
*
statefile
;
/* for lxc-checkpoint */
/* for lxc-checkpoint */
int
kill
;
int
flags
;
int
pause
;
/* for lxc-console */
/* for lxc-console */
int
ttynum
;
int
ttynum
;
...
...
src/lxc/checkpoint.c
View file @
ad3ac5e0
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
lxc_log_define
(
lxc_checkpoint
,
lxc
);
lxc_log_define
(
lxc_checkpoint
,
lxc
);
int
lxc_checkpoint
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
)
int
lxc_checkpoint
(
const
char
*
name
,
const
char
*
statefile
,
int
flags
)
{
{
return
0
;
return
0
;
}
}
src/lxc/lxc.h
View file @
ad3ac5e0
...
@@ -27,17 +27,17 @@
...
@@ -27,17 +27,17 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <stddef.h>
#include <lxc/state.h>
struct
lxc_msg
;
/**
/**
Following code is for liblxc.
Following code is for liblxc.
lxc/lxc.h will contain exports of liblxc
lxc/lxc.h will contain exports of liblxc
**/
**/
#include <stddef.h>
#include <lxc/state.h>
struct
lxc_msg
;
/*
/*
* Start the specified command inside a container
* Start the specified command inside a container
* @name : the name of the container
* @name : the name of the container
...
@@ -139,22 +139,25 @@ extern int lxc_cgroup_get(const char *name, const char *subsystem,
...
@@ -139,22 +139,25 @@ extern int lxc_cgroup_get(const char *name, const char *subsystem,
extern
const
char
*
lxc_strerror
(
int
error
);
extern
const
char
*
lxc_strerror
(
int
error
);
/*
/*
* Checkpoint a container
previously frozen
* Checkpoint a container
* @name : the name of the container being checkpointed
* @name : the name of the container being checkpointed
* @
fd : file descriptor
on which the container is checkpointed
* @
statefile: string object
on which the container is checkpointed
* @flags : checkpoint flags
* @flags : checkpoint flags
(an ORed value)
* Returns 0 on success, < 0 otherwise
* Returns 0 on success, < 0 otherwise
*/
*/
extern
int
lxc_checkpoint
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
);
extern
int
lxc_checkpoint
(
const
char
*
name
,
const
char
*
statefile
,
int
flags
);
#define LXC_FLAG_PAUSE 1
#define LXC_FLAG_HALT 2
/*
/*
* Restart a container
previously frozen
* Restart a container
* @name : the name of the container being restarted
* @name : the name of the container being restarted
* @fd : file descriptor from which the container is restarted
* @statefile: string object from which the container is restarted
* @flags : restart flags
* @rcfile: container configuration file.
* @flags : restart flags (an ORed value)
* Returns 0 on success, < 0 otherwise
* Returns 0 on success, < 0 otherwise
*/
*/
extern
int
lxc_restart
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
);
extern
int
lxc_restart
(
const
char
*
,
const
char
*
,
const
char
*
,
int
);
/*
/*
* Returns the version number of the library
* Returns the version number of the library
...
...
src/lxc/lxc_checkpoint.c
View file @
ad3ac5e0
...
@@ -23,8 +23,9 @@
...
@@ -23,8 +23,9 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <libgen.h>
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <lxc/lxc.h>
#include <lxc/lxc.h>
...
@@ -49,8 +50,8 @@ static int my_checker(const struct lxc_arguments* args)
...
@@ -49,8 +50,8 @@ static int my_checker(const struct lxc_arguments* args)
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
)
{
switch
(
c
)
{
case
'k'
:
args
->
kill
=
1
;
break
;
case
'k'
:
args
->
flags
=
LXC_FLAG_HALT
;
break
;
case
'p'
:
args
->
pause
=
1
;
break
;
case
'p'
:
args
->
flags
=
LXC_FLAG_PAUSE
;
break
;
case
'd'
:
args
->
statefile
=
arg
;
break
;
case
'd'
:
args
->
statefile
=
arg
;
break
;
}
}
return
0
;
return
0
;
...
@@ -83,40 +84,19 @@ Options :\n\
...
@@ -83,40 +84,19 @@ Options :\n\
.
rcfile
=
NULL
,
.
rcfile
=
NULL
,
};
};
static
int
save_config_file
(
const
char
*
name
,
const
char
*
dir
)
static
int
create_statefile
(
const
char
*
dir
)
{
{
char
*
src
,
*
dst
;
if
(
mkdir
(
dir
,
0700
)
==
-
1
&&
errno
!=
EEXIST
)
{
int
ret
;
ERROR
(
"'%s' creation error : %m"
,
dir
);
if
(
!
asprintf
(
&
src
,
LXCPATH
"/%s/config"
,
name
))
{
ERROR
(
"failed to allocate memory"
);
return
-
1
;
}
if
(
access
(
src
,
F_OK
))
{
free
(
src
);
return
0
;
}
if
(
!
asprintf
(
&
dst
,
"%s/config"
,
dir
))
{
ERROR
(
"failed to allocate memory"
);
free
(
src
);
return
-
1
;
return
-
1
;
}
}
ret
=
lxc_copy_file
(
src
,
dst
);
return
0
;
if
(
ret
)
ERROR
(
"failed to copy '%s' to '%s'"
,
src
,
dst
);
free
(
src
);
free
(
dst
);
return
ret
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
ret
=
-
1
;
int
ret
;
ret
=
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
);
ret
=
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
);
if
(
ret
)
if
(
ret
)
...
@@ -127,13 +107,11 @@ int main(int argc, char *argv[])
...
@@ -127,13 +107,11 @@ int main(int argc, char *argv[])
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
ret
=
save_config_file
(
my_args
.
name
,
my_args
.
statefile
);
ret
=
create_statefile
(
my_args
.
statefile
);
if
(
ret
)
{
if
(
ret
)
ERROR
(
"failed to save the configuration"
);
return
ret
;
return
ret
;
}
ret
=
lxc_checkpoint
(
my_args
.
name
,
-
1
,
0
);
ret
=
lxc_checkpoint
(
my_args
.
name
,
my_args
.
statefile
,
my_args
.
flags
);
if
(
ret
)
{
if
(
ret
)
{
ERROR
(
"failed to checkpoint '%s'"
,
my_args
.
name
);
ERROR
(
"failed to checkpoint '%s'"
,
my_args
.
name
);
return
ret
;
return
ret
;
...
...
src/lxc/lxc_restart.c
View file @
ad3ac5e0
...
@@ -20,8 +20,10 @@
...
@@ -20,8 +20,10 @@
* License along with this library; if not, write to the Free Software
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdio.h>
#include <libgen.h>
#undef _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/types.h>
...
@@ -30,6 +32,8 @@
...
@@ -30,6 +32,8 @@
#include "arguments.h"
#include "arguments.h"
lxc_log_define
(
lxc_restart
,
lxc
);
static
int
my_checker
(
const
struct
lxc_arguments
*
args
)
static
int
my_checker
(
const
struct
lxc_arguments
*
args
)
{
{
if
(
!
args
->
statefile
)
{
if
(
!
args
->
statefile
)
{
...
@@ -43,9 +47,9 @@ static int my_checker(const struct lxc_arguments* args)
...
@@ -43,9 +47,9 @@ static int my_checker(const struct lxc_arguments* args)
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
)
{
switch
(
c
)
{
case
'd'
:
case
'd'
:
args
->
statefile
=
arg
;
break
;
args
->
statefile
=
arg
;
case
'f'
:
args
->
rcfile
=
arg
;
break
;
break
;
case
'p'
:
args
->
flags
=
LXC_FLAG_PAUSE
;
break
;
}
}
return
0
;
return
0
;
...
@@ -53,6 +57,8 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
...
@@ -53,6 +57,8 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
static
const
struct
option
my_longopts
[]
=
{
static
const
struct
option
my_longopts
[]
=
{
{
"directory"
,
required_argument
,
0
,
'd'
},
{
"directory"
,
required_argument
,
0
,
'd'
},
{
"rcfile"
,
required_argument
,
0
,
'f'
},
{
"pause"
,
no_argument
,
0
,
'p'
},
LXC_COMMON_OPTIONS
LXC_COMMON_OPTIONS
};
};
...
@@ -64,8 +70,10 @@ static struct lxc_arguments my_args = {
...
@@ -64,8 +70,10 @@ static struct lxc_arguments my_args = {
lxc-restart restarts from STATEFILE the NAME container
\n
\
lxc-restart restarts from STATEFILE the NAME container
\n
\
\n
\
\n
\
Options :
\n
\
Options :
\n
\
-n, --name=NAME NAME for name of the container
\n
\
-n, --name=NAME NAME for name of the container
\n
\
-d, --directory=STATEFILE for name of statefile
\n
"
,
-p, --pause do not release the container after the restart
\n
\
-d, --directory=STATEFILE for name of statefile
\n
\
-f, --rcfile=FILE Load configuration file FILE
\n
"
,
.
options
=
my_longopts
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
parser
=
my_parser
,
.
checker
=
my_checker
,
.
checker
=
my_checker
,
...
@@ -80,8 +88,6 @@ int main(int argc, char *argv[])
...
@@ -80,8 +88,6 @@ int main(int argc, char *argv[])
my_args
.
progname
,
my_args
.
quiet
))
my_args
.
progname
,
my_args
.
quiet
))
return
-
1
;
return
-
1
;
if
(
lxc_restart
(
my_args
.
name
,
-
1
,
0
))
return
lxc_restart
(
my_args
.
name
,
my_args
.
statefile
,
my_args
.
rcfile
,
return
-
1
;
my_args
.
flags
);
return
0
;
}
}
src/lxc/restart.c
View file @
ad3ac5e0
...
@@ -25,7 +25,8 @@
...
@@ -25,7 +25,8 @@
lxc_log_define
(
lxc_restart
,
lxc
);
lxc_log_define
(
lxc_restart
,
lxc
);
int
lxc_restart
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
)
int
lxc_restart
(
const
char
*
name
,
const
char
*
statefile
,
const
char
*
rcfile
,
int
flags
)
{
{
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment