[systemd-devel] [PATCH 2/2] tmpfiles: explicitly check for existing files

Michael Olbrich m.olbrich at pengutronix.de
Sun Aug 17 00:45:01 PDT 2014


On read-only filesystems trying to create the target will not fail with
EEXIST but with EROFS.
---

Some more cases that fail on read-only filesystems.

 src/tmpfiles/tmpfiles.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 3bab7ac..3572367 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -671,7 +671,10 @@ static int create_item(Item *i) {
                 break;
 
         case COPY_FILES:
-                r = copy_tree(i->argument, i->path, false);
+                if (stat(i->path, &st) < 0)
+                        r = copy_tree(i->argument, i->path, false);
+                else
+                        r = -EEXIST;
                 if (r < 0) {
                         struct stat a, b;
 
@@ -789,13 +792,17 @@ static int create_item(Item *i) {
         case CREATE_SYMLINK:
 
                 label_context_set(i->path, S_IFLNK);
-                r = symlink(i->argument, i->path);
+                if (stat(i->path, &st) < 0) {
+                        if (symlink(i->argument, i->path) < 0)
+                                r = -errno;
+                } else
+                        r = -EEXIST;
                 label_context_clear();
 
                 if (r < 0) {
                         _cleanup_free_ char *x = NULL;
 
-                        if (errno != EEXIST) {
+                        if (r != -EEXIST) {
                                 log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
                                 return -errno;
                         }
-- 
2.0.1



More information about the systemd-devel mailing list