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
e9a55b51
Unverified
Commit
e9a55b51
authored
Feb 28, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
terminal: non-functional changes
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
d712f9e8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
90 deletions
+98
-90
terminal.c
src/lxc/terminal.c
+12
-12
terminal.h
src/lxc/terminal.h
+86
-78
No files found.
src/lxc/terminal.c
View file @
e9a55b51
...
@@ -1162,22 +1162,22 @@ int lxc_terminal_prepare_login(int fd)
...
@@ -1162,22 +1162,22 @@ int lxc_terminal_prepare_login(int fd)
return
0
;
return
0
;
}
}
void
lxc_terminal_info_init
(
struct
lxc_terminal_info
*
pty
)
void
lxc_terminal_info_init
(
struct
lxc_terminal_info
*
terminal
)
{
{
pty
->
name
[
0
]
=
'\0'
;
terminal
->
name
[
0
]
=
'\0'
;
pty
->
master
=
-
EBADF
;
terminal
->
master
=
-
EBADF
;
pty
->
slave
=
-
EBADF
;
terminal
->
slave
=
-
EBADF
;
pty
->
busy
=
-
1
;
terminal
->
busy
=
-
1
;
}
}
void
lxc_terminal_init
(
struct
lxc_terminal
*
pty
)
void
lxc_terminal_init
(
struct
lxc_terminal
*
terminal
)
{
{
memset
(
pty
,
0
,
sizeof
(
*
pty
));
memset
(
terminal
,
0
,
sizeof
(
*
terminal
));
pty
->
slave
=
-
EBADF
;
terminal
->
slave
=
-
EBADF
;
pty
->
master
=
-
EBADF
;
terminal
->
master
=
-
EBADF
;
pty
->
peer
=
-
EBADF
;
terminal
->
peer
=
-
EBADF
;
pty
->
log_fd
=
-
EBADF
;
terminal
->
log_fd
=
-
EBADF
;
lxc_terminal_info_init
(
&
pty
->
proxy
);
lxc_terminal_info_init
(
&
terminal
->
proxy
);
}
}
void
lxc_terminal_conf_free
(
struct
lxc_terminal
*
terminal
)
void
lxc_terminal_conf_free
(
struct
lxc_terminal
*
terminal
)
...
...
src/lxc/terminal.h
View file @
e9a55b51
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#ifndef __LXC_
CONSOLE
_H
#ifndef __LXC_
TERMINAL
_H
#define __LXC_
CONSOLE
_H
#define __LXC_
TERMINAL
_H
#include "config.h"
#include "config.h"
...
@@ -36,15 +36,17 @@ struct lxc_container;
...
@@ -36,15 +36,17 @@ struct lxc_container;
struct
lxc_conf
;
struct
lxc_conf
;
struct
lxc_epoll_descr
;
struct
lxc_epoll_descr
;
/* Defines a structure containing a pty information for virtualizing a tty
* @name : the path name of the slave pty side
* @master : the file descriptor of the master
* @slave : the file descriptor of the slave
*/
struct
lxc_terminal_info
{
struct
lxc_terminal_info
{
/* the path name of the slave side */
char
name
[
MAXPATHLEN
];
char
name
[
MAXPATHLEN
];
/* the file descriptor of the master */
int
master
;
int
master
;
/* the file descriptor of the slave */
int
slave
;
int
slave
;
/* whether the terminal is currently used */
int
busy
;
int
busy
;
};
};
...
@@ -53,25 +55,32 @@ struct lxc_terminal_state {
...
@@ -53,25 +55,32 @@ struct lxc_terminal_state {
int
stdinfd
;
int
stdinfd
;
int
stdoutfd
;
int
stdoutfd
;
int
masterfd
;
int
masterfd
;
/* Escape sequence to use for exiting the pty. A single char can be
* specified. The pty can then exited by doing: Ctrl + specified_char +
/* Escape sequence to use for exiting the terminal. A single char can
* q. This field is checked by lxc_terminal_stdin_cb(). Set to -1 to
* be specified. The terminal can then exited by doing: Ctrl +
* disable exiting the pty via a escape sequence.
* specified_char + q. This field is checked by
* lxc_terminal_stdin_cb(). Set to -1 to disable exiting the terminal
* via a escape sequence.
*/
*/
int
escape
;
int
escape
;
/* Used internally by lxc_terminal_stdin_cb() to check whether an
/* Used internally by lxc_terminal_stdin_cb() to check whether an
* escape sequence has been received.
* escape sequence has been received.
*/
*/
int
saw_escape
;
int
saw_escape
;
/* Name of the container to forward the SIGWINCH event to. */
/* Name of the container to forward the SIGWINCH event to. */
const
char
*
winch_proxy
;
const
char
*
winch_proxy
;
/* Path of the container to forward the SIGWINCH event to. */
/* Path of the container to forward the SIGWINCH event to. */
const
char
*
winch_proxy_lxcpath
;
const
char
*
winch_proxy_lxcpath
;
/* File descriptor that accepts signals. If set to -1 no signal handler
/* File descriptor that accepts signals. If set to -1 no signal handler
* could be installed. This also means that the sigset_t oldmask member
* could be installed. This also means that the sigset_t oldmask member
* is meaningless.
* is meaningless.
*/
*/
int
sigfd
;
int
sigfd
;
sigset_t
oldmask
;
sigset_t
oldmask
;
};
};
...
@@ -86,7 +95,7 @@ struct lxc_terminal {
...
@@ -86,7 +95,7 @@ struct lxc_terminal {
struct
termios
*
tios
;
struct
termios
*
tios
;
struct
lxc_terminal_state
*
tty_state
;
struct
lxc_terminal_state
*
tty_state
;
struct
/* lxc_
console
_log */
{
struct
/* lxc_
terminal
_log */
{
/* size of the log file */
/* size of the log file */
uint64_t
log_size
;
uint64_t
log_size
;
...
@@ -109,7 +118,7 @@ struct lxc_terminal {
...
@@ -109,7 +118,7 @@ struct lxc_terminal {
};
};
};
};
/*
/*
*
* lxc_terminal_allocate: allocate the console or a tty
* lxc_terminal_allocate: allocate the console or a tty
*
*
* @conf : the configuration of the container to allocate from
* @conf : the configuration of the container to allocate from
...
@@ -119,61 +128,54 @@ struct lxc_terminal {
...
@@ -119,61 +128,54 @@ struct lxc_terminal {
*/
*/
extern
int
lxc_terminal_allocate
(
struct
lxc_conf
*
conf
,
int
sockfd
,
int
*
ttynum
);
extern
int
lxc_terminal_allocate
(
struct
lxc_conf
*
conf
,
int
sockfd
,
int
*
ttynum
);
/*
/*
*
* Create a new
pty
:
* Create a new
terminal
:
* - calls openpty() to allocate a master/slave p
ty p
air
* - calls openpty() to allocate a master/slave pair
* - sets the FD_CLOEXEC flag on the master/slave fds
* - sets the FD_CLOEXEC flag on the master/slave fds
* - allocates either the current controlling
pty (default) or a user specified
* - allocates either the current controlling
terminal (default) or a user
*
pty as peer pt
y for the newly created master/slave pair
*
specified terminal as prox
y for the newly created master/slave 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.)
* (For an unprivileged container the created pty on the host is not
* automatically chowned to the uid/gid of the unprivileged user. For this
* ttys_shift_ids() can be called.)
*/
*/
extern
int
lxc_terminal_create
(
struct
lxc_terminal
*
console
);
extern
int
lxc_terminal_create
(
struct
lxc_terminal
*
console
);
/**
/**
* lxc_terminal_setup: Create a new
pty
.
* lxc_terminal_setup: Create a new
terminal
.
* - In addition to lxc_terminal_create() also sets up
all pty logs
.
* - In addition to lxc_terminal_create() also sets up
logging
.
*/
*/
extern
int
lxc_terminal_setup
(
struct
lxc_conf
*
);
extern
int
lxc_terminal_setup
(
struct
lxc_conf
*
);
/*
/**
* Delete a pty created via lxc_terminal_setup():
* Delete a terminal created via lxc_terminal_create() or lxc_terminal_setup():
* - set old terminal settings
* Note, registered handlers are not automatically deleted.
* - memory allocated via lxc_terminal_setup() is free()ed.
* - close master/slave pty pair and allocated fd for the peer (usually
* /dev/tty)
* Registered handlers in a mainloop are not automatically deleted.
*/
*/
extern
void
lxc_terminal_delete
(
struct
lxc_terminal
*
);
extern
void
lxc_terminal_delete
(
struct
lxc_terminal
*
);
/*
/*
*
* lxc_terminal_free: mark the
console or a tty as unallocated, free any
* lxc_terminal_free: mark the
terminal as unallocated and free any resources
*
resources
allocated by lxc_terminal_allocate().
* allocated by lxc_terminal_allocate().
*
*
* @conf : the configuration of the container whose tty was closed
* @conf : the configuration of the container whose tty was closed
* @fd : the socket fd whose remote side was closed, which indicated
* @fd : the socket fd whose remote side was closed, which indicated
* the
console or tty
is no longer in use. this is used to match
* the
terminal
is no longer in use. this is used to match
* which
console/tty
is being freed.
* which
terminal
is being freed.
*/
*/
extern
void
lxc_terminal_free
(
struct
lxc_conf
*
conf
,
int
fd
);
extern
void
lxc_terminal_free
(
struct
lxc_conf
*
conf
,
int
fd
);
/*
/*
*
* Register
pty event handlers in an open mainloop
* Register
terminal event handlers in an open mainloop.
*/
*/
extern
int
lxc_terminal_mainloop_add
(
struct
lxc_epoll_descr
*
,
struct
lxc_terminal
*
);
extern
int
lxc_terminal_mainloop_add
(
struct
lxc_epoll_descr
*
,
struct
lxc_terminal
*
);
/*
/*
*
* Handle SIGWINCH events on the allocated
pty
s.
* Handle SIGWINCH events on the allocated
terminal
s.
*/
*/
extern
void
lxc_terminal_sigwinch
(
int
sig
);
extern
void
lxc_terminal_sigwinch
(
int
sig
);
/*
/*
*
* Connect to one of the
p
tys given to the container via lxc.tty.max.
* Connect to one of the
t
tys given to the container via lxc.tty.max.
* - allocates either the current controlling
pty
(default) or a user specified
* - allocates either the current controlling
terminal
(default) or a user specified
*
pty as peer pty
for the containers tty
*
terminal as proxy terminal
for the containers tty
* - sets up SIGWINCH handler, winsz, and new terminal settings
* - sets up SIGWINCH handler, winsz, and new terminal settings
* - opens mainloop
* - opens mainloop
* - registers SIGWINCH, I/O handlers in the mainloop
* - registers SIGWINCH, I/O handlers in the mainloop
...
@@ -183,24 +185,24 @@ extern int lxc_console(struct lxc_container *c, int ttynum,
...
@@ -183,24 +185,24 @@ extern int lxc_console(struct lxc_container *c, int ttynum,
int
stdinfd
,
int
stdoutfd
,
int
stderrfd
,
int
stdinfd
,
int
stdoutfd
,
int
stderrfd
,
int
escape
);
int
escape
);
/*
/*
*
* Allocate one of the
ptys
given to the container via lxc.tty.max. Returns an
* Allocate one of the
tty
given to the container via lxc.tty.max. Returns an
* open fd to the allocated
p
ty.
* open fd to the allocated
t
ty.
* Set ttynum to -1 to allocate the first available
p
ty, or to a value within
* Set ttynum to -1 to allocate the first available
t
ty, or to a value within
* the range specified by lxc.tty.max to allocate a specific
p
ty.
* the range specified by lxc.tty.max to allocate a specific
t
ty.
*/
*/
extern
int
lxc_terminal_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
extern
int
lxc_terminal_getfd
(
struct
lxc_container
*
c
,
int
*
ttynum
,
int
*
masterfd
);
int
*
masterfd
);
/*
/*
*
* Make fd a duplicate of the standard file descriptors
:
* Make fd a duplicate of the standard file descriptors
. The fd is made a
*
fd is made a duplicate of a specific standard file descriptor iff th
e
*
duplicate of a specific standard file descriptor iff the standard fil
e
*
standard file descriptor refers to a pty
.
*
descriptor refers to a terminal
.
*/
*/
extern
int
lxc_terminal_set_stdfds
(
int
fd
);
extern
int
lxc_terminal_set_stdfds
(
int
fd
);
/*
/*
*
* Handler for events on the stdin fd of the
pty
. To be registered via the
* Handler for events on the stdin fd of the
terminal
. To be registered via the
* corresponding functions declared and defined in mainloop.{c,h} or
* 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.
...
@@ -208,42 +210,46 @@ extern int lxc_terminal_set_stdfds(int fd);
...
@@ -208,42 +210,46 @@ extern int lxc_terminal_set_stdfds(int fd);
extern
int
lxc_terminal_stdin_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
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
pty. To be registered via the
* Handler for events on the master fd of the
terminal. To be registered via
* 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_master_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
struct
lxc_epoll_descr
*
descr
);
struct
lxc_epoll_descr
*
descr
);
/*
/*
*
* Setup new terminal properties. The old terminal settings are stored in
* Setup new terminal properties. The old terminal settings are stored in
* oldtios.
* oldtios.
*/
*/
extern
int
lxc_setup_tios
(
int
fd
,
struct
termios
*
oldtios
);
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 : terminal to get size from (typically a slave pty)
* @srcfd
* @dstfd : terminal to set size on (typically a master pty)
* - terminal to get size from (typically a slave pty)
* @dstfd
* - terminal to set size on (typically a master pty)
*/
*/
extern
void
lxc_terminal_winsz
(
int
srcfd
,
int
dstfd
);
extern
void
lxc_terminal_winsz
(
int
srcfd
,
int
dstfd
);
/*
/*
* lxc_terminal_signal_init: install signal handler
* lxc_terminal_signal_init: install signal handler
*
*
* @srcfd : src for winsz in SIGWINCH handler
* @srcfd
* @dstfd : dst for winsz in SIGWINCH handler
* - src for winsz in SIGWINCH handler
* @dstfd
* - dst for winsz in SIGWINCH handler
*
*
* Returns lxc_terminal_state structure on success or NULL on failure. The
sigfd
* Returns lxc_terminal_state structure on success or NULL on failure. The
*
member of the returned lxc_terminal_state can be select()/poll()ed/epoll()ed
*
sigfd member of the returned lxc_terminal_state can be
*
on (ie
added to a mainloop) for signals.
*
select()/poll()ed/epoll()ed on (i.e.
added to a mainloop) for signals.
*
*
* Must be called with process_lock held to protect the lxc_ttys list, or
* Must be called with process_lock held to protect the lxc_ttys list, or
from
*
from
a non-threaded context.
* a non-threaded context.
*
*
* Note that the signal handler isn't installed as a classic asychronous
* Note that the signal handler isn't installed as a classic asychronous
* handler, rather signalfd(2) is used so that we can handle the signal when
* handler, rather signalfd(2) is used so that we can handle the signal when
...
@@ -256,17 +262,18 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
...
@@ -256,17 +262,18 @@ extern void lxc_terminal_winsz(int srcfd, int dstfd);
*/
*/
extern
struct
lxc_terminal_state
*
lxc_terminal_signal_init
(
int
srcfd
,
int
dstfd
);
extern
struct
lxc_terminal_state
*
lxc_terminal_signal_init
(
int
srcfd
,
int
dstfd
);
/*
/*
*
* Handler for signal events. To be registered via the corresponding functions
* Handler for signal events. To be registered via the corresponding functions
* declared and defined in mainloop.{c,h} or lxc_terminal_mainloop_add().
* declared and defined in mainloop.{c,h} or lxc_terminal_mainloop_add().
*/
*/
extern
int
lxc_terminal_signalfd_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
extern
int
lxc_terminal_signalfd_cb
(
int
fd
,
uint32_t
events
,
void
*
cbdata
,
struct
lxc_epoll_descr
*
descr
);
struct
lxc_epoll_descr
*
descr
);
/*
/*
*
* lxc_terminal_signal_fini: uninstall signal handler
* lxc_terminal_signal_fini: uninstall signal handler
*
*
* @ts : the lxc_terminal_state returned by lxc_terminal_signal_init
* @ts
* - the lxc_terminal_state returned by lxc_terminal_signal_init
*
*
* Restore the saved signal handler that was in effect at the time
* Restore the saved signal handler that was in effect at the time
* lxc_terminal_signal_init() was called.
* lxc_terminal_signal_init() was called.
...
@@ -276,16 +283,17 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
...
@@ -276,16 +283,17 @@ extern int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
*/
*/
extern
void
lxc_terminal_signal_fini
(
struct
lxc_terminal_state
*
ts
);
extern
void
lxc_terminal_signal_fini
(
struct
lxc_terminal_state
*
ts
);
extern
int
lxc_terminal_write_ringbuffer
(
struct
lxc_terminal
*
console
);
extern
int
lxc_terminal_write_ringbuffer
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_create_log_file
(
struct
lxc_terminal
*
console
);
extern
int
lxc_terminal_create_log_file
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_io_cb
(
int
fd
,
uint32_t
events
,
void
*
data
,
extern
int
lxc_terminal_io_cb
(
int
fd
,
uint32_t
events
,
void
*
data
,
struct
lxc_epoll_descr
*
descr
);
struct
lxc_epoll_descr
*
descr
);
extern
int
lxc_make_controlling_terminal
(
int
fd
);
extern
int
lxc_make_controlling_terminal
(
int
fd
);
extern
int
lxc_terminal_prepare_login
(
int
fd
);
extern
int
lxc_terminal_prepare_login
(
int
fd
);
extern
void
lxc_terminal_conf_free
(
struct
lxc_terminal
*
console
);
extern
void
lxc_terminal_conf_free
(
struct
lxc_terminal
*
terminal
);
extern
void
lxc_terminal_info_init
(
struct
lxc_terminal_info
*
pty
);
extern
void
lxc_terminal_info_init
(
struct
lxc_terminal_info
*
terminal
);
extern
void
lxc_terminal_init
(
struct
lxc_terminal
*
pty
);
extern
void
lxc_terminal_init
(
struct
lxc_terminal
*
terminal
);
extern
int
lxc_terminal_map_ids
(
struct
lxc_conf
*
c
,
struct
lxc_terminal
*
pty
);
extern
int
lxc_terminal_map_ids
(
struct
lxc_conf
*
c
,
struct
lxc_terminal
*
terminal
);
#endif
#endif
/* __LXC_TERMINAL_H */
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