diff options
author | Alan Somers <asomers@gmail.com> | 2019-05-15 14:35:57 -0600 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2019-05-15 21:35:57 +0100 |
commit | 1f842c996e46788115d6b5ca142fad949712c8e9 (patch) | |
tree | 2a070544cd76fad641913c2b9a489712fc99e012 /test | |
parent | 7a5e1a9a9a61416c759ce02a48e600814fd13711 (diff) | |
download | fuse-1f842c996e46788115d6b5ca142fad949712c8e9.tar.gz |
passthrough: fix unix-domain sockets on FreeBSD (#413)
FreeBSD doesn't allow creating sockets using mknod(2). Instead, one has to use socket(2)
and bind(2). Add appropriate logic to the examples and add a test case.
Diffstat (limited to 'test')
-rwxr-xr-x | test/test_examples.py | 31 | ||||
-rw-r--r-- | test/test_syscalls.c | 53 |
2 files changed, 76 insertions, 8 deletions
diff --git a/test/test_examples.py b/test/test_examples.py index 3aabd19..d0da69d 100755 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -8,10 +8,12 @@ if __name__ == '__main__': import subprocess import os import sys +import py import pytest import stat import shutil import filecmp +import tempfile import time import errno import sys @@ -56,6 +58,20 @@ def invoke_mount_fuse_drop_privileges(mnt_dir, name, options): return invoke_mount_fuse(mnt_dir, name, options + ('drop_privileges',)) +class raii_tmpdir: + def __init__(self): + self.d = tempfile.mkdtemp() + + def __str__(self): + return str(self.d) + + def mkdir(self, path): + return py.path.local(str(self.d)).mkdir(path) + +@pytest.fixture +def short_tmpdir(): + return raii_tmpdir() + @pytest.mark.parametrize("cmdline_builder", (invoke_directly, invoke_mount_fuse, invoke_mount_fuse_drop_privileges)) @pytest.mark.parametrize("options", powerset(options)) @@ -84,8 +100,7 @@ def test_hello(tmpdir, name, options, cmdline_builder): @pytest.mark.parametrize("writeback", (False, True)) @pytest.mark.parametrize("name", ('passthrough', 'passthrough_fh', 'passthrough_ll')) @pytest.mark.parametrize("debug", (False, True)) -def test_passthrough(tmpdir, name, debug, capfd, writeback): - +def test_passthrough(short_tmpdir, name, debug, capfd, writeback): # Avoid false positives from libfuse debug messages if debug: capfd.register_output(r'^ unique: [0-9]+, error: -[0-9]+ .+$', @@ -95,8 +110,8 @@ def test_passthrough(tmpdir, name, debug, capfd, writeback): capfd.register_output(r"^ \d\d \[[^\]]+ message: 'No error: 0'\]", count=0) - mnt_dir = str(tmpdir.mkdir('mnt')) - src_dir = str(tmpdir.mkdir('src')) + mnt_dir = str(short_tmpdir.mkdir('mnt')) + src_dir = str(short_tmpdir.mkdir('src')) cmdline = base_cmdline + \ [ pjoin(basename, 'example', name), @@ -145,7 +160,7 @@ def test_passthrough(tmpdir, name, debug, capfd, writeback): # When writeback caching is enabled, kernel has to open files for # reading even when userspace opens with O_WDONLY. This fails if the # filesystem process doesn't have special permission. - syscall_test_cmd.append('-52') + syscall_test_cmd.append('-53') subprocess.check_call(syscall_test_cmd) except: cleanup(mount_process, mnt_dir) @@ -154,9 +169,9 @@ def test_passthrough(tmpdir, name, debug, capfd, writeback): umount(mount_process, mnt_dir) @pytest.mark.parametrize("cache", (False, True)) -def test_passthrough_hp(tmpdir, cache): - mnt_dir = str(tmpdir.mkdir('mnt')) - src_dir = str(tmpdir.mkdir('src')) +def test_passthrough_hp(short_tmpdir, cache): + mnt_dir = str(short_tmpdir.mkdir('mnt')) + src_dir = str(short_tmpdir.mkdir('src')) cmdline = base_cmdline + \ [ pjoin(basename, 'example', 'passthrough_hp'), diff --git a/test/test_syscalls.c b/test/test_syscalls.c index a7e2bc7..1d776fd 100644 --- a/test/test_syscalls.c +++ b/test/test_syscalls.c @@ -11,8 +11,10 @@ #include <utime.h> #include <errno.h> #include <assert.h> +#include <sys/socket.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/un.h> #ifndef ALLPERMS # define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */ @@ -23,6 +25,7 @@ static char testfile[1024]; static char testfile2[1024]; static char testdir[1024]; static char testdir2[1024]; +static char testsock[1024]; static char subfile[1280]; static char testfile_r[1024]; @@ -1734,6 +1737,53 @@ static int test_mkdir(void) return 0; } +static int test_socket(void) +{ + struct sockaddr_un su; + int fd; + int res; + int err = 0; + + start_test("socket"); + if (strlen(testsock) + 1 > sizeof(su.sun_path)) { + fprintf(stderr, "Need to shorten mount point by %lu chars\n", + strlen(testsock) + 1 - sizeof(su.sun_path)); + return -1; + } + unlink(testsock); + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + PERROR("socket"); + return -1; + } + su.sun_family = AF_UNIX; + strncpy(su.sun_path, testsock, sizeof(su.sun_path)); + res = bind(fd, (struct sockaddr*)&su, sizeof(su)); + if (res == -1) { + PERROR("bind"); + return -1; + } + + res = check_type(testsock, S_IFSOCK); + if (res == -1) + return -1; + err += check_nlink(testsock, 1); + close(fd); + res = unlink(testsock); + if (res == -1) { + PERROR("unlink"); + return -1; + } + res = check_nonexist(testsock); + if (res == -1) + return -1; + if (err) + return -1; + + success(); + return 0; +} + #define test_create_ro_dir(flags) \ do_test_create_ro_dir(flags, #flags) @@ -1822,6 +1872,7 @@ int main(int argc, char *argv[]) sprintf(testdir, "%s/testdir", basepath); sprintf(testdir2, "%s/testdir2", basepath); sprintf(subfile, "%s/subfile", testdir2); + sprintf(testsock, "%s/testsock", basepath); sprintf(testfile_r, "%s/testfile", realpath); sprintf(testfile2_r, "%s/testfile2", realpath); @@ -1845,6 +1896,7 @@ int main(int argc, char *argv[]) err += test_rename_dir(); err += test_rename_dir_loop(); err += test_seekdir(); + err += test_socket(); err += test_utime(); err += test_truncate(0); err += test_truncate(testdatalen / 2); @@ -1903,6 +1955,7 @@ int main(int argc, char *argv[]) unlink(testfile); unlink(testfile2); + unlink(testsock); rmdir(testdir); rmdir(testdir2); |