Skip to contentSkip to conversation

terminal attributes is not restored when using /dev/tty monitor

PATCH In review Shahar Havivi 3 participants 8 messages Feb 20, 2010 – Feb 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 terminal attributes is not restored when using /dev/tty monitor

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +14 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
            speed, parity, data_bits, stop_bits);
 #endif
     tcgetattr (fd, &tty);
+    oldtty = tty;
 
 #define check_speed(val) if (speed <= val) { spd = B##val; break; }
     speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
     return 0;
 }
 
+static void tty_exit(void)
+{
+    tcsetattr(0, TCSANOW, &oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}
+
 static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 {
     const char *filename = qemu_opt_get(opts, "path");
@@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
         return NULL;
     }
     chr->chr_ioctl = tty_serial_ioctl;
+    chr->chr_close = qemu_chr_close_tty;
+    atexit(tty_exit);
     return chr;
 }
 #else  /* ! __linux__ && ! __sun__ */
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 27 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +1 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
            speed, parity, data_bits, stop_bits);
 #endif
     tcgetattr (fd, &tty);
+    oldtty = tty;
 
 #define check_speed(val) if (speed <= val) { spd = B##val; break; }
     speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
     return 0;
 }
 

qemu-char.c static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) · line 1186

Quoted 10 lines
qemu-char.c +10 -0
+static void tty_exit(void)
+{
+    tcsetattr(0, TCSANOW, &oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

David

Quoted 13 lines
qemu-char.c +3 -0
+
 static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 {
     const char *filename = qemu_opt_get(opts, "path");
@@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
         return NULL;
     }
     chr->chr_ioctl = tty_serial_ioctl;
+    chr->chr_close = qemu_chr_close_tty;
+    atexit(tty_exit);
     return chr;
 }
 #else  /* ! __linux__ && ! __sun__ */
#2 lore raw
Quoted 51 lines · David S. Ahern

Date: Sat, 20 Feb 2010 08:18:54 -0700
From: "David S. Ahern" <[email protected]>
To: Shahar Havivi <[email protected]>
CC: [email protected], Dor Laor <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
using /dev/tty monitor

Quoted 27 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +1 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
            speed, parity, data_bits, stop_bits);
 #endif
     tcgetattr (fd, &tty);
+    oldtty = tty;
 
 #define check_speed(val) if (speed <= val) { spd = B##val; break; }
     speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
     return 0;
 }
 

qemu-char.c static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) · line 1186

Quoted 10 lines
qemu-char.c +10 -0
+static void tty_exit(void)
+{
+    tcsetattr(0, TCSANOW, &oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

Quoted 3 lines

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

David

Sure you right about the fd but the chr->chr_close not called all the time that is why I added the atexit() call, and the restore tty flags. Shaahr.

Quoted 15 lines
Quoted 15 lines
qemu-char.c +3 -0
+
 static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 {
     const char *filename = qemu_opt_get(opts, "path");
@@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
         return NULL;
     }
     chr->chr_ioctl = tty_serial_ioctl;
+    chr->chr_close = qemu_chr_close_tty;
+    atexit(tty_exit);
     return chr;
 }
 #else  /* ! __linux__ && ! __sun__ */
#3 lore raw
In reply to David S. Ahern
Quoted 44 lines · David S. Ahern
Quoted 28 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
  qemu-char.c |   14 ++++++++++++++
  1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +2 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
             speed, parity, data_bits, stop_bits);
  #endif
      tcgetattr (fd,&tty);
+    oldtty = tty;
 
  #define check_speed(val) if (speed<= val) { spd = B##val; break; }
      speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
      return 0;
  }
 
+static void tty_exit(void)

qemu-char.c static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) · line 1187

