aboutsummaryrefslogtreecommitdiff
path: root/src/connection.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-08-29 14:22:43 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-08-31 15:55:26 -0700
commitd9216488a2a743e74fc39a06f2dfb26336fafac3 (patch)
tree23e3d0ec190b33f5a071da7176843720f630731c /src/connection.lisp
parent030fa324859eb5b3e7b539c6e1dcbbb3fac1db4c (diff)
downloadconsfigurator-d9216488a2a743e74fc39a06f2dfb26336fafac3.tar.gz
MKTEMP: also fail if mktemp(1) outputs anything to stderr
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection.lisp')
-rw-r--r--src/connection.lisp39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/connection.lisp b/src/connection.lisp
index 07ffa10..c8f2dab 100644
--- a/src/connection.lisp
+++ b/src/connection.lisp
@@ -310,30 +310,33 @@ which will be cleaned up when BODY is finished."
;; just write to stderr and exit zero. So we examine the stderr, and
;; if there is any, exit nonzero ourselves.
;;
+ ;; We apply the same stderr handling to mktemp(1), exiting if we see
+ ;; anything on stderr, as a simple way to ensure that non-fatal
+ ;; errors/warnings are not captured as the path to the temporary file.
+ ;;
;; While GNU M4 mkstemp makes the temporary file at most readable and
;; writeable by its owner, POSIX doesn't require this, so set a umask.
(connection-run
connection
- #?"umask 077
-if command -v m4 >/dev/null; then
- if tmpf=\$(exec 3>&1
- if err=\$(echo 'mkstemp(${template})' | m4 2>&1 1>&3); then
- case $err in
- ?*) printf >&2 \"%s\\n\" \"$err\"; exit 1 ;;
- *) exit 0 ;;
- esac
- else
- case $err in
- ?*) printf >&2 \"%s\\n\" \"$err\" ;;
- esac
- exit 1
- fi); then
- echo $tmpf
+ #?"if tmpf=\$(umask 077; exec 3>&1
+ if err=\$(if command -v m4 >/dev/null; then
+ echo 'mkstemp(${template})' | m4 2>&1 1>&3
+ else
+ mktemp '${template}' 2>&1 1>&3
+ fi); then
+ case $err in
+ ?*) printf >&2 \"%s\\n\" \"$err\"; exit 1 ;;
+ *) exit 0 ;;
+ esac
else
- exit 1;
- fi
+ case $err in
+ ?*) printf >&2 \"%s\\n\" \"$err\" ;;
+ esac
+ exit 1
+ fi); then
+ echo $tmpf
else
- mktemp '${template}'
+ exit 1;
fi"
nil)
(let ((lines (lines out)))