From a542c4dc43db906b30ea6b2b1192cf87b01f572e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 May 2015 21:48:20 +0200 Subject: tmpfiles: use lstat() instead of stat() when checking whether a file system object already exists --- src/tmpfiles/tmpfiles.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 32bb097dd3..f7dad8491e 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1253,13 +1253,12 @@ static int create_item(Item *i) { if (errno != EEXIST) return log_error_errno(errno, "Failed to create fifo %s: %m", i->path); - if (stat(i->path, &st) < 0) + if (lstat(i->path, &st) < 0) return log_error_errno(errno, "stat(%s) failed: %m", i->path); if (!S_ISFIFO(st.st_mode)) { if (i->force) { - RUN_WITH_UMASK(0000) { mac_selinux_create_file_prepare(i->path, S_IFIFO); r = mkfifo_atomic(i->path, i->mode); @@ -1270,7 +1269,7 @@ static int create_item(Item *i) { return log_error_errno(r, "Failed to create fifo %s: %m", i->path); creation = CREATION_FORCE; } else { - log_debug("%s is not a fifo.", i->path); + log_warning("\"%s\" already exists and is not a fifo.", i->path); return 0; } } else @@ -1311,6 +1310,7 @@ static int create_item(Item *i) { if (r < 0) return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path); + creation = CREATION_FORCE; } else { log_debug("\"%s\" is not a symlink or does not point to the correct path.", i->path); @@ -1319,9 +1319,9 @@ static int create_item(Item *i) { } else creation = CREATION_EXISTING; } else + creation = CREATION_NORMAL; log_debug("%s symlink \"%s\".", creation_mode_verb_to_string(creation), i->path); - break; } @@ -1357,7 +1357,7 @@ static int create_item(Item *i) { if (errno != EEXIST) return log_error_errno(errno, "Failed to create device node %s: %m", i->path); - if (stat(i->path, &st) < 0) + if (lstat(i->path, &st) < 0) return log_error_errno(errno, "stat(%s) failed: %m", i->path); if ((st.st_mode & S_IFMT) != file_type) { @@ -1381,6 +1381,7 @@ static int create_item(Item *i) { creation = CREATION_EXISTING; } else creation = CREATION_NORMAL; + log_debug("%s %s device node \"%s\" %u:%u.", creation_mode_verb_to_string(creation), i->type == CREATE_BLOCK_DEVICE ? "block" : "char", -- cgit v1.2.3-54-g00ecf