Skip to content

Commit

Permalink
Use KJ_SYSCALL_FD.
Browse files Browse the repository at this point in the history
Turns out this is the only file in this repo that uses KJ_SYSCALL at all!
  • Loading branch information
kentonv committed Dec 24, 2024
1 parent 3ae2509 commit baa362d
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/workerd/server/workerd.c++
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ class FileWatcher {
kj::HashMap<int, kj::HashSet<kj::String>> filesWatched;

static kj::AutoCloseFd makeInotify() {
int fd;
KJ_SYSCALL(fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
return kj::AutoCloseFd(fd);
return KJ_SYSCALL_FD(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
}
};

Expand Down Expand Up @@ -233,17 +231,13 @@ class FileWatcher {
KJ_IF_SOME(fd, f.getFd()) {
// We need to duplicate the FD because the original will probably be closed later and
// closing the FD unregisters it from kqueue.
int duped;
KJ_SYSCALL(duped = dup(fd));
watchFd(kj::AutoCloseFd(duped));
watchFd(KJ_SYSCALL_FD(dup(fd)));
return;
}
}

// No existing file, open from disk.
int fd;
KJ_SYSCALL(fd = open(path.toNativeString(true).cStr(), O_RDONLY));
watchFd(kj::AutoCloseFd(fd));
watchFd(KJ_SYSCALL_FD(open(path.toNativeString(true).cStr(), O_RDONLY)));
}

kj::Promise<void> onChange() {
Expand Down Expand Up @@ -275,9 +269,7 @@ class FileWatcher {
kj::Vector<kj::AutoCloseFd> filesWatched;

static kj::AutoCloseFd makeKqueue() {
int fd_;
KJ_SYSCALL(fd_ = kqueue());
auto fd = kj::AutoCloseFd(fd_);
auto fd = KJ_SYSCALL_FD(kqueue());
KJ_SYSCALL(fcntl(fd, F_SETFD, FD_CLOEXEC));
return kj::mv(fd);
}
Expand Down

0 comments on commit baa362d

Please sign in to comment.