| 2149 | } |
| 2150 | |
| 2151 | static int private_log_file_open(int directory_fd, const char *base_name, struct stat *status_out) { |
| 2152 | int flags = O_WRONLY | O_APPEND | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK; |
| 2153 | int fd = openat(directory_fd, base_name, flags | O_CREAT | O_EXCL, 0600); |
| 2154 | if (fd < 0 && errno == EEXIST) { |
| 2155 | fd = openat(directory_fd, base_name, flags); |
| 2156 | } |
| 2157 | struct stat status; |
| 2158 | if (fd < 0 || !fd_set_cloexec(fd) || fchmod(fd, 0600) != 0 || |
| 2159 | !private_regular_file_snapshot(directory_fd, base_name, fd, 1, &status) || |
| 2160 | status.st_size < 0) { |
| 2161 | if (fd >= 0) { |
| 2162 | (void)close(fd); |
| 2163 | } |
| 2164 | return -1; |
| 2165 | } |
| 2166 | *status_out = status; |
| 2167 | return fd; |
| 2168 | } |
| 2169 | |
| 2170 | FILE *cbm_daemon_ipc_private_log_open(const char *directory_path, const char *base_name, |
| 2171 | size_t rotate_cap_bytes) { |
no test coverage detected