Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] compinit forks less
- X-seq: zsh-workers 54433
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Charles Blake <charlechaud@xxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] compinit forks less
- Date: Thu, 30 Apr 2026 15:37:01 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=L1dAnZKHY8R4BE8yQ33lTlwH1rKDslF01cxtkjK4kWI=; fh=lNwkaVSUgCqMTMeZdgLy2I+b6F4zkEqzT0VbYWrffUU=; b=VI/5BaBPz33z9V+Bhr1Zmw5hf6O0dOBR2o1/JoWvpZP2UMW1rT2NLhTBMatyOtP0pO hTm/7MLEuxRqQdqY76RMsXvjc/cpVHnzNubvLohpquIX2awmjzlqy5H5u85bXpM2AXKD vV96F1gjmvP5a7GXNKz6+GhlBe66Lfob6YaL6FIAtlXvvm/TzJ8HRfcnvmznm+3gbsKg lvhRWLm0H6WUmSOBQdzNSIEXnMJ3rxrOP6L2o8pj6DPBGoccXig1GxpdClT0m4WKfLve Ib4mIEvsJtk9/4Ofl5UWcra+SA4Wj3VOrnDZRH5EFTpjMzo15vh8meSZM3auQJ19gFyU XoFQ==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1777588633; cv=none; d=google.com; s=arc-20240605; b=JJHxlSmFL1Jm5qzAQkG6lXLJb/QWAKbw07vldGCci8y3Iwa31wRTI8BKPKNs4VB7Pu P8gDlkWBOzwNROkLYi2sVYJYa8mTkC9cs8DFVcW7fhThGfUA5npRyINS/9r1DOaFdTom mQuxlFSdQxOuLEDJTYggTzmLlNiZEdrIjWzwH2Dst7g4BOSQqBqDa/2gHVrHd1T5TR4P 4hjL2dEkNrnAGeC+cMlveSsFrL5Ll3geaRhg+m6LA8+U8fr1Jkd6tiPCV8f7oVDBEXgy nvGlnpAda5csAwwr8okKmPJ0Lb7vX2PbaQ+Qs8dcgMOyJqvc5mHnukjUa0Ol5go/bxJG pmUw==
- Archived-at: <https://zsh.org/workers/54433>
- In-reply-to: <CAKiz1a9_6YTDSXX+Pkfqyn+hkgLMB-M4U3i07HnYkDj_wo1gEQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKiz1a_X09-MpXhOwtD2H4tykBi9HTkLq52Xirc25WHXsmjn4w@mail.gmail.com> <da9600c7-48e6-44b7-91ba-57265e4e76b8@app.fastmail.com> <CAKiz1a9_6YTDSXX+Pkfqyn+hkgLMB-M4U3i07HnYkDj_wo1gEQ@mail.gmail.com>
It bears mention that while my first here-string idea uses two temp
files, this new still uses one temp file, and a racy one at that (not
that I see any real attack by messing up bindkey introspection).
I'm not sure where you're coming up with "racy". The same mechanism is used for this file as is used for ="" substitutions. If there's a problem here, there's a problem there.
I imagine this must have been discussed long ago when ${ } got in
This is essentially the same way bash also implements ${ ... }. There's no portable deadlock-free way to have a process connect to itself with a pipe. This was discussed when the feature was developed.
All that said, there's a different way to go about it, see attached. Question, should rplyoutfd here be entered into fdtable somehow? It is not for here-strings.
diff --git a/Src/subst.c b/Src/subst.c
index 56c1ad6dd..659074568 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1872,6 +1872,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
*/
char *rplyvar = NULL; /* Indicates ${|...;} or ${{var} ...;} */
char *rplytmp = NULL; /* Indicates ${ ... ;} */
+ int rplyoutfd;
*s++ = '\0';
/*
@@ -1990,14 +1991,15 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
* Then fall through to the regular parameter handling
* to manage word splitting, expansion flags, etc.
*/
- char *outfmt = ">| %s {\n%s\n;}"; /* 13 */
- if ((rplytmp = gettempname(NULL, 1))) {
- /* Prevent shenanigans with $TMPPREFIX */
- char *tmpfile = quotestring(rplytmp, QT_BACKSLASH);
- char *dummy = zhalloc(strlen(cmdarg) +
- strlen(tmpfile) +
- 13);
- sprintf(dummy, outfmt, tmpfile, cmdarg);
+ char *outfmt = ">&%d {\n%s\n;}"; /* 13 */
+ if ((rplyoutfd = gettempfile(NULL, 1, &rplytmp))) {
+ char *dummy = zhalloc(strlen(cmdarg) + 20);
+#if defined(F_SETFD) && defined(FD_CLOEXEC)
+ /* If cmdarg execs a program, close this FD. */
+ fcntl(rplyoutfd, F_SETFD, FD_CLOEXEC);
+#endif
+
+ sprintf(dummy, outfmt, rplyoutfd, cmdarg);
cmdarg = dummy;
} else {
/* TMPPREFIX not writable? */
@@ -2074,8 +2076,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
unqueue_signals();
}
- if (rplytmp)
+ if (rplytmp) {
+ zclose(rplyoutfd);
unlink(rplytmp);
+ }
if (rplyvar) {
if (inchar != Inbrace) {
if ((val = dupstring(getsparam(rplyvar))))
Messages sorted by:
Reverse Date,
Date,
Thread,
Author