return 0;
}
-extern int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
- struct lxc_conf *conf)
+int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
+ struct lxc_console *console)
{
int ret;
- struct lxc_console *console = &conf->console;
-
- if (!conf->rootfs.path) {
- INFO("no rootfs, no console.");
- return 0;
- }
if (console->master < 0) {
INFO("no console");
return 0;
}
- if (lxc_mainloop_add_handler(descr, console->master,
- lxc_console_cb_con, console)) {
- ERROR("failed to add to mainloop console handler for '%d'",
- console->master);
+ ret = lxc_mainloop_add_handler(descr, console->master,
+ lxc_console_cb_con, console);
+ if (ret < 0) {
+ ERROR("Failed to add handler for %d to mainloop", console->master);
return -1;
}
- /* we cache the descr so that we can add an fd to it when someone
- * does attach to it in lxc_console_allocate()
+ /* We cache the descr so that we can add an fd to it when someone
+ * does attach to it in lxc_console_allocate().
*/
console->descr = descr;
ret = lxc_console_mainloop_add_peer(console);
int lxc_poll(const char *name, struct lxc_handler *handler)
{
int ret;
+ bool has_console = (handler->conf->rootfs.path != NULL);
struct lxc_epoll_descr descr, descr_console;
ret = lxc_mainloop_open(&descr);
goto out_sigfd;
}
- ret = lxc_mainloop_open(&descr_console);
- if (ret < 0) {
- ERROR("Failed to create console mainloop");
- goto out_mainloop;
+ if (has_console) {
+ ret = lxc_mainloop_open(&descr_console);
+ if (ret < 0) {
+ ERROR("Failed to create console mainloop");
+ goto out_mainloop;
+ }
}
ret = lxc_mainloop_add_handler(&descr, handler->sigfd, signal_handler, handler);
goto out_mainloop_console;
}
- ret = lxc_console_mainloop_add(&descr, handler->conf);
- if (ret < 0) {
- ERROR("Failed to add console handlers to mainloop");
- goto out_mainloop_console;
- }
+ if (has_console) {
+ struct lxc_console *console = &handler->conf->console;
- ret = lxc_console_mainloop_add(&descr_console, handler->conf);
- if (ret < 0) {
- ERROR("Failed to add console handlers to console mainloop");
- goto out_mainloop_console;
+ ret = lxc_console_mainloop_add(&descr, console);
+ if (ret < 0) {
+ ERROR("Failed to add console handlers to mainloop");
+ goto out_mainloop_console;
+ }
+
+ ret = lxc_console_mainloop_add(&descr_console, console);
+ if (ret < 0) {
+ ERROR("Failed to add console handlers to console mainloop");
+ goto out_mainloop_console;
+ }
}
ret = lxc_cmd_mainloop_add(name, &descr, handler);
if (ret < 0 || !handler->init_died)
goto out_mainloop;
- ret = lxc_mainloop(&descr_console, 0);
+ if (has_console)
+ ret = lxc_mainloop(&descr_console, 0);
+
out_mainloop:
lxc_mainloop_close(&descr);
TRACE("Closed mainloop");
out_mainloop_console:
- lxc_mainloop_close(&descr_console);
- TRACE("Closed console mainloop");
+ if (has_console) {
+ lxc_mainloop_close(&descr_console);
+ TRACE("Closed console mainloop");
+ }
out_sigfd:
close(handler->sigfd);