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

fix returning hostname from uname on posix #2220

Merged
merged 1 commit into from Nov 7, 2018

Conversation

Projects
None yet
3 participants
@tchaloupka
Copy link
Contributor

commented Oct 17, 2018

As seen in documentation nodename is char[] of unspecified size and string is null terminated.

There is specified size of 65 in druntime.

But to!string on the char array doesn't handle null terminated string but just returns it in a full length with nulls.

I've found this out on one of the servers where something strange was logged and it was exactly 65 chars in length.

Fixed it using std.string.fromStringz.

Note: This should be fixed in vibe-core too

@ZombineDev
Copy link
Contributor

left a comment

Looks good, but could be simplified a bit:

utsname name;
if (uname(&name)) return hostName;
hostName = name.nodename.to!string();
hostName = (&name.nodename[0]).fromStringz().idup;

This comment has been minimized.

Copy link
@ZombineDev

ZombineDev Oct 17, 2018

Contributor

Simply name.nodename.ptr.to!string should do the trick.

@ZombineDev

This comment has been minimized.

Copy link
Contributor

commented Oct 17, 2018

But to!string on the char array doesn't handle null terminated string but just returns it in a full length with nulls.

to!string handles null terminated strings, we just need to pass char*, instead of char[].

@tchaloupka tchaloupka force-pushed the tchaloupka:fix_hostname branch from e885a31 to 1472fee Oct 17, 2018

@tchaloupka

This comment has been minimized.

Copy link
Contributor Author

commented Oct 17, 2018

Great, didn't know that, better? :)

@ZombineDev

This comment has been minimized.

Copy link
Contributor

commented Oct 17, 2018

better? :)

perfect ;)

@s-ludwig s-ludwig merged commit ce49484 into vibe-d:master Nov 7, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@s-ludwig

This comment has been minimized.

Copy link
Member

commented Nov 7, 2018

Thanks for the fix, I'll check vibe-core now. The documentation is quite confusing, considering that char[] is equivalent to char* in C.

s-ludwig added a commit to vibe-d/vibe-core that referenced this pull request Nov 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.