Commit 0d4137cc by Christian Brauner

make tty helper functions extern

- lxc_console_cb_tty_stdin() - lxc_console_cb_tty_master() - lxc_setup_tios(int fd, struct termios *oldtios); - lxc_console_winsz(int srcfd, int dstfd); - lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata, struct lxc_epoll_descr *descr); - lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd); - lxc_console_sigwinch_fini(struct lxc_tty_state *ts); We can make use these functions in other modules. Signed-off-by: 's avatarChristian Brauner <christian.brauner@mailbox.org>
parent 014d5e1e
...@@ -1332,7 +1332,7 @@ out: ...@@ -1332,7 +1332,7 @@ out:
return bret; return bret;
} }
static bool collect_subsytems(void) static bool collect_subsystems(void)
{ {
char *line = NULL; char *line = NULL;
nih_local char **cgm_subsys_list = NULL; nih_local char **cgm_subsys_list = NULL;
...@@ -1444,7 +1444,7 @@ out_free: ...@@ -1444,7 +1444,7 @@ out_free:
struct cgroup_ops *cgm_ops_init(void) struct cgroup_ops *cgm_ops_init(void)
{ {
check_supports_multiple_controllers(-1); check_supports_multiple_controllers(-1);
if (!collect_subsytems()) if (!collect_subsystems())
return NULL; return NULL;
if (api_version < CGM_SUPPORTS_MULT_CONTROLLERS) if (api_version < CGM_SUPPORTS_MULT_CONTROLLERS)
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "log.h" #include "log.h"
#include "conf.h" #include "conf.h"
#include "config.h" #include "config.h"
#include "console.h"
#include "start.h" /* for struct lxc_handler */ #include "start.h" /* for struct lxc_handler */
#include "caps.h" #include "caps.h"
#include "commands.h" #include "commands.h"
...@@ -55,19 +56,6 @@ lxc_log_define(lxc_console, lxc); ...@@ -55,19 +56,6 @@ lxc_log_define(lxc_console, lxc);
static struct lxc_list lxc_ttys; static struct lxc_list lxc_ttys;
typedef void (*sighandler_t)(int); typedef void (*sighandler_t)(int);
struct lxc_tty_state
{
struct lxc_list node;
int stdinfd;
int stdoutfd;
int masterfd;
int escape;
int saw_escape;
const char *winch_proxy;
const char *winch_proxy_lxcpath;
int sigfd;
sigset_t oldmask;
};
__attribute__((constructor)) __attribute__((constructor))
void lxc_console_init(void) void lxc_console_init(void)
...@@ -80,7 +68,7 @@ void lxc_console_init(void) ...@@ -80,7 +68,7 @@ void lxc_console_init(void)
* @srcfd : terminal to get size from (typically a slave pty) * @srcfd : terminal to get size from (typically a slave pty)
* @dstfd : terminal to set size on (typically a master pty) * @dstfd : terminal to set size on (typically a master pty)
*/ */
static void lxc_console_winsz(int srcfd, int dstfd) void lxc_console_winsz(int srcfd, int dstfd)
{ {
struct winsize wsz; struct winsize wsz;
if (isatty(srcfd) && ioctl(srcfd, TIOCGWINSZ, &wsz) == 0) { if (isatty(srcfd) && ioctl(srcfd, TIOCGWINSZ, &wsz) == 0) {
...@@ -93,10 +81,8 @@ static void lxc_console_winsz(int srcfd, int dstfd) ...@@ -93,10 +81,8 @@ static void lxc_console_winsz(int srcfd, int dstfd)
static void lxc_console_winch(struct lxc_tty_state *ts) static void lxc_console_winch(struct lxc_tty_state *ts)
{ {
lxc_console_winsz(ts->stdinfd, ts->masterfd); lxc_console_winsz(ts->stdinfd, ts->masterfd);
if (ts->winch_proxy) { if (ts->winch_proxy)
lxc_cmd_console_winch(ts->winch_proxy, lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
ts->winch_proxy_lxcpath);
}
} }
void lxc_console_sigwinch(int sig) void lxc_console_sigwinch(int sig)
...@@ -110,13 +96,14 @@ void lxc_console_sigwinch(int sig) ...@@ -110,13 +96,14 @@ void lxc_console_sigwinch(int sig)
} }
} }
static int lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata, int lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct signalfd_siginfo siginfo; struct signalfd_siginfo siginfo;
struct lxc_tty_state *ts = cbdata; struct lxc_tty_state *ts = cbdata;
if (read(fd, &siginfo, sizeof(siginfo)) < sizeof(siginfo)) { ssize_t ret = read(fd, &siginfo, sizeof(siginfo));
if (ret < 0 || (size_t)ret < sizeof(siginfo)) {
ERROR("failed to read signal info"); ERROR("failed to read signal info");
return -1; return -1;
} }
...@@ -145,7 +132,7 @@ static int lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata, ...@@ -145,7 +132,7 @@ static int lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata,
* prevent lxc_ttys list corruption, but using the fd we can provide the * prevent lxc_ttys list corruption, but using the fd we can provide the
* tty_state needed to the callback (lxc_console_cb_sigwinch_fd()). * tty_state needed to the callback (lxc_console_cb_sigwinch_fd()).
*/ */
static struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd) struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd)
{ {
sigset_t mask; sigset_t mask;
struct lxc_tty_state *ts; struct lxc_tty_state *ts;
...@@ -200,11 +187,11 @@ out: ...@@ -200,11 +187,11 @@ out:
* 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 a non-threaded context. * from a non-threaded context.
*/ */
static void lxc_console_sigwinch_fini(struct lxc_tty_state *ts) void lxc_console_sigwinch_fini(struct lxc_tty_state *ts)
{ {
if (ts->sigfd >= 0) { if (ts->sigfd >= 0)
close(ts->sigfd); close(ts->sigfd);
}
lxc_list_del(&ts->node); lxc_list_del(&ts->node);
sigprocmask(SIG_SETMASK, &ts->oldmask, NULL); sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
free(ts); free(ts);
...@@ -243,6 +230,7 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data, ...@@ -243,6 +230,7 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
if (w != r) if (w != r)
WARN("console short write r:%d w:%d", r, w); WARN("console short write r:%d w:%d", r, w);
return 0; return 0;
} }
...@@ -302,7 +290,7 @@ int lxc_console_mainloop_add(struct lxc_epoll_descr *descr, ...@@ -302,7 +290,7 @@ int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
return 0; return 0;
} }
static int setup_tios(int fd, struct termios *oldtios) int lxc_setup_tios(int fd, struct termios *oldtios)
{ {
struct termios newtios; struct termios newtios;
...@@ -382,7 +370,7 @@ static int lxc_console_peer_proxy_alloc(struct lxc_console *console, int sockfd) ...@@ -382,7 +370,7 @@ static int lxc_console_peer_proxy_alloc(struct lxc_console *console, int sockfd)
return -1; return -1;
} }
if (setup_tios(console->peerpty.slave, &oldtermio) < 0) if (lxc_setup_tios(console->peerpty.slave, &oldtermio) < 0)
goto err1; goto err1;
ts = lxc_console_sigwinch_init(console->peerpty.master, console->master); ts = lxc_console_sigwinch_init(console->peerpty.master, console->master);
...@@ -435,9 +423,8 @@ int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) ...@@ -435,9 +423,8 @@ int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
} }
/* search for next available tty, fixup index tty1 => [0] */ /* search for next available tty, fixup index tty1 => [0] */
for (ttynum = 1; for (ttynum = 1; ttynum <= tty_info->nbtty && tty_info->pty_info[ttynum - 1].busy; ttynum++)
ttynum <= tty_info->nbtty && tty_info->pty_info[ttynum - 1].busy; ;
ttynum++);
/* we didn't find any available slot for tty */ /* we didn't find any available slot for tty */
if (ttynum > tty_info->nbtty) if (ttynum > tty_info->nbtty)
...@@ -521,7 +508,7 @@ static void lxc_console_peer_default(struct lxc_console *console) ...@@ -521,7 +508,7 @@ static void lxc_console_peer_default(struct lxc_console *console)
goto err1; goto err1;
} }
if (setup_tios(console->peer, console->tios) < 0) if (lxc_setup_tios(console->peer, console->tios) < 0)
goto err2; goto err2;
return; return;
...@@ -629,8 +616,8 @@ int lxc_console_set_stdfds(struct lxc_handler *handler) ...@@ -629,8 +616,8 @@ int lxc_console_set_stdfds(struct lxc_handler *handler)
return 0; return 0;
} }
static int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata, int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct lxc_tty_state *ts = cbdata; struct lxc_tty_state *ts = cbdata;
char c; char c;
...@@ -662,12 +649,12 @@ static int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata, ...@@ -662,12 +649,12 @@ static int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
return 0; return 0;
} }
static int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata, int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct lxc_tty_state *ts = cbdata; struct lxc_tty_state *ts = cbdata;
char buf[1024]; char buf[1024];
int r,w; int r, w;
assert(fd == ts->masterfd); assert(fd == ts->masterfd);
r = read(fd, buf, sizeof(buf)); r = read(fd, buf, sizeof(buf));
...@@ -704,7 +691,7 @@ int lxc_console(struct lxc_container *c, int ttynum, ...@@ -704,7 +691,7 @@ int lxc_console(struct lxc_container *c, int ttynum,
return -1; return -1;
} }
ret = setup_tios(stdinfd, &oldtios); ret = lxc_setup_tios(stdinfd, &oldtios);
if (ret) { if (ret) {
ERROR("failed to setup tios"); ERROR("failed to setup tios");
return -1; return -1;
...@@ -785,3 +772,4 @@ err1: ...@@ -785,3 +772,4 @@ err1:
return ret; return ret;
} }
...@@ -24,8 +24,24 @@ ...@@ -24,8 +24,24 @@
#ifndef __LXC_CONSOLE_H #ifndef __LXC_CONSOLE_H
#define __LXC_CONSOLE_H #define __LXC_CONSOLE_H
#include "conf.h"
#include "list.h"
struct lxc_epoll_descr; struct lxc_epoll_descr;
struct lxc_container; struct lxc_container;
struct lxc_tty_state
{
struct lxc_list node;
int stdinfd;
int stdoutfd;
int masterfd;
int escape;
int saw_escape;
const char *winch_proxy;
const char *winch_proxy_lxcpath;
int sigfd;
sigset_t oldmask;
};
extern int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttynum); extern int lxc_console_allocate(struct lxc_conf *conf, int sockfd, int *ttynum);
extern int lxc_console_create(struct lxc_conf *); extern int lxc_console_create(struct lxc_conf *);
...@@ -40,5 +56,15 @@ extern int lxc_console(struct lxc_container *c, int ttynum, ...@@ -40,5 +56,15 @@ extern int lxc_console(struct lxc_container *c, int ttynum,
extern int lxc_console_getfd(struct lxc_container *c, int *ttynum, extern int lxc_console_getfd(struct lxc_container *c, int *ttynum,
int *masterfd); int *masterfd);
extern int lxc_console_set_stdfds(struct lxc_handler *); extern int lxc_console_set_stdfds(struct lxc_handler *);
extern int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr);
extern int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr);
extern int lxc_setup_tios(int fd, struct termios *oldtios);
extern void lxc_console_winsz(int srcfd, int dstfd);
extern int lxc_console_cb_sigwinch_fd(int fd, uint32_t events, void *cbdata,
struct lxc_epoll_descr *descr);
extern struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd);
extern void lxc_console_sigwinch_fini(struct lxc_tty_state *ts);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment