Index | Thread | Search

From:
Steffen Nurpmeso <steffen@sdaoden.eu>
Subject:
Re: openat(2) is mostly useless, sadly
To:
Mark Kettenis <mark.kettenis@xs4all.nl>
Cc:
"Theo de Raadt" <deraadt@openbsd.org>, h@hartzer.sh, tech@openbsd.org
Date:
Sat, 31 May 2025 22:00:58 +0200

Download raw body.

Thread
  • H. Hartzer:

    openat(2) is mostly useless, sadly

  • H. Hartzer:

    openat(2) is mostly useless, sadly

  • Mark Kettenis wrote in
     <871ps43k34.fsf@bloch.sibelius.xs4all.nl>:
     |> From: "Theo de Raadt" <deraadt@openbsd.org>
     |> Date: Fri, 30 May 2025 19:17:46 -0600
     |> 
     |> Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
     |> 
     |>> I would not use ENOTTY for F_BELOW on !DIR, maybe ENOTDIR is
     |>> better.
     |> 
     |>>From errno(2) manpage:
     |> 
     |>      20 ENOTDIR Not a directory. A component of the specified pathname
     |>              existed, but it was not a directory, when a directory was
     |>              expected.
     |> 
     |> F_BELOW is fcntl(2).
     |> 
     |>      int
     |>      fcntl(int fd, int cmd, ...);
     |> 
     |> But there is no pathname.  Yes it is partly vague, but then grep \
     |> the whole
     |> tree for ENOTDIR and always anticipates a pathname at a higher level.
     |
     |Note that openat(2) says:
     |
     |[ENOTDIR]          The path argument specifies a relative path and the fd
     |                   argument is a valid file descriptor but it does not
     |     reference a directory.
     |
     |So here ENOTDIR does apply to a file descriptor.
    
    The POSIX standard says
    
      8542           [ENOTDIR]            Not a directory or a symbolic link to a directory.
    
    Linux says
    
           ENOTDIR         Not a directory (POSIX.1‐2001).
    
    
    The wording of "path" is BSD specific.
    It in Research UNIX V7 we read
    
      .en 20 ENOTDIR "Not a directory
      A non-directory was specified where a directory
      is required,
      for example in a path name or
      as an argument to
      .IR chdir .
    
    That comes from Research V4
    
      .en 20 ENOTDIR "Not a directory"
      A non-directory was specified where a directory
      is required,
      for example in a path name or
      as an argument to
      .it chdir.
    
    Since BSD 4.2 has the same words, the intent must have been
    detoriated somewhere in the meantime.
    
    This is the problem with a one dimensional errno.  FreeBSD just
    had those more descriptive string additions a la Plan9.
    I for myself simply overlay.  For example i use ENOMSG (No message
    of the desired type).  Even though OpenBSD turned this into
    
      .It Er 90 ENOMSG Em "\&No message of desired type".
      An IPC message queue does not contain a message of the desired type,
      or a message catalog does not contain the requested message.
    
    But even the OpenBSD intro.2 is very clear, actually:
    
      Note that a number of system calls overload the meanings of
      these error numbers, and that the meanings must be interpreted
      according to the type and circumstances of the call.
    
     --End of <871ps43k34.fsf@bloch.sibelius.xs4all.nl>
    
    The question i forgot to ask is why the FreeBSD people said that
    "beneath" does not work, except for RESOLVE_BENEATH.  Neither in
    the commit nor that phabricator thing is any explanation why it
    actually did not work out.
    I think the idea is good.  People would need to adapt.
    
    --steffen
    |
    |Der Kragenbaer,                The moon bear,
    |der holt sich munter           he cheerfully and one by one
    |einen nach dem anderen runter  wa.ks himself off
    |(By Robert Gernhardt)
    
    
  • H. Hartzer:

    openat(2) is mostly useless, sadly

  • H. Hartzer:

    openat(2) is mostly useless, sadly