From: Daniel P. Berrange Date: Wed, 15 Feb 2012 13:12:11 +0000 (+0000) Subject: Improve error reporting when virsh console is run without a TTY X-Git-Tag: v0.9.11-rc1~226 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af6b61ba06002239fad248e88553b437e538b5c4;p=thirdparty%2Flibvirt.git Improve error reporting when virsh console is run without a TTY If attempting to run ssh root@somehost virsh console someguest You'll get an error 2012-02-15 13:11:47.683+0000: 4765: info : libvirt version: 0.9.10, package: 1.fc18 (Unknown, 2012-02-15-11:48:57, lettuce.camlab.fab.redhat.com) 2012-02-15 13:11:47.683+0000: 4765: error : vshRunConsole:320 : unable to get tty attributes: Invalid argument Connected to domain f16x86_64 Escape character is ^] There are several problems here - The actual error message is bad for users - We shouldn't rely on VIR_ERROR for this case - The prompt makes it look like we still connected because we didn't flush stdout. * virsh.c: Flush stdout before starting console and check for a valid tty --- diff --git a/tools/virsh.c b/tools/virsh.c index 3be86ed97b..b97a8880cd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -838,8 +838,14 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom, const char *name) goto cleanup; } + if (!isatty(STDIN_FILENO)) { + vshError(ctl, "%s", _("Cannot run interactive console without a controlling TTY")); + goto cleanup; + } + vshPrintExtra(ctl, _("Connected to domain %s\n"), virDomainGetName(dom)); vshPrintExtra(ctl, _("Escape character is %s\n"), ctl->escapeChar); + fflush(stdout); if (vshRunConsole(dom, name, ctl->escapeChar) == 0) ret = true;