psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone

Blame 0002-New-API-internal-get-console-socket-to-support-virt-.patch

e83612e
From 0fb454a7887727f7319fecc0caf2d55af3390062 Mon Sep 17 00:00:00 2001
3f26098
From: "Richard W.M. Jones" <rjones@redhat.com>
3f26098
Date: Thu, 2 Mar 2017 11:06:27 +0000
3f26098
Subject: [PATCH 02/10] New API: internal-get-console-socket to support
3f26098
 virt-rescue.
3f26098
3f26098
This API intended for use by virt-rescue only gets the file descriptor
3f26098
of the console socket.
3f26098
3f26098
(cherry picked from commit 84c9f98c2e09a459ced3c7e85191f2e47d149a52)
3f26098
---
3f26098
 generator/actions_core.ml                  | 11 +++++++
3f26098
 generator/actions_properties_deprecated.ml |  4 +--
3f26098
 lib/Makefile.am                            |  1 +
3f26098
 lib/conn-socket.c                          | 16 +++++++++-
3f26098
 lib/guestfs-internal.h                     |  3 ++
3f26098
 lib/rescue.c                               | 47 ++++++++++++++++++++++++++++++
3f26098
 6 files changed, 79 insertions(+), 3 deletions(-)
3f26098
 create mode 100644 lib/rescue.c
3f26098
3f26098
diff --git a/generator/actions_core.ml b/generator/actions_core.ml
1ab6357
index 5e487df02..259ca9051 100644
3f26098
--- a/generator/actions_core.ml
3f26098
+++ b/generator/actions_core.ml
3f26098
@@ -1722,6 +1722,17 @@ call it returns a simple true/false boolean result, instead
3f26098
 of throwing an exception if a feature is not found.  For
3f26098
 other documentation see C<guestfs_available>." };
3f26098
 
3f26098
+  { defaults with
3f26098
+    name = "internal_get_console_socket"; added = (1, 37, 1);
3f26098
+    style = RInt "fd", [], [];
3f26098
+    visibility = VInternal;
3f26098
+    test_excuse = "writing to the socket may block";
3f26098
+    shortdesc = "get the appliance console socket";
3f26098
+    longdesc = "\
3f26098
+This call is used by L<virt-rescue(1)> to write directly to
3f26098
+appliance console (for passing through keystrokes).  It should
3f26098
+not normally be used by other libguestfs users." };
3f26098
+
3f26098
 ]
3f26098
 
