summaryrefslogtreecommitdiff
path: root/src/journal/sd-journal.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-19 18:01:05 +0100
committerLennart Poettering <lennart@poettering.net>2018-02-20 15:39:31 +0100
commit3cc44114038621237a9d8ee4be3ff836138a55c1 (patch)
tree667e511d5a69feb4c11ab5830f2669b723764401 /src/journal/sd-journal.c
parent9c66f528138f4fc856b3e9e137245b7048d5747d (diff)
downloadsystemd-3cc44114038621237a9d8ee4be3ff836138a55c1.tar.gz
stat-util: unify code that checks whether something is a regular file
Let's add a common implementation for regular file checks, that are careful to return the right error code (EISDIR/EISLNK/EBADFD) when we are encountering a wrong file node.
Diffstat (limited to 'src/journal/sd-journal.c')
-rw-r--r--src/journal/sd-journal.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 7e1fda8596..11dbd83f2d 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1303,14 +1303,10 @@ static int add_any_file(
r = log_debug_errno(errno, "Failed to fstat file '%s': %m", path);
goto finish;
}
- if (S_ISDIR(st.st_mode)) {
- log_debug("Uh, file '%s' is a directory? Refusing.", path);
- r = -EISDIR;
- goto finish;
- }
- if (!S_ISREG(st.st_mode)) {
- log_debug("Uh, file '%s' is not a regular file? Refusing.", path);
- r = -EBADFD;
+
+ r = stat_verify_regular(&st);
+ if (r < 0) {
+ log_debug_errno(r, "Refusing to open '%s', as it is not a regular file.", path);
goto finish;
}
@@ -2074,14 +2070,9 @@ _public_ int sd_journal_open_files_fd(sd_journal **ret, int fds[], unsigned n_fd
goto fail;
}
- if (S_ISDIR(st.st_mode)) {
- r = -EISDIR;
- goto fail;
- }
- if (!S_ISREG(st.st_mode)) {
- r = -EBADFD;
+ r = stat_verify_regular(&st);
+ if (r < 0)
goto fail;
- }
r = add_any_file(j, fds[i], NULL);
if (r < 0)