]> err.no Git - systemd/commitdiff
tmpfiles: if we are supposed to write a string to a file, it's OK if we can't write...
authorLennart Poettering <lennart@poettering.net>
Tue, 15 May 2012 12:34:33 +0000 (14:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 15 May 2012 12:35:51 +0000 (14:35 +0200)
src/shared/util.c
src/tmpfiles/tmpfiles.c

index d6af92745341a4f34a1dabe870ba4022070b5ee2..0b81e1c4f985ea08dfc657682576d467e060bae1 100644 (file)
@@ -597,7 +597,8 @@ int write_one_line_file(const char *fn, const char *line) {
         assert(fn);
         assert(line);
 
-        if (!(f = fopen(fn, "we")))
+        f = fopen(fn, "we");
+        if (!f)
                 return -errno;
 
         errno = 0;
index 235617853b592e1a8b99c8343df2a993b203d674..2ee0601e643f24e6baee10b8e827572f50151a60 100644 (file)
@@ -617,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;
                         }