10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*12836Srich.burridge@oracle.com * Common Development and Distribution License (the "License").
6*12836Srich.burridge@oracle.com * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12836Srich.burridge@oracle.com * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
260Sstevel@tonic-gate /* All Rights Reserved */
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
300Sstevel@tonic-gate * The Regents of the University of California
310Sstevel@tonic-gate * All Rights Reserved
320Sstevel@tonic-gate *
330Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
340Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
350Sstevel@tonic-gate * contributors.
360Sstevel@tonic-gate */
370Sstevel@tonic-gate
380Sstevel@tonic-gate #define __EXTENSIONS__
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <stdio.h>
410Sstevel@tonic-gate #include <stdio.h>
420Sstevel@tonic-gate #include <string.h>
430Sstevel@tonic-gate #include <locale.h>
440Sstevel@tonic-gate #include <unistd.h>
450Sstevel@tonic-gate #include <stdlib.h>
460Sstevel@tonic-gate #include <errno.h>
470Sstevel@tonic-gate #include <sys/fcntl.h>
480Sstevel@tonic-gate #include <sys/stat.h>
490Sstevel@tonic-gate #include <sys/utsname.h>
500Sstevel@tonic-gate #include <sys/systeminfo.h>
510Sstevel@tonic-gate
520Sstevel@tonic-gate static void usage(void);
530Sstevel@tonic-gate
540Sstevel@tonic-gate /* ARGSUSED */
550Sstevel@tonic-gate int
main(int argc,char * argv[],char * envp[])560Sstevel@tonic-gate main(int argc, char *argv[], char *envp[])
570Sstevel@tonic-gate {
580Sstevel@tonic-gate char *nodename;
590Sstevel@tonic-gate char *optstring = "asnrpvmiS:X";
600Sstevel@tonic-gate int sflg = 0, nflg = 0, rflg = 0, vflg = 0, mflg = 0;
610Sstevel@tonic-gate int pflg = 0, iflg = 0, Sflg = 0;
620Sstevel@tonic-gate int errflg = 0, optlet;
630Sstevel@tonic-gate int Xflg = 0;
640Sstevel@tonic-gate struct utsname unstr, *un;
650Sstevel@tonic-gate char fmt_string[] = " %.*s";
660Sstevel@tonic-gate char *fs = &fmt_string[1];
670Sstevel@tonic-gate char procbuf[SYS_NMLN];
680Sstevel@tonic-gate
690Sstevel@tonic-gate (void) umask(~(S_IRWXU|S_IRGRP|S_IROTH) & S_IAMB);
700Sstevel@tonic-gate un = &unstr;
710Sstevel@tonic-gate (void) uname(un);
720Sstevel@tonic-gate
730Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
740Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
750Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
760Sstevel@tonic-gate #endif
770Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
780Sstevel@tonic-gate
790Sstevel@tonic-gate while ((optlet = getopt(argc, argv, optstring)) != EOF)
800Sstevel@tonic-gate switch (optlet) {
810Sstevel@tonic-gate case 'a':
820Sstevel@tonic-gate sflg++; nflg++; rflg++; vflg++; mflg++;
83*12836Srich.burridge@oracle.com pflg++;
84*12836Srich.burridge@oracle.com iflg++;
850Sstevel@tonic-gate break;
860Sstevel@tonic-gate case 's':
870Sstevel@tonic-gate sflg++;
880Sstevel@tonic-gate break;
890Sstevel@tonic-gate case 'n':
900Sstevel@tonic-gate nflg++;
910Sstevel@tonic-gate break;
920Sstevel@tonic-gate case 'r':
930Sstevel@tonic-gate rflg++;
940Sstevel@tonic-gate break;
950Sstevel@tonic-gate case 'v':
960Sstevel@tonic-gate vflg++;
970Sstevel@tonic-gate break;
980Sstevel@tonic-gate case 'm':
990Sstevel@tonic-gate mflg++;
1000Sstevel@tonic-gate break;
1010Sstevel@tonic-gate case 'p':
1020Sstevel@tonic-gate pflg++;
1030Sstevel@tonic-gate break;
1040Sstevel@tonic-gate case 'i':
1050Sstevel@tonic-gate iflg++;
1060Sstevel@tonic-gate break;
1070Sstevel@tonic-gate case 'S':
1080Sstevel@tonic-gate Sflg++;
1090Sstevel@tonic-gate nodename = optarg;
1100Sstevel@tonic-gate break;
1110Sstevel@tonic-gate case 'X':
1120Sstevel@tonic-gate Xflg++;
1130Sstevel@tonic-gate break;
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate case '?':
1160Sstevel@tonic-gate errflg++;
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate if (errflg || (optind != argc))
1200Sstevel@tonic-gate usage();
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate if ((Sflg > 1) ||
1230Sstevel@tonic-gate (Sflg && (sflg || nflg || rflg || vflg || mflg || pflg || iflg ||
124*12836Srich.burridge@oracle.com Xflg))) {
1250Sstevel@tonic-gate usage();
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate /* If we're changing the system name */
1290Sstevel@tonic-gate if (Sflg) {
1300Sstevel@tonic-gate int len = strlen(nodename);
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate if (len > SYS_NMLN - 1) {
1330Sstevel@tonic-gate (void) fprintf(stderr, gettext(
134*12836Srich.burridge@oracle.com "uname: name must be <= %d letters\n"),
135*12836Srich.burridge@oracle.com SYS_NMLN-1);
1360Sstevel@tonic-gate exit(1);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate if (sysinfo(SI_SET_HOSTNAME, nodename, len) < 0) {
1390Sstevel@tonic-gate int err = errno;
1400Sstevel@tonic-gate (void) fprintf(stderr, gettext(
141*12836Srich.burridge@oracle.com "uname: error in setting name: %s\n"),
142*12836Srich.burridge@oracle.com strerror(err));
1430Sstevel@tonic-gate exit(1);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate return (0);
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate /*
1490Sstevel@tonic-gate * "uname -s" is the default
1500Sstevel@tonic-gate */
1510Sstevel@tonic-gate if (!(sflg || nflg || rflg || vflg || mflg || pflg || iflg || Xflg))
1520Sstevel@tonic-gate sflg++;
1530Sstevel@tonic-gate if (sflg) {
1540Sstevel@tonic-gate (void) fprintf(stdout, fs, sizeof (un->sysname),
1550Sstevel@tonic-gate un->sysname);
1560Sstevel@tonic-gate fs = fmt_string;
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate if (nflg) {
1590Sstevel@tonic-gate (void) fprintf(stdout, fs, sizeof (un->nodename), un->nodename);
1600Sstevel@tonic-gate fs = fmt_string;
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate if (rflg) {
1630Sstevel@tonic-gate (void) fprintf(stdout, fs, sizeof (un->release), un->release);
1640Sstevel@tonic-gate fs = fmt_string;
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate if (vflg) {
1670Sstevel@tonic-gate (void) fprintf(stdout, fs, sizeof (un->version), un->version);
1680Sstevel@tonic-gate fs = fmt_string;
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate if (mflg) {
1710Sstevel@tonic-gate (void) fprintf(stdout, fs, sizeof (un->machine), un->machine);
1720Sstevel@tonic-gate fs = fmt_string;
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate if (pflg) {
1750Sstevel@tonic-gate if (sysinfo(SI_ARCHITECTURE, procbuf, sizeof (procbuf)) == -1) {
1760Sstevel@tonic-gate (void) fprintf(stderr, gettext(
177*12836Srich.burridge@oracle.com "uname: sysinfo failed\n"));
1780Sstevel@tonic-gate exit(1);
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate (void) fprintf(stdout, fs, strlen(procbuf), procbuf);
1810Sstevel@tonic-gate fs = fmt_string;
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate if (iflg) {
1840Sstevel@tonic-gate if (sysinfo(SI_PLATFORM, procbuf, sizeof (procbuf)) == -1) {
1850Sstevel@tonic-gate (void) fprintf(stderr, gettext(
186*12836Srich.burridge@oracle.com "uname: sysinfo failed\n"));
1870Sstevel@tonic-gate exit(1);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate (void) fprintf(stdout, fs, strlen(procbuf), procbuf);
1900Sstevel@tonic-gate fs = fmt_string;
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate if (Xflg) {
1930Sstevel@tonic-gate int val;
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate (void) fprintf(stdout, "System = %.*s\n", sizeof (un->sysname),
1960Sstevel@tonic-gate un->sysname);
1970Sstevel@tonic-gate (void) fprintf(stdout, "Node = %.*s\n", sizeof (un->nodename),
1980Sstevel@tonic-gate un->nodename);
1990Sstevel@tonic-gate (void) fprintf(stdout, "Release = %.*s\n", sizeof (un->release),
2000Sstevel@tonic-gate un->release);
2010Sstevel@tonic-gate (void) fprintf(stdout, "KernelID = %.*s\n",
2020Sstevel@tonic-gate sizeof (un->version), un->version);
2030Sstevel@tonic-gate (void) fprintf(stdout, "Machine = %.*s\n", sizeof (un->machine),
2040Sstevel@tonic-gate un->machine);
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate /* Not availible on Solaris so hardcode the output */
2070Sstevel@tonic-gate (void) fprintf(stdout, "BusType = <unknown>\n");
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate /* Serialization is not supported in 2.6, so hard code output */
2100Sstevel@tonic-gate (void) fprintf(stdout, "Serial = <unknown>\n");
2110Sstevel@tonic-gate (void) fprintf(stdout, "Users = <unknown>\n");
2120Sstevel@tonic-gate (void) fprintf(stdout, "OEM# = 0\n");
2130Sstevel@tonic-gate (void) fprintf(stdout, "Origin# = 1\n");
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate val = sysconf(_SC_NPROCESSORS_CONF);
2160Sstevel@tonic-gate (void) fprintf(stdout, "NumCPU = %d\n", val);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate (void) putchar('\n');
2190Sstevel@tonic-gate return (0);
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate static void
usage(void)2230Sstevel@tonic-gate usage(void)
2240Sstevel@tonic-gate {
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate (void) fprintf(stderr, gettext(
227*12836Srich.burridge@oracle.com "usage: uname [-snrvmapiX]\n"
228*12836Srich.burridge@oracle.com " uname [-S system_name]\n"));
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate exit(1);
2310Sstevel@tonic-gate }
232