Re: [libvirt] [PATCH 2/3] virsh: Rename vshMakeStdinRaw to vshTTYMakeRaw and move it to virsh.c

2013-09-04 Thread Eric Blake
On 08/29/2013 10:36 AM, Peter Krempa wrote:
 Move the function to virsh.c to the rest of the TTY managing functions
 and change the code so that it mirrors the rest.
 ---
  tools/virsh-console.c | 50 +-
  tools/virsh-console.h |  7 +++
  tools/virsh-domain.c  |  2 +-
  tools/virsh.c | 48 +---
  tools/virsh.h |  1 +
  5 files changed, 55 insertions(+), 53 deletions(-)

As we guessed on IRC, this and similar patches have broken the build for
mingw, which lacks most terminal control functions.  I'm working on a
patch that uses #ifndef WIN32 to skip the code that doesn't work on
mingw (I don't know if mingw can ever reliably use ssh connections, or
if it is better off relying on tls certificates for authentication instead).

In file included from ../../tools/virsh-domain-monitor.h:29:0,
 from ../../tools/virsh-domain-monitor.c:27:
../../tools/virsh.h:245:20: error: field 'termattr' has incomplete type
 struct termios termattr;/* settings of the tty terminal */
^
In file included from ../../tools/virsh-host.h:29:0,
 from ../../tools/virsh-host.c:27:
...

-- 
Eric Blake   eblake 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

Re: [libvirt] [PATCH 2/3] virsh: Rename vshMakeStdinRaw to vshTTYMakeRaw and move it to virsh.c

2013-09-03 Thread Martin Kletzander
On 08/29/2013 06:36 PM, Peter Krempa wrote:
 Move the function to virsh.c to the rest of the TTY managing functions
 and change the code so that it mirrors the rest.
 ---
  tools/virsh-console.c | 50 +-
  tools/virsh-console.h |  7 +++
  tools/virsh-domain.c  |  2 +-
  tools/virsh.c | 48 +---
  tools/virsh.h |  1 +
  5 files changed, 55 insertions(+), 53 deletions(-)
 
 diff --git a/tools/virsh-console.c b/tools/virsh-console.c
 index debf12c..cc9cc6a 100644
 --- a/tools/virsh-console.c
 +++ b/tools/virsh-console.c
