1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1993-1994, by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate */ 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * This program replicates the function of the links from a machine name 28*0Sstevel@tonic-gate * (such as sun4c) through /usr/kvm to true or false as appropriate. It 29*0Sstevel@tonic-gate * knows the correct special cases. 30*0Sstevel@tonic-gate * 31*0Sstevel@tonic-gate * IMPORTANT NOTE: 32*0Sstevel@tonic-gate * 33*0Sstevel@tonic-gate * Do not modify this program to know about additional special cases or 34*0Sstevel@tonic-gate * reflect new platforms or instruction set architectures. This is a 35*0Sstevel@tonic-gate * deprecated interface and strictly for backwards compatibility. This 36*0Sstevel@tonic-gate * is psarc/1992/171. Note the following excerpt from the opinion: 37*0Sstevel@tonic-gate * 38*0Sstevel@tonic-gate * It is most important to note that the manual page states in 39*0Sstevel@tonic-gate * the NOTES section: "The machid family of commands is 40*0Sstevel@tonic-gate * obsolete. Use uname -p and uname -m instead." 41*0Sstevel@tonic-gate * 42*0Sstevel@tonic-gate * The intent of Kernel Architecture Project team is to provide 43*0Sstevel@tonic-gate * only enough functionality to mimic the existing definitions 44*0Sstevel@tonic-gate * on the SPARC and Intel x86 versions of Solaris 2.x. No new 45*0Sstevel@tonic-gate * identifiers will ever be added to the documented and 46*0Sstevel@tonic-gate * undocumented identifiers listed above. 47*0Sstevel@tonic-gate */ 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate #include <errno.h> 52*0Sstevel@tonic-gate #include <stdlib.h> 53*0Sstevel@tonic-gate #include <stdio.h> 54*0Sstevel@tonic-gate #include <string.h> 55*0Sstevel@tonic-gate #include <limits.h> 56*0Sstevel@tonic-gate #include <sys/systeminfo.h> 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate static char static_buf[SYS_NMLN]; 59*0Sstevel@tonic-gate static char *progname; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate static void get_info_item(int command, char **buf, long *count); 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate /* ARGSUSED */ 64*0Sstevel@tonic-gate int 65*0Sstevel@tonic-gate main(int argc, char *argv[], char *envp[]) 66*0Sstevel@tonic-gate { 67*0Sstevel@tonic-gate char *buf = &static_buf[0]; 68*0Sstevel@tonic-gate long buflen = SYS_NMLN; 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate if ((progname = strrchr(argv[0], '/')) == NULL) 71*0Sstevel@tonic-gate progname = argv[0]; 72*0Sstevel@tonic-gate else 73*0Sstevel@tonic-gate progname++; 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate /* 76*0Sstevel@tonic-gate * First possible match is on the processor type. 77*0Sstevel@tonic-gate * 78*0Sstevel@tonic-gate * Special case for architectures: i386 matches i486 and visa versa. 79*0Sstevel@tonic-gate */ 80*0Sstevel@tonic-gate get_info_item(SI_ARCHITECTURE, &buf, &buflen); 81*0Sstevel@tonic-gate if (strcmp(buf, progname) == 0) 82*0Sstevel@tonic-gate return (0); 83*0Sstevel@tonic-gate if ((strcmp(buf, "i386") == 0 && strcmp(progname, "i486") == 0) || 84*0Sstevel@tonic-gate (strcmp(buf, "i486") == 0 && strcmp(progname, "i386") == 0)) 85*0Sstevel@tonic-gate return (0); 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate /* 88*0Sstevel@tonic-gate * Next possible match is the machine, or more exactly, the value 89*0Sstevel@tonic-gate * which would be returned by uname(2) in the machine field or uname(1) 90*0Sstevel@tonic-gate * with the -m option. For historical reasons this is really is 91*0Sstevel@tonic-gate * often a class of platforms which are identical to userland processes 92*0Sstevel@tonic-gate * such as sun4c, sun4m, etc. 93*0Sstevel@tonic-gate */ 94*0Sstevel@tonic-gate get_info_item(SI_MACHINE, &buf, &buflen); 95*0Sstevel@tonic-gate if (strcmp(buf, progname) == 0) 96*0Sstevel@tonic-gate return (0); 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate /* 99*0Sstevel@tonic-gate * Finally, match the vendor. We hardwire in one historical match. 100*0Sstevel@tonic-gate */ 101*0Sstevel@tonic-gate get_info_item(SI_HW_PROVIDER, &buf, &buflen); 102*0Sstevel@tonic-gate if (strcmp(buf, progname) == 0) 103*0Sstevel@tonic-gate return (0); 104*0Sstevel@tonic-gate if (strcasecmp(buf, "Sun_Microsystems") == 0 && 105*0Sstevel@tonic-gate strcmp("sun", progname) == 0) 106*0Sstevel@tonic-gate return (0); 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate return (255); 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate /* 112*0Sstevel@tonic-gate * get_info_item is a wrapper around the sysinfo system call. It makes sure 113*0Sstevel@tonic-gate * the buffer is large enough, returning a larger buffer if needed. On 114*0Sstevel@tonic-gate * unrecoverable error, it exits. An error message doesn't help and makes 115*0Sstevel@tonic-gate * this tiny program link stdio and maybe deal with internationalization, 116*0Sstevel@tonic-gate * so the best thing is to die silently. Note that the larger buffer is 117*0Sstevel@tonic-gate * retained for later use. Reality is that the buffer will always be big 118*0Sstevel@tonic-gate * enough, but this is coded to the spec rather than implementation. 119*0Sstevel@tonic-gate */ 120*0Sstevel@tonic-gate static void 121*0Sstevel@tonic-gate get_info_item(int command, char **buf, long *count) 122*0Sstevel@tonic-gate { 123*0Sstevel@tonic-gate long error; 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate error = sysinfo(command, *buf, *count); 126*0Sstevel@tonic-gate if (error > *count) { 127*0Sstevel@tonic-gate *count = error; 128*0Sstevel@tonic-gate if (*buf != static_buf) { 129*0Sstevel@tonic-gate free(*buf); 130*0Sstevel@tonic-gate } 131*0Sstevel@tonic-gate *buf = (char *) malloc(*count); 132*0Sstevel@tonic-gate error = sysinfo(command, *buf, *count); 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate if (error == -1) 136*0Sstevel@tonic-gate exit(-1); 137*0Sstevel@tonic-gate } 138