Git development
 help / color / mirror / Atom feed
* uname check fails on Solaris due to different return value
@ 2026-11-12 15:52 Jakub Kulik
  2026-11-12 19:29 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kulik @ 2026-11-12 15:52 UTC (permalink / raw)
  To: git@vger.kernel.org

Hi, I encountered one more minor Solaris failure.

On Solaris, uname syscall returns non-negative value on success and -1 on failure [1], which is different from seemingly all other supported platforms, which return 0 on success (and still -1 on failure). As such, the current check in version.c doesn't work on Solaris.

I managed to fix this with:

--- git-2.56.0/version.c
+++ git-2.56.0/version.c
@@ -83,7 +83,7 @@ int get_uname_info(struct strbuf *buf, u
 {
 	struct utsname uname_info;
 
-	if (uname(&uname_info)) {
+	if (uname(&uname_info) < 0) {
 		strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"),
 			    strerror(errno),
 			    errno);


which *I think* should work on other platforms as well ([2]), but I might be missing some where this change wouldn't work. Still, I wanted to at least report this.

Thanks and Best regards,
Jakub

[1] https://docs.oracle.com/cd/E88353_01/html/E37841/uname-2.html
    https://smartos.org/man/2/uname
[2] https://pubs.opengroup.org/onlinepubs/009604599/functions/uname.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: uname check fails on Solaris due to different return value
  2026-11-12 15:52 uname check fails on Solaris due to different return value Jakub Kulik
@ 2026-11-12 19:29 ` Junio C Hamano
  2026-11-18 16:01   ` [PATCH] version: accept positive uname(2) return values Jakub Kulik
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2026-11-12 19:29 UTC (permalink / raw)
  To: Jakub Kulik; +Cc: git@vger.kernel.org

Jakub Kulik <jakub.kulik@oracle.com> writes:

> Hi, I encountered one more minor Solaris failure.
>
> On Solaris, uname syscall returns non-negative value on success
> and -1 on failure [1], which is different from seemingly all other
> supported platforms, which return 0 on success (and still -1 on
> failure). As such, the current check in version.c doesn't work on
> Solaris.

It seems that POSIX.1 is pretty clear on this.

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

Erroring upon seeing a non-zero value like the preimage of your
patch below *is* buggy, and the updated code looks right.

> I managed to fix this with:
>
> --- git-2.56.0/version.c
> +++ git-2.56.0/version.c
> @@ -83,7 +83,7 @@ int get_uname_info(struct strbuf *buf, u
>  {
>  	struct utsname uname_info;
>  
> -	if (uname(&uname_info)) {
> +	if (uname(&uname_info) < 0) {
>  		strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"),
>  			    strerror(errno),
>  			    errno);
>
>
> which *I think* should work on other platforms as well ([2]), but
> I might be missing some where this change wouldn't work. Still, I
> wanted to at least report this.

Thanks.  Care to make it into a real patch?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] version: accept positive uname(2) return values
  2026-11-12 19:29 ` Junio C Hamano
@ 2026-11-18 16:01   ` Jakub Kulik
  2026-11-18 17:11     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kulik @ 2026-11-18 16:01 UTC (permalink / raw)
  To: git; +Cc: gitster, Jakub Kulik

POSIX specifies that uname(2) can return any non-negative value on
success. Update the get_uname_info() check to follow this.

Signed-off-by: Jakub Kulik <jakub.kulik@oracle.com>
---
Thank you. Hope this is how it should look.

 version.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/version.c b/version.c
index 21ec7c0fbe..ca3be6d610 100644
--- a/version.c
+++ b/version.c
@@ -83,7 +83,7 @@ int get_uname_info(struct strbuf *buf, unsigned int full)
 {
 	struct utsname uname_info;
 
-	if (uname(&uname_info)) {
+	if (uname(&uname_info) < 0) {
 		strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"),
 			    strerror(errno),
 			    errno);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] version: accept positive uname(2) return values
  2026-11-18 16:01   ` [PATCH] version: accept positive uname(2) return values Jakub Kulik
@ 2026-11-18 17:11     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2026-11-18 17:11 UTC (permalink / raw)
  To: Jakub Kulik; +Cc: git

Jakub Kulik <jakub.kulik@oracle.com> writes:

> POSIX specifies that uname(2) can return any non-negative value on
> success. Update the get_uname_info() check to follow this.
>
> Signed-off-by: Jakub Kulik <jakub.kulik@oracle.com>
> ---
> Thank you. Hope this is how it should look.

Perfect.  Thanks.

>
>  version.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/version.c b/version.c
> index 21ec7c0fbe..ca3be6d610 100644
> --- a/version.c
> +++ b/version.c
> @@ -83,7 +83,7 @@ int get_uname_info(struct strbuf *buf, unsigned int full)
>  {
>  	struct utsname uname_info;
>  
> -	if (uname(&uname_info)) {
> +	if (uname(&uname_info) < 0) {
>  		strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"),
>  			    strerror(errno),
>  			    errno);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-18 17:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 15:52 uname check fails on Solaris due to different return value Jakub Kulik
2026-11-12 19:29 ` Junio C Hamano
2026-11-18 16:01   ` [PATCH] version: accept positive uname(2) return values Jakub Kulik
2026-11-18 17:11     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox