[systemd-commits] 3 commits - CODING_STYLE src/tmpfiles

Lennart Poettering lennart at kemper.freedesktop.org
Fri May 15 12:49:07 PDT 2015


 CODING_STYLE            |    3 +++
 src/tmpfiles/tmpfiles.c |   28 +++++++++++++++++-----------
 2 files changed, 20 insertions(+), 11 deletions(-)

New commits:
commit a542c4dc43db906b30ea6b2b1192cf87b01f572e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 15 21:48:20 2015 +0200

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

diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 32bb097..f7dad84 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",

commit 7b135a73999b6911ebb85c053b6f7701fdac1883
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 15 21:47:22 2015 +0200

    tmpfiles: don't fail if we cannot create a subvolume because a file system is read-only but a dir already exists anyway
    
    https://bugs.freedesktop.org/show_bug.cgi?id=90281

diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 5a57835..32bb097 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1214,20 +1214,25 @@ static int create_item(Item *i) {
                                 r = mkdir_label(i->path, i->mode);
 
                 if (r < 0) {
-                        if (r != -EEXIST)
-                                return log_error_errno(r, "Failed to create directory or subvolume \"%s\": %m", i->path);
+                        int k;
 
-                        if (stat(i->path, &st) < 0)
-                                return log_error_errno(errno, "stat(%s) failed: %m", i->path);
+                        if (r != -EEXIST && r != -EROFS)
+                                return log_error_errno(r, "Failed to create directory or subvolume \"%s\": %m", i->path);
 
-                        if (!S_ISDIR(st.st_mode)) {
-                                log_debug("\"%s\" already exists and is not a directory.", i->path);
+                        k = is_dir(i->path, false);
+                        if (k == -ENOENT && r == -EROFS)
+                                return log_error_errno(r, "%s does not exist and cannot be created as the file system is read-only.", i->path);
+                        if (k < 0)
+                                return log_error_errno(k, "Failed to check if %s exists: %m", i->path);
+                        if (!k) {
+                                log_warning("\"%s\" already exists and is not a directory.", i->path);
                                 return 0;
                         }
 
                         creation = CREATION_EXISTING;
                 } else
                         creation = CREATION_NORMAL;
+
                 log_debug("%s directory \"%s\".", creation_mode_verb_to_string(creation), i->path);
 
                 r = path_set_perms(i, i->path);

commit 0fef704c6fbb07cb0289eadc405f49286aa70e53
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 15 21:34:14 2015 +0200

    CODING_STYLE: document that EXIT_FAILURE and EXIT_SUCCESS should be used

diff --git a/CODING_STYLE b/CODING_STYLE
index 795521c..fab9288 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -287,3 +287,6 @@
           zero(t);
           t.foo = 7;
           t.bar = "bazz";
+
+- When returning a return code from main(), please preferably use
+  EXIT_FAILURE and EXIT_SUCCESS as defined by libc.



More information about the systemd-commits mailing list