Commit 7b863cc0 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Wire up text console I/O class

parent 89a1e74b
......@@ -7,7 +7,9 @@ AC_CANONICAL_HOST
AM_SILENT_RULES([yes])
GIO_UNIX_REQUIRED=2.28.0
GOBJECT_REQUIRED=2.28.0
LIBVIRT_GLIB_REQUIRED=0.0.2
LIBVIRT_GOBJECT_REQUIRED=0.0.2
GOBJECT_INTROSPECTION_REQUIRED=0.10.8
......@@ -41,7 +43,9 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name])
dnl IT_PROG_INTLTOOL([0.35.0])
PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0 >= $GIO_UNIX_REQUIRED)
PKG_CHECK_MODULES(GOBJECT, gobject-2.0 >= $GOBJECT_REQUIRED)
PKG_CHECK_MODULES(LIBVIRT_GLIB, libvirt-glib-1.0 >= $LIBVIRT_GOBJECT_REQUIRED)
PKG_CHECK_MODULES(LIBVIRT_GOBJECT, libvirt-gobject-1.0 >= $LIBVIRT_GOBJECT_REQUIRED)
......
......@@ -2,6 +2,7 @@
const LibvirtGObject = imports.gi.LibvirtGObject;
const LibvirtSandbox = imports.gi.LibvirtSandbox;
const Gtk = imports.gi.Gtk;
LibvirtGObject.init_object_check(null, null);
......@@ -11,4 +12,19 @@ conn.open(null)
var ctxt = LibvirtSandbox.Context.new(conn, cfg);
ctxt.start();
var con = ctxt.get_console()
var closed = function(error) {
Gtk.main_quit();
}
con.connect("closed", closed);
con.attach_stdio()
Gtk.main()
con.detach()
ctxt.stop();
......@@ -4,15 +4,38 @@ use strict;
use warnings;
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(basename => 'GLib', version => '2.0', package => 'GLib');
Glib::Object::Introspection->setup(basename => 'Gtk', version => '3.0', package => 'Gtk');
Glib::Object::Introspection->setup(basename => 'LibvirtGObject', version => '1.0', package => 'LibvirtGObject');
Glib::Object::Introspection->setup(basename => 'LibvirtSandbox', version => '1.0', package => 'LibvirtSandbox');
LibvirtGObject::init_object_check(undef);
sub do_quit {
Gtk::main_quit();
}
print "Foo\n";
my $cfg = LibvirtSandbox::Config->new("sandbox");
my $conn = LibvirtGObject::Connection->new("qemu:///session");
$conn->open(undef);
my $ctxt = LibvirtSandbox::Context->new($conn, $cfg);
$ctxt->start();
my $con = $ctxt->get_console();
$con->connect("closed", \&do_quit);
$con->attach_stdio();
GLib::timeout_add(5000, \&do_quit);
Gtk::main();
$con->detach();
$ctxt->stop();
......@@ -2,13 +2,37 @@
from gi.repository import LibvirtGObject
from gi.repository import LibvirtSandbox
from gi.repository import GLib
from gi.repository import Gtk
import sys
args = sys.argv[1:]
LibvirtGObject.init_object_check(None)
cfg = LibvirtSandbox.Config.new("sandbox")
cfg.set_command(args)
cfg.set_tty(True)
conn = LibvirtGObject.Connection.new("qemu:///session")
conn.open(None)
ctxt = LibvirtSandbox.Context.new(conn, cfg)
ctxt.start()
ctxt.stop()
con = ctxt.get_console()
def closed(obj, error):
Gtk.main_quit()
con.connect("closed", closed)
con.attach_stdio()
Gtk.main()
try:
con.detach()
ctxt.stop()
except:
pass
finally:
pass
......@@ -60,6 +60,7 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-builder-initrd.h \
libvirt-sandbox-builder-machine.h \
libvirt-sandbox-builder-container.h \
libvirt-sandbox-console.h \
libvirt-sandbox-context.h \
libvirt-sandbox-context-graphical.h \
$(NULL)
......@@ -73,6 +74,7 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-builder-initrd.c \
libvirt-sandbox-builder-machine.c \
libvirt-sandbox-builder-container.c \
libvirt-sandbox-console.c \
libvirt-sandbox-context.c \
libvirt-sandbox-context-graphical.c \
$(NULL)
......@@ -89,9 +91,13 @@ libvirt_sandbox_1_0_la_CFLAGS = \
-DLIBEXECDIR="\"$(libexecdir)\"" \
$(COVERAGE_CFLAGS) \
-I$(top_srcdir) \
$(GIO_UNIX_CFLAGS) \
$(LIBVIRT_GLIB_CFLAGS) \
$(LIBVIRT_GOBJECT_CFLAGS) \
$(WARN_CFLAGS)
libvirt_sandbox_1_0_la_LIBADD = \
$(GIO_UNIX_LIBS) \
$(LIBVIRT_GLIB_LIBS) \
$(LIBVIRT_GOBJECT_LIBS) \
$(CYGWIN_EXTRA_LIBADD)
libvirt_sandbox_1_0_la_DEPENDENCIES = \
......
This diff is collapsed.
/*
* libvirt-sandbox-console.h: libvirt sandbox console
*
* Copyright (C) 2011 Red Hat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#if !defined(__LIBVIRT_SANDBOX_H__) && !defined(LIBVIRT_SANDBOX_BUILD)
#error "Only <libvirt-sandbox/libvirt-sandbox.h> can be included directly."
#endif
#ifndef __LIBVIRT_SANDBOX_CONSOLE_H__
#define __LIBVIRT_SANDBOX_CONSOLE_H__
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>
G_BEGIN_DECLS
#define GVIR_SANDBOX_TYPE_CONSOLE (gvir_sandbox_console_get_type ())
#define GVIR_SANDBOX_CONSOLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_SANDBOX_TYPE_CONSOLE, GVirSandboxConsole))
#define GVIR_SANDBOX_CONSOLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_SANDBOX_TYPE_CONSOLE, GVirSandboxConsoleClass))
#define GVIR_SANDBOX_IS_CONSOLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_SANDBOX_TYPE_CONSOLE))
#define GVIR_SANDBOX_IS_CONSOLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_SANDBOX_TYPE_CONSOLE))
#define GVIR_SANDBOX_CONSOLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_SANDBOX_TYPE_CONSOLE, GVirSandboxConsoleClass))
#define GVIR_SANDBOX_TYPE_CONSOLE_HANDLE (gvir_sandbox_console_handle_get_type ())
typedef struct _GVirSandboxConsole GVirSandboxConsole;
typedef struct _GVirSandboxConsolePrivate GVirSandboxConsolePrivate;
typedef struct _GVirSandboxConsoleClass GVirSandboxConsoleClass;
struct _GVirSandboxConsole
{
GObject parent;
GVirSandboxConsolePrivate *priv;
/* Do not add fields to this struct */
};
struct _GVirSandboxConsoleClass
{
GObjectClass parent_class;
void (*closed)(GVirSandboxConsole *console, gboolean err);
};
GType gvir_sandbox_console_get_type(void);
GVirSandboxConsole *gvir_sandbox_console_new(GVirConnection *connection,
GVirDomain *domain);
gboolean gvir_sandbox_console_attach_stdio(GVirSandboxConsole *console,
GError **error);
gboolean gvir_sandbox_console_attach(GVirSandboxConsole *console,
GUnixInputStream *localStdin,
GUnixOutputStream *localStdout,
GUnixOutputStream *localStderr,
GError **error);
gboolean gvir_sandbox_console_detach(GVirSandboxConsole *console,
GError **error);
G_END_DECLS
#endif /* __LIBVIRT_SANDBOX_CONSOLE_H__ */
......@@ -32,6 +32,8 @@ struct _GVirSandboxContextPrivate
GVirConnection *connection;
GVirDomain *domain;
GVirSandboxConfig *config;
GVirSandboxConsole *console;
gboolean active;
GVirSandboxBuilder *builder;
GVirSandboxCleaner *cleaner;
......@@ -127,6 +129,9 @@ static void gvir_sandbox_context_finalize(GObject *object)
GVirSandboxContext *ctxt = GVIR_SANDBOX_CONTEXT(object);
GVirSandboxContextPrivate *priv = ctxt->priv;
if (priv->active)
gvir_sandbox_context_stop(ctxt, NULL);
if (priv->domain)
g_object_unref(priv->domain);
if (priv->connection)
......@@ -311,6 +316,9 @@ gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error)
if (!(gvir_sandbox_cleaner_run_post_start(priv->cleaner, NULL)))
goto error;
priv->console = gvir_sandbox_console_new(priv->connection, priv->domain);
priv->active = TRUE;
g_object_unref(config);
return TRUE;
......@@ -353,5 +361,24 @@ gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error)
g_object_unref(priv->cleaner);
priv->cleaner = gvir_sandbox_cleaner_new();
g_object_unref(priv->console);
priv->console = NULL;
priv->active = FALSE;
return ret;
}
/**
* gvir_sandbox_context_get_console:
* @ctxt: (transfer none): the sandbox context
*
* Returns: (transfer full)(allow-none): the sandbox console (or NULL)
*/
GVirSandboxConsole *gvir_sandbox_context_get_console(GVirSandboxContext *ctxt)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
return g_object_ref(priv->console);
}
......@@ -71,9 +71,7 @@ gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error);
GVirDomain *gvir_sandbox_context_get_domain(GVirSandboxContext *ctxt);
GVirConnection *gvir_sandbox_context_get_connection(GVirSandboxContext *ctxt);
#if 0
GVirSandboxConsole *gvir_sandbox_context_get_console(GVirSandboxContext *ctxt);
#endif
G_END_DECLS
......
......@@ -330,12 +330,12 @@ decode_command(const char *base64str, char ***retargv)
{
gsize len;
gchar *cmdstr;
int theargc = 0;
char **theargv = NULL;
char *end;
long long int ret;
char *cmd;
char **tmp;
int theargc = 0;
char **theargv = NULL;
char *end;
long long int ret;
char *cmd;
char **tmp;
if (!(cmdstr = (char*)g_base64_decode(base64str, &len))) {
fprintf(stderr, "libvirt-sandbox-init-common: %s: cannot decode %s\n",
......@@ -869,7 +869,6 @@ int main(int argc, char **argv) {
cmdarg = argv[optind];
setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin/:/usr/sbin", 1);
struct rlimit res = { 65536, 65536 };
setrlimit(RLIMIT_NOFILE, &res);
......
......@@ -398,8 +398,8 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
#ifdef STRACE
args[narg++] = STRACE;
args[narg++] = "-f";
args[narg++] = "-e";
args[narg++] = STRACE_FILTER;
// args[narg++] = "-e";
// args[narg++] = STRACE_FILTER;
args[narg++] = "-s";
args[narg++] = "2000";
#endif
......@@ -424,7 +424,7 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
args[narg++] = cmdargs;
if (debug)
fprintf(stderr, "Running common init\n");
fprintf(stderr, "libvirt-sandbox-init-qemu: Running common init %s\n", args[0]);
execv(args[0], (char**)args);
fprintf(stderr, "libvirt-sandbox-init-qemu: %s: cannot execute %s: %s\n",
__func__, args[0], strerror(errno));
......
......@@ -36,6 +36,7 @@
#include <libvirt-sandbox/libvirt-sandbox-builder-initrd.h>
#include <libvirt-sandbox/libvirt-sandbox-builder-machine.h>
#include <libvirt-sandbox/libvirt-sandbox-builder-container.h>
#include <libvirt-sandbox/libvirt-sandbox-console.h>
#include <libvirt-sandbox/libvirt-sandbox-context.h>
#include <libvirt-sandbox/libvirt-sandbox-context-graphical.h>
......
......@@ -21,12 +21,14 @@ LIBVIRT_SANDBOX_0.0.1 {
gvir_sandbox_config_get_mounts;
gvir_sandbox_config_get_name;
gvir_sandbox_config_get_root;
gvir_sandbox_config_get_tty;
gvir_sandbox_config_get_security_level;
gvir_sandbox_config_get_security_type;
gvir_sandbox_config_get_type;
gvir_sandbox_config_new;
gvir_sandbox_config_set_command;
gvir_sandbox_config_set_root;
gvir_sandbox_config_set_tty;
gvir_sandbox_config_set_security_level;
gvir_sandbox_config_set_security_type;
......@@ -39,10 +41,17 @@ LIBVIRT_SANDBOX_0.0.1 {
gvir_sandbox_config_initrd_set_init;
gvir_sandbox_config_initrd_set_kver;
gvir_sandbox_console_get_type;
gvir_sandbox_console_new;
gvir_sandbox_console_attach;
gvir_sandbox_console_attach_stdio;
gvir_sandbox_console_detach;
gvir_sandbox_context_get_type;
gvir_sandbox_context_get_config;
gvir_sandbox_context_get_domain;
gvir_sandbox_context_get_connection;
gvir_sandbox_context_get_console;
gvir_sandbox_context_new;
gvir_sandbox_context_start;
gvir_sandbox_context_stop;
......
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