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
184de6b8
Unverified
Commit
184de6b8
authored
Jul 05, 2020
by
Stéphane Graber
Committed by
GitHub
Jul 05, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3477 from brauner/2020-07-05/fixes
tree-wide: update terminal terminology once more
parents
3e519859
41808e20
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
192 additions
and
192 deletions
+192
-192
lxc.container.conf.sgml.in
doc/ja/lxc.container.conf.sgml.in
+2
-2
lxc.container.conf.sgml.in
doc/ko/lxc.container.conf.sgml.in
+1
-1
lxc.container.conf.sgml.in
doc/lxc.container.conf.sgml.in
+1
-1
openpty.c
src/include/openpty.c
+15
-15
openpty.h
src/include/openpty.h
+3
-3
attach.c
src/lxc/attach.c
+5
-5
commands.c
src/lxc/commands.c
+9
-9
commands.h
src/lxc/commands.h
+1
-1
conf.c
src/lxc/conf.c
+43
-43
criu.c
src/lxc/criu.c
+2
-2
lxccontainer.c
src/lxc/lxccontainer.c
+2
-2
lxccontainer.h
src/lxc/lxccontainer.h
+2
-2
start.c
src/lxc/start.c
+8
-8
terminal.c
src/lxc/terminal.c
+70
-70
terminal.h
src/lxc/terminal.h
+16
-16
console.c
src/tests/console.c
+12
-12
No files found.
doc/ja/lxc.container.conf.sgml.in
View file @
184de6b8
...
...
@@ -1152,11 +1152,11 @@ by KATOH Yasufumi <karma at jazz.email.ne.jp>
<!--
If set, the container will have a new pseudo tty
instance, making this private to it. The value specifies
the maximum number of pseudo ttys allowed for a pt
s
the maximum number of pseudo ttys allowed for a pt
y
instance (this limitation is not implemented yet).
-->
もし設定された場合、コンテナは新しい pseudo tty インスタンスを持ち、それを自身のプライベートとします。
この値は pt
s
インスタンスに許可される pseudo tty の最大数を指定します (この制限はまだ実装されていません)。
この値は pt
y
インスタンスに許可される pseudo tty の最大数を指定します (この制限はまだ実装されていません)。
</para>
</listitem>
</varlistentry>
...
...
doc/ko/lxc.container.conf.sgml.in
View file @
184de6b8
...
...
@@ -844,7 +844,7 @@ by Sungbae Yoo <sungbae.yoo at samsung.com>
<!--
If set, the container will have a new pseudo tty
instance, making this private to it. The value specifies
the maximum number of pseudo ttys allowed for a pt
s
the maximum number of pseudo ttys allowed for a pt
y
instance (this limitation is not implemented yet).
-->
만약 지정되었다면, 컨테이너는 새 pseudo tty 인스턴스를 갖는다. 그리고 이것을 자기자신 전용으로 만든다. 지정하는 값은 pseudo tty의 최대 개수를 지정한다. (이 제한은 아직 구현되지 않았다)
...
...
doc/lxc.container.conf.sgml.in
View file @
184de6b8
...
...
@@ -873,7 +873,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<para>
If set, the container will have a new pseudo tty
instance, making this private to it. The value specifies
the maximum number of pseudo ttys allowed for a pt
s
the maximum number of pseudo ttys allowed for a pt
y
instance (this limitation is not implemented yet).
</para>
</listitem>
...
...
src/include/openpty.c
View file @
184de6b8
...
...
@@ -32,45 +32,45 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#define _PATH_DEVPTMX "/dev/pt
m
x"
#define _PATH_DEVPTMX "/dev/ptx"
int
openpty
(
int
*
apt
m
x
,
int
*
apts
,
char
*
name
,
struct
termios
*
termp
,
int
openpty
(
int
*
aptx
,
int
*
apts
,
char
*
name
,
struct
termios
*
termp
,
struct
winsize
*
winp
)
{
char
buf
[
PATH_MAX
];
int
pt
mx
,
pts
;
int
pt
x
,
pty
;
pt
m
x
=
open
(
_PATH_DEVPTMX
,
O_RDWR
);
if
(
pt
m
x
==
-
1
)
ptx
=
open
(
_PATH_DEVPTMX
,
O_RDWR
);
if
(
ptx
==
-
1
)
return
-
1
;
if
(
grantpt
(
pt
m
x
))
if
(
grantpt
(
ptx
))
goto
fail
;
if
(
unlockpt
(
pt
m
x
))
if
(
unlockpt
(
ptx
))
goto
fail
;
if
(
pt
sname_r
(
ptm
x
,
buf
,
sizeof
buf
))
if
(
pt
yname_r
(
pt
x
,
buf
,
sizeof
buf
))
goto
fail
;
pt
s
=
open
(
buf
,
O_RDWR
|
O_NOCTTY
);
if
(
pt
s
==
-
1
)
pt
y
=
open
(
buf
,
O_RDWR
|
O_NOCTTY
);
if
(
pt
y
==
-
1
)
goto
fail
;
/* XXX Should we ignore errors here? */
if
(
termp
)
tcsetattr
(
pt
s
,
TCSAFLUSH
,
termp
);
tcsetattr
(
pt
y
,
TCSAFLUSH
,
termp
);
if
(
winp
)
ioctl
(
pt
s
,
TIOCSWINSZ
,
winp
);
ioctl
(
pt
y
,
TIOCSWINSZ
,
winp
);
*
apt
mx
=
ptm
x
;
*
apts
=
pt
s
;
*
apt
x
=
pt
x
;
*
apts
=
pt
y
;
if
(
name
!=
NULL
)
strcpy
(
name
,
buf
);
return
0
;
fail:
close
(
pt
m
x
);
close
(
ptx
);
return
-
1
;
}
src/include/openpty.h
View file @
184de6b8
...
...
@@ -28,11 +28,11 @@
#include <sys/ioctl.h>
/*
* Create pseudo tty pt
mx pts
pair with @__name and set terminal
* Create pseudo tty pt
x pty
pair with @__name and set terminal
* attributes according to @__termp and @__winp and return handles for both
* ends in @__apt
m
x and @__apts.
* ends in @__aptx and @__apts.
*/
extern
int
openpty
(
int
*
__apt
m
x
,
int
*
__apts
,
char
*
__name
,
extern
int
openpty
(
int
*
__aptx
,
int
*
__apts
,
char
*
__name
,
const
struct
termios
*
__termp
,
const
struct
winsize
*
__winp
);
...
...
src/lxc/attach.c
View file @
184de6b8
...
...
@@ -932,14 +932,14 @@ static int lxc_attach_terminal_mainloop_init(struct lxc_terminal *terminal,
return
0
;
}
static
inline
void
lxc_attach_terminal_close_pt
m
x
(
struct
lxc_terminal
*
terminal
)
static
inline
void
lxc_attach_terminal_close_ptx
(
struct
lxc_terminal
*
terminal
)
{
close_prot_errno_disarm
(
terminal
->
pt
m
x
);
close_prot_errno_disarm
(
terminal
->
ptx
);
}
static
inline
void
lxc_attach_terminal_close_pts
(
struct
lxc_terminal
*
terminal
)
{
close_prot_errno_disarm
(
terminal
->
pt
s
);
close_prot_errno_disarm
(
terminal
->
pt
y
);
}
static
inline
void
lxc_attach_terminal_close_peer
(
struct
lxc_terminal
*
terminal
)
...
...
@@ -1332,7 +1332,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
close_prot_errno_disarm
(
ipc_sockets
[
0
]);
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
{
lxc_attach_terminal_close_pt
m
x
(
&
terminal
);
lxc_attach_terminal_close_ptx
(
&
terminal
);
lxc_attach_terminal_close_peer
(
&
terminal
);
lxc_attach_terminal_close_log
(
&
terminal
);
}
...
...
@@ -1377,7 +1377,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
payload
.
ipc_socket
=
ipc_sockets
[
1
];
payload
.
options
=
options
;
payload
.
init_ctx
=
init_ctx
;
payload
.
terminal_pts_fd
=
terminal
.
pt
s
;
payload
.
terminal_pts_fd
=
terminal
.
pt
y
;
payload
.
exec_function
=
exec_function
;
payload
.
exec_payload
=
exec_payload
;
...
...
src/lxc/commands.c
View file @
184de6b8
...
...
@@ -108,7 +108,7 @@ static const char *lxc_cmd_str(lxc_cmd_t cmd)
* stored directly in data and datalen will be 0.
*
* As a special case, the response for LXC_CMD_CONSOLE is created
* here as it contains an fd for the pt
m
x pty passed through the
* here as it contains an fd for the ptx pty passed through the
* unix socket.
*/
static
int
lxc_cmd_rsp_recv
(
int
sock
,
struct
lxc_cmd_rr
*
cmd
)
...
...
@@ -139,7 +139,7 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd)
ENOMEM
,
"Failed to receive response for command
\"
%s
\"
"
,
lxc_cmd_str
(
cmd
->
req
.
cmd
));
rspdata
->
pt
m
xfd
=
move_fd
(
fd_rsp
);
rspdata
->
ptxfd
=
move_fd
(
fd_rsp
);
rspdata
->
ttynum
=
PTR_TO_INT
(
rsp
->
data
);
rsp
->
data
=
rspdata
;
}
...
...
@@ -844,7 +844,7 @@ static int lxc_cmd_terminal_winch_callback(int fd, struct lxc_cmd_req *req,
* @name : name of container to connect to
* @ttynum : in: the tty to open or -1 for next available
* : out: the tty allocated
* @fd : out: file descriptor for pt
m
x side of pty
* @fd : out: file descriptor for ptx side of pty
* @lxcpath : the lxcpath in which the container is running
*
* Returns fd holding tty allocated on success, < 0 on failure
...
...
@@ -871,11 +871,11 @@ int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath)
if
(
ret
==
0
)
return
log_error
(
-
1
,
"tty number %d invalid, busy or all ttys busy"
,
*
ttynum
);
if
(
rspdata
->
pt
m
xfd
<
0
)
if
(
rspdata
->
ptxfd
<
0
)
return
log_error
(
-
1
,
"Unable to allocate fd for tty %d"
,
rspdata
->
ttynum
);
ret
=
cmd
.
rsp
.
ret
;
/* socket fd */
*
fd
=
rspdata
->
pt
m
xfd
;
*
fd
=
rspdata
->
ptxfd
;
*
ttynum
=
rspdata
->
ttynum
;
return
log_info
(
ret
,
"Alloced fd %d for tty %d via socket %d"
,
*
fd
,
rspdata
->
ttynum
,
ret
);
...
...
@@ -885,17 +885,17 @@ static int lxc_cmd_console_callback(int fd, struct lxc_cmd_req *req,
struct
lxc_handler
*
handler
,
struct
lxc_epoll_descr
*
descr
)
{
int
pt
m
xfd
,
ret
;
int
ptxfd
,
ret
;
struct
lxc_cmd_rsp
rsp
;
int
ttynum
=
PTR_TO_INT
(
req
->
data
);
pt
m
xfd
=
lxc_terminal_allocate
(
handler
->
conf
,
fd
,
&
ttynum
);
if
(
pt
m
xfd
<
0
)
ptxfd
=
lxc_terminal_allocate
(
handler
->
conf
,
fd
,
&
ttynum
);
if
(
ptxfd
<
0
)
return
LXC_CMD_REAP_CLIENT_FD
;
memset
(
&
rsp
,
0
,
sizeof
(
rsp
));
rsp
.
data
=
INT_TO_PTR
(
ttynum
);
ret
=
lxc_abstract_unix_send_fds
(
fd
,
&
pt
m
xfd
,
1
,
&
rsp
,
sizeof
(
rsp
));
ret
=
lxc_abstract_unix_send_fds
(
fd
,
&
ptxfd
,
1
,
&
rsp
,
sizeof
(
rsp
));
if
(
ret
<
0
)
{
lxc_terminal_free
(
handler
->
conf
,
fd
);
return
log_error_errno
(
LXC_CMD_REAP_CLIENT_FD
,
errno
,
...
...
src/lxc/commands.h
View file @
184de6b8
...
...
@@ -61,7 +61,7 @@ struct lxc_cmd_rr {
};
struct
lxc_cmd_console_rsp_data
{
int
pt
m
xfd
;
int
ptxfd
;
int
ttynum
;
};
...
...
src/lxc/conf.c
View file @
184de6b8
...
...
@@ -921,33 +921,33 @@ int lxc_allocate_ttys(struct lxc_conf *conf)
for
(
size_t
i
=
0
;
i
<
ttys
->
max
;
i
++
)
{
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
tty
->
pt
m
x
=
-
EBADF
;
tty
->
pt
s
=
-
EBADF
;
ret
=
openpty
(
&
tty
->
pt
mx
,
&
tty
->
pts
,
NULL
,
NULL
,
NULL
);
tty
->
ptx
=
-
EBADF
;
tty
->
pt
y
=
-
EBADF
;
ret
=
openpty
(
&
tty
->
pt
x
,
&
tty
->
pty
,
NULL
,
NULL
,
NULL
);
if
(
ret
<
0
)
{
ttys
->
max
=
i
;
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to create tty %zu"
,
i
);
}
ret
=
ttyname_r
(
tty
->
pt
s
,
tty
->
name
,
sizeof
(
tty
->
name
));
ret
=
ttyname_r
(
tty
->
pt
y
,
tty
->
name
,
sizeof
(
tty
->
name
));
if
(
ret
<
0
)
{
ttys
->
max
=
i
;
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to retrieve name of tty %zu pt
s
"
,
i
);
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to retrieve name of tty %zu pt
y
"
,
i
);
}
DEBUG
(
"Created tty
\"
%s
\"
with pt
mx fd %d and pts
fd %d"
,
tty
->
name
,
tty
->
pt
mx
,
tty
->
pts
);
DEBUG
(
"Created tty
\"
%s
\"
with pt
x fd %d and pty
fd %d"
,
tty
->
name
,
tty
->
pt
x
,
tty
->
pty
);
/* Prevent leaking the file descriptors to the container */
ret
=
fd_cloexec
(
tty
->
pt
m
x
,
true
);
ret
=
fd_cloexec
(
tty
->
ptx
,
true
);
if
(
ret
<
0
)
SYSWARN
(
"Failed to set FD_CLOEXEC flag on pt
m
x fd %d of tty device
\"
%s
\"
"
,
tty
->
pt
m
x
,
tty
->
name
);
SYSWARN
(
"Failed to set FD_CLOEXEC flag on ptx fd %d of tty device
\"
%s
\"
"
,
tty
->
ptx
,
tty
->
name
);
ret
=
fd_cloexec
(
tty
->
pt
s
,
true
);
ret
=
fd_cloexec
(
tty
->
pt
y
,
true
);
if
(
ret
<
0
)
SYSWARN
(
"Failed to set FD_CLOEXEC flag on pt
s
fd %d of tty device
\"
%s
\"
"
,
tty
->
pt
s
,
tty
->
name
);
SYSWARN
(
"Failed to set FD_CLOEXEC flag on pt
y
fd %d of tty device
\"
%s
\"
"
,
tty
->
pt
y
,
tty
->
name
);
tty
->
busy
=
-
1
;
}
...
...
@@ -964,8 +964,8 @@ void lxc_delete_tty(struct lxc_tty_info *ttys)
for
(
int
i
=
0
;
i
<
ttys
->
max
;
i
++
)
{
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
close_prot_errno_disarm
(
tty
->
pt
m
x
);
close_prot_errno_disarm
(
tty
->
pt
s
);
close_prot_errno_disarm
(
tty
->
ptx
);
close_prot_errno_disarm
(
tty
->
pt
y
);
}
free_disarm
(
ttys
->
tty
);
...
...
@@ -986,15 +986,15 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
int
ttyfds
[
2
];
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
ttyfds
[
0
]
=
tty
->
pt
m
x
;
ttyfds
[
1
]
=
tty
->
pt
s
;
ttyfds
[
0
]
=
tty
->
ptx
;
ttyfds
[
1
]
=
tty
->
pt
y
;
ret
=
lxc_abstract_unix_send_fds
(
sock
,
ttyfds
,
2
,
NULL
,
0
);
if
(
ret
<
0
)
break
;
TRACE
(
"Sent tty
\"
%s
\"
with pt
mx fd %d and pts
fd %d to parent"
,
tty
->
name
,
tty
->
pt
mx
,
tty
->
pts
);
TRACE
(
"Sent tty
\"
%s
\"
with pt
x fd %d and pty
fd %d to parent"
,
tty
->
name
,
tty
->
pt
x
,
tty
->
pty
);
}
if
(
ret
<
0
)
...
...
@@ -1582,7 +1582,7 @@ static inline bool wants_console(const struct lxc_terminal *terminal)
static
int
lxc_setup_dev_console
(
const
struct
lxc_rootfs
*
rootfs
,
const
struct
lxc_terminal
*
console
,
int
pt
s
_mnt_fd
)
int
pt
y
_mnt_fd
)
{
int
ret
;
char
path
[
PATH_MAX
];
...
...
@@ -1615,12 +1615,12 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create console"
);
ret
=
fchmod
(
console
->
pt
s
,
S_IXUSR
|
S_IXGRP
);
ret
=
fchmod
(
console
->
pt
y
,
S_IXUSR
|
S_IXGRP
);
if
(
ret
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
if
(
pt
s
_mnt_fd
>=
0
)
{
ret
=
move_mount
(
pt
s
_mnt_fd
,
""
,
-
EBADF
,
path
,
MOVE_MOUNT_F_EMPTY_PATH
);
if
(
pt
y
_mnt_fd
>=
0
)
{
ret
=
move_mount
(
pt
y
_mnt_fd
,
""
,
-
EBADF
,
path
,
MOVE_MOUNT_F_EMPTY_PATH
);
if
(
!
ret
)
{
DEBUG
(
"Moved mount
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
path
);
goto
finish
;
...
...
@@ -1629,21 +1629,21 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
if
(
ret
&&
errno
!=
ENOSYS
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pt
s
_mnt_fd
,
console
->
name
,
path
);
pt
y
_mnt_fd
,
console
->
name
,
path
);
}
ret
=
safe_mount
(
console
->
name
,
path
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pt
s
_mnt_fd
,
console
->
name
,
path
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pt
y
_mnt_fd
,
console
->
name
,
path
);
finish:
DEBUG
(
"Mounted pt
s device %d(%s) onto
\"
%s
\"
"
,
pts
_mnt_fd
,
console
->
name
,
path
);
DEBUG
(
"Mounted pt
y device %d(%s) onto
\"
%s
\"
"
,
pty
_mnt_fd
,
console
->
name
,
path
);
return
0
;
}
static
int
lxc_setup_ttydir_console
(
const
struct
lxc_rootfs
*
rootfs
,
const
struct
lxc_terminal
*
console
,
char
*
ttydir
,
int
pt
s
_mnt_fd
)
char
*
ttydir
,
int
pt
y
_mnt_fd
)
{
int
ret
;
char
path
[
PATH_MAX
],
lxcpath
[
PATH_MAX
];
...
...
@@ -1686,13 +1686,13 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create console"
);
ret
=
fchmod
(
console
->
pt
s
,
S_IXUSR
|
S_IXGRP
);
ret
=
fchmod
(
console
->
pt
y
,
S_IXUSR
|
S_IXGRP
);
if
(
ret
<
0
)
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' */
if
(
pt
s
_mnt_fd
>=
0
)
{
ret
=
move_mount
(
pt
s
_mnt_fd
,
""
,
-
EBADF
,
lxcpath
,
MOVE_MOUNT_F_EMPTY_PATH
);
if
(
pt
y
_mnt_fd
>=
0
)
{
ret
=
move_mount
(
pt
y
_mnt_fd
,
""
,
-
EBADF
,
lxcpath
,
MOVE_MOUNT_F_EMPTY_PATH
);
if
(
!
ret
)
{
DEBUG
(
"Moved mount
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
goto
finish
;
...
...
@@ -1701,12 +1701,12 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
if
(
ret
&&
errno
!=
ENOSYS
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pt
s
_mnt_fd
,
console
->
name
,
lxcpath
);
pt
y
_mnt_fd
,
console
->
name
,
lxcpath
);
}
ret
=
safe_mount
(
console
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
,
rootfs_path
);
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pt
s
_mnt_fd
,
console
->
name
,
lxcpath
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount %d(%s) on
\"
%s
\"
"
,
pt
y
_mnt_fd
,
console
->
name
,
lxcpath
);
DEBUG
(
"Mounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
finish:
...
...
@@ -1722,13 +1722,13 @@ finish:
static
int
lxc_setup_console
(
const
struct
lxc_rootfs
*
rootfs
,
const
struct
lxc_terminal
*
console
,
char
*
ttydir
,
int
pt
s
_mnt_fd
)
int
pt
y
_mnt_fd
)
{
if
(
!
ttydir
)
return
lxc_setup_dev_console
(
rootfs
,
console
,
pt
s
_mnt_fd
);
return
lxc_setup_dev_console
(
rootfs
,
console
,
pt
y
_mnt_fd
);
return
lxc_setup_ttydir_console
(
rootfs
,
console
,
ttydir
,
pt
s
_mnt_fd
);
return
lxc_setup_ttydir_console
(
rootfs
,
console
,
ttydir
,
pt
y
_mnt_fd
);
}
static
int
parse_mntopt
(
char
*
opt
,
unsigned
long
*
flags
,
char
**
data
,
size_t
size
)
...
...
@@ -2546,10 +2546,10 @@ struct lxc_conf *lxc_conf_init(void)
new
->
console
.
path
=
NULL
;
new
->
console
.
peer
=
-
1
;
new
->
console
.
proxy
.
busy
=
-
1
;
new
->
console
.
proxy
.
pt
m
x
=
-
1
;
new
->
console
.
proxy
.
pt
s
=
-
1
;
new
->
console
.
pt
m
x
=
-
1
;
new
->
console
.
pt
s
=
-
1
;
new
->
console
.
proxy
.
ptx
=
-
1
;
new
->
console
.
proxy
.
pt
y
=
-
1
;
new
->
console
.
ptx
=
-
1
;
new
->
console
.
pt
y
=
-
1
;
new
->
console
.
name
[
0
]
=
'\0'
;
memset
(
&
new
->
console
.
ringbuf
,
0
,
sizeof
(
struct
lxc_ringbuf
));
new
->
maincmd_fd
=
-
1
;
...
...
@@ -3183,7 +3183,7 @@ static int lxc_setup_boot_id(void)
int
lxc_setup
(
struct
lxc_handler
*
handler
)
{
__do_close
int
pt
s
_mnt_fd
=
-
EBADF
;
__do_close
int
pt
y
_mnt_fd
=
-
EBADF
;
int
ret
;
const
char
*
lxcpath
=
handler
->
lxcpath
,
*
name
=
handler
->
name
;
struct
lxc_conf
*
lxc_conf
=
handler
->
conf
;
...
...
@@ -3223,9 +3223,9 @@ int lxc_setup(struct lxc_handler *handler)
}
if
(
wants_console
(
&
lxc_conf
->
console
))
{
pt
s
_mnt_fd
=
open_tree
(
-
EBADF
,
lxc_conf
->
console
.
name
,
pt
y
_mnt_fd
=
open_tree
(
-
EBADF
,
lxc_conf
->
console
.
name
,
OPEN_TREE_CLONE
|
OPEN_TREE_CLOEXEC
|
AT_EMPTY_PATH
);
if
(
pt
s
_mnt_fd
<
0
)
if
(
pt
y
_mnt_fd
<
0
)
SYSTRACE
(
"Failed to create detached mount for container's console
\"
%s
\"
"
,
lxc_conf
->
console
.
name
);
else
...
...
@@ -3310,7 +3310,7 @@ int lxc_setup(struct lxc_handler *handler)
return
log_error
(
-
1
,
"Failed to
\"
/proc
\"
LSMs"
);
ret
=
lxc_setup_console
(
&
lxc_conf
->
rootfs
,
&
lxc_conf
->
console
,
lxc_conf
->
ttys
.
dir
,
pt
s
_mnt_fd
);
lxc_conf
->
ttys
.
dir
,
pt
y
_mnt_fd
);
if
(
ret
<
0
)
return
log_error
(
-
1
,
"Failed to setup console"
);
...
...
src/lxc/criu.c
View file @
184de6b8
...
...
@@ -67,7 +67,7 @@ struct criu_opts {
struct
lxc_handler
*
handler
;
int
console_fd
;
/* The path that is bind mounted from /dev/console, if any. We don't
* want to use `--ext-mount-map auto`'s result here because the pt
s
* want to use `--ext-mount-map auto`'s result here because the pt
y
* device may have a different path (e.g. if the pty number is
* different) on the target host. NULL if lxc.console.path = "none".
*/
...
...
@@ -1020,7 +1020,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
os
.
action
=
"restore"
;
os
.
user
=
opts
;
os
.
c
=
c
;
os
.
console_fd
=
c
->
lxc_conf
->
console
.
pt
s
;
os
.
console_fd
=
c
->
lxc_conf
->
console
.
pt
y
;
os
.
criu_version
=
criu_version
;
os
.
handler
=
handler
;
...
...
src/lxc/lxccontainer.c
View file @
184de6b8
...
...
@@ -537,12 +537,12 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
WRAP_API
(
bool
,
lxcapi_unfreeze
)
static
int
do_lxcapi_console_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
pt
m
xfd
)
static
int
do_lxcapi_console_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
ptxfd
)
{
if
(
!
c
)
return
-
1
;
return
lxc_terminal_getfd
(
c
,
ttynum
,
pt
m
xfd
);
return
lxc_terminal_getfd
(
c
,
ttynum
,
ptxfd
);
}
WRAP_API_2
(
int
,
lxcapi_console_getfd
,
int
*
,
int
*
)
...
...
src/lxc/lxccontainer.h
View file @
184de6b8
...
...
@@ -563,7 +563,7 @@ struct lxc_container {
* \param c Container.
* \param[in,out] ttynum Terminal number to attempt to allocate,
* or \c -1 to allocate the first available tty.
* \param[out] pt
mxfd File descriptor referring to the ptm
x side of the pty.
* \param[out] pt
xfd File descriptor referring to the pt
x side of the pty.
*
* \return tty file descriptor number on success, or \c -1 on
* failure.
...
...
@@ -575,7 +575,7 @@ struct lxc_container {
* descriptor when no longer required so that it may be allocated
* by another caller.
*/
int
(
*
console_getfd
)(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
pt
m
xfd
);
int
(
*
console_getfd
)(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
ptxfd
);
/*!
* \brief Allocate and run a console tty.
...
...
src/lxc/start.c
View file @
184de6b8
...
...
@@ -1297,14 +1297,14 @@ static int do_start(void *data)
* setup on its console ie. the pty allocated in lxc_terminal_setup() so
* make sure that that pty is stdin,stdout,stderr.
*/
if
(
handler
->
conf
->
console
.
pt
s
>=
0
)
{
if
(
handler
->
conf
->
console
.
pt
y
>=
0
)
{
if
(
handler
->
daemonize
||
!
handler
->
conf
->
is_execute
)
ret
=
set_stdfds
(
handler
->
conf
->
console
.
pt
s
);
ret
=
set_stdfds
(
handler
->
conf
->
console
.
pt
y
);
else
ret
=
lxc_terminal_set_stdfds
(
handler
->
conf
->
console
.
pt
s
);
ret
=
lxc_terminal_set_stdfds
(
handler
->
conf
->
console
.
pt
y
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to redirect std{in,out,err} to pty file descriptor %d"
,
handler
->
conf
->
console
.
pt
s
);
handler
->
conf
->
console
.
pt
y
);
goto
out_warn_father
;
}
}
...
...
@@ -1331,7 +1331,7 @@ static int do_start(void *data)
close_prot_errno_disarm
(
handler
->
sigfd
);
if
(
handler
->
conf
->
console
.
pt
s
<
0
&&
handler
->
daemonize
)
{
if
(
handler
->
conf
->
console
.
pt
y
<
0
&&
handler
->
daemonize
)
{
if
(
devnull_fd
<
0
)
{
devnull_fd
=
open_devnull
();
if
(
devnull_fd
<
0
)
...
...
@@ -1483,9 +1483,9 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
tty
=
&
ttys
->
tty
[
i
];
tty
->
busy
=
-
1
;
tty
->
pt
m
x
=
ttyfds
[
0
];
tty
->
pt
s
=
ttyfds
[
1
];
TRACE
(
"Received pty with pt
mx fd %d and pts fd %d from child"
,
tty
->
ptmx
,
tty
->
pts
);
tty
->
ptx
=
ttyfds
[
0
];
tty
->
pt
y
=
ttyfds
[
1
];
TRACE
(
"Received pty with pt
x fd %d and pty fd %d from child"
,
tty
->
ptx
,
tty
->
pty
);
}
if
(
ret
<
0
)
...
...
src/lxc/terminal.c
View file @
184de6b8
This diff is collapsed.
Click to expand it.
src/lxc/terminal.h
View file @
184de6b8
...
...
@@ -15,14 +15,14 @@ struct lxc_conf;
struct
lxc_epoll_descr
;
struct
lxc_terminal_info
{
/* the path name of the pt
s
side */
/* the path name of the pt
y
side */
char
name
[
PATH_MAX
];
/* the file descriptor of the pt
m
x */
int
pt
m
x
;
/* the file descriptor of the ptx */
int
ptx
;
/* the file descriptor of the pt
s
*/
int
pt
s
;
/* the file descriptor of the pt
y
*/
int
pt
y
;
/* whether the terminal is currently used */
int
busy
;
...
...
@@ -32,7 +32,7 @@ struct lxc_terminal_state {
struct
lxc_list
node
;
int
stdinfd
;
int
stdoutfd
;
int
pt
m
xfd
;
int
ptxfd
;
/* Escape sequence to use for exiting the terminal. A single char can
* be specified. The terminal can then exited by doing: Ctrl +
...
...
@@ -57,8 +57,8 @@ struct lxc_terminal_state {
};
struct
lxc_terminal
{
int
pt
s
;
int
pt
m
x
;
int
pt
y
;
int
ptx
;
int
peer
;
struct
lxc_terminal_info
proxy
;
struct
lxc_epoll_descr
*
descr
;
...
...
@@ -102,10 +102,10 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
/**
* Create a new terminal:
* - calls openpty() to allocate a pt
mx/pts
pair
* - sets the FD_CLOEXEC flag on the pt
mx/pts
fds
* - calls openpty() to allocate a pt
x/pty
pair
* - sets the FD_CLOEXEC flag on the pt
x/pty
fds
* - allocates either the current controlling terminal (default) or a user
* specified terminal as proxy for the newly created pt
mx/pts
pair
* specified terminal as proxy for the newly created pt
x/pty
pair
* - sets up SIGWINCH handler, winsz, and new terminal settings
* (Handlers for SIGWINCH and I/O are not registered in a mainloop.)
*/
...
...
@@ -164,7 +164,7 @@ extern int lxc_console(struct lxc_container *c, int ttynum,
* the range specified by lxc.tty.max to allocate a specific tty.
*/
extern
int
lxc_terminal_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
pt
m
xfd
);
int
*
ptxfd
);
/**
* Make fd a duplicate of the standard file descriptors. The fd is made a
...
...
@@ -183,12 +183,12 @@ extern int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
struct
lxc_epoll_descr
*
descr
);
/**
* Handler for events on the pt
m
x fd of the terminal. To be registered via
* Handler for events on the ptx fd of the terminal. To be registered via
* the corresponding functions declared and defined in mainloop.{c,h} or
* lxc_terminal_mainloop_add().
* This function exits the loop cleanly when an EPOLLHUP event is received.
*/
extern
int
lxc_terminal_pt
m
x_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
extern
int
lxc_terminal_ptx_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
struct
lxc_epoll_descr
*
descr
);
/**
...
...
@@ -202,9 +202,9 @@ extern int lxc_setup_tios(int fd, struct termios *oldtios);
* lxc_terminal_winsz: propagate winsz from one terminal to another
*
* @srcfd
* - terminal to get size from (typically a pt
s
pty)
* - terminal to get size from (typically a pt
y
pty)
* @dstfd
* - terminal to set size on (typically a pt
m
x pty)
* - terminal to set size on (typically a ptx pty)
*/
extern
void
lxc_terminal_winsz
(
int
srcfd
,
int
dstfd
);
...
...
src/tests/console.c
View file @
184de6b8
...
...
@@ -37,14 +37,14 @@
} while (0)
static
void
test_console_close_all
(
int
ttyfd
[
MAXCONSOLES
],
int
pt
m
xfd
[
MAXCONSOLES
])
int
ptxfd
[
MAXCONSOLES
])
{
int
i
;
for
(
i
=
0
;
i
<
MAXCONSOLES
;
i
++
)
{
if
(
pt
m
xfd
[
i
]
!=
-
1
)
{
close
(
pt
m
xfd
[
i
]);
pt
m
xfd
[
i
]
=
-
1
;
if
(
ptxfd
[
i
]
!=
-
1
)
{
close
(
ptxfd
[
i
]);
ptxfd
[
i
]
=
-
1
;
}
if
(
ttyfd
[
i
]
!=
-
1
)
{
...
...
@@ -59,14 +59,14 @@ static int test_console_running_container(struct lxc_container *c)
int
nrconsoles
,
i
,
ret
=
-
1
;
int
ttynum
[
MAXCONSOLES
];
int
ttyfd
[
MAXCONSOLES
];
int
pt
m
xfd
[
MAXCONSOLES
];
int
ptxfd
[
MAXCONSOLES
];
for
(
i
=
0
;
i
<
MAXCONSOLES
;
i
++
)
ttynum
[
i
]
=
ttyfd
[
i
]
=
pt
m
xfd
[
i
]
=
-
1
;
ttynum
[
i
]
=
ttyfd
[
i
]
=
ptxfd
[
i
]
=
-
1
;
ttynum
[
0
]
=
1
;
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
pt
m
xfd
[
0
]);
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
ptxfd
[
0
]);
if
(
ret
<
0
)
{
TSTERR
(
"console allocate failed"
);
goto
err1
;
...
...
@@ -79,12 +79,12 @@ static int test_console_running_container(struct lxc_container *c)
}
/* attempt to alloc same ttynum */
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
pt
m
xfd
[
1
]);
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
ptxfd
[
1
]);
if
(
ret
!=
-
1
)
{
TSTERR
(
"console allocate should fail for allocated ttynum %d"
,
ttynum
[
0
]);
goto
err2
;
}
close
(
pt
mxfd
[
0
]);
ptm
xfd
[
0
]
=
-
1
;
close
(
pt
xfd
[
0
]);
pt
xfd
[
0
]
=
-
1
;
close
(
ttyfd
[
0
]);
ttyfd
[
0
]
=
-
1
;
/* ensure we can allocate all consoles, we do this a few times to
...
...
@@ -92,7 +92,7 @@ static int test_console_running_container(struct lxc_container *c)
*/
for
(
i
=
0
;
i
<
10
;
i
++
)
{
for
(
nrconsoles
=
0
;
nrconsoles
<
MAXCONSOLES
;
nrconsoles
++
)
{
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
nrconsoles
],
&
pt
m
xfd
[
nrconsoles
]);
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
nrconsoles
],
&
ptxfd
[
nrconsoles
]);
if
(
ret
<
0
)
break
;
ttyfd
[
nrconsoles
]
=
ret
;
...
...
@@ -103,13 +103,13 @@ static int test_console_running_container(struct lxc_container *c)
goto
err2
;
}
test_console_close_all
(
ttyfd
,
pt
m
xfd
);
test_console_close_all
(
ttyfd
,
ptxfd
);
}
ret
=
0
;
err2:
test_console_close_all
(
ttyfd
,
pt
m
xfd
);
test_console_close_all
(
ttyfd
,
ptxfd
);
err1:
return
ret
;
...
...
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