From 7e1cbd14bb3fe604466b90ed65f0aebf6207a74c Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 4 Sep 2013 15:57:30 -0600 Subject: [PATCH] virsh: fix build on mingw, which lacks termios stuff Recent patches to fix handling of Ctrl-C when interacting with ssh are not portable to mingw, which lacks termios handling. The simplest solution is to just compile that code out, and if someone ever appears that has a serious interest in getting virsh fully functional even with ssh connections, they can provide patches at that time. * tools/virsh.h (_vshControl): Make termattr conditional. * tools/virsh.c (vshTTYIsInterruptCharacter) (vshTTYDisableInterrupt, vshTTYRestore, cfmakeraw, vshTTYMakeRaw) (main): Likewise. Signed-off-by: Eric Blake --- tools/virsh.c | 25 ++++++++++++++++++------- tools/virsh.h | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 37e971659f..bf2fbf81c7 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2213,20 +2213,23 @@ vshPrintExtra(vshControl *ctl, const char *format, ...) bool -vshTTYIsInterruptCharacter(vshControl *ctl, - const char chr) +vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED, + const char chr ATTRIBUTE_UNUSED) { +#ifndef WIN32 if (ctl->istty && ctl->termattr.c_cc[VINTR] == chr) return true; +#endif return false; } int -vshTTYDisableInterrupt(vshControl *ctl) +vshTTYDisableInterrupt(vshControl *ctl ATTRIBUTE_UNUSED) { +#ifndef WIN32 struct termios termset = ctl->termattr; if (!ctl->istty) @@ -2241,25 +2244,28 @@ vshTTYDisableInterrupt(vshControl *ctl) if (tcsetattr(STDIN_FILENO, TCSANOW, &termset) < 0) return -1; +#endif return 0; } int -vshTTYRestore(vshControl *ctl) +vshTTYRestore(vshControl *ctl ATTRIBUTE_UNUSED) { +#ifndef WIN32 if (!ctl->istty) return 0; if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &ctl->termattr) < 0) return -1; +#endif return 0; } -#ifndef HAVE_CFMAKERAW +#if !defined(WIN32) && !defined(HAVE_CFMAKERAW) /* provide fallback in case cfmakeraw isn't available */ static void cfmakeraw(struct termios *attr) @@ -2271,12 +2277,14 @@ cfmakeraw(struct termios *attr) attr->c_cflag &= ~(CSIZE | PARENB); attr->c_cflag |= CS8; } -#endif /* !HAVE_CFMAKERAW */ +#endif /* !WIN32 && !HAVE_CFMAKERAW */ int -vshTTYMakeRaw(vshControl *ctl, bool report_errors) +vshTTYMakeRaw(vshControl *ctl ATTRIBUTE_UNUSED, + bool report_errors ATTRIBUTE_UNUSED) { +#ifndef WIN32 struct termios rawattr = ctl->termattr; char ebuf[1024]; @@ -2297,6 +2305,7 @@ vshTTYMakeRaw(vshControl *ctl, bool report_errors) virStrerror(errno, ebuf, sizeof(ebuf))); return -1; } +#endif return 0; } @@ -3249,8 +3258,10 @@ main(int argc, char **argv) if (isatty(STDIN_FILENO)) { ctl->istty = true; +#ifndef WIN32 if (tcgetattr(STDIN_FILENO, &ctl->termattr) < 0) ctl->istty = false; +#endif } if (virMutexInit(&ctl->lock) < 0) { diff --git a/tools/virsh.h b/tools/virsh.h index 8afe13f60d..b5e2715e65 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -242,7 +242,9 @@ struct _vshControl { const char *escapeChar; /* String representation of console escape character */ +# ifndef WIN32 struct termios termattr; /* settings of the tty terminal */ +# endif bool istty; /* is the terminal a tty */ }; -- GitLab