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
86530b0a
Commit
86530b0a
authored
Jan 22, 2018
by
LiFeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix comments and add check in lxc_poll.
Add check whether handler->conf->console.path is 'none' Signed-off-by:
LiFeng
<
lifeng68@huawei.com
>
parent
3dc035f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
43 deletions
+63
-43
conf.c
src/lxc/conf.c
+33
-26
start.c
src/lxc/start.c
+30
-17
No files found.
src/lxc/conf.c
View file @
86530b0a
...
...
@@ -1565,11 +1565,12 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
{
char
path
[
MAXPATHLEN
];
int
ret
,
fd
;
char
*
rootfs_path
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
if
(
console
->
path
&&
!
strcmp
(
console
->
path
,
"none"
))
return
0
;
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/console"
,
rootfs
->
path
?
rootfs
->
mount
:
""
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/console"
,
rootfs
_path
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
return
-
1
;
...
...
@@ -1579,10 +1580,10 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
if
(
file_exists
(
path
))
{
ret
=
lxc_unstack_mountpoint
(
path
,
false
);
if
(
ret
<
0
)
{
ERROR
(
"
f
ailed to unmount
\"
%s
\"
: %s"
,
path
,
strerror
(
errno
));
ERROR
(
"
F
ailed to unmount
\"
%s
\"
: %s"
,
path
,
strerror
(
errno
));
return
-
ret
;
}
else
{
DEBUG
(
"
c
leared all (%d) mounts from
\"
%s
\"
"
,
ret
,
path
);
DEBUG
(
"
C
leared all (%d) mounts from
\"
%s
\"
"
,
ret
,
path
);
}
}
...
...
@@ -1592,24 +1593,26 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
fd
=
open
(
path
,
O_CREAT
|
O_EXCL
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
);
if
(
fd
<
0
)
{
if
(
errno
!=
EEXIST
)
{
SYSERROR
(
"
f
ailed to create console"
);
SYSERROR
(
"
F
ailed to create console"
);
return
-
errno
;
}
}
else
{
close
(
fd
);
}
if
(
chmod
(
console
->
name
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
))
{
SYSERROR
(
"failed to set mode '0%o' to '%s'"
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
,
console
->
name
);
ret
=
chmod
(
console
->
name
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to set mode '0%o' to '%s'"
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
,
console
->
name
);
return
-
errno
;
}
if
(
safe_mount
(
console
->
name
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs
->
path
?
rootfs
->
mount
:
""
)
<
0
)
{
ERROR
(
"failed to mount '%s' on '%s'"
,
console
->
name
,
path
);
ret
=
safe_mount
(
console
->
name
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to mount '%s' on '%s'"
,
console
->
name
,
path
);
return
-
1
;
}
DEBUG
(
"
m
ounted pts device
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
path
);
DEBUG
(
"
M
ounted pts device
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
path
);
return
0
;
}
...
...
@@ -1619,78 +1622,82 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
{
int
ret
,
fd
;
char
path
[
MAXPATHLEN
],
lxcpath
[
MAXPATHLEN
];
char
*
rootfs_path
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
if
(
console
->
path
&&
!
strcmp
(
console
->
path
,
"none"
))
return
0
;
/* create rootfs/dev/<ttydir> directory */
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/%s"
,
rootfs
->
path
?
rootfs
->
mount
:
""
,
ttydir
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/%s"
,
rootfs
_path
,
ttydir
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
return
-
1
;
ret
=
mkdir
(
path
,
0755
);
if
(
ret
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"
f
ailed with errno %d to create %s"
,
errno
,
path
);
SYSERROR
(
"
F
ailed with errno %d to create %s"
,
errno
,
path
);
return
-
errno
;
}
DEBUG
(
"Created directory for console and tty devices at
\"
%s
\"
"
,
path
);
ret
=
snprintf
(
lxcpath
,
sizeof
(
lxcpath
),
"%s/dev/%s/console"
,
rootfs
->
path
?
rootfs
->
mount
:
""
,
ttydir
);
ret
=
snprintf
(
lxcpath
,
sizeof
(
lxcpath
),
"%s/dev/%s/console"
,
rootfs
_path
,
ttydir
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
lxcpath
))
return
-
1
;
ret
=
creat
(
lxcpath
,
0660
);
if
(
ret
==
-
1
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"
e
rror %d creating %s"
,
errno
,
lxcpath
);
SYSERROR
(
"
E
rror %d creating %s"
,
errno
,
lxcpath
);
return
-
errno
;
}
if
(
ret
>=
0
)
close
(
ret
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/console"
,
rootfs
->
path
?
rootfs
->
mount
:
""
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/console"
,
rootfs
_path
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
return
-
1
;
if
(
file_exists
(
path
))
{
ret
=
lxc_unstack_mountpoint
(
path
,
false
);
if
(
ret
<
0
)
{
ERROR
(
"
f
ailed to unmount
\"
%s
\"
: %s"
,
path
,
strerror
(
errno
));
ERROR
(
"
F
ailed to unmount
\"
%s
\"
: %s"
,
path
,
strerror
(
errno
));
return
-
ret
;
}
else
{
DEBUG
(
"
c
leared all (%d) mounts from
\"
%s
\"
"
,
ret
,
path
);
DEBUG
(
"
C
leared all (%d) mounts from
\"
%s
\"
"
,
ret
,
path
);
}
}
fd
=
open
(
path
,
O_CREAT
|
O_EXCL
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
);
if
(
fd
<
0
)
{
if
(
errno
!=
EEXIST
)
{
SYSERROR
(
"
f
ailed to create console"
);
SYSERROR
(
"
F
ailed to create console"
);
return
-
errno
;
}
}
else
{
close
(
fd
);
}
if
(
chmod
(
console
->
name
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
))
{
SYSERROR
(
"failed to set mode '0%o' to '%s'"
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
,
console
->
name
);
ret
=
chmod
(
console
->
name
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to set mode '0%o' to '%s'"
,
S_IXUSR
|
S_IXGRP
|
S_IXOTH
,
console
->
name
);
return
-
errno
;
}
/* bind mount console->name to '/dev/<ttydir>/console' */
if
(
safe_mount
(
console
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
,
rootfs
->
path
?
rootfs
->
mount
:
""
)
<
0
)
{
ERROR
(
"failed to mount '%s' on '%s'"
,
console
->
name
,
lxcpath
);
ret
=
safe_mount
(
console
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to mount '%s' on '%s'"
,
console
->
name
,
lxcpath
);
return
-
1
;
}
DEBUG
(
"
m
ounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
DEBUG
(
"
M
ounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
/* bind mount '/dev/<ttydir>/console' to '/dev/console' */
if
(
safe_mount
(
lxcpath
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs
->
path
?
rootfs
->
mount
:
""
)
<
0
)
{
ERROR
(
"failed to mount '%s' on '%s'"
,
console
->
name
,
lxcpath
);
ret
=
safe_mount
(
lxcpath
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to mount '%s' on '%s'"
,
console
->
name
,
lxcpath
);
return
-
1
;
}
DEBUG
(
"
m
ounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
DEBUG
(
"
M
ounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
DEBUG
(
"
c
onsole has been setup under
\"
%s
\"
and mounted to
\"
%s
\"
"
,
lxcpath
,
path
);
DEBUG
(
"
C
onsole has been setup under
\"
%s
\"
and mounted to
\"
%s
\"
"
,
lxcpath
,
path
);
return
0
;
}
...
...
src/lxc/start.c
View file @
86530b0a
...
...
@@ -472,19 +472,24 @@ int lxc_set_state(const char *name, struct lxc_handler *handler,
int
lxc_poll
(
const
char
*
name
,
struct
lxc_handler
*
handler
)
{
int
ret
;
struct
lxc_console
*
console
=
&
handler
->
conf
->
consol
e
;
bool
has_console
=
tru
e
;
struct
lxc_epoll_descr
descr
,
descr_console
;
if
(
handler
->
conf
->
console
.
path
&&
!
strcmp
(
handler
->
conf
->
console
.
path
,
"none"
))
has_console
=
false
;
ret
=
lxc_mainloop_open
(
&
descr
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create mainloop"
);
goto
out_sigfd
;
}
ret
=
lxc_mainloop_open
(
&
descr_console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create console mainloop"
);
goto
out_mainloop
;
if
(
has_console
)
{
ret
=
lxc_mainloop_open
(
&
descr_console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create console mainloop"
);
goto
out_mainloop
;
}
}
ret
=
lxc_mainloop_add_handler
(
&
descr
,
handler
->
sigfd
,
signal_handler
,
handler
);
...
...
@@ -493,16 +498,20 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
goto
out_mainloop_console
;
}
ret
=
lxc_console_mainloop_add
(
&
descr
,
console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to add console handlers to mainloop"
);
goto
out_mainloop_console
;
}
if
(
has_console
)
{
struct
lxc_console
*
console
=
&
handler
->
conf
->
console
;
ret
=
lxc_console_mainloop_add
(
&
descr_console
,
console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to add console handlers to console mainloop"
);
goto
out_mainloop_console
;
ret
=
lxc_console_mainloop_add
(
&
descr
,
console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to add console handlers to mainloop"
);
goto
out_mainloop_console
;
}
ret
=
lxc_console_mainloop_add
(
&
descr_console
,
console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to add console handlers to console mainloop"
);
goto
out_mainloop_console
;
}
}
ret
=
lxc_cmd_mainloop_add
(
name
,
&
descr
,
handler
);
...
...
@@ -519,15 +528,19 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
if
(
ret
<
0
||
!
handler
->
init_died
)
goto
out_mainloop
;
ret
=
lxc_mainloop
(
&
descr_console
,
0
);
if
(
has_console
)
ret
=
lxc_mainloop
(
&
descr_console
,
0
);
out_mainloop:
lxc_mainloop_close
(
&
descr
);
TRACE
(
"Closed mainloop"
);
out_mainloop_console:
lxc_mainloop_close
(
&
descr_console
);
TRACE
(
"Closed console mainloop"
);
if
(
has_console
)
{
lxc_mainloop_close
(
&
descr_console
);
TRACE
(
"Closed console mainloop"
);
}
out_sigfd:
close
(
handler
->
sigfd
);
...
...
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