Skip to content

Commit

Permalink
connectd: Ignore sodium fd for Mac tests
Browse files Browse the repository at this point in the history
On Mac most tests report BROKEN because sodium creating an untracked fd pointing to /dev/random. dev_report_fd’s finds it at tear down and reports a BROKEN message.

We allow a single “char special” fd without reporting it as broken improving QOL for Mac developers.

While we’re here we added the fd mode to the log to help with future rogue fd issues.

ChangeLog-None
  • Loading branch information
ddustin authored and rustyrussell committed Oct 19, 2023
1 parent 87f4907 commit e1ac241
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <netinet/in.h>
#include <signal.h>
#include <sodium.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
Expand Down Expand Up @@ -1957,12 +1958,36 @@ static const char *try_tal_name(const tal_t *ctx, const void *p)
return tal_fmt(ctx, "%p", p);
}

static char *fd_mode_str(int fd)
{
struct stat finfo;
if (0 != fstat(fd, &finfo))
return "invalid fd";
if (S_ISBLK(finfo.st_mode))
return "block special";
if (S_ISCHR(finfo.st_mode))
return "char special";
if (S_ISDIR(finfo.st_mode))
return "directory";
if (S_ISFIFO(finfo.st_mode))
return "fifo or socket";
if (S_ISREG(finfo.st_mode))
return "regular file";
if (S_ISLNK(finfo.st_mode))
return "symbolic link";
if (S_ISSOCK(finfo.st_mode))
return "socket";
return "unknown";
}

static void dev_report_fds(struct daemon *daemon, const u8 *msg)
{
bool found_chr_fd = false;
for (int fd = 3; fd < 4096; fd++) {
bool listener;
const struct io_conn *c;
const struct io_listener *l;
struct stat finfo;
if (!isatty(fd) && errno == EBADF)
continue;
if (fd == HSM_FD) {
Expand All @@ -1983,7 +2008,16 @@ static void dev_report_fds(struct daemon *daemon, const u8 *msg)
}
c = io_have_fd(fd, &listener);
if (!c) {
status_broken("dev_report_fds: %i open but unowned?", fd);
/* We consider a single CHR as expected */
if (!found_chr_fd && !fstat(fd, &finfo)
&& S_ISCHR(finfo.st_mode)) {
found_chr_fd = true;
status_info("dev_report_fds: %i -> char fd", fd);
continue;
}

status_broken("dev_report_fds: %i open but unowned? fd"
" mode: %s", fd, fd_mode_str(fd));
continue;
} else if (listener) {
l = (void *)c;
Expand Down

0 comments on commit e1ac241

Please sign in to comment.