unistd: add {get,set}domainname
This implements getdomainname(2) and setdomainname(2), which are
common UNIX extensions not covered by POSIX. References:
- http://man7.org/linux/man-pages/man2/getdomainname.2.html
- http://man7.org/linux/man-pages/man2/setdomainname.2.html
Rebased, PTAL. In this iteration:
- split gethostname test to its own commit
- changed gethostname and getdomainname to allocate their own buffer
- added emscripten, reported https://github.com/rust-lang/libc/issues/868 for BSDs (I can tackle this later if nobody else does)
libc's maintainers probably aren't going to add the definitions themselves, even for reported issues. Like Nix, they mostly rely on pull requests from their users. Could you please open a PR for libc?
This got stale due to lack of time on my side, but I'll eventually get back to this (just not high priority at the moment). In the meanwhile, @gnzlbg is pushing forward the BSD libc fix, kudos to them.
Rebased to take care of BSD and Apple, PTAL.
@Susurrus I adjusted and documented POSIX_HOST_NAME_MAX as suggested, PTAL.
Gentle ping for a review.
@lucab Are you planning on coming back to this?
@Susurrus yes but I need to figure out the story with HOST_NAME_MAX Linux and POSIX, and forward to libc.
@lucab Did the HOST_NAME_MAX get sorted yet?
So, the full story is as follows.
Host names returned by gethostname() are limited to HOST_NAME_MAX bytes (not including the terminating null), which is defined by each OS.
According to POSIX limits, the minimum acceptable value should be _POSIX_HOST_NAME_MAX which is equal to 255.
However it looks like glibc is not POSIX compliant here, and defines HOST_NAME_MAX as 64. Instead, musl took a different decision and set it to 255.
But, the Linux kernel implementation effectively limits it to 64.
Additionally, it looks like some systems (freebsd, macos) try to avoid fixing HOST_NAME_MAX, using sysconf(_SC_HOST_NAME_MAX) instead. This latter seems to be indeed the correct POSIX way.
@Susurrus @asomers what would you like to do out of this? I'm inclined to just switch to using sysconf everywhere and falling back to _POSIX_HOST_NAME_MAX if that fails, as it seems reasonably clean and minimize the allocation in the happy case, without pushing this mess forward in libc.
Yes, sysconf sounds like the safest approach.
Travis is red due to android missing POSIX constants in libc crate, see https://github.com/rust-lang/libc/pull/990.
Rebased, this is now green. I think I've addressed all comments in reviews so far, but at this point this PR is quite different from its initial version. PTAL.
@asomers I was a bit unsure about the safety of your comments so I added some idempotency checks to the tests. You are indeed right, so I pushed the rework and the additional testing logic. Everything is green, PTAL.
Ok, everything looks good to me! It only needs a squash. @Susurrus do you have any comments?
@asomers ack. I squashed one commit out. I'm keeping two commits for the two separate changelog entries. Let me know if you prefer everything together.
I came looking exactly for this! I'm not very knowledgeable about POSIX but I'm happy to help this get merged if needed. Are there any major blocks that need to be resolved?