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
8a2404e9
Unverified
Commit
8a2404e9
authored
Nov 15, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: expand console log tests
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
966b9ecd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
16 deletions
+112
-16
console_log.c
src/tests/console_log.c
+112
-16
No files found.
src/tests/console_log.c
View file @
8a2404e9
...
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
...
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
int
logfd
,
ret
;
int
logfd
,
ret
;
char
buf
[
4096
+
1
];
char
buf
[
4096
+
1
];
ssize_t
bytes
;
ssize_t
bytes
;
struct
stat
st
;
struct
stat
st
_buffer_log_file
,
st_log_file
,
st_log_file_old
;
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
struct
lxc_console_log
log
;
struct
lxc_console_log
log
;
bool
do_unlink
=
false
;
bool
do_unlink
=
false
;
...
@@ -57,12 +57,18 @@ int main(int argc, char *argv[])
...
@@ -57,12 +57,18 @@ int main(int argc, char *argv[])
}
}
/* Set console ringbuffer size. */
/* Set console ringbuffer size. */
if
(
!
c
->
set_config_item
(
c
,
"lxc.console.
log
size"
,
"4096"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.console.
buffer.
size"
,
"4096"
))
{
lxc_error
(
"%s
\n
"
,
"Failed to set config item
\"
lxc.console.
log
size
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to set config item
\"
lxc.console.
buffer.
size
\"
"
);
goto
on_error_put
;
goto
on_error_put
;
}
}
/* Set on-disk logfile. */
/* Set ringbuffer log file. */
if
(
!
c
->
set_config_item
(
c
,
"lxc.console.buffer.logfile"
,
"/tmp/console-buffer-log.log"
))
{
lxc_error
(
"%s
\n
"
,
"Failed to set config item
\"
lxc.console.buffer.logfile
\"
"
);
goto
on_error_put
;
}
/* Set console log file. */
if
(
!
c
->
set_config_item
(
c
,
"lxc.console.logfile"
,
"/tmp/console-log.log"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.console.logfile"
,
"/tmp/console-log.log"
))
{
lxc_error
(
"%s
\n
"
,
"Failed to set config item
\"
lxc.console.logfile
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to set config item
\"
lxc.console.logfile
\"
"
);
goto
on_error_put
;
goto
on_error_put
;
...
@@ -135,11 +141,17 @@ int main(int argc, char *argv[])
...
@@ -135,11 +141,17 @@ int main(int argc, char *argv[])
goto
on_error_stop
;
goto
on_error_stop
;
}
}
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to load config for container
\"
console-log
\"
"
);
goto
on_error_stop
;
}
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to start container
\"
console-log
\"
daemonized"
);
lxc_error
(
"%s
\n
"
,
"Failed to start container
\"
console-log
\"
daemonized"
);
goto
on_error_destroy
;
goto
on_error_destroy
;
}
}
do_unlink
=
true
;
/* Leave some time for the container to write something to the log. */
/* Leave some time for the container to write something to the log. */
sleep
(
2
);
sleep
(
2
);
...
@@ -158,31 +170,31 @@ int main(int argc, char *argv[])
...
@@ -158,31 +170,31 @@ int main(int argc, char *argv[])
*
log
.
read_max
,
log
.
data
);
*
log
.
read_max
,
log
.
data
);
}
}
logfd
=
open
(
"/tmp/console-log.log"
,
O_RDONLY
);
logfd
=
open
(
"/tmp/console-
buffer-
log.log"
,
O_RDONLY
);
if
(
logfd
<
0
)
{
if
(
logfd
<
0
)
{
lxc_error
(
"%s - Failed to open console log file "
lxc_error
(
"%s - Failed to open console
ringbuffer
log file "
"
\"
/tmp/console-log.log
\"\n
"
,
strerror
(
errno
));
"
\"
/tmp/console-
buffer-
log.log
\"\n
"
,
strerror
(
errno
));
goto
on_error_stop
;
goto
on_error_stop
;
}
}
bytes
=
lxc_read_nointr
(
logfd
,
buf
,
4096
+
1
);
bytes
=
lxc_read_nointr
(
logfd
,
buf
,
4096
+
1
);
close
(
logfd
);
close
(
logfd
);
if
(
bytes
<
0
||
((
uint64_t
)
bytes
!=
*
log
.
read_max
))
{
if
(
bytes
<
0
||
((
uint64_t
)
bytes
!=
*
log
.
read_max
))
{
lxc_error
(
"%s - Failed to read console log file "
lxc_error
(
"%s - Failed to read console
ringbuffer
log file "
"
\"
/tmp/console-log.log
\"\n
"
,
strerror
(
errno
));
"
\"
/tmp/console-
buffer-
log.log
\"\n
"
,
strerror
(
errno
));
goto
on_error_stop
;
goto
on_error_stop
;
}
}
ret
=
stat
(
"/tmp/console-
log.log"
,
&
st
);
ret
=
stat
(
"/tmp/console-
buffer-log.log"
,
&
st_buffer_log_file
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
lxc_error
(
"%s - Failed to stat on-disk logfile
\n
"
,
strerror
(
errno
));
lxc_error
(
"%s - Failed to stat on-disk logfile
\n
"
,
strerror
(
errno
));
goto
on_error_stop
;
goto
on_error_stop
;
}
}
if
((
uint64_t
)
st
.
st_size
!=
*
log
.
read_max
)
{
if
((
uint64_t
)
st
_buffer_log_file
.
st_size
!=
*
log
.
read_max
)
{
lxc_error
(
"On-disk logfile size and used ringbuffer size do "
lxc_error
(
"On-disk logfile size and used ringbuffer size do "
"not match: %"
PRIu64
" != %"
PRIu64
"
\n
"
,
"not match: %"
PRIu64
" != %"
PRIu64
"
\n
"
,
(
uint64_t
)
st
.
st_size
,
*
log
.
read_max
);
(
uint64_t
)
st
_buffer_log_file
.
st_size
,
*
log
.
read_max
);
goto
on_error_stop
;
goto
on_error_stop
;
}
}
...
@@ -192,8 +204,86 @@ int main(int argc, char *argv[])
...
@@ -192,8 +204,86 @@ int main(int argc, char *argv[])
goto
on_error_stop
;
goto
on_error_stop
;
}
else
{
}
else
{
lxc_debug
(
"Retrieved %"
PRIu64
" bytes from console log and "
lxc_debug
(
"Retrieved %"
PRIu64
" bytes from console log and "
"console log file. Contents are:
\"
%s
\"
-
\"
%s
\"\n
"
,
"console ringbuffer log file. Contents are:
\"
%s
\"
- "
*
log
.
read_max
,
log
.
data
,
buf
);
"
\"
%s
\"\n
"
,
*
log
.
read_max
,
log
.
data
,
buf
);
}
ret
=
stat
(
"/tmp/console-log.log"
,
&
st_log_file
);
if
(
ret
<
0
)
{
lxc_error
(
"%s - Failed to stat on-disk logfile
\n
"
,
strerror
(
errno
));
goto
on_error_stop
;
}
/* Turn on rotation for the console log file. */
if
(
!
c
->
set_config_item
(
c
,
"lxc.console.rotate"
,
"1"
))
{
lxc_error
(
"%s
\n
"
,
"Failed to set config item
\"
lxc.console.rotate
\"
"
);
goto
on_error_put
;
}
if
(
!
c
->
stop
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Failed to stop container
\"
console-log
\"
"
);
goto
on_error_stop
;
}
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to start container
\"
console-log
\"
daemonized"
);
goto
on_error_destroy
;
}
/* Leave some time for the container to write something to the log. */
sleep
(
2
);
/* The console log file size must be greater than the console log file
* size since we append to the latter and we truncated the former
* already.
*/
if
(
st_log_file
.
st_size
<=
st_buffer_log_file
.
st_size
)
{
lxc_error
(
"%s - Console log file size was smaller than the "
"console buffer log file size: %zu < %zu
\n
"
,
strerror
(
errno
),
(
size_t
)
st_log_file
.
st_size
,
(
size_t
)
st_buffer_log_file
.
st_size
);
goto
on_error_stop
;
}
else
{
lxc_debug
(
"Console log file size is %zu bytes and console "
"buffer log file size is %zu bytes
\n
"
,
(
size_t
)
st_log_file
.
st_size
,
(
size_t
)
st_buffer_log_file
.
st_size
);
}
ret
=
stat
(
"/tmp/console-log.log"
,
&
st_log_file
);
if
(
ret
<
0
)
{
lxc_error
(
"%s - Failed to stat on-disk logfile
\n
"
,
strerror
(
errno
));
goto
on_error_stop
;
}
log
.
read_max
=
&
(
uint64_t
){
0
};
log
.
read
=
false
;
log
.
write_logfile
=
false
;
log
.
clear
=
true
;
ret
=
c
->
console_log
(
c
,
&
log
);
if
(
ret
<
0
)
{
lxc_error
(
"%s - Failed to retrieve console log
\n
"
,
strerror
(
-
ret
));
goto
on_error_stop
;
}
/* There should now be a rotated log file called
* "/tmp/console-log.log.1"
*/
ret
=
stat
(
"/tmp/console-log.log.1"
,
&
st_log_file_old
);
if
(
ret
<
0
)
{
lxc_error
(
"%s - Failed to stat on-disk logfile
\n
"
,
strerror
(
errno
));
goto
on_error_stop
;
}
/* The rotated log file should have the same size as before the
* rotation.
*/
if
(
st_log_file
.
st_size
!=
st_log_file_old
.
st_size
)
{
lxc_error
(
"%s - Console log file size changed during log "
"rotation: %zu != %zu
\n
"
,
strerror
(
errno
),
(
size_t
)
st_log_file
.
st_size
,
(
size_t
)
st_log_file_old
.
st_size
);
goto
on_error_stop
;
}
}
fret
=
0
;
fret
=
0
;
...
@@ -211,7 +301,13 @@ on_error_put:
...
@@ -211,7 +301,13 @@ on_error_put:
if
(
do_unlink
)
{
if
(
do_unlink
)
{
ret
=
unlink
(
"/tmp/console-log.log"
);
ret
=
unlink
(
"/tmp/console-log.log"
);
if
(
ret
<
0
)
if
(
ret
<
0
)
lxc_error
(
"%s - Failed to remove container log file
\n
"
,
strerror
(
errno
));
lxc_error
(
"%s - Failed to remove container log file
\n
"
,
strerror
(
errno
));
ret
=
unlink
(
"/tmp/console-log.log.1"
);
if
(
ret
<
0
)
lxc_error
(
"%s - Failed to remove container log file
\n
"
,
strerror
(
errno
));
}
}
exit
(
fret
);
exit
(
fret
);
}
}
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