summary refs log tree commit diff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-10-24 20:24:35 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-10-24 20:24:35 +0100
commit1f6dcf9bcdade41886e36826196e79502a9afa26 (patch)
treee9d95392ceb2b911f2973d5dbdee4d4dd9aa3706 /Src/utils.c
parent8e9a68ad14655c1949b1a04d5715a5caa8c344ee (diff)
downloadzsh-1f6dcf9bcdade41886e36826196e79502a9afa26.tar.gz
zsh-1f6dcf9bcdade41886e36826196e79502a9afa26.tar.xz
zsh-1f6dcf9bcdade41886e36826196e79502a9afa26.zip
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.
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/Src/utils.c b/Src/utils.c
index 61cbe84aa..4c69d75a1 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1892,6 +1892,32 @@ redup(int x, int y)
 }
 
 /*
+ * 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.
  * The fd should already be known to fdtable (e.g. by movefd).