tmpfiles: use lstat() instead of stat() when checking whether a file system object already exists

This commit is contained in:
Lennart Poettering 2015-05-15 21:48:20 +02:00
parent 7b135a7399
commit a542c4dc43

View file

@ -1253,13 +1253,12 @@ static int create_item(Item *i) {
if (errno != EEXIST) if (errno != EEXIST)
return log_error_errno(errno, "Failed to create fifo %s: %m", i->path); 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); return log_error_errno(errno, "stat(%s) failed: %m", i->path);
if (!S_ISFIFO(st.st_mode)) { if (!S_ISFIFO(st.st_mode)) {
if (i->force) { if (i->force) {
RUN_WITH_UMASK(0000) { RUN_WITH_UMASK(0000) {
mac_selinux_create_file_prepare(i->path, S_IFIFO); mac_selinux_create_file_prepare(i->path, S_IFIFO);
r = mkfifo_atomic(i->path, i->mode); 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); return log_error_errno(r, "Failed to create fifo %s: %m", i->path);
creation = CREATION_FORCE; creation = CREATION_FORCE;
} else { } else {
log_debug("%s is not a fifo.", i->path); log_warning("\"%s\" already exists and is not a fifo.", i->path);
return 0; return 0;
} }
} else } else
@ -1311,6 +1310,7 @@ static int create_item(Item *i) {
if (r < 0) if (r < 0)
return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path); return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path);
creation = CREATION_FORCE; creation = CREATION_FORCE;
} else { } else {
log_debug("\"%s\" is not a symlink or does not point to the correct path.", i->path); 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 } else
creation = CREATION_EXISTING; creation = CREATION_EXISTING;
} else } else
creation = CREATION_NORMAL; creation = CREATION_NORMAL;
log_debug("%s symlink \"%s\".", creation_mode_verb_to_string(creation), i->path); log_debug("%s symlink \"%s\".", creation_mode_verb_to_string(creation), i->path);
break; break;
} }
@ -1357,7 +1357,7 @@ static int create_item(Item *i) {
if (errno != EEXIST) if (errno != EEXIST)
return log_error_errno(errno, "Failed to create device node %s: %m", i->path); 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); return log_error_errno(errno, "stat(%s) failed: %m", i->path);
if ((st.st_mode & S_IFMT) != file_type) { if ((st.st_mode & S_IFMT) != file_type) {
@ -1381,6 +1381,7 @@ static int create_item(Item *i) {
creation = CREATION_EXISTING; creation = CREATION_EXISTING;
} else } else
creation = CREATION_NORMAL; creation = CREATION_NORMAL;
log_debug("%s %s device node \"%s\" %u:%u.", log_debug("%s %s device node \"%s\" %u:%u.",
creation_mode_verb_to_string(creation), creation_mode_verb_to_string(creation),
i->type == CREATE_BLOCK_DEVICE ? "block" : "char", i->type == CREATE_BLOCK_DEVICE ? "block" : "char",