public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Pty is losing bytes
@ 2005-02-15  2:00 Alex Davis
  2005-02-15 10:48 ` Andreas Schwab
  0 siblings, 1 reply; 23+ messages in thread
From: Alex Davis @ 2005-02-15  2:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: schwab

Problem does not exist on 2.6.8.1. Compiling your program and running

./a.out < README | diff README -

produces no output.

I tested various files ranging in size from 10 to 60k.

-Alex


=====
I code, therefore I am


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Pty is losing bytes
@ 2005-02-15  0:54 Andreas Schwab
  2005-02-15 19:08 ` Linus Torvalds
  0 siblings, 1 reply; 23+ messages in thread
From: Andreas Schwab @ 2005-02-15  0:54 UTC (permalink / raw)
  To: linux-kernel

Recent kernel are losing bytes on a pty.  Try running this program (needs
to be linked against -lutil) with a moderately large input (10K - 20K).
The output should match its input, but instead there is always one byte
missing at the end of the first 4K chunk read by the child.

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pty.h>
#include <sys/wait.h>

char buf[4096];

int main (void)
{
    int master;
    int stdout = dup (1);
    int pid = forkpty (&master, 0, 0, 0);
    int bytes_read;
    int bytes_written;

    if (pid < 0) exit (1);
    if (pid > 0) {
        while ((bytes_read = read (0, buf, sizeof (buf))) > 0) {
            char *p = buf;
            while (bytes_read > 0 &&
                   (bytes_written = write (master, p, bytes_read)) > 0)
              bytes_read -= bytes_written, p += bytes_written;
        }
        write (master, "EOF\n", 4);
        waitpid (pid, 0, 0);
        exit (0);
    }

    while ((bytes_read = read (0, buf, sizeof (buf))) > 0) {
        char *p = buf;
        if (strncmp (buf, "EOF\n", 4) == 0) break;
        while (bytes_read > 0 &&
               (bytes_written = write (stdout, p, bytes_read)) > 0)
          bytes_read -= bytes_written, p += bytes_written;
    }
    exit (0);
}

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2005-02-18 16:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-15  2:00 Pty is losing bytes Alex Davis
2005-02-15 10:48 ` Andreas Schwab
2005-02-15 11:01   ` Jan De Luyck
  -- strict thread matches above, loose matches on Subject: below --
2005-02-15  0:54 Andreas Schwab
2005-02-15 19:08 ` Linus Torvalds
2005-02-15 19:44   ` Linus Torvalds
2005-02-15 22:13     ` Alan Cox
2005-02-15 19:58   ` Sergey Vlasov
2005-02-15 20:13     ` Sergey Vlasov
2005-02-15 20:06   ` Alan Curry
2005-02-15 20:30   ` Andreas Schwab
2005-02-15 20:56     ` Linus Torvalds
2005-02-15 21:54       ` Andreas Schwab
2005-02-16  3:12       ` Roman Zippel
2005-02-16  4:05         ` Linus Torvalds
2005-02-16 14:42           ` Theodore Ts'o
2005-02-16 16:06             ` Linus Torvalds
2005-02-17  4:44               ` Theodore Ts'o
2005-02-17 15:45                 ` Linus Torvalds
2005-02-18 16:32                   ` Theodore Ts'o
2005-02-16 19:49           ` Roman Zippel
2005-02-16 19:58             ` Linus Torvalds
2005-02-16 22:46               ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox