Skip to content
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

On Solaris, GetHostName() returns empty string #783

Merged
merged 1 commit into from
Jan 19, 2022

Conversation

fkolarek
Copy link
Contributor

@fkolarek fkolarek commented Jan 14, 2022

Description

Currently on SunOS, a call to GetHostName() will return an empty hostname. This is because the return value of uname() is a "non-negative value" as per the man page, but in my testing it seems to return 1. This causes the returned hostname value to be an empty string in calls to GetHostName() or "(unknown)" in calls to LogDestination::hostname(). Example log file:

Log file created at: 2022/01/14 15:29:08
Running on machine: (unknown)

Changes

Modifying this code to check for a return value of less than zero will work on Solaris as well as Linux and AIX. I don't know how useful this would be to the general populace seeing most folks are running on Linux, but I figured it wouldn't hurt considering the triviality of the actual code change.

Notes

Solaris uname manpage
AIX uname manpage
Linux manpage

As per https://docs.oracle.com/cd/E18752_01/html/816-5167/uname-2.html#REFMAN2uname-2
Solaris version of uname() return a non-negative value on success. Modifying this code to check
for a return value of less than zero will work on Solaris as well as Linux and AIX.
@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2022

Codecov Report

Merging #783 (3dce803) into master (6434410) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #783   +/-   ##
=======================================
  Coverage   72.65%   72.65%           
=======================================
  Files          17       17           
  Lines        3247     3247           
=======================================
  Hits         2359     2359           
  Misses        888      888           
Impacted Files Coverage Δ
src/logging.cc 73.39% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6434410...3dce803. Read the comment docs.

@fkolarek fkolarek changed the title On Solaris, uname() returns non-negative value On Solaris, uname() returns non-negative value on success, not zero Jan 16, 2022
@fkolarek fkolarek changed the title On Solaris, uname() returns non-negative value on success, not zero On Solaris, GetHostName() returns empty string for hostname Jan 17, 2022
@fkolarek fkolarek changed the title On Solaris, GetHostName() returns empty string for hostname On Solaris, GetHostName() returns empty string Jan 17, 2022
@sergiud sergiud added the bug label Jan 19, 2022
@sergiud sergiud added this to the 0.6 milestone Jan 19, 2022
@sergiud
Copy link
Collaborator

sergiud commented Jan 19, 2022

Thanks!

@sergiud sergiud merged commit b0174b3 into google:master Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants