nix icon indicating copy to clipboard operation
nix copied to clipboard

unistd: add {get,set}domainname

Open lucab opened this issue 8 years ago • 17 comments

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

lucab avatar Dec 10 '17 21:12 lucab

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)

lucab avatar Dec 11 '17 12:12 lucab

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?

asomers avatar Dec 11 '17 15:12 asomers

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.

lucab avatar Jan 18 '18 09:01 lucab

Rebased to take care of BSD and Apple, PTAL.

lucab avatar Jan 27 '18 14:01 lucab

@Susurrus I adjusted and documented POSIX_HOST_NAME_MAX as suggested, PTAL.

lucab avatar Jan 29 '18 11:01 lucab

Gentle ping for a review.

lucab avatar Feb 02 '18 11:02 lucab

@lucab Are you planning on coming back to this?

Susurrus avatar Feb 21 '18 03:02 Susurrus

@Susurrus yes but I need to figure out the story with HOST_NAME_MAX Linux and POSIX, and forward to libc.

lucab avatar Feb 21 '18 08:02 lucab

@lucab Did the HOST_NAME_MAX get sorted yet?

Susurrus avatar Apr 07 '18 17:04 Susurrus

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.

lucab avatar May 16 '18 13:05 lucab

Yes, sysconf sounds like the safest approach.

asomers avatar May 16 '18 14:05 asomers

Travis is red due to android missing POSIX constants in libc crate, see https://github.com/rust-lang/libc/pull/990.

lucab avatar May 22 '18 12:05 lucab

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.

lucab avatar May 22 '18 20:05 lucab

@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.

lucab avatar May 25 '18 14:05 lucab

Ok, everything looks good to me! It only needs a squash. @Susurrus do you have any comments?

asomers avatar May 25 '18 17:05 asomers

@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.

lucab avatar May 27 '18 08:05 lucab

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?

CrumblyLiquid avatar Dec 10 '25 23:12 CrumblyLiquid