-
Notifications
You must be signed in to change notification settings - Fork 47
Return /etc/hostname when 'hostname' command does not exist #642
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -158,7 +158,17 @@ def getExtraCommandOutputFileName(): | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def getHostname(): | ||||||||||||||||||||||||||
| return getCmndOutput("hostname", True) | ||||||||||||||||||||||||||
| hostname = "" | ||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||
| hostname = getCmndOutput("hostname", True) | ||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||
| if hostname == "": | ||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||
| hostname = getCmndOutput("cat /etc/hostname", True) | ||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||
|
Comment on lines
+164
to
+171
|
||||||||||||||||||||||||||
| except Exception: | |
| pass | |
| if hostname == "": | |
| try: | |
| hostname = getCmndOutput("cat /etc/hostname", True) | |
| except Exception: | |
| except RuntimeError: | |
| pass | |
| if hostname == "": | |
| try: | |
| hostname = getCmndOutput("cat /etc/hostname", True) | |
| except RuntimeError: |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both the hostname command and /etc/hostname fallback fail, this now returns an empty string. That propagates into email subjects/bodies (e.g., "...: %s: %s"), producing blank hostnames and making messages harder to interpret. Consider returning a clear sentinel like "unknown" (or using socket.gethostname() as a final fallback) instead of "".
Uh oh!
There was an error while loading. Please reload this page.