From d89ce8ce5dbbd18b2b01b0710d710d517ec16def Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 20 Oct 2020 15:02:45 -0400 Subject: [PATCH] port: tests: /proc/self/fd is Linux only, use /dev/fd on other Unices MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I2be8120c7dce3f12daaf12a190810a145afa50b6 Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- tests/unit/test_fd_tracker.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_fd_tracker.c b/tests/unit/test_fd_tracker.c index db9b4248b..c4248ed81 100644 --- a/tests/unit/test_fd_tracker.c +++ b/tests/unit/test_fd_tracker.c @@ -40,6 +40,13 @@ int lttng_opt_mi; #define TMP_DIR_PATTERN "/tmp/fd-tracker-XXXXXX" #define TEST_UNLINK_DIRECTORY_NAME "unlinked_files" +#ifdef __linux__ +#define SELF_FD_DIR "/proc/self/fd" +#else +/* Most Unices have /dev/fd */ +#define SELF_FD_DIR "/dev/fd" +#endif + /* * Count of fds, beyond stdin, stderr, stdout that were open * at the launch of the test. This allows the test to succeed when @@ -84,9 +91,9 @@ int fd_count(void) struct dirent *entry; int count = 0; - dir = opendir("/proc/self/fd"); + dir = opendir(SELF_FD_DIR); if (!dir) { - perror("# Failed to enumerate /proc/self/fd/ to count the number of used file descriptors"); + perror("# Failed to enumerate " SELF_FD_DIR " to count the number of used file descriptors"); count = -1; goto end; } @@ -100,7 +107,7 @@ int fd_count(void) /* Don't account for the file descriptor opened by opendir(). */ count--; if (closedir(dir)) { - perror("# Failed to close test program's self/fd directory file descriptor"); + perror("# Failed to close test program's " SELF_FD_DIR " directory file descriptor"); } end: return count; -- 2.34.1