libredirect: add test for 'bind'

This commit is contained in:
Bjørn Forsman
2026-01-21 19:20:36 +01:00
parent ee4dd307bb
commit c63e9516f8
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ else
installCheckPhase = ''
(
source "$hook/nix-support/setup-hook"
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true:/bar/baz=$(mktemp -d)" ./test
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true:/bar/baz=$(mktemp -d):/run/sock=$PWD/test.sock" ./test
)
'';
+17
View File
@@ -8,16 +8,32 @@
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#define TESTDIR "/bar/baz"
#define TESTPATH "/foo/bar/test"
#define TESTSOCK "/run/sock"
#define SUBTEST "./test sub"
extern char **environ;
void test_bind(void) {
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
assert(fd != -1);
struct sockaddr_un addr = {
.sun_family = AF_UNIX,
.sun_path = TESTSOCK,
};
unlink(TESTSOCK);
int ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
assert(ret == 0);
close(fd);
}
void test_spawn(void) {
pid_t pid;
int ret;
@@ -160,6 +176,7 @@ int main(int argc, char *argv[])
assert(mktemp(buf) == buf);
assert_mktemp_path(TESTDIR "/temp", "", buf);
test_bind();
test_spawn();
test_system();
test_stat_with_null_path();