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
e98fe68b
Commit
e98fe68b
authored
Oct 07, 2009
by
Daniel Lezcano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle the state command
handle the state command. Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
66aeffc7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletion
+64
-1
commands.c
src/lxc/commands.c
+3
-0
commands.h
src/lxc/commands.h
+1
-0
state.c
src/lxc/state.c
+60
-1
No files found.
src/lxc/commands.c
View file @
e98fe68b
...
@@ -97,6 +97,8 @@ extern int lxc_console_callback(int fd, struct lxc_request *request,
...
@@ -97,6 +97,8 @@ extern int lxc_console_callback(int fd, struct lxc_request *request,
struct
lxc_handler
*
handler
);
struct
lxc_handler
*
handler
);
extern
int
lxc_stop_callback
(
int
fd
,
struct
lxc_request
*
request
,
extern
int
lxc_stop_callback
(
int
fd
,
struct
lxc_request
*
request
,
struct
lxc_handler
*
handler
);
struct
lxc_handler
*
handler
);
extern
int
lxc_state_callback
(
int
fd
,
struct
lxc_request
*
request
,
struct
lxc_handler
*
handler
);
static
int
trigger_command
(
int
fd
,
struct
lxc_request
*
request
,
static
int
trigger_command
(
int
fd
,
struct
lxc_request
*
request
,
struct
lxc_handler
*
handler
)
struct
lxc_handler
*
handler
)
...
@@ -107,6 +109,7 @@ static int trigger_command(int fd, struct lxc_request *request,
...
@@ -107,6 +109,7 @@ static int trigger_command(int fd, struct lxc_request *request,
callback
cb
[
LXC_COMMAND_MAX
]
=
{
callback
cb
[
LXC_COMMAND_MAX
]
=
{
[
LXC_COMMAND_TTY
]
=
lxc_console_callback
,
[
LXC_COMMAND_TTY
]
=
lxc_console_callback
,
[
LXC_COMMAND_STOP
]
=
lxc_stop_callback
,
[
LXC_COMMAND_STOP
]
=
lxc_stop_callback
,
[
LXC_COMMAND_STATE
]
=
lxc_state_callback
,
};
};
if
(
request
->
type
<
0
||
request
->
type
>=
LXC_COMMAND_MAX
)
if
(
request
->
type
<
0
||
request
->
type
>=
LXC_COMMAND_MAX
)
...
...
src/lxc/commands.h
View file @
e98fe68b
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
enum
{
enum
{
LXC_COMMAND_TTY
,
LXC_COMMAND_TTY
,
LXC_COMMAND_STOP
,
LXC_COMMAND_STOP
,
LXC_COMMAND_STATE
,
LXC_COMMAND_MAX
,
LXC_COMMAND_MAX
,
};
};
...
...
src/lxc/state.c
View file @
e98fe68b
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include <lxc/lxc.h>
#include <lxc/lxc.h>
#include <lxc/log.h>
#include <lxc/log.h>
#include "commands.h"
lxc_log_define
(
lxc_state
,
lxc
);
lxc_log_define
(
lxc_state
,
lxc
);
...
@@ -68,7 +69,7 @@ int lxc_rmstate(const char *name)
...
@@ -68,7 +69,7 @@ int lxc_rmstate(const char *name)
return
0
;
return
0
;
}
}
lxc_state_t
lxc_getstate
(
const
char
*
name
)
lxc_state_t
__
lxc_getstate
(
const
char
*
name
)
{
{
int
fd
,
err
;
int
fd
,
err
;
char
file
[
MAXPATHLEN
];
char
file
[
MAXPATHLEN
];
...
@@ -124,6 +125,36 @@ static int freezer_state(const char *name)
...
@@ -124,6 +125,36 @@ static int freezer_state(const char *name)
return
lxc_str2state
(
status
);
return
lxc_str2state
(
status
);
}
}
lxc_state_t
lxc_getstate
(
const
char
*
name
)
{
struct
lxc_command
command
=
{
.
request
=
{
.
type
=
LXC_COMMAND_STATE
},
};
int
ret
;
ret
=
lxc_command
(
name
,
&
command
);
if
(
ret
<
0
)
{
ERROR
(
"failed to send command"
);
return
-
1
;
}
if
(
!
ret
)
{
WARN
(
"'%s' has stopped before sending its state"
,
name
);
return
-
1
;
}
if
(
command
.
answer
.
ret
<
0
)
{
ERROR
(
"failed to get state for '%s': %s"
,
name
,
strerror
(
-
command
.
answer
.
ret
));
return
-
1
;
}
DEBUG
(
"'%s' is in '%s' state"
,
name
,
lxc_state2str
(
command
.
answer
.
ret
));
return
command
.
answer
.
ret
;
}
lxc_state_t
lxc_state
(
const
char
*
name
)
lxc_state_t
lxc_state
(
const
char
*
name
)
{
{
int
state
=
freezer_state
(
name
);
int
state
=
freezer_state
(
name
);
...
@@ -131,3 +162,31 @@ lxc_state_t lxc_state(const char *name)
...
@@ -131,3 +162,31 @@ lxc_state_t lxc_state(const char *name)
state
=
lxc_getstate
(
name
);
state
=
lxc_getstate
(
name
);
return
state
;
return
state
;
}
}
/*----------------------------------------------------------------------------
* functions used by lxc-start mainloop
* to handle above command request.
*--------------------------------------------------------------------------*/
extern
int
lxc_state_callback
(
int
fd
,
struct
lxc_request
*
request
,
struct
lxc_handler
*
handler
)
{
struct
lxc_answer
answer
;
int
ret
;
answer
.
ret
=
handler
->
state
;
ret
=
send
(
fd
,
&
answer
,
sizeof
(
answer
),
0
);
if
(
ret
<
0
)
{
WARN
(
"failed to send answer to the peer"
);
goto
out
;
}
if
(
ret
!=
sizeof
(
answer
))
{
ERROR
(
"partial answer sent"
);
goto
out
;
}
out:
return
ret
;
}
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