diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-02-19 17:37:47 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-02-20 15:39:21 +0100 |
commit | 817b1c5b1e9af0a2cac9b895f1880ff61812f8cf (patch) | |
tree | d30b4a71d6cde4c7852a5dbc2421a4545b492c61 /src/journal/journal-file.c | |
parent | journal-file: refuse opening non-regular journal files (diff) | |
download | systemd-817b1c5b1e9af0a2cac9b895f1880ff61812f8cf.tar.xz systemd-817b1c5b1e9af0a2cac9b895f1880ff61812f8cf.zip |
journal-file: add O_NONBLOCK for paranoia when opening journal files
Diffstat (limited to 'src/journal/journal-file.c')
-rw-r--r-- | src/journal/journal-file.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 09c511b8b8..1640a8baf0 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -3298,6 +3298,8 @@ int journal_file_open( goto fail; } } else { + assert(fd >= 0); + /* If we don't know the path, fill in something explanatory and vaguely useful */ if (asprintf(&f->path, "/proc/self/%i", fd) < 0) { r = -ENOMEM; @@ -3312,7 +3314,11 @@ int journal_file_open( } if (f->fd < 0) { - f->fd = open(f->path, f->flags|O_CLOEXEC, f->mode); + /* We pass O_NONBLOCK here, so that in case somebody pointed us to some character device node or FIFO + * or so, we likely fail quickly than block for long. For regular files O_NONBLOCK has no effect, hence + * it doesn't hurt in that case. */ + + f->fd = open(f->path, f->flags|O_CLOEXEC|O_NONBLOCK, f->mode); if (f->fd < 0) { r = -errno; goto fail; @@ -3320,6 +3326,10 @@ int journal_file_open( /* fds we opened here by us should also be closed by us. */ f->close_fd = true; + + r = fd_nonblock(f->fd, false); + if (r < 0) + goto fail; } f->cache_fd = mmap_cache_add_fd(f->mmap, f->fd); |