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
148e709e
Unverified
Commit
148e709e
authored
Jun 17, 2020
by
Christian Brauner
Committed by
Stéphane Graber
Jun 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree-wide: use "ptmx" and "pts" as terminal terms
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
e84f3ab7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
77 additions
and
77 deletions
+77
-77
attach.c
src/lxc/attach.c
+13
-13
commands.c
src/lxc/commands.c
+9
-9
commands.h
src/lxc/commands.h
+1
-1
conf.c
src/lxc/conf.c
+25
-25
criu.c
src/lxc/criu.c
+1
-1
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
+0
-0
terminal.h
src/lxc/terminal.h
+16
-16
No files found.
src/lxc/attach.c
View file @
148e709e
...
@@ -629,7 +629,7 @@ static signed long get_personality(const char *name, const char *lxcpath)
...
@@ -629,7 +629,7 @@ static signed long get_personality(const char *name, const char *lxcpath)
struct
attach_clone_payload
{
struct
attach_clone_payload
{
int
ipc_socket
;
int
ipc_socket
;
int
terminal_
slave
_fd
;
int
terminal_
pts
_fd
;
lxc_attach_options_t
*
options
;
lxc_attach_options_t
*
options
;
struct
lxc_proc_context_info
*
init_ctx
;
struct
lxc_proc_context_info
*
init_ctx
;
lxc_attach_exec_t
exec_function
;
lxc_attach_exec_t
exec_function
;
...
@@ -639,7 +639,7 @@ struct attach_clone_payload {
...
@@ -639,7 +639,7 @@ struct attach_clone_payload {
static
void
lxc_put_attach_clone_payload
(
struct
attach_clone_payload
*
p
)
static
void
lxc_put_attach_clone_payload
(
struct
attach_clone_payload
*
p
)
{
{
close_prot_errno_disarm
(
p
->
ipc_socket
);
close_prot_errno_disarm
(
p
->
ipc_socket
);
close_prot_errno_disarm
(
p
->
terminal_
slave
_fd
);
close_prot_errno_disarm
(
p
->
terminal_
pts
_fd
);
if
(
p
->
init_ctx
)
{
if
(
p
->
init_ctx
)
{
lxc_proc_put_context_info
(
p
->
init_ctx
);
lxc_proc_put_context_info
(
p
->
init_ctx
);
p
->
init_ctx
=
NULL
;
p
->
init_ctx
=
NULL
;
...
@@ -860,13 +860,13 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -860,13 +860,13 @@ static int attach_child_main(struct attach_clone_payload *payload)
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
{
ret
=
lxc_terminal_prepare_login
(
payload
->
terminal_
slave
_fd
);
ret
=
lxc_terminal_prepare_login
(
payload
->
terminal_
pts
_fd
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to prepare terminal file descriptor %d"
,
payload
->
terminal_
slave
_fd
);
SYSERROR
(
"Failed to prepare terminal file descriptor %d"
,
payload
->
terminal_
pts
_fd
);
goto
on_error
;
goto
on_error
;
}
}
TRACE
(
"Prepared terminal file descriptor %d"
,
payload
->
terminal_
slave
_fd
);
TRACE
(
"Prepared terminal file descriptor %d"
,
payload
->
terminal_
pts
_fd
);
}
}
/* Avoid unnecessary syscalls. */
/* Avoid unnecessary syscalls. */
...
@@ -936,14 +936,14 @@ static int lxc_attach_terminal_mainloop_init(struct lxc_terminal *terminal,
...
@@ -936,14 +936,14 @@ static int lxc_attach_terminal_mainloop_init(struct lxc_terminal *terminal,
return
0
;
return
0
;
}
}
static
inline
void
lxc_attach_terminal_close_
master
(
struct
lxc_terminal
*
terminal
)
static
inline
void
lxc_attach_terminal_close_
ptmx
(
struct
lxc_terminal
*
terminal
)
{
{
close_prot_errno_disarm
(
terminal
->
master
);
close_prot_errno_disarm
(
terminal
->
ptmx
);
}
}
static
inline
void
lxc_attach_terminal_close_
slave
(
struct
lxc_terminal
*
terminal
)
static
inline
void
lxc_attach_terminal_close_
pts
(
struct
lxc_terminal
*
terminal
)
{
{
close_prot_errno_disarm
(
terminal
->
slave
);
close_prot_errno_disarm
(
terminal
->
pts
);
}
}
static
inline
void
lxc_attach_terminal_close_peer
(
struct
lxc_terminal
*
terminal
)
static
inline
void
lxc_attach_terminal_close_peer
(
struct
lxc_terminal
*
terminal
)
...
@@ -1173,7 +1173,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
...
@@ -1173,7 +1173,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
free
(
cwd
);
free
(
cwd
);
lxc_proc_close_ns_fd
(
init_ctx
);
lxc_proc_close_ns_fd
(
init_ctx
);
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
lxc_attach_terminal_close_
slave
(
&
terminal
);
lxc_attach_terminal_close_
pts
(
&
terminal
);
/* Attach to cgroup, if requested. */
/* Attach to cgroup, if requested. */
if
(
options
->
attach_flags
&
LXC_ATTACH_MOVE_TO_CGROUP
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_MOVE_TO_CGROUP
)
{
...
@@ -1336,7 +1336,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
...
@@ -1336,7 +1336,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
close_prot_errno_disarm
(
ipc_sockets
[
0
]);
close_prot_errno_disarm
(
ipc_sockets
[
0
]);
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
{
lxc_attach_terminal_close_
master
(
&
terminal
);
lxc_attach_terminal_close_
ptmx
(
&
terminal
);
lxc_attach_terminal_close_peer
(
&
terminal
);
lxc_attach_terminal_close_peer
(
&
terminal
);
lxc_attach_terminal_close_log
(
&
terminal
);
lxc_attach_terminal_close_log
(
&
terminal
);
}
}
...
@@ -1381,7 +1381,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
...
@@ -1381,7 +1381,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
payload
.
ipc_socket
=
ipc_sockets
[
1
];
payload
.
ipc_socket
=
ipc_sockets
[
1
];
payload
.
options
=
options
;
payload
.
options
=
options
;
payload
.
init_ctx
=
init_ctx
;
payload
.
init_ctx
=
init_ctx
;
payload
.
terminal_
slave_fd
=
terminal
.
slave
;
payload
.
terminal_
pts_fd
=
terminal
.
pts
;
payload
.
exec_function
=
exec_function
;
payload
.
exec_function
=
exec_function
;
payload
.
exec_payload
=
exec_payload
;
payload
.
exec_payload
=
exec_payload
;
...
@@ -1411,7 +1411,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
...
@@ -1411,7 +1411,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
if
(
options
->
attach_flags
&
LXC_ATTACH_TERMINAL
)
lxc_attach_terminal_close_
slave
(
&
terminal
);
lxc_attach_terminal_close_
pts
(
&
terminal
);
/* Tell grandparent the pid of the pid of the newly created child. */
/* Tell grandparent the pid of the pid of the newly created child. */
ret
=
lxc_write_nointr
(
ipc_sockets
[
1
],
&
pid
,
sizeof
(
pid
));
ret
=
lxc_write_nointr
(
ipc_sockets
[
1
],
&
pid
,
sizeof
(
pid
));
...
...
src/lxc/commands.c
View file @
148e709e
...
@@ -108,7 +108,7 @@ static const char *lxc_cmd_str(lxc_cmd_t cmd)
...
@@ -108,7 +108,7 @@ static const char *lxc_cmd_str(lxc_cmd_t cmd)
* stored directly in data and datalen will be 0.
* stored directly in data and datalen will be 0.
*
*
* As a special case, the response for LXC_CMD_CONSOLE is created
* As a special case, the response for LXC_CMD_CONSOLE is created
* here as it contains an fd for the
master
pty passed through the
* here as it contains an fd for the
ptmx
pty passed through the
* unix socket.
* unix socket.
*/
*/
static
int
lxc_cmd_rsp_recv
(
int
sock
,
struct
lxc_cmd_rr
*
cmd
)
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)
...
@@ -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
\"
"
,
ENOMEM
,
"Failed to receive response for command
\"
%s
\"
"
,
lxc_cmd_str
(
cmd
->
req
.
cmd
));
lxc_cmd_str
(
cmd
->
req
.
cmd
));
rspdata
->
master
fd
=
move_fd
(
fd_rsp
);
rspdata
->
ptmx
fd
=
move_fd
(
fd_rsp
);
rspdata
->
ttynum
=
PTR_TO_INT
(
rsp
->
data
);
rspdata
->
ttynum
=
PTR_TO_INT
(
rsp
->
data
);
rsp
->
data
=
rspdata
;
rsp
->
data
=
rspdata
;
}
}
...
@@ -844,7 +844,7 @@ static int lxc_cmd_terminal_winch_callback(int fd, struct lxc_cmd_req *req,
...
@@ -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
* @name : name of container to connect to
* @ttynum : in: the tty to open or -1 for next available
* @ttynum : in: the tty to open or -1 for next available
* : out: the tty allocated
* : out: the tty allocated
* @fd : out: file descriptor for
master
side of pty
* @fd : out: file descriptor for
ptmx
side of pty
* @lxcpath : the lxcpath in which the container is running
* @lxcpath : the lxcpath in which the container is running
*
*
* Returns fd holding tty allocated on success, < 0 on failure
* 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)
...
@@ -871,11 +871,11 @@ int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath)
if
(
ret
==
0
)
if
(
ret
==
0
)
return
log_error
(
-
1
,
"tty number %d invalid, busy or all ttys busy"
,
*
ttynum
);
return
log_error
(
-
1
,
"tty number %d invalid, busy or all ttys busy"
,
*
ttynum
);
if
(
rspdata
->
master
fd
<
0
)
if
(
rspdata
->
ptmx
fd
<
0
)
return
log_error
(
-
1
,
"Unable to allocate fd for tty %d"
,
rspdata
->
ttynum
);
return
log_error
(
-
1
,
"Unable to allocate fd for tty %d"
,
rspdata
->
ttynum
);
ret
=
cmd
.
rsp
.
ret
;
/* socket fd */
ret
=
cmd
.
rsp
.
ret
;
/* socket fd */
*
fd
=
rspdata
->
master
fd
;
*
fd
=
rspdata
->
ptmx
fd
;
*
ttynum
=
rspdata
->
ttynum
;
*
ttynum
=
rspdata
->
ttynum
;
return
log_info
(
ret
,
"Alloced fd %d for tty %d via socket %d"
,
*
fd
,
rspdata
->
ttynum
,
ret
);
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,
...
@@ -885,17 +885,17 @@ static int lxc_cmd_console_callback(int fd, struct lxc_cmd_req *req,
struct
lxc_handler
*
handler
,
struct
lxc_handler
*
handler
,
struct
lxc_epoll_descr
*
descr
)
struct
lxc_epoll_descr
*
descr
)
{
{
int
master
fd
,
ret
;
int
ptmx
fd
,
ret
;
struct
lxc_cmd_rsp
rsp
;
struct
lxc_cmd_rsp
rsp
;
int
ttynum
=
PTR_TO_INT
(
req
->
data
);
int
ttynum
=
PTR_TO_INT
(
req
->
data
);
master
fd
=
lxc_terminal_allocate
(
handler
->
conf
,
fd
,
&
ttynum
);
ptmx
fd
=
lxc_terminal_allocate
(
handler
->
conf
,
fd
,
&
ttynum
);
if
(
master
fd
<
0
)
if
(
ptmx
fd
<
0
)
return
LXC_CMD_REAP_CLIENT_FD
;
return
LXC_CMD_REAP_CLIENT_FD
;
memset
(
&
rsp
,
0
,
sizeof
(
rsp
));
memset
(
&
rsp
,
0
,
sizeof
(
rsp
));
rsp
.
data
=
INT_TO_PTR
(
ttynum
);
rsp
.
data
=
INT_TO_PTR
(
ttynum
);
ret
=
lxc_abstract_unix_send_fds
(
fd
,
&
master
fd
,
1
,
&
rsp
,
sizeof
(
rsp
));
ret
=
lxc_abstract_unix_send_fds
(
fd
,
&
ptmx
fd
,
1
,
&
rsp
,
sizeof
(
rsp
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
lxc_terminal_free
(
handler
->
conf
,
fd
);
lxc_terminal_free
(
handler
->
conf
,
fd
);
return
log_error_errno
(
LXC_CMD_REAP_CLIENT_FD
,
errno
,
return
log_error_errno
(
LXC_CMD_REAP_CLIENT_FD
,
errno
,
...
...
src/lxc/commands.h
View file @
148e709e
...
@@ -61,7 +61,7 @@ struct lxc_cmd_rr {
...
@@ -61,7 +61,7 @@ struct lxc_cmd_rr {
};
};
struct
lxc_cmd_console_rsp_data
{
struct
lxc_cmd_console_rsp_data
{
int
master
fd
;
int
ptmx
fd
;
int
ttynum
;
int
ttynum
;
};
};
...
...
src/lxc/conf.c
View file @
148e709e
...
@@ -921,33 +921,33 @@ int lxc_allocate_ttys(struct lxc_conf *conf)
...
@@ -921,33 +921,33 @@ int lxc_allocate_ttys(struct lxc_conf *conf)
for
(
size_t
i
=
0
;
i
<
ttys
->
max
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
ttys
->
max
;
i
++
)
{
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
tty
->
master
=
-
EBADF
;
tty
->
ptmx
=
-
EBADF
;
tty
->
slave
=
-
EBADF
;
tty
->
pts
=
-
EBADF
;
ret
=
openpty
(
&
tty
->
master
,
&
tty
->
slave
,
NULL
,
NULL
,
NULL
);
ret
=
openpty
(
&
tty
->
ptmx
,
&
tty
->
pts
,
NULL
,
NULL
,
NULL
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ttys
->
max
=
i
;
ttys
->
max
=
i
;
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to create tty %zu"
,
i
);
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to create tty %zu"
,
i
);
}
}
ret
=
ttyname_r
(
tty
->
slave
,
tty
->
name
,
sizeof
(
tty
->
name
));
ret
=
ttyname_r
(
tty
->
pts
,
tty
->
name
,
sizeof
(
tty
->
name
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ttys
->
max
=
i
;
ttys
->
max
=
i
;
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to retrieve name of tty %zu
slave
"
,
i
);
return
log_error_errno
(
-
ENOTTY
,
ENOTTY
,
"Failed to retrieve name of tty %zu
pts
"
,
i
);
}
}
DEBUG
(
"Created tty
\"
%s
\"
with
master fd %d and slave
fd %d"
,
DEBUG
(
"Created tty
\"
%s
\"
with
ptmx fd %d and pts
fd %d"
,
tty
->
name
,
tty
->
master
,
tty
->
slave
);
tty
->
name
,
tty
->
ptmx
,
tty
->
pts
);
/* Prevent leaking the file descriptors to the container */
/* Prevent leaking the file descriptors to the container */
ret
=
fd_cloexec
(
tty
->
master
,
true
);
ret
=
fd_cloexec
(
tty
->
ptmx
,
true
);
if
(
ret
<
0
)
if
(
ret
<
0
)
SYSWARN
(
"Failed to set FD_CLOEXEC flag on
master
fd %d of tty device
\"
%s
\"
"
,
SYSWARN
(
"Failed to set FD_CLOEXEC flag on
ptmx
fd %d of tty device
\"
%s
\"
"
,
tty
->
master
,
tty
->
name
);
tty
->
ptmx
,
tty
->
name
);
ret
=
fd_cloexec
(
tty
->
slave
,
true
);
ret
=
fd_cloexec
(
tty
->
pts
,
true
);
if
(
ret
<
0
)
if
(
ret
<
0
)
SYSWARN
(
"Failed to set FD_CLOEXEC flag on
slave
fd %d of tty device
\"
%s
\"
"
,
SYSWARN
(
"Failed to set FD_CLOEXEC flag on
pts
fd %d of tty device
\"
%s
\"
"
,
tty
->
slave
,
tty
->
name
);
tty
->
pts
,
tty
->
name
);
tty
->
busy
=
-
1
;
tty
->
busy
=
-
1
;
}
}
...
@@ -964,8 +964,8 @@ void lxc_delete_tty(struct lxc_tty_info *ttys)
...
@@ -964,8 +964,8 @@ void lxc_delete_tty(struct lxc_tty_info *ttys)
for
(
int
i
=
0
;
i
<
ttys
->
max
;
i
++
)
{
for
(
int
i
=
0
;
i
<
ttys
->
max
;
i
++
)
{
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
close_prot_errno_disarm
(
tty
->
master
);
close_prot_errno_disarm
(
tty
->
ptmx
);
close_prot_errno_disarm
(
tty
->
slave
);
close_prot_errno_disarm
(
tty
->
pts
);
}
}
free_disarm
(
ttys
->
tty
);
free_disarm
(
ttys
->
tty
);
...
@@ -986,15 +986,15 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
...
@@ -986,15 +986,15 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
int
ttyfds
[
2
];
int
ttyfds
[
2
];
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
struct
lxc_terminal_info
*
tty
=
&
ttys
->
tty
[
i
];
ttyfds
[
0
]
=
tty
->
master
;
ttyfds
[
0
]
=
tty
->
ptmx
;
ttyfds
[
1
]
=
tty
->
slave
;
ttyfds
[
1
]
=
tty
->
pts
;
ret
=
lxc_abstract_unix_send_fds
(
sock
,
ttyfds
,
2
,
NULL
,
0
);
ret
=
lxc_abstract_unix_send_fds
(
sock
,
ttyfds
,
2
,
NULL
,
0
);
if
(
ret
<
0
)
if
(
ret
<
0
)
break
;
break
;
TRACE
(
"Sent tty
\"
%s
\"
with
master fd %d and slave
fd %d to parent"
,
TRACE
(
"Sent tty
\"
%s
\"
with
ptmx fd %d and pts
fd %d to parent"
,
tty
->
name
,
tty
->
master
,
tty
->
slave
);
tty
->
name
,
tty
->
ptmx
,
tty
->
pts
);
}
}
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -1615,7 +1615,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
...
@@ -1615,7 +1615,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
if
(
ret
<
0
&&
errno
!=
EEXIST
)
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create console"
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create console"
);
ret
=
fchmod
(
console
->
slave
,
S_IXUSR
|
S_IXGRP
);
ret
=
fchmod
(
console
->
pts
,
S_IXUSR
|
S_IXGRP
);
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
);
...
@@ -1686,7 +1686,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
...
@@ -1686,7 +1686,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
if
(
ret
<
0
&&
errno
!=
EEXIST
)
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create console"
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create console"
);
ret
=
fchmod
(
console
->
slave
,
S_IXUSR
|
S_IXGRP
);
ret
=
fchmod
(
console
->
pts
,
S_IXUSR
|
S_IXGRP
);
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
);
...
@@ -2546,10 +2546,10 @@ struct lxc_conf *lxc_conf_init(void)
...
@@ -2546,10 +2546,10 @@ struct lxc_conf *lxc_conf_init(void)
new
->
console
.
path
=
NULL
;
new
->
console
.
path
=
NULL
;
new
->
console
.
peer
=
-
1
;
new
->
console
.
peer
=
-
1
;
new
->
console
.
proxy
.
busy
=
-
1
;
new
->
console
.
proxy
.
busy
=
-
1
;
new
->
console
.
proxy
.
master
=
-
1
;
new
->
console
.
proxy
.
ptmx
=
-
1
;
new
->
console
.
proxy
.
slave
=
-
1
;
new
->
console
.
proxy
.
pts
=
-
1
;
new
->
console
.
master
=
-
1
;
new
->
console
.
ptmx
=
-
1
;
new
->
console
.
slave
=
-
1
;
new
->
console
.
pts
=
-
1
;
new
->
console
.
name
[
0
]
=
'\0'
;
new
->
console
.
name
[
0
]
=
'\0'
;
memset
(
&
new
->
console
.
ringbuf
,
0
,
sizeof
(
struct
lxc_ringbuf
));
memset
(
&
new
->
console
.
ringbuf
,
0
,
sizeof
(
struct
lxc_ringbuf
));
new
->
maincmd_fd
=
-
1
;
new
->
maincmd_fd
=
-
1
;
...
...
src/lxc/criu.c
View file @
148e709e
...
@@ -1020,7 +1020,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
...
@@ -1020,7 +1020,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
os
.
action
=
"restore"
;
os
.
action
=
"restore"
;
os
.
user
=
opts
;
os
.
user
=
opts
;
os
.
c
=
c
;
os
.
c
=
c
;
os
.
console_fd
=
c
->
lxc_conf
->
console
.
slave
;
os
.
console_fd
=
c
->
lxc_conf
->
console
.
pts
;
os
.
criu_version
=
criu_version
;
os
.
criu_version
=
criu_version
;
os
.
handler
=
handler
;
os
.
handler
=
handler
;
...
...
src/lxc/lxccontainer.c
View file @
148e709e
...
@@ -537,12 +537,12 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
...
@@ -537,12 +537,12 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
WRAP_API
(
bool
,
lxcapi_unfreeze
)
WRAP_API
(
bool
,
lxcapi_unfreeze
)
static
int
do_lxcapi_console_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
master
fd
)
static
int
do_lxcapi_console_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
ptmx
fd
)
{
{
if
(
!
c
)
if
(
!
c
)
return
-
1
;
return
-
1
;
return
lxc_terminal_getfd
(
c
,
ttynum
,
master
fd
);
return
lxc_terminal_getfd
(
c
,
ttynum
,
ptmx
fd
);
}
}
WRAP_API_2
(
int
,
lxcapi_console_getfd
,
int
*
,
int
*
)
WRAP_API_2
(
int
,
lxcapi_console_getfd
,
int
*
,
int
*
)
...
...
src/lxc/lxccontainer.h
View file @
148e709e
...
@@ -563,7 +563,7 @@ struct lxc_container {
...
@@ -563,7 +563,7 @@ struct lxc_container {
* \param c Container.
* \param c Container.
* \param[in,out] ttynum Terminal number to attempt to allocate,
* \param[in,out] ttynum Terminal number to attempt to allocate,
* or \c -1 to allocate the first available tty.
* or \c -1 to allocate the first available tty.
* \param[out]
masterfd File descriptor referring to the master
side of the pty.
* \param[out]
ptmxfd File descriptor referring to the ptmx
side of the pty.
*
*
* \return tty file descriptor number on success, or \c -1 on
* \return tty file descriptor number on success, or \c -1 on
* failure.
* failure.
...
@@ -575,7 +575,7 @@ struct lxc_container {
...
@@ -575,7 +575,7 @@ struct lxc_container {
* descriptor when no longer required so that it may be allocated
* descriptor when no longer required so that it may be allocated
* by another caller.
* by another caller.
*/
*/
int
(
*
console_getfd
)(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
master
fd
);
int
(
*
console_getfd
)(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
ptmx
fd
);
/*!
/*!
* \brief Allocate and run a console tty.
* \brief Allocate and run a console tty.
...
...
src/lxc/start.c
View file @
148e709e
...
@@ -1249,14 +1249,14 @@ static int do_start(void *data)
...
@@ -1249,14 +1249,14 @@ static int do_start(void *data)
* setup on its console ie. the pty allocated in lxc_terminal_setup() so
* setup on its console ie. the pty allocated in lxc_terminal_setup() so
* make sure that that pty is stdin,stdout,stderr.
* make sure that that pty is stdin,stdout,stderr.
*/
*/
if
(
handler
->
conf
->
console
.
slave
>=
0
)
{
if
(
handler
->
conf
->
console
.
pts
>=
0
)
{
if
(
handler
->
daemonize
||
!
handler
->
conf
->
is_execute
)
if
(
handler
->
daemonize
||
!
handler
->
conf
->
is_execute
)
ret
=
set_stdfds
(
handler
->
conf
->
console
.
slave
);
ret
=
set_stdfds
(
handler
->
conf
->
console
.
pts
);
else
else
ret
=
lxc_terminal_set_stdfds
(
handler
->
conf
->
console
.
slave
);
ret
=
lxc_terminal_set_stdfds
(
handler
->
conf
->
console
.
pts
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to redirect std{in,out,err} to pty file descriptor %d"
,
ERROR
(
"Failed to redirect std{in,out,err} to pty file descriptor %d"
,
handler
->
conf
->
console
.
slave
);
handler
->
conf
->
console
.
pts
);
goto
out_warn_father
;
goto
out_warn_father
;
}
}
}
}
...
@@ -1283,7 +1283,7 @@ static int do_start(void *data)
...
@@ -1283,7 +1283,7 @@ static int do_start(void *data)
close_prot_errno_disarm
(
handler
->
sigfd
);
close_prot_errno_disarm
(
handler
->
sigfd
);
if
(
handler
->
conf
->
console
.
slave
<
0
&&
handler
->
daemonize
)
{
if
(
handler
->
conf
->
console
.
pts
<
0
&&
handler
->
daemonize
)
{
if
(
devnull_fd
<
0
)
{
if
(
devnull_fd
<
0
)
{
devnull_fd
=
open_devnull
();
devnull_fd
=
open_devnull
();
if
(
devnull_fd
<
0
)
if
(
devnull_fd
<
0
)
...
@@ -1435,9 +1435,9 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
...
@@ -1435,9 +1435,9 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
tty
=
&
ttys
->
tty
[
i
];
tty
=
&
ttys
->
tty
[
i
];
tty
->
busy
=
-
1
;
tty
->
busy
=
-
1
;
tty
->
master
=
ttyfds
[
0
];
tty
->
ptmx
=
ttyfds
[
0
];
tty
->
slave
=
ttyfds
[
1
];
tty
->
pts
=
ttyfds
[
1
];
TRACE
(
"Received pty with
master fd %d and slave fd %d from child"
,
tty
->
master
,
tty
->
slave
);
TRACE
(
"Received pty with
ptmx fd %d and pts fd %d from child"
,
tty
->
ptmx
,
tty
->
pts
);
}
}
if
(
ret
<
0
)
if
(
ret
<
0
)
...
...
src/lxc/terminal.c
View file @
148e709e
This diff is collapsed.
Click to expand it.
src/lxc/terminal.h
View file @
148e709e
...
@@ -15,14 +15,14 @@ struct lxc_conf;
...
@@ -15,14 +15,14 @@ struct lxc_conf;
struct
lxc_epoll_descr
;
struct
lxc_epoll_descr
;
struct
lxc_terminal_info
{
struct
lxc_terminal_info
{
/* the path name of the
slave
side */
/* the path name of the
pts
side */
char
name
[
PATH_MAX
];
char
name
[
PATH_MAX
];
/* the file descriptor of the
master
*/
/* the file descriptor of the
ptmx
*/
int
master
;
int
ptmx
;
/* the file descriptor of the
slave
*/
/* the file descriptor of the
pts
*/
int
slave
;
int
pts
;
/* whether the terminal is currently used */
/* whether the terminal is currently used */
int
busy
;
int
busy
;
...
@@ -32,7 +32,7 @@ struct lxc_terminal_state {
...
@@ -32,7 +32,7 @@ struct lxc_terminal_state {
struct
lxc_list
node
;
struct
lxc_list
node
;
int
stdinfd
;
int
stdinfd
;
int
stdoutfd
;
int
stdoutfd
;
int
master
fd
;
int
ptmx
fd
;
/* Escape sequence to use for exiting the terminal. A single char can
/* Escape sequence to use for exiting the terminal. A single char can
* be specified. The terminal can then exited by doing: Ctrl +
* be specified. The terminal can then exited by doing: Ctrl +
...
@@ -57,8 +57,8 @@ struct lxc_terminal_state {
...
@@ -57,8 +57,8 @@ struct lxc_terminal_state {
};
};
struct
lxc_terminal
{
struct
lxc_terminal
{
int
slave
;
int
pts
;
int
master
;
int
ptmx
;
int
peer
;
int
peer
;
struct
lxc_terminal_info
proxy
;
struct
lxc_terminal_info
proxy
;
struct
lxc_epoll_descr
*
descr
;
struct
lxc_epoll_descr
*
descr
;
...
@@ -102,10 +102,10 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
...
@@ -102,10 +102,10 @@ extern int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttynum
/**
/**
* Create a new terminal:
* Create a new terminal:
* - calls openpty() to allocate a
master/slave
pair
* - calls openpty() to allocate a
ptmx/pts
pair
* - sets the FD_CLOEXEC flag on the
master/slave
fds
* - sets the FD_CLOEXEC flag on the
ptmx/pts
fds
* - allocates either the current controlling terminal (default) or a user
* - allocates either the current controlling terminal (default) or a user
* specified terminal as proxy for the newly created
master/slave
pair
* specified terminal as proxy for the newly created
ptmx/pts
pair
* - sets up SIGWINCH handler, winsz, and new terminal settings
* - sets up SIGWINCH handler, winsz, and new terminal settings
* (Handlers for SIGWINCH and I/O are not registered in a mainloop.)
* (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,
...
@@ -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.
* the range specified by lxc.tty.max to allocate a specific tty.
*/
*/
extern
int
lxc_terminal_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
extern
int
lxc_terminal_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
master
fd
);
int
*
ptmx
fd
);
/**
/**
* Make fd a duplicate of the standard file descriptors. The fd is made a
* 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,
...
@@ -183,12 +183,12 @@ extern int lxc_terminal_stdin_cb(int fd, uint32_t events, void *cbdata,
struct
lxc_epoll_descr
*
descr
);
struct
lxc_epoll_descr
*
descr
);
/**
/**
* Handler for events on the
master
fd of the terminal. To be registered via
* Handler for events on the
ptmx
fd of the terminal. To be registered via
* the corresponding functions declared and defined in mainloop.{c,h} or
* the corresponding functions declared and defined in mainloop.{c,h} or
* lxc_terminal_mainloop_add().
* lxc_terminal_mainloop_add().
* This function exits the loop cleanly when an EPOLLHUP event is received.
* This function exits the loop cleanly when an EPOLLHUP event is received.
*/
*/
extern
int
lxc_terminal_
master
_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
extern
int
lxc_terminal_
ptmx
_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
struct
lxc_epoll_descr
*
descr
);
struct
lxc_epoll_descr
*
descr
);
/**
/**
...
@@ -202,9 +202,9 @@ extern int lxc_setup_tios(int fd, struct termios *oldtios);
...
@@ -202,9 +202,9 @@ extern int lxc_setup_tios(int fd, struct termios *oldtios);
* lxc_terminal_winsz: propagate winsz from one terminal to another
* lxc_terminal_winsz: propagate winsz from one terminal to another
*
*
* @srcfd
* @srcfd
* - terminal to get size from (typically a
slave
pty)
* - terminal to get size from (typically a
pts
pty)
* @dstfd
* @dstfd
* - terminal to set size on (typically a
master
pty)
* - terminal to set size on (typically a
ptmx
pty)
*/
*/
extern
void
lxc_terminal_winsz
(
int
srcfd
,
int
dstfd
);
extern
void
lxc_terminal_winsz
(
int
srcfd
,
int
dstfd
);
...
...
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