Skip to content

Commit baa362d

Browse files
committedDec 24, 2024
Use KJ_SYSCALL_FD.
Turns out this is the only file in this repo that uses KJ_SYSCALL at all!
1 parent 3ae2509 commit baa362d

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed
 

‎src/workerd/server/workerd.c++

+4-12
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ class FileWatcher {
200200
kj::HashMap<int, kj::HashSet<kj::String>> filesWatched;
201201

202202
static kj::AutoCloseFd makeInotify() {
203-
int fd;
204-
KJ_SYSCALL(fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
205-
return kj::AutoCloseFd(fd);
203+
return KJ_SYSCALL_FD(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
206204
}
207205
};
208206

@@ -233,17 +231,13 @@ class FileWatcher {
233231
KJ_IF_SOME(fd, f.getFd()) {
234232
// We need to duplicate the FD because the original will probably be closed later and
235233
// closing the FD unregisters it from kqueue.
236-
int duped;
237-
KJ_SYSCALL(duped = dup(fd));
238-
watchFd(kj::AutoCloseFd(duped));
234+
watchFd(KJ_SYSCALL_FD(dup(fd)));
239235
return;
240236
}
241237
}
242238

243239
// No existing file, open from disk.
244-
int fd;
245-
KJ_SYSCALL(fd = open(path.toNativeString(true).cStr(), O_RDONLY));
246-
watchFd(kj::AutoCloseFd(fd));
240+
watchFd(KJ_SYSCALL_FD(open(path.toNativeString(true).cStr(), O_RDONLY)));
247241
}
248242

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

277271
static kj::AutoCloseFd makeKqueue() {
278-
int fd_;
279-
KJ_SYSCALL(fd_ = kqueue());
280-
auto fd = kj::AutoCloseFd(fd_);
272+
auto fd = KJ_SYSCALL_FD(kqueue());
281273
KJ_SYSCALL(fcntl(fd, F_SETFD, FD_CLOEXEC));
282274
return kj::mv(fd);
283275
}

0 commit comments

Comments
 (0)