diff options
| author | Evan Gates <evan.gates@gmail.com> | 2023-09-18 20:38:35 -0600 |
|---|---|---|
| committer | Randy Palamar <palamar@ualberta.ca> | 2023-09-22 08:58:13 -0600 |
| commit | 1344151b195c5ff83c2337427c1fdb1162250045 (patch) | |
| tree | 44049837a590d6eb480d2becb3193eee6d0a7c7d /vis-single.c | |
| parent | 7367ea8a14c7413e5e8e2cd16edb4a05690ef782 (diff) | |
| download | vis-1344151b195c5ff83c2337427c1fdb1162250045.tar.gz vis-1344151b195c5ff83c2337427c1fdb1162250045.tar.xz | |
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 (limited to 'vis-single.c')
| -rw-r--r-- | vis-single.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/vis-single.c b/vis-single.c index 11af10f..1a1e2c3 100644 --- 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"); |
