zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: [for consideration] TMPSUFFIX
@ 2016-09-25 22:51 Bart Schaefer
  2016-09-26  7:25 ` Daniel Shahaf
  2016-09-28  6:09 ` PATCH: [for consideration] TMPSUFFIX Sebastian Gniazdowski
  0 siblings, 2 replies; 12+ messages in thread
From: Bart Schaefer @ 2016-09-25 22:51 UTC (permalink / raw)
  To: zsh-workers

The signal queuing in utils.c was just something I noticed while looking
for the right place to put the TMPSUFFIX code.

The addfilelist() is done whether or not we successfully opened the file,
because (a) it was that way before and (b) the name is returned either
way, so the caller might try to create the file itself.  However, it
seems a bit odd that the failure of open() is mostly ignored?


diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 03625ce..c7d84b9 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -1547,6 +1547,15 @@ A pathname prefix which the shell will use for all temporary files.
 Note that this should include an initial part for the file name as
 well as any directory names.  The default is `tt(/tmp/zsh)'.
 )
+vindex(TMPSUFFIX)
+item(tt(TMPSUFFIX))(
+A filename suffix which the shell will use for temporary files created
+by process substitutions (e.g., `tt(=LPAR()var(list)RPAR())').
+Note that the value should include a leading dot `tt(.)' if intended
+to be interpreted as a file extension.  The default is not to append
+any suffix, thus this parameter should be assigned only when needed
+and then unset again.
+)
 vindex(watch)
 vindex(WATCH)
 item(tt(watch) <S> <Z> (tt(WATCH) <S>))(
diff --git a/Src/exec.c b/Src/exec.c
index 4e89340..6b5bfd6 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4332,18 +4332,27 @@ getoutputfile(char *cmd, char **eptr)
 	    untokenize(s);
     }
 
-    addfilelist(nam, 0);
-
     if (!s)
 	child_block();
-    fd = open(nam, O_WRONLY | O_CREAT | O_EXCL | O_NOCTTY, 0600);
+
+    if ((fd = open(nam, O_WRONLY | O_CREAT | O_EXCL | O_NOCTTY, 0600)) >= 0) {
+	char *suffix = getsparam("TMPSUFFIX");
+	if (suffix && *suffix && !strstr(suffix, "/")) {
+	    suffix = dyncat(nam, unmeta(suffix));
+	    if (link(nam, suffix) == 0)
+		nam = ztrdup(suffix);
+	}
+    }
+    addfilelist(nam, 0);
 
     if (s) {
 	/* optimised here-string */
 	int len;
-	unmetafy(s, &len);
-	write_loop(fd, s, len);
-	close(fd);
+	if (fd >= 0) {
+	    unmetafy(s, &len);
+	    write_loop(fd, s, len);
+	    close(fd);
+	}
 	return nam;
     }
 
diff --git a/Src/utils.c b/Src/utils.c
index b434821..db43529 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2164,6 +2164,7 @@ gettempfile(const char *prefix, int use_heap, char **tempname)
 #if HAVE_MKSTEMP
     char *suffix = prefix ? ".XXXXXX" : "XXXXXX";
 
+    queue_signals();
     if (!prefix && !(prefix = getsparam("TMPPREFIX")))
 	prefix = DEFAULT_TMPPREFIX;
     if (use_heap)
@@ -2180,6 +2181,7 @@ gettempfile(const char *prefix, int use_heap, char **tempname)
 #else
     int failures = 0;
 
+    queue_signals();
     do {
 	if (!(fn = gettempname(prefix, use_heap))) {
 	    fd = -1;
@@ -2193,6 +2195,8 @@ gettempfile(const char *prefix, int use_heap, char **tempname)
     } while (errno == EEXIST && ++failures < 16);
 #endif
     *tempname = fn;
+
+    unqueue_signals();
     return fd;
 }
 


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-09-30 22:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-25 22:51 PATCH: [for consideration] TMPSUFFIX Bart Schaefer
2016-09-26  7:25 ` Daniel Shahaf
2016-09-26 16:19   ` Bart Schaefer
2016-09-27  7:00     ` Daniel Shahaf
2016-09-27 19:20       ` Bart Schaefer
2016-09-28 10:24         ` Daniel Shahaf
2016-09-28 18:49           ` _dispatch (was Re: PATCH: [for consideration] TMPSUFFIX) Bart Schaefer
2016-09-29  6:39             ` Daniel Shahaf
2016-09-29  7:30               ` Bart Schaefer
2016-09-30  7:03                 ` Daniel Shahaf
2016-09-30 21:53                   ` Bart Schaefer
2016-09-28  6:09 ` PATCH: [for consideration] TMPSUFFIX Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).