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
9b937486
Unverified
Commit
9b937486
authored
Jul 03, 2018
by
Christian Brauner
Committed by
GitHub
Jul 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2445 from 2xsec/bugfix
tests: cleanup source codes.
parents
5221c891
6ea8a436
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
453 additions
and
215 deletions
+453
-215
api_reboot.c
src/tests/api_reboot.c
+3
-0
clonetest.c
src/tests/clonetest.c
+11
-0
concurrent.c
src/tests/concurrent.c
+213
-200
config_jump_table.c
src/tests/config_jump_table.c
+1
-1
console.c
src/tests/console.c
+17
-0
containertests.c
src/tests/containertests.c
+22
-0
createtest.c
src/tests/createtest.c
+4
-0
criu_check_feature.c
src/tests/criu_check_feature.c
+1
-0
destroytest.c
src/tests/destroytest.c
+7
-0
device_add_remove.c
src/tests/device_add_remove.c
+2
-0
get_item.c
src/tests/get_item.c
+50
-1
getkeys.c
src/tests/getkeys.c
+1
-0
list.c
src/tests/list.c
+10
-0
locktests.c
src/tests/locktests.c
+14
-0
lxc-test-utils.c
src/tests/lxc-test-utils.c
+24
-0
lxc_raw_clone.c
src/tests/lxc_raw_clone.c
+1
-4
lxcpath.c
src/tests/lxcpath.c
+2
-0
may_control.c
src/tests/may_control.c
+4
-0
reboot.c
src/tests/reboot.c
+4
-0
saveconfig.c
src/tests/saveconfig.c
+8
-0
shortlived.c
src/tests/shortlived.c
+14
-0
shutdowntest.c
src/tests/shutdowntest.c
+7
-4
snapshot.c
src/tests/snapshot.c
+17
-4
startone.c
src/tests/startone.c
+15
-1
state_server.c
src/tests/state_server.c
+1
-0
No files found.
src/tests/api_reboot.c
View file @
9b937486
...
@@ -59,6 +59,7 @@ int main(int argc, char *argv[])
...
@@ -59,6 +59,7 @@ int main(int argc, char *argv[])
lxc_error
(
"%s
\n
"
,
"Container
\"
reboot
\"
is not defined"
);
lxc_error
(
"%s
\n
"
,
"Container
\"
reboot
\"
is not defined"
);
goto
on_error_put
;
goto
on_error_put
;
}
}
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
NULL
))
{
if
(
!
c
->
load_config
(
c
,
NULL
))
{
...
@@ -118,7 +119,9 @@ on_error_stop:
...
@@ -118,7 +119,9 @@ on_error_stop:
on_error_put:
on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All reboot tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All reboot tests passed"
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/clonetest.c
View file @
9b937486
...
@@ -41,6 +41,7 @@ int main(int argc, char *argv[])
...
@@ -41,6 +41,7 @@ int main(int argc, char *argv[])
lxc_container_put
(
c
);
lxc_container_put
(
c
);
c
=
NULL
;
c
=
NULL
;
}
}
if
(
c2
)
{
if
(
c2
)
{
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
...
@@ -52,11 +53,14 @@ int main(int argc, char *argv[])
...
@@ -52,11 +53,14 @@ int main(int argc, char *argv[])
ret
=
1
;
ret
=
1
;
goto
out
;
goto
out
;
}
}
c
->
save_config
(
c
,
NULL
);
c
->
save_config
(
c
,
NULL
);
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
...
@@ -92,12 +96,14 @@ int main(int argc, char *argv[])
...
@@ -92,12 +96,14 @@ int main(int argc, char *argv[])
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
}
}
c2
=
lxc_container_new
(
"clonetest-o1"
,
NULL
);
c2
=
lxc_container_new
(
"clonetest-o1"
,
NULL
);
if
(
c2
)
{
if
(
c2
)
{
if
(
c2
->
is_defined
(
c2
))
if
(
c2
->
is_defined
(
c2
))
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
}
}
c2
=
lxc_container_new
(
"clonetest-o2"
,
NULL
);
c2
=
lxc_container_new
(
"clonetest-o2"
,
NULL
);
if
(
c2
)
{
if
(
c2
)
{
if
(
c2
->
is_defined
(
c2
))
if
(
c2
->
is_defined
(
c2
))
...
@@ -112,6 +118,7 @@ int main(int argc, char *argv[])
...
@@ -112,6 +118,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"failed loading clonetestlvm1
\n
"
);
fprintf
(
stderr
,
"failed loading clonetestlvm1
\n
"
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
fprintf
(
stderr
,
"clonetestlvm1 does not exist, skipping lvm tests
\n
"
);
fprintf
(
stderr
,
"clonetestlvm1 does not exist, skipping lvm tests
\n
"
);
ret
=
0
;
ret
=
0
;
...
@@ -138,6 +145,7 @@ int main(int argc, char *argv[])
...
@@ -138,6 +145,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"lvm clone failed
\n
"
);
fprintf
(
stderr
,
"lvm clone failed
\n
"
);
goto
out
;
goto
out
;
}
}
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
c
=
c2
=
NULL
;
c
=
c2
=
NULL
;
...
@@ -166,13 +174,16 @@ out:
...
@@ -166,13 +174,16 @@ out:
if
(
c3
)
{
if
(
c3
)
{
lxc_container_put
(
c3
);
lxc_container_put
(
c3
);
}
}
if
(
c2
)
{
if
(
c2
)
{
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
}
}
if
(
c
)
{
if
(
c
)
{
c
->
destroy
(
c
);
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/concurrent.c
View file @
9b937486
...
@@ -35,223 +35,236 @@ static int delay = 0;
...
@@ -35,223 +35,236 @@ static int delay = 0;
static
const
char
*
template
=
"busybox"
;
static
const
char
*
template
=
"busybox"
;
static
const
struct
option
options
[]
=
{
static
const
struct
option
options
[]
=
{
{
"threads"
,
required_argument
,
NULL
,
'j'
},
{
"threads"
,
required_argument
,
NULL
,
'j'
},
{
"iterations"
,
required_argument
,
NULL
,
'i'
},
{
"iterations"
,
required_argument
,
NULL
,
'i'
},
{
"template"
,
required_argument
,
NULL
,
't'
},
{
"template"
,
required_argument
,
NULL
,
't'
},
{
"delay"
,
required_argument
,
NULL
,
'd'
},
{
"delay"
,
required_argument
,
NULL
,
'd'
},
{
"modes"
,
required_argument
,
NULL
,
'm'
},
{
"modes"
,
required_argument
,
NULL
,
'm'
},
{
"quiet"
,
no_argument
,
NULL
,
'q'
},
{
"quiet"
,
no_argument
,
NULL
,
'q'
},
{
"debug"
,
no_argument
,
NULL
,
'D'
},
{
"debug"
,
no_argument
,
NULL
,
'D'
},
{
"help"
,
no_argument
,
NULL
,
'?'
},
{
"help"
,
no_argument
,
NULL
,
'?'
},
{
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
},
};
};
static
void
usage
(
void
)
{
static
void
usage
(
void
)
{
fprintf
(
stderr
,
"Usage: lxc-test-concurrent [OPTION]...
\n\n
"
fprintf
(
stderr
,
"Usage: lxc-test-concurrent [OPTION]...
\n\n
"
"Common options :
\n
"
"Common options :
\n
"
" -j, --threads=N Threads to run concurrently
\n
"
" -j, --threads=N Threads to run concurrently
\n
"
" (default: 5, use 1 for no threading)
\n
"
" (default: 5, use 1 for no threading)
\n
"
" -i, --iterations=N Number times to run the test (default: 1)
\n
"
" -i, --iterations=N Number times to run the test (default: 1)
\n
"
" -t, --template=t Template to use (default: busybox)
\n
"
" -t, --template=t Template to use (default: busybox)
\n
"
" -d, --delay=N Delay in seconds between start and stop
\n
"
" -d, --delay=N Delay in seconds between start and stop
\n
"
" -m, --modes=<mode,mode,...> Modes to run (create, start, stop, destroy)
\n
"
" -m, --modes=<mode,mode,...> Modes to run (create, start, stop, destroy)
\n
"
" -q, --quiet Don't produce any output
\n
"
" -q, --quiet Don't produce any output
\n
"
" -D, --debug Create a debug log
\n
"
" -D, --debug Create a debug log
\n
"
" -?, --help Give this help list
\n
"
" -?, --help Give this help list
\n
"
"
\n
"
"
\n
"
"Mandatory or optional arguments to long options are also mandatory or optional
\n
"
"Mandatory or optional arguments to long options are also mandatory or optional
\n
"
"for any corresponding short options.
\n\n
"
);
"for any corresponding short options.
\n\n
"
);
}
}
struct
thread_args
{
struct
thread_args
{
int
thread_id
;
int
thread_id
;
int
return_code
;
int
return_code
;
const
char
*
mode
;
const
char
*
mode
;
};
};
static
void
do_function
(
void
*
arguments
)
static
void
do_function
(
void
*
arguments
)
{
{
char
name
[
NAME_MAX
+
1
];
char
name
[
NAME_MAX
+
1
];
struct
thread_args
*
args
=
arguments
;
struct
thread_args
*
args
=
arguments
;
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
sprintf
(
name
,
"lxc-test-concurrent-%d"
,
args
->
thread_id
);
sprintf
(
name
,
"lxc-test-concurrent-%d"
,
args
->
thread_id
);
args
->
return_code
=
1
;
args
->
return_code
=
1
;
c
=
lxc_container_new
(
name
,
NULL
);
if
(
!
c
)
{
c
=
lxc_container_new
(
name
,
NULL
);
fprintf
(
stderr
,
"Unable to instantiate container (%s)
\n
"
,
name
);
if
(
!
c
)
{
return
;
fprintf
(
stderr
,
"Unable to instantiate container (%s)
\n
"
,
name
);
}
return
;
}
if
(
debug
)
c
->
set_config_item
(
c
,
"lxc.log.level"
,
"DEBUG"
);
if
(
debug
)
c
->
set_config_item
(
c
,
"lxc.log.level"
,
"DEBUG"
);
if
(
strcmp
(
args
->
mode
,
"create"
)
==
0
)
{
if
(
!
c
->
is_defined
(
c
))
{
if
(
strcmp
(
args
->
mode
,
"create"
)
==
0
)
{
if
(
!
c
->
create
(
c
,
template
,
NULL
,
NULL
,
1
,
NULL
))
{
if
(
!
c
->
is_defined
(
c
))
{
fprintf
(
stderr
,
"Creating the container (%s) failed...
\n
"
,
name
);
if
(
!
c
->
create
(
c
,
template
,
NULL
,
NULL
,
1
,
NULL
))
{
goto
out
;
fprintf
(
stderr
,
"Creating the container (%s) failed...
\n
"
,
name
);
}
goto
out
;
}
}
}
else
if
(
strcmp
(
args
->
mode
,
"start"
)
==
0
)
{
}
if
(
c
->
is_defined
(
c
)
&&
!
c
->
is_running
(
c
))
{
}
else
if
(
strcmp
(
args
->
mode
,
"start"
)
==
0
)
{
c
->
want_daemonize
(
c
,
true
);
if
(
c
->
is_defined
(
c
)
&&
!
c
->
is_running
(
c
))
{
if
(
!
c
->
start
(
c
,
false
,
NULL
))
{
c
->
want_daemonize
(
c
,
true
);
fprintf
(
stderr
,
"Starting the container (%s) failed...
\n
"
,
name
);
goto
out
;
if
(
!
c
->
start
(
c
,
false
,
NULL
))
{
}
fprintf
(
stderr
,
"Starting the container (%s) failed...
\n
"
,
name
);
if
(
!
c
->
wait
(
c
,
"RUNNING"
,
15
))
{
goto
out
;
fprintf
(
stderr
,
"Waiting the container (%s) to start failed...
\n
"
,
name
);
}
goto
out
;
}
if
(
!
c
->
wait
(
c
,
"RUNNING"
,
15
))
{
sleep
(
delay
);
fprintf
(
stderr
,
"Waiting the container (%s) to start failed...
\n
"
,
name
);
}
goto
out
;
}
else
if
(
strcmp
(
args
->
mode
,
"stop"
)
==
0
)
{
}
if
(
c
->
is_defined
(
c
)
&&
c
->
is_running
(
c
))
{
if
(
!
c
->
stop
(
c
))
{
sleep
(
delay
);
fprintf
(
stderr
,
"Stopping the container (%s) failed...
\n
"
,
name
);
}
goto
out
;
}
else
if
(
strcmp
(
args
->
mode
,
"stop"
)
==
0
)
{
}
if
(
c
->
is_defined
(
c
)
&&
c
->
is_running
(
c
))
{
if
(
!
c
->
wait
(
c
,
"STOPPED"
,
15
))
{
if
(
!
c
->
stop
(
c
))
{
fprintf
(
stderr
,
"Waiting the container (%s) to stop failed...
\n
"
,
name
);
fprintf
(
stderr
,
"Stopping the container (%s) failed...
\n
"
,
name
);
goto
out
;
goto
out
;
}
}
}
}
else
if
(
strcmp
(
args
->
mode
,
"destroy"
)
==
0
)
{
if
(
!
c
->
wait
(
c
,
"STOPPED"
,
15
))
{
if
(
c
->
is_defined
(
c
)
&&
!
c
->
is_running
(
c
))
{
fprintf
(
stderr
,
"Waiting the container (%s) to stop failed...
\n
"
,
name
);
if
(
!
c
->
destroy
(
c
))
{
goto
out
;
fprintf
(
stderr
,
"Destroying the container (%s) failed...
\n
"
,
name
);
}
goto
out
;
}
}
}
else
if
(
strcmp
(
args
->
mode
,
"destroy"
)
==
0
)
{
}
if
(
c
->
is_defined
(
c
)
&&
!
c
->
is_running
(
c
))
{
}
if
(
!
c
->
destroy
(
c
))
{
args
->
return_code
=
0
;
fprintf
(
stderr
,
"Destroying the container (%s) failed...
\n
"
,
name
);
goto
out
;
}
}
}
args
->
return_code
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
debug
)
lxc_log_close
();
if
(
debug
)
lxc_log_close
();
}
}
static
void
*
concurrent
(
void
*
arguments
)
static
void
*
concurrent
(
void
*
arguments
)
{
{
do_function
(
arguments
);
do_function
(
arguments
);
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
return
NULL
;
return
NULL
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
,
j
,
iter
,
opt
;
int
i
,
j
,
iter
,
opt
;
pthread_attr_t
attr
;
pthread_attr_t
attr
;
pthread_t
*
threads
;
pthread_t
*
threads
;
struct
thread_args
*
args
;
struct
thread_args
*
args
;
char
*
modes_default
[]
=
{
"create"
,
"start"
,
"stop"
,
"destroy"
,
NULL
};
char
*
modes_default
[]
=
{
"create"
,
"start"
,
"stop"
,
"destroy"
,
NULL
};
char
**
modes
=
modes_default
;
char
**
modes
=
modes_default
;
pthread_attr_init
(
&
attr
);
pthread_attr_init
(
&
attr
);
while
((
opt
=
getopt_long
(
argc
,
argv
,
"j:i:t:d:m:qD"
,
options
,
NULL
))
!=
-
1
)
{
while
((
opt
=
getopt_long
(
argc
,
argv
,
"j:i:t:d:m:qD"
,
options
,
NULL
))
!=
-
1
)
{
switch
(
opt
)
{
switch
(
opt
)
{
case
'j'
:
case
'j'
:
nthreads
=
atoi
(
optarg
);
nthreads
=
atoi
(
optarg
);
break
;
break
;
case
'i'
:
case
'i'
:
iterations
=
atoi
(
optarg
);
iterations
=
atoi
(
optarg
);
break
;
break
;
case
't'
:
case
't'
:
template
=
optarg
;
template
=
optarg
;
break
;
break
;
case
'd'
:
case
'd'
:
delay
=
atoi
(
optarg
);
delay
=
atoi
(
optarg
);
break
;
break
;
case
'q'
:
case
'q'
:
quiet
=
1
;
quiet
=
1
;
break
;
break
;
case
'D'
:
case
'D'
:
debug
=
1
;
debug
=
1
;
break
;
break
;
case
'm'
:
{
case
'm'
:
{
char
*
mode_tok
,
*
tok
,
*
saveptr
=
NULL
;
char
*
mode_tok
,
*
tok
,
*
saveptr
=
NULL
;
if
(
!
optarg
)
if
(
!
optarg
)
continue
;
continue
;
modes
=
NULL
;
modes
=
NULL
;
for
(
i
=
0
,
mode_tok
=
optarg
;
for
(
i
=
0
,
mode_tok
=
optarg
;
(
tok
=
strtok_r
(
mode_tok
,
","
,
&
saveptr
));
(
tok
=
strtok_r
(
mode_tok
,
","
,
&
saveptr
));
i
++
,
mode_tok
=
NULL
)
{
i
++
,
mode_tok
=
NULL
)
{
modes
=
realloc
(
modes
,
sizeof
(
*
modes
)
*
(
i
+
2
));
modes
=
realloc
(
modes
,
sizeof
(
*
modes
)
*
(
i
+
2
));
if
(
!
modes
)
{
if
(
!
modes
)
{
perror
(
"realloc"
);
perror
(
"realloc"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
modes
[
i
]
=
tok
;
modes
[
i
]
=
tok
;
}
}
if
(
modes
)
modes
[
i
]
=
NULL
;
if
(
modes
)
break
;
modes
[
i
]
=
NULL
;
}
break
;
default:
/* '?' */
}
usage
();
default:
/* '?' */
exit
(
EXIT_FAILURE
);
usage
();
}
exit
(
EXIT_FAILURE
);
}
}
}
threads
=
malloc
(
sizeof
(
*
threads
)
*
nthreads
);
args
=
malloc
(
sizeof
(
*
args
)
*
nthreads
);
threads
=
malloc
(
sizeof
(
*
threads
)
*
nthreads
);
if
(
threads
==
NULL
||
args
==
NULL
)
{
args
=
malloc
(
sizeof
(
*
args
)
*
nthreads
);
fprintf
(
stderr
,
"Unable malloc enough memory for %d threads
\n
"
,
nthreads
);
if
(
threads
==
NULL
||
args
==
NULL
)
{
exit
(
EXIT_FAILURE
);
fprintf
(
stderr
,
"Unable malloc enough memory for %d threads
\n
"
,
nthreads
);
}
exit
(
EXIT_FAILURE
);
}
for
(
iter
=
1
;
iter
<=
iterations
;
iter
++
)
{
int
fd
;
for
(
iter
=
1
;
iter
<=
iterations
;
iter
++
)
{
fd
=
open
(
"/"
,
O_RDONLY
);
int
fd
;
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Failed to open /
\n
"
);
fd
=
open
(
"/"
,
O_RDONLY
);
continue
;
if
(
fd
<
0
)
{
}
fprintf
(
stderr
,
"Failed to open /
\n
"
);
continue
;
if
(
!
quiet
)
}
printf
(
"
\n
Iteration %d/%d maxfd:%d
\n
"
,
iter
,
iterations
,
fd
);
close
(
fd
);
if
(
!
quiet
)
printf
(
"
\n
Iteration %d/%d maxfd:%d
\n
"
,
iter
,
iterations
,
fd
);
for
(
i
=
0
;
modes
[
i
];
i
++
)
{
if
(
!
quiet
)
close
(
fd
);
printf
(
"Executing (%s) for %d containers...
\n
"
,
modes
[
i
],
nthreads
);
for
(
j
=
0
;
j
<
nthreads
;
j
++
)
{
for
(
i
=
0
;
modes
[
i
];
i
++
)
{
args
[
j
].
thread_id
=
j
;
if
(
!
quiet
)
args
[
j
].
mode
=
modes
[
i
];
printf
(
"Executing (%s) for %d containers...
\n
"
,
modes
[
i
],
nthreads
);
if
(
nthreads
>
1
)
{
for
(
j
=
0
;
j
<
nthreads
;
j
++
)
{
if
(
pthread_create
(
&
threads
[
j
],
&
attr
,
concurrent
,
(
void
*
)
&
args
[
j
])
!=
0
)
{
args
[
j
].
thread_id
=
j
;
perror
(
"pthread_create() error"
);
args
[
j
].
mode
=
modes
[
i
];
exit
(
EXIT_FAILURE
);
}
if
(
nthreads
>
1
)
{
}
else
{
if
(
pthread_create
(
&
threads
[
j
],
&
attr
,
concurrent
,
(
void
*
)
&
args
[
j
])
!=
0
)
{
do_function
(
&
args
[
j
]);
perror
(
"pthread_create() error"
);
}
exit
(
EXIT_FAILURE
);
}
}
}
else
{
for
(
j
=
0
;
j
<
nthreads
;
j
++
)
{
do_function
(
&
args
[
j
]);
if
(
nthreads
>
1
)
{
}
if
(
pthread_join
(
threads
[
j
],
NULL
)
!=
0
)
{
}
perror
(
"pthread_join() error"
);
exit
(
EXIT_FAILURE
);
for
(
j
=
0
;
j
<
nthreads
;
j
++
)
{
}
if
(
nthreads
>
1
)
{
}
if
(
pthread_join
(
threads
[
j
],
NULL
)
!=
0
)
{
if
(
args
[
j
].
return_code
)
{
perror
(
"pthread_join() error"
);
fprintf
(
stderr
,
"thread returned error %d
\n
"
,
args
[
j
].
return_code
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
}
}
}
if
(
args
[
j
].
return_code
)
{
}
fprintf
(
stderr
,
"thread returned error %d
\n
"
,
args
[
j
].
return_code
);
exit
(
EXIT_FAILURE
);
free
(
args
);
}
free
(
threads
);
}
pthread_attr_destroy
(
&
attr
);
}
exit
(
EXIT_SUCCESS
);
}
free
(
args
);
free
(
threads
);
pthread_attr_destroy
(
&
attr
);
exit
(
EXIT_SUCCESS
);
}
}
src/tests/config_jump_table.c
View file @
9b937486
...
@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
...
@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
for
(
key
=
strtok_r
(
keys
,
"
\n
"
,
&
saveptr
);
key
!=
NULL
;
for
(
key
=
strtok_r
(
keys
,
"
\n
"
,
&
saveptr
);
key
!=
NULL
;
key
=
strtok_r
(
NULL
,
"
\n
"
,
&
saveptr
))
{
key
=
strtok_r
(
NULL
,
"
\n
"
,
&
saveptr
))
{
struct
lxc_config_t
*
config
;
struct
lxc_config_t
*
config
;
config
=
lxc_get_config
(
key
);
config
=
lxc_get_config
(
key
);
if
(
!
config
)
{
if
(
!
config
)
{
lxc_error
(
"configuration key
\"
%s
\"
not implemented in "
lxc_error
(
"configuration key
\"
%s
\"
not implemented in "
...
@@ -90,5 +91,4 @@ on_error:
...
@@ -90,5 +91,4 @@ on_error:
free
(
keys
);
free
(
keys
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/console.c
View file @
9b937486
...
@@ -46,6 +46,7 @@ static void test_console_close_all(int ttyfd[MAXCONSOLES],
...
@@ -46,6 +46,7 @@ static void test_console_close_all(int ttyfd[MAXCONSOLES],
close
(
masterfd
[
i
]);
close
(
masterfd
[
i
]);
masterfd
[
i
]
=
-
1
;
masterfd
[
i
]
=
-
1
;
}
}
if
(
ttyfd
[
i
]
!=
-
1
)
{
if
(
ttyfd
[
i
]
!=
-
1
)
{
close
(
ttyfd
[
i
]);
close
(
ttyfd
[
i
]);
ttyfd
[
i
]
=
-
1
;
ttyfd
[
i
]
=
-
1
;
...
@@ -64,11 +65,13 @@ static int test_console_running_container(struct lxc_container *c)
...
@@ -64,11 +65,13 @@ static int test_console_running_container(struct lxc_container *c)
ttynum
[
i
]
=
ttyfd
[
i
]
=
masterfd
[
i
]
=
-
1
;
ttynum
[
i
]
=
ttyfd
[
i
]
=
masterfd
[
i
]
=
-
1
;
ttynum
[
0
]
=
1
;
ttynum
[
0
]
=
1
;
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
masterfd
[
0
]);
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
masterfd
[
0
]);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
TSTERR
(
"console allocate failed"
);
TSTERR
(
"console allocate failed"
);
goto
err1
;
goto
err1
;
}
}
ttyfd
[
0
]
=
ret
;
ttyfd
[
0
]
=
ret
;
if
(
ttynum
[
0
]
!=
1
)
{
if
(
ttynum
[
0
]
!=
1
)
{
TSTERR
(
"console allocate got bad ttynum %d"
,
ttynum
[
0
]);
TSTERR
(
"console allocate got bad ttynum %d"
,
ttynum
[
0
]);
...
@@ -94,16 +97,20 @@ static int test_console_running_container(struct lxc_container *c)
...
@@ -94,16 +97,20 @@ static int test_console_running_container(struct lxc_container *c)
break
;
break
;
ttyfd
[
nrconsoles
]
=
ret
;
ttyfd
[
nrconsoles
]
=
ret
;
}
}
if
(
nrconsoles
!=
TTYCNT
)
{
if
(
nrconsoles
!=
TTYCNT
)
{
TSTERR
(
"didn't allocate all consoles %d != %d"
,
nrconsoles
,
TTYCNT
);
TSTERR
(
"didn't allocate all consoles %d != %d"
,
nrconsoles
,
TTYCNT
);
goto
err2
;
goto
err2
;
}
}
test_console_close_all
(
ttyfd
,
masterfd
);
test_console_close_all
(
ttyfd
,
masterfd
);
}
}
ret
=
0
;
ret
=
0
;
err2:
err2:
test_console_close_all
(
ttyfd
,
masterfd
);
test_console_close_all
(
ttyfd
,
masterfd
);
err1:
err1:
return
ret
;
return
ret
;
}
}
...
@@ -135,20 +142,24 @@ static int test_console(const char *lxcpath,
...
@@ -135,20 +142,24 @@ static int test_console(const char *lxcpath,
TSTERR
(
"instantiating container %s"
,
name
);
TSTERR
(
"instantiating container %s"
,
name
);
goto
out1
;
goto
out1
;
}
}
if
(
c
->
is_defined
(
c
))
{
if
(
c
->
is_defined
(
c
))
{
c
->
stop
(
c
);
c
->
stop
(
c
);
c
->
destroy
(
c
);
c
->
destroy
(
c
);
c
=
lxc_container_new
(
name
,
lxcpath
);
c
=
lxc_container_new
(
name
,
lxcpath
);
}
}
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
TSTERR
(
"creating container %s"
,
name
);
TSTERR
(
"creating container %s"
,
name
);
goto
out2
;
goto
out2
;
}
}
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
c
->
set_config_item
(
c
,
"lxc.tty.max"
,
TTYCNT_STR
);
c
->
set_config_item
(
c
,
"lxc.tty.max"
,
TTYCNT_STR
);
c
->
set_config_item
(
c
,
"lxc.pty.max"
,
"1024"
);
c
->
set_config_item
(
c
,
"lxc.pty.max"
,
"1024"
);
c
->
save_config
(
c
,
NULL
);
c
->
save_config
(
c
,
NULL
);
c
->
want_daemonize
(
c
,
true
);
c
->
want_daemonize
(
c
,
true
);
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
TSTERR
(
"starting container %s"
,
name
);
TSTERR
(
"starting container %s"
,
name
);
goto
out3
;
goto
out3
;
...
@@ -157,10 +168,13 @@ static int test_console(const char *lxcpath,
...
@@ -157,10 +168,13 @@ static int test_console(const char *lxcpath,
ret
=
test_console_running_container
(
c
);
ret
=
test_console_running_container
(
c
);
c
->
stop
(
c
);
c
->
stop
(
c
);
out3:
out3:
c
->
destroy
(
c
);
c
->
destroy
(
c
);
out2:
out2:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
out1:
out1:
return
ret
;
return
ret
;
}
}
...
@@ -168,6 +182,7 @@ out1:
...
@@ -168,6 +182,7 @@ out1:
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
ret
;
int
ret
;
ret
=
test_console
(
NULL
,
NULL
,
TSTNAME
,
"busybox"
);
ret
=
test_console
(
NULL
,
NULL
,
TSTNAME
,
"busybox"
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
err1
;
goto
err1
;
...
@@ -175,7 +190,9 @@ int main(int argc, char *argv[])
...
@@ -175,7 +190,9 @@ int main(int argc, char *argv[])
ret
=
test_console
(
"/var/lib/lxctest2"
,
NULL
,
TSTNAME
,
"busybox"
);
ret
=
test_console
(
"/var/lib/lxctest2"
,
NULL
,
TSTNAME
,
"busybox"
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
err1
;
goto
err1
;
printf
(
"All tests passed
\n
"
);
printf
(
"All tests passed
\n
"
);
err1:
err1:
return
ret
;
return
ret
;
}
}
src/tests/containertests.c
View file @
9b937486
...
@@ -39,10 +39,12 @@ static int destroy_busybox(void)
...
@@ -39,10 +39,12 @@ static int destroy_busybox(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -51,12 +53,15 @@ again:
...
@@ -51,12 +53,15 @@ again:
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -69,10 +74,12 @@ static int create_busybox(void)
...
@@ -69,10 +74,12 @@ static int create_busybox(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -81,12 +88,15 @@ again:
...
@@ -81,12 +88,15 @@ again:
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -99,25 +109,30 @@ int main(int argc, char *argv[])
...
@@ -99,25 +109,30 @@ int main(int argc, char *argv[])
char
*
str
;
char
*
str
;
ret
=
1
;
ret
=
1
;
/* test refcounting */
/* test refcounting */
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"%d: error creating lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error creating lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
}
}
if
(
!
lxc_container_get
(
c
))
{
if
(
!
lxc_container_get
(
c
))
{
fprintf
(
stderr
,
"%d: error getting refcount
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: error getting refcount
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
/* peek in, inappropriately, make sure refcount is a we'd like */
/* peek in, inappropriately, make sure refcount is a we'd like */
if
(
c
->
numthreads
!=
2
)
{
if
(
c
->
numthreads
!=
2
)
{
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
2
);
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
2
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
c
->
name
,
MYNAME
)
!=
0
)
{
if
(
strcmp
(
c
->
name
,
MYNAME
)
!=
0
)
{
fprintf
(
stderr
,
"%d: container has wrong name (%s not %s)
\n
"
,
__LINE__
,
c
->
name
,
MYNAME
);
fprintf
(
stderr
,
"%d: container has wrong name (%s not %s)
\n
"
,
__LINE__
,
c
->
name
,
MYNAME
);
goto
out
;
goto
out
;
}
}
str
=
c
->
config_file_name
(
c
);
str
=
c
->
config_file_name
(
c
);
#define CONFIGFNAM LXCPATH "/" MYNAME "/config"
#define CONFIGFNAM LXCPATH "/" MYNAME "/config"
if
(
!
str
||
strcmp
(
str
,
CONFIGFNAM
))
{
if
(
!
str
||
strcmp
(
str
,
CONFIGFNAM
))
{
...
@@ -127,19 +142,23 @@ int main(int argc, char *argv[])
...
@@ -127,19 +142,23 @@ int main(int argc, char *argv[])
free
(
str
);
free
(
str
);
free
(
c
->
configfile
);
free
(
c
->
configfile
);
c
->
configfile
=
NULL
;
c
->
configfile
=
NULL
;
str
=
c
->
config_file_name
(
c
);
str
=
c
->
config_file_name
(
c
);
if
(
str
)
{
if
(
str
)
{
fprintf
(
stderr
,
"%d: config file name was not NULL as it should have been
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: config file name was not NULL as it should have been
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
lxc_container_put
(
c
)
!=
0
)
{
if
(
lxc_container_put
(
c
)
!=
0
)
{
fprintf
(
stderr
,
"%d: c was freed on non-final put
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: c was freed on non-final put
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
c
->
numthreads
!=
1
)
{
if
(
c
->
numthreads
!=
1
)
{
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
1
);
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
1
);
goto
out
;
goto
out
;
}
}
if
(
lxc_container_put
(
c
)
!=
1
)
{
if
(
lxc_container_put
(
c
)
!=
1
)
{
fprintf
(
stderr
,
"%d: c was not freed on final put
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: c was not freed on final put
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -202,9 +221,11 @@ int main(int argc, char *argv[])
...
@@ -202,9 +221,11 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: lxc_get_wait_states gave %d not %d
\n
"
,
__LINE__
,
numstates
,
MAX_STATE
);
fprintf
(
stderr
,
"%d: lxc_get_wait_states gave %d not %d
\n
"
,
__LINE__
,
numstates
,
MAX_STATE
);
goto
out
;
goto
out
;
}
}
const
char
**
sstr
=
malloc
(
numstates
*
sizeof
(
const
char
*
));
const
char
**
sstr
=
malloc
(
numstates
*
sizeof
(
const
char
*
));
numstates
=
lxc_get_wait_states
(
sstr
);
numstates
=
lxc_get_wait_states
(
sstr
);
int
i
;
int
i
;
for
(
i
=
0
;
i
<
numstates
;
i
++
)
{
for
(
i
=
0
;
i
<
numstates
;
i
++
)
{
fprintf
(
stderr
,
"got state %d %s
\n
"
,
i
,
sstr
[
i
]);
fprintf
(
stderr
,
"got state %d %s
\n
"
,
i
,
sstr
[
i
]);
}
}
...
@@ -237,6 +258,7 @@ out:
...
@@ -237,6 +258,7 @@ out:
c
->
stop
(
c
);
c
->
stop
(
c
);
destroy_busybox
();
destroy_busybox
();
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/createtest.c
View file @
9b937486
...
@@ -48,8 +48,10 @@ int main(int argc, char *argv[])
...
@@ -48,8 +48,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -63,6 +65,7 @@ int main(int argc, char *argv[])
...
@@ -63,6 +65,7 @@ int main(int argc, char *argv[])
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
c
->
want_daemonize
(
c
,
true
);
c
->
want_daemonize
(
c
,
true
);
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
...
@@ -85,6 +88,7 @@ int main(int argc, char *argv[])
...
@@ -85,6 +88,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/criu_check_feature.c
View file @
9b937486
...
@@ -86,5 +86,6 @@ on_error_put:
...
@@ -86,5 +86,6 @@ on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All criu feature check tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All criu feature check tests passed"
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/destroytest.c
View file @
9b937486
...
@@ -37,24 +37,30 @@ static int create_container(void)
...
@@ -37,24 +37,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -96,6 +102,7 @@ int main(int argc, char *argv[])
...
@@ -96,6 +102,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/device_add_remove.c
View file @
9b937486
...
@@ -50,6 +50,7 @@ int main(int argc, char *argv[])
...
@@ -50,6 +50,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"Adding %s to the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
fprintf
(
stderr
,
"Adding %s to the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
remove_device_node
(
c
,
DEVICE
,
DEVICE
))
{
if
(
!
c
->
remove_device_node
(
c
,
DEVICE
,
DEVICE
))
{
fprintf
(
stderr
,
"Removing %s from the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
fprintf
(
stderr
,
"Removing %s from the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
goto
out
;
goto
out
;
...
@@ -64,6 +65,7 @@ int main(int argc, char *argv[])
...
@@ -64,6 +65,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"Destroying the container (%s) failed...
\n
"
,
NAME
);
fprintf
(
stderr
,
"Destroying the container (%s) failed...
\n
"
,
NAME
);
goto
out
;
goto
out
;
}
}
ret
=
0
;
ret
=
0
;
out:
out:
...
...
src/tests/get_item.c
View file @
9b937486
...
@@ -49,11 +49,13 @@ int main(int argc, char *argv[])
...
@@ -49,11 +49,13 @@ int main(int argc, char *argv[])
lxc_error
(
"%s
\n
"
,
"Failed to set lxc.log.syslog.
\n
"
);
lxc_error
(
"%s
\n
"
,
"Failed to set lxc.log.syslog.
\n
"
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.log.syslog"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.log.syslog"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
lxc_error
(
"Failed to retrieve lxc.log.syslog: %d.
\n
"
,
ret
);
lxc_error
(
"Failed to retrieve lxc.log.syslog: %d.
\n
"
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"local0"
)
!=
0
)
{
if
(
strcmp
(
v2
,
"local0"
)
!=
0
)
{
lxc_error
(
"Expected: local0 == %s.
\n
"
,
v2
);
lxc_error
(
"Expected: local0 == %s.
\n
"
,
v2
);
goto
out
;
goto
out
;
...
@@ -71,6 +73,7 @@ int main(int argc, char *argv[])
...
@@ -71,6 +73,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set hook.pre-start
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set hook.pre-start
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.hook.pre-start"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.hook.pre-start"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.hook.pre-start) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.hook.pre-start) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -89,6 +92,7 @@ int main(int argc, char *argv[])
...
@@ -89,6 +92,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set tty
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set tty
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.tty.max"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.tty.max"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.tty) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.tty) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -100,6 +104,7 @@ int main(int argc, char *argv[])
...
@@ -100,6 +104,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set arch
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set arch
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.arch"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.arch"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.arch) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.arch) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -111,6 +116,7 @@ int main(int argc, char *argv[])
...
@@ -111,6 +116,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set init_uid
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set init_uid
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.init.uid"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.init.uid"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_uid) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_uid) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -122,6 +128,7 @@ int main(int argc, char *argv[])
...
@@ -122,6 +128,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set init_gid
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set init_gid
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.init.gid"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.init.gid"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_gid) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.init_gid) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -132,12 +139,13 @@ int main(int argc, char *argv[])
...
@@ -132,12 +139,13 @@ int main(int argc, char *argv[])
#define HNAME "hostname1"
#define HNAME "hostname1"
// demonstrate proper usage:
// demonstrate proper usage:
char
*
alloced
;
char
*
alloced
;
int
len
;
if
(
!
c
->
set_config_item
(
c
,
"lxc.uts.name"
,
HNAME
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.uts.name"
,
HNAME
))
{
fprintf
(
stderr
,
"%d: failed to set utsname
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set utsname
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
int
len
;
len
=
c
->
get_config_item
(
c
,
"lxc.uts.name"
,
NULL
,
0
);
// query the size of the string
len
=
c
->
get_config_item
(
c
,
"lxc.uts.name"
,
NULL
,
0
);
// query the size of the string
if
(
len
<
0
)
{
if
(
len
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
len
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
len
);
...
@@ -151,6 +159,7 @@ int main(int argc, char *argv[])
...
@@ -151,6 +159,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to allocate %d bytes for utsname
\n
"
,
__LINE__
,
len
);
fprintf
(
stderr
,
"%d: failed to allocate %d bytes for utsname
\n
"
,
__LINE__
,
len
);
goto
out
;
goto
out
;
}
}
// now pass in the malloc'd array, and pass in length of string + 1: again
// now pass in the malloc'd array, and pass in length of string + 1: again
// because we need room for the trailing \0
// because we need room for the trailing \0
ret
=
c
->
get_config_item
(
c
,
"lxc.uts.name"
,
alloced
,
len
+
1
);
ret
=
c
->
get_config_item
(
c
,
"lxc.uts.name"
,
alloced
,
len
+
1
);
...
@@ -158,6 +167,7 @@ int main(int argc, char *argv[])
...
@@ -158,6 +167,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.utsname) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
alloced
,
HNAME
)
!=
0
||
ret
!=
len
)
{
if
(
strcmp
(
alloced
,
HNAME
)
!=
0
||
ret
!=
len
)
{
fprintf
(
stderr
,
"lxc.utsname returned wrong value: %d %s not %d %s
\n
"
,
ret
,
alloced
,
len
,
HNAME
);
fprintf
(
stderr
,
"lxc.utsname returned wrong value: %d %s not %d %s
\n
"
,
ret
,
alloced
,
len
,
HNAME
);
goto
out
;
goto
out
;
...
@@ -169,6 +179,7 @@ int main(int argc, char *argv[])
...
@@ -169,6 +179,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set mount.entry
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set mount.entry
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.mount.entry"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.mount.entry"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.mount.entry) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.mount.entry) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -186,11 +197,13 @@ int main(int argc, char *argv[])
...
@@ -186,11 +197,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set limit.nofile
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set limit.nofile
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.prlimit.nofile"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.prlimit.nofile"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.prlimit.nofile) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.prlimit.nofile) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"1234:unlimited"
))
{
if
(
strcmp
(
v2
,
"1234:unlimited"
))
{
fprintf
(
stderr
,
"%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
...
@@ -201,11 +214,13 @@ int main(int argc, char *argv[])
...
@@ -201,11 +214,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set limit.stack
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set limit.stack
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.prlimit.stack"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.prlimit.stack"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.prlimit.stack) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.prlimit.stack) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"unlimited"
))
{
if
(
strcmp
(
v2
,
"unlimited"
))
{
fprintf
(
stderr
,
"%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
...
@@ -219,6 +234,7 @@ int main(int argc, char *argv[])
...
@@ -219,6 +234,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(limit) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(limit) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v3
,
ALL_LIMITS
))
{
if
(
strcmp
(
v3
,
ALL_LIMITS
))
{
fprintf
(
stderr
,
"%d: lxc.prlimit returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
ALL_LIMITS
)
-
1
,
ALL_LIMITS
);
fprintf
(
stderr
,
"%d: lxc.prlimit returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
ALL_LIMITS
)
-
1
,
ALL_LIMITS
);
goto
out
;
goto
out
;
...
@@ -229,11 +245,13 @@ int main(int argc, char *argv[])
...
@@ -229,11 +245,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed clearing limit.nofile
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing limit.nofile
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.prlimit"
,
v3
,
2047
);
ret
=
c
->
get_config_item
(
c
,
"lxc.prlimit"
,
v3
,
2047
);
if
(
ret
!=
sizeof
(
LIMIT_STACK
)
-
1
)
{
if
(
ret
!=
sizeof
(
LIMIT_STACK
)
-
1
)
{
fprintf
(
stderr
,
"%d: get_config_item(limit) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(limit) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v3
,
LIMIT_STACK
))
{
if
(
strcmp
(
v3
,
LIMIT_STACK
))
{
fprintf
(
stderr
,
"%d: lxc.prlimit returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
LIMIT_STACK
)
-
1
,
LIMIT_STACK
);
fprintf
(
stderr
,
"%d: lxc.prlimit returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
LIMIT_STACK
)
-
1
,
LIMIT_STACK
);
goto
out
;
goto
out
;
...
@@ -253,11 +271,13 @@ int main(int argc, char *argv[])
...
@@ -253,11 +271,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set lxc.sysctl.net.ipv4.ip_forward
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set lxc.sysctl.net.ipv4.ip_forward
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.sysctl.net.ipv4.ip_forward"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.sysctl.net.ipv4.ip_forward"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"1"
))
{
if
(
strcmp
(
v2
,
"1"
))
{
fprintf
(
stderr
,
"%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
...
@@ -268,11 +288,13 @@ int main(int argc, char *argv[])
...
@@ -268,11 +288,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set lxc.sysctl.net.core.somaxconn
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set lxc.sysctl.net.core.somaxconn
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.sysctl.net.core.somaxconn"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.sysctl.net.core.somaxconn"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"256"
))
{
if
(
strcmp
(
v2
,
"256"
))
{
fprintf
(
stderr
,
"%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
...
@@ -284,6 +306,7 @@ int main(int argc, char *argv[])
...
@@ -284,6 +306,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(sysctl) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(sysctl) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v3
,
ALL_SYSCTLS
))
{
if
(
strcmp
(
v3
,
ALL_SYSCTLS
))
{
fprintf
(
stderr
,
"%d: lxc.sysctl returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
ALL_SYSCTLS
)
-
1
,
ALL_SYSCTLS
);
fprintf
(
stderr
,
"%d: lxc.sysctl returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
ALL_SYSCTLS
)
-
1
,
ALL_SYSCTLS
);
goto
out
;
goto
out
;
...
@@ -294,11 +317,13 @@ int main(int argc, char *argv[])
...
@@ -294,11 +317,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed clearing lxc.sysctl.net.ipv4.ip_forward
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.sysctl.net.ipv4.ip_forward
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.sysctl"
,
v3
,
2047
);
ret
=
c
->
get_config_item
(
c
,
"lxc.sysctl"
,
v3
,
2047
);
if
(
ret
!=
sizeof
(
SYSCTL_SOMAXCONN
)
-
1
)
{
if
(
ret
!=
sizeof
(
SYSCTL_SOMAXCONN
)
-
1
)
{
fprintf
(
stderr
,
"%d: get_config_item(sysctl) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(sysctl) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v3
,
SYSCTL_SOMAXCONN
))
{
if
(
strcmp
(
v3
,
SYSCTL_SOMAXCONN
))
{
fprintf
(
stderr
,
"%d: lxc.sysctl returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
SYSCTL_SOMAXCONN
)
-
1
,
SYSCTL_SOMAXCONN
);
fprintf
(
stderr
,
"%d: lxc.sysctl returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
SYSCTL_SOMAXCONN
)
-
1
,
SYSCTL_SOMAXCONN
);
goto
out
;
goto
out
;
...
@@ -324,6 +349,7 @@ int main(int argc, char *argv[])
...
@@ -324,6 +349,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(lxc.proc.setgroups) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.proc.setgroups) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"allow"
))
{
if
(
strcmp
(
v2
,
"allow"
))
{
fprintf
(
stderr
,
"%d: lxc.proc.setgroups returned wrong value: %d %s not 10
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: lxc.proc.setgroups returned wrong value: %d %s not 10
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
...
@@ -340,6 +366,7 @@ int main(int argc, char *argv[])
...
@@ -340,6 +366,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(lxc.proc.oom_score_adj) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.proc.oom_score_adj) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v2
,
"10"
))
{
if
(
strcmp
(
v2
,
"10"
))
{
fprintf
(
stderr
,
"%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
...
@@ -351,6 +378,7 @@ int main(int argc, char *argv[])
...
@@ -351,6 +378,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(proc) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(proc) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v3
,
ALL_PROCS
))
{
if
(
strcmp
(
v3
,
ALL_PROCS
))
{
fprintf
(
stderr
,
"%d: lxc.proc returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
ALL_PROCS
)
-
1
,
ALL_PROCS
);
fprintf
(
stderr
,
"%d: lxc.proc returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
ALL_PROCS
)
-
1
,
ALL_PROCS
);
goto
out
;
goto
out
;
...
@@ -361,11 +389,13 @@ int main(int argc, char *argv[])
...
@@ -361,11 +389,13 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed clearing lxc.proc.setgroups
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.proc.setgroups
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.proc"
,
v3
,
2047
);
ret
=
c
->
get_config_item
(
c
,
"lxc.proc"
,
v3
,
2047
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(proc) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(proc) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
v3
,
PROC_OOM_SCORE_ADJ
))
{
if
(
strcmp
(
v3
,
PROC_OOM_SCORE_ADJ
))
{
fprintf
(
stderr
,
"%d: lxc.proc returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
PROC_OOM_SCORE_ADJ
)
-
1
,
PROC_OOM_SCORE_ADJ
);
fprintf
(
stderr
,
"%d: lxc.proc returned wrong value: %d %s not %d %s
\n
"
,
__LINE__
,
ret
,
v3
,
(
int
)
sizeof
(
PROC_OOM_SCORE_ADJ
)
-
1
,
PROC_OOM_SCORE_ADJ
);
goto
out
;
goto
out
;
...
@@ -376,6 +406,7 @@ int main(int argc, char *argv[])
...
@@ -376,6 +406,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set aa_profile
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set aa_profile
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.apparmor.profile"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.apparmor.profile"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.aa_profile) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.aa_profile) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -397,6 +428,7 @@ int main(int argc, char *argv[])
...
@@ -397,6 +428,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error opening lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -414,17 +446,20 @@ int main(int argc, char *argv[])
...
@@ -414,17 +446,20 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) with NULL returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) with NULL returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v1
,
1
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v1
,
1
);
if
(
ret
<
5
||
ret
>
255
)
{
if
(
ret
<
5
||
ret
>
255
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.cap.drop"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
printf
(
"%d: get_config_item(lxc.cap.drop) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item(lxc.net) returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item(lxc.net) returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -436,18 +471,22 @@ int main(int argc, char *argv[])
...
@@ -436,18 +471,22 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set lxc.net.0.type
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set lxc.net.0.type
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
))
{
fprintf
(
stderr
,
"%d: failed to set network.link
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network.link
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
))
{
fprintf
(
stderr
,
"%d: failed to set network.flags
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network.flags
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.hwaddr"
,
"00:16:3e:xx:xx:xx"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.hwaddr"
,
"00:16:3e:xx:xx:xx"
))
{
fprintf
(
stderr
,
"%d: failed to set network.hwaddr
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network.hwaddr
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.ipv4.address"
,
"10.2.3.4"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.ipv4.address"
,
"10.2.3.4"
))
{
fprintf
(
stderr
,
"%d: failed to set ipv4
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set ipv4
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -458,10 +497,12 @@ int main(int argc, char *argv[])
...
@@ -458,10 +497,12 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: lxc.net.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: lxc.net.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.net.0.ipv4.address"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.net.0.ipv4.address"
))
{
fprintf
(
stderr
,
"%d: failed clearing all ipv4 entries
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing all ipv4 entries
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.net.0.ipv4.address"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net.0.ipv4.address"
,
v2
,
255
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -478,10 +519,12 @@ int main(int argc, char *argv[])
...
@@ -478,10 +519,12 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: lxc.net.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: lxc.net.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.ipv4.gateway"
,
""
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.ipv4.gateway"
,
""
))
{
fprintf
(
stderr
,
"%d: failed clearing ipv4.gateway
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing ipv4.gateway
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.net.0.ipv4.gateway"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net.0.ipv4.gateway"
,
v2
,
255
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -494,6 +537,7 @@ int main(int argc, char *argv[])
...
@@ -494,6 +537,7 @@ int main(int argc, char *argv[])
goto
out
;
goto
out
;
}
}
printf
(
"%d: get_config_item (link) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
printf
(
"%d: get_config_item (link) returned %d %s
\n
"
,
__LINE__
,
ret
,
v2
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net.0.name"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net.0.name"
,
v2
,
255
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: get_config_item returned %d
\n
"
,
__LINE__
,
ret
);
...
@@ -505,6 +549,7 @@ int main(int argc, char *argv[])
...
@@ -505,6 +549,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: clear_config_item failed
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: clear_config_item failed
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_config_item
(
c
,
"lxc.net"
,
v2
,
255
);
ret
=
c
->
get_config_item
(
c
,
"lxc.net"
,
v2
,
255
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: network was not actually cleared (get_network returned %d)
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: network was not actually cleared (get_network returned %d)
\n
"
,
__LINE__
,
ret
);
...
@@ -529,14 +574,17 @@ int main(int argc, char *argv[])
...
@@ -529,14 +574,17 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed clearing lxc.cgroup
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.cgroup
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.cap.drop"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.cap.drop"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.cap.drop
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.cap.drop
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.mount.entry"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.mount.entry"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.mount.entry
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.mount.entry
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
clear_config_item
(
c
,
"lxc.hook"
))
{
if
(
!
c
->
clear_config_item
(
c
,
"lxc.hook"
))
{
fprintf
(
stderr
,
"%d: failed clearing lxc.hook
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed clearing lxc.hook
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -554,6 +602,7 @@ int main(int argc, char *argv[])
...
@@ -554,6 +602,7 @@ int main(int argc, char *argv[])
printf
(
"All get_item tests passed
\n
"
);
printf
(
"All get_item tests passed
\n
"
);
fret
=
EXIT_SUCCESS
;
fret
=
EXIT_SUCCESS
;
out:
out:
if
(
c
)
{
if
(
c
)
{
c
->
destroy
(
c
);
c
->
destroy
(
c
);
...
...
src/tests/getkeys.c
View file @
9b937486
...
@@ -51,6 +51,7 @@ int main(int argc, char *argv[])
...
@@ -51,6 +51,7 @@ int main(int argc, char *argv[])
ret
=
1
;
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_keys
(
c
,
NULL
,
v3
,
len
+
1
);
ret
=
c
->
get_keys
(
c
,
NULL
,
v3
,
len
+
1
);
if
(
ret
!=
len
)
{
if
(
ret
!=
len
)
{
fprintf
(
stderr
,
"%d: failed to get keys (%d)
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: failed to get keys (%d)
\n
"
,
__LINE__
,
ret
);
...
...
src/tests/list.c
View file @
9b937486
...
@@ -31,17 +31,21 @@ static void test_list_func(const char *lxcpath, const char *type,
...
@@ -31,17 +31,21 @@ static void test_list_func(const char *lxcpath, const char *type,
char
**
names
;
char
**
names
;
printf
(
"%-10s Counting containers
\n
"
,
type
);
printf
(
"%-10s Counting containers
\n
"
,
type
);
n
=
func
(
lxcpath
,
NULL
,
NULL
);
n
=
func
(
lxcpath
,
NULL
,
NULL
);
printf
(
"%-10s Counted %d containers
\n
"
,
type
,
n
);
printf
(
"%-10s Counted %d containers
\n
"
,
type
,
n
);
printf
(
"%-10s Get container struct only
\n
"
,
type
);
printf
(
"%-10s Get container struct only
\n
"
,
type
);
n2
=
func
(
lxcpath
,
NULL
,
&
clist
);
n2
=
func
(
lxcpath
,
NULL
,
&
clist
);
if
(
n2
!=
n
)
if
(
n2
!=
n
)
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
struct
lxc_container
*
c
=
clist
[
i
];
struct
lxc_container
*
c
=
clist
[
i
];
printf
(
"%-10s Got container struct %s
\n
"
,
type
,
c
->
name
);
printf
(
"%-10s Got container struct %s
\n
"
,
type
,
c
->
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
if
(
n2
>
0
)
{
if
(
n2
>
0
)
{
free
(
clist
);
free
(
clist
);
clist
=
NULL
;
clist
=
NULL
;
...
@@ -51,10 +55,12 @@ static void test_list_func(const char *lxcpath, const char *type,
...
@@ -51,10 +55,12 @@ static void test_list_func(const char *lxcpath, const char *type,
n2
=
func
(
lxcpath
,
&
names
,
NULL
);
n2
=
func
(
lxcpath
,
&
names
,
NULL
);
if
(
n2
!=
n
)
if
(
n2
!=
n
)
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
printf
(
"%-10s Got container name %s
\n
"
,
type
,
names
[
i
]);
printf
(
"%-10s Got container name %s
\n
"
,
type
,
names
[
i
]);
free
(
names
[
i
]);
free
(
names
[
i
]);
}
}
if
(
n2
>
0
)
{
if
(
n2
>
0
)
{
free
(
names
);
free
(
names
);
names
=
NULL
;
names
=
NULL
;
...
@@ -64,14 +70,18 @@ static void test_list_func(const char *lxcpath, const char *type,
...
@@ -64,14 +70,18 @@ static void test_list_func(const char *lxcpath, const char *type,
n2
=
func
(
lxcpath
,
&
names
,
&
clist
);
n2
=
func
(
lxcpath
,
&
names
,
&
clist
);
if
(
n2
!=
n
)
if
(
n2
!=
n
)
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
struct
lxc_container
*
c
=
clist
[
i
];
struct
lxc_container
*
c
=
clist
[
i
];
printf
(
"%-10s Got container struct %s, name %s
\n
"
,
type
,
c
->
name
,
names
[
i
]);
printf
(
"%-10s Got container struct %s, name %s
\n
"
,
type
,
c
->
name
,
names
[
i
]);
if
(
strcmp
(
c
->
name
,
names
[
i
]))
if
(
strcmp
(
c
->
name
,
names
[
i
]))
fprintf
(
stderr
,
"ERROR: name mismatch!
\n
"
);
fprintf
(
stderr
,
"ERROR: name mismatch!
\n
"
);
free
(
names
[
i
]);
free
(
names
[
i
]);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
if
(
n2
>
0
)
{
if
(
n2
>
0
)
{
free
(
names
);
free
(
names
);
free
(
clist
);
free
(
clist
);
...
...
src/tests/locktests.c
View file @
9b937486
...
@@ -38,39 +38,49 @@ static void test_two_locks(void)
...
@@ -38,39 +38,49 @@ static void test_two_locks(void)
if
(
pipe
(
p
)
<
0
)
if
(
pipe
(
p
)
<
0
)
exit
(
1
);
exit
(
1
);
if
((
pid
=
fork
())
<
0
)
if
((
pid
=
fork
())
<
0
)
exit
(
1
);
exit
(
1
);
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
if
(
read
(
p
[
0
],
&
c
,
1
)
<
0
)
{
if
(
read
(
p
[
0
],
&
c
,
1
)
<
0
)
{
perror
(
"read"
);
perror
(
"read"
);
exit
(
1
);
exit
(
1
);
}
}
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
if
(
!
l
)
{
if
(
!
l
)
{
fprintf
(
stderr
,
"%d: child: failed to create lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: child: failed to create lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
if
(
lxclock
(
l
,
0
)
<
0
)
{
if
(
lxclock
(
l
,
0
)
<
0
)
{
fprintf
(
stderr
,
"%d: child: failed to grab lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: child: failed to grab lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
fprintf
(
stderr
,
"%d: child: grabbed lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: child: grabbed lock
\n
"
,
__LINE__
);
exit
(
0
);
exit
(
0
);
}
}
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
if
(
!
l
)
{
if
(
!
l
)
{
fprintf
(
stderr
,
"%d: failed to create lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
if
(
lxclock
(
l
,
0
)
<
0
)
{
if
(
lxclock
(
l
,
0
)
<
0
)
{
fprintf
(
stderr
,
"%d; failed to get lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d; failed to get lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
if
(
write
(
p
[
1
],
"a"
,
1
)
<
0
)
{
if
(
write
(
p
[
1
],
"a"
,
1
)
<
0
)
{
perror
(
"write"
);
perror
(
"write"
);
exit
(
1
);
exit
(
1
);
}
}
sleep
(
3
);
sleep
(
3
);
ret
=
waitpid
(
pid
,
&
status
,
WNOHANG
);
ret
=
waitpid
(
pid
,
&
status
,
WNOHANG
);
if
(
ret
==
pid
)
{
// task exited
if
(
ret
==
pid
)
{
// task exited
if
(
WIFEXITED
(
status
))
{
if
(
WIFEXITED
(
status
))
{
...
@@ -85,6 +95,7 @@ static void test_two_locks(void)
...
@@ -85,6 +95,7 @@ static void test_two_locks(void)
perror
(
"waitpid"
);
perror
(
"waitpid"
);
exit
(
1
);
exit
(
1
);
}
}
kill
(
pid
,
SIGKILL
);
kill
(
pid
,
SIGKILL
);
wait
(
&
status
);
wait
(
&
status
);
close
(
p
[
1
]);
close
(
p
[
1
]);
...
@@ -103,6 +114,7 @@ int main(int argc, char *argv[])
...
@@ -103,6 +114,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to get unnamed lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to get unnamed lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
ret
=
lxclock
(
lock
,
0
);
ret
=
lxclock
(
lock
,
0
);
if
(
ret
)
{
if
(
ret
)
{
fprintf
(
stderr
,
"%d: failed to take unnamed lock (%d)
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: failed to take unnamed lock (%d)
\n
"
,
__LINE__
,
ret
);
...
@@ -121,8 +133,10 @@ int main(int argc, char *argv[])
...
@@ -121,8 +133,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to get lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to get lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
struct
stat
sb
;
struct
stat
sb
;
char
*
pathname
=
RUNTIME_PATH
"/lxc/lock/var/lib/lxc/"
;
char
*
pathname
=
RUNTIME_PATH
"/lxc/lock/var/lib/lxc/"
;
ret
=
stat
(
pathname
,
&
sb
);
ret
=
stat
(
pathname
,
&
sb
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: filename %s not created
\n
"
,
__LINE__
,
fprintf
(
stderr
,
"%d: filename %s not created
\n
"
,
__LINE__
,
...
...
src/tests/lxc-test-utils.c
View file @
9b937486
...
@@ -49,6 +49,7 @@ void test_lxc_deslashify(void)
...
@@ -49,6 +49,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A/B/C/D/E"
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A/B/C/D/E"
)
==
0
);
free
(
t
);
free
(
t
);
...
@@ -57,6 +58,7 @@ void test_lxc_deslashify(void)
...
@@ -57,6 +58,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A"
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A"
)
==
0
);
free
(
t
);
free
(
t
);
...
@@ -64,6 +66,7 @@ void test_lxc_deslashify(void)
...
@@ -64,6 +66,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
""
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
""
)
==
0
);
free
(
t
);
free
(
t
);
...
@@ -72,6 +75,7 @@ void test_lxc_deslashify(void)
...
@@ -72,6 +75,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/"
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/"
)
==
0
);
free
(
t
);
free
(
t
);
}
}
...
@@ -188,6 +192,7 @@ void test_detect_ramfs_rootfs(void)
...
@@ -188,6 +192,7 @@ void test_detect_ramfs_rootfs(void)
for
(
i
=
0
;
i
<
sizeof
(
mountinfo
)
/
sizeof
(
mountinfo
[
0
]);
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
mountinfo
)
/
sizeof
(
mountinfo
[
0
]);
i
++
)
{
if
(
strcmp
(
mountinfo
[
i
],
"24 0 8:2 / / rw - rootfs rootfs rw,size=1004396k,nr_inodes=251099"
)
==
0
)
if
(
strcmp
(
mountinfo
[
i
],
"24 0 8:2 / / rw - rootfs rootfs rw,size=1004396k,nr_inodes=251099"
)
==
0
)
continue
;
continue
;
if
(
fprintf
(
fp2
,
"%s
\n
"
,
mountinfo
[
i
])
<
0
)
{
if
(
fprintf
(
fp2
,
"%s
\n
"
,
mountinfo
[
i
])
<
0
)
{
lxc_error
(
"Could not write
\"
%s
\"
to temporary file."
,
mountinfo
[
i
]);
lxc_error
(
"Could not write
\"
%s
\"
to temporary file."
,
mountinfo
[
i
]);
goto
non_test_error
;
goto
non_test_error
;
...
@@ -217,6 +222,7 @@ non_test_error:
...
@@ -217,6 +222,7 @@ non_test_error:
fclose
(
fp1
);
fclose
(
fp1
);
else
if
(
fd1
>
0
)
else
if
(
fd1
>
0
)
close
(
fd1
);
close
(
fd1
);
if
(
fp2
)
if
(
fp2
)
fclose
(
fp2
);
fclose
(
fp2
);
else
if
(
fd2
>
0
)
else
if
(
fd2
>
0
)
...
@@ -229,8 +235,10 @@ non_test_error:
...
@@ -229,8 +235,10 @@ non_test_error:
}
}
close
(
init_ns
);
close
(
init_ns
);
}
}
if
(
fret
==
EXIT_SUCCESS
)
if
(
fret
==
EXIT_SUCCESS
)
return
;
return
;
exit
(
fret
);
exit
(
fret
);
}
}
...
@@ -246,11 +254,13 @@ void test_lxc_safe_uint(void)
...
@@ -246,11 +254,13 @@ void test_lxc_safe_uint(void)
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
numstr
,
&
n
))
&&
n
==
UINT_MAX
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
numstr
,
&
n
))
&&
n
==
UINT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
+
1
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
+
1
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
...
@@ -277,21 +287,25 @@ void test_lxc_safe_int(void)
...
@@ -277,21 +287,25 @@ void test_lxc_safe_int(void)
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MAX
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
+
1
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
+
1
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MIN
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MIN
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
-
1
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
-
1
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
...
@@ -394,6 +408,7 @@ void test_parse_byte_size_string(void)
...
@@ -394,6 +408,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
0
)
{
if
(
n
!=
0
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -404,6 +419,7 @@ void test_parse_byte_size_string(void)
...
@@ -404,6 +419,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1
)
{
if
(
n
!=
1
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -420,6 +436,7 @@ void test_parse_byte_size_string(void)
...
@@ -420,6 +436,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1
)
{
if
(
n
!=
1
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -430,6 +447,7 @@ void test_parse_byte_size_string(void)
...
@@ -430,6 +447,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1024
)
{
if
(
n
!=
1024
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -440,6 +458,7 @@ void test_parse_byte_size_string(void)
...
@@ -440,6 +458,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1048576
)
{
if
(
n
!=
1048576
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -456,6 +475,7 @@ void test_parse_byte_size_string(void)
...
@@ -456,6 +475,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1
)
{
if
(
n
!=
1
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -466,6 +486,7 @@ void test_parse_byte_size_string(void)
...
@@ -466,6 +486,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1024
)
{
if
(
n
!=
1024
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -476,6 +497,7 @@ void test_parse_byte_size_string(void)
...
@@ -476,6 +497,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1048576
)
{
if
(
n
!=
1048576
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -503,8 +525,10 @@ void test_lxc_config_net_hwaddr(void)
...
@@ -503,8 +525,10 @@ void test_lxc_config_net_hwaddr(void)
if
(
lxc_config_net_hwaddr
(
"lxc.net"
))
if
(
lxc_config_net_hwaddr
(
"lxc.net"
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net."
))
if
(
lxc_config_net_hwaddr
(
"lxc.net."
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net.0."
))
if
(
lxc_config_net_hwaddr
(
"lxc.net.0."
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
...
src/tests/lxc_raw_clone.c
View file @
9b937486
...
@@ -125,6 +125,7 @@ int main(int argc, char *argv[])
...
@@ -125,6 +125,7 @@ int main(int argc, char *argv[])
flags
|=
CLONE_NEWIPC
;
flags
|=
CLONE_NEWIPC
;
flags
|=
CLONE_NEWPID
;
flags
|=
CLONE_NEWPID
;
flags
|=
CLONE_NEWUTS
;
flags
|=
CLONE_NEWUTS
;
pid
=
lxc_raw_clone
(
flags
);
pid
=
lxc_raw_clone
(
flags
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
lxc_error
(
"%s
\n
"
,
"Failed to call lxc_raw_clone(CLONE_NEWUSER "
lxc_error
(
"%s
\n
"
,
"Failed to call lxc_raw_clone(CLONE_NEWUSER "
...
@@ -172,7 +173,6 @@ int main(int argc, char *argv[])
...
@@ -172,7 +173,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
...
@@ -190,7 +190,6 @@ int main(int argc, char *argv[])
...
@@ -190,7 +190,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -208,7 +207,6 @@ int main(int argc, char *argv[])
...
@@ -208,7 +207,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
...
@@ -226,7 +224,6 @@ int main(int argc, char *argv[])
...
@@ -226,7 +224,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
...
src/tests/lxcpath.c
View file @
9b937486
...
@@ -44,6 +44,7 @@ int main()
...
@@ -44,6 +44,7 @@ int main()
TSTERR
(
"create using default path"
);
TSTERR
(
"create using default path"
);
goto
err
;
goto
err
;
}
}
p1
=
c
->
get_config_path
(
c
);
p1
=
c
->
get_config_path
(
c
);
p2
=
c
->
config_file_name
(
c
);
p2
=
c
->
config_file_name
(
c
);
if
(
!
p1
||
!
p2
||
strncmp
(
p1
,
p2
,
strlen
(
p1
)))
{
if
(
!
p1
||
!
p2
||
strncmp
(
p1
,
p2
,
strlen
(
p1
)))
{
...
@@ -57,6 +58,7 @@ int main()
...
@@ -57,6 +58,7 @@ int main()
TSTERR
(
"Error setting custom path"
);
TSTERR
(
"Error setting custom path"
);
goto
err
;
goto
err
;
}
}
p1
=
c
->
get_config_path
(
c
);
p1
=
c
->
get_config_path
(
c
);
p2
=
c
->
config_file_name
(
c
);
p2
=
c
->
config_file_name
(
c
);
if
(
strcmp
(
p1
,
CPATH
)
||
strcmp
(
p2
,
FPATH
))
{
if
(
strcmp
(
p1
,
CPATH
)
||
strcmp
(
p2
,
FPATH
))
{
...
...
src/tests/may_control.c
View file @
9b937486
...
@@ -35,12 +35,16 @@ int main(int argc, char *argv[])
...
@@ -35,12 +35,16 @@ int main(int argc, char *argv[])
if
(
argc
<
2
)
if
(
argc
<
2
)
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
name
=
argv
[
1
];
name
=
argv
[
1
];
if
(
argc
==
3
)
if
(
argc
==
3
)
lxcpath
=
argv
[
2
];
lxcpath
=
argv
[
2
];
c
=
lxc_container_new
(
name
,
lxcpath
);
c
=
lxc_container_new
(
name
,
lxcpath
);
if
(
c
)
if
(
c
)
may
=
c
->
may_control
(
c
);
may
=
c
->
may_control
(
c
);
printf
(
"You may%s control %s
\n
"
,
may
?
""
:
" not"
,
name
);
printf
(
"You may%s control %s
\n
"
,
may
?
""
:
" not"
,
name
);
exit
(
may
?
0
:
1
);
exit
(
may
?
0
:
1
);
}
}
src/tests/reboot.c
View file @
9b937486
...
@@ -41,6 +41,7 @@ static int do_reboot(void *arg)
...
@@ -41,6 +41,7 @@ static int do_reboot(void *arg)
if
(
reboot
(
*
cmd
))
if
(
reboot
(
*
cmd
))
printf
(
"failed to reboot(%d): %s
\n
"
,
*
cmd
,
strerror
(
errno
));
printf
(
"failed to reboot(%d): %s
\n
"
,
*
cmd
,
strerror
(
errno
));
return
0
;
return
0
;
}
}
...
@@ -65,6 +66,7 @@ static int test_reboot(int cmd, int sig)
...
@@ -65,6 +66,7 @@ static int test_reboot(int cmd, int sig)
if
(
!
WIFSIGNALED
(
status
))
{
if
(
!
WIFSIGNALED
(
status
))
{
if
(
sig
!=
-
1
)
if
(
sig
!=
-
1
)
printf
(
"child process exited but was not signaled
\n
"
);
printf
(
"child process exited but was not signaled
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -89,9 +91,11 @@ static int have_reboot_patch(void)
...
@@ -89,9 +91,11 @@ static int have_reboot_patch(void)
fclose
(
f
);
fclose
(
f
);
if
(
ret
!=
1
)
if
(
ret
!=
1
)
return
0
;
return
0
;
ret
=
reboot
(
v
?
LINUX_REBOOT_CMD_CAD_ON
:
LINUX_REBOOT_CMD_CAD_OFF
);
ret
=
reboot
(
v
?
LINUX_REBOOT_CMD_CAD_ON
:
LINUX_REBOOT_CMD_CAD_OFF
);
if
(
ret
!=
-
1
)
if
(
ret
!=
-
1
)
return
0
;
return
0
;
return
1
;
return
1
;
}
}
...
...
src/tests/saveconfig.c
View file @
9b937486
...
@@ -37,24 +37,30 @@ static int create_container(void)
...
@@ -37,24 +37,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -90,6 +96,7 @@ int main(int argc, char *argv[])
...
@@ -90,6 +96,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed writing config file /tmp/lxctest1
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed writing config file /tmp/lxctest1
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
rename
(
LXCPATH
"/"
MYNAME
"/config"
,
LXCPATH
"/"
MYNAME
"/config.bak"
);
rename
(
LXCPATH
"/"
MYNAME
"/config"
,
LXCPATH
"/"
MYNAME
"/config.bak"
);
if
(
!
c
->
save_config
(
c
,
NULL
))
{
if
(
!
c
->
save_config
(
c
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed writing config file
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed writing config file
\n
"
,
__LINE__
);
...
@@ -108,6 +115,7 @@ int main(int argc, char *argv[])
...
@@ -108,6 +115,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/shortlived.c
View file @
9b937486
...
@@ -46,10 +46,12 @@ static int destroy_container(void)
...
@@ -46,10 +46,12 @@ static int destroy_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -58,12 +60,15 @@ again:
...
@@ -58,12 +60,15 @@ again:
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -76,24 +81,30 @@ static int create_container(void)
...
@@ -76,24 +81,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -124,6 +135,7 @@ int main(int argc, char *argv[])
...
@@ -124,6 +135,7 @@ int main(int argc, char *argv[])
log
.
prefix
=
"shortlived"
;
log
.
prefix
=
"shortlived"
;
log
.
quiet
=
false
;
log
.
quiet
=
false
;
log
.
lxcpath
=
NULL
;
log
.
lxcpath
=
NULL
;
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -256,11 +268,13 @@ out:
...
@@ -256,11 +268,13 @@ out:
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
char
buf
[
4096
];
char
buf
[
4096
];
ssize_t
buflen
;
ssize_t
buflen
;
while
((
buflen
=
read
(
fd
,
buf
,
1024
))
>
0
)
{
while
((
buflen
=
read
(
fd
,
buf
,
1024
))
>
0
)
{
buflen
=
write
(
STDERR_FILENO
,
buf
,
buflen
);
buflen
=
write
(
STDERR_FILENO
,
buf
,
buflen
);
if
(
buflen
<=
0
)
if
(
buflen
<=
0
)
break
;
break
;
}
}
close
(
fd
);
close
(
fd
);
}
}
}
}
...
...
src/tests/shutdowntest.c
View file @
9b937486
...
@@ -49,8 +49,10 @@ int main(int argc, char *argv[])
...
@@ -49,8 +49,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -64,6 +66,7 @@ int main(int argc, char *argv[])
...
@@ -64,6 +66,7 @@ int main(int argc, char *argv[])
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
c
->
want_daemonize
(
c
,
true
);
c
->
want_daemonize
(
c
,
true
);
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
...
@@ -74,9 +77,9 @@ int main(int argc, char *argv[])
...
@@ -74,9 +77,9 @@ int main(int argc, char *argv[])
if
(
!
c
->
shutdown
(
c
,
120
))
{
if
(
!
c
->
shutdown
(
c
,
120
))
{
fprintf
(
stderr
,
"%d: failed to shut down %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to shut down %s
\n
"
,
__LINE__
,
MYNAME
);
if
(
!
c
->
stop
(
c
))
{
if
(
!
c
->
stop
(
c
))
fprintf
(
stderr
,
"%d: failed to kill %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to kill %s
\n
"
,
__LINE__
,
MYNAME
);
}
goto
out
;
goto
out
;
}
}
...
@@ -92,10 +95,10 @@ int main(int argc, char *argv[])
...
@@ -92,10 +95,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
if
(
c
&&
c
->
is_defined
(
c
))
{
if
(
c
&&
c
->
is_defined
(
c
))
c
->
destroy
(
c
);
c
->
destroy
(
c
);
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/snapshot.c
View file @
9b937486
...
@@ -32,23 +32,28 @@
...
@@ -32,23 +32,28 @@
static
void
try_to_remove
(
void
)
static
void
try_to_remove
(
void
)
{
{
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
c
=
lxc_container_new
(
RESTNAME
,
NULL
);
c
=
lxc_container_new
(
RESTNAME
,
NULL
);
if
(
c
)
{
if
(
c
)
{
c
->
snapshot_destroy_all
(
c
);
c
->
snapshot_destroy_all
(
c
);
if
(
c
->
is_defined
(
c
))
if
(
c
->
is_defined
(
c
))
c
->
destroy
(
c
);
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
c
=
lxc_container_new
(
MYNAME2
,
NULL
);
c
=
lxc_container_new
(
MYNAME2
,
NULL
);
if
(
c
)
{
if
(
c
)
{
c
->
destroy_with_snapshots
(
c
);
c
->
destroy_with_snapshots
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
c
)
{
if
(
c
)
{
c
->
snapshot_destroy_all
(
c
);
c
->
snapshot_destroy_all
(
c
);
if
(
c
->
is_defined
(
c
))
if
(
c
->
is_defined
(
c
))
c
->
destroy
(
c
);
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
}
}
...
@@ -66,6 +71,7 @@ int main(int argc, char *argv[])
...
@@ -66,6 +71,7 @@ int main(int argc, char *argv[])
template
=
argv
[
1
];
template
=
argv
[
1
];
try_to_remove
();
try_to_remove
();
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"%s: %d: failed to load first container
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed to load first container
\n
"
,
__FILE__
,
__LINE__
);
...
@@ -76,15 +82,19 @@ int main(int argc, char *argv[])
...
@@ -76,15 +82,19 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: %s thought it was defined
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: %s thought it was defined
\n
"
,
__LINE__
,
MYNAME
);
(
void
)
c
->
destroy_with_snapshots
(
c
);
(
void
)
c
->
destroy_with_snapshots
(
c
);
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.type"
,
"empty"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.type"
,
"empty"
))
{
fprintf
(
stderr
,
"%s: %d: failed to set network type
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed to set network type
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
c
->
save_config
(
c
,
NULL
);
c
->
save_config
(
c
,
NULL
);
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%s: %d: failed to create %s container
\n
"
,
__FILE__
,
__LINE__
,
template
);
fprintf
(
stderr
,
"%s: %d: failed to create %s container
\n
"
,
__FILE__
,
__LINE__
,
template
);
goto
err
;
goto
err
;
}
}
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
if
(
c
->
snapshot
(
c
,
NULL
)
!=
0
)
{
if
(
c
->
snapshot
(
c
,
NULL
)
!=
0
)
{
...
@@ -110,13 +120,14 @@ int main(int argc, char *argv[])
...
@@ -110,13 +120,14 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
s
[
i
].
free
(
&
s
[
i
]);
s
[
i
].
free
(
&
s
[
i
]);
}
free
(
s
);
free
(
s
);
if
(
!
c
->
snapshot_restore
(
c
,
"snap0"
,
RESTNAME
))
{
if
(
!
c
->
snapshot_restore
(
c
,
"snap0"
,
RESTNAME
))
{
...
@@ -152,13 +163,14 @@ int main(int argc, char *argv[])
...
@@ -152,13 +163,14 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
s
[
i
].
free
(
&
s
[
i
]);
s
[
i
].
free
(
&
s
[
i
]);
}
free
(
s
);
free
(
s
);
if
(
!
c2
->
snapshot_restore
(
c2
,
"snap0"
,
NULL
))
{
if
(
!
c2
->
snapshot_restore
(
c2
,
"snap0"
,
NULL
))
{
...
@@ -177,6 +189,7 @@ good:
...
@@ -177,6 +189,7 @@ good:
printf
(
"All tests passed
\n
"
);
printf
(
"All tests passed
\n
"
);
exit
(
0
);
exit
(
0
);
err:
err:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
try_to_remove
();
try_to_remove
();
...
...
src/tests/startone.c
View file @
9b937486
...
@@ -39,24 +39,30 @@ static int destroy_container(void)
...
@@ -39,24 +39,30 @@ static int destroy_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -69,24 +75,30 @@ static int create_container(void)
...
@@ -69,24 +75,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -100,6 +112,7 @@ int main(int argc, char *argv[])
...
@@ -100,6 +112,7 @@ int main(int argc, char *argv[])
int
len
;
int
len
;
ret
=
1
;
ret
=
1
;
/* test a real container */
/* test a real container */
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
...
@@ -167,6 +180,7 @@ int main(int argc, char *argv[])
...
@@ -167,6 +180,7 @@ int main(int argc, char *argv[])
}
}
sleep
(
3
);
sleep
(
3
);
s
=
c
->
state
(
c
);
s
=
c
->
state
(
c
);
if
(
!
s
||
strcmp
(
s
,
"RUNNING"
))
{
if
(
!
s
||
strcmp
(
s
,
"RUNNING"
))
{
fprintf
(
stderr
,
"%d: %s is in state %s, not in RUNNING.
\n
"
,
__LINE__
,
c
->
name
,
s
?
s
:
"undefined"
);
fprintf
(
stderr
,
"%d: %s is in state %s, not in RUNNING.
\n
"
,
__LINE__
,
c
->
name
,
s
?
s
:
"undefined"
);
...
@@ -192,7 +206,7 @@ int main(int argc, char *argv[])
...
@@ -192,7 +206,7 @@ int main(int argc, char *argv[])
goto
out
;
goto
out
;
}
}
sprintf
(
buf
,
"XXX"
);
sprintf
(
buf
,
"XXX"
);
len
=
c
->
get_cgroup_item
(
c
,
"freezer.state"
,
buf
,
200
);
len
=
c
->
get_cgroup_item
(
c
,
"freezer.state"
,
buf
,
200
);
if
(
len
<=
0
||
(
strcmp
(
buf
,
"FREEZING
\n
"
)
&&
strcmp
(
buf
,
"FROZEN
\n
"
)))
{
if
(
len
<=
0
||
(
strcmp
(
buf
,
"FREEZING
\n
"
)
&&
strcmp
(
buf
,
"FROZEN
\n
"
)))
{
fprintf
(
stderr
,
"%d: not able to get freezer.state (len %d buf %s)
\n
"
,
__LINE__
,
len
,
buf
);
fprintf
(
stderr
,
"%d: not able to get freezer.state (len %d buf %s)
\n
"
,
__LINE__
,
len
,
buf
);
...
...
src/tests/state_server.c
View file @
9b937486
...
@@ -149,5 +149,6 @@ on_error_put:
...
@@ -149,5 +149,6 @@ on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All state server tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All state server tests passed"
);
exit
(
ret
);
exit
(
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