[...]
 @@ -319,40 +306,13 @@ vshGetEscapeChar(const char *s)
 
 
  int
 -vshMakeStdinRaw(struct termios *ttyattr, bool report_errors)
 -{
 -struct termios rawattr;
 -char ebuf[1024];
 -
 -if (tcgetattr(STDIN_FILENO, ttyattr)  0) {
 -if (report_errors)
 -VIR_ERROR(_(unable to get tty attributes: %s),
 -  virStrerror(errno, ebuf, sizeof(ebuf)));
 -return -1;
 -}
 -
 -rawattr = *ttyattr;
 -cfmakeraw(rawattr);
 -
 -if (tcsetattr(STDIN_FILENO, TCSAFLUSH, rawattr)  0) {
 -if (report_errors)
 -VIR_ERROR(_(unable to set tty attributes: %s),
 -  virStrerror(errno, ebuf, sizeof(ebuf)));
 -return -1;
 -}
 -
 -return 0;
 -}
 -
 -
 -int
 -vshRunConsole(virDomainPtr dom,
 +vshRunConsole(vshControl *ctl,
 +  virDomainPtr dom,
const char *dev_name,
const char *escape_seq,

You can get rid of this one since we call it with ctl-excapeChar only.

The rest looks ok, but Michal already ACK'd it, so...

Martin

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/3] virsh: Rename vshMakeStdinRaw to vshTTYMakeRaw and move it to virsh.c

2013-09-03 Thread Peter Krempa
On 09/03/13 12:02, Martin Kletzander wrote:
 On 08/29/2013 06:36 PM, Peter Krempa wrote:
 Move the function to virsh.c to the rest of the TTY managing functions
 and change the code so that it mirrors the rest.
 ---
  tools/virsh-console.c | 50 
 +-
  tools/virsh-console.h |  7 +++
  tools/virsh-domain.c  |  2 +-
  tools/virsh.c | 48 +---
  tools/virsh.h |  1 +
  5 files changed, 55 insertions(+), 53 deletions(-)

 diff --git a/tools/virsh-console.c b/tools/virsh-console.c
 index debf12c..cc9cc6a 100644
 --- a/tools/virsh-console.c
 +++ b/tools/virsh-console.c
 [...]
 @@ -319,40 +306,13 @@ vshGetEscapeChar(const char *s)


  int
 -vshMakeStdinRaw(struct termios *ttyattr, bool report_errors)
 -{
 -struct termios rawattr;
 -char ebuf[1024];
 -
 -if (tcgetattr(STDIN_FILENO, ttyattr)  0) {
 -if (report_errors)
 -VIR_ERROR(_(unable to get tty attributes: %s),
 -  virStrerror(errno, ebuf, sizeof(ebuf)));
 -return -1;
 -}
 -
 -rawattr = *ttyattr;
 -cfmakeraw(rawattr);
 -
 -if (tcsetattr(STDIN_FILENO, TCSAFLUSH, rawattr)  0) {
 -if (report_errors)
 -VIR_ERROR(_(unable to set tty attributes: %s),
 -  virStrerror(errno, ebuf, sizeof(ebuf)));
 -return -1;
 -}
 -
 -return 0;
 -}
 -
 -
 -int
 -vshRunConsole(virDomainPtr dom,
 +vshRunConsole(vshControl *ctl,
 +  virDomainPtr dom,
const char *dev_name,
const char *escape_seq,
 
 You can get rid of this one since we call it with ctl-excapeChar only.
 
 The rest looks ok, but Michal already ACK'd it, so...

Right, I removed the parameter and pushed the rest of the series. Thanks.

Peter




signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 2/3] virsh: Rename vshMakeStdinRaw to vshTTYMakeRaw and move it to virsh.c

2013-08-29 Thread Peter Krempa
Move the function to virsh.c to the rest of the TTY managing functions
and change the code so that it mirrors the rest.
---
 tools/virsh-console.c | 50 +-
 tools/virsh-console.h |  7 +++
 tools/virsh-domain.c  |  2 +-
 tools/virsh.c | 48 +---
 tools/virsh.h |  1 +
 5 files changed, 55 insertions(+), 53 deletions(-)

diff --git a/tools/virsh-console.c b/tools/virsh-console.c
index debf12c..cc9cc6a 100644
--- a/tools/virsh-console.c
+++ b/tools/virsh-console.c
@@ -37,6 +37,7 @@
 # include c-ctype.h

 # include internal.h
+# include virsh.h
 # include virsh-console.h
 # include virlog.h
 # include virfile.h
@@ -85,20 +86,6 @@ virConsoleHandleSignal(int sig ATTRIBUTE_UNUSED)
 }


-# ifndef HAVE_CFMAKERAW
-static void
-cfmakeraw(struct termios *attr)
-{
-attr-c_iflag = ~(IGNBRK | BRKINT | PARMRK | ISTRIP
- | INLCR | IGNCR | ICRNL | IXON);
-attr-c_oflag = ~OPOST;
-attr-c_lflag = ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
-attr-c_cflag = ~(CSIZE | PARENB);
-attr-c_cflag |= CS8;
-}
-# endif /* !HAVE_CFMAKERAW */
-
-
 static void
 virConsoleShutdown(virConsolePtr con)
 {
@@ -319,40 +306,13 @@ vshGetEscapeChar(const char *s)


 int
-vshMakeStdinRaw(struct termios *ttyattr, bool report_errors)
-{
-struct termios rawattr;
-char ebuf[1024];
-
-if (tcgetattr(STDIN_FILENO, ttyattr)  0) {
-if (report_errors)
-VIR_ERROR(_(unable to get tty attributes: %s),
-  virStrerror(errno, ebuf, sizeof(ebuf)));
-return -1;
-}
-
-rawattr = *ttyattr;
-cfmakeraw(rawattr);
-
-if (tcsetattr(STDIN_FILENO, TCSAFLUSH, rawattr)  0) {
-if (report_errors)
-VIR_ERROR(_(unable to set tty attributes: %s),
-  virStrerror(errno, ebuf, sizeof(ebuf)));
-return -1;
-}
-
-return 0;
-}
-
-
-int
-vshRunConsole(virDomainPtr dom,
+vshRunConsole(vshControl *ctl,
+  virDomainPtr dom,
   const char *dev_name,
   const char *escape_seq,
   unsigned int flags)
 {
 int ret = -1;
-struct termios ttyattr;
 void (*old_sigquit)(int);
 void (*old_sigterm)(int);
 void (*old_sigint)(int);
@@ -365,7 +325,7 @@ vshRunConsole(virDomainPtr dom,
result in it being echoed back already), and
also ensure Ctrl-C, etc is blocked, and misc
other bits */
-if (vshMakeStdinRaw(ttyattr, true)  0)
+if (vshTTYMakeRaw(ctl, true)  0)
 goto resettty;

 /* Trap all common signals so that we can safely restore
@@ -433,7 +393,7 @@ cleanup:
 resettty:
 /* Put STDIN back into the (sane?) state we found
it in before starting */
-tcsetattr(STDIN_FILENO, TCSAFLUSH, ttyattr);
+vshTTYRestore(ctl);

 return ret;
 }
diff --git a/tools/virsh-console.h b/tools/virsh-console.h
index 96ef235..d6dbedd 100644
--- a/tools/virsh-console.h
+++ b/tools/virsh-console.h
@@ -25,15 +25,14 @@

 # ifndef WIN32

-#  include termios.h
+#  include virsh.h

-int vshRunConsole(virDomainPtr dom,
+int vshRunConsole(vshControl *ctl,
+  virDomainPtr dom,
   const char *dev_name,
   const char *escape_seq,
   unsigned int flags);

-int vshMakeStdinRaw(struct termios *ttyattr, bool report_errors);
-
 # endif /* !WIN32 */

 #endif /* __VIR_CONSOLE_H__ */
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 60eed51..7a60e48 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2263,7 +2263,7 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom,
 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, flags) == 0)
+if (vshRunConsole(ctl, dom, name, ctl-escapeChar, flags) == 0)
 ret = true;

  cleanup:
diff --git a/tools/virsh.c b/tools/virsh.c
index 0cc9bdd..37e9716 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -458,14 +458,13 @@ int
 vshAskReedit(vshControl *ctl, const char *msg)
 {
 int c = -1;
-struct termios ttyattr;

 if (!isatty(STDIN_FILENO))
 return -1;

 vshReportError(ctl);

-if (vshMakeStdinRaw(ttyattr, false)  0)
+if (vshTTYMakeRaw(ctl, false)  0)
 return -1;

 while (true) {
@@ -488,7 +487,7 @@ vshAskReedit(vshControl *ctl, const char *msg)
 }
 }

-tcsetattr(STDIN_FILENO, TCSAFLUSH, ttyattr);
+vshTTYRestore(ctl);

 vshPrint(ctl, \r\n);
 return c;
@@ -2260,6 +2259,49 @@ vshTTYRestore(vshControl *ctl)
 }


+#ifndef HAVE_CFMAKERAW
+/* provide fallback in case cfmakeraw isn't available */
+static void
+cfmakeraw(struct termios *attr)
+{
+attr-c_iflag = ~(IGNBRK | BRKINT | PARMRK | ISTRIP
+ | INLCR | IGNCR | ICRNL | IXON);
+attr-c_oflag = ~OPOST;
+