3f26098
 let daemon_functions = [
3f26098
diff --git a/generator/actions_properties_deprecated.ml b/generator/actions_properties_deprecated.ml
1ab6357
index 53277822e..f36509e75 100644
3f26098
--- a/generator/actions_properties_deprecated.ml
3f26098
+++ b/generator/actions_properties_deprecated.ml
3f26098
@@ -128,7 +128,7 @@ See C<guestfs_set_backend> and L<guestfs(3)/BACKEND>." };
3f26098
   { defaults with
3f26098
     name = "set_direct"; added = (1, 0, 72);
3f26098
     style = RErr, [Bool "direct"], [];
3f26098
-    deprecated_by = Deprecated_no_replacement;
3f26098
+    deprecated_by = Replaced_by "internal_get_console_socket";
3f26098
     fish_alias = ["direct"]; config_only = true;
3f26098
     blocking = false;
3f26098
     shortdesc = "enable or disable direct appliance mode";
3f26098
@@ -149,7 +149,7 @@ The default is disabled." };
3f26098
   { defaults with
3f26098
     name = "get_direct"; added = (1, 0, 72);
3f26098
     style = RBool "direct", [], [];
3f26098
-    deprecated_by = Deprecated_no_replacement;
3f26098
+    deprecated_by = Replaced_by "internal_get_console_socket";
3f26098
     blocking = false;
3f26098
     shortdesc = "get direct appliance mode flag";
3f26098
     longdesc = "\
3f26098
diff --git a/lib/Makefile.am b/lib/Makefile.am
c4bd84b
index 22974187f..c3e013a52 100644
3f26098
--- a/lib/Makefile.am
3f26098
+++ b/lib/Makefile.am
c4bd84b
@@ -117,6 +117,7 @@ libguestfs_la_SOURCES = \
3f26098
 	private-data.c \
3f26098
 	proto.c \
3f26098
 	qemu.c \
3f26098
+	rescue.c \
3f26098
 	stringsbuf.c \
3f26098
 	structs-compare.c \
3f26098
 	structs-copy.c \
3f26098
diff --git a/lib/conn-socket.c b/lib/conn-socket.c
1ab6357
index 2cd261a2b..8ecfed856 100644
3f26098
--- a/lib/conn-socket.c
3f26098
+++ b/lib/conn-socket.c
3f26098
@@ -1,5 +1,5 @@
3f26098
 /* libguestfs
3f26098
- * Copyright (C) 2013 Red Hat Inc.
3f26098
+ * Copyright (C) 2013-2017 Red Hat Inc.
3f26098
  *
3f26098
  * This library is free software; you can redistribute it and/or
3f26098
  * modify it under the terms of the GNU Lesser General Public
3f26098
@@ -397,6 +397,19 @@ handle_log_message (guestfs_h *g,
3f26098
   return 1;
3f26098
 }
3f26098
 
3f26098
+static int
3f26098
+get_console_sock (guestfs_h *g, struct connection *connv)
3f26098
+{
3f26098
+  struct connection_socket *conn = (struct connection_socket *) connv;
3f26098
+
3f26098
+  if (conn->console_sock == -1) {
3f26098
+    error (g, _("console socket not connected"));
3f26098
+    return -1;
3f26098
+  }
3f26098
+
3f26098
+  return conn->console_sock;
3f26098
+}
3f26098
+
3f26098
 static void
3f26098
 free_conn_socket (guestfs_h *g, struct connection *connv)
3f26098
 {
3f26098
@@ -418,6 +431,7 @@ static struct connection_ops ops = {
3f26098
   .read_data = read_data,
3f26098
   .write_data = write_data,
3f26098
   .can_read_data = can_read_data,
3f26098
+  .get_console_sock = get_console_sock,
3f26098
 };
3f26098
 
3f26098
 /**
3f26098
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
e83612e
index 949cacfef..51f532a1b 100644
3f26098
--- a/lib/guestfs-internal.h
3f26098
+++ b/lib/guestfs-internal.h
3f26098
@@ -373,6 +373,9 @@ struct connection_ops {
3f26098
    * Returns: 1 = yes, 0 = no, -1 = error
3f26098
    */
3f26098
   int (*can_read_data) (guestfs_h *g, struct connection *);
3f26098
+
3f26098
+  /* Get the console socket (to support virt-rescue). */
3f26098
+  int (*get_console_sock) (guestfs_h *g, struct connection *);
3f26098
 };
3f26098
 
3f26098
 /**
3f26098
diff --git a/lib/rescue.c b/lib/rescue.c
3f26098
new file mode 100644
1ab6357
index 000000000..ae7811a31
3f26098
--- /dev/null
3f26098
+++ b/lib/rescue.c
3f26098
@@ -0,0 +1,47 @@
3f26098
+/* libguestfs
3f26098
+ * Copyright (C) 2017 Red Hat Inc.
3f26098
+ *
3f26098
+ * This library is free software; you can redistribute it and/or
3f26098
+ * modify it under the terms of the GNU Lesser General Public
3f26098
+ * License as published by the Free Software Foundation; either
3f26098
+ * version 2 of the License, or (at your option) any later version.
3f26098
+ *
3f26098
+ * This library is distributed in the hope that it will be useful,
3f26098
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3f26098
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3f26098
+ * Lesser General Public License for more details.
3f26098
+ *
3f26098
+ * You should have received a copy of the GNU Lesser General Public
3f26098
+ * License along with this library; if not, write to the Free Software
3f26098
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3f26098
+ */
3f26098
+
3f26098
+/**
3f26098
+ * Support for virt-rescue(1).
3f26098
+ */
3f26098
+
3f26098
+#include <config.h>
3f26098
+
3f26098
+#include <stdio.h>
3f26098
+#include <stdlib.h>
3f26098
+#include <errno.h>
3f26098
+#include <libintl.h>
3f26098
+
3f26098
+#include "guestfs.h"
3f26098
+#include "guestfs-internal.h"
3f26098
+#include "guestfs-internal-actions.h"
3f26098
+
3f26098
+int
3f26098
+guestfs_impl_internal_get_console_socket (guestfs_h *g)
3f26098
+{
3f26098
+  if (!g->conn) {
3f26098
+    error (g, _("no console socket, the handle must be launched"));
3f26098
+    return -1;
3f26098
+  }
3f26098
+
3f26098
+  if (!g->conn->ops->get_console_sock)
3f26098
+    NOT_SUPPORTED (g, -1,
3f26098
+           _("connection class does not support getting the console socket"));
3f26098
+
3f26098
+  return g->conn->ops->get_console_sock (g, g->conn);
3f26098
+}
3f26098
-- 
c4bd84b
2.13.2
3f26098