Blame man2/uname.2

Packit 7cfc04
.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" 2007-07-05 mtk: Added details on underlying system call interfaces
Packit 7cfc04
.\"
Packit 7cfc04
.TH UNAME 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
uname \- get name and information about current kernel
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <sys/utsname.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int uname(struct utsname *" buf );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR uname ()
Packit 7cfc04
returns system information in the structure pointed to by
Packit 7cfc04
.IR buf .
Packit 7cfc04
The
Packit 7cfc04
.I utsname
Packit 7cfc04
struct is defined in
Packit 7cfc04
.IR <sys/utsname.h> :
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct utsname {
Packit 7cfc04
    char sysname[];    /* Operating system name (e.g., "Linux") */
Packit 7cfc04
    char nodename[];   /* Name within "some implementation-defined
Packit 7cfc04
                          network" */
Packit 7cfc04
    char release[];    /* Operating system release (e.g., "2.6.28") */
Packit 7cfc04
    char version[];    /* Operating system version */
Packit 7cfc04
    char machine[];    /* Hardware identifier */
Packit 7cfc04
#ifdef _GNU_SOURCE
Packit 7cfc04
    char domainname[]; /* NIS or YP domain name */
Packit 7cfc04
#endif
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The length of the arrays in a
Packit 7cfc04
.I struct utsname
Packit 7cfc04
is unspecified (see NOTES);
Packit 7cfc04
the fields are terminated by a null byte (\(aq\\0\(aq).
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, zero is returned.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
.I buf
Packit 7cfc04
is not valid.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008, SVr4.
Packit 7cfc04
There is no
Packit 7cfc04
.BR uname ()
Packit 7cfc04
call in 4.3BSD.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I domainname
Packit 7cfc04
member (the NIS or YP domain name) is a GNU extension.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
This is a system call, and the operating system presumably knows
Packit 7cfc04
its name, release and version.
Packit 7cfc04
It also knows what hardware it runs on.
Packit 7cfc04
So, four of the fields of the struct are meaningful.
Packit 7cfc04
On the other hand, the field
Packit 7cfc04
.I nodename
Packit 7cfc04
is meaningless:
Packit 7cfc04
it gives the name of the present machine in some undefined
Packit 7cfc04
network, but typically machines are in more than one network
Packit 7cfc04
and have several names.
Packit 7cfc04
Moreover, the kernel has no way of knowing
Packit 7cfc04
about such things, so it has to be told what to answer here.
Packit 7cfc04
The same holds for the additional
Packit 7cfc04
.I domainname
Packit 7cfc04
field.
Packit 7cfc04
.PP
Packit 7cfc04
To this end, Linux uses the system calls
Packit 7cfc04
.BR sethostname (2)
Packit 7cfc04
and
Packit 7cfc04
.BR setdomainname (2).
Packit 7cfc04
Note that there is no standard that says that the hostname set by
Packit 7cfc04
.BR sethostname (2)
Packit 7cfc04
is the same string as the
Packit 7cfc04
.I nodename
Packit 7cfc04
field of the struct returned by
Packit 7cfc04
.BR uname ()
Packit 7cfc04
(indeed, some systems allow a 256-byte hostname and an 8-byte nodename),
Packit 7cfc04
but this is true on Linux.
Packit 7cfc04
The same holds for
Packit 7cfc04
.BR setdomainname (2)
Packit 7cfc04
and the
Packit 7cfc04
.I domainname
Packit 7cfc04
field.
Packit 7cfc04
.PP
Packit 7cfc04
The length of the fields in the struct varies.
Packit 7cfc04
Some operating systems
Packit 7cfc04
or libraries use a hardcoded 9 or 33 or 65 or 257.
Packit 7cfc04
Other systems use
Packit 7cfc04
.B SYS_NMLN
Packit 7cfc04
or
Packit 7cfc04
.B _SYS_NMLN
Packit 7cfc04
or
Packit 7cfc04
.B UTSLEN
Packit 7cfc04
or
Packit 7cfc04
.BR _UTSNAME_LENGTH .
Packit 7cfc04
Clearly, it is a bad
Packit 7cfc04
idea to use any of these constants; just use sizeof(...).
Packit 7cfc04
Often 257 is chosen in order to have room for an internet hostname.
Packit 7cfc04
.PP
Packit 7cfc04
Part of the utsname information is also accessible via
Packit 7cfc04
.IR /proc/sys/kernel/ { ostype ,
Packit 7cfc04
.IR hostname ,
Packit 7cfc04
.IR osrelease ,
Packit 7cfc04
.IR version ,
Packit 7cfc04
.IR domainname }.
Packit 7cfc04
.SS C library/kernel differences
Packit 7cfc04
.PP
Packit 7cfc04
Over time, increases in the size of the
Packit 7cfc04
.I utsname
Packit 7cfc04
structure have led to three successive versions of
Packit 7cfc04
.BR uname ():
Packit 7cfc04
.IR sys_olduname ()
Packit 7cfc04
(slot
Packit 7cfc04
.IR __NR_oldolduname ),
Packit 7cfc04
.IR sys_uname ()
Packit 7cfc04
(slot
Packit 7cfc04
.IR __NR_olduname ),
Packit 7cfc04
and
Packit 7cfc04
.IR sys_newuname ()
Packit 7cfc04
(slot
Packit 7cfc04
.IR __NR_uname) .
Packit 7cfc04
The first one
Packit 7cfc04
.\" That was back before Linux 1.0
Packit 7cfc04
used length 9 for all fields;
Packit 7cfc04
the second
Packit 7cfc04
.\" That was also back before Linux 1.0
Packit 7cfc04
used 65;
Packit 7cfc04
the third also uses 65 but adds the
Packit 7cfc04
.I domainname
Packit 7cfc04
field.
Packit 7cfc04
The glibc
Packit 7cfc04
.BR uname ()
Packit 7cfc04
wrapper function hides these details from applications,
Packit 7cfc04
invoking the most recent version of the system call provided by the kernel.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR uname (1),
Packit 7cfc04
.BR getdomainname (2),
Packit 7cfc04
.BR gethostname (2),
Packit 7cfc04
.BR namespaces (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.