chiark / gitweb /
cgtop: work even if not all cgroups are available
[elogind.git] / src / tmpfiles / tmpfiles.c
index 5db827eca204e4b9fbdff86e9ca35f0c23bddb39..2ee0601e643f24e6baee10b8e827572f50151a60 100644 (file)
 #include "log.h"
 #include "util.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "strv.h"
 #include "label.h"
 #include "set.h"
+#include "conf-files.h"
 
 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
  * them in the file system. This is intended to be used to create
@@ -615,8 +617,13 @@ static int create_item(Item *i) {
                         iovec[1].iov_len = 1;
 
                         n = writev(fd, iovec, 2);
-                        if (n < 0 || (size_t) n != l+1) {
-                                log_error("Failed to write file %s: %s", i->path, n < 0 ? strerror(-n) : "Short");
+
+                        /* It's OK if we don't write the trailing
+                         * newline, hence we check for l, instead of
+                         * l+1 here. Files in /sys often refuse
+                         * writing of the trailing newline. */
+                        if (n < 0 || (size_t) n < l) {
+                                log_error("Failed to write file %s: %s", i->path, n < 0 ? strerror(-n) : "Short write");
                                 close_nointr_nofail(fd);
                                 return n < 0 ? n : -EIO;
                         }
@@ -1291,8 +1298,8 @@ int main(int argc, char *argv[]) {
                                     "/usr/lib/tmpfiles.d",
                                     NULL);
                 if (r < 0) {
-                        r = EXIT_FAILURE;
                         log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
+                        r = EXIT_FAILURE;
                         goto finish;
                 }