Blame SOURCES/0054-New-API-internal-get-console-socket-to-support-virt-.patch

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