Print this page
3788 /etc/bootrc is defunct and should be removed
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/prtconf/prtconf.c
+++ new/usr/src/cmd/prtconf/prtconf.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 29 #include <stdio.h>
30 30 #include <stdarg.h>
31 31 #include <stdlib.h>
32 32 #include <unistd.h>
33 33 #include <strings.h>
34 34 #include <sys/systeminfo.h>
35 35 #include <sys/types.h>
36 36 #include <sys/stat.h>
37 37 #include "prtconf.h"
38 38
39 39 struct prt_opts opts;
40 40 struct prt_dbg dbg;
41 41 static char new_path[MAXPATHLEN];
42 42
43 43 #define INDENT_LENGTH 4
44 44
45 45 #ifdef __x86
46 46 static const char *usage = "%s [ -V | -x | -abcdvpPD ] [ <device_path > ]\n";
47 47 #else
48 48 static const char *usage =
49 49 "%s [ -F | -V | -x | -abcdvpPD ][ <device_path > ]\n";
50 50 #endif /* __x86 */
51 51
52 52 static void
53 53 setpname(const char *name)
54 54 {
55 55 char *p;
56 56
57 57 if (name == NULL)
58 58 opts.o_progname = "prtconf";
59 59 else if (p = strrchr(name, '/'))
60 60 opts.o_progname = (const char *) p + 1;
61 61 else
62 62 opts.o_progname = name;
63 63 }
64 64
65 65 /*PRINTFLIKE1*/
66 66 void
67 67 dprintf(const char *fmt, ...)
68 68 {
69 69 if (dbg.d_debug) {
70 70 va_list ap;
71 71 va_start(ap, fmt);
72 72 (void) vfprintf(stderr, fmt, ap);
73 73 va_end(ap);
74 74 }
75 75 }
76 76
77 77 void
78 78 indent_to_level(int ilev)
79 79 {
80 80 (void) printf("%*s", INDENT_LENGTH * ilev, "");
81 81 }
82 82
83 83 static void
84 84 cleanup_path(const char *input_path, char *path)
85 85 {
86 86 char *ptr, *ptr2;
87 87 size_t len;
88 88
89 89 if ((input_path == NULL) || (path == NULL))
90 90 return;
91 91
92 92 (void) strcpy(path, input_path);
93 93
94 94 /*LINTED*/
95 95 while (1) {
96 96 len = strlen(path);
97 97 if (len == 0)
98 98 break;
99 99
100 100 /* change substring "//" into "/" */
101 101 if (ptr = strstr(path, "//")) {
102 102 len = strlen(ptr + 1);
103 103 (void) memmove(ptr, ptr + 1, len + 1);
104 104 continue;
105 105 }
106 106 /* change substring "/./" into "/" */
107 107 if (ptr = strstr(path, "/./")) {
108 108 len = strlen(ptr + 2);
109 109 (void) memmove(ptr, ptr + 2, len + 1);
110 110 continue;
111 111 }
112 112
113 113 /* change substring "/<foo>/../" into "/" */
114 114 if (ptr = strstr(path, "/../")) {
115 115 len = strlen(ptr + 3);
116 116 *ptr = '\0';
117 117 ptr2 = strrchr(path, (int)'/');
118 118 if (ptr2 == NULL) {
119 119 /* path had a leading "/../" */
120 120 ptr2 = path;
121 121 }
122 122 (void) memmove(ptr2, ptr + 3, len + 1);
123 123 continue;
124 124 }
125 125
126 126 /* change trailing "/<foo>/.." into "/" */
127 127 if ((len >= 3) &&
128 128 (path[len - 3] == '/') &&
129 129 (path[len - 2] == '.') &&
130 130 (path[len - 1] == '.')) {
131 131 path[len - 3] = '\0';
132 132 ptr2 = strrchr(path, (int)'/');
133 133 if (ptr2 != NULL) {
134 134 ptr2[1] = '\0';
135 135 } else {
136 136 /* path was "/.." */
137 137 path[0] = '/';
138 138 path[1] = '\0';
139 139 }
140 140 continue;
141 141 }
142 142
143 143 /* change trailing "/." into "/" */
144 144 if ((len >= 2) &&
145 145 (path[len - 2] == '/') &&
146 146 (path[len - 1] == '.')) {
147 147 path[len - 1] = '\0';
148 148 continue;
149 149 }
150 150
151 151 /* remove trailing "/" unless it's the root */
152 152 if ((len > 1) && (path[len - 1] == '/')) {
153 153 path[len - 1] = '\0';
154 154 continue;
155 155 }
156 156
157 157 break;
158 158 }
159 159 }
160 160
161 161
162 162 /*
163 163 * debug version has two more flags:
164 164 * -L force load driver
165 165 * -M: print per driver list
166 166 */
167 167
168 168 #ifdef DEBUG
169 169 static const char *optstring = "abcdDvVxpPFf:M:dLuC";
170 170 #else
171 171 static const char *optstring = "abcdDvVxpPFf:uC";
172 172 #endif /* DEBUG */
173 173
174 174 int
175 175 main(int argc, char *argv[])
176 176 {
177 177 long pagesize, npages;
178 178 int c, ret;
179 179 char hw_provider[SYS_NMLN];
180 180
181 181 setpname(argv[0]);
182 182 opts.o_promdev = "/dev/openprom";
183 183
184 184 while ((c = getopt(argc, argv, optstring)) != -1) {
185 185 switch (c) {
186 186 case 'a':
187 187 ++opts.o_ancestors;
188 188 break;
189 189 case 'b':
190 190 ++opts.o_productinfo;
191 191 break;
192 192 case 'c':
193 193 ++opts.o_children;
194 194 break;
195 195 case 'd':
196 196 ++opts.o_pciid;
197 197 break;
198 198 case 'D':
199 199 ++opts.o_drv_name;
200 200 break;
201 201 case 'v':
202 202 ++opts.o_verbose;
203 203 break;
204 204 case 'p':
205 205 ++opts.o_prominfo;
206 206 break;
207 207 case 'f':
208 208 opts.o_promdev = optarg;
209 209 break;
210 210 case 'V':
211 211 ++opts.o_promversion;
212 212 break;
213 213 case 'x':
214 214 ++opts.o_prom_ready64;
215 215 break;
216 216 case 'F':
217 217 ++opts.o_fbname;
218 218 ++opts.o_noheader;
219 219 break;
220 220 case 'P':
221 221 ++opts.o_pseudodevs;
222 222 break;
223 223 case 'C':
224 224 ++opts.o_forcecache;
225 225 break;
226 226 #ifdef DEBUG
227 227 case 'M':
228 228 dbg.d_drivername = optarg;
229 229 ++dbg.d_bydriver;
230 230 break;
231 231 case 'L':
232 232 ++dbg.d_forceload;
233 233 break;
234 234 #endif /* DEBUG */
235 235
236 236 default:
237 237 (void) fprintf(stderr, usage, opts.o_progname);
238 238 return (1);
239 239 }
240 240 }
241 241
242 242 (void) uname(&opts.o_uts);
243 243
244 244 if (opts.o_fbname)
245 245 return (do_fbname());
246 246
247 247 if (opts.o_promversion)
248 248 return (do_promversion());
249 249
250 250 if (opts.o_prom_ready64)
251 251 return (do_prom_version64());
252 252
253 253 if (opts.o_productinfo)
254 254 return (do_productinfo());
255 255
256 256 opts.o_devices_path = NULL;
257 257 opts.o_devt = DDI_DEV_T_NONE;
258 258 opts.o_target = 0;
259 259 if (optind < argc) {
260 260 struct stat sinfo;
261 261 char *path = argv[optind];
262 262 int error;
263 263
264 264 if (opts.o_prominfo) {
265 265 /* PROM tree cannot be used with path */
266 266 (void) fprintf(stderr, "%s: path and -p option are "
267 267 "mutually exclusive\n", opts.o_progname);
268 268 return (1);
269 269 }
270 270
271 271 if (strlen(path) >= MAXPATHLEN) {
272 272 (void) fprintf(stderr, "%s: "
273 273 "path specified is too long\n", opts.o_progname);
274 274 return (1);
275 275 }
276 276
277 277 if (error = stat(path, &sinfo)) {
278 278
279 279 /* an invalid path was specified */
280 280 (void) fprintf(stderr, "%s: invalid path specified\n",
281 281 opts.o_progname);
282 282 return (1);
283 283
284 284 } else if (((sinfo.st_mode & S_IFMT) == S_IFCHR) ||
285 285 ((sinfo.st_mode & S_IFMT) == S_IFBLK)) {
286 286
287 287 opts.o_devt = sinfo.st_rdev;
288 288 error = 0;
289 289
290 290 } else if ((sinfo.st_mode & S_IFMT) == S_IFDIR) {
291 291 size_t len, plen;
292 292
293 293 /* clean up the path */
294 294 cleanup_path(path, new_path);
295 295
296 296 len = strlen(new_path);
297 297 plen = strlen("/devices");
298 298 if (len < plen) {
299 299 /* This is not a valid /devices path */
300 300 error = 1;
301 301 } else if ((len == plen) &&
302 302 (strcmp(new_path, "/devices") == 0)) {
303 303 /* /devices is the root nexus */
304 304 opts.o_devices_path = "/";
305 305 error = 0;
306 306 } else if (strncmp(new_path, "/devices/", plen + 1)) {
307 307 /* This is not a valid /devices path */
308 308 error = 1;
309 309 } else {
310 310 /* a /devices/ path was specified */
311 311 opts.o_devices_path = new_path + plen;
312 312 error = 0;
313 313 }
314 314
315 315 } else {
316 316 /* an invalid device path was specified */
317 317 error = 1;
318 318 }
319 319
320 320 if (error) {
321 321 (void) fprintf(stderr, "%s: "
322 322 "invalid device path specified\n",
323 323 opts.o_progname);
324 324 return (1);
325 325 }
326 326
327 327 opts.o_target = 1;
328 328 }
329 329
330 330 if ((opts.o_ancestors || opts.o_children) && (!opts.o_target)) {
331 331 (void) fprintf(stderr, "%s: options require a device path\n",
332 332 opts.o_progname);
333 333 return (1);
↓ open down ↓ |
333 lines elided |
↑ open up ↑ |
334 334 }
335 335
336 336 if (opts.o_target) {
337 337 prtconf_devinfo();
338 338 return (0);
339 339 }
340 340
341 341 ret = sysinfo(SI_HW_PROVIDER, hw_provider, sizeof (hw_provider));
342 342 /*
343 343 * If 0 bytes are returned (the system returns '1', for the \0),
344 - * we're probably on x86, and there has been no si-hw-provider
345 - * set in /etc/bootrc, default to Oracle.
344 + * we're probably on x86, default to Oracle.
346 345 */
347 346 if (ret <= 1) {
348 347 (void) strncpy(hw_provider, "Oracle Corporation",
349 348 sizeof (hw_provider));
350 349 }
351 350 (void) printf("System Configuration: %s %s\n", hw_provider,
352 351 opts.o_uts.machine);
353 352
354 353 pagesize = sysconf(_SC_PAGESIZE);
355 354 npages = sysconf(_SC_PHYS_PAGES);
356 355 (void) printf("Memory size: ");
357 356 if (pagesize == -1 || npages == -1)
358 357 (void) printf("unable to determine\n");
359 358 else {
360 359 const int64_t kbyte = 1024;
361 360 const int64_t mbyte = 1024 * 1024;
362 361 int64_t ii = (int64_t)pagesize * npages;
363 362
364 363 if (ii >= mbyte)
365 364 (void) printf("%ld Megabytes\n",
366 365 (long)((ii+mbyte-1) / mbyte));
367 366 else
368 367 (void) printf("%ld Kilobytes\n",
369 368 (long)((ii+kbyte-1) / kbyte));
370 369 }
371 370
372 371 if (opts.o_prominfo) {
373 372 (void) printf("System Peripherals (PROM Nodes):\n\n");
374 373 if (do_prominfo() == 0)
375 374 return (0);
376 375 (void) fprintf(stderr, "%s: Defaulting to non-PROM mode...\n",
377 376 opts.o_progname);
378 377 }
379 378
380 379 (void) printf("System Peripherals (Software Nodes):\n\n");
381 380
382 381 (void) prtconf_devinfo();
383 382
384 383 return (0);
385 384 }
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX