NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: procfs difference between NetBSD and Linux



    Date:        Sat, 05 Jun 2021 23:03:05 +0700
    From:        Robert Elz <kre%munnari.OZ.AU@localhost>
    Message-ID:  <2011.1622908985%jinx.noi.kre.to@localhost>

  | Replying to my own message again (draw your own conclusions)...

And now I am replying to my reply to my message.   All remaining hope is lost!

  | Building now and then will test this version soon (I had already run
  | the AFS tests, which don't test this particular scenario, apparently,

And of course I meant ATF tests.... Did you need any more proof?

  | as they all worked about as well as they typically do for me, certainly
  | no kernel crash from them).

I will run them again on this version, and won't reply again unless there
is something worth saying ("they worked, as well as usual" isn't it).

But for now, my modified version of dholland@'s patch is looking good:

netbsd# >/
-sh: cannot create /: is a directory
netbsd# >/bin
-sh: cannot create /bin: is a directory

No more panic, and the results that we want.   Further, with /proc
mounted, and this (modified from the original in this thread to
supply a little more info) test program:

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>

int main ()
{
   int fd, new_fd, err;
   char buf[PATH_MAX];

   fd = openat (AT_FDCWD, "foo.txt",  O_RDONLY|O_NOFOLLOW|O_DIRECT);
   err = errno;
   printf ("fd = %d (flags %#x) err=%d\n", fd, fcntl(fd, F_GETFL, 0),
        (fd == -1 ? err : 0));
   sprintf(buf, "/proc/self/fd/%d", fd);
   sleep(2);
   new_fd = openat(AT_FDCWD, buf, O_RDWR|O_CREAT|O_NONBLOCK, 0744);
   err = errno;
   printf ("new_fd = %d (flags %#x) err=%d\n", new_fd,
        fcntl(new_fd, F_GETFL, 0), (new_fd == -1 ? err : 0));
}

(and after creating "foo.txt" of course), the results are...

fd = 3 (flags 0x80000) err=0
new_fd = 4 (flags 0x6) err=0

The "O_DIRECT" in the first open I added just so the result from
F_GETFL wouldn't be 0, it is otherwise meaningless (that is the 0x80000)
The flags value is O_DIRECT|O_RDONLY, as expected, O_NOFOLLOW is an operation,
not a mode, and isn't saved.

For new_fd, flags 6 is O_RDWR|O_NONBLOCK (O_CREAT isn't saved, naturally,
that's also an operation, not a mode).

I suspect this is what we want.

Without /proc mounted ... and yes, initially I forgot it was needed,
we get:

fd = 3 (flags 0x80000) err=0
new_fd = -1 (flags 0xffffffff) err=2

which also looks correct, not that anything there is in any way related
to these changes in that case.

Now I'll leave it for David to turn my mangling into something sane,
but I think we probably have (in perhaps a messy way) this one solved.

kre

ps: David, I'll send the vfs_lookup.c I used in an off-list message, to
save you recreating it out of the e-mail...



Home | Main Index | Thread Index | Old Index