Skip to content

Add fallback for hostname if uname isn't available. - #12655

Merged
ioquatix merged 1 commit into
ruby:masterfrom
ioquatix:hostname-uname-fallback
Jan 28, 2025
Merged

ioquatix merged 1 commit into
ruby:masterfrom
ioquatix:hostname-uname-fallback

Conversation

@ioquatix

@ioquatix ioquatix commented Jan 28, 2025 •

Copy link
Copy Markdown
Member

cc @Segaja

@ioquatix
ioquatix requested a review from eregon January 28, 2025 11:35
@ioquatix ioquatix self-assigned this Jan 28, 2025
@ioquatix
ioquatix merged commit d3abee7 into ruby:master Jan 28, 2025
@ioquatix
ioquatix deleted the hostname-uname-fallback branch January 28, 2025 12:20
def system_hostname
# Most platforms implement this POSIX standard:
`uname -n`.strip
rescue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not good because it relies on deep implementation details of backticks, which might vary between platforms and Ruby implementations.
Specifically, it relies on uname -n to use no shell, because if it used a shell it wouldn't raise an exception and just emit some stderr output + exit code 1.
It's best to not rely on deep implementation details like that in ruby/spec.

And anyway the real meaningful condition is POSIX vs not POSIX here, not try and rescue.

So it should use platform_is/platform_is_not :windows guards as I wrote you on Slack.

Also this is the second time you merge a PR and only ask for reviews after, this is uncomfortable and time-wasting so for the next PR wait for my review before merging.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And anyway the real meaningful condition is POSIX vs not POSIX here, not try and rescue.

So it should use platform_is/platform_is_not :windows guards as I wrote you on Slack.

Why there isn't platform_is :posix?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why there isn't platform_is :posix?

platform_is :posix sounds nice but platform_is_not :posix seems not so clear, e.g. there might be platforms which are not POSIX and are not Windows (although I don't think we support any of those).

@eregon

eregon commented Jan 31, 2025

Copy link
Copy Markdown
Member

@Segaja Could you explain the rationale for these changes? Please answer my questions at https://bugs.ruby-lang.org/issues/21095#note-7
We should not add complexity to the test suite without understanding the need first.

@ruby ruby deleted a comment from Pricer187 Jan 31, 2025
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