diff options
-rw-r--r-- | runner/executor.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/runner/executor.c b/runner/executor.c index 78a1ba5d..2754f5a2 100644 --- a/runner/executor.c +++ b/runner/executor.c @@ -238,8 +238,15 @@ static char *filenames[] = { static int open_at_end(int dirfd, char *name) { - int fd = openat(dirfd, name, O_WRONLY | O_CREAT | O_CLOEXEC, 0666); + int fd = openat(dirfd, name, O_RDWR | O_CREAT | O_CLOEXEC, 0666); + char last; + if (fd >= 0) { + if (lseek(fd, -1, SEEK_END) >= 0 && + read(fd, &last, 1) == 1 && + last != '\n') { + write(fd, "\n", 1); + } lseek(fd, 0, SEEK_END); } |