Re: Would O_APPEND for /dev/null be possible?

From: Steffen Nurpmeso <steffen_at_sdaoden.eu>
Date: Wed, 09 Aug 2017 23:21:44 +0200
Good evening.

Bryan Drewery <bdrewery_at_FreeBSD.org> wrote:
 |On 8/7/2017 2:36 PM, Steffen Nurpmeso wrote:
 |> I can open a file with "a+", which, for this software, means
 |> "O_RDWR | O_APPEND | O_CREAT | n_O_NOFOLLOW" on Linux, Solaris and
 |> OpenBSD, but FreeBSD complains, i think because O_APPEND.  (I
 ...
 |> # cat uh.c
 |> #include <err.h>
 |> #include <fcntl.h>
 |> 
 |> int main() {
 |>         int fd;
 |> 
 |>         fd = open("/dev/null", O_RDWR | O_APPEND | O_CREAT | O_NOFOLLOW);
 |>         if (fd == -1)
 |>                 err(1, "open");
 |>         return 0;
 |>}
 |
 |> # truss ./uh
 |...
 |> openat(AT_FDCWD,"/dev/null",O_RDWR|O_APPEND|O_NOFOLLOW|O_CREAT,03777776252\
 |> 0) = 3 (0x3)
 |
 |Seems to work fine.

Puh. ...  I really looked, logically this codepath should not use
locking, so i thought ...  Hmm, this is even more complicated than
i thought, wait, i have to debug that.  And: it turns out that
a fseek(3) on the descriptor opened not only fails but sets the
ferror(3) state of the FILE!  I would need to look into the
standard whether this behaviour is correct, but in any case we are
not prepared for that, and neither of Linux, Solaris nor OpenBSD
enter this condition.

(What i did is with the MUA i maintain use the rather useless
`write' command which by default writes to /dev/null, this stacks
over c_write()[1] over to save1()[2] which does a lot of stuff,
anyway /dev/null opened via n_fopen_any()[3] to MBOX preparation
call n_folder_mbox_prepare_append()[4] which is defined here[5].
This never made problems yet, but of course i admit it is
a generalization (of several instances of rather identical code in
former versions of this MUA) which is truly bad and will,
hopefully, in a distant future be replaced by a "Mailbox" object
which then has some kind of Mailbox::append() (or prepare_append()
first if anything else fails), and that could act better for some
special files.  Anyway, that not today.)

  [1] https://git.sdaoden.eu/cgit/s-nail.git/tree/cmd-write.c#n380
  [2] https://git.sdaoden.eu/cgit/s-nail.git/tree/cmd-write.c#n56
  [3] https://git.sdaoden.eu/cgit/s-nail.git/tree/cmd-write.c#n145
  [4] https://git.sdaoden.eu/cgit/s-nail.git/tree/cmd-write.c#n168
  [5] https://git.sdaoden.eu/cgit/s-nail.git/tree/folder.c#n900

Ciao!

--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)
Received on Wed Aug 09 2017 - 19:20:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:12 UTC