Skip to content

fix: can not get hostname in redhat #12267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xuruidong
Copy link
Contributor

@xuruidong xuruidong commented May 29, 2025

Description

I use docker image apache/apisix:3.11.0-redhat , and get an error from the log: "sh: /bin/hostname: No such file or directory"
image

Which issue(s) this PR fixes:

Fixes # #12270

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels May 29, 2025
@Baoyuantop
Copy link
Contributor

Hi @xuruidong, can you create an issue first and include minimal steps to reproduce it?

@xuruidong
Copy link
Contributor Author

Hi @xuruidong, can you create an issue first and include minimal steps to reproduce it?

done


else
hostname = "unknown"
log.error("failed to read output of \"/bin/hostname\": ", err)
log.error("gethostname error:", ffi_string(C.strerror(ffi.errno())))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can obtain the hostname by reading /proc/sys/kernel/hostname?
The /bin/hostname requires a binary, but as long as procfs exists, the above path will reflect the hostname, which may be more reliable. 🤔

The gethostname may behave differently on various Linux kernels and libc implementations, such as the maximum length of hostname. I noticed that you assumed it to be 256. It seems that this is not good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants