8672 proc_t changes broke genunix dmods and walker
[unleashed.git] / usr / src / cmd / uname / uname.c
blob2c43b50cd6efedd68ee26a99922200e35478e191
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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
31 * All Rights Reserved
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
35 * contributors.
38 #define __EXTENSIONS__
39 #include <sys/types.h>
40 #include <stdio.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <locale.h>
44 #include <unistd.h>
45 #include <stdlib.h>
46 #include <errno.h>
47 #include <sys/fcntl.h>
48 #include <sys/stat.h>
49 #include <sys/utsname.h>
50 #include <sys/systeminfo.h>
52 static void usage(void);
54 /* ARGSUSED */
55 int
56 main(int argc, char *argv[], char *envp[])
58 char *nodename;
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;
63 int Xflg = 0;
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);
70 un = &unstr;
71 (void) uname(un);
73 (void) setlocale(LC_ALL, "");
74 #if !defined(TEXT_DOMAIN)
75 #define TEXT_DOMAIN "SYS_TEST"
76 #endif
77 (void) textdomain(TEXT_DOMAIN);
79 while ((optlet = getopt(argc, argv, optstring)) != EOF)
80 switch (optlet) {
81 case 'a':
82 sflg++; nflg++; rflg++; vflg++; mflg++;
83 pflg++;
84 iflg++;
85 break;
86 case 's':
87 sflg++;
88 break;
89 case 'n':
90 nflg++;
91 break;
92 case 'r':
93 rflg++;
94 break;
95 case 'v':
96 vflg++;
97 break;
98 case 'm':
99 mflg++;
100 break;
101 case 'p':
102 pflg++;
103 break;
104 case 'i':
105 iflg++;
106 break;
107 case 'S':
108 Sflg++;
109 nodename = optarg;
110 break;
111 case 'X':
112 Xflg++;
113 break;
115 case '?':
116 errflg++;
119 if (errflg || (optind != argc))
120 usage();
122 if ((Sflg > 1) ||
123 (Sflg && (sflg || nflg || rflg || vflg || mflg || pflg || iflg ||
124 Xflg))) {
125 usage();
128 /* If we're changing the system name */
129 if (Sflg) {
130 int len = strlen(nodename);
132 if (len > SYS_NMLN - 1) {
133 (void) fprintf(stderr, gettext(
134 "uname: name must be <= %d letters\n"),
135 SYS_NMLN-1);
136 exit(1);
138 if (sysinfo(SI_SET_HOSTNAME, nodename, len) < 0) {
139 int err = errno;
140 (void) fprintf(stderr, gettext(
141 "uname: error in setting name: %s\n"),
142 strerror(err));
143 exit(1);
145 return (0);
149 * "uname -s" is the default
151 if (!(sflg || nflg || rflg || vflg || mflg || pflg || iflg || Xflg))
152 sflg++;
153 if (sflg) {
154 (void) fprintf(stdout, fs, sizeof (un->sysname),
155 un->sysname);
156 fs = fmt_string;
158 if (nflg) {
159 (void) fprintf(stdout, fs, sizeof (un->nodename), un->nodename);
160 fs = fmt_string;
162 if (rflg) {
163 (void) fprintf(stdout, fs, sizeof (un->release), un->release);
164 fs = fmt_string;
166 if (vflg) {
167 (void) fprintf(stdout, fs, sizeof (un->version), un->version);
168 fs = fmt_string;
170 if (mflg) {
171 (void) fprintf(stdout, fs, sizeof (un->machine), un->machine);
172 fs = fmt_string;
174 if (pflg) {
175 if (sysinfo(SI_ARCHITECTURE, procbuf, sizeof (procbuf)) == -1) {
176 (void) fprintf(stderr, gettext(
177 "uname: sysinfo failed\n"));
178 exit(1);
180 (void) fprintf(stdout, fs, strlen(procbuf), procbuf);
181 fs = fmt_string;
183 if (iflg) {
184 if (sysinfo(SI_PLATFORM, procbuf, sizeof (procbuf)) == -1) {
185 (void) fprintf(stderr, gettext(
186 "uname: sysinfo failed\n"));
187 exit(1);
189 (void) fprintf(stdout, fs, strlen(procbuf), procbuf);
190 fs = fmt_string;
192 if (Xflg) {
193 int val;
195 (void) fprintf(stdout, "System = %.*s\n", sizeof (un->sysname),
196 un->sysname);
197 (void) fprintf(stdout, "Node = %.*s\n", sizeof (un->nodename),
198 un->nodename);
199 (void) fprintf(stdout, "Release = %.*s\n", sizeof (un->release),
200 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),
204 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');
219 return (0);
222 static void
223 usage(void)
226 (void) fprintf(stderr, gettext(
227 "usage: uname [-snrvmapiX]\n"
228 " uname [-S system_name]\n"));
230 exit(1);