Skip to contentSkip to conversation

Fix detection of uname failure

PATCH Superseded Charles Bailey 3 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix detection of uname failure

From: Charles Bailey <[email protected]>

According to POSIX specification uname must return -1 on failure and a non-negative value on success. Although many implementations do return 0 on success it is valid to return any positive value for success. In particular, Solaris returns 1.

---
 dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
dir.c +1 -1
index 8209f8b..52dbfd0 100644
@@ -1848,7 +1848,7 @@ static const char *get_ident_string(void)
 
 	if (sb.len)
 		return sb.buf;
-	if (uname(&uts))
+	if (uname(&uts) == -1)
 		die_errno(_("failed to get kernel name and information"));
 	strbuf_addf(&sb, "Location %s, system %s %s %s", get_git_work_tree(),
 		    uts.sysname, uts.release, uts.version);
Signature · 1 line
2.4.0.53.g8440f74
#1 lore raw

Hi Charles,

Quoted 11 lines · Charles Bailey
dir.c +1 -1
index 8209f8b..52dbfd0 100644
@@ -1848,7 +1848,7 @@ static const char *get_ident_string(void)
 
 	if (sb.len)
 		return sb.buf;
-	if (uname(&uts))
+	if (uname(&uts) == -1)
 
Quoted 1 line

From a quick git grep '== -1' and another quick git grep '< 0' it appears to me that we prefer the latter. Maybe you want to adjust it in the patch, too?

Ciao,
Johannes

#2 lore raw

PATCH v2 1/1 Fix detection of uname failure

From: Charles Bailey <[email protected]>

According to POSIX specification uname must return -1 on failure and a non-negative value on success. Although many implementations do return 0 on success it is valid to return any positive value for success. In particular, Solaris returns 1.

---
 dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
dir.c +1 -1
index 8209f8b..1d42811 100644
@@ -1848,7 +1848,7 @@ static const char *get_ident_string(void)
 
 	if (sb.len)
 		return sb.buf;
-	if (uname(&uts))
+	if (uname(&uts) < 0)
 		die_errno(_("failed to get kernel name and information"));
 	strbuf_addf(&sb, "Location %s, system %s %s %s", get_git_work_tree(),
 		    uts.sysname, uts.release, uts.version);
Signature · 1 line
2.4.0.53.g8440f74
#4 lore raw
Quoted 11 lines · Johannes Schindelin
Quoted 8 lines · Charles Bailey

From: Charles Bailey <[email protected]>

According to POSIX specification uname must return -1 on failure and a non-negative value on success. Although many implementations do return 0 on success it is valid to return any positive value for success. In particular, Solaris returns 1.

I'd s/Ack/Review/; as the original is not your code but you are well qualified (and have my trust) to judge the change to this codepath ;-)

Thanks.

#5 lore raw

Hi Junio,

Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Johannes Schindelin
Quoted 7 lines · Charles Bailey

From: Charles Bailey <[email protected]>

According to POSIX specification uname must return -1 on failure and a non-negative value on success. Although many implementations do return 0 on success it is valid to return any positive value for success. In particular, Solaris returns 1.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I'd s/Ack/Review/; as the original is not your code but you are well qualified (and have my trust) to judge the change to this codepath ;-)

Yeah, that's what I meant ;-)

Ciao,
Dscho

#6 lore raw
In reply to Johannes Schindelin
Quoted 2 lines · Johannes Schindelin

From a quick git grep '== -1' and another quick git grep '< 0' it appears to me that we prefer the latter. Maybe you want to adjust it in the patch, too?

I did the same grep and found lots of examples of both. Many of the "< 0" applied to comparisons with variables and not API calls and many were internal (to git) calls and not POSIX or C library calls so I wasn't convinced to change my initial fix.

Having said that and thought about it some more, I think '< 0' is probably better. In POSIX, we shouldn't ever get a negative value which isn't -1, but if we ever do it is probably safer to fail. I'll send and update.

Charles.

#7 lore raw
Quoted 4 lines · Charles Bailey

... I think '< 0' is
probably better. In POSIX, we shouldn't ever get a negative value which isn't -1, but if we ever do it is probably safer to fail. I'll send and update.

Thanks; I was about to type the same reasoning and conclusion ;-)