From: Zbigniew Jędrzejewski-Szmek Date: Sat, 5 Nov 2022 15:12:15 +0000 (+0100) Subject: sd-journal: make prot_from_flags() static and rename X-Git-Tag: v253-rc1~572^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e58dc999c9f253b13bd6ed3f8d7c9844bc05a97;p=thirdparty%2Fsystemd.git sd-journal: make prot_from_flags() static and rename The function had just one caller and a name that didn't explain much. Let's make it static and rename for clarity. While at it, the only caller was not doing error handling correctly — the function would potentially return a negative error value which wasn't handled. In practice this couldn't happen, but let's remove this ambiguity. --- diff --git a/src/basic/util.c b/src/basic/util.c index fbcb87001a9..e1f090ebb94 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -23,24 +23,6 @@ int saved_argc = 0; char **saved_argv = NULL; static int saved_in_initrd = -1; -int prot_from_flags(int flags) { - - switch (flags & O_ACCMODE) { - - case O_RDONLY: - return PROT_READ; - - case O_WRONLY: - return PROT_WRITE; - - case O_RDWR: - return PROT_READ|PROT_WRITE; - - default: - return -EINVAL; - } -} - bool in_initrd(void) { int r; const char *e; diff --git a/src/basic/util.h b/src/basic/util.h index 5d5d8216108..0fcc1882f68 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -19,8 +19,6 @@ static inline void save_argc_argv(int argc, char **argv) { saved_argv = argv; } -int prot_from_flags(int flags) _const_; - bool in_initrd(void); void in_initrd_force(bool value); diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index c1ec6bb1d85..3f0dcaebf17 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -92,6 +92,19 @@ # pragma GCC diagnostic ignored "-Waddress-of-packed-member" #endif +static int mmap_prot_from_open_flags(int flags) { + switch (flags & O_ACCMODE) { + case O_RDONLY: + return PROT_READ; + case O_WRONLY: + return PROT_WRITE; + case O_RDWR: + return PROT_READ|PROT_WRITE; + default: + assert_not_reached(); + } +} + int journal_file_tail_end_by_pread(JournalFile *f, uint64_t *ret_offset) { uint64_t p; int r; @@ -3767,7 +3780,7 @@ int journal_file_open( newly_created = f->last_stat.st_size == 0 && journal_file_writable(f); } - f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(open_flags)); + f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, mmap_prot_from_open_flags(open_flags)); if (!f->cache_fd) { r = -ENOMEM; goto fail;