RFR: 8327621: Check return value of uname in os::get_host_name

Peter Tribble peter.tribble at gmail.com
Thu Mar 7 19:02:23 UTC 2024


On Thu, Mar 7, 2024 at 6:29 PM Johan Sjölen <jsjolen at openjdk.org> wrote:

> Hi,
>
> Trivial bug fix where we didn't check the return value of `uname(2)` on
> POSIX platforms. I checked callers of `get_host_name` and all wrap the
> calls in an `if` branch so they already handle failures.
>

I notice you're checking for a return value of zero. Posix 1003.1 states
something like

Upon successful completion, a non-negative value is returned. Otherwise, −1
is returned and errno is set to indicate the error.

So the correct check based on that would be != -1.

Linux and FreeBSD document returning 0 on success, but Solaris/illumos
definitely returns 1
(and as the port maintainer there it would be nice to have this correct). I
don't have an AIX box
right now but the existing uname(2) check within openjdk is for -1, eg
https://github.com/openjdk/jdk/blob/master/src/hotspot/os/aix/os_aix.cpp#L2799

Thanks,


> Regards,
> Johan
>
> -------------
>
> Commit messages:
>  - Check the return value of uname
>
> Changes: https://git.openjdk.org/jdk/pull/18157/files
>  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18157&range=00
>   Issue: https://bugs.openjdk.org/browse/JDK-8327621
>   Stats: 5 lines in 1 file changed: 2 ins; 0 del; 3 mod
>   Patch: https://git.openjdk.org/jdk/pull/18157.diff
>   Fetch: git fetch https://git.openjdk.org/jdk.git
> pull/18157/head:pull/18157
>
> PR: https://git.openjdk.org/jdk/pull/18157
>


-- 
-Peter Tribble
http://www.petertribble.co.uk/ - http://ptribble.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/hotspot-runtime-dev/attachments/20240307/dfa31b6a/attachment.htm>


More information about the hotspot-runtime-dev mailing list