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
fe8ded6d
Commit
fe8ded6d
authored
Aug 26, 2016
by
Serge Hallyn
Committed by
GitHub
Aug 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1139 from brauner/2016-08-18/use_exit_in_all_tools
tools: use exit(EXIT_*) everywhere
parents
ff475ab9
f0c6ee28
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
140 additions
and
139 deletions
+140
-139
lxc_autostart.c
src/lxc/tools/lxc_autostart.c
+4
-4
lxc_cgroup.c
src/lxc/tools/lxc_cgroup.c
+10
-10
lxc_checkpoint.c
src/lxc/tools/lxc_checkpoint.c
+11
-8
lxc_clone.c
src/lxc/tools/lxc_clone.c
+1
-1
lxc_config.c
src/lxc/tools/lxc_config.c
+4
-4
lxc_console.c
src/lxc/tools/lxc_console.c
+1
-1
lxc_device.c
src/lxc/tools/lxc_device.c
+6
-6
lxc_execute.c
src/lxc/tools/lxc_execute.c
+9
-9
lxc_freeze.c
src/lxc/tools/lxc_freeze.c
+8
-8
lxc_info.c
src/lxc/tools/lxc_info.c
+3
-3
lxc_monitor.c
src/lxc/tools/lxc_monitor.c
+7
-11
lxc_start.c
src/lxc/tools/lxc_start.c
+12
-12
lxc_stop.c
src/lxc/tools/lxc_stop.c
+22
-21
lxc_top.c
src/lxc/tools/lxc_top.c
+1
-1
lxc_unfreeze.c
src/lxc/tools/lxc_unfreeze.c
+8
-8
lxc_unshare.c
src/lxc/tools/lxc_unshare.c
+15
-14
lxc_usernsexec.c
src/lxc/tools/lxc_usernsexec.c
+10
-10
lxc_wait.c
src/lxc/tools/lxc_wait.c
+8
-8
No files found.
src/lxc/tools/lxc_autostart.c
View file @
fe8ded6d
...
@@ -334,17 +334,17 @@ int main(int argc, char *argv[])
...
@@ -334,17 +334,17 @@ int main(int argc, char *argv[])
struct
lxc_list
*
cmd_group
;
struct
lxc_list
*
cmd_group
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
1
;
exit
(
EXIT_FAILURE
)
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
1
;
exit
(
EXIT_FAILURE
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
count
=
list_defined_containers
(
my_args
.
lxcpath
[
0
],
NULL
,
&
containers
);
count
=
list_defined_containers
(
my_args
.
lxcpath
[
0
],
NULL
,
&
containers
);
if
(
count
<
0
)
if
(
count
<
0
)
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
!
my_args
.
all
)
{
if
(
!
my_args
.
all
)
{
/* Allocate an array for our container group lists */
/* Allocate an array for our container group lists */
...
@@ -522,5 +522,5 @@ int main(int argc, char *argv[])
...
@@ -522,5 +522,5 @@ int main(int argc, char *argv[])
toss_list
(
cmd_groups_list
);
toss_list
(
cmd_groups_list
);
free
(
containers
);
free
(
containers
);
return
0
;
exit
(
EXIT_SUCCESS
)
;
}
}
src/lxc/tools/lxc_cgroup.c
View file @
fe8ded6d
...
@@ -69,47 +69,47 @@ int main(int argc, char *argv[])
...
@@ -69,47 +69,47 @@ int main(int argc, char *argv[])
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
1
;
exit
(
EXIT_FAILURE
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
state_object
=
my_args
.
argv
[
0
];
state_object
=
my_args
.
argv
[
0
];
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
if
(
!
c
)
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
ERROR
(
"Failed to load rcfile"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
ERROR
(
"Out of memory setting new config filename"
);
ERROR
(
"Out of memory setting new config filename"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
}
}
if
(
!
c
->
may_control
(
c
))
{
if
(
!
c
->
may_control
(
c
))
{
ERROR
(
"Insufficent privileges to control %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"Insufficent privileges to control %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
!
c
->
is_running
(
c
))
{
if
(
!
c
->
is_running
(
c
))
{
ERROR
(
"'%s:%s' is not running"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"'%s:%s' is not running"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
((
my_args
.
argc
)
>
1
)
{
if
((
my_args
.
argc
)
>
1
)
{
...
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
...
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
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
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
}
else
{
}
else
{
int
len
=
4096
;
int
len
=
4096
;
...
@@ -128,11 +128,11 @@ int main(int argc, char *argv[])
...
@@ -128,11 +128,11 @@ int main(int argc, char *argv[])
ERROR
(
"failed to retrieve value of '%s' for '%s:%s'"
,
ERROR
(
"failed to retrieve value of '%s' for '%s:%s'"
,
state_object
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
state_object
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
printf
(
"%*s"
,
ret
,
buffer
);
printf
(
"%*s"
,
ret
,
buffer
);
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
0
;
exit
(
EXIT_SUCCESS
)
;
}
}
src/lxc/tools/lxc_checkpoint.c
View file @
fe8ded6d
...
@@ -198,21 +198,21 @@ int main(int argc, char *argv[])
...
@@ -198,21 +198,21 @@ int main(int argc, char *argv[])
bool
ret
;
bool
ret
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
1
);
exit
(
EXIT_FAILURE
);
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
exit
(
1
);
exit
(
EXIT_FAILURE
);
lxc_log_options_no_override
();
lxc_log_options_no_override
();
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"System error loading %s
\n
"
,
my_args
.
name
);
fprintf
(
stderr
,
"System error loading %s
\n
"
,
my_args
.
name
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
...
@@ -220,26 +220,26 @@ int main(int argc, char *argv[])
...
@@ -220,26 +220,26 @@ int main(int argc, char *argv[])
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
}
}
if
(
!
c
->
may_control
(
c
))
{
if
(
!
c
->
may_control
(
c
))
{
fprintf
(
stderr
,
"Insufficent privileges to control %s
\n
"
,
my_args
.
name
);
fprintf
(
stderr
,
"Insufficent privileges to control %s
\n
"
,
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
fprintf
(
stderr
,
"%s is not defined
\n
"
,
my_args
.
name
);
fprintf
(
stderr
,
"%s is not defined
\n
"
,
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -248,5 +248,8 @@ int main(int argc, char *argv[])
...
@@ -248,5 +248,8 @@ int main(int argc, char *argv[])
else
else
ret
=
checkpoint
(
c
);
ret
=
checkpoint
(
c
);
return
!
ret
;
if
(
!
ret
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_SUCCESS
);
}
}
src/lxc/tools/lxc_clone.c
View file @
fe8ded6d
...
@@ -89,7 +89,7 @@ static void usage(const char *me)
...
@@ -89,7 +89,7 @@ static void usage(const char *me)
printf
(
" -p: use container orig from custom lxcpath
\n
"
);
printf
(
" -p: use container orig from custom lxcpath
\n
"
);
printf
(
" -P: create container new in custom lxcpath
\n
"
);
printf
(
" -P: create container new in custom lxcpath
\n
"
);
printf
(
" -R: rename existing container
\n
"
);
printf
(
" -R: rename existing container
\n
"
);
exit
(
1
);
exit
(
EXIT_SUCCESS
);
}
}
static
struct
option
options
[]
=
{
static
struct
option
options
[]
=
{
...
...
src/lxc/tools/lxc_config.c
View file @
fe8ded6d
...
@@ -45,7 +45,7 @@ static void usage(char *me)
...
@@ -45,7 +45,7 @@ static void usage(char *me)
{
{
printf
(
"Usage: %s -l: list all available configuration items
\n
"
,
me
);
printf
(
"Usage: %s -l: list all available configuration items
\n
"
,
me
);
printf
(
" %s item: print configuration item
\n
"
,
me
);
printf
(
" %s item: print configuration item
\n
"
,
me
);
exit
(
1
);
exit
(
EXIT_SUCCESS
);
}
}
static
void
list_config_items
(
void
)
static
void
list_config_items
(
void
)
...
@@ -54,7 +54,7 @@ static void list_config_items(void)
...
@@ -54,7 +54,7 @@ static void list_config_items(void)
for
(
i
=
&
items
[
0
];
i
->
name
;
i
++
)
for
(
i
=
&
items
[
0
];
i
->
name
;
i
++
)
printf
(
"%s
\n
"
,
i
->
name
);
printf
(
"%s
\n
"
,
i
->
name
);
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
...
@@ -73,9 +73,9 @@ int main(int argc, char *argv[])
...
@@ -73,9 +73,9 @@ int main(int argc, char *argv[])
printf
(
"%s
\n
"
,
value
);
printf
(
"%s
\n
"
,
value
);
else
else
printf
(
"%s is not set.
\n
"
,
argv
[
1
]);
printf
(
"%s is not set.
\n
"
,
argv
[
1
]);
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
}
}
printf
(
"Unknown configuration item: %s
\n
"
,
argv
[
1
]);
printf
(
"Unknown configuration item: %s
\n
"
,
argv
[
1
]);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
src/lxc/tools/lxc_console.c
View file @
fe8ded6d
...
@@ -146,5 +146,5 @@ int main(int argc, char *argv[])
...
@@ -146,5 +146,5 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
EXIT_SUCCESS
;
exit
(
EXIT_SUCCESS
)
;
}
}
src/lxc/tools/lxc_device.c
View file @
fe8ded6d
...
@@ -66,7 +66,7 @@ static bool is_interface(const char* dev_name, pid_t pid)
...
@@ -66,7 +66,7 @@ static bool is_interface(const char* dev_name, pid_t pid)
if
(
p
<
0
)
{
if
(
p
<
0
)
{
SYSERROR
(
"failed to fork task."
);
SYSERROR
(
"failed to fork task."
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
p
==
0
)
{
if
(
p
==
0
)
{
...
@@ -86,10 +86,10 @@ static bool is_interface(const char* dev_name, pid_t pid)
...
@@ -86,10 +86,10 @@ static bool is_interface(const char* dev_name, pid_t pid)
/* Iterate through the interfaces */
/* Iterate through the interfaces */
for
(
tempIfAddr
=
interfaceArray
;
tempIfAddr
!=
NULL
;
tempIfAddr
=
tempIfAddr
->
ifa_next
)
{
for
(
tempIfAddr
=
interfaceArray
;
tempIfAddr
!=
NULL
;
tempIfAddr
=
tempIfAddr
->
ifa_next
)
{
if
(
strcmp
(
tempIfAddr
->
ifa_name
,
dev_name
)
==
0
)
{
if
(
strcmp
(
tempIfAddr
->
ifa_name
,
dev_name
)
==
0
)
{
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
}
}
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
wait_for_pid
(
p
)
==
0
)
{
if
(
wait_for_pid
(
p
)
==
0
)
{
...
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
...
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
if
(
geteuid
()
!=
0
)
{
if
(
geteuid
()
!=
0
)
{
ERROR
(
"%s must be run as root"
,
argv
[
0
]);
ERROR
(
"%s must be run as root"
,
argv
[
0
]);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
...
@@ -184,9 +184,9 @@ int main(int argc, char *argv[])
...
@@ -184,9 +184,9 @@ int main(int argc, char *argv[])
ERROR
(
"Error: Please use add or del (Please see --help output)"
);
ERROR
(
"Error: Please use add or del (Please see --help output)"
);
goto
err1
;
goto
err1
;
}
}
exit
(
0
);
exit
(
EXIT_SUCCESS
);
err1:
err1:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
err:
err:
exit
(
ret
);
exit
(
EXIT_FAILURE
);
}
}
src/lxc/tools/lxc_execute.c
View file @
fe8ded6d
...
@@ -102,14 +102,14 @@ int main(int argc, char *argv[])
...
@@ -102,14 +102,14 @@ int main(int argc, char *argv[])
lxc_list_init
(
&
defines
);
lxc_list_init
(
&
defines
);
if
(
lxc_caps_init
())
if
(
lxc_caps_init
())
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
1
;
exit
(
EXIT_FAILURE
)
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
1
;
exit
(
EXIT_FAILURE
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
/* rcfile is specified in the cli option */
/* rcfile is specified in the cli option */
...
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
...
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
my_args
.
lxcpath
[
0
],
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
;
exit
(
EXIT_FAILURE
)
;
}
}
/* container configuration does not exist */
/* container configuration does not exist */
...
@@ -134,16 +134,16 @@ int main(int argc, char *argv[])
...
@@ -134,16 +134,16 @@ int main(int argc, char *argv[])
conf
=
lxc_conf_init
();
conf
=
lxc_conf_init
();
if
(
!
conf
)
{
if
(
!
conf
)
{
ERROR
(
"failed to initialize configuration"
);
ERROR
(
"failed to initialize configuration"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
rcfile
&&
lxc_config_read
(
rcfile
,
conf
,
NULL
))
{
if
(
rcfile
&&
lxc_config_read
(
rcfile
,
conf
,
NULL
))
{
ERROR
(
"failed to read configuration file"
);
ERROR
(
"failed to read configuration file"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
lxc_config_define_load
(
&
defines
,
conf
))
if
(
lxc_config_define_load
(
&
defines
,
conf
))
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
my_args
.
uid
)
if
(
my_args
.
uid
)
conf
->
init_uid
=
my_args
.
uid
;
conf
->
init_uid
=
my_args
.
uid
;
...
@@ -156,6 +156,6 @@ int main(int argc, char *argv[])
...
@@ -156,6 +156,6 @@ int main(int argc, char *argv[])
lxc_conf_free
(
conf
);
lxc_conf_free
(
conf
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
1
;
exit
(
EXIT_FAILURE
)
;
return
ret
;
exit
(
EXIT_SUCCESS
)
;
}
}
src/lxc/tools/lxc_freeze.c
View file @
fe8ded6d
...
@@ -59,20 +59,20 @@ int main(int argc, char *argv[])
...
@@ -59,20 +59,20 @@ int main(int argc, char *argv[])
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
1
);
exit
(
EXIT_FAILURE
);
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
exit
(
1
);
exit
(
EXIT_FAILURE
);
lxc_log_options_no_override
();
lxc_log_options_no_override
();
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
ERROR
(
"No such container: %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"No such container: %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
...
@@ -80,29 +80,29 @@ int main(int argc, char *argv[])
...
@@ -80,29 +80,29 @@ int main(int argc, char *argv[])
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
ERROR
(
"Failed to load rcfile"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
ERROR
(
"Out of memory setting new config filename"
);
ERROR
(
"Out of memory setting new config filename"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
}
}
if
(
!
c
->
may_control
(
c
))
{
if
(
!
c
->
may_control
(
c
))
{
ERROR
(
"Insufficent privileges to control %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"Insufficent privileges to control %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
!
c
->
freeze
(
c
))
{
if
(
!
c
->
freeze
(
c
))
{
ERROR
(
"Failed to freeze %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"Failed to freeze %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
src/lxc/tools/lxc_info.c
View file @
fe8ded6d
...
@@ -396,18 +396,18 @@ int main(int argc, char *argv[])
...
@@ -396,18 +396,18 @@ int main(int argc, char *argv[])
int
ret
=
EXIT_FAILURE
;
int
ret
=
EXIT_FAILURE
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
ret
;
exit
(
ret
)
;
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
ret
;
exit
(
ret
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
if
(
print_info
(
my_args
.
name
,
my_args
.
lxcpath
[
0
])
==
0
)
if
(
print_info
(
my_args
.
name
,
my_args
.
lxcpath
[
0
])
==
0
)
ret
=
EXIT_SUCCESS
;
ret
=
EXIT_SUCCESS
;
return
ret
;
exit
(
ret
)
;
}
}
src/lxc/tools/lxc_monitor.c
View file @
fe8ded6d
...
@@ -92,17 +92,17 @@ int main(int argc, char *argv[])
...
@@ -92,17 +92,17 @@ int main(int argc, char *argv[])
nfds_t
nfds
;
nfds_t
nfds
;
int
len
,
rc_main
,
rc_snp
,
i
;
int
len
,
rc_main
,
rc_snp
,
i
;
rc_main
=
0
;
rc_main
=
EXIT_FAILURE
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
1
;
exit
(
rc_main
)
;
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
1
;
exit
(
rc_main
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
if
(
quit_monitord
)
{
if
(
quit_monitord
)
{
...
@@ -124,32 +124,29 @@ int main(int argc, char *argv[])
...
@@ -124,32 +124,29 @@ int main(int argc, char *argv[])
}
}
close
(
fd
);
close
(
fd
);
}
}
return
ret
;
exit
(
ret
)
;
}
}
len
=
strlen
(
my_args
.
name
)
+
3
;
len
=
strlen
(
my_args
.
name
)
+
3
;
regexp
=
malloc
(
len
+
3
);
regexp
=
malloc
(
len
+
3
);
if
(
!
regexp
)
{
if
(
!
regexp
)
{
ERROR
(
"failed to allocate memory"
);
ERROR
(
"failed to allocate memory"
);
return
1
;
exit
(
rc_main
)
;
}
}
rc_snp
=
snprintf
(
regexp
,
len
,
"^%s$"
,
my_args
.
name
);
rc_snp
=
snprintf
(
regexp
,
len
,
"^%s$"
,
my_args
.
name
);
if
(
rc_snp
<
0
||
rc_snp
>=
len
)
{
if
(
rc_snp
<
0
||
rc_snp
>=
len
)
{
ERROR
(
"Name too long"
);
ERROR
(
"Name too long"
);
rc_main
=
1
;
goto
error
;
goto
error
;
}
}
if
(
regcomp
(
&
preg
,
regexp
,
REG_NOSUB
|
REG_EXTENDED
))
{
if
(
regcomp
(
&
preg
,
regexp
,
REG_NOSUB
|
REG_EXTENDED
))
{
ERROR
(
"failed to compile the regex '%s'"
,
my_args
.
name
);
ERROR
(
"failed to compile the regex '%s'"
,
my_args
.
name
);
rc_main
=
1
;
goto
error
;
goto
error
;
}
}
fds
=
malloc
(
my_args
.
lxcpath_cnt
*
sizeof
(
struct
pollfd
));
fds
=
malloc
(
my_args
.
lxcpath_cnt
*
sizeof
(
struct
pollfd
));
if
(
!
fds
)
{
if
(
!
fds
)
{
SYSERROR
(
"out of memory"
);
SYSERROR
(
"out of memory"
);
rc_main
=
-
1
;
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -162,7 +159,6 @@ int main(int argc, char *argv[])
...
@@ -162,7 +159,6 @@ int main(int argc, char *argv[])
fd
=
lxc_monitor_open
(
my_args
.
lxcpath
[
i
]);
fd
=
lxc_monitor_open
(
my_args
.
lxcpath
[
i
]);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
close_fds
(
fds
,
i
);
close_fds
(
fds
,
i
);
rc_main
=
1
;
goto
cleanup
;
goto
cleanup
;
}
}
fds
[
i
].
fd
=
fd
;
fds
[
i
].
fd
=
fd
;
...
@@ -174,7 +170,6 @@ int main(int argc, char *argv[])
...
@@ -174,7 +170,6 @@ int main(int argc, char *argv[])
for
(;;)
{
for
(;;)
{
if
(
lxc_monitor_read_fdset
(
fds
,
nfds
,
&
msg
,
-
1
)
<
0
)
{
if
(
lxc_monitor_read_fdset
(
fds
,
nfds
,
&
msg
,
-
1
)
<
0
)
{
rc_main
=
1
;
goto
close_and_clean
;
goto
close_and_clean
;
}
}
...
@@ -196,6 +191,7 @@ int main(int argc, char *argv[])
...
@@ -196,6 +191,7 @@ int main(int argc, char *argv[])
break
;
break
;
}
}
}
}
rc_main
=
0
;
close_and_clean:
close_and_clean:
close_fds
(
fds
,
nfds
);
close_fds
(
fds
,
nfds
);
...
@@ -207,5 +203,5 @@ cleanup:
...
@@ -207,5 +203,5 @@ cleanup:
error:
error:
free
(
regexp
);
free
(
regexp
);
return
rc_main
;
exit
(
rc_main
)
;
}
}
src/lxc/tools/lxc_start.c
View file @
fe8ded6d
...
@@ -203,7 +203,7 @@ Options :\n\
...
@@ -203,7 +203,7 @@ Options :\n\
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
err
=
1
;
int
err
=
EXIT_FAILURE
;
struct
lxc_conf
*
conf
;
struct
lxc_conf
*
conf
;
char
*
const
*
args
;
char
*
const
*
args
;
char
*
rcfile
=
NULL
;
char
*
rcfile
=
NULL
;
...
@@ -216,10 +216,10 @@ int main(int argc, char *argv[])
...
@@ -216,10 +216,10 @@ int main(int argc, char *argv[])
lxc_list_init
(
&
defines
);
lxc_list_init
(
&
defines
);
if
(
lxc_caps_init
())
if
(
lxc_caps_init
())
return
err
;
exit
(
err
)
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
err
;
exit
(
err
)
;
if
(
!
my_args
.
argc
)
if
(
!
my_args
.
argc
)
args
=
default_args
;
args
=
default_args
;
...
@@ -228,7 +228,7 @@ int main(int argc, char *argv[])
...
@@ -228,7 +228,7 @@ int main(int argc, char *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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
err
;
exit
(
err
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
const
char
*
lxcpath
=
my_args
.
lxcpath
[
0
];
const
char
*
lxcpath
=
my_args
.
lxcpath
[
0
];
...
@@ -245,13 +245,13 @@ int main(int argc, char *argv[])
...
@@ -245,13 +245,13 @@ int main(int argc, char *argv[])
c
=
lxc_container_new
(
my_args
.
name
,
lxcpath
);
c
=
lxc_container_new
(
my_args
.
name
,
lxcpath
);
if
(
!
c
)
{
if
(
!
c
)
{
ERROR
(
"Failed to create lxc_container"
);
ERROR
(
"Failed to create lxc_container"
);
return
err
;
exit
(
err
)
;
}
}
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
ERROR
(
"Failed to load rcfile"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
err
;
exit
(
err
)
;
}
}
}
else
{
}
else
{
int
rc
;
int
rc
;
...
@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
...
@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
lxcpath
,
my_args
.
name
);
rc
=
asprintf
(
&
rcfile
,
"%s/%s/config"
,
lxcpath
,
my_args
.
name
);
if
(
rc
==
-
1
)
{
if
(
rc
==
-
1
)
{
SYSERROR
(
"failed to allocate memory"
);
SYSERROR
(
"failed to allocate memory"
);
return
err
;
exit
(
err
)
;
}
}
INFO
(
"using rcfile %s"
,
rcfile
);
INFO
(
"using rcfile %s"
,
rcfile
);
...
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
...
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
c
=
lxc_container_new
(
my_args
.
name
,
lxcpath
);
c
=
lxc_container_new
(
my_args
.
name
,
lxcpath
);
if
(
!
c
)
{
if
(
!
c
)
{
ERROR
(
"Failed to create lxc_container"
);
ERROR
(
"Failed to create lxc_container"
);
return
err
;
exit
(
err
)
;
}
}
}
}
...
@@ -336,9 +336,9 @@ int main(int argc, char *argv[])
...
@@ -336,9 +336,9 @@ int main(int argc, char *argv[])
c
->
want_close_all_fds
(
c
,
true
);
c
->
want_close_all_fds
(
c
,
true
);
if
(
args
==
default_args
)
if
(
args
==
default_args
)
err
=
c
->
start
(
c
,
0
,
NULL
)
?
0
:
1
;
err
=
c
->
start
(
c
,
0
,
NULL
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
else
else
err
=
c
->
start
(
c
,
0
,
args
)
?
0
:
1
;
err
=
c
->
start
(
c
,
0
,
args
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
if
(
err
)
{
if
(
err
)
{
ERROR
(
"The container failed to start."
);
ERROR
(
"The container failed to start."
);
...
@@ -348,10 +348,10 @@ int main(int argc, char *argv[])
...
@@ -348,10 +348,10 @@ int main(int argc, char *argv[])
"--logfile and --logpriority options."
);
"--logfile and --logpriority options."
);
err
=
c
->
error_num
;
err
=
c
->
error_num
;
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
err
;
exit
(
err
)
;
}
}
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
err
;
exit
(
err
)
;
}
}
src/lxc/tools/lxc_stop.c
View file @
fe8ded6d
...
@@ -143,14 +143,14 @@ int main(int argc, char *argv[])
...
@@ -143,14 +143,14 @@ int main(int argc, char *argv[])
{
{
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
bool
s
;
bool
s
;
int
ret
=
1
;
int
ret
=
EXIT_FAILURE
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
1
;
exit
(
ret
)
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
1
;
exit
(
ret
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
/* Set default timeout */
/* Set default timeout */
...
@@ -170,33 +170,35 @@ int main(int argc, char *argv[])
...
@@ -170,33 +170,35 @@ int main(int argc, char *argv[])
/* some checks */
/* some checks */
if
(
!
my_args
.
hardstop
&&
my_args
.
timeout
<
-
1
)
{
if
(
!
my_args
.
hardstop
&&
my_args
.
timeout
<
-
1
)
{
fprintf
(
stderr
,
"invalid timeout
\n
"
);
fprintf
(
stderr
,
"invalid timeout
\n
"
);
return
1
;
exit
(
ret
)
;
}
}
if
(
my_args
.
hardstop
&&
my_args
.
nokill
)
{
if
(
my_args
.
hardstop
&&
my_args
.
nokill
)
{
fprintf
(
stderr
,
"-k can't be used with --nokill
\n
"
);
fprintf
(
stderr
,
"-k can't be used with --nokill
\n
"
);
return
1
;
exit
(
ret
)
;
}
}
if
(
my_args
.
hardstop
&&
my_args
.
reboot
)
{
if
(
my_args
.
hardstop
&&
my_args
.
reboot
)
{
fprintf
(
stderr
,
"-k can't be used with -r
\n
"
);
fprintf
(
stderr
,
"-k can't be used with -r
\n
"
);
return
1
;
exit
(
ret
)
;
}
}
if
(
my_args
.
hardstop
&&
my_args
.
timeout
)
{
if
(
my_args
.
hardstop
&&
my_args
.
timeout
)
{
fprintf
(
stderr
,
"-k doesn't allow timeouts
\n
"
);
fprintf
(
stderr
,
"-k doesn't allow timeouts
\n
"
);
return
1
;
exit
(
ret
)
;
}
}
if
(
my_args
.
nolock
&&
!
my_args
.
hardstop
)
{
if
(
my_args
.
nolock
&&
!
my_args
.
hardstop
)
{
fprintf
(
stderr
,
"--nolock may only be used with -k
\n
"
);
fprintf
(
stderr
,
"--nolock may only be used with -k
\n
"
);
return
1
;
exit
(
ret
)
;
}
}
/* shortcut - if locking is bogus, we should be able to kill
/* shortcut - if locking is bogus, we should be able to kill
* containers at least */
* containers at least */
if
(
my_args
.
nolock
)
if
(
my_args
.
nolock
)
{
return
lxc_cmd_stop
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
ret
=
lxc_cmd_stop
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
exit
(
ret
);
}
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
...
@@ -224,19 +226,19 @@ int main(int argc, char *argv[])
...
@@ -224,19 +226,19 @@ int main(int argc, char *argv[])
if
(
!
c
->
is_running
(
c
))
{
if
(
!
c
->
is_running
(
c
))
{
fprintf
(
stderr
,
"%s is not running
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"%s is not running
\n
"
,
c
->
name
);
ret
=
2
;
ret
=
EXIT_FAILURE
;
goto
out
;
goto
out
;
}
}
/* kill */
/* kill */
if
(
my_args
.
hardstop
)
{
if
(
my_args
.
hardstop
)
{
ret
=
c
->
stop
(
c
)
?
0
:
1
;
ret
=
c
->
stop
(
c
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
goto
out
;
goto
out
;
}
}
/* reboot */
/* reboot */
if
(
my_args
.
reboot
)
{
if
(
my_args
.
reboot
)
{
ret
=
do_reboot_and_check
(
&
my_args
,
c
);
ret
=
do_reboot_and_check
(
&
my_args
,
c
)
<
0
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
goto
out
;
goto
out
;
}
}
...
@@ -244,17 +246,16 @@ int main(int argc, char *argv[])
...
@@ -244,17 +246,16 @@ int main(int argc, char *argv[])
s
=
c
->
shutdown
(
c
,
my_args
.
timeout
);
s
=
c
->
shutdown
(
c
,
my_args
.
timeout
);
if
(
!
s
)
{
if
(
!
s
)
{
if
(
my_args
.
timeout
==
0
)
if
(
my_args
.
timeout
==
0
)
ret
=
0
;
ret
=
EXIT_SUCCESS
;
else
if
(
my_args
.
nokill
)
else
if
(
my_args
.
nokill
)
ret
=
1
;
ret
=
EXIT_FAILURE
;
else
else
ret
=
c
->
stop
(
c
)
?
0
:
1
;
ret
=
c
->
stop
(
c
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
}
else
}
else
{
ret
=
0
;
ret
=
EXIT_SUCCESS
;
}
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
<
0
)
exit
(
ret
);
return
1
;
return
ret
;
}
}
src/lxc/tools/lxc_top.c
View file @
fe8ded6d
...
@@ -506,5 +506,5 @@ int main(int argc, char *argv[])
...
@@ -506,5 +506,5 @@ int main(int argc, char *argv[])
err1:
err1:
lxc_mainloop_close
(
&
descr
);
lxc_mainloop_close
(
&
descr
);
out:
out:
return
ret
;
exit
(
EXIT_FAILURE
)
;
}
}
src/lxc/tools/lxc_unfreeze.c
View file @
fe8ded6d
...
@@ -57,26 +57,26 @@ int main(int argc, char *argv[])
...
@@ -57,26 +57,26 @@ int main(int argc, char *argv[])
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
1
);
exit
(
EXIT_FAILURE
);
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
exit
(
1
);
exit
(
EXIT_FAILURE
);
lxc_log_options_no_override
();
lxc_log_options_no_override
();
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
ERROR
(
"No such container: %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"No such container: %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
!
c
->
may_control
(
c
))
{
if
(
!
c
->
may_control
(
c
))
{
ERROR
(
"Insufficent privileges to control %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"Insufficent privileges to control %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
...
@@ -84,23 +84,23 @@ int main(int argc, char *argv[])
...
@@ -84,23 +84,23 @@ int main(int argc, char *argv[])
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
ERROR
(
"Failed to load rcfile"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
ERROR
(
"Out of memory setting new config filename"
);
ERROR
(
"Out of memory setting new config filename"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
}
}
if
(
!
c
->
unfreeze
(
c
))
{
if
(
!
c
->
unfreeze
(
c
))
{
ERROR
(
"Failed to unfreeze %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
ERROR
(
"Failed to unfreeze %s:%s"
,
my_args
.
lxcpath
[
0
],
my_args
.
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
src/lxc/tools/lxc_unshare.c
View file @
fe8ded6d
...
@@ -77,7 +77,7 @@ static void usage(char *cmd)
...
@@ -77,7 +77,7 @@ static void usage(char *cmd)
fprintf
(
stderr
,
"
\t
-H <hostname>: Set the hostname in the container
\n
"
);
fprintf
(
stderr
,
"
\t
-H <hostname>: Set the hostname in the container
\n
"
);
fprintf
(
stderr
,
"
\t
-d : Daemonize (do not wait for container to exit)
\n
"
);
fprintf
(
stderr
,
"
\t
-d : Daemonize (do not wait for container to exit)
\n
"
);
fprintf
(
stderr
,
"
\t
-M : reMount default fs inside container (/proc /dev/shm /dev/mqueue)
\n
"
);
fprintf
(
stderr
,
"
\t
-M : reMount default fs inside container (/proc /dev/shm /dev/mqueue)
\n
"
);
_exit
(
1
);
_exit
(
EXIT_SUCCESS
);
}
}
static
bool
lookup_user
(
const
char
*
optarg
,
uid_t
*
uid
)
static
bool
lookup_user
(
const
char
*
optarg
,
uid_t
*
uid
)
...
@@ -134,13 +134,13 @@ static int do_start(void *arg)
...
@@ -134,13 +134,13 @@ static int do_start(void *arg)
if
((
flags
&
CLONE_NEWUTS
)
&&
want_hostname
)
if
((
flags
&
CLONE_NEWUTS
)
&&
want_hostname
)
if
(
sethostname
(
want_hostname
,
strlen
(
want_hostname
))
<
0
)
{
if
(
sethostname
(
want_hostname
,
strlen
(
want_hostname
))
<
0
)
{
ERROR
(
"failed to set hostname %s: %s"
,
want_hostname
,
strerror
(
errno
));
ERROR
(
"failed to set hostname %s: %s"
,
want_hostname
,
strerror
(
errno
));
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
// Setuid is useful even without a new user id space
// Setuid is useful even without a new user id space
if
(
start_arg
->
setuid
&&
setuid
(
uid
))
{
if
(
start_arg
->
setuid
&&
setuid
(
uid
))
{
ERROR
(
"failed to set uid %d: %s"
,
uid
,
strerror
(
errno
));
ERROR
(
"failed to set uid %d: %s"
,
uid
,
strerror
(
errno
));
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
execvp
(
args
[
0
],
args
);
execvp
(
args
[
0
],
args
);
...
@@ -177,7 +177,7 @@ int main(int argc, char *argv[])
...
@@ -177,7 +177,7 @@ int main(int argc, char *argv[])
case
'i'
:
case
'i'
:
if
(
!
(
tmpif
=
malloc
(
sizeof
(
*
tmpif
))))
{
if
(
!
(
tmpif
=
malloc
(
sizeof
(
*
tmpif
))))
{
perror
(
"malloc"
);
perror
(
"malloc"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
tmpif
->
mi_ifname
=
optarg
;
tmpif
->
mi_ifname
=
optarg
;
tmpif
->
mi_next
=
my_iflist
;
tmpif
->
mi_next
=
my_iflist
;
...
@@ -197,21 +197,21 @@ int main(int argc, char *argv[])
...
@@ -197,21 +197,21 @@ int main(int argc, char *argv[])
break
;
break
;
case
'u'
:
case
'u'
:
if
(
!
lookup_user
(
optarg
,
&
uid
))
if
(
!
lookup_user
(
optarg
,
&
uid
))
return
1
;
exit
(
EXIT_FAILURE
)
;
start_arg
.
setuid
=
true
;
start_arg
.
setuid
=
true
;
}
}
}
}
if
(
argv
[
optind
]
==
NULL
)
{
if
(
argv
[
optind
]
==
NULL
)
{
ERROR
(
"a command to execute in the new namespace is required"
);
ERROR
(
"a command to execute in the new namespace is required"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
args
=
&
argv
[
optind
];
args
=
&
argv
[
optind
];
ret
=
lxc_caps_init
();
ret
=
lxc_caps_init
();
if
(
ret
)
if
(
ret
)
return
1
;
exit
(
EXIT_FAILURE
)
;
ret
=
lxc_fill_namespace_flags
(
namespaces
,
&
flags
);
ret
=
lxc_fill_namespace_flags
(
namespaces
,
&
flags
);
if
(
ret
)
if
(
ret
)
...
@@ -219,23 +219,23 @@ int main(int argc, char *argv[])
...
@@ -219,23 +219,23 @@ int main(int argc, char *argv[])
if
(
!
(
flags
&
CLONE_NEWNET
)
&&
my_iflist
)
{
if
(
!
(
flags
&
CLONE_NEWNET
)
&&
my_iflist
)
{
ERROR
(
"-i <interfacename> needs -s NETWORK option"
);
ERROR
(
"-i <interfacename> needs -s NETWORK option"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
!
(
flags
&
CLONE_NEWUTS
)
&&
start_arg
.
want_hostname
)
{
if
(
!
(
flags
&
CLONE_NEWUTS
)
&&
start_arg
.
want_hostname
)
{
ERROR
(
"-H <hostname> needs -s UTSNAME option"
);
ERROR
(
"-H <hostname> needs -s UTSNAME option"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
!
(
flags
&
CLONE_NEWNS
)
&&
start_arg
.
want_default_mounts
)
{
if
(
!
(
flags
&
CLONE_NEWNS
)
&&
start_arg
.
want_default_mounts
)
{
ERROR
(
"-M needs -s MOUNT option"
);
ERROR
(
"-M needs -s MOUNT option"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
pid
=
lxc_clone
(
do_start
,
&
start_arg
,
flags
);
pid
=
lxc_clone
(
do_start
,
&
start_arg
,
flags
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
ERROR
(
"failed to clone"
);
ERROR
(
"failed to clone"
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
my_iflist
)
{
if
(
my_iflist
)
{
...
@@ -246,12 +246,13 @@ int main(int argc, char *argv[])
...
@@ -246,12 +246,13 @@ int main(int argc, char *argv[])
}
}
if
(
daemonize
)
if
(
daemonize
)
exit
(
0
);
exit
(
EXIT_SUCCESS
);
if
(
waitpid
(
pid
,
&
status
,
0
)
<
0
)
{
if
(
waitpid
(
pid
,
&
status
,
0
)
<
0
)
{
ERROR
(
"failed to wait for '%d'"
,
pid
);
ERROR
(
"failed to wait for '%d'"
,
pid
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
return
lxc_error_set_and_log
(
pid
,
status
);
/* Call exit() directly on this function because it retuns an exit code. */
exit
(
lxc_error_set_and_log
(
pid
,
status
));
}
}
src/lxc/tools/lxc_usernsexec.c
View file @
fe8ded6d
...
@@ -71,7 +71,7 @@ static void usage(const char *name)
...
@@ -71,7 +71,7 @@ static void usage(const char *name)
printf
(
" Note: This program uses newuidmap(2) and newgidmap(2).
\n
"
);
printf
(
" Note: This program uses newuidmap(2) and newgidmap(2).
\n
"
);
printf
(
" As such, /etc/subuid and /etc/subgid must grant the
\n
"
);
printf
(
" As such, /etc/subuid and /etc/subgid must grant the
\n
"
);
printf
(
" calling user permission to use the mapped ranges
\n
"
);
printf
(
" calling user permission to use the mapped ranges
\n
"
);
exit
(
1
);
exit
(
EXIT_SUCCESS
);
}
}
static
void
opentty
(
const
char
*
tty
,
int
which
)
{
static
void
opentty
(
const
char
*
tty
,
int
which
)
{
...
@@ -282,7 +282,7 @@ int main(int argc, char *argv[])
...
@@ -282,7 +282,7 @@ int main(int argc, char *argv[])
ret
=
readlink
(
"/proc/self/fd/0"
,
ttyname0
,
sizeof
(
ttyname0
));
ret
=
readlink
(
"/proc/self/fd/0"
,
ttyname0
,
sizeof
(
ttyname0
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
perror
(
"unable to open stdin."
);
perror
(
"unable to open stdin."
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
ret
=
readlink
(
"/proc/self/fd/1"
,
ttyname1
,
sizeof
(
ttyname1
));
ret
=
readlink
(
"/proc/self/fd/1"
,
ttyname1
,
sizeof
(
ttyname1
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
...
@@ -310,7 +310,7 @@ int main(int argc, char *argv[])
...
@@ -310,7 +310,7 @@ int main(int argc, char *argv[])
if
(
lxc_list_empty
(
&
active_map
))
{
if
(
lxc_list_empty
(
&
active_map
))
{
if
(
find_default_map
())
{
if
(
find_default_map
())
{
fprintf
(
stderr
,
"You have no allocated subuids or subgids
\n
"
);
fprintf
(
stderr
,
"You have no allocated subuids or subgids
\n
"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
}
}
...
@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
...
@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
if
(
pipe
(
pipe1
)
<
0
||
pipe
(
pipe2
)
<
0
)
{
if
(
pipe
(
pipe1
)
<
0
||
pipe
(
pipe2
)
<
0
)
{
perror
(
"pipe"
);
perror
(
"pipe"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
((
pid
=
fork
())
==
0
)
{
if
((
pid
=
fork
())
==
0
)
{
// Child.
// Child.
...
@@ -342,15 +342,15 @@ int main(int argc, char *argv[])
...
@@ -342,15 +342,15 @@ int main(int argc, char *argv[])
buf
[
0
]
=
'1'
;
buf
[
0
]
=
'1'
;
if
(
write
(
pipe1
[
1
],
buf
,
1
)
<
1
)
{
if
(
write
(
pipe1
[
1
],
buf
,
1
)
<
1
)
{
perror
(
"write pipe"
);
perror
(
"write pipe"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
read
(
pipe2
[
0
],
buf
,
1
)
<
1
)
{
if
(
read
(
pipe2
[
0
],
buf
,
1
)
<
1
)
{
perror
(
"read pipe"
);
perror
(
"read pipe"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
buf
[
0
]
!=
'1'
)
{
if
(
buf
[
0
]
!=
'1'
)
{
fprintf
(
stderr
,
"parent had an error, child exiting
\n
"
);
fprintf
(
stderr
,
"parent had an error, child exiting
\n
"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
close
(
pipe1
[
1
]);
close
(
pipe1
[
1
]);
...
@@ -362,7 +362,7 @@ int main(int argc, char *argv[])
...
@@ -362,7 +362,7 @@ int main(int argc, char *argv[])
close
(
pipe2
[
0
]);
close
(
pipe2
[
0
]);
if
(
read
(
pipe1
[
0
],
buf
,
1
)
<
1
)
{
if
(
read
(
pipe1
[
0
],
buf
,
1
)
<
1
)
{
perror
(
"read pipe"
);
perror
(
"read pipe"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
buf
[
0
]
=
'1'
;
buf
[
0
]
=
'1'
;
...
@@ -373,12 +373,12 @@ int main(int argc, char *argv[])
...
@@ -373,12 +373,12 @@ int main(int argc, char *argv[])
}
}
if
(
write
(
pipe2
[
1
],
buf
,
1
)
<
0
)
{
if
(
write
(
pipe2
[
1
],
buf
,
1
)
<
0
)
{
perror
(
"write to pipe"
);
perror
(
"write to pipe"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
((
ret
=
waitpid
(
pid
,
&
status
,
__WALL
))
<
0
)
{
if
((
ret
=
waitpid
(
pid
,
&
status
,
__WALL
))
<
0
)
{
printf
(
"waitpid() returns %d, errno %d
\n
"
,
ret
,
errno
);
printf
(
"waitpid() returns %d, errno %d
\n
"
,
ret
,
errno
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
exit
(
WEXITSTATUS
(
status
));
exit
(
WEXITSTATUS
(
status
));
...
...
src/lxc/tools/lxc_wait.c
View file @
fe8ded6d
...
@@ -85,24 +85,24 @@ int main(int argc, char *argv[])
...
@@ -85,24 +85,24 @@ int main(int argc, char *argv[])
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
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
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
return
1
;
exit
(
EXIT_FAILURE
)
;
lxc_log_options_no_override
();
lxc_log_options_no_override
();
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
if
(
!
c
)
return
1
;
exit
(
EXIT_FAILURE
)
;
if
(
!
c
->
may_control
(
c
))
{
if
(
!
c
->
may_control
(
c
))
{
fprintf
(
stderr
,
"Insufficent privileges to control %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"Insufficent privileges to control %s
\n
"
,
c
->
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
...
@@ -110,19 +110,19 @@ int main(int argc, char *argv[])
...
@@ -110,19 +110,19 @@ int main(int argc, char *argv[])
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
}
}
if
(
!
c
->
wait
(
c
,
my_args
.
states
,
my_args
.
timeout
))
{
if
(
!
c
->
wait
(
c
,
my_args
.
states
,
my_args
.
timeout
))
{
lxc_container_put
(
c
);
lxc_container_put
(
c
);
return
1
;
exit
(
EXIT_FAILURE
)
;
}
}
return
0
;
exit
(
EXIT_SUCCESS
)
;
}
}
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