Subject: Return codes from uname()

From: [email-masked]
Date: Mon, 14 Dec 1998 23:53:46 -0600 (CST)

Full_Name: Thomas Maslen
Version: 2.1.4
CVS_Date: 
OS: Solaris 2.6
X_Server: 
Submission from: (NULL) (130.102.176.3)

In libs/System.c:getostype(), the code calls uname() and then checks that
the
return value == 0.  It should instead check for >= 0, because uname() can 
legitimately return any nonnegative value for success, and on Solaris 2.6
it
really does return 1 rather than 0.

(I think the bug originally appeared in a patch to 2.0.46, and there the
effect
was more obvious:  the first part of the HOSTDISPLAY environment variable
ended
up containing random binary garbage).

--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 15 Dec 1998 20:25:43 +0100

> really does return 1 rather than 0.

Hmm, legitimated by what? My Linux manpage says that it returns 0
or -1, nothing else. Is this guaranteed to work with all systems?

> up containing random binary garbage).

Bye

Dominik
-- 
Dominik Vogt, [email-masked]
Reply-To: [email-masked]

---

From: [email-masked] (Paul D. Smith)
Date: 15 Dec 1998 15:39:35 -0500

%% Dominik Vogt <[email-masked]> writes:

  >> In libs/System.c:getostype(), the code calls uname() and then
  >> checks that the return value == 0.  It should instead check for >=
  >> 0, because uname() can legitimately return any nonnegative value
  >> for success, and on Solaris 2.6 it really does return 1 rather than
  >> 0.

  dv> Hmm, legitimated by what? My Linux manpage says that it returns 0
  dv> or -1, nothing else. Is this guaranteed to work with all systems?

According to POSIX 1003.1-1990, uname() returns 0 on success and -1 on
failure.  There is no other valid return code.

Unless there have been modifications in subsequent versions of the
standard, Solaris is non-conformant.

However, the Solaris (2.5.1, here) man page does document it differently
than POSIX:

  RETURN VALUES
       Upon successful completion, a non-negative value is returned.   Other-
       wise,  a  value  of  -1  is  returned and errno is set to indicate the
       error.

Although Solaris appears wrong here, the fix can't hurt anything on
conformant systems so you might as well make the change.  The error is
well-defined to be -1 everywhere, so using >=0 instead of ==0 won't be a
problem.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[email-masked]>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dan Espen <[email-masked]>
Date: Tue, 15 Dec 1998 16:00:09 -0500

> well-defined to be -1 everywhere, so using >=0 instead of ==0 won't be a

Sun's not the only one, HPUX 11:

RETURN VALUE
      uname() and setuname() return the following values:

            n   Successful completion.  n is a nonnegative value.
           -1   Failure.  errno is set to indicate the error.

> -- 
>  Paul D. Smith <[email-masked]>         Network Management Developmen

--
Dan Espen                                Phone: (732) 699-5570
444 Hoes Lane  Room RRC 1C-214           E-mail: [email-masked]
Piscataway, NJ 08854
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: "Thomas Maslen" <[email-masked]>
Date: Wed, 16 Dec 1998 10:48:17 +1000

> standard, Solaris is non-conformant.

Digital Unix 4.0 has the same wording as Solaris, though Digital's uname()
does appear to return 0.

More to the point, Unix 98 (or the Single Unix Specification, Version 2, 
or whatever) says

    RETURN VALUE

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

I don't understand why 0 wasn't enough, but it does look as though the
standard has changed and at least one platform uses the looser definition.

> The error is well-defined to be -1 everywhere, so using >=0 instead of 
> ==0 won't be a problem.

Agreed.

In fact, the other place that uname() is used in 2.1.14 is in gethostname(),
for platforms that don't have gethostname() themselves, and there the code
dodges the problem by checking for the error case (-1) and treating anything
else as success.

Thomas Maslen
[email-masked]

---

From: [email-masked] (Paul D. Smith)
Date: 15 Dec 1998 21:57:09 -0500

>> standard, Solaris is non-conformant.

  tm> More to the point, Unix 98 (or the Single Unix Specification, Version 2, 
  tm> or whatever) says

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

  tm> I don't understand why 0 wasn't enough, but it does look as though
  tm> the standard has changed and at least one platform uses the looser
  tm> definition.

"The" standard?  Of course Unix98 most definitely != POSIX, any vintage.
As the man said, "that's the great thing about standards, there are so
many to choose from!"

:)