From owner-freebsd-current@freebsd.org Wed Aug 9 21:20:51 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B1505DD61D1 for ; Wed, 9 Aug 2017 21:20:51 +0000 (UTC) (envelope-from steffen@sdaoden.eu) Received: from sdaoden.eu (sdaoden.eu [217.144.132.164]) by mx1.freebsd.org (Postfix) with ESMTP id 7F1071CB9; Wed, 9 Aug 2017 21:20:51 +0000 (UTC) (envelope-from steffen@sdaoden.eu) Received: by sdaoden.eu (Postfix, from userid 1000) id 7E43E16051; Wed, 9 Aug 2017 23:20:44 +0200 (CEST) Date: Wed, 09 Aug 2017 23:21:44 +0200 From: Steffen Nurpmeso To: Bryan Drewery Cc: freebsd-current@freebsd.org Subject: Re: Would O_APPEND for /dev/null be possible? Message-ID: <20170809212144.Qx0Yr%steffen@sdaoden.eu> References: <20170807213656.FwzOG%steffen@sdaoden.eu> <768c55f1-6a10-868b-9cd5-6ca5f93aaca3@FreeBSD.org> Mail-Followup-To: Bryan Drewery , freebsd-current@freebsd.org, Steffen Nurpmeso User-Agent: s-nail v14.9.3-dirty OpenPGP: id=232C220BCB5690A37BD22FFDEB66022795F382CE; url=https://www.sdaoden.eu/downloads/steffen.asc BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in the world can make no bugs. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2017 21:20:51 -0000 Good evening. Bryan Drewery 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 |> #include |> |> 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)