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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-11-08 13:41:13 +01:00
parent bcb639662e
commit 0e58dc999c
3 changed files with 14 additions and 21 deletions
-18
View 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;
-2
View 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);
+14 -1
View File
@@ -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;