diff options
author | Colin Watson <cjwatson@debian.org> | 2017-01-03 12:09:42 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2017-01-03 12:23:00 +0000 |
commit | cc50ca70e3b438577c33a85147e2a68666deaad9 (patch) | |
tree | 61580f79d8af26080488ad21d994fdec5af85a29 /regress | |
parent | d225c4fe44ad94a30a5033e58594f2bebaa674f2 (diff) |
Create mux socket for regress in temp directory
In some setups, creating the socket under OBJ may result in a path that
is too long for a Unix domain socket. Add a helper to let us portably
create a temporary directory instead.
Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=2660
Last-Update: 2017-01-03
Patch-Name: regress-mktemp.patch
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 | 11 |
4 files changed, 74 insertions, 2 deletions
diff --git a/regress/forwarding.sh b/regress/forwarding.sh index a1a4b13f2..592de7bc3 100644 --- a/regress/forwarding.sh +++ b/regress/forwarding.sh | |||
@@ -10,7 +10,8 @@ start_sshd | |||
10 | base=33 | 10 | base=33 |
11 | last=$PORT | 11 | last=$PORT |
12 | fwd="" | 12 | fwd="" |
13 | CTL=$OBJ/ctl-sock | 13 | make_tmpdir |
14 | CTL=$TMP/ctl-sock | ||
14 | 15 | ||
15 | for j in 0 1 2; do | 16 | for j in 0 1 2; do |
16 | for i in 0 1 2; do | 17 | 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 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017 Colin Watson <cjwatson@debian.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | /* Roughly equivalent to "mktemp -d -t TEMPLATE", but portable. */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | |||
21 | #include <limits.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | |||
25 | #include "log.h" | ||
26 | |||
27 | static void | ||
28 | usage(void) | ||
29 | { | ||
30 | fprintf(stderr, "mkdtemp template\n"); | ||
31 | exit(1); | ||
32 | } | ||
33 | |||
34 | int | ||
35 | main(int argc, char **argv) | ||
36 | { | ||
37 | const char *base; | ||
38 | const char *tmpdir; | ||
39 | char template[PATH_MAX]; | ||
40 | int r; | ||
41 | char *dir; | ||
42 | |||
43 | if (argc != 2) | ||
44 | usage(); | ||
45 | base = argv[1]; | ||
46 | |||
47 | if ((tmpdir = getenv("TMPDIR")) == NULL) | ||
48 | tmpdir = "/tmp"; | ||
49 | r = snprintf(template, sizeof(template), "%s/%s", tmpdir, base); | ||
50 | if (r < 0 || (size_t)r >= sizeof(template)) | ||
51 | fatal("template string too long"); | ||
52 | dir = mkdtemp(template); | ||
53 | if (dir == NULL) { | ||
54 | perror("mkdtemp"); | ||
55 | exit(1); | ||
56 | } | ||
57 | puts(dir); | ||
58 | return 0; | ||
59 | } | ||
diff --git a/regress/multiplex.sh b/regress/multiplex.sh index acb9234d9..0ac4065e7 100644 --- a/regress/multiplex.sh +++ b/regress/multiplex.sh | |||
@@ -1,7 +1,8 @@ | |||
1 | # $OpenBSD: multiplex.sh,v 1.27 2014/12/22 06:14:29 djm Exp $ | 1 | # $OpenBSD: multiplex.sh,v 1.27 2014/12/22 06:14:29 djm Exp $ |
2 | # Placed in the Public Domain. | 2 | # Placed in the Public Domain. |
3 | 3 | ||
4 | CTL=/tmp/openssh.regress.ctl-sock.$$ | 4 | make_tmpdir |
5 | CTL=$TMP/ctl-sock | ||
5 | 6 | ||
6 | tid="connection multiplexing" | 7 | tid="connection multiplexing" |
7 | 8 | ||
diff --git a/regress/test-exec.sh b/regress/test-exec.sh index bfa48803b..13a8e18f3 100644 --- a/regress/test-exec.sh +++ b/regress/test-exec.sh | |||
@@ -317,6 +317,14 @@ stop_sshd () | |||
317 | fi | 317 | fi |
318 | } | 318 | } |
319 | 319 | ||
320 | TMP= | ||
321 | |||
322 | make_tmpdir () | ||
323 | { | ||
324 | TMP="$($OBJ/mkdtemp openssh-regress-XXXXXXXXXXXX)" || \ | ||
325 | fatal "failed to create temporary directory" | ||
326 | } | ||
327 | |||
320 | # helper | 328 | # helper |
321 | cleanup () | 329 | cleanup () |
322 | { | 330 | { |
@@ -327,6 +335,9 @@ cleanup () | |||
327 | kill $SSH_PID | 335 | kill $SSH_PID |
328 | fi | 336 | fi |
329 | fi | 337 | fi |
338 | if [ "x$TMP" != "x" ]; then | ||
339 | rm -rf "$TMP" | ||
340 | fi | ||
330 | stop_sshd | 341 | stop_sshd |
331 | } | 342 | } |
332 | 343 | ||