diff options
Diffstat (limited to 'regress')
-rw-r--r-- | regress/forwarding.sh | 3 | ||||
-rw-r--r-- | regress/mkdtemp.c | 59 | ||||
-rw-r--r-- | regress/multiplex.sh | 3 | ||||
-rw-r--r-- | regress/test-exec.sh | 12 |
4 files changed, 75 insertions, 2 deletions
diff --git a/regress/forwarding.sh b/regress/forwarding.sh index 39fccba73..7d0fae114 100644 --- a/regress/forwarding.sh +++ b/regress/forwarding.sh @@ -10,7 +10,8 @@ start_sshd base=33 last=$PORT fwd="" -CTL=/tmp/openssh.regress.ctl-sock.$$ +make_tmpdir +CTL=${SSH_REGRESS_TMP}/ctl-sock for j in 0 1 2; do for i in 0 1 2; do diff --git a/regress/mkdtemp.c b/regress/mkdtemp.c new file mode 100644 index 000000000..8c7d2e219 --- /dev/null +++ b/regress/mkdtemp.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 Colin Watson <cjwatson@debian.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* Roughly equivalent to "mktemp -d -t TEMPLATE", but portable. */ + +#include "includes.h" + +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> + +#include "log.h" + +static void +usage(void) +{ + fprintf(stderr, "mkdtemp template\n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + const char *base; + const char *tmpdir; + char template[PATH_MAX]; + int r; + char *dir; + + if (argc != 2) + usage(); + base = argv[1]; + + if ((tmpdir = getenv("TMPDIR")) == NULL) + tmpdir = "/tmp"; + r = snprintf(template, sizeof(template), "%s/%s", tmpdir, base); + if (r < 0 || (size_t)r >= sizeof(template)) + fatal("template string too long"); + dir = mkdtemp(template); + if (dir == NULL) { + perror("mkdtemp"); + exit(1); + } + puts(dir); + return 0; +} diff --git a/regress/multiplex.sh b/regress/multiplex.sh index 078a53a88..a6fad8eb8 100644 --- a/regress/multiplex.sh +++ b/regress/multiplex.sh @@ -1,7 +1,8 @@ # $OpenBSD: multiplex.sh,v 1.28 2017/04/30 23:34:55 djm Exp $ # Placed in the Public Domain. -CTL=/tmp/openssh.regress.ctl-sock.$$ +make_tmpdir +CTL=${SSH_REGRESS_TMP}/ctl-sock tid="connection multiplexing" diff --git a/regress/test-exec.sh b/regress/test-exec.sh index f09fe0ec4..f0e3dabfe 100644 --- a/regress/test-exec.sh +++ b/regress/test-exec.sh @@ -76,6 +76,9 @@ SFTP=sftp SFTPSERVER=/usr/libexec/openssh/sftp-server SCP=scp +# Set by make_tmpdir() on demand (below). +SSH_REGRESS_TMP= + # Interop testing PLINK=plink PUTTYGEN=puttygen @@ -322,6 +325,12 @@ stop_sshd () fi } +make_tmpdir () +{ + SSH_REGRESS_TMP="$($OBJ/mkdtemp openssh-regress-XXXXXXXXXXXX)" || \ + fatal "failed to create temporary directory" +} + # helper cleanup () { @@ -332,6 +341,9 @@ cleanup () kill $SSH_PID fi fi + if [ "x$SSH_REGRESS_TMP" != "x" ]; then + rm -rf "$SSH_REGRESS_TMP" + fi stop_sshd } |