Skip to content

Conversation

@ioquatix
Copy link
Member

@ioquatix ioquatix merged commit 46b544c into ruby:master Jan 28, 2025
84 checks passed
@ioquatix ioquatix deleted the hostname-uname branch January 28, 2025 00:36
describe "Socket.gethostname" do
it "returns the host name" do
Socket.gethostname.should == `hostname`.strip
Socket.gethostname.should == `uname -n`.strip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break on pure Windows (GitHub Actions have msys).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can have a conditional on Windows to use hostname?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would be good to avoid using uname on Windows as it might not be there/it's not the right thing to use.
You can use platform_is :windows do for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert this, hostname is more portable, and Arch can add a dependency to inetutils to run specs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostname is not more portable, it is a GNU-specific tool (inettools) and uname -n is standardised by POSIX/Open Group: https://pubs.opengroup.org/onlinepubs/009695399/utilities/uname.html and should be available everywhere. However, I accept on vanilla Windows, only hostname.exe exists.

eregon added a commit that referenced this pull request Jan 28, 2025
@ioquatix
Copy link
Member Author

Rather than reverting this, I am okay to add a fallback to hostname: #12655

k0kubun added a commit that referenced this pull request Feb 14, 2025
	Prefer `uname -n` over `hostname`. (#12647)

	Add fallback for `hostname` if `uname` isn't available. (#12655)
matzbot pushed a commit that referenced this pull request Mar 8, 2025
	Prefer `uname -n` over `hostname`. (#12647)

	Add fallback for `hostname` if `uname` isn't available. (#12655)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants