[PATCH] Fix detection of uname failure

Subsystems: the rest

STALE3744d

5 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] Fix detection of uname failure

From: Charles Bailey <hidden>
Date: 2016-06-15 23:05:46

From: Charles Bailey <redacted>

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.

Signed-off-by: Charles Bailey <redacted>
---
 dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index 8209f8b..52dbfd0 100644
--- a/dir.c
+++ b/dir.c
@@ -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);
-- 
2.4.0.53.g8440f74

Re: [PATCH] Fix detection of uname failure

From: Johannes Schindelin <hidden>
Date: 2016-06-15 23:05:46

Hi Charles,

On 2015-07-17 14:11, Charles Bailey wrote:
quoted hunk
diff --git a/dir.c b/dir.c
index 8209f8b..52dbfd0 100644
--- a/dir.c
+++ b/dir.c
@@ -1848,7 +1848,7 @@ static const char *get_ident_string(void)
 
 	if (sb.len)
 		return sb.buf;
-	if (uname(&uts))
+	if (uname(&uts) == -1)
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

Re: [PATCH] Fix detection of uname failure

From: Charles Bailey <hidden>
Date: 2016-06-15 23:05:47

On Fri, Jul 17, 2015 at 03:06:57PM +0200, Johannes Schindelin wrote:
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.

[PATCH v2] Fix detection of uname failure

From: Charles Bailey <hidden>
Date: 2016-06-15 23:05:47

From: Charles Bailey <redacted>

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.

Signed-off-by: Charles Bailey <redacted>
---
 dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index 8209f8b..1d42811 100644
--- a/dir.c
+++ b/dir.c
@@ -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);
-- 
2.4.0.53.g8440f74

Re: [PATCH v2] Fix detection of uname failure

From: Johannes Schindelin <hidden>
Date: 2016-06-15 23:05:47

On 2015-07-17 19:09, Charles Bailey wrote:
From: Charles Bailey <redacted>

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.

Signed-off-by: Charles Bailey <redacted>
Acked-by: Johannes Schindelin <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help