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
8d06bd13
Commit
8d06bd13
authored
May 07, 2013
by
Dwight Engen
Committed by
Serge Hallyn
May 08, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-monitor multiple paths
Signed-off-by:
Dwight Engen
<
dwight.engen@oracle.com
>
Signed-off-by:
Serge Hallyn
<
serge.hallyn@ubuntu.com
>
parent
566c0d6d
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
155 additions
and
59 deletions
+155
-59
lxc-monitor.sgml.in
doc/lxc-monitor.sgml.in
+7
-0
arguments.c
src/lxc/arguments.c
+32
-2
arguments.h
src/lxc/arguments.h
+4
-1
lxc.h
src/lxc/lxc.h
+25
-4
lxc_attach.c
src/lxc/lxc_attach.c
+4
-4
lxc_cgroup.c
src/lxc/lxc_cgroup.c
+3
-3
lxc_checkpoint.c
src/lxc/lxc_checkpoint.c
+1
-1
lxc_console.c
src/lxc/lxc_console.c
+2
-2
lxc_execute.c
src/lxc/lxc_execute.c
+3
-3
lxc_freeze.c
src/lxc/lxc_freeze.c
+2
-2
lxc_info.c
src/lxc/lxc_info.c
+3
-3
lxc_kill.c
src/lxc/lxc_kill.c
+2
-2
lxc_monitor.c
src/lxc/lxc_monitor.c
+24
-7
lxc_restart.c
src/lxc/lxc_restart.c
+3
-3
lxc_start.c
src/lxc/lxc_start.c
+3
-3
lxc_stop.c
src/lxc/lxc_stop.c
+2
-2
lxc_unfreeze.c
src/lxc/lxc_unfreeze.c
+2
-2
lxc_wait.c
src/lxc/lxc_wait.c
+3
-2
monitor.c
src/lxc/monitor.c
+30
-13
No files found.
doc/lxc-monitor.sgml.in
View file @
8d06bd13
...
@@ -63,6 +63,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
...
@@ -63,6 +63,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
to monitor all the containers, several of them or just one.
to monitor all the containers, several of them or just one.
</para>
</para>
<para>
The <option>-P, --lxcpath</option>=PATH option may be specified multiple
times to monitor more than one container path. Note however that
containers with the same name in multiple paths will be
indistinguishable in the output.
</para>
</refsect1>
</refsect1>
&commonoptions;
&commonoptions;
...
...
src/lxc/arguments.c
View file @
8d06bd13
...
@@ -150,13 +150,32 @@ See the %s man page for further information.\n\n",
...
@@ -150,13 +150,32 @@ See the %s man page for further information.\n\n",
exit
(
code
);
exit
(
code
);
}
}
static
int
lxc_arguments_lxcpath_add
(
struct
lxc_arguments
*
args
,
const
char
*
lxcpath
)
{
if
(
args
->
lxcpath_additional
!=
-
1
&&
args
->
lxcpath_cnt
>
args
->
lxcpath_additional
)
{
fprintf
(
stderr
,
"This command only accepts %d -P,--lxcpath arguments
\n
"
,
args
->
lxcpath_additional
+
1
);
exit
(
EXIT_FAILURE
);
}
args
->
lxcpath
=
realloc
(
args
->
lxcpath
,
(
args
->
lxcpath_cnt
+
1
)
*
sizeof
(
args
->
lxcpath
[
0
]));
if
(
args
->
lxcpath
==
NULL
)
{
lxc_error
(
args
,
"no memory"
);
return
ENOMEM
;
}
args
->
lxcpath
[
args
->
lxcpath_cnt
++
]
=
lxcpath
;
return
0
;
}
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
int
argc
,
char
*
const
argv
[])
int
argc
,
char
*
const
argv
[])
{
{
char
shortopts
[
256
];
char
shortopts
[
256
];
int
ret
=
0
;
int
ret
=
0
;
args
->
lxcpath
=
default_lxc_path
();
ret
=
build_shortopts
(
args
->
options
,
shortopts
,
sizeof
(
shortopts
));
ret
=
build_shortopts
(
args
->
options
,
shortopts
,
sizeof
(
shortopts
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
lxc_error
(
args
,
"build_shortopts() failed : %s"
,
lxc_error
(
args
,
"build_shortopts() failed : %s"
,
...
@@ -176,7 +195,11 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
...
@@ -176,7 +195,11 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
case
'l'
:
args
->
log_priority
=
optarg
;
break
;
case
'l'
:
args
->
log_priority
=
optarg
;
break
;
case
'c'
:
args
->
console
=
optarg
;
break
;
case
'c'
:
args
->
console
=
optarg
;
break
;
case
'q'
:
args
->
quiet
=
1
;
break
;
case
'q'
:
args
->
quiet
=
1
;
break
;
case
'P'
:
args
->
lxcpath
=
optarg
;
break
;
case
'P'
:
ret
=
lxc_arguments_lxcpath_add
(
args
,
optarg
);
if
(
ret
<
0
)
return
ret
;
break
;
case
OPT_USAGE
:
print_usage
(
args
->
options
,
args
);
case
OPT_USAGE
:
print_usage
(
args
->
options
,
args
);
case
'?'
:
print_help
(
args
,
1
);
case
'?'
:
print_help
(
args
,
1
);
case
'h'
:
print_help
(
args
,
0
);
case
'h'
:
print_help
(
args
,
0
);
...
@@ -195,6 +218,13 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
...
@@ -195,6 +218,13 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
args
->
argv
=
&
argv
[
optind
];
args
->
argv
=
&
argv
[
optind
];
args
->
argc
=
argc
-
optind
;
args
->
argc
=
argc
-
optind
;
/* If no lxcpaths were given, use default */
if
(
!
args
->
lxcpath_cnt
)
{
ret
=
lxc_arguments_lxcpath_add
(
args
,
default_lxc_path
());
if
(
ret
<
0
)
return
ret
;
}
/* Check the command options */
/* Check the command options */
if
(
!
args
->
name
)
{
if
(
!
args
->
name
)
{
...
...
src/lxc/arguments.h
View file @
8d06bd13
...
@@ -47,7 +47,10 @@ struct lxc_arguments {
...
@@ -47,7 +47,10 @@ struct lxc_arguments {
const
char
*
console
;
const
char
*
console
;
const
char
*
console_log
;
const
char
*
console_log
;
const
char
*
pidfile
;
const
char
*
pidfile
;
const
char
*
lxcpath
;
const
char
**
lxcpath
;
int
lxcpath_cnt
;
/* set to 0 to accept only 1 lxcpath, -1 for unlimited */
int
lxcpath_additional
;
/* for lxc-checkpoint/restart */
/* for lxc-checkpoint/restart */
const
char
*
statefile
;
const
char
*
statefile
;
...
...
src/lxc/lxc.h
View file @
8d06bd13
...
@@ -28,6 +28,7 @@ extern "C" {
...
@@ -28,6 +28,7 @@ extern "C" {
#endif
#endif
#include <stddef.h>
#include <stddef.h>
#include <sys/types.h>
#include <lxc/state.h>
#include <lxc/state.h>
struct
lxc_msg
;
struct
lxc_msg
;
...
@@ -77,17 +78,37 @@ extern int lxc_execute(const char *name, char *const argv[], int quiet,
...
@@ -77,17 +78,37 @@ extern int lxc_execute(const char *name, char *const argv[], int quiet,
extern
int
lxc_monitor_open
(
const
char
*
lxcpath
);
extern
int
lxc_monitor_open
(
const
char
*
lxcpath
);
/*
/*
* Read the state of the container if this one has changed
* Blocking read for the next container state change
* The function will block until there is an event available
* @fd : the file descriptor provided by lxc_monitor_open
* @fd : the file descriptor provided by lxc_monitor_open
* @
state
: the variable which will be filled with the state
* @
msg
: the variable which will be filled with the state
* Returns 0 if the monitored container has exited, > 0 if
* Returns 0 if the monitored container has exited, > 0 if
* data was read
en
, < 0 otherwise
* data was read, < 0 otherwise
*/
*/
extern
int
lxc_monitor_read
(
int
fd
,
struct
lxc_msg
*
msg
);
extern
int
lxc_monitor_read
(
int
fd
,
struct
lxc_msg
*
msg
);
/*
* Blocking read for the next container state change with timeout
* @fd : the file descriptor provided by lxc_monitor_open
* @msg : the variable which will be filled with the state
* @timeout : the timeout in seconds to wait for a state change
* Returns 0 if the monitored container has exited, > 0 if
* data was read, < 0 otherwise
*/
extern
int
lxc_monitor_read_timeout
(
int
fd
,
struct
lxc_msg
*
msg
,
int
timeout
);
extern
int
lxc_monitor_read_timeout
(
int
fd
,
struct
lxc_msg
*
msg
,
int
timeout
);
/*
/*
* Blocking read from multiple monitors for the next container state
* change with timeout
* @rfds : an fd_set of file descriptors provided by lxc_monitor_open
* @nfds : the maximum fd number in rfds + 1
* @msg : the variable which will be filled with the state
* @timeout : the timeout in seconds to wait for a state change
* Returns 0 if the monitored container has exited, > 0 if
* data was read, < 0 otherwise
*/
extern
int
lxc_monitor_read_fdset
(
fd_set
*
rfds
,
int
nfds
,
struct
lxc_msg
*
msg
,
int
timeout
);
/*
* Close the fd associated with the monitoring
* Close the fd associated with the monitoring
* @fd : the file descriptor provided by lxc_monitor_open
* @fd : the file descriptor provided by lxc_monitor_open
* Returns 0 on success, < 0 otherwise
* Returns 0 on success, < 0 otherwise
...
...
src/lxc/lxc_attach.c
View file @
8d06bd13
...
@@ -292,11 +292,11 @@ int main(int argc, char *argv[])
...
@@ -292,11 +292,11 @@ int main(int argc, char *argv[])
return
ret
;
return
ret
;
ret
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
ret
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
);
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
init_pid
=
get_init_pid
(
my_args
.
name
,
my_args
.
lxcpath
);
init_pid
=
get_init_pid
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
if
(
init_pid
<
0
)
{
if
(
init_pid
<
0
)
{
ERROR
(
"failed to get the init pid"
);
ERROR
(
"failed to get the init pid"
);
return
-
1
;
return
-
1
;
...
@@ -314,7 +314,7 @@ int main(int argc, char *argv[])
...
@@ -314,7 +314,7 @@ int main(int argc, char *argv[])
* by asking lxc-start
* by asking lxc-start
*/
*/
if
(
namespace_flags
==
-
1
)
{
if
(
namespace_flags
==
-
1
)
{
namespace_flags
=
lxc_get_clone_flags
(
my_args
.
name
,
my_args
.
lxcpath
);
namespace_flags
=
lxc_get_clone_flags
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
/* call failed */
/* call failed */
if
(
namespace_flags
==
-
1
)
{
if
(
namespace_flags
==
-
1
)
{
ERROR
(
"failed to automatically determine the "
ERROR
(
"failed to automatically determine the "
...
@@ -387,7 +387,7 @@ int main(int argc, char *argv[])
...
@@ -387,7 +387,7 @@ int main(int argc, char *argv[])
}
}
if
(
!
elevated_privileges
)
{
if
(
!
elevated_privileges
)
{
ret
=
lxc_cgroup_attach
(
grandchild
,
my_args
.
name
,
my_args
.
lxcpath
);
ret
=
lxc_cgroup_attach
(
grandchild
,
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"failed to attach process to cgroup"
);
ERROR
(
"failed to attach process to cgroup"
);
return
-
1
;
return
-
1
;
...
...
src/lxc/lxc_cgroup.c
View file @
8d06bd13
...
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
...
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
state_object
=
my_args
.
argv
[
0
];
state_object
=
my_args
.
argv
[
0
];
...
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
...
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
value
=
my_args
.
argv
[
1
];
value
=
my_args
.
argv
[
1
];
if
(
value
)
{
if
(
value
)
{
if
(
lxc_cgroup_set
(
my_args
.
name
,
state_object
,
value
,
my_args
.
lxcpath
))
{
if
(
lxc_cgroup_set
(
my_args
.
name
,
state_object
,
value
,
my_args
.
lxcpath
[
0
]
))
{
ERROR
(
"failed to assign '%s' value to '%s' for '%s'"
,
ERROR
(
"failed to assign '%s' value to '%s' for '%s'"
,
value
,
state_object
,
my_args
.
name
);
value
,
state_object
,
my_args
.
name
);
return
-
1
;
return
-
1
;
...
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
...
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
int
ret
;
int
ret
;
char
buffer
[
len
];
char
buffer
[
len
];
ret
=
lxc_cgroup_get
(
my_args
.
name
,
state_object
,
buffer
,
len
,
my_args
.
lxcpath
);
ret
=
lxc_cgroup_get
(
my_args
.
name
,
state_object
,
buffer
,
len
,
my_args
.
lxcpath
[
0
]
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"failed to retrieve value of '%s' for '%s'"
,
ERROR
(
"failed to retrieve value of '%s' for '%s'"
,
state_object
,
my_args
.
name
);
state_object
,
my_args
.
name
);
...
...
src/lxc/lxc_checkpoint.c
View file @
8d06bd13
...
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
...
@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
return
ret
;
return
ret
;
ret
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
ret
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
);
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
...
...
src/lxc/lxc_console.c
View file @
8d06bd13
...
@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
...
@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
err
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
err
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
);
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
);
if
(
err
)
if
(
err
)
return
-
1
;
return
-
1
;
...
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
...
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
}
}
err
=
lxc_console
(
my_args
.
name
,
my_args
.
ttynum
,
&
master
,
my_args
.
lxcpath
);
err
=
lxc_console
(
my_args
.
name
,
my_args
.
ttynum
,
&
master
,
my_args
.
lxcpath
[
0
]
);
if
(
err
)
if
(
err
)
goto
out
;
goto
out
;
...
...
src/lxc/lxc_execute.c
View file @
8d06bd13
...
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
...
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
/* rcfile is specified in the cli option */
/* rcfile is specified in the cli option */
...
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
...
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
else
{
else
{
int
rc
;
int
rc
;
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
,
my_args
.
name
);
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
[
0
]
,
my_args
.
name
);
if
(
rc
==
-
1
)
{
if
(
rc
==
-
1
)
{
SYSERROR
(
"failed to allocate memory"
);
SYSERROR
(
"failed to allocate memory"
);
return
-
1
;
return
-
1
;
...
@@ -137,5 +137,5 @@ int main(int argc, char *argv[])
...
@@ -137,5 +137,5 @@ int main(int argc, char *argv[])
if
(
lxc_config_define_load
(
&
defines
,
conf
))
if
(
lxc_config_define_load
(
&
defines
,
conf
))
return
-
1
;
return
-
1
;
return
lxc_execute
(
my_args
.
name
,
my_args
.
argv
,
my_args
.
quiet
,
conf
,
my_args
.
lxcpath
);
return
lxc_execute
(
my_args
.
name
,
my_args
.
argv
,
my_args
.
quiet
,
conf
,
my_args
.
lxcpath
[
0
]
);
}
}
src/lxc/lxc_freeze.c
View file @
8d06bd13
...
@@ -55,9 +55,9 @@ int main(int argc, char *argv[])
...
@@ -55,9 +55,9 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
return
lxc_freeze
(
my_args
.
name
,
my_args
.
lxcpath
);
return
lxc_freeze
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
}
}
src/lxc/lxc_info.c
View file @
8d06bd13
...
@@ -80,14 +80,14 @@ int main(int argc, char *argv[])
...
@@ -80,14 +80,14 @@ int main(int argc, char *argv[])
return
1
;
return
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
1
;
return
1
;
if
(
!
state
&&
!
pid
)
if
(
!
state
&&
!
pid
)
state
=
pid
=
true
;
state
=
pid
=
true
;
if
(
state
||
test_state
)
{
if
(
state
||
test_state
)
{
ret
=
lxc_getstate
(
my_args
.
name
,
my_args
.
lxcpath
);
ret
=
lxc_getstate
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
1
;
return
1
;
if
(
test_state
)
if
(
test_state
)
...
@@ -97,7 +97,7 @@ int main(int argc, char *argv[])
...
@@ -97,7 +97,7 @@ int main(int argc, char *argv[])
}
}
if
(
pid
)
if
(
pid
)
printf
(
"pid:%10d
\n
"
,
get_init_pid
(
my_args
.
name
,
my_args
.
lxcpath
));
printf
(
"pid:%10d
\n
"
,
get_init_pid
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
));
return
0
;
return
0
;
}
}
src/lxc/lxc_kill.c
View file @
8d06bd13
...
@@ -62,7 +62,7 @@ int main(int argc, char *argv[], char *envp[])
...
@@ -62,7 +62,7 @@ int main(int argc, char *argv[], char *envp[])
return
ret
;
return
ret
;
ret
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
ret
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
);
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
...
@@ -76,7 +76,7 @@ int main(int argc, char *argv[], char *envp[])
...
@@ -76,7 +76,7 @@ int main(int argc, char *argv[], char *envp[])
}
else
}
else
sig
=
SIGKILL
;
sig
=
SIGKILL
;
pid
=
get_init_pid
(
my_args
.
name
,
my_args
.
lxcpath
);
pid
=
get_init_pid
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
ERROR
(
"failed to get the init pid"
);
ERROR
(
"failed to get the init pid"
);
return
-
1
;
return
-
1
;
...
...
src/lxc/lxc_monitor.c
View file @
8d06bd13
...
@@ -52,6 +52,7 @@ Options :\n\
...
@@ -52,6 +52,7 @@ Options :\n\
.
options
=
my_longopts
,
.
options
=
my_longopts
,
.
parser
=
NULL
,
.
parser
=
NULL
,
.
checker
=
NULL
,
.
checker
=
NULL
,
.
lxcpath_additional
=
-
1
,
};
};
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
...
@@ -59,14 +60,14 @@ int main(int argc, char *argv[])
...
@@ -59,14 +60,14 @@ int main(int argc, char *argv[])
char
*
regexp
;
char
*
regexp
;
struct
lxc_msg
msg
;
struct
lxc_msg
msg
;
regex_t
preg
;
regex_t
preg
;
int
fd
;
fd_set
rfds
,
rfds_save
;
int
len
,
rc
;
int
len
,
rc
,
i
,
nfds
=
-
1
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
len
=
strlen
(
my_args
.
name
)
+
3
;
len
=
strlen
(
my_args
.
name
)
+
3
;
...
@@ -87,16 +88,33 @@ int main(int argc, char *argv[])
...
@@ -87,16 +88,33 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
}
}
lxc_monitord_spawn
(
my_args
.
lxcpath
);
if
(
my_args
.
lxcpath_cnt
>
FD_SETSIZE
)
{
ERROR
(
"too many paths requested, only the first %d will be monitored"
,
FD_SETSIZE
);
my_args
.
lxcpath_cnt
=
FD_SETSIZE
;
}
FD_ZERO
(
&
rfds
);
for
(
i
=
0
;
i
<
my_args
.
lxcpath_cnt
;
i
++
)
{
int
fd
;
lxc_monitord_spawn
(
my_args
.
lxcpath
[
i
]);
fd
=
lxc_monitor_open
(
my_args
.
lxcpath
);
fd
=
lxc_monitor_open
(
my_args
.
lxcpath
[
i
]
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
-
1
;
return
-
1
;
FD_SET
(
fd
,
&
rfds
);
if
(
fd
>
nfds
)
nfds
=
fd
;
}
memcpy
(
&
rfds_save
,
&
rfds
,
sizeof
(
rfds_save
));
nfds
++
;
setlinebuf
(
stdout
);
setlinebuf
(
stdout
);
for
(;;)
{
for
(;;)
{
if
(
lxc_monitor_read
(
fd
,
&
msg
)
<
0
)
memcpy
(
&
rfds
,
&
rfds_save
,
sizeof
(
rfds
));
if
(
lxc_monitor_read_fdset
(
&
rfds
,
nfds
,
&
msg
,
-
1
)
<
0
)
return
-
1
;
return
-
1
;
msg
.
name
[
sizeof
(
msg
.
name
)
-
1
]
=
'\0'
;
msg
.
name
[
sizeof
(
msg
.
name
)
-
1
]
=
'\0'
;
...
@@ -118,4 +136,3 @@ int main(int argc, char *argv[])
...
@@ -118,4 +136,3 @@ int main(int argc, char *argv[])
return
0
;
return
0
;
}
}
src/lxc/lxc_restart.c
View file @
8d06bd13
...
@@ -124,7 +124,7 @@ int main(int argc, char *argv[])
...
@@ -124,7 +124,7 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
/* rcfile is specified in the cli option */
/* rcfile is specified in the cli option */
...
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
...
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
else
{
else
{
int
rc
;
int
rc
;
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
,
my_args
.
name
);
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
[
0
]
,
my_args
.
name
);
if
(
rc
==
-
1
)
{
if
(
rc
==
-
1
)
{
SYSERROR
(
"failed to allocate memory"
);
SYSERROR
(
"failed to allocate memory"
);
return
-
1
;
return
-
1
;
...
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
...
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
}
}
}
}
ret
=
lxc_restart
(
my_args
.
name
,
sfd
,
conf
,
my_args
.
flags
,
my_args
.
lxcpath
);
ret
=
lxc_restart
(
my_args
.
name
,
sfd
,
conf
,
my_args
.
flags
,
my_args
.
lxcpath
[
0
]
);
if
(
my_args
.
statefile
)
if
(
my_args
.
statefile
)
close
(
sfd
);
close
(
sfd
);
...
...
src/lxc/lxc_start.c
View file @
8d06bd13
...
@@ -165,7 +165,7 @@ int main(int argc, char *argv[])
...
@@ -165,7 +165,7 @@ int main(int argc, char *argv[])
args
=
my_args
.
argv
;
args
=
my_args
.
argv
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
err
;
return
err
;
/* rcfile is specified in the cli option */
/* rcfile is specified in the cli option */
...
@@ -174,7 +174,7 @@ int main(int argc, char *argv[])
...
@@ -174,7 +174,7 @@ int main(int argc, char *argv[])
else
{
else
{
int
rc
;
int
rc
;
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
,
my_args
.
name
);
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
[
0
]
,
my_args
.
name
);
if
(
rc
==
-
1
)
{
if
(
rc
==
-
1
)
{
SYSERROR
(
"failed to allocate memory"
);
SYSERROR
(
"failed to allocate memory"
);
return
err
;
return
err
;
...
@@ -252,7 +252,7 @@ int main(int argc, char *argv[])
...
@@ -252,7 +252,7 @@ int main(int argc, char *argv[])
if
(
my_args
.
close_all_fds
)
if
(
my_args
.
close_all_fds
)
conf
->
close_all_fds
=
1
;
conf
->
close_all_fds
=
1
;
err
=
lxc_start
(
my_args
.
name
,
args
,
conf
,
my_args
.
lxcpath
);
err
=
lxc_start
(
my_args
.
name
,
args
,
conf
,
my_args
.
lxcpath
[
0
]
);
/*
/*
* exec ourself, that requires to have all opened fd
* exec ourself, that requires to have all opened fd
...
...
src/lxc/lxc_stop.c
View file @
8d06bd13
...
@@ -55,8 +55,8 @@ int main(int argc, char *argv[])
...
@@ -55,8 +55,8 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
return
lxc_stop
(
my_args
.
name
,
my_args
.
lxcpath
);
return
lxc_stop
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
}
}
src/lxc/lxc_unfreeze.c
View file @
8d06bd13
...
@@ -54,9 +54,9 @@ int main(int argc, char *argv[])
...
@@ -54,9 +54,9 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
return
lxc_unfreeze
(
my_args
.
name
,
my_args
.
lxcpath
);
return
lxc_unfreeze
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]
);
}
}
src/lxc/lxc_wait.c
View file @
8d06bd13
...
@@ -84,8 +84,9 @@ int main(int argc, char *argv[])
...
@@ -84,8 +84,9 @@ int main(int argc, char *argv[])
return
-
1
;
return
-
1
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]
))
return
-
1
;
return
-
1
;
return
lxc_wait
(
strdup
(
my_args
.
name
),
my_args
.
states
,
my_args
.
timeout
,
my_args
.
lxcpath
);
return
lxc_wait
(
strdup
(
my_args
.
name
),
my_args
.
states
,
my_args
.
timeout
,
my_args
.
lxcpath
[
0
]);
}
}
src/lxc/monitor.c
View file @
8d06bd13
...
@@ -147,33 +147,50 @@ err1:
...
@@ -147,33 +147,50 @@ err1:
return
ret
;
return
ret
;
}
}
int
lxc_monitor_read_timeout
(
int
fd
,
struct
lxc_msg
*
msglxc
,
int
timeout
)
int
lxc_monitor_read_fdset
(
fd_set
*
rfds
,
int
nfds
,
struct
lxc_msg
*
msg
,
int
timeout
)
{
{
fd_set
rfds
;
struct
timeval
tval
,
*
tv
=
NULL
;
struct
timeval
tv
;
int
ret
,
i
;
int
ret
;
if
(
timeout
!=
-
1
)
{
if
(
timeout
!=
-
1
)
{
FD_ZERO
(
&
rfds
);
tv
=
&
tval
;
FD_SET
(
fd
,
&
rfds
);
tv
->
tv_sec
=
timeout
;
tv
->
tv_usec
=
0
;
tv
.
tv_sec
=
timeout
;
}
tv
.
tv_usec
=
0
;
ret
=
select
(
fd
+
1
,
&
rfds
,
NULL
,
NULL
,
&
tv
);
ret
=
select
(
nfds
,
rfds
,
NULL
,
NULL
,
tv
);
if
(
ret
==
-
1
)
if
(
ret
==
-
1
)
return
-
1
;
return
-
1
;
else
if
(
!
ret
)
else
if
(
ret
==
0
)
return
-
2
;
// timed out
return
-
2
;
// timed out
}
ret
=
recv
(
fd
,
msglxc
,
sizeof
(
*
msglxc
),
0
);
/* only read from the first ready fd, the others will remain ready
* for when this routine is called again
*/
for
(
i
=
0
;
i
<
nfds
;
i
++
)
{
if
(
FD_ISSET
(
i
,
rfds
))
{
ret
=
recv
(
i
,
msg
,
sizeof
(
*
msg
),
0
);
if
(
ret
<=
0
)
{
if
(
ret
<=
0
)
{
SYSERROR
(
"client failed to recv (monitord died?) %s"
,
SYSERROR
(
"client failed to recv (monitord died?) %s"
,
strerror
(
errno
));
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
return
ret
;
return
ret
;
}
}
SYSERROR
(
"no ready fd found?"
);
return
-
1
;
}
int
lxc_monitor_read_timeout
(
int
fd
,
struct
lxc_msg
*
msg
,
int
timeout
)
{
fd_set
rfds
;
FD_ZERO
(
&
rfds
);
FD_SET
(
fd
,
&
rfds
);
return
lxc_monitor_read_fdset
(
&
rfds
,
fd
+
1
,
msg
,
timeout
);
}
}
int
lxc_monitor_read
(
int
fd
,
struct
lxc_msg
*
msg
)
int
lxc_monitor_read
(
int
fd
,
struct
lxc_msg
*
msg
)
...
...
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