]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/uname.2
s/\\'/\\(aq/
[thirdparty/man-pages.git] / man2 / uname.2
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" 2007-07-05 mtk: Added details on underlying system call interfaces
24 .\"
25 .TH UNAME 2 2007-07-05 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 uname \- get name and information about current kernel
28 .SH SYNOPSIS
29 .B #include <sys/utsname.h>
30 .sp
31 .BI "int uname(struct utsname *" buf );
32 .SH DESCRIPTION
33 .BR uname ()
34 returns system information in the structure pointed to by
35 .IR buf .
36 The
37 .I utsname
38 struct is defined in
39 .IR <sys/utsname.h> :
40 .in +4n
41 .nf
42
43 struct utsname {
44 char sysname[];
45 char nodename[];
46 char release[];
47 char version[];
48 char machine[];
49 #ifdef _GNU_SOURCE
50 char domainname[];
51 #endif
52 };
53
54 .fi
55 .in
56 The length of the arrays in a
57 .I struct utsname
58 is unspecified; the fields are terminated by a null byte (\(aq\\0\(aq).
59 .SH "RETURN VALUE"
60 On success, zero is returned.
61 On error, \-1 is returned, and
62 .I errno
63 is set appropriately.
64 .SH ERRORS
65 .TP
66 .B EFAULT
67 .I buf
68 is not valid.
69 .SH "CONFORMING TO"
70 SVr4, POSIX.1-2001.
71 There is no
72 .BR uname ()
73 call in 4.3BSD.
74 .PP
75 The
76 .I domainname
77 member (the NIS or YP domain name) is a GNU extension.
78 .SH NOTES
79 This is a system call, and the operating system presumably knows
80 its name, release and version.
81 It also knows what hardware it runs on.
82 So, four of the fields of the struct are meaningful.
83 On the other hand, the field \fInodename\fP is meaningless:
84 it gives the name of the present machine in some undefined
85 network, but typically machines are in more than one network
86 and have several names.
87 Moreover, the kernel has no way of knowing
88 about such things, so it has to be told what to answer here.
89 The same holds for the additional \fIdomainname\fP field.
90 .LP
91 To this end Linux uses the system calls
92 .BR sethostname (2)
93 and
94 .BR setdomainname (2).
95 Note that there is no standard that says that the hostname set by
96 .BR sethostname (2)
97 is the same string as the \fInodename\fP field of the struct returned by
98 .BR uname ()
99 (indeed, some systems allow a 256-byte hostname and an 8-byte nodename),
100 but this is true on Linux.
101 The same holds for
102 .BR setdomainname (2)
103 and the \fIdomainname\fP field.
104 .LP
105 The length of the fields in the struct varies.
106 Some operating systems
107 or libraries use a hardcoded 9 or 33 or 65 or 257.
108 Other systems use
109 .B SYS_NMLN
110 or
111 .B _SYS_NMLN
112 or
113 .B UTSLEN
114 or
115 .BR _UTSNAME_LENGTH .
116 Clearly, it is a bad
117 idea to use any of these constants; just use sizeof(...).
118 Often 257 is chosen in order to have room for an internet hostname.
119 .LP
120 Part of the utsname information is also accessible via
121 .BR sysctl (2)
122 and via
123 .IR /proc/sys/kernel/ { ostype ,
124 .IR hostname ,
125 .IR osrelease ,
126 .IR version ,
127 .IR domainname }.
128 .SS Underlying kernel interface
129 .LP
130 Over time, increases in the size of the
131 .I utsuname
132 structure have led to three successive versions of
133 .BR uname ():
134 .IR sys_olduname ()
135 (slot
136 .IR __NR_oldolduname ),
137 .IR sys_uname ()
138 (slot
139 .IR __NR_olduname ),
140 and
141 .IR sys_newuname ()
142 (slot
143 .IR __NR_uname) .
144 The first one used length 9 for all fields;
145 the second used 65;
146 the third also uses 65 but adds the \fIdomainname\fP field.
147 The glibc
148 .BR uname ()
149 wrapper function hides these details from applications,
150 invoking the most recent version of the system call provided by the kernel.
151 .SH "SEE ALSO"
152 .BR uname (1),
153 .BR getdomainname (2),
154 .BR gethostname (2)