This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Bug#81059: fstat misbehaviour: errno set inappropriately
- To: GNU C Library <libc-alpha at sourceware dot cygnus dot com>
- Subject: Re: Bug#81059: fstat misbehaviour: errno set inappropriately
- From: Ben Collins <bcollins at debian dot org>
- Date: Tue, 2 Jan 2001 10:57:22 -0500
Seems errno wasn't getting reset if a program called fxstat which tried to
call fstat64 and got ENOSYS. I'm not sure if this is the proper fix, but
I have provided a testcase which shows the problem. Note, the testcase
only works when you compile glibc against LFS capable kernel headers,
and then try to run it on a non-LFS capable kernel. I don't know any
other way around this.
2001-01-01 Ben Collins <bcollins@debian.org>
* sysdeps/unix/sysv/linux/i386/fxstat.c: Reset the old errno if
the syscall for fstat64 fails with ENOSYS.
--
-----------=======-=-======-=========-----------=====------------=-=------
/ Ben Collins -- ...on that fantastic voyage... -- Debian GNU/Linux \
` bcollins@debian.org -- bcollins@openldap.org -- bcollins@linux.com '
`---=========------=======-------------=-=-----=-===-======-------=--=---'
Index: sysdeps/unix/sysv/linux/i386/fxstat.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/i386/fxstat.c,v
retrieving revision 1.7
diff -u -u -r1.7 fxstat.c
--- fxstat.c 2000/08/12 05:02:43 1.7
+++ fxstat.c 2001/01/02 15:56:18
@@ -73,6 +73,7 @@
if (! __have_no_stat64)
{
struct stat64 buf64;
+ int olderror = errno;
result = INLINE_SYSCALL (fstat64, 2, fd, __ptrvalue (&buf64));
@@ -81,6 +82,8 @@
if (result != -1 || errno != ENOSYS)
return result;
+
+ __set_errno(olderror);
__have_no_stat64 = 1;
}
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#define TESTFILE "testfile"
int main(int argc, char *argv[])
{
struct stat S;
int fd;
system("touch " TESTFILE);
fd = open(TESTFILE, O_RDONLY);
/* This shouldn't happen, and isn't what we are testing. */
if (fstat(fd, &S)) {
perror(TESTFILE);
exit(1);
}
/* This should also succeed. */
errno = 0;
if (fstat(fd, &S)) {
perror(TESTFILE);
exit(1);
}
/* Now, here's the real test. This should be 0. */
if (errno) {
perror("Failed");
exit(1);
}
exit(0);
}