Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Handling of tempfile open failure
- X-seq: zsh-workers 39470
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Handling of tempfile open failure
- Date: Tue, 27 Sep 2016 23:50:50 -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=V5lBfWqdw+TyasLBWlPyQxxzXSH0j3b5LkS558f9Efc=; b=fAQdGF9NeptH0raOwlDmF2d1l6v6LuKbaJS6mI4s53Esw+L33j6SXVVYmppc1ObADe TmgE6v2nMN2+rwxSobKvzyMO8rPbjsKDgo7iTVY9WaSlvI97EmtCfCz0Ej3U31W3DPOg 3Af5CFXJt08iVJgK2xKIHEmylgrquZPjzqiJeBfXr87J62xNc/BDxFaqpIz5zHaSKv/2 3g7QPRViT3VXBTnIRyKxDPVr85uakRYAUDgQyEedm7xOZArz7l4jmahdmVjc5kU6hYMK LFoGbqk7BnoTbrfO/BiZETKeN6IhO9Dt4YvgtWz1Ctl85W6toL24DObZEAMeAQaZcXPP KTqQ==
- 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
Separating this from the thread about TMPSUFFIX.
Manufacturing a conflict by stepping through the debugger:
torch% print -l X =(:) X
zsh: process substitution failed: file exists
torch% print $?
1
diff --git a/Src/exec.c b/Src/exec.c
index c27c41c..bdbad76 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4332,11 +4332,17 @@ getoutputfile(char *cmd, char **eptr)
untokenize(s);
}
- addfilelist(nam, 0);
+ if (!s) /* Unclear why we need to do this before open() */
+ child_block(); /* but it has been so for a long time: leave it */
- 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) {
+ zerr("process substitution failed: %e", errno);
+ free(nam);
+ if (!s)
+ child_unblock();
+ return NULL;
+ }
+ addfilelist(nam, 0);
if (s) {
/* optimised here-string */
@@ -4347,7 +4353,7 @@ getoutputfile(char *cmd, char **eptr)
return nam;
}
- if (fd < 0 || (cmdoutpid = pid = zfork(NULL)) == -1) {
+ if ((cmdoutpid = pid = zfork(NULL)) == -1) {
/* fork or open error */
child_unblock();
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