| 2246 | } |
| 2247 | |
| 2248 | static void dev_report_fds(struct daemon *daemon, const u8 *msg) |
| 2249 | { |
| 2250 | bool found_chr_fd = false; |
| 2251 | |
| 2252 | /* Not only would this get upset with all the /dev/null, |
| 2253 | * our symbol code fails if it can't open files */ |
| 2254 | if (daemon->dev_exhausted_fds) |
| 2255 | return; |
| 2256 | |
| 2257 | for (int fd = 3; fd < 4096; fd++) { |
| 2258 | bool listener; |
| 2259 | const struct io_conn *c; |
| 2260 | const struct io_listener *l; |
| 2261 | struct stat finfo; |
| 2262 | if (!isatty(fd) && errno == EBADF) |
| 2263 | continue; |
| 2264 | if (fd == HSM_FD) { |
| 2265 | status_info("dev_report_fds: %i -> hsm fd", fd); |
| 2266 | continue; |
| 2267 | } |
| 2268 | if (fd == GOSSIPCTL_FD) { |
| 2269 | status_info("dev_report_fds: %i -> gossipd fd", fd); |
| 2270 | continue; |
| 2271 | } |
| 2272 | if (fd == daemon->dev_disconnect_fd) { |
| 2273 | status_info("dev_report_fds: %i -> dev_disconnect_fd", fd); |
| 2274 | continue; |
| 2275 | } |
| 2276 | if (daemon->gossmap_raw && fd == gossmap_fd(daemon->gossmap_raw)) { |
| 2277 | status_info("dev_report_fds: %i -> gossip_store", fd); |
| 2278 | continue; |
| 2279 | } |
| 2280 | if (fd == tor_service_fd) { |
| 2281 | status_info("dev_report_fds: %i -> tor service fd", fd); |
| 2282 | continue; |
| 2283 | } |
| 2284 | c = io_have_fd(fd, &listener); |
| 2285 | if (!c) { |
| 2286 | /* We consider a single CHR as expected */ |
| 2287 | if (!found_chr_fd && !fstat(fd, &finfo) |
| 2288 | && S_ISCHR(finfo.st_mode)) { |
| 2289 | found_chr_fd = true; |
| 2290 | status_info("dev_report_fds: %i -> char fd", fd); |
| 2291 | continue; |
| 2292 | } |
| 2293 | |
| 2294 | status_broken("dev_report_fds: %i open but unowned? fd" |
| 2295 | " mode: %s", fd, fd_mode_str(fd)); |
| 2296 | continue; |
| 2297 | } else if (listener) { |
| 2298 | l = (void *)c; |
| 2299 | status_info("dev_report_fds: %i -> listener (%s)", fd, |
| 2300 | backtrace_symname(tmpctx, l->init)); |
| 2301 | } else { |
| 2302 | status_info("dev_report_fds: %i -> IN=%s:%s+%s(%s), OUT=%s:%s+%s(%s)", |
| 2303 | fd, |
| 2304 | io_plan_status_str(c->plan[IO_IN].status), |
| 2305 | backtrace_symname(tmpctx, c->plan[IO_IN].io), |
no test coverage detected