From 359203e1ee7b298eb3ca2ea43bfd9d0e8b7795cf Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 15 May 2012 14:34:33 +0200
Subject: [PATCH] tmpfiles: if we are supposed to write a string to a file,
it's OK if we can't write the trailing newline (cherry
picked from commit
03ad1136ba6ddaeca626aa24362dab764c7e2398)
---
src/shared/util.c | 3 ++-
src/tmpfiles/tmpfiles.c | 9 +++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index fb7631d..c1fc1a7 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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;
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 072776e..86c32ca 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -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;
}