summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2018-05-24 14:17:07 +0200
committerFranck Bui <fbui@suse.com>2018-07-30 14:44:58 +0200
commit14f3480af1f5b5884827977fedecf0d7bb61ebab (patch)
tree34f56b2703459e1c040d4d30cd94f1361cb6253e
parent1c57fa90be988b6f50324dbaf1996ddc3e114faf (diff)
downloadsystemd-14f3480af1f5b5884827977fedecf0d7bb61ebab.tar.gz
systemd-14f3480af1f5b5884827977fedecf0d7bb61ebab.tar.bz2
systemd-14f3480af1f5b5884827977fedecf0d7bb61ebab.zip
tmpfiles: stat file in item_do() rather than in its callers
This a slight simplification since all callers of item_do() (glob_item_recursively() and item_do() itself) stat the file descriptor only for passing it to item_do().
-rw-r--r--src/tmpfiles/tmpfiles.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 52f4d90fba..31d4c923a2 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1295,18 +1295,23 @@ static int write_one_file(Item *i, const char *path) {
typedef int (*action_t)(Item *, const char *);
typedef int (*fdaction_t)(Item *, int fd, const struct stat *st);
-static int item_do(Item *i, int fd, const struct stat *st, fdaction_t action) {
+static int item_do(Item *i, int fd, fdaction_t action) {
+ struct stat st;
int r = 0, q;
assert(i);
assert(fd >= 0);
- assert(st);
+
+ if (fstat(fd, &st) < 0) {
+ r = -errno;
+ goto finish;
+ }
/* This returns the first error we run into, but nevertheless
* tries to go on */
- r = action(i, fd, st);
+ r = action(i, fd, &st);
- if (S_ISDIR(st->st_mode)) {
+ if (S_ISDIR(st.st_mode)) {
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
@@ -1322,16 +1327,15 @@ static int item_do(Item *i, int fd, const struct stat *st, fdaction_t action) {
}
FOREACH_DIRENT_ALL(de, d, q = -errno; goto finish) {
- struct stat de_st;
int de_fd;
if (dot_or_dot_dot(de->d_name))
continue;
de_fd = openat(fd, de->d_name, O_NOFOLLOW|O_CLOEXEC|O_PATH);
- if (de_fd >= 0 && fstat(de_fd, &de_st) >= 0)
+ if (de_fd >= 0)
/* pass ownership of dirent fd over */
- q = item_do(i, de_fd, &de_st, action);
+ q = item_do(i, de_fd, action);
else
q = -errno;
@@ -1377,7 +1381,6 @@ static int glob_item_recursively(Item *i, fdaction_t action) {
STRV_FOREACH(fn, g.gl_pathv) {
_cleanup_close_ int fd = -1;
- struct stat st;
/* Make sure we won't trigger/follow file object (such as
* device nodes, automounts, ...) pointed out by 'fn' with
@@ -1390,12 +1393,7 @@ static int glob_item_recursively(Item *i, fdaction_t action) {
continue;
}
- if (fstat(fd, &st) < 0) {
- r = r ?: -errno;
- continue;
- }
-
- k = item_do(i, fd, &st, action);
+ k = item_do(i, fd, action);
if (k < 0 && r == 0)
r = k;