mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-01 22:02:33 +00:00
Merge pull request #951 from brauner/2016-04-07/lxc_attach_sigwinch_handler
lxc-attach: attach even without sigwinch handler
This commit is contained in:
commit
aa3ea4d3cc
@ -118,9 +118,9 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(ts, 0, sizeof(*ts));
|
memset(ts, 0, sizeof(*ts));
|
||||||
ts->stdinfd = srcfd;
|
ts->stdinfd = srcfd;
|
||||||
ts->masterfd = dstfd;
|
ts->masterfd = dstfd;
|
||||||
ts->sigfd = -1;
|
ts->sigfd = -1;
|
||||||
|
|
||||||
/* add tty to list to be scanned at SIGWINCH time */
|
/* add tty to list to be scanned at SIGWINCH time */
|
||||||
lxc_list_add_elem(&ts->node, ts);
|
lxc_list_add_elem(&ts->node, ts);
|
||||||
@ -129,26 +129,20 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd)
|
|||||||
sigemptyset(&mask);
|
sigemptyset(&mask);
|
||||||
sigaddset(&mask, SIGWINCH);
|
sigaddset(&mask, SIGWINCH);
|
||||||
if (sigprocmask(SIG_BLOCK, &mask, &ts->oldmask)) {
|
if (sigprocmask(SIG_BLOCK, &mask, &ts->oldmask)) {
|
||||||
SYSERROR("failed to block SIGWINCH");
|
SYSERROR("failed to block SIGWINCH.");
|
||||||
goto err1;
|
ts->sigfd = -1;
|
||||||
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
ts->sigfd = signalfd(-1, &mask, 0);
|
ts->sigfd = signalfd(-1, &mask, 0);
|
||||||
if (ts->sigfd < 0) {
|
if (ts->sigfd < 0) {
|
||||||
SYSERROR("failed to get signalfd");
|
SYSERROR("failed to get signalfd.");
|
||||||
goto err2;
|
sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
|
||||||
|
ts->sigfd = -1;
|
||||||
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("%d got SIGWINCH fd %d", getpid(), ts->sigfd);
|
DEBUG("%d got SIGWINCH fd %d", getpid(), ts->sigfd);
|
||||||
goto out;
|
|
||||||
|
|
||||||
err2:
|
|
||||||
sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
|
|
||||||
err1:
|
|
||||||
lxc_list_del(&ts->node);
|
|
||||||
free(ts);
|
|
||||||
ts = NULL;
|
|
||||||
out:
|
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +201,7 @@ static void lxc_console_mainloop_add_peer(struct lxc_console *console)
|
|||||||
WARN("console peer not added to mainloop");
|
WARN("console peer not added to mainloop");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (console->tty_state) {
|
if (console->tty_state && console->tty_state->sigfd != -1) {
|
||||||
if (lxc_mainloop_add_handler(console->descr,
|
if (lxc_mainloop_add_handler(console->descr,
|
||||||
console->tty_state->sigfd,
|
console->tty_state->sigfd,
|
||||||
lxc_console_cb_sigwinch_fd,
|
lxc_console_cb_sigwinch_fd,
|
||||||
@ -291,7 +285,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
|
|||||||
|
|
||||||
static void lxc_console_peer_proxy_free(struct lxc_console *console)
|
static void lxc_console_peer_proxy_free(struct lxc_console *console)
|
||||||
{
|
{
|
||||||
if (console->tty_state) {
|
if (console->tty_state && console->tty_state->sigfd != -1) {
|
||||||
lxc_console_sigwinch_fini(console->tty_state);
|
lxc_console_sigwinch_fini(console->tty_state);
|
||||||
console->tty_state = NULL;
|
console->tty_state = NULL;
|
||||||
}
|
}
|
||||||
@ -446,9 +440,11 @@ static void lxc_console_peer_default(struct lxc_console *console)
|
|||||||
goto err1;
|
goto err1;
|
||||||
|
|
||||||
ts = lxc_console_sigwinch_init(console->peer, console->master);
|
ts = lxc_console_sigwinch_init(console->peer, console->master);
|
||||||
if (!ts)
|
|
||||||
WARN("Unable to install SIGWINCH");
|
|
||||||
console->tty_state = ts;
|
console->tty_state = ts;
|
||||||
|
if (!ts) {
|
||||||
|
WARN("Unable to install SIGWINCH");
|
||||||
|
goto err1;
|
||||||
|
}
|
||||||
|
|
||||||
lxc_console_winsz(console->peer, console->master);
|
lxc_console_winsz(console->peer, console->master);
|
||||||
|
|
||||||
@ -471,6 +467,7 @@ err1:
|
|||||||
console->peer = -1;
|
console->peer = -1;
|
||||||
out:
|
out:
|
||||||
DEBUG("no console peer");
|
DEBUG("no console peer");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lxc_console_delete(struct lxc_console *console)
|
void lxc_console_delete(struct lxc_console *console)
|
||||||
@ -695,11 +692,13 @@ int lxc_console(struct lxc_container *c, int ttynum,
|
|||||||
goto err3;
|
goto err3;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = lxc_mainloop_add_handler(&descr, ts->sigfd,
|
if (ts->sigfd != -1) {
|
||||||
lxc_console_cb_sigwinch_fd, ts);
|
ret = lxc_mainloop_add_handler(&descr, ts->sigfd,
|
||||||
if (ret) {
|
lxc_console_cb_sigwinch_fd, ts);
|
||||||
ERROR("failed to add handler for SIGWINCH fd");
|
if (ret) {
|
||||||
goto err4;
|
ERROR("failed to add handler for SIGWINCH fd");
|
||||||
|
goto err4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = lxc_mainloop_add_handler(&descr, ts->stdinfd,
|
ret = lxc_mainloop_add_handler(&descr, ts->stdinfd,
|
||||||
@ -727,7 +726,8 @@ int lxc_console(struct lxc_container *c, int ttynum,
|
|||||||
err4:
|
err4:
|
||||||
lxc_mainloop_close(&descr);
|
lxc_mainloop_close(&descr);
|
||||||
err3:
|
err3:
|
||||||
lxc_console_sigwinch_fini(ts);
|
if (ts->sigfd != -1)
|
||||||
|
lxc_console_sigwinch_fini(ts);
|
||||||
err2:
|
err2:
|
||||||
close(masterfd);
|
close(masterfd);
|
||||||
close(ttyfd);
|
close(ttyfd);
|
||||||
|
@ -47,7 +47,9 @@ struct lxc_tty_state
|
|||||||
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 SIGWINCH signals. */
|
/* File descriptor that accepts SIGWINCH signals. If set to -1 no
|
||||||
|
* SIGWINCH handler could be installed. This also means that
|
||||||
|
* the sigset_t oldmask member is meaningless. */
|
||||||
int sigfd;
|
int sigfd;
|
||||||
sigset_t oldmask;
|
sigset_t oldmask;
|
||||||
};
|
};
|
||||||
|
@ -264,7 +264,6 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
|
|||||||
* always do the correct thing. strdup() must be used since console.path
|
* always do the correct thing. strdup() must be used since console.path
|
||||||
* is free()ed when we call lxc_container_put(). */
|
* is free()ed when we call lxc_container_put(). */
|
||||||
free(conf->console.path);
|
free(conf->console.path);
|
||||||
conf->console.path = NULL;
|
|
||||||
conf->console.path = strdup("/dev/tty");
|
conf->console.path = strdup("/dev/tty");
|
||||||
if (!conf->console.path)
|
if (!conf->console.path)
|
||||||
return -1;
|
return -1;
|
||||||
@ -326,12 +325,17 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
|
|||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register sigwinch handler in mainloop. */
|
/* Register sigwinch handler in mainloop. When ts->sigfd == -1 it means
|
||||||
ret = lxc_mainloop_add_handler(&descr, ts->sigfd,
|
* we weren't able to install a sigwinch handler in
|
||||||
lxc_console_cb_sigwinch_fd, ts);
|
* lxc_console_create(). We don't consider this fatal and just move on.
|
||||||
if (ret) {
|
*/
|
||||||
ERROR("failed to add handler for SIGWINCH fd");
|
if (ts->sigfd != -1) {
|
||||||
goto err3;
|
ret = lxc_mainloop_add_handler(&descr, ts->sigfd,
|
||||||
|
lxc_console_cb_sigwinch_fd, ts);
|
||||||
|
if (ret) {
|
||||||
|
ERROR("failed to add handler for SIGWINCH fd");
|
||||||
|
goto err3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register i/o callbacks in mainloop. */
|
/* Register i/o callbacks in mainloop. */
|
||||||
@ -359,7 +363,8 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
|
|||||||
err3:
|
err3:
|
||||||
lxc_mainloop_close(&descr);
|
lxc_mainloop_close(&descr);
|
||||||
err2:
|
err2:
|
||||||
lxc_console_sigwinch_fini(ts);
|
if (ts->sigfd != -1)
|
||||||
|
lxc_console_sigwinch_fini(ts);
|
||||||
err1:
|
err1:
|
||||||
lxc_console_delete(&conf->console);
|
lxc_console_delete(&conf->console);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user