Problems with read() on /proc/devices with x86_64 system
From: Martin Schlemmer
Date: Wed Feb 22 2006 - 14:02:46 EST
Hi,
Not sure when it started, but 2.6.16-rc[1234] at least have problems
with unbuffered read() and /proc/devices on my x86_64 box. I first
picked it up with dmsetup that did not want to work properly built
against klibc (glibc with fread() worked fine though, as it mmap()'d the
file).
Following code (from HPA and klibc mailing lists), when compiled and run
with /proc/devices only reads the first two lines and then exits
normally, where with any other file works as expected.
-----
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
char c;
int i, fd, rv;
for ( i = 1 ; i < argc ; i++ ) {
fd = open(argv[i], O_RDONLY);
if ( fd < 0 ) {
perror(argv[i]);
exit(1);
}
while ( (rv = read(fd, &c, 1)) ) {
if ( rv == -1 ) {
if ( errno == EINTR || errno == EAGAIN )
continue;
perror(argv[i]);
exit(1);
}
putchar(c);
}
close(fd);
}
return 0;
}
-----
Output over here:
-----
# ./readbychar.klibc /proc/devices
Character devices:
1 mem
#
-----
Thanks,
--
Martin Schlemmer
Attachment:
signature.asc
Description: This is a digitally signed message part