]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: make prot_from_flags() static and rename
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 5 Nov 2022 15:12:15 +0000 (16:12 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Nov 2022 12:41:13 +0000 (13:41 +0100)
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.

src/basic/util.c
src/basic/util.h
src/libsystemd/sd-journal/journal-file.c

index fbcb87001a900d55be06176674134c67a6996130..e1f090ebb9465f5df980685c949119f617e28a17 100644 (file)
@@ -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;
index 5d5d8216108391291b721dcf80948a4ec44e854d..0fcc1882f6818a985a83655bde11d64154acbbcf 100644 (file)
@@ -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);
 
index c1ec6bb1d85efd529e7e1cc13a15a02a5130e616..3f0dcaebf17057e78754c2add9b5f99220c4d995 100644 (file)
 #  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;