vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 55b6c7decf0de6349ea907141f8975ad5c284e09 parent 6376fc6bec23de01d361c7f0af317c28a0cb5eb1 Author: Evan Gates <evan.gates@gmail.com> Date: Mon, 18 Sep 2023 20:38:35 -0600 vis-single: respect TMPDIR The temporary directory for vis-single was hard coded to /tmp. If /tmp happens to be mounted noexec then vis fails as it cannot run anything placed inside the temporary directory. If the TMPDIR environment variable is set, respect it for vis-single. Diffstat:
| M | vis-single.c | | | 16 | +++++++++++++--- |
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/vis-single.c b/vis-single.c @@ -19,8 +19,12 @@ #include "vis-single-payload.inc" +#ifndef VIS_TMP_DIR +#define VIS_TMP_DIR "/tmp" +#endif + #ifndef VIS_TMP -#define VIS_TMP "/tmp/.vis-single-XXXXXX" +#define VIS_TMP ".vis-single-XXXXXX" #endif #ifndef VIS_TERMINFO @@ -94,8 +98,14 @@ static int unlink_cb(const char *path, const struct stat *sb, int typeflag, stru int main(int argc, char **argv) { int rc = EXIT_FAILURE; - char exe[256], path[PATH_MAX]; - char tmp_dirname[] = VIS_TMP; + char exe[256], path[PATH_MAX], tmp_dirname[PATH_MAX]; + + char *tmpdir = getenv("TMPDIR"); + if (snprintf(tmp_dirname, sizeof(tmp_dirname), "%s/%s", + tmpdir ? tmpdir : VIS_TMP_DIR, VIS_TMP) < 0) { + perror("snprintf"); + return rc; + } if (!mkdtemp(tmp_dirname)) { perror("mkdtemp");