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
dc46df1e
Commit
dc46df1e
authored
Apr 21, 2017
by
Stéphane Graber
Committed by
GitHub
Apr 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1519 from brauner/2017-04-21/setup_pts
conf: use bind-mount for /dev/ptmx
parents
68a1e26c
d5cb35d6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
23 deletions
+59
-23
conf.c
src/lxc/conf.c
+59
-23
No files found.
src/lxc/conf.c
View file @
dc46df1e
...
...
@@ -1453,50 +1453,86 @@ static int setup_pivot_root(const struct lxc_rootfs *rootfs)
return
0
;
}
static
int
setup_pts
(
int
pts
)
static
int
lxc_setup_devpts
(
int
num_
pts
)
{
char
target
[
PATH_MAX
];
int
ret
;
const
char
*
devpts_mntopts
=
"newinstance,ptmxmode=0666,mode=0620,gid=5"
;
if
(
!
pts
)
if
(
!
num_pts
)
{
DEBUG
(
"no new devpts instance will be mounted since no pts "
"devices are requested"
);
return
0
;
}
if
(
!
access
(
"/dev/pts/ptmx"
,
F_OK
)
&&
umount
(
"/dev/pts"
))
{
SYSERROR
(
"failed to umount 'dev/pts'"
);
/* Unmount old devpts instance. */
ret
=
access
(
"/dev/pts/ptmx"
,
F_OK
);
if
(
!
ret
)
{
ret
=
umount
(
"/dev/pts"
);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to unmount old devpts instance"
);
return
-
1
;
}
DEBUG
(
"unmounted old /dev/pts instance"
);
}
if
(
mkdir
(
"/dev/pts"
,
0755
))
{
if
(
errno
!=
EEXIST
)
{
SYSERROR
(
"failed to create '/dev/pts'"
);
/* Create mountpoint for devpts instance. */
ret
=
mkdir
(
"/dev/pts"
,
0755
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"failed to create the
\"
/dev/pts
\"
directory"
);
return
-
1
;
}
/* Mount new devpts instance. */
ret
=
mount
(
"devpts"
,
"/dev/pts"
,
"devpts"
,
MS_MGC_VAL
,
devpts_mntopts
);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to mount new devpts instance"
);
return
-
1
;
}
if
(
mount
(
"devpts"
,
"/dev/pts"
,
"devpts"
,
MS_MGC_VAL
,
"newinstance,ptmxmode=0666,mode=0620,gid=5"
))
{
SYSERROR
(
"failed to mount a new instance of '/dev/pts'"
);
/* Remove any pre-existing /dev/ptmx file. */
ret
=
access
(
"/dev/ptmx"
,
F_OK
);
if
(
!
ret
)
{
ret
=
remove
(
"/dev/ptmx"
);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to remove existing
\"
/dev/ptmx
\"
"
);
return
-
1
;
}
DEBUG
(
"removed existing
\"
/dev/ptmx
\"
"
);
}
if
(
access
(
"/dev/ptmx"
,
F_OK
))
{
if
(
!
symlink
(
"/dev/pts/ptmx"
,
"/dev/ptmx"
))
goto
out
;
SYSERROR
(
"failed to
symlink '/dev/pts/ptmx'->'/dev/ptmx'
"
);
/* Create dummy /dev/ptmx file as bind mountpoint for /dev/pts/ptmx. */
ret
=
open
(
"/dev/ptmx"
,
O_CREAT
,
0666
);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to
create dummy
\"
/dev/ptmx
\"
file as bind mount target
"
);
return
-
1
;
}
DEBUG
(
"created dummy
\"
/dev/ptmx
\"
file as bind mount target"
);
if
(
realpath
(
"/dev/ptmx"
,
target
)
&&
!
strcmp
(
target
,
"/dev/pts/ptmx"
))
goto
out
;
/* Fallback option: create symlink /dev/ptmx -> /dev/pts/ptmx */
ret
=
mount
(
"/dev/pts/ptmx"
,
"/dev/ptmx"
,
"none"
,
MS_BIND
,
0
);
if
(
!
ret
)
{
DEBUG
(
"bind mounted
\"
/dev/pts/ptmx
\"
to
\"
/dev/ptmx
\"
"
);
return
0
;
}
else
{
/* Fallthrough and try to create a symlink. */
ERROR
(
"failed to bind mount
\"
/dev/pts/ptmx
\"
to
\"
/dev/ptmx
\"
"
);
}
/* fallback here, /dev/pts/ptmx exists just mount bind */
if
(
mount
(
"/dev/pts/ptmx"
,
"/dev/ptmx"
,
"none"
,
MS_BIND
,
0
))
{
SYSERROR
(
"mount failed '/dev/pts/ptmx'->'/dev/ptmx'"
);
/* Remove the dummy /dev/ptmx file we created above. */
ret
=
remove
(
"/dev/ptmx"
);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to remove existing
\"
/dev/ptmx
\"
"
);
return
-
1
;
}
INFO
(
"created new pts instance"
);
/* Fallback option: Create symlink /dev/ptmx -> /dev/pts/ptmx. */
ret
=
symlink
(
"/dev/pts/ptmx"
,
"/dev/ptmx"
);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to create symlink
\"
/dev/ptmx
\"
->
\"
/dev/pts/ptmx
\"
"
);
return
-
1
;
}
DEBUG
(
"created symlink
\"
/dev/ptmx
\"
->
\"
/dev/pts/ptmx
\"
"
);
out:
return
0
;
}
...
...
@@ -4114,7 +4150,7 @@ int lxc_setup(struct lxc_handler *handler)
return
-
1
;
}
if
(
setup_
pts
(
lxc_conf
->
pts
))
{
if
(
lxc_setup_dev
pts
(
lxc_conf
->
pts
))
{
ERROR
(
"failed to setup the new pts instance"
);
return
-
1
;
}
...
...
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