zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/3] Fix the mktemp() warning, in debug builds only.
@ 2019-12-17  7:44 Daniel Shahaf
  2019-12-17  7:44 ` [PATCH 2/3] Make 'make -s' print nothing when it does nothing Daniel Shahaf
  2019-12-17  7:44 ` [PATCH 3/3] internal: Document forklevel, locallevel, and exit_pending Daniel Shahaf
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Shahaf @ 2019-12-17  7:44 UTC (permalink / raw)
  To: zsh-workers

On Linux, linking to mktemp() generates the following warning:
.
    utils.o: In function `gettempname':
    ./Src/utils.c:2229: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'

The warning cannot be disabled.

Work around that by using mkstemp() instead, and massage its output so
it behaves like mktemp().  See the new comment for further details.
---
The purpose of this patch is to eliminate the spurious warning from the
edit-compile-test cycle.

Cheers,

Daniel


 Src/utils.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/Src/utils.c b/Src/utils.c
index 1d916e71f..086c0dfcb 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2201,6 +2201,31 @@ gettempname(const char *prefix, int use_heap)
 #ifdef HAVE__MKTEMP
     /* Zsh uses mktemp() safely, so silence the warnings */
     ret = (char *) _mktemp(ret);
+#elif HAVE_MKSTEMP && defined(DEBUG)
+    {
+	/* zsh uses mktemp() safely (all callers use O_EXCL, and one of them
+	 * uses mkfifo()/mknod(), as opposed to open()), but some compilers
+	 * warn about this anyway and give no way to disable the warning. To
+	 * appease them, use mkstemp() and then close the fd and unlink the
+	 * filename, to match callers' expectations.
+	 *
+	 * But do this in debug builds only, because we don't want to suffer
+	 * x3 the disk access (touch, unlink, touch again) in production.
+	 */
+	int fd;
+	errno = 0;
+	fd = mkstemp(ret);
+	if (fd < 0)
+	    zwarn("can't get a temporary filename: %e", errno);
+	else {
+	    close(fd);
+	    ret = ztrdup(ret);
+
+	    errno = 0;
+	    if (unlink(ret) < 0)
+		zwarn("unlinking a temporary filename failed: %e", errno);
+	}
+    }
 #else
     ret = (char *) mktemp(ret);
 #endif

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

* [PATCH 2/3] Make 'make -s' print nothing when it does nothing.
  2019-12-17  7:44 [PATCH 1/3] Fix the mktemp() warning, in debug builds only Daniel Shahaf
@ 2019-12-17  7:44 ` Daniel Shahaf
  2019-12-17  7:44 ` [PATCH 3/3] internal: Document forklevel, locallevel, and exit_pending Daniel Shahaf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2019-12-17  7:44 UTC (permalink / raw)
  To: zsh-workers

---
I omitted the line entirely since there's no easy way to omit it only
for 'make -s'.  The syntax of $(MAKEFLAGS) can take one of two different
forms (it's actually standardized this way ☹) and it didn't seem worth
the trouble to support both.

Cheers,

Daniel


 Src/Makefile.in | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Src/Makefile.in b/Src/Makefile.in
index 0577554f8..0fdbb73d2 100644
--- a/Src/Makefile.in
+++ b/Src/Makefile.in
@@ -94,7 +94,6 @@ zsh.res.o: $(sdir)/zsh.rc $(sdir)/zsh.ico
 stamp-modobjs: modobjs
 	@if cmp -s stamp-modobjs.tmp stamp-modobjs; then \
 	    rm -f stamp-modobjs.tmp; \
-	    echo "\`stamp-modobjs' is up to date."; \
 	else \
 	    mv -f stamp-modobjs.tmp stamp-modobjs; \
 	    echo "Updated \`stamp-modobjs'."; \

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

* [PATCH 3/3] internal: Document forklevel, locallevel, and exit_pending.
  2019-12-17  7:44 [PATCH 1/3] Fix the mktemp() warning, in debug builds only Daniel Shahaf
  2019-12-17  7:44 ` [PATCH 2/3] Make 'make -s' print nothing when it does nothing Daniel Shahaf
@ 2019-12-17  7:44 ` Daniel Shahaf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2019-12-17  7:44 UTC (permalink / raw)
  To: zsh-workers

---
 Src/builtin.c | 6 +++++-
 Src/exec.c    | 4 ++++
 Src/params.c  | 6 +++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index 5fe5ea6d1..0ecabf854 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5601,7 +5601,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
     return 0;
 }
 
-/* Flag that we should exit the shell as soon as all functions return. */
+/* Boolean flag that we should exit the shell as soon as all functions return.
+ *
+ * Set by the 'exit' builtin.
+ */
+
 /**/
 mod_export int
 exit_pending;
diff --git a/Src/exec.c b/Src/exec.c
index 0d9d7de7c..50027654a 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -971,6 +971,10 @@ hashcmd(char *arg0, char **pp)
     return cn;
 }
 
+/* The value that 'locallevel' had when we forked. When we get back to this
+ * level, the current process (which is a subshell) will terminate.
+ */
+
 /**/
 int
 forklevel;
diff --git a/Src/params.c b/Src/params.c
index da7a6b4c5..5eaafe34e 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -44,7 +44,11 @@
 #endif
 #endif
 
-/* what level of localness we are at */
+/* What level of localness we are at.
+ *
+ * Hand-wavingly, this is incremented at every function call and decremented
+ * at every function return.  See startparamscope().
+ */
  
 /**/
 mod_export int locallevel;

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

end of thread, other threads:[~2019-12-17  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17  7:44 [PATCH 1/3] Fix the mktemp() warning, in debug builds only Daniel Shahaf
2019-12-17  7:44 ` [PATCH 2/3] Make 'make -s' print nothing when it does nothing Daniel Shahaf
2019-12-17  7:44 ` [PATCH 3/3] internal: Document forklevel, locallevel, and exit_pending Daniel Shahaf

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).