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
efbfe93f
Unverified
Commit
efbfe93f
authored
May 14, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console: only create detached mount when a console is requested
otherwise weird things might happen. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
65633592
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
7 deletions
+39
-7
conf.c
src/lxc/conf.c
+39
-7
No files found.
src/lxc/conf.c
View file @
efbfe93f
...
@@ -1575,6 +1575,11 @@ static int setup_personality(int persona)
...
@@ -1575,6 +1575,11 @@ static int setup_personality(int persona)
return
0
;
return
0
;
}
}
static
inline
bool
wants_console
(
const
struct
lxc_terminal
*
terminal
)
{
return
!
terminal
->
path
||
strcmp
(
terminal
->
path
,
"none"
);
}
static
int
lxc_setup_dev_console
(
const
struct
lxc_rootfs
*
rootfs
,
static
int
lxc_setup_dev_console
(
const
struct
lxc_rootfs
*
rootfs
,
const
struct
lxc_terminal
*
console
,
const
struct
lxc_terminal
*
console
,
int
pts_mnt_fd
)
int
pts_mnt_fd
)
...
@@ -1583,7 +1588,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
...
@@ -1583,7 +1588,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
char
path
[
PATH_MAX
];
char
path
[
PATH_MAX
];
char
*
rootfs_path
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
char
*
rootfs_path
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
if
(
console
->
path
&&
!
strcmp
(
console
->
path
,
"none"
))
if
(
!
wants_console
(
console
))
return
0
;
return
0
;
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/console"
,
rootfs_path
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/console"
,
rootfs_path
);
...
@@ -1614,13 +1619,24 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
...
@@ -1614,13 +1619,24 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
if
(
ret
<
0
)
if
(
ret
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
if
(
pts_mnt_fd
>=
0
)
if
(
pts_mnt_fd
>=
0
)
{
ret
=
move_mount
(
pts_mnt_fd
,
""
,
-
EBADF
,
path
,
MOVE_MOUNT_F_EMPTY_PATH
);
ret
=
move_mount
(
pts_mnt_fd
,
""
,
-
EBADF
,
path
,
MOVE_MOUNT_F_EMPTY_PATH
);
else
if
(
!
ret
)
{
DEBUG
(
"Moved mount
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
path
);
goto
finish
;
}
if
(
ret
&&
errno
!=
ENOSYS
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
path
);
}
ret
=
safe_mount
(
console
->
name
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
ret
=
safe_mount
(
console
->
name
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
path
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
path
);
finish:
DEBUG
(
"Mounted pts device %d(%s) onto
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
path
);
DEBUG
(
"Mounted pts device %d(%s) onto
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
path
);
return
0
;
return
0
;
}
}
...
@@ -1633,7 +1649,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
...
@@ -1633,7 +1649,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
char
path
[
PATH_MAX
],
lxcpath
[
PATH_MAX
];
char
path
[
PATH_MAX
],
lxcpath
[
PATH_MAX
];
char
*
rootfs_path
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
char
*
rootfs_path
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
if
(
console
->
path
&&
!
strcmp
(
console
->
path
,
"none"
))
if
(
!
wants_console
(
console
))
return
0
;
return
0
;
/* create rootfs/dev/<ttydir> directory */
/* create rootfs/dev/<ttydir> directory */
...
@@ -1675,14 +1691,25 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
...
@@ -1675,14 +1691,25 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
/* bind mount console->name to '/dev/<ttydir>/console' */
/* bind mount console->name to '/dev/<ttydir>/console' */
if
(
pts_mnt_fd
>=
0
)
if
(
pts_mnt_fd
>=
0
)
{
ret
=
move_mount
(
pts_mnt_fd
,
""
,
-
EBADF
,
path
,
MOVE_MOUNT_F_EMPTY_PATH
);
ret
=
move_mount
(
pts_mnt_fd
,
""
,
-
EBADF
,
lxcpath
,
MOVE_MOUNT_F_EMPTY_PATH
);
else
if
(
!
ret
)
{
DEBUG
(
"Moved mount
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
goto
finish
;
}
if
(
ret
&&
errno
!=
ENOSYS
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
lxcpath
);
}
ret
=
safe_mount
(
console
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
ret
=
safe_mount
(
console
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
lxcpath
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pts_mnt_fd
,
console
->
name
,
lxcpath
);
DEBUG
(
"Mounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
DEBUG
(
"Mounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
finish:
/* bind mount '/dev/<ttydir>/console' to '/dev/console' */
/* bind mount '/dev/<ttydir>/console' to '/dev/console' */
ret
=
safe_mount
(
lxcpath
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
ret
=
safe_mount
(
lxcpath
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -3316,11 +3343,16 @@ int lxc_setup(struct lxc_handler *handler)
...
@@ -3316,11 +3343,16 @@ int lxc_setup(struct lxc_handler *handler)
return
log_error
(
-
1
,
"Failed to send network device names and ifindices to parent"
);
return
log_error
(
-
1
,
"Failed to send network device names and ifindices to parent"
);
}
}
if
(
wants_console
(
&
lxc_conf
->
console
))
{
pts_mnt_fd
=
open_tree
(
-
EBADF
,
lxc_conf
->
console
.
name
,
pts_mnt_fd
=
open_tree
(
-
EBADF
,
lxc_conf
->
console
.
name
,
OPEN_TREE_CLONE
|
OPEN_TREE_CLOEXEC
|
AT_EMPTY_PATH
);
OPEN_TREE_CLONE
|
OPEN_TREE_CLOEXEC
|
AT_EMPTY_PATH
);
if
(
pts_mnt_fd
<
0
)
if
(
pts_mnt_fd
<
0
)
SYSTRACE
(
"Failed to create detached mount for container's console
\"
%s
\"
"
,
SYSTRACE
(
"Failed to create detached mount for container's console
\"
%s
\"
"
,
lxc_conf
->
console
.
name
);
lxc_conf
->
console
.
name
);
else
TRACE
(
"Created detached mount for container's console
\"
%s
\"
"
,
lxc_conf
->
console
.
name
);
}
if
(
lxc_conf
->
autodev
>
0
)
{
if
(
lxc_conf
->
autodev
>
0
)
{
ret
=
mount_autodev
(
name
,
&
lxc_conf
->
rootfs
,
lxc_conf
->
autodevtmpfssize
,
lxcpath
);
ret
=
mount_autodev
(
name
,
&
lxc_conf
->
rootfs
,
lxc_conf
->
autodevtmpfssize
,
lxcpath
);
...
...
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