Quoted 10 lines
qemu-char.c +9 -0
+{
+    tcsetattr(0, TCSANOW,&oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}
 

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

Quoted 2 lines

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

It didn't apply with git-am. I'm not sure why, am investigating now.

Regards,

Anthony Liguori

Quoted 21 lines

David

Quoted 14 lines
qemu-char.c +1 -0
+
  static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
  {
      const char *filename = qemu_opt_get(opts, "path");
qemu-char.c +2 -0
@@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
          return NULL;
      }
      chr->chr_ioctl = tty_serial_ioctl;
+    chr->chr_close = qemu_chr_close_tty;
+    atexit(tty_exit);
      return chr;
  }
  #else  /* ! __linux__&&  ! __sun__ */
#4 lore raw
Quoted 51 lines · Anthony Liguori

Date: Sat, 20 Feb 2010 11:03:41 -0600
From: Anthony Liguori <[email protected]>
To: "David S. Ahern" <[email protected]>
Cc: Dor Laor <[email protected]>, Shahar Havivi <[email protected]>,
[email protected]
Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
using /dev/tty monitor

Quoted 42 lines · David S. Ahern
Quoted 27 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +1 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
            speed, parity, data_bits, stop_bits);
 #endif
     tcgetattr (fd,&tty);
+    oldtty = tty;
 
 #define check_speed(val) if (speed<= val) { spd = B##val; break; }
     speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
     return 0;
 }
 

qemu-char.c static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) · line 1186

Quoted 10 lines
qemu-char.c +10 -0
+static void tty_exit(void)
+{
+    tcsetattr(0, TCSANOW,&oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

Quoted 8 lines
Quoted 1 line

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

It didn't apply with git-am. I'm not sure why, am investigating now.

Regards,

Anthony Liguori

Note that the method fd_chr_close() is closing the fd_in, no need to the close logic again, and when opening a monitor with /dev/tty the chr->chr_close not called that is why you need to register with atexit(). (same as stdio monitor does).
Shahar.

Quoted 21 lines
Quoted 18 lines

David

Quoted 13 lines
qemu-char.c +3 -0
+
 static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
 {
     const char *filename = qemu_opt_get(opts, "path");
@@ -1190,6 +1202,8 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
         return NULL;
     }
     chr->chr_ioctl = tty_serial_ioctl;
+    chr->chr_close = qemu_chr_close_tty;
+    atexit(tty_exit);
     return chr;
 }
 #else  /* ! __linux__&&  ! __sun__ */
#7 lore raw
In reply to Anthony Liguori
Quoted 46 lines · Anthony Liguori
Quoted 45 lines · David S. Ahern
Quoted 29 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
  qemu-char.c |   14 ++++++++++++++
  1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +2 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
             speed, parity, data_bits, stop_bits);
  #endif
      tcgetattr (fd,&tty);
+    oldtty = tty;
 
  #define check_speed(val) if (speed<= val) { spd = B##val; break; }
      speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState
 *chr, int cmd, void *arg)
      return 0;
  }
 
+static void tty_exit(void)

qemu-char.c static int tty_serial_ioctl(CharDriverState · line 1188

Quoted 10 lines
qemu-char.c +9 -0
+{
+    tcsetattr(0, TCSANOW,&oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}
 

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

Quoted 9 lines
Quoted 2 lines

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

It didn't apply with git-am. I'm not sure why, am investigating now.

Regards,

Anthony Liguori

Are you referring to my patch? I'm still learning the git commands, so maybe I messed something up. I used git format-patch followed git send-mail.

If I save the email (Thunderbird client, saving the copy I received of what I sent using git send-mail), strip out the mail headers and use patch it applies fine - but with the warning "(Stripping trailing CRs from patch.)"

David

#5 lore raw
In reply to Shahar Havivi
Quoted 58 lines · Shahar Havivi
Quoted 57 lines · Anthony Liguori

Date: Sat, 20 Feb 2010 11:03:41 -0600
From: Anthony Liguori <[email protected]>
To: "David S. Ahern" <[email protected]>
Cc: Dor Laor <[email protected]>, Shahar Havivi <[email protected]>,
[email protected]
Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
using /dev/tty monitor

Quoted 42 lines · David S. Ahern
Quoted 27 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +1 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
            speed, parity, data_bits, stop_bits);
 #endif
     tcgetattr (fd,&tty);
+    oldtty = tty;
 
 #define check_speed(val) if (speed<= val) { spd = B##val; break; }
     speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
     return 0;
 }
 

