summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorZach Smith <z@zxmth.us>2019-10-03 18:19:18 -0700
committerZach Smith <z@zxmth.us>2019-10-03 18:28:15 -0700
commitd0ea5c5e39dce60efbce6d86534eb9ca253440b0 (patch)
tree76fa1d6111fc318b676ade8ff28a82e109d1d21e /src/tmpfiles
parentc55ac248257e780bc4e70492527ea910744c5226 (diff)
downloadsystemd-d0ea5c5e39dce60efbce6d86534eb9ca253440b0.tar.gz
systemd-d0ea5c5e39dce60efbce6d86534eb9ca253440b0.tar.bz2
systemd-d0ea5c5e39dce60efbce6d86534eb9ca253440b0.zip
systemd-tmpfiles: allow appending content to file
Adds support to append to files with w+ type. w /tmp/13291.out - - - - first line\n w+ /tmp/13291.out - - - - second line\n
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 5630cddb4d..19a2aa6f21 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1257,7 +1257,7 @@ static int path_set_attribute(Item *item, const char *path) {
static int write_one_file(Item *i, const char *path) {
_cleanup_close_ int fd = -1, dir_fd = -1;
char *bn;
- int r;
+ int flags, r;
assert(i);
assert(path);
@@ -1272,8 +1272,10 @@ static int write_one_file(Item *i, const char *path) {
bn = basename(path);
+ flags = O_NONBLOCK|O_CLOEXEC|O_WRONLY|O_NOCTTY;
+
/* Follows symlinks */
- fd = openat(dir_fd, bn, O_NONBLOCK|O_CLOEXEC|O_WRONLY|O_NOCTTY, i->mode);
+ fd = openat(dir_fd, bn, i->append_or_force ? flags|O_APPEND : flags, i->mode);
if (fd < 0) {
if (errno == ENOENT) {
log_debug_errno(errno, "Not writing missing file \"%s\": %m", path);
@@ -2794,7 +2796,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
size_t n;
for (n = 0; n < existing->n_items; n++) {
- if (!item_compatible(existing->items + n, &i)) {
+ if (!item_compatible(existing->items + n, &i) && !i.append_or_force) {
log_notice("[%s:%u] Duplicate line for path \"%s\", ignoring.",
fname, line, i.path);
return 0;