On the GitHub Cygwin machines (Cygwin 3.3.6 and 3.5.3), I see this test failure:
FAIL: test-sethostname2 ======================= setting a too long hostname succeeded. FAIL test-sethostname2.exe (exit status: 1) The cause: Cygwin apparently does not reject a too long hostname argument. While the LSB specifies it should fail in this case, I don't think it's worth a workaround in Gnulib, since this function is rarely used. So, let me just skip this test and notify the Cygwin people. 2024-05-23 Bruno Haible <br...@clisp.org> sethostname tests: Avoid test failure on Cygwin. * tests/test-sethostname2.c (main): On Cygwin, skip the "too long hostname" test. * doc/glibc-functions/sethostname.texi: Mention the Cygwin problem. diff --git a/doc/glibc-functions/sethostname.texi b/doc/glibc-functions/sethostname.texi index 1aff926cd4..cef0edf268 100644 --- a/doc/glibc-functions/sethostname.texi +++ b/doc/glibc-functions/sethostname.texi @@ -40,4 +40,8 @@ The second parameter is @code{int} instead of @code{size_t} on some platforms: macOS 12.5, FreeBSD 14.0, MidnightBSD 3.0, Solaris 11 2010-11, Solaris 11 OpenIndiana, Solaris 11 OmniOS. +@item +This function does not reject a too long host name on some platforms: +@c https://cygwin.com/pipermail/cygwin/2024-May/255986.html +Cygwin 3.5.3. @end itemize diff --git a/tests/test-sethostname2.c b/tests/test-sethostname2.c index 33d7da76de..25a3ae1857 100644 --- a/tests/test-sethostname2.c +++ b/tests/test-sethostname2.c @@ -45,7 +45,6 @@ main (int argc, _GL_UNUSED char *argv[]) { char origname[HOST_NAME_MAX]; char newname[HOST_NAME_MAX]; - char longname[HOST_NAME_MAX + 2]; int rcs, i; /* skip the tests if we don't have root privilege. this does not @@ -108,23 +107,31 @@ main (int argc, _GL_UNUSED char *argv[]) #endif } - /* glibc does allow setting a zero length name, so the lower bound - needs no test. validate that we are constrained by - HOST_NAME_MAX */ - for (i = 0; i < (HOST_NAME_MAX + 1); i++) - longname[i] = 'a'; - - longname[i] = '\0'; - - rcs = sethostname (longname, (HOST_NAME_MAX + 1)); - - if (rcs != -1) - { - /* attempt to restore the original name. */ - ASSERT (sethostname (origname, strlen (origname)) == 0); - fprintf (stderr, "setting a too long hostname succeeded.\n"); - return 1; - } + /* Known Cygwin bug: + <https://cygwin.com/pipermail/cygwin/2024-May/255986.html> */ +#if !defined __CYGWIN__ + { + char longname[HOST_NAME_MAX + 2]; + + /* glibc does allow setting a zero length name, so the lower bound + needs no test. validate that we are constrained by + HOST_NAME_MAX */ + for (i = 0; i < (HOST_NAME_MAX + 1); i++) + longname[i] = 'a'; + + longname[i] = '\0'; + + rcs = sethostname (longname, (HOST_NAME_MAX + 1)); + + if (rcs != -1) + { + /* attempt to restore the original name. */ + ASSERT (sethostname (origname, strlen (origname)) == 0); + fprintf (stderr, "setting a too long hostname succeeded.\n"); + return 1; + } + } +#endif /* restore the original name. */ ASSERT (sethostname (origname, strlen (origname)) == 0);