qemu-char.c static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) · line 1186

Quoted 10 lines
qemu-char.c +10 -0
+static void tty_exit(void)
+{
+    tcsetattr(0, TCSANOW,&oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

Quoted 1 line

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

It didn't apply with git-am. I'm not sure why, am investigating now.

Regards,

Quoted 7 lines
Quoted 2 lines

Anthony Liguori

Note that the method fd_chr_close() is closing the fd_in, no need to the close logic again, and when opening a monitor with /dev/tty the chr->chr_close not called that is why you need to register with atexit(). (same as stdio monitor does).
Shahar.

I don't see that fd_chr_close() closes the fd; it only unregisters the handler.

David

#6 lore raw
Quoted 77 lines · David S. Ahern

Date: Sun, 21 Feb 2010 07:32:41 -0700
From: "David S. Ahern" <[email protected]>
To: Shahar Havivi <[email protected]>
CC: Anthony Liguori <[email protected]>, Dor Laor <[email protected]>,
[email protected]
Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
using /dev/tty monitor

Quoted 58 lines · Shahar Havivi
Quoted 57 lines · Anthony Liguori

Date: Sat, 20 Feb 2010 11:03:41 -0600
From: Anthony Liguori <[email protected]>
To: "David S. Ahern" <[email protected]>
Cc: Dor Laor <[email protected]>, Shahar Havivi <[email protected]>,
[email protected]
Subject: Re: [Qemu-devel] [PATCH] terminal attributes is not restored when
using /dev/tty monitor

Quoted 42 lines · David S. Ahern
Quoted 27 lines · Shahar Havivi

when exiting qemu that run with "-monitor /dev/tty", the launching terminal get weird behaviour because no restore terminals action has taken.
added chr_close and register atexit() code for tty devices (like stdio does)

---
 qemu-char.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
qemu-char.c +1 -0
index 75dbf66..de16883 100644
@@ -1002,6 +1002,7 @@ static void tty_serial_init(int fd, int speed,
            speed, parity, data_bits, stop_bits);
 #endif
     tcgetattr (fd,&tty);
+    oldtty = tty;
 
 #define check_speed(val) if (speed<= val) { spd = B##val; break; }
     speed = speed * 10 / 11;
@@ -1173,6 +1174,17 @@ static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg)
     return 0;
 }
 

qemu-char.c static int tty_serial_ioctl(CharDriverState *chr, int cmd, void *arg) · line 1186

Quoted 10 lines
qemu-char.c +10 -0
+static void tty_exit(void)
+{
+    tcsetattr(0, TCSANOW,&oldtty);
+}
+
+static void qemu_chr_close_tty(struct CharDriverState *chr)
+{
+    tty_exit();
+    fd_chr_close(chr);
+}

The close callback needs to close the fd for the device as well. I have sent a patch to handle this; waiting for it to be included:

Quoted 1 line

http://permalink.gmane.org/gmane.comp.emulators.qemu/63472

It didn't apply with git-am. I'm not sure why, am investigating now.

Regards,

Quoted 7 lines
Quoted 2 lines

Anthony Liguori

Note that the method fd_chr_close() is closing the fd_in, no need to the close logic again, and when opening a monitor with /dev/tty the chr->chr_close not called that is why you need to register with atexit(). (same as stdio monitor does).
Shahar.

Quoted 4 lines

I don't see that fd_chr_close() closes the fd; it only unregisters the handler.

David

you right, my bad.