| 2198 | } |
| 2199 | |
| 2200 | static void dev_report_fds(struct daemon *daemon, const u8 *msg) |
| 2201 | { |
| 2202 | bool found_chr_fd = false; |
| 2203 | |
| 2204 | /* Not only would this get upset with all the /dev/null, |
| 2205 | * our symbol code fails if it can't open files */ |
| 2206 | if (daemon->dev_exhausted_fds) |
| 2207 | return; |
| 2208 | |
| 2209 | for (int fd = 3; fd < 4096; fd++) { |
| 2210 | bool listener; |
| 2211 | const struct io_conn *c; |
| 2212 | const struct io_listener *l; |
| 2213 | struct stat finfo; |
| 2214 | if (!isatty(fd) && errno == EBADF) |
| 2215 | continue; |
| 2216 | if (fd == HSM_FD) { |
| 2217 | status_info("dev_report_fds: %i -> hsm fd", fd); |
| 2218 | continue; |
| 2219 | } |
| 2220 | if (fd == GOSSIPCTL_FD) { |
| 2221 | status_info("dev_report_fds: %i -> gossipd fd", fd); |
| 2222 | continue; |
| 2223 | } |
| 2224 | if (fd == daemon->dev_disconnect_fd) { |
| 2225 | status_info("dev_report_fds: %i -> dev_disconnect_fd", fd); |
| 2226 | continue; |
| 2227 | } |
| 2228 | if (daemon->gossmap_raw && fd == gossmap_fd(daemon->gossmap_raw)) { |
| 2229 | status_info("dev_report_fds: %i -> gossip_store", fd); |
| 2230 | continue; |
| 2231 | } |
| 2232 | if (fd == tor_service_fd) { |
| 2233 | status_info("dev_report_fds: %i -> tor service fd", fd); |
| 2234 | continue; |
| 2235 | } |
| 2236 | c = io_have_fd(fd, &listener); |
| 2237 | if (!c) { |
| 2238 | /* We consider a single CHR as expected */ |
| 2239 | if (!found_chr_fd && !fstat(fd, &finfo) |
| 2240 | && S_ISCHR(finfo.st_mode)) { |
| 2241 | found_chr_fd = true; |
| 2242 | status_info("dev_report_fds: %i -> char fd", fd); |
| 2243 | continue; |
| 2244 | } |
| 2245 | |
| 2246 | status_broken("dev_report_fds: %i open but unowned? fd" |
| 2247 | " mode: %s", fd, fd_mode_str(fd)); |
| 2248 | continue; |
| 2249 | } else if (listener) { |
| 2250 | l = (void *)c; |
| 2251 | status_info("dev_report_fds: %i -> listener (%s)", fd, |
| 2252 | backtrace_symname(tmpctx, l->init)); |
| 2253 | } else { |
| 2254 | status_info("dev_report_fds: %i -> IN=%s:%s+%s(%s), OUT=%s:%s+%s(%s)", |
| 2255 | fd, |
| 2256 | io_plan_status_str(c->plan[IO_IN].status), |
| 2257 | backtrace_symname(tmpctx, c->plan[IO_IN].io), |
no test coverage detected