Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-07-11 02:57:04 +0300
committerAnna Henningsen <anna@addaleax.net>2020-07-14 16:07:14 +0300
commitb58c06d92c3865b41a50171c2692e36c0b487420 (patch)
treefc9d4fa7f04df3711259f6dc52859142b2f1412b /src/env.cc
parent4cac54362a146ee05f640ea68f810daa90a10406 (diff)
src: add option to track unmanaged file descriptors
Add the ability to track “raw” file descriptors, i.e. integers returned by `fs.open()`, and close them on `Environment` shutdown, to match the behavior for all other resource types (which are also closed on shutdown). PR-URL: https://github.com/nodejs/node/pull/34303 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc
index 1ab9206ce48..bcaa50bd012 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -619,6 +619,12 @@ void Environment::RunCleanup() {
}
CleanupHandles();
}
+
+ for (const int fd : unmanaged_fds_) {
+ uv_fs_t close_req;
+ uv_fs_close(nullptr, &close_req, fd, nullptr);
+ uv_fs_req_cleanup(&close_req);
+ }
}
void Environment::RunAtExitCallbacks() {
@@ -981,6 +987,24 @@ Environment* Environment::worker_parent_env() const {
return worker_context()->env();
}
+void Environment::AddUnmanagedFd(int fd) {
+ if (!tracks_unmanaged_fds()) return;
+ auto result = unmanaged_fds_.insert(fd);
+ if (!result.second) {
+ ProcessEmitWarning(
+ this, "File descriptor %d opened in unmanaged mode twice", fd);
+ }
+}
+
+void Environment::RemoveUnmanagedFd(int fd) {
+ if (!tracks_unmanaged_fds()) return;
+ size_t removed_count = unmanaged_fds_.erase(fd);
+ if (removed_count == 0) {
+ ProcessEmitWarning(
+ this, "File descriptor %d closed but not opened in unmanaged mode", fd);
+ }
+}
+
void Environment::BuildEmbedderGraph(Isolate* isolate,
EmbedderGraph* graph,
void* data) {