Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Thomas Leitner
Tue, 09 Jan 1996 00:00
Bug in libc 5.0.9 !!
Author: Thomas Leitner
Date: Tue, 09 Jan 1996 00:00
Date: Tue, 09 Jan 1996 00:00
111 lines
4055 bytes
4055 bytes
[ Article reposted from comp.os.linux.development.apps ]
[ Author was Thomas Leitner ]
[ Posted on 9 Jan 1996 10:18:23 GMT ]
Hi,
We found the following bug in libc 5.0.9 when we ported our app. to Linux:
When a file is opened by two processes where one process repeatedly writes
a data block with fwrite and the other process reads it with fread, the
reader process does *not* get the actual data from the file. It gets the
old data from the stream buffer instead which is *wrong*. I tried this on
all sorts of Unixes I could get an account on at our campus (OSF/1 3.2,
Solaris 2.4, Ultrix 4.4, SunOS 4.1.3_U1) and it works as its supposed
to but on Linux (Slackware 3.0) with libc 5.0.9, the same data is
read all over again.
Note that the fix for this is to set the input stream to unbuffered
using "setbuf(fi, NULL);".
Comments anyone?
Tom
P.S: Here's my test program. Start writer process with "lbug" and
reader process with "lbug read".
/* lbug.c: demonstrates a bug in libc 5.0.9 under Linux */
#define _POSIX_SOURCE 1
#include <stdlib.h>
#include <stdio.h>
void main(int argc, char *argv[])
{
/* if more than one argument given -> READ the file */
if (argc > 1) {
int i;
char buffer[512];
FILE *fi = fopen("test.dat", "rb");
if (fi == (FILE*) NULL) {
perror("fopen(test.dat)");
exit(1);
}
/* THIS IS NEEDED UNDER LINUX W/ LIBC 5.0.9 TO GET IT GOING */
/*setbuf(fi, NULL);*/
while (1) {
if (fseek(fi, 0L, SEEK_SET) != 0) {
perror("fseek");
exit(1);
}
if (fread(buffer, 512, 1, fi) != 1) {
perror("fread");
exit(1);
}
for (i = 0; i < 512; i++) {
if (buffer[0] != buffer[i]) printf("BUFFER ERROR\n");
}
printf("read buffer %d\n", (int) buffer[0]);
sleep(1);
}
} else {
/* no argument given -> WRITE the file */
int i = 0;
char buffer[512];
FILE *fo = fopen("test.dat", "wb");
if (fo == (FILE*) NULL) {
perror("fopen(test.dat)");
exit(1);
}
while (1) {
i++;
i = i % 256;
memset(buffer, i, 512);
if (fseek(fo, 0L, SEEK_SET) != 0) {
perror("fseek");
exit(1);
}
if (fwrite(buffer, 512, 1, fo) != 1) {
perror("fwrite");
exit(1);
}
printf("wrote buffer %d\n", i);
sleep(1);
}
}
}
/* E O F */
--
Tom Leitner, tom@finwds01.tu-graz.ac.at |\ _,,,---,,_
Dept. of Communications zzz. /,`.-'`' -. ;-;;,_.
Graz University of Technology |,4- ) )-,_. ,\ ( `'-'
Inffeldgasse 12 '---''(_/--' `-'\_)
A-8010 Graz / Austria / Europe, Phone: +43-316-873-7455, Fax: +43-316-463-697
WWW home page: http://wiis.tu-graz.ac.at/people/tom.html
--
Tom Leitner, tom@finwds01.tu-graz.ac.at |\ _,,,---,,_
Dept. of Communications zzz. /,`.-'`' -. ;-;;,_.
Graz University of Technology |,4- ) )-,_. ,\ ( `'-'
Inffeldgasse 12 '---''(_/--' `-'\_)
A-8010 Graz / Austria / Europe, Phone: +43-316-873-7455, Fax: +43-316-463-697
WWW home page: http://wiis.tu-graz.ac.at/people/tom.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads