]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
* src/makefile.am src/libxen.c src/xensh.c: add a small tool sensh,
authorDaniel Veillard <veillard@redhat.com>
Thu, 10 Nov 2005 16:12:31 +0000 (16:12 +0000)
committerDaniel Veillard <veillard@redhat.com>
Thu, 10 Nov 2005 16:12:31 +0000 (16:12 +0000)
  implement xenopenconnect and xencloseconnect.
Daniel

ChangeLog
src/Makefile.am
src/libxen.c
src/xensh.c [new file with mode: 0644]

index 2f02aefa422b281cc39d46bea06d5efb85f07b1e..cf243547da65bed0ed3e8e1e17ef0c92c346ce84 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Nov 10 17:11:03 CET 2005 Daniel Veillard <veillard@redhat.com>
+
+       * src/makefile.am src/libxen.c src/xensh.c: add a small tool sensh,
+         implement xenopenconnect and xencloseconnect.
+
 Wed Nov  9 10:57:12 CET 2005 Daniel Veillard <veillard@redhat.com>
 
        * docs/Goals: added a Goals document for the library
index c54dd1e410fc36c726e5e78fe8940b86a5e1a242..3ca31023c5e5f41b2a062cc3279ec62a70bd9890 100644 (file)
@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
 
 INCLUDES = -I$(top_builddir)/include -I@srcdir@/include
+DEPS = libxen.la
+LDADDS = libxen.la
 
 EXTRA_DIST = libxen_sym.version
 
@@ -9,3 +11,11 @@ libxen_la_LIBADD =
 libxen_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libxen_sym.version \
                     -version-info @LIBXEN_VERSION_INFO@
 libxen_la_SOURCES = libxen.c internal.h
+
+noinst_PROGRAMS=xensh
+
+xensh_SOURCES=xensh.c
+xensh_LDFLAGS =
+xensh_DEPENDENCIES = $(DEPS)
+xensh_LDADD= $(LDADDS)
+
index 7aba219e9ee9355809dd9e3f700448279be3b56a..ff107ca351a15524c522f841557abc9477551cd7 100644 (file)
@@ -18,6 +18,8 @@
  * TODO:
  * - use lock to protect against concurrent accesses ?
  * - use reference counting to garantee coherent pointer state ?
+ * - error reporting layer
+ * - memory wrappers for malloc/free ?
  */
 
 #define XEN_CONNECT_MAGIC 0x4F23DEAD
@@ -42,7 +44,22 @@ struct _xenConnect {
  */
 xenConnectPtr
 xenOpenConnect(const char *name) {
-    return(NULL);
+    xenConnectPtr ret;
+    int handle;
+
+    handle = xc_interface_open();
+    if (handle == -1) {
+        return(NULL);
+    }
+    ret = (xenConnectPtr) malloc(sizeof(xenConnect));
+    if (ret == NULL) {
+        xc_interface_close(handle);
+        return(NULL);
+    }
+    ret->magic = XEN_CONNECT_MAGIC;
+    ret->handle = handle;
+
+    return(ret);
 }
 
 /**
@@ -60,11 +77,10 @@ int
 xenCloseConnect(xenConnectPtr conn) {
     if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC))
         return(-1);
-    /*
-     * TODO:
-     * Free the domain pointers associated to this connection
-     */
+
     conn->magic = -1;
+    xc_interface_close(conn->handle);
+    conn->handle = -1;
     free(conn);
     return(0);
 }
diff --git a/src/xensh.c b/src/xensh.c
new file mode 100644 (file)
index 0000000..6299892
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * xensh.c: a Xen shell used to exercise the libxen API
+ *
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Daniel Veillard <veillard@redhat.com>
+ */
+
+#include "libxen.h"
+#include <stdio.h>
+
+int errcode = 0;
+xenConnectPtr conn;
+
+int main(int argc, char **argv) {
+    int ret;
+    
+    conn = xenOpenConnect(NULL);
+    if (conn == NULL) {
+        fprintf(stderr, "Failed to connect to the hypervisor\n");
+        errcode = 1;
+       goto done;
+    }
+
+done:
+    if (conn != NULL) {
+        ret = xenCloseConnect(conn);
+       if (ret != 0) {
+           fprintf(stderr, "Failed to connect to the hypervisor\n");
+           if (errcode == 0)
+               errcode = 1;
+       }
+    }
+    exit(errcode);
+}