| 152 | -------------------------------------------------------------------------*/ |
| 153 | |
| 154 | int |
| 155 | LogFile::open_file() |
| 156 | { |
| 157 | // whatever we want to open should have a name |
| 158 | ink_assert(m_name != nullptr); |
| 159 | |
| 160 | // is_open() takes into account if we're using BaseLogFile or a naked fd |
| 161 | if (is_open()) { |
| 162 | return LOG_FILE_NO_ERROR; |
| 163 | } |
| 164 | |
| 165 | bool file_exists = LogFile::exists(m_name); |
| 166 | |
| 167 | if (m_file_format == LOG_FILE_PIPE) { |
| 168 | // setup pipe |
| 169 | if (mkfifo(m_name, S_IRUSR | S_IWUSR | S_IRGRP) < 0) { |
| 170 | if (errno != EEXIST) { |
| 171 | Error("Could not create named pipe %s for logging: %s", m_name, strerror(errno)); |
| 172 | return LOG_FILE_COULD_NOT_CREATE_PIPE; |
| 173 | } |
| 174 | } else { |
| 175 | Dbg(dbg_ctl_log_file, "Created named pipe %s for logging", m_name); |
| 176 | } |
| 177 | |
| 178 | // now open the pipe |
| 179 | Dbg(dbg_ctl_log_file, "attempting to open pipe %s", m_name); |
| 180 | m_fd = ::open(m_name, O_WRONLY | O_NDELAY, 0); |
| 181 | if (m_fd < 0) { |
| 182 | Dbg(dbg_ctl_log_file, "no readers for pipe %s", m_name); |
| 183 | return LOG_FILE_NO_PIPE_READERS; |
| 184 | } |
| 185 | |
| 186 | #ifdef F_GETPIPE_SZ |
| 187 | // adjust pipe size if necessary |
| 188 | if (m_pipe_buffer_size) { |
| 189 | long pipe_size = static_cast<long>(fcntl(m_fd, F_GETPIPE_SZ)); |
| 190 | if (pipe_size == -1) { |
| 191 | Error("Get pipe size failed for pipe %s: %s", m_name, strerror(errno)); |
| 192 | } else { |
| 193 | Dbg(dbg_ctl_log_file, "Previous buffer size for pipe %s: %ld", m_name, pipe_size); |
| 194 | } |
| 195 | |
| 196 | int ret = fcntl(m_fd, F_SETPIPE_SZ, m_pipe_buffer_size); |
| 197 | if (ret == -1) { |
| 198 | Error("Set pipe size failed for pipe %s to size %d: %s", m_name, m_pipe_buffer_size, strerror(errno)); |
| 199 | } |
| 200 | |
| 201 | pipe_size = static_cast<long>(fcntl(m_fd, F_GETPIPE_SZ)); |
| 202 | if (pipe_size == -1) { |
| 203 | Error("Get pipe size after setting it failed for pipe %s: %s", m_name, strerror(errno)); |
| 204 | } else { |
| 205 | Dbg(dbg_ctl_log_file, "New buffer size for pipe %s: %ld", m_name, pipe_size); |
| 206 | } |
| 207 | } |
| 208 | #endif // F_GETPIPE_SZ |
| 209 | } else { |
| 210 | if (m_log) { |
| 211 | int status = m_log->open_file(Log::config->logfile_perm); |
no test coverage detected