about summary refs log tree commit diff
path: root/Src/jobs.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2013-07-17 21:33:16 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2013-07-17 21:33:16 +0100
commit3c5732223f65309c6820f15b8519f674bd21185b (patch)
treede612bd280082af425beb16695c1cf39a32933cd /Src/jobs.c
parent29256a7c9656e20fc44ebeb257230ba41c23e74e (diff)
downloadzsh-3c5732223f65309c6820f15b8519f674bd21185b.tar.gz
zsh-3c5732223f65309c6820f15b8519f674bd21185b.tar.xz
zsh-3c5732223f65309c6820f15b8519f674bd21185b.zip
31528: use job table to record file descriptors associated with process subst
Diffstat (limited to 'Src/jobs.c')
-rw-r--r--Src/jobs.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/Src/jobs.c b/Src/jobs.c
index 0dbb10b4f..a1955bb0f 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1113,16 +1113,48 @@ printjob(Job jn, int lng, int synch)
     return doneprint;
 }
 
+/* Add a file to be deleted or fd to be closed to the current job */
+
+/**/
+void
+addfilelist(const char *name, int fd)
+{
+    Jobfile jf = (Jobfile)zalloc(sizeof(struct jobfile));
+    LinkList ll = jobtab[thisjob].filelist;
+
+    if (!ll)
+	ll = jobtab[thisjob].filelist = znewlinklist();
+    if (name)
+    {
+	jf->u.name = ztrdup(name);
+	jf->is_fd = 0;
+    }
+    else
+    {
+	jf->u.fd = fd;
+	jf->is_fd = 1;
+    }
+    zaddlinknode(ll, jf);
+}
+
+/* Finished with list of files for a job */
+
 /**/
 void
 deletefilelist(LinkList file_list, int disowning)
 {
-    char *s;
+    Jobfile jf;
     if (file_list) {
-	while ((s = (char *)getlinknode(file_list))) {
-	    if (!disowning)
-		unlink(s);
-	    zsfree(s);
+	while ((jf = (Jobfile)getlinknode(file_list))) {
+	    if (jf->is_fd) {
+		if (!disowning)
+		    zclose(jf->u.fd);
+	    } else {
+		if (!disowning)
+		    unlink(jf->u.name);
+		zsfree(jf->u.name);
+	    }
+	    zfree(jf, sizeof(*jf));
 	}
 	zfree(file_list, sizeof(struct linklist));
     }