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
c0614b0c
Commit
c0614b0c
authored
Apr 28, 2017
by
Serge Hallyn
Committed by
GitHub
Apr 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1529 from brauner/2017-04-28/create_proc_if_missing
utils: tweak lxc_mount_proc_if_needed()
parents
1545a1f1
fc2ad9dc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
16 deletions
+28
-16
conf.c
src/lxc/conf.c
+8
-7
utils.c
src/lxc/utils.c
+19
-8
utils.h
src/lxc/utils.h
+1
-1
No files found.
src/lxc/conf.c
View file @
c0614b0c
...
@@ -3760,20 +3760,21 @@ int ttys_shift_ids(struct lxc_conf *c)
...
@@ -3760,20 +3760,21 @@ int ttys_shift_ids(struct lxc_conf *c)
return
0
;
return
0
;
}
}
/* NOTE:
not to
be called from inside the container namespace! */
/* NOTE:
Must not
be called from inside the container namespace! */
int
tmp_proc_mount
(
struct
lxc_conf
*
lxc_
conf
)
int
lxc_create_tmp_proc_mount
(
struct
lxc_conf
*
conf
)
{
{
int
mounted
;
int
mounted
;
mounted
=
mount_proc_if_needed
(
lxc_conf
->
rootfs
.
path
?
lxc_
conf
->
rootfs
.
mount
:
""
);
mounted
=
lxc_mount_proc_if_needed
(
conf
->
rootfs
.
path
?
conf
->
rootfs
.
mount
:
""
);
if
(
mounted
==
-
1
)
{
if
(
mounted
==
-
1
)
{
SYSERROR
(
"failed to mount /proc in the container
.
"
);
SYSERROR
(
"failed to mount /proc in the container"
);
/* continue only if there is no rootfs */
/* continue only if there is no rootfs */
if
(
lxc_
conf
->
rootfs
.
path
)
if
(
conf
->
rootfs
.
path
)
return
-
1
;
return
-
1
;
}
else
if
(
mounted
==
1
)
{
}
else
if
(
mounted
==
1
)
{
lxc_
conf
->
tmp_umount_proc
=
1
;
conf
->
tmp_umount_proc
=
1
;
}
}
return
0
;
return
0
;
}
}
...
@@ -4063,7 +4064,7 @@ int lxc_setup(struct lxc_handler *handler)
...
@@ -4063,7 +4064,7 @@ int lxc_setup(struct lxc_handler *handler)
}
}
/* mount /proc if it's not already there */
/* mount /proc if it's not already there */
if
(
tmp_proc_mount
(
lxc_conf
)
<
0
)
{
if
(
lxc_create_
tmp_proc_mount
(
lxc_conf
)
<
0
)
{
ERROR
(
"failed to LSM mount proc for '%s'"
,
name
);
ERROR
(
"failed to LSM mount proc for '%s'"
,
name
);
return
-
1
;
return
-
1
;
}
}
...
...
src/lxc/utils.c
View file @
c0614b0c
...
@@ -1754,7 +1754,7 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
...
@@ -1754,7 +1754,7 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
*
*
* NOTE: not to be called from inside the container namespace!
* NOTE: not to be called from inside the container namespace!
*/
*/
int
mount_proc_if_needed
(
const
char
*
rootfs
)
int
lxc_
mount_proc_if_needed
(
const
char
*
rootfs
)
{
{
char
path
[
MAXPATHLEN
];
char
path
[
MAXPATHLEN
];
char
link
[
20
];
char
link
[
20
];
...
@@ -1766,37 +1766,48 @@ int mount_proc_if_needed(const char *rootfs)
...
@@ -1766,37 +1766,48 @@ int mount_proc_if_needed(const char *rootfs)
SYSERROR
(
"proc path name too long"
);
SYSERROR
(
"proc path name too long"
);
return
-
1
;
return
-
1
;
}
}
memset
(
link
,
0
,
20
);
memset
(
link
,
0
,
20
);
linklen
=
readlink
(
path
,
link
,
20
);
linklen
=
readlink
(
path
,
link
,
20
);
mypid
=
(
int
)
getpid
();
mypid
=
(
int
)
getpid
();
INFO
(
"I am %d, /proc/self points to '%s'"
,
mypid
,
link
);
INFO
(
"I am %d, /proc/self points to
\"
%s
\"
"
,
mypid
,
link
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/proc"
,
rootfs
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/proc"
,
rootfs
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
{
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
{
SYSERROR
(
"proc path name too long"
);
SYSERROR
(
"proc path name too long"
);
return
-
1
;
return
-
1
;
}
}
if
(
linklen
<
0
)
/* /proc not mounted */
/* /proc not mounted */
if
(
linklen
<
0
)
{
if
(
mkdir
(
path
,
0755
)
&&
errno
!=
EEXIST
)
return
-
1
;
goto
domount
;
goto
domount
;
}
if
(
lxc_safe_int
(
link
,
&
link_to_pid
)
<
0
)
if
(
lxc_safe_int
(
link
,
&
link_to_pid
)
<
0
)
return
-
1
;
return
-
1
;
if
(
link_to_pid
!=
mypid
)
{
/* wrong /procs mounted */
/* wrong /procs mounted */
umount2
(
path
,
MNT_DETACH
);
/* ignore failure */
if
(
link_to_pid
!=
mypid
)
{
/* ignore failure */
umount2
(
path
,
MNT_DETACH
);
goto
domount
;
goto
domount
;
}
}
/* the right proc is already mounted */
/* the right proc is already mounted */
return
0
;
return
0
;
domount
:
domount
:
if
(
!
strcmp
(
rootfs
,
""
))
/* rootfs is NULL */
/* rootfs is NULL */
if
(
!
strcmp
(
rootfs
,
""
))
ret
=
mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
);
ret
=
mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
);
else
else
ret
=
safe_mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
,
rootfs
);
ret
=
safe_mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
,
rootfs
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
INFO
(
"
M
ounted /proc in container for security transition"
);
INFO
(
"
m
ounted /proc in container for security transition"
);
return
1
;
return
1
;
}
}
...
...
src/lxc/utils.h
View file @
c0614b0c
...
@@ -326,7 +326,7 @@ char *get_template_path(const char *t);
...
@@ -326,7 +326,7 @@ char *get_template_path(const char *t);
int
setproctitle
(
char
*
title
);
int
setproctitle
(
char
*
title
);
int
safe_mount
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
fstype
,
int
safe_mount
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
fstype
,
unsigned
long
flags
,
const
void
*
data
,
const
char
*
rootfs
);
unsigned
long
flags
,
const
void
*
data
,
const
char
*
rootfs
);
int
mount_proc_if_needed
(
const
char
*
rootfs
);
int
lxc_
mount_proc_if_needed
(
const
char
*
rootfs
);
int
open_devnull
(
void
);
int
open_devnull
(
void
);
int
set_stdfds
(
int
fd
);
int
set_stdfds
(
int
fd
);
int
null_stdfds
(
void
);
int
null_stdfds
(
void
);
...
...
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