4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
25 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
29 * University Copyright- Copyright (c) 1982, 1986, 1988
30 * The Regents of the University of California
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
38 #define __EXTENSIONS__
39 #include <sys/types.h>
47 #include <sys/fcntl.h>
49 #include <sys/utsname.h>
50 #include <sys/systeminfo.h>
52 static void usage(void);
56 main(int argc
, char *argv
[], char *envp
[])
59 char *optstring
= "asnrpvmiS:X";
60 int sflg
= 0, nflg
= 0, rflg
= 0, vflg
= 0, mflg
= 0;
61 int pflg
= 0, iflg
= 0, Sflg
= 0;
62 int errflg
= 0, optlet
;
64 struct utsname unstr
, *un
;
65 char fmt_string
[] = " %.*s";
66 char *fs
= &fmt_string
[1];
67 char procbuf
[SYS_NMLN
];
69 (void) umask(~(S_IRWXU
|S_IRGRP
|S_IROTH
) & S_IAMB
);
73 (void) setlocale(LC_ALL
, "");
74 #if !defined(TEXT_DOMAIN)
75 #define TEXT_DOMAIN "SYS_TEST"
77 (void) textdomain(TEXT_DOMAIN
);
79 while ((optlet
= getopt(argc
, argv
, optstring
)) != EOF
)
82 sflg
++; nflg
++; rflg
++; vflg
++; mflg
++;
119 if (errflg
|| (optind
!= argc
))
123 (Sflg
&& (sflg
|| nflg
|| rflg
|| vflg
|| mflg
|| pflg
|| iflg
||
128 /* If we're changing the system name */
130 int len
= strlen(nodename
);
132 if (len
> SYS_NMLN
- 1) {
133 (void) fprintf(stderr
, gettext(
134 "uname: name must be <= %d letters\n"),
138 if (sysinfo(SI_SET_HOSTNAME
, nodename
, len
) < 0) {
140 (void) fprintf(stderr
, gettext(
141 "uname: error in setting name: %s\n"),
149 * "uname -s" is the default
151 if (!(sflg
|| nflg
|| rflg
|| vflg
|| mflg
|| pflg
|| iflg
|| Xflg
))
154 (void) fprintf(stdout
, fs
, sizeof (un
->sysname
),
159 (void) fprintf(stdout
, fs
, sizeof (un
->nodename
), un
->nodename
);
163 (void) fprintf(stdout
, fs
, sizeof (un
->release
), un
->release
);
167 (void) fprintf(stdout
, fs
, sizeof (un
->version
), un
->version
);
171 (void) fprintf(stdout
, fs
, sizeof (un
->machine
), un
->machine
);
175 if (sysinfo(SI_ARCHITECTURE
, procbuf
, sizeof (procbuf
)) == -1) {
176 (void) fprintf(stderr
, gettext(
177 "uname: sysinfo failed\n"));
180 (void) fprintf(stdout
, fs
, strlen(procbuf
), procbuf
);
184 if (sysinfo(SI_PLATFORM
, procbuf
, sizeof (procbuf
)) == -1) {
185 (void) fprintf(stderr
, gettext(
186 "uname: sysinfo failed\n"));
189 (void) fprintf(stdout
, fs
, strlen(procbuf
), procbuf
);
195 (void) fprintf(stdout
, "System = %.*s\n", sizeof (un
->sysname
),
197 (void) fprintf(stdout
, "Node = %.*s\n", sizeof (un
->nodename
),
199 (void) fprintf(stdout
, "Release = %.*s\n", sizeof (un
->release
),
201 (void) fprintf(stdout
, "KernelID = %.*s\n",
202 sizeof (un
->version
), un
->version
);
203 (void) fprintf(stdout
, "Machine = %.*s\n", sizeof (un
->machine
),
206 /* Not availible on Solaris so hardcode the output */
207 (void) fprintf(stdout
, "BusType = <unknown>\n");
209 /* Serialization is not supported in 2.6, so hard code output */
210 (void) fprintf(stdout
, "Serial = <unknown>\n");
211 (void) fprintf(stdout
, "Users = <unknown>\n");
212 (void) fprintf(stdout
, "OEM# = 0\n");
213 (void) fprintf(stdout
, "Origin# = 1\n");
215 val
= sysconf(_SC_NPROCESSORS_CONF
);
216 (void) fprintf(stdout
, "NumCPU = %d\n", val
);
218 (void) putchar('\n');
226 (void) fprintf(stderr
, gettext(
227 "usage: uname [-snrvmapiX]\n"
228 " uname [-S system_name]\n"));