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
3b988b33
Unverified
Commit
3b988b33
authored
Oct 23, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console: move ringbuffer into lxc_console_create()
This makes the whole setup more flexible. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
69629c82
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
65 deletions
+54
-65
conf.c
src/lxc/conf.c
+1
-59
conf.h
src/lxc/conf.h
+1
-1
console.c
src/lxc/console.c
+51
-0
start.c
src/lxc/start.c
+1
-5
No files found.
src/lxc/conf.c
View file @
3b988b33
...
@@ -3083,65 +3083,7 @@ static bool verify_start_hooks(struct lxc_conf *conf)
...
@@ -3083,65 +3083,7 @@ static bool verify_start_hooks(struct lxc_conf *conf)
return
true
;
return
true
;
}
}
/**
int
lxc_setup
(
struct
lxc_handler
*
handler
)
* Note that this function needs to run before the mainloop starts. Since we
* register a handler for the console's masterfd when we create the mainloop
* the console handler needs to see an allocated ringbuffer.
*/
static
int
lxc_setup_console_ringbuf
(
struct
lxc_console
*
console
)
{
int
ret
;
struct
lxc_ringbuf
*
buf
=
&
console
->
ringbuf
;
uint64_t
size
=
console
->
log_size
;
/* no ringbuffer previously allocated and no ringbuffer requested */
if
(
!
buf
->
addr
&&
size
<=
0
)
return
0
;
/* ringbuffer allocated but no new ringbuffer requested */
if
(
buf
->
addr
&&
size
<=
0
)
{
lxc_ringbuf_release
(
buf
);
buf
->
addr
=
NULL
;
buf
->
r_off
=
0
;
buf
->
w_off
=
0
;
buf
->
size
=
0
;
TRACE
(
"Deallocated console ringbuffer"
);
return
0
;
}
if
(
size
<=
0
)
return
0
;
/* check wether the requested size for the ringbuffer has changed */
if
(
buf
->
addr
&&
buf
->
size
!=
size
)
{
TRACE
(
"Console ringbuffer size changed from %"
PRIu64
" to %"
PRIu64
" bytes. Deallocating console ringbuffer"
,
buf
->
size
,
size
);
lxc_ringbuf_release
(
buf
);
}
ret
=
lxc_ringbuf_create
(
buf
,
size
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to setup %"
PRIu64
" byte console ringbuffer"
,
size
);
return
-
1
;
}
TRACE
(
"Allocated %"
PRIu64
" byte console ringbuffer"
,
size
);
return
0
;
}
int
lxc_setup_parent
(
struct
lxc_handler
*
handler
)
{
int
ret
;
ret
=
lxc_setup_console_ringbuf
(
&
handler
->
conf
->
console
);
if
(
ret
<
0
)
return
-
1
;
return
0
;
}
int
lxc_setup_child
(
struct
lxc_handler
*
handler
)
{
{
int
ret
;
int
ret
;
const
char
*
name
=
handler
->
name
;
const
char
*
name
=
handler
->
name
;
...
...
src/lxc/conf.h
View file @
3b988b33
...
@@ -379,7 +379,7 @@ extern int lxc_delete_autodev(struct lxc_handler *handler);
...
@@ -379,7 +379,7 @@ extern int lxc_delete_autodev(struct lxc_handler *handler);
extern
void
lxc_clear_includes
(
struct
lxc_conf
*
conf
);
extern
void
lxc_clear_includes
(
struct
lxc_conf
*
conf
);
extern
int
do_rootfs_setup
(
struct
lxc_conf
*
conf
,
const
char
*
name
,
extern
int
do_rootfs_setup
(
struct
lxc_conf
*
conf
,
const
char
*
name
,
const
char
*
lxcpath
);
const
char
*
lxcpath
);
extern
int
lxc_setup
_child
(
struct
lxc_handler
*
handler
);
extern
int
lxc_setup
(
struct
lxc_handler
*
handler
);
extern
int
lxc_setup_parent
(
struct
lxc_handler
*
handler
);
extern
int
lxc_setup_parent
(
struct
lxc_handler
*
handler
);
extern
int
setup_resource_limits
(
struct
lxc_list
*
limits
,
pid_t
pid
);
extern
int
setup_resource_limits
(
struct
lxc_list
*
limits
,
pid_t
pid
);
extern
int
find_unmapped_nsid
(
struct
lxc_conf
*
conf
,
enum
idtype
idtype
);
extern
int
find_unmapped_nsid
(
struct
lxc_conf
*
conf
,
enum
idtype
idtype
);
...
...
src/lxc/console.c
View file @
3b988b33
...
@@ -535,6 +535,53 @@ void lxc_console_delete(struct lxc_console *console)
...
@@ -535,6 +535,53 @@ void lxc_console_delete(struct lxc_console *console)
console
->
log_fd
=
-
1
;
console
->
log_fd
=
-
1
;
}
}
/**
* Note that this function needs to run before the mainloop starts. Since we
* register a handler for the console's masterfd when we create the mainloop
* the console handler needs to see an allocated ringbuffer.
*/
static
int
lxc_setup_console_ringbuf
(
struct
lxc_console
*
console
)
{
int
ret
;
struct
lxc_ringbuf
*
buf
=
&
console
->
ringbuf
;
uint64_t
size
=
console
->
log_size
;
/* no ringbuffer previously allocated and no ringbuffer requested */
if
(
!
buf
->
addr
&&
size
<=
0
)
return
0
;
/* ringbuffer allocated but no new ringbuffer requested */
if
(
buf
->
addr
&&
size
<=
0
)
{
lxc_ringbuf_release
(
buf
);
buf
->
addr
=
NULL
;
buf
->
r_off
=
0
;
buf
->
w_off
=
0
;
buf
->
size
=
0
;
TRACE
(
"Deallocated console ringbuffer"
);
return
0
;
}
if
(
size
<=
0
)
return
0
;
/* check wether the requested size for the ringbuffer has changed */
if
(
buf
->
addr
&&
buf
->
size
!=
size
)
{
TRACE
(
"Console ringbuffer size changed from %"
PRIu64
" to %"
PRIu64
" bytes. Deallocating console ringbuffer"
,
buf
->
size
,
size
);
lxc_ringbuf_release
(
buf
);
}
ret
=
lxc_ringbuf_create
(
buf
,
size
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to setup %"
PRIu64
" byte console ringbuffer"
,
size
);
return
-
1
;
}
TRACE
(
"Allocated %"
PRIu64
" byte console ringbuffer"
,
size
);
return
0
;
}
int
lxc_console_create
(
struct
lxc_conf
*
conf
)
int
lxc_console_create
(
struct
lxc_conf
*
conf
)
{
{
int
ret
,
saved_errno
;
int
ret
,
saved_errno
;
...
@@ -587,6 +634,10 @@ int lxc_console_create(struct lxc_conf *conf)
...
@@ -587,6 +634,10 @@ int lxc_console_create(struct lxc_conf *conf)
DEBUG
(
"Using
\"
%s
\"
as console log file"
,
console
->
log_path
);
DEBUG
(
"Using
\"
%s
\"
as console log file"
,
console
->
log_path
);
}
}
ret
=
lxc_setup_console_ringbuf
(
console
);
if
(
ret
<
0
)
goto
err
;
return
0
;
return
0
;
err
:
err
:
...
...
src/lxc/start.c
View file @
3b988b33
...
@@ -904,7 +904,7 @@ static int do_start(void *data)
...
@@ -904,7 +904,7 @@ static int do_start(void *data)
}
}
/* Setup the container, ip, names, utsname, ... */
/* Setup the container, ip, names, utsname, ... */
ret
=
lxc_setup
_child
(
handler
);
ret
=
lxc_setup
(
handler
);
close
(
handler
->
data_sock
[
0
]);
close
(
handler
->
data_sock
[
0
]);
close
(
handler
->
data_sock
[
1
]);
close
(
handler
->
data_sock
[
1
]);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
...
@@ -1266,10 +1266,6 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1266,10 +1266,6 @@ static int lxc_spawn(struct lxc_handler *handler)
flags
&=
~
CLONE_NEWNET
;
flags
&=
~
CLONE_NEWNET
;
}
}
ret
=
lxc_setup_parent
(
handler
);
if
(
ret
<
0
)
goto
out_delete_net
;
if
(
fork_before_clone
)
if
(
fork_before_clone
)
handler
->
pid
=
lxc_fork_attach_clone
(
do_start
,
handler
,
flags
|
CLONE_PARENT
);
handler
->
pid
=
lxc_fork_attach_clone
(
do_start
,
handler
,
flags
|
CLONE_PARENT
);
else
else
...
...
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