From 1f6dcf9bcdade41886e36826196e79502a9afa26 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Sat, 24 Oct 2015 20:24:35 +0100
Subject: 36941: Mark file descripors in ztcp as used.
Allow such file descriptors to be either internal and closed on exec
or external and so managed explicitly by module.
---
Src/utils.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
(limited to 'Src/utils.c')
diff --git a/Src/utils.c b/Src/utils.c
index 61cbe84aa..4c69d75a1 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1891,6 +1891,32 @@ redup(int x, int y)
return ret;
}
+/*
+ * Add an fd opened ithin a module.
+ *
+ * If is_internal is FALSE, the fd can be used within the shell for
+ * normal I/O but it will not be closed automatically or by normal shell
+ * syntax; it can only be closed by the module (which should included
+ * zclose() as part of the sequence).
+ *
+ * If is_internal is TRUE the fd is treated like others created by the
+ * shell for internall use; it can be closed and will be closed by the
+ * shell if it exec's or performs an exec with a fork optimised out.
+ *.
+ * Safe if fd is -1 to indicate failure.
+ */
+/**/
+mod_export void
+addmodulefd(int fd, bool is_internal)
+{
+ if (fd >= 0) {
+ check_fd_table(fd);
+ fdtable[fd] = is_internal ? FDT_INTERNAL : FDT_MODULE;
+ }
+}
+
+/**/
+
/*
* Indicate that an fd has a file lock; if cloexec is 1 it will be closed
* on exec.
--
cgit 1.4.1