| 516 | } |
| 517 | |
| 518 | static int posix_log_file_open(const posix_log_path_t *path, struct stat *status_out, |
| 519 | bool *created_out) { |
| 520 | int flags = O_RDWR | O_APPEND | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK; |
| 521 | int fd = openat(path->dir_fd, path->base, flags | O_CREAT | O_EXCL, 0600); |
| 522 | bool created = fd >= 0; |
| 523 | if (fd < 0 && errno == EEXIST) { |
| 524 | fd = openat(path->dir_fd, path->base, flags); |
| 525 | } |
| 526 | struct stat status; |
| 527 | struct stat by_path; |
| 528 | if (fd < 0 || !fd_cloexec(fd) || !fd_regular_current_user(fd, &status) || |
| 529 | fchmod(fd, 0600) != 0 || |
| 530 | fstatat(path->dir_fd, path->base, &by_path, AT_SYMLINK_NOFOLLOW) != 0 || |
| 531 | !S_ISREG(by_path.st_mode) || status.st_dev != by_path.st_dev || |
| 532 | status.st_ino != by_path.st_ino) { |
| 533 | if (fd >= 0) { |
| 534 | (void)close(fd); |
| 535 | } |
| 536 | return -1; |
| 537 | } |
| 538 | *status_out = status; |
| 539 | *created_out = created; |
| 540 | return fd; |
| 541 | } |
| 542 | |
| 543 | static bool posix_complete_write(int fd, const char *record, size_t record_length, |
| 544 | off_t original_size) { |
no test coverage detected