[libvirt] [PATCH] Improve error reporting when virsh console is run without a TTY
From: Daniel P. Berrange berra...@redhat.com If attempting to run ssh root@somehost virsh console someguest You'll get an error 2012-02-15 13:11:47.683+: 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+: 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 --- tools/virsh.c |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 3be86ed..b97a888 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; -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Improve error reporting when virsh console is run without a TTY
On 02/24/2012 08:13 AM, Daniel P. Berrange wrote: From: Daniel P. Berrange berra...@redhat.com If attempting to run ssh root@somehost virsh console someguest You'll get an error 2012-02-15 13:11:47.683+: 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+: 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. Did you also test 'ssh root@somehost virsh start --console someguest' to make sure that the guest is started, but the console sanely refused? +++ 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); At any rate, this looks sane. ACK. Hmm, we ought to ask gnulib if they will relicense the isatty() module (currently LGPLv3+); as isatty() on mingw has bugs worth working around. -- Eric Blake ebl...@redhat.com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Improve error reporting when virsh console is run without a TTY
From: Daniel P. Berrange berra...@redhat.com If attempting to run ssh root@somehost virsh console someguest You'll get an error 2012-02-15 13:11:47.683+: 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+: 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 --- tools/virsh.c |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 66ba61c..d4d3a83 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; -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Improve error reporting when virsh console is run without a TTY
On Wed, Feb 15, 2012 at 13:16:05 +, Daniel P. Berrange wrote: From: Daniel P. Berrange berra...@redhat.com If attempting to run ssh root@somehost virsh console someguest You'll get an error 2012-02-15 13:11:47.683+: 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+: 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 --- tools/virsh.c |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) ACK Jirka -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list