From: Zygo Blaxell Date: Fri, 13 Mar 2026 23:06:32 +0000 (-0400) Subject: hash: fix FLAGS_CREATE_FILE O_WRONLY preventing pread on new hash table X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=719046b53b4942e6c6e7ccfcb1a3f1b4bd565f1c;p=bees hash: fix FLAGS_CREATE_FILE O_WRONLY preventing pread on new hash table FLAGS_CREATE_FILE used O_WRONLY|O_CREAT|O_EXCL. On a fresh beeshome, open_file() creates beeshash.dat through this flag and assigns the write-only fd to m_fd. The prefetch thread then calls pread_or_die(m_fd) and gets EBADF because pread() requires O_RDONLY or O_RDWR. In production, beesd and OpenRC pre-create beeshash.dat with truncate(1) before exec'ing bees, so the creation branch in open_file() was never exercised. Integration tests exposed this by starting bees on a fresh $BEESHOME. Change FLAGS_CREATE_FILE from O_WRONLY to O_RDWR. The name still describes the intent (O_CREAT|O_EXCL ensure exclusive creation); O_RDWR simply allows reading the file back after writing it. Signed-off-by: Zygo Blaxell --- diff --git a/src/bees.h b/src/bees.h index 1fd86b4d..7c0cfca5 100644 --- a/src/bees.h +++ b/src/bees.h @@ -118,14 +118,11 @@ const size_t BEES_READAHEAD_SIZE = 1024 * 1024; // Flags const int FLAGS_OPEN_COMMON = O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC | O_NOATIME | O_LARGEFILE | O_NOCTTY; -const int FLAGS_OPEN_DIR = FLAGS_OPEN_COMMON | O_RDONLY | O_DIRECTORY; -const int FLAGS_OPEN_FILE = FLAGS_OPEN_COMMON | O_RDONLY; -const int FLAGS_OPEN_FILE_RW = FLAGS_OPEN_COMMON | O_RDWR; -const int FLAGS_OPEN_TMPFILE = FLAGS_OPEN_FILE_RW | O_TMPFILE | O_TRUNC | O_EXCL; -const int FLAGS_CREATE_FILE = FLAGS_OPEN_COMMON | O_WRONLY | O_CREAT | O_EXCL; - -// Fanotify allows O_APPEND, O_DSYNC, O_NOATIME, O_NONBLOCK, O_CLOEXEC, O_LARGEFILE -const int FLAGS_OPEN_FANOTIFY = O_RDWR | O_NOATIME | O_CLOEXEC | O_LARGEFILE; +const int FLAGS_OPEN_DIR = FLAGS_OPEN_COMMON | O_RDONLY | O_DIRECTORY; ///< Open a directory read-only. +const int FLAGS_OPEN_FILE = FLAGS_OPEN_COMMON | O_RDONLY; ///< Open a regular file read-only. +const int FLAGS_OPEN_FILE_RW = FLAGS_OPEN_COMMON | O_RDWR; ///< Open a regular file read-write. +const int FLAGS_OPEN_TMPFILE = FLAGS_OPEN_FILE_RW | O_TMPFILE | O_TRUNC | O_EXCL; ///< Create an anonymous temp file. +const int FLAGS_CREATE_FILE = FLAGS_OPEN_COMMON | O_RDWR | O_CREAT | O_EXCL; ///< Create a new file exclusively. // macros ----------------------------------------