From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16281 invoked by alias); 25 Sep 2016 23:51:44 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39439 Received: (qmail 15194 invoked from network); 25 Sep 2016 23:51:44 -0000 X-Qmail-Scanner-Diagnostics: from mail-pa0-f54.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.220.54):SA:0(0.0/5.0):. Processed in 0.627727 secs); 25 Sep 2016 23:51:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:to:subject:mime-version; bh=lvL7awiRnlxmrO4Qp4BvuzlbkRzQD68N8Hdr+RZ89gk=; b=ZRH/K03OvuCrM69A5bkA6ueQ2/zvSeFAs0GSXtFsOBCovHc7A0Qyen5UKL3Xo6bfyG g03+AmoYA0gF/sKP3C+npDJCsATb1aIlSp5RclasMEdp60mjZbhO+RKqXysorx+wZUIy A151fL7+lRge9leuDYulUT36Fy7zSqbxxShq2o1qMkRPqeaM7n6W6oMQEJPymqjGAC5f qMZbmzweutvwifwsexgqKAI+n9uxlWy5g/25Td+vv8XNiMSOB2/lt9sTAAd9xofY95cy aqECK6f14h08vHDTpjhVKS5JLXrk5gR6aArWezxB8gHGfSLsp9wg0vXtgiBIQGFLpvCr /K7A== X-Gm-Message-State: AE9vXwMIjiH60e2+MB8nXDMXBHSqf29jLQ9bJmH3QzC27DWZQvVq0tm7Q5I3hL5Xu7K5yw== X-Received: by 10.66.76.65 with SMTP id i1mr32886140paw.51.1474843862082; Sun, 25 Sep 2016 15:51:02 -0700 (PDT) From: Bart Schaefer Message-Id: <160925155112.ZM23899@torch.brasslantern.com> Date: Sun, 25 Sep 2016 15:51:12 -0700 X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: PATCH: [for consideration] TMPSUFFIX MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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) (tt(WATCH) ))( 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; }