]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Show 'connected to console' message later
authorAndrea Bolognani <abologna@redhat.com>
Thu, 28 Mar 2024 22:36:40 +0000 (23:36 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Tue, 2 Apr 2024 16:26:35 +0000 (18:26 +0200)
Right now, we display the message before actually attempting
to connect to the VM console. That operation, however, can
fail for a number of reasons: for example, is the VM doesn't
have a serial device, the output ends up looking like

  $ virsh console cirros
  Connected to domain 'cirros'
  Escape character is ^] (Ctrl + ])
  error: internal error: cannot find character device <null>

The initial message is misleading. Change things so that it's
only printed if we actually successfully connected to the VM
console.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tools/virsh-console.c
tools/virsh-domain.c

index 7c561a11f3304c8efba0ede1d8d206ef785a1850..27f2d09f5f1c8a35b66827cefaa19c483a6e1a26 100644 (file)
@@ -418,12 +418,6 @@ virshRunConsole(vshControl *ctl,
 
     sigemptyset(&sighandler.sa_mask);
 
-    /* Put STDIN into raw mode so that stuff typed does not echo to the screen
-     * (the TTY reads will result in it being echoed back already), and also
-     * ensure Ctrl-C, etc is blocked, and misc other bits */
-    if (vshTTYMakeRaw(ctl, true) < 0)
-        goto resettty;
-
     if (!(con = virConsoleNew()))
         goto resettty;
 
@@ -447,6 +441,19 @@ virshRunConsole(vshControl *ctl,
     if (virDomainOpenConsole(dom, dev_name, con->st, flags) < 0)
         goto cleanup;
 
+    vshPrintExtra(ctl, _("Connected to domain '%1$s'\n"), virDomainGetName(dom));
+    vshPrintExtra(ctl, _("Escape character is %1$s"), priv->escapeChar);
+    if (priv->escapeChar[0] == '^')
+        vshPrintExtra(ctl, " (Ctrl + %c)", priv->escapeChar[1]);
+    vshPrintExtra(ctl, "\n");
+    fflush(stdout);
+
+    /* Put STDIN into raw mode so that stuff typed does not echo to the screen
+     * (the TTY reads will result in it being echoed back already), and also
+     * ensure Ctrl-C, etc is blocked, and misc other bits */
+    if (vshTTYMakeRaw(ctl, true) < 0)
+        goto cleanup;
+
     virObjectRef(con);
     if ((con->stdinWatch = virEventAddHandle(STDIN_FILENO,
                                              VIR_EVENT_HANDLE_READABLE,
index 694958f990b3e24740ffc7c556eb65f753d4b69d..3d9c48629a858388a023d006a5dbbbe0e13ac6b5 100644 (file)
@@ -3017,7 +3017,6 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom,
               unsigned int flags)
 {
     int state;
-    virshControl *priv = ctl->privData;
 
     if ((state = virshDomainState(ctl, dom, NULL)) < 0) {
         vshError(ctl, "%s", _("Unable to get domain status"));
@@ -3034,12 +3033,6 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom,
         return false;
     }
 
-    vshPrintExtra(ctl, _("Connected to domain '%1$s'\n"), virDomainGetName(dom));
-    vshPrintExtra(ctl, _("Escape character is %1$s"), priv->escapeChar);
-    if (priv->escapeChar[0] == '^')
-        vshPrintExtra(ctl, " (Ctrl + %c)", priv->escapeChar[1]);
-    vshPrintExtra(ctl, "\n");
-    fflush(stdout);
     if (virshRunConsole(ctl, dom, name, resume_domain, flags) == 0)
         return true;