lkml.org 
[lkml]   [2005]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectPty is losing bytes
From
Date
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."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:10    [W:0.059 / U:0.772 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site