<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/1b99b4b81436a0cb52d207449a51a8e89525981a">https://github.com/macports/macports-legacy-support/commit/1b99b4b81436a0cb52d207449a51a8e89525981a</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 1b99b4b81436a0cb52d207449a51a8e89525981a
</span>Author: Fred Wright <fw@fwright.net>
AuthorDate: Thu Feb 15 16:04:22 2024 -0800
<span style='display:block; white-space:pre;color:#404040;'> test_fdopendir: Add pipe tests
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> The stdin test was failing (legacy version only) when the test was run
</span><span style='display:block; white-space:pre;color:#404040;'> from a pipe rather than a tty or pty. This adds an explicit test for
</span><span style='display:block; white-space:pre;color:#404040;'> the pipe case, allowing that to be tested even while the program is
</span><span style='display:block; white-space:pre;color:#404040;'> being run from a tty or pty. The existing stdin test can also be
</span><span style='display:block; white-space:pre;color:#404040;'> observed to fail when running the test via "ssh -T" or by running:
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> cat /dev/null | .../test_fdopendir
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Since a pipe is now created for this test, it also tests the
</span><span style='display:block; white-space:pre;color:#404040;'> closed-pipe case, as a general test of a closed-fd case, which isn't
</span><span style='display:block; white-space:pre;color:#404040;'> necessarily the same as a numerically invalid fd (though it should
</span><span style='display:block; white-space:pre;color:#404040;'> return the same EBADF).
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> TESTED:
</span><span style='display:block; white-space:pre;color:#404040;'> Without new fdopendir() fixes, the open-pipe test fails in all <10.10
</span><span style='display:block; white-space:pre;color:#404040;'> OSes, and the closed-pipe test fails in 10.4. With new fixes, all
</span><span style='display:block; white-space:pre;color:#404040;'> tests pass in all OS versions.
</span><span style='display:block; white-space:pre;color:#404040;'> Tested on 10.4-10.5 ppc, 10.4-10.6 i386, 10.4-12.x x86_64, 11.x-14.x
</span><span style='display:block; white-space:pre;color:#404040;'> arm64.
</span>---
test/test_fdopendir.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/test/test_fdopendir.c b/test/test_fdopendir.c
</span><span style='display:block; white-space:pre;color:#808080;'>index d51bafa..94210a4 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/test/test_fdopendir.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/test/test_fdopendir.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -54,6 +54,7 @@ int main() {
</span> DIR *dir;
char *first_entry = NULL;
int err;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ int pipefds[2];
</span>
/* Test fdopendir with a valid directory fd, then use readdir */
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -207,6 +208,28 @@ int main() {
</span> err = check_failure(AT_FDCWD, "AT_FDCWD", "EBADF", EBADF);
if (err) return 1;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ /*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Try to use fdopendir with pipe - Should fail with ENOTDIR
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * This reproduces the stdin test failure seen when running the test via
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * a pipe, rather than a tty or pty.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (pipe(pipefds) < 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ perror("Unable to create pipe for pipe test");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (void) close(pipefds[1]); /* Close the writing side immediately */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = check_failure(pipefds[0], "pipe", "ENOTDIR", ENOTDIR);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (void) close(pipefds[0]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (err) return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Also try with closed pipe - Should fail with EBADF */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ err = check_failure(pipefds[0], "closed", "EBADF", EBADF);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (err) return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> return 0;
}
</pre><pre style='margin:0'>
</pre>