Subject: Re: syscalls return values
To: Allen Briggs <briggs@ninthwonder.com>
From: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
List: tech-kern
Date: 01/20/2001 00:16:01
> Is that what you're doing?=20

I think it's a problem in Linux's libc: if I print retval before
exitting linux_sys_lstat, I got zero, the ktrace shows a zero return
value, but the program gets an error.

If I revert to libc5, the problem disapear (the program works). I'm now
sure it's a libc problem. Now, how can I fix it? (ooops, sory, this is
not a tech-kern topic anymore...)

Here is the code:
#include <sys/stat.h>
#include <unistd.h>

int main (int argc, char** argv) {
        const char* file_name=3D"/etc";
        struct stat buf;
        int res;

        if (argc>=3D2)=20
                file_name=3Dargv[1];

        res=3Dlstat(file_name, &buf);
        if (res<0) {
                printf("res=3D%d  file_name=3D%s
&buf=3D0x%lx\n",res,file_name,&buf);
                perror("lstat() failed");
                exit(-1);
        }

        printf(" st_dev=3D%d \n   st_ino=3D%d \n st_mode=3D%oo \n
st_nlink=3D0x%x=20
            \n st_uid=3D%d \n st_gid=3D%d \n st_redv=3D%d \n st_size=3D0x%l=
x
            \n st_blksize=3D0x%lx \n st_blocks=3D0x%lx \n st_atime=3D0x%lx
            \n st_mtime=3D0x%lx \n st_ctime=3D0x%lx \n", buf.st_dev,=20
            buf.st_ino, buf.st_mode, buf.st_nlink, buf.st_uid,
            buf.st_gid, buf.st_rdev, buf.st_size, buf.st_blksize,
            buf.st_blocks, buf.st_atime, buf.st_mtime, buf.st_ctime);
       =20
        return 0;
}

Here is the output with libc6
res=3D-1  file_name=3D/etc  &buf=3D0x7fffe840
lstat() failed: Invalid argument

And here is the end of the ktrace:

   203 lstat    RET   close 0
   203 lstat    CALL  getpid
   203 lstat    RET   getpid 203/0xcb
   203 lstat    CALL  lstat(0x1802028,0x7fffe788)
   203 lstat    NAMI  "/emul/linux/etc"
   203 lstat    NAMI  "/emul/linux"
   203 lstat    NAMI  "/emul/linux/etc"
   203 lstat    RET   lstat 0
   203 lstat    CALL  fstat(0x1,0x7fffdf68)
   203 lstat    RET   fstat 0
   203 lstat    CALL  powerpc_mmap(0,0x10000,0x3,0x22,0xffffffff,0)
   203 lstat    RET   powerpc_mmap 1100406784/0x4196e000
   203 lstat    CALL  ioctl(0x1,TIOCGETA,0x7fffde78)
   203 lstat    RET   ioctl 0
   203 lstat    CALL  write(0x1,0x4196e000,0x28)
   203 lstat    GIO   fd 1 wrote 40 bytes
       "res=3D-1  file_name=3D/etc  &buf=3D0x7fffe840
       "
   203 lstat    RET   write 40/0x28
   203 lstat    CALL  write(0x2,0x7fffbc68,0x21)
   203 lstat    GIO   fd 2 wrote 33 bytes
       "lstat() failed: Invalid argument
       "
   203 lstat    RET   write 33/0x21
   203 lstat    CALL  munmap(0x4196e000,0x10000)
   203 lstat    RET   munmap 0
   203 lstat    CALL  exit(0xffffffff)

--=20
Emmanuel Dreyfus. =20
Vous avez deplac=E9 la souris.=20
Windows NT doit maintenant redemarrer pour valider les modifications.
p99dreyf@criens.u-psud.fr