| 1567 | } |
| 1568 | |
| 1569 | static int private_log_file_open(int directory_fd, const char *base_name, struct stat *status_out) { |
| 1570 | int flags = O_WRONLY | O_APPEND | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK; |
| 1571 | int fd = openat(directory_fd, base_name, flags | O_CREAT | O_EXCL, 0600); |
| 1572 | if (fd < 0 && errno == EEXIST) { |
| 1573 | fd = openat(directory_fd, base_name, flags); |
| 1574 | } |
| 1575 | struct stat status; |
| 1576 | if (fd < 0 || !fd_set_cloexec(fd) || fchmod(fd, 0600) != 0 || |
| 1577 | !private_regular_file_snapshot(directory_fd, base_name, fd, 1, &status) || |
| 1578 | status.st_size < 0) { |
| 1579 | if (fd >= 0) { |
| 1580 | (void)close(fd); |
| 1581 | } |
| 1582 | return -1; |
| 1583 | } |
| 1584 | *status_out = status; |
| 1585 | return fd; |
| 1586 | } |
| 1587 | |
| 1588 | FILE *cbm_daemon_ipc_private_log_open(const char *directory_path, const char *base_name, |
| 1589 | size_t rotate_cap_bytes) { |
no test coverage detected