提交 7e1cbd14 编写于 作者: E Eric Blake

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: NEric Blake <eblake@redhat.com>
上级 5236aed8
...@@ -2213,20 +2213,23 @@ vshPrintExtra(vshControl *ctl, const char *format, ...) ...@@ -2213,20 +2213,23 @@ vshPrintExtra(vshControl *ctl, const char *format, ...)
bool bool
vshTTYIsInterruptCharacter(vshControl *ctl, vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED,
const char chr) const char chr ATTRIBUTE_UNUSED)
{ {
#ifndef WIN32
if (ctl->istty && if (ctl->istty &&
ctl->termattr.c_cc[VINTR] == chr) ctl->termattr.c_cc[VINTR] == chr)
return true; return true;
#endif
return false; return false;
} }
int int
vshTTYDisableInterrupt(vshControl *ctl) vshTTYDisableInterrupt(vshControl *ctl ATTRIBUTE_UNUSED)
{ {
#ifndef WIN32
struct termios termset = ctl->termattr; struct termios termset = ctl->termattr;
if (!ctl->istty) if (!ctl->istty)
...@@ -2241,25 +2244,28 @@ vshTTYDisableInterrupt(vshControl *ctl) ...@@ -2241,25 +2244,28 @@ vshTTYDisableInterrupt(vshControl *ctl)
if (tcsetattr(STDIN_FILENO, TCSANOW, &termset) < 0) if (tcsetattr(STDIN_FILENO, TCSANOW, &termset) < 0)
return -1; return -1;
#endif
return 0; return 0;
} }
int int
vshTTYRestore(vshControl *ctl) vshTTYRestore(vshControl *ctl ATTRIBUTE_UNUSED)
{ {
#ifndef WIN32
if (!ctl->istty) if (!ctl->istty)
return 0; return 0;
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &ctl->termattr) < 0) if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &ctl->termattr) < 0)
return -1; return -1;
#endif
return 0; return 0;
} }
#ifndef HAVE_CFMAKERAW #if !defined(WIN32) && !defined(HAVE_CFMAKERAW)
/* provide fallback in case cfmakeraw isn't available */ /* provide fallback in case cfmakeraw isn't available */
static void static void
cfmakeraw(struct termios *attr) cfmakeraw(struct termios *attr)
...@@ -2271,12 +2277,14 @@ cfmakeraw(struct termios *attr) ...@@ -2271,12 +2277,14 @@ cfmakeraw(struct termios *attr)
attr->c_cflag &= ~(CSIZE | PARENB); attr->c_cflag &= ~(CSIZE | PARENB);
attr->c_cflag |= CS8; attr->c_cflag |= CS8;
} }
#endif /* !HAVE_CFMAKERAW */ #endif /* !WIN32 && !HAVE_CFMAKERAW */
int int
vshTTYMakeRaw(vshControl *ctl, bool report_errors) vshTTYMakeRaw(vshControl *ctl ATTRIBUTE_UNUSED,
bool report_errors ATTRIBUTE_UNUSED)
{ {
#ifndef WIN32
struct termios rawattr = ctl->termattr; struct termios rawattr = ctl->termattr;
char ebuf[1024]; char ebuf[1024];
...@@ -2297,6 +2305,7 @@ vshTTYMakeRaw(vshControl *ctl, bool report_errors) ...@@ -2297,6 +2305,7 @@ vshTTYMakeRaw(vshControl *ctl, bool report_errors)
virStrerror(errno, ebuf, sizeof(ebuf))); virStrerror(errno, ebuf, sizeof(ebuf)));
return -1; return -1;
} }
#endif
return 0; return 0;
} }
...@@ -3249,8 +3258,10 @@ main(int argc, char **argv) ...@@ -3249,8 +3258,10 @@ main(int argc, char **argv)
if (isatty(STDIN_FILENO)) { if (isatty(STDIN_FILENO)) {
ctl->istty = true; ctl->istty = true;
#ifndef WIN32
if (tcgetattr(STDIN_FILENO, &ctl->termattr) < 0) if (tcgetattr(STDIN_FILENO, &ctl->termattr) < 0)
ctl->istty = false; ctl->istty = false;
#endif
} }
if (virMutexInit(&ctl->lock) < 0) { if (virMutexInit(&ctl->lock) < 0) {
......
...@@ -242,7 +242,9 @@ struct _vshControl { ...@@ -242,7 +242,9 @@ struct _vshControl {
const char *escapeChar; /* String representation of const char *escapeChar; /* String representation of
console escape character */ console escape character */
# ifndef WIN32
struct termios termattr; /* settings of the tty terminal */ struct termios termattr; /* settings of the tty terminal */
# endif
bool istty; /* is the terminal a tty */ bool istty; /* is the terminal a tty */
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册