Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: [for consideration] TMPSUFFIX
- X-seq: zsh-workers 39439
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: [for consideration] TMPSUFFIX
- Date: Sun, 25 Sep 2016 15:51:12 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:to:subject:mime-version; bh=lvL7awiRnlxmrO4Qp4BvuzlbkRzQD68N8Hdr+RZ89gk=; b=KF3I7kart3I+YjKS0toOS+09UcHxtobtMvEVBvCqlxvcJxoxhFtK6ys5ULEbkrmYOz G/QAbydk+cRjtl5mpPaIhtHuCdEaordZ4L+gN5GDZo7Nmkf8BNXCrQRF/wiDGTNuw09k hWNUyZb+vjGPMUt33d96RCCqg498Y1B8ISjkizzb5vIBS5CymnsfY2Zo7uXH2qvhkwjo m81KBjEgsavySLHM7z+mQHVSsgOOzPuswWMXkp/eY8F030vWY8LQTdBugvbClZe2dOJO Qwf4XI4QJF6Eir+y78cgVjX+LgO5gnFbPMpe82hrcOTiPSGmvqp/B7iveFew6VmWAbcJ igAQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author