fb633e
diff -Nrup a/sysdeps/unix/sysv/linux/tcsetattr.c b/sysdeps/unix/sysv/linux/tcsetattr.c
fb633e
--- a/sysdeps/unix/sysv/linux/tcsetattr.c	2012-06-05 07:42:49.000000000 -0600
fb633e
+++ b/sysdeps/unix/sysv/linux/tcsetattr.c	2012-06-07 12:15:21.831318623 -0600
fb633e
@@ -48,6 +48,7 @@ tcsetattr (fd, optional_actions, termios
fb633e
 {
fb633e
   struct __kernel_termios k_termios;
fb633e
   unsigned long int cmd;
fb633e
+  int retval;
fb633e
 
fb633e
   switch (optional_actions)
fb633e
     {
fb633e
@@ -79,6 +80,35 @@ tcsetattr (fd, optional_actions, termios
fb633e
   memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0],
fb633e
 	  __KERNEL_NCCS * sizeof (cc_t));
fb633e
 
fb633e
-  return INLINE_SYSCALL (ioctl, 3, fd, cmd, &k_termios);
fb633e
+  retval = INLINE_SYSCALL (ioctl, 3, fd, cmd, &k_termios);
fb633e
+
fb633e
+  if (retval == 0 && cmd == TCSETS)
fb633e
+    {
fb633e
+      /* The Linux kernel has a bug which silently ignore the invalid
fb633e
+        c_cflag on pty. We have to check it here. */
fb633e
+      int save = errno;
fb633e
+      retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios);
fb633e
+      if (retval)
fb633e
+       {
fb633e
+         /* We cannot verify if the setting is ok. We don't return
fb633e
+            an error (?). */
fb633e
+         __set_errno (save);
fb633e
+         retval = 0;
fb633e
+       }
fb633e
+      else if ((termios_p->c_cflag & (PARENB | CREAD))
fb633e
+              != (k_termios.c_cflag & (PARENB | CREAD))
fb633e
+              || ((termios_p->c_cflag & CSIZE)
fb633e
+                  && ((termios_p->c_cflag & CSIZE)
fb633e
+                      != (k_termios.c_cflag & CSIZE))))
fb633e
+       {
fb633e
+         /* It looks like the Linux kernel silently changed the
fb633e
+            PARENB/CREAD/CSIZE bits in c_cflag. Report it as an
fb633e
+            error. */
fb633e
+         __set_errno (EINVAL);
fb633e
+         retval = -1;
fb633e
+       }
fb633e
+    }
fb633e
+
fb633e
+  return retval;
fb633e
 }
fb633e
 libc_hidden_def (tcsetattr)