xref: /freebsd/libexec/rtld-elf/tests/set_var_test.c (revision e27501388fc0dc2a29f90cb24ba8d36e9bb6631f)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2026 Alex S <iwtcex@gmail.com>
5  */
6 
7 #include <atf-c.h>
8 #include <dlfcn.h>
9 #include <fcntl.h>
10 #include <link.h>
11 #include <stdio.h>
12 
13 ATF_TC_WITHOUT_HEAD(set_var_library_path_fds);
14 ATF_TC_BODY(set_var_library_path_fds, tc)
15 {
16 	void *handle;
17 	char *pathfds;
18 	int testdir;
19 
20 	handle = dlopen("libpythagoras.so.0", RTLD_LAZY);
21 	ATF_REQUIRE(handle == NULL);
22 
23 	testdir = open(atf_tc_get_config_var(tc, "srcdir"),
24 	    O_RDONLY | O_DIRECTORY);
25 	ATF_REQUIRE(testdir >= 0);
26 
27 	ATF_REQUIRE(asprintf(&pathfds, "%d", testdir) > 0);
28 	ATF_REQUIRE(rtld_set_var("LIBRARY_PATH_FDS", pathfds) == 0);
29 
30 	handle = dlopen("libpythagoras.so.0", RTLD_LAZY);
31 	ATF_REQUIRE(handle != NULL);
32 }
33 
34 ATF_TP_ADD_TCS(tp)
35 {
36 	ATF_TP_ADD_TC(tp, set_var_library_path_fds);
37 	return atf_no_error();
38 }
39