Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
criu
Project
Project
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
zhul
criu
Commits
2c6b61f1
Commit
2c6b61f1
authored
Sep 25, 2013
by
Pavel Emelyanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zdtm: Test for chroot
Signed-off-by:
Pavel Emelyanov
<
xemul@parallels.com
>
parent
c378f790
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
0 deletions
+172
-0
zdtm.sh
test/zdtm.sh
+2
-0
Makefile
test/zdtm/live/static/Makefile
+7
-0
chroot.c
test/zdtm/live/static/chroot.c
+163
-0
No files found.
test/zdtm.sh
View file @
2c6b61f1
...
@@ -94,6 +94,7 @@ static/sk-netlink
...
@@ -94,6 +94,7 @@ static/sk-netlink
static/proc-self
static/proc-self
static/grow_map
static/grow_map
static/grow_map02
static/grow_map02
static/chroot
"
"
# Duplicate list with ns/ prefix
# Duplicate list with ns/ prefix
TEST_LIST
=
$TEST_LIST
$(
echo
$TEST_LIST
|
tr
' '
'\n'
|
sed
's#^#ns/#'
)
TEST_LIST
=
$TEST_LIST
$(
echo
$TEST_LIST
|
tr
' '
'\n'
|
sed
's#^#ns/#'
)
...
@@ -140,6 +141,7 @@ packet_sock
...
@@ -140,6 +141,7 @@ packet_sock
fanotify00
fanotify00
sk-netlink
sk-netlink
tun
tun
chroot
"
"
source
$(
readlink
-f
`
dirname
$0
`
/env.sh
)
||
exit
1
source
$(
readlink
-f
`
dirname
$0
`
/env.sh
)
||
exit
1
...
...
test/zdtm/live/static/Makefile
View file @
2c6b61f1
...
@@ -142,10 +142,14 @@ TST_DIR = \
...
@@ -142,10 +142,14 @@ TST_DIR = \
overmount_fifo
\
overmount_fifo
\
overmount_sock
\
overmount_sock
\
TST_DIR_FILE
=
\
chroot
TST
=
\
TST
=
\
$(TST_NOFILE)
\
$(TST_NOFILE)
\
$(TST_FILE)
\
$(TST_FILE)
\
$(TST_DIR)
\
$(TST_DIR)
\
$(TST_DIR_FILE)
\
env00
\
env00
\
fifo-rowo-pair
\
fifo-rowo-pair
\
umask00
\
umask00
\
...
@@ -183,6 +187,9 @@ $(TST_FILE:%=%.pid): %.pid: %
...
@@ -183,6 +187,9 @@ $(TST_FILE:%=%.pid): %.pid: %
$(TST_DIR
:
%=%.pid): %.pid: %
$(TST_DIR
:
%=%.pid): %.pid: %
$
(
<D
)
/
$
(
<F
)
--pidfile
=
$@
--outfile
=
$<
.out
--dirname
=
$<
.test
$
(
<D
)
/
$
(
<F
)
--pidfile
=
$@
--outfile
=
$<
.out
--dirname
=
$<
.test
$(TST_DIR_FILE
:
%=%.pid): %.pid: %
$
(
<D
)
/
$
(
<F
)
--pidfile
=
$@
--outfile
=
$<
.out
--dirname
=
$<
.dir.test
--filename
=
$<
.test
cmdlinenv00.pid
:
cmdlinenv00
cmdlinenv00.pid
:
cmdlinenv00
$
(
<D
)
/
$
(
<F
)
--pidfile
=
$@
--outfile
=
$<
.out
--arg1
=
arg1
--arg2
=
arg2
--arg3
=
arg3
$
(
<D
)
/
$
(
<F
)
--pidfile
=
$@
--outfile
=
$<
.out
--arg1
=
arg1
--arg2
=
arg2
--arg3
=
arg3
...
...
test/zdtm/live/static/chroot.c
0 → 100644
View file @
2c6b61f1
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <sys/wait.h>
#include "zdtmtst.h"
const
char
*
test_doc
=
"Check that root didn't change"
;
const
char
*
test_author
=
"Pavel Emelianov <xemul@parallels.com>"
;
char
*
dirname
;
TEST_OPTION
(
dirname
,
string
,
"directory name"
,
1
);
char
*
filename
;
TEST_OPTION
(
filename
,
string
,
"file name"
,
1
);
static
char
*
filepath
;
#define MSG "chroot-file-contents"
static
int
make_file
(
char
*
name
)
{
int
fd
;
fd
=
open
(
name
,
O_RDWR
|
O_CREAT
,
0666
);
if
(
fd
<
0
)
return
-
1
;
if
(
write
(
fd
,
MSG
,
sizeof
(
MSG
))
!=
sizeof
(
MSG
))
return
-
1
;
return
fd
;
}
static
int
check_file
(
int
fd
)
{
char
r
[
sizeof
(
MSG
)];
lseek
(
fd
,
0
,
SEEK_SET
);
if
(
read
(
fd
,
r
,
sizeof
(
r
))
!=
sizeof
(
MSG
))
return
-
1
;
if
(
memcmp
(
r
,
MSG
,
sizeof
(
MSG
)))
return
-
1
;
return
0
;
}
#define SUCCESS 0
#define ERR_PIPES (char)0x7f
/* bitmap of errors */
#define ERR_IN_FILE 1
#define ERR_ROOT 2
#define ERR_DIR 4
#define ERR_OPEN 2
#define ERR_FILE2 4
int
main
(
int
argc
,
char
**
argv
)
{
int
pid
,
pipe_prep
[
2
],
pipe_goon
[
2
],
pipe_res
[
2
];
char
res
;
int
fd
,
fd2
;
test_init
(
argc
,
argv
);
filepath
=
malloc
(
strlen
(
filename
)
+
1
);
sprintf
(
filepath
,
"/%s"
,
filename
);
pipe
(
pipe_prep
);
pipe
(
pipe_goon
);
pipe
(
pipe_res
);
pid
=
test_fork
();
if
(
pid
!=
0
)
{
close
(
pipe_prep
[
1
]);
close
(
pipe_goon
[
0
]);
close
(
pipe_res
[
1
]);
res
=
ERR_PIPES
;
read
(
pipe_prep
[
0
],
&
res
,
1
);
if
(
res
!=
SUCCESS
)
{
if
(
res
==
ERR_PIPES
)
err
(
"broken pipes"
);
else
{
if
(
res
&
ERR_IN_FILE
)
err
(
"inside-root file fail"
);
if
(
res
&
ERR_ROOT
)
err
(
"chroot fail"
);
if
(
res
&
ERR_DIR
)
err
(
"mkdir fail"
);
}
return
0
;
}
test_daemon
();
test_waitsig
();
close
(
pipe_goon
[
1
]);
res
=
ERR_PIPES
;
read
(
pipe_res
[
0
],
&
res
,
1
);
if
(
res
==
SUCCESS
)
pass
();
else
if
(
res
==
ERR_PIPES
)
fail
(
"broken pipes"
);
else
{
if
(
res
&
ERR_IN_FILE
)
fail
(
"opened file broken"
);
if
(
res
&
ERR_OPEN
)
fail
(
"open in chroot fail"
);
if
(
res
&
ERR_FILE2
)
fail
(
"wrong file opened"
);
}
wait
(
NULL
);
return
0
;
}
close
(
pipe_prep
[
0
]);
close
(
pipe_goon
[
1
]);
close
(
pipe_res
[
0
]);
if
(
mkdir
(
dirname
,
0700
))
{
res
=
ERR_DIR
;
goto
err_nodir
;
}
if
(
chroot
(
dirname
))
{
res
=
ERR_ROOT
;
goto
err_noroot
;
}
fd
=
make_file
(
filepath
);
if
(
fd
<
0
)
{
res
=
ERR_IN_FILE
;
goto
err_nofile2
;
}
res
=
SUCCESS
;
write
(
pipe_prep
[
1
],
&
res
,
1
);
close
(
pipe_prep
[
1
]);
read
(
pipe_goon
[
0
],
&
res
,
1
);
res
=
SUCCESS
;
if
(
check_file
(
fd
))
res
|=
ERR_IN_FILE
;
fd2
=
open
(
filepath
,
O_RDWR
);
if
(
fd2
<
0
)
res
|=
ERR_OPEN
;
else
if
(
check_file
(
fd2
))
res
|=
ERR_FILE2
;
write
(
pipe_res
[
1
],
&
res
,
1
);
exit
(
0
);
err_nofile2:
err_noroot:
err_nodir:
write
(
pipe_prep
[
1
],
&
res
,
1
);
exit
(
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment