1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate * This command can now print the value of data items
32*7c478bd9Sstevel@tonic-gate * from [1] /dev/kmem is the default, and [2] a named
33*7c478bd9Sstevel@tonic-gate * file passed with the -n argument. If the read is from
34*7c478bd9Sstevel@tonic-gate * /dev/kmem, we also print the value of BSS symbols.
35*7c478bd9Sstevel@tonic-gate * The logic to support this is: if read is from file,
36*7c478bd9Sstevel@tonic-gate * [1] find the section number of .bss, [2] look through
37*7c478bd9Sstevel@tonic-gate * nlist for symbols that are in .bss section and zero
38*7c478bd9Sstevel@tonic-gate * the n_value field. At print time, if the n_value field
39*7c478bd9Sstevel@tonic-gate * is non-zero, print the info.
40*7c478bd9Sstevel@tonic-gate *
41*7c478bd9Sstevel@tonic-gate * This protects us from trying to read a bss symbol from
42*7c478bd9Sstevel@tonic-gate * the file and, possibly, dropping core.
43*7c478bd9Sstevel@tonic-gate *
44*7c478bd9Sstevel@tonic-gate * When reading from /dev/kmem, the n_value field is the
45*7c478bd9Sstevel@tonic-gate * seek address, and the contents are read from that address.
46*7c478bd9Sstevel@tonic-gate *
47*7c478bd9Sstevel@tonic-gate * NOTE: when reading from /dev/kmem, the actual, incore
48*7c478bd9Sstevel@tonic-gate * values will be printed, for example: the current nodename
49*7c478bd9Sstevel@tonic-gate * will be printed, etc.
50*7c478bd9Sstevel@tonic-gate *
51*7c478bd9Sstevel@tonic-gate * the cmn line usage is: sysdef -i -n namelist -h -d -D
52*7c478bd9Sstevel@tonic-gate * (-i for incore, though this is now the default, the option
53*7c478bd9Sstevel@tonic-gate * is left in place for SVID compatibility)
54*7c478bd9Sstevel@tonic-gate */
55*7c478bd9Sstevel@tonic-gate #include <stdio.h>
56*7c478bd9Sstevel@tonic-gate #include <nlist.h>
57*7c478bd9Sstevel@tonic-gate #include <string.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/var.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
62*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
63*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
64*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
65*7c478bd9Sstevel@tonic-gate #include <sys/resource.h>
66*7c478bd9Sstevel@tonic-gate #include <sys/conf.h>
67*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
68*7c478bd9Sstevel@tonic-gate #include <sys/signal.h>
69*7c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
70*7c478bd9Sstevel@tonic-gate #include <sys/procset.h>
71*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
72*7c478bd9Sstevel@tonic-gate #include <sys/machelf.h>
73*7c478bd9Sstevel@tonic-gate #include <dirent.h>
74*7c478bd9Sstevel@tonic-gate #include <ctype.h>
75*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
76*7c478bd9Sstevel@tonic-gate #include <time.h>
77*7c478bd9Sstevel@tonic-gate #include <unistd.h>
78*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate #include <libelf.h>
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate extern void sysdef_devinfo(void);
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate static gid_t egid;
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate #define SYM_VALUE(sym) (nl[(sym)].n_value)
87*7c478bd9Sstevel@tonic-gate #define MEMSEEK(sym) memseek(sym)
88*7c478bd9Sstevel@tonic-gate #define MEMREAD(var) fread((char *)&var, sizeof (var), 1, \
89*7c478bd9Sstevel@tonic-gate (incore ? memfile : sysfile))
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate struct var v;
92*7c478bd9Sstevel@tonic-gate struct tune tune;
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate int incore = 1; /* The default is "incore" */
95*7c478bd9Sstevel@tonic-gate int bss; /* if read from file, don't read bss symbols */
96*7c478bd9Sstevel@tonic-gate int hostidf = 0; /* 0 == print hostid with other info, */
97*7c478bd9Sstevel@tonic-gate /* 1 == print just the hostid */
98*7c478bd9Sstevel@tonic-gate int devflag = 0; /* SunOS4.x devinfo compatible output */
99*7c478bd9Sstevel@tonic-gate int drvname_flag = 0; /* print the driver name as well as the node */
100*7c478bd9Sstevel@tonic-gate int nflag = 0;
101*7c478bd9Sstevel@tonic-gate char *os = "/dev/ksyms"; /* Wont always have a /kernel/unix */
102*7c478bd9Sstevel@tonic-gate /* This wont fully replace it funtionally */
103*7c478bd9Sstevel@tonic-gate /* but is a reasonable default/placeholder */
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate char *mem = "/dev/kmem";
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate int nstrpush;
108*7c478bd9Sstevel@tonic-gate ssize_t strmsgsz, strctlsz;
109*7c478bd9Sstevel@tonic-gate short ts_maxupri;
110*7c478bd9Sstevel@tonic-gate char sys_name[10];
111*7c478bd9Sstevel@tonic-gate int nlsize, lnsize;
112*7c478bd9Sstevel@tonic-gate FILE *sysfile, *memfile;
113*7c478bd9Sstevel@tonic-gate
114*7c478bd9Sstevel@tonic-gate void setln(char *, int, int, int);
115*7c478bd9Sstevel@tonic-gate void getnlist(void);
116*7c478bd9Sstevel@tonic-gate void memseek(int);
117*7c478bd9Sstevel@tonic-gate void devices(void);
118*7c478bd9Sstevel@tonic-gate void sysdev(void);
119*7c478bd9Sstevel@tonic-gate int setup(char *);
120*7c478bd9Sstevel@tonic-gate void modules(void);
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate struct nlist *nl, *nlptr;
123*7c478bd9Sstevel@tonic-gate int vs, tu, utsnm, bdev, pnstrpush,
124*7c478bd9Sstevel@tonic-gate pstrmsgsz, pstrctlsz, endnm,
125*7c478bd9Sstevel@tonic-gate pts_maxupri, psys_name, fd_cur, fd_max;
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate #define MAXI 300
128*7c478bd9Sstevel@tonic-gate #define MAXL MAXI/11+10
129*7c478bd9Sstevel@tonic-gate #define EXPAND 99
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate struct link {
132*7c478bd9Sstevel@tonic-gate char *l_cfnm; /* config name from master table */
133*7c478bd9Sstevel@tonic-gate int l_funcidx; /* index into name list structure */
134*7c478bd9Sstevel@tonic-gate unsigned int l_soft :1; /* software driver flag from master table */
135*7c478bd9Sstevel@tonic-gate unsigned int l_dtype:1; /* set if block device */
136*7c478bd9Sstevel@tonic-gate unsigned int l_used :1; /* set when device entry is printed */
137*7c478bd9Sstevel@tonic-gate } *ln, *lnptr, *majsrch();
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate /* ELF Items */
140*7c478bd9Sstevel@tonic-gate Elf *elfd = NULL;
141*7c478bd9Sstevel@tonic-gate Ehdr *ehdr = NULL;
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gate #ifdef _ELF64
144*7c478bd9Sstevel@tonic-gate #define elf_getehdr elf64_getehdr
145*7c478bd9Sstevel@tonic-gate #define elf_getshdr elf64_getshdr
146*7c478bd9Sstevel@tonic-gate #else
147*7c478bd9Sstevel@tonic-gate #define elf_getehdr elf32_getehdr
148*7c478bd9Sstevel@tonic-gate #define elf_getshdr elf32_getshdr
149*7c478bd9Sstevel@tonic-gate #endif
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate /* This procedure checks if module "name" is currently loaded */
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate int
loaded_mod(const char * name)154*7c478bd9Sstevel@tonic-gate loaded_mod(const char *name)
155*7c478bd9Sstevel@tonic-gate {
156*7c478bd9Sstevel@tonic-gate struct modinfo modinfo;
157*7c478bd9Sstevel@tonic-gate
158*7c478bd9Sstevel@tonic-gate /* mi_nextid of -1 means we're getting info on all modules */
159*7c478bd9Sstevel@tonic-gate modinfo.mi_id = modinfo.mi_nextid = -1;
160*7c478bd9Sstevel@tonic-gate modinfo.mi_info = MI_INFO_ALL;
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate while (modctl(MODINFO, modinfo.mi_id, &modinfo) >= 0)
163*7c478bd9Sstevel@tonic-gate if (strcmp(modinfo.mi_name, name) == 0)
164*7c478bd9Sstevel@tonic-gate return (1);
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate return (0);
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate const char *sysv_transition =
170*7c478bd9Sstevel@tonic-gate "*\n* IPC %s\n*\n"
171*7c478bd9Sstevel@tonic-gate "* The IPC %s module no longer has system-wide limits.\n"
172*7c478bd9Sstevel@tonic-gate "* Please see the \"Solaris Tunable Parameters Reference Manual\" for\n"
173*7c478bd9Sstevel@tonic-gate "* information on how the old limits map to resource controls and\n"
174*7c478bd9Sstevel@tonic-gate "* the prctl(1) and getrctl(2) manual pages for information on\n"
175*7c478bd9Sstevel@tonic-gate "* observing the new limits.\n*\n";
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate const char *sysv_notloaded =
178*7c478bd9Sstevel@tonic-gate "*\n* IPC %s module is not loaded\n*\n";
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate * Emit a message pointing script writers to the new source for
182*7c478bd9Sstevel@tonic-gate * System V IPC information.
183*7c478bd9Sstevel@tonic-gate */
184*7c478bd9Sstevel@tonic-gate void
sysvipc(const char * module,const char * name)185*7c478bd9Sstevel@tonic-gate sysvipc(const char *module, const char *name)
186*7c478bd9Sstevel@tonic-gate {
187*7c478bd9Sstevel@tonic-gate if (loaded_mod(module))
188*7c478bd9Sstevel@tonic-gate (void) printf(sysv_transition, name, name);
189*7c478bd9Sstevel@tonic-gate else
190*7c478bd9Sstevel@tonic-gate (void) printf(sysv_notloaded, name);
191*7c478bd9Sstevel@tonic-gate }
192*7c478bd9Sstevel@tonic-gate
193*7c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])194*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
195*7c478bd9Sstevel@tonic-gate {
196*7c478bd9Sstevel@tonic-gate struct utsname utsname;
197*7c478bd9Sstevel@tonic-gate Elf_Scn *scn;
198*7c478bd9Sstevel@tonic-gate Shdr *shdr;
199*7c478bd9Sstevel@tonic-gate char *name;
200*7c478bd9Sstevel@tonic-gate int ndx;
201*7c478bd9Sstevel@tonic-gate int i;
202*7c478bd9Sstevel@tonic-gate char hostid[256], *end;
203*7c478bd9Sstevel@tonic-gate unsigned long hostval;
204*7c478bd9Sstevel@tonic-gate uint_t rlim_fd_cur, rlim_fd_max;
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate egid = getegid();
207*7c478bd9Sstevel@tonic-gate setegid(getgid());
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "dihDn:?")) != EOF) {
210*7c478bd9Sstevel@tonic-gate switch (i) {
211*7c478bd9Sstevel@tonic-gate case 'D':
212*7c478bd9Sstevel@tonic-gate drvname_flag++;
213*7c478bd9Sstevel@tonic-gate break;
214*7c478bd9Sstevel@tonic-gate case 'd':
215*7c478bd9Sstevel@tonic-gate devflag++;
216*7c478bd9Sstevel@tonic-gate break;
217*7c478bd9Sstevel@tonic-gate case 'h':
218*7c478bd9Sstevel@tonic-gate hostidf++;
219*7c478bd9Sstevel@tonic-gate break;
220*7c478bd9Sstevel@tonic-gate case 'i':
221*7c478bd9Sstevel@tonic-gate incore++; /* In case "-i and -n" passed */
222*7c478bd9Sstevel@tonic-gate break; /* Not logical, but not disallowed */
223*7c478bd9Sstevel@tonic-gate case 'n':
224*7c478bd9Sstevel@tonic-gate nflag = 1;
225*7c478bd9Sstevel@tonic-gate incore--; /* Not incore, use specified file */
226*7c478bd9Sstevel@tonic-gate os = optarg;
227*7c478bd9Sstevel@tonic-gate break;
228*7c478bd9Sstevel@tonic-gate default:
229*7c478bd9Sstevel@tonic-gate fprintf(stderr,
230*7c478bd9Sstevel@tonic-gate "usage: %s [-D -d -i -h -n namelist]\n",
231*7c478bd9Sstevel@tonic-gate argv[0]);
232*7c478bd9Sstevel@tonic-gate return (1);
233*7c478bd9Sstevel@tonic-gate }
234*7c478bd9Sstevel@tonic-gate }
235*7c478bd9Sstevel@tonic-gate
236*7c478bd9Sstevel@tonic-gate /*
237*7c478bd9Sstevel@tonic-gate * Prints hostid of machine.
238*7c478bd9Sstevel@tonic-gate */
239*7c478bd9Sstevel@tonic-gate if (sysinfo(SI_HW_SERIAL, hostid, sizeof (hostid)) == -1) {
240*7c478bd9Sstevel@tonic-gate fprintf(stderr, "hostid: sysinfo failed\n");
241*7c478bd9Sstevel@tonic-gate return (1);
242*7c478bd9Sstevel@tonic-gate }
243*7c478bd9Sstevel@tonic-gate hostval = strtoul(hostid, &end, 10);
244*7c478bd9Sstevel@tonic-gate if (hostval == 0 && end == hostid) {
245*7c478bd9Sstevel@tonic-gate fprintf(stderr, "hostid: hostid string returned by "
246*7c478bd9Sstevel@tonic-gate "sysinfo not numeric: \"%s\"\n", hostid);
247*7c478bd9Sstevel@tonic-gate return (1);
248*7c478bd9Sstevel@tonic-gate }
249*7c478bd9Sstevel@tonic-gate if (!devflag)
250*7c478bd9Sstevel@tonic-gate fprintf(stdout, "*\n* Hostid\n*\n %8.8x\n", hostval);
251*7c478bd9Sstevel@tonic-gate
252*7c478bd9Sstevel@tonic-gate if (hostidf)
253*7c478bd9Sstevel@tonic-gate return (0);
254*7c478bd9Sstevel@tonic-gate
255*7c478bd9Sstevel@tonic-gate if (((sysfile = fopen(os, "r")) == NULL) && nflag) {
256*7c478bd9Sstevel@tonic-gate fprintf(stderr, "cannot open %s\n", os);
257*7c478bd9Sstevel@tonic-gate return (1);
258*7c478bd9Sstevel@tonic-gate }
259*7c478bd9Sstevel@tonic-gate
260*7c478bd9Sstevel@tonic-gate if (sysfile) {
261*7c478bd9Sstevel@tonic-gate if (incore) {
262*7c478bd9Sstevel@tonic-gate int memfd;
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate setegid(egid);
265*7c478bd9Sstevel@tonic-gate if ((memfile = fopen(mem, "r")) == NULL) {
266*7c478bd9Sstevel@tonic-gate fprintf(stderr, "cannot open %s\n", mem);
267*7c478bd9Sstevel@tonic-gate return (1);
268*7c478bd9Sstevel@tonic-gate }
269*7c478bd9Sstevel@tonic-gate setegid(getgid());
270*7c478bd9Sstevel@tonic-gate
271*7c478bd9Sstevel@tonic-gate memfd = fileno(memfile);
272*7c478bd9Sstevel@tonic-gate fcntl(memfd, F_SETFD,
273*7c478bd9Sstevel@tonic-gate fcntl(memfd, F_GETFD, 0) | FD_CLOEXEC);
274*7c478bd9Sstevel@tonic-gate }
275*7c478bd9Sstevel@tonic-gate
276*7c478bd9Sstevel@tonic-gate /*
277*7c478bd9Sstevel@tonic-gate * Use libelf to read both COFF and ELF namelists
278*7c478bd9Sstevel@tonic-gate */
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate if ((elf_version(EV_CURRENT)) == EV_NONE) {
281*7c478bd9Sstevel@tonic-gate fprintf(stderr, "ELF Access Library out of date\n");
282*7c478bd9Sstevel@tonic-gate return (1);
283*7c478bd9Sstevel@tonic-gate }
284*7c478bd9Sstevel@tonic-gate
285*7c478bd9Sstevel@tonic-gate if ((elfd = elf_begin(fileno(sysfile), ELF_C_READ,
286*7c478bd9Sstevel@tonic-gate NULL)) == NULL) {
287*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Unable to elf begin %s (%s)\n",
288*7c478bd9Sstevel@tonic-gate os, elf_errmsg(-1));
289*7c478bd9Sstevel@tonic-gate return (1);
290*7c478bd9Sstevel@tonic-gate }
291*7c478bd9Sstevel@tonic-gate
292*7c478bd9Sstevel@tonic-gate if ((ehdr = elf_getehdr(elfd)) == NULL) {
293*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Can't read Exec header (%s)\n",
294*7c478bd9Sstevel@tonic-gate os, elf_errmsg(-1));
295*7c478bd9Sstevel@tonic-gate return (1);
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate
298*7c478bd9Sstevel@tonic-gate if ((((elf_kind(elfd)) != ELF_K_ELF) &&
299*7c478bd9Sstevel@tonic-gate ((elf_kind(elfd)) != ELF_K_COFF)) ||
300*7c478bd9Sstevel@tonic-gate (ehdr->e_type != ET_EXEC)) {
301*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: invalid file\n", os);
302*7c478bd9Sstevel@tonic-gate elf_end(elfd);
303*7c478bd9Sstevel@tonic-gate return (1);
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate
306*7c478bd9Sstevel@tonic-gate /*
307*7c478bd9Sstevel@tonic-gate * If this is a file read, look for .bss section
308*7c478bd9Sstevel@tonic-gate */
309*7c478bd9Sstevel@tonic-gate
310*7c478bd9Sstevel@tonic-gate if (!incore) {
311*7c478bd9Sstevel@tonic-gate ndx = 1;
312*7c478bd9Sstevel@tonic-gate scn = NULL;
313*7c478bd9Sstevel@tonic-gate while ((scn = elf_nextscn(elfd, scn)) != NULL) {
314*7c478bd9Sstevel@tonic-gate if ((shdr = elf_getshdr(scn)) == NULL) {
315*7c478bd9Sstevel@tonic-gate fprintf(stderr,
316*7c478bd9Sstevel@tonic-gate "%s: Error reading Shdr (%s)\n",
317*7c478bd9Sstevel@tonic-gate os, elf_errmsg(-1));
318*7c478bd9Sstevel@tonic-gate return (1);
319*7c478bd9Sstevel@tonic-gate }
320*7c478bd9Sstevel@tonic-gate name = elf_strptr(elfd, ehdr->e_shstrndx,
321*7c478bd9Sstevel@tonic-gate (size_t)shdr->sh_name);
322*7c478bd9Sstevel@tonic-gate if ((name) && ((strcmp(name, ".bss")) == 0)) {
323*7c478bd9Sstevel@tonic-gate bss = ndx;
324*7c478bd9Sstevel@tonic-gate }
325*7c478bd9Sstevel@tonic-gate ndx++;
326*7c478bd9Sstevel@tonic-gate }
327*7c478bd9Sstevel@tonic-gate } /* (!incore) */
328*7c478bd9Sstevel@tonic-gate }
329*7c478bd9Sstevel@tonic-gate
330*7c478bd9Sstevel@tonic-gate uname(&utsname);
331*7c478bd9Sstevel@tonic-gate if (!devflag)
332*7c478bd9Sstevel@tonic-gate printf("*\n* %s Configuration\n*\n", utsname.machine);
333*7c478bd9Sstevel@tonic-gate
334*7c478bd9Sstevel@tonic-gate if (sysfile) {
335*7c478bd9Sstevel@tonic-gate nlsize = MAXI;
336*7c478bd9Sstevel@tonic-gate lnsize = MAXL;
337*7c478bd9Sstevel@tonic-gate nl = (struct nlist *)calloc(nlsize, sizeof (struct nlist));
338*7c478bd9Sstevel@tonic-gate ln = (struct link *)calloc(lnsize, sizeof (struct link));
339*7c478bd9Sstevel@tonic-gate nlptr = nl;
340*7c478bd9Sstevel@tonic-gate lnptr = ln;
341*7c478bd9Sstevel@tonic-gate
342*7c478bd9Sstevel@tonic-gate bdev = setup("bdevsw");
343*7c478bd9Sstevel@tonic-gate setup("");
344*7c478bd9Sstevel@tonic-gate
345*7c478bd9Sstevel@tonic-gate getnlist();
346*7c478bd9Sstevel@tonic-gate
347*7c478bd9Sstevel@tonic-gate if (!devflag)
348*7c478bd9Sstevel@tonic-gate printf("*\n* Devices\n*\n");
349*7c478bd9Sstevel@tonic-gate devices();
350*7c478bd9Sstevel@tonic-gate if (devflag)
351*7c478bd9Sstevel@tonic-gate return (0);
352*7c478bd9Sstevel@tonic-gate
353*7c478bd9Sstevel@tonic-gate printf("*\n* Loadable Objects\n");
354*7c478bd9Sstevel@tonic-gate
355*7c478bd9Sstevel@tonic-gate modules();
356*7c478bd9Sstevel@tonic-gate }
357*7c478bd9Sstevel@tonic-gate
358*7c478bd9Sstevel@tonic-gate printf("*\n* System Configuration\n*\n");
359*7c478bd9Sstevel@tonic-gate
360*7c478bd9Sstevel@tonic-gate sysdev();
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate if (sysfile) {
363*7c478bd9Sstevel@tonic-gate /* easy stuff */
364*7c478bd9Sstevel@tonic-gate printf("*\n* Tunable Parameters\n*\n");
365*7c478bd9Sstevel@tonic-gate nlptr = nl;
366*7c478bd9Sstevel@tonic-gate vs = setup("v");
367*7c478bd9Sstevel@tonic-gate tu = setup("tune");
368*7c478bd9Sstevel@tonic-gate utsnm = setup("utsname");
369*7c478bd9Sstevel@tonic-gate pnstrpush = setup("nstrpush");
370*7c478bd9Sstevel@tonic-gate pstrmsgsz = setup("strmsgsz");
371*7c478bd9Sstevel@tonic-gate pstrctlsz = setup("strctlsz");
372*7c478bd9Sstevel@tonic-gate pts_maxupri = setup("ts_maxupri");
373*7c478bd9Sstevel@tonic-gate psys_name = setup("sys_name");
374*7c478bd9Sstevel@tonic-gate fd_cur = setup("rlim_fd_cur");
375*7c478bd9Sstevel@tonic-gate fd_max = setup("rlim_fd_max");
376*7c478bd9Sstevel@tonic-gate
377*7c478bd9Sstevel@tonic-gate /*
378*7c478bd9Sstevel@tonic-gate * This assignment to endnm must follow all calls to setup().
379*7c478bd9Sstevel@tonic-gate */
380*7c478bd9Sstevel@tonic-gate endnm = setup("");
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate getnlist();
383*7c478bd9Sstevel@tonic-gate
384*7c478bd9Sstevel@tonic-gate for (nlptr = &nl[vs]; nlptr != &nl[endnm]; nlptr++) {
385*7c478bd9Sstevel@tonic-gate if (nlptr->n_value == 0 &&
386*7c478bd9Sstevel@tonic-gate (incore || nlptr->n_scnum != bss)) {
387*7c478bd9Sstevel@tonic-gate fprintf(stderr, "namelist error on <%s>\n",
388*7c478bd9Sstevel@tonic-gate nlptr->n_name);
389*7c478bd9Sstevel@tonic-gate /* return (1); */
390*7c478bd9Sstevel@tonic-gate }
391*7c478bd9Sstevel@tonic-gate }
392*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(vs)) {
393*7c478bd9Sstevel@tonic-gate MEMSEEK(vs);
394*7c478bd9Sstevel@tonic-gate MEMREAD(v);
395*7c478bd9Sstevel@tonic-gate }
396*7c478bd9Sstevel@tonic-gate printf("%8d maximum memory allowed in buffer cache "
397*7c478bd9Sstevel@tonic-gate "(bufhwm)\n", v.v_bufhwm * 1024);
398*7c478bd9Sstevel@tonic-gate printf("%8d maximum number of processes (v.v_proc)\n",
399*7c478bd9Sstevel@tonic-gate v.v_proc);
400*7c478bd9Sstevel@tonic-gate printf("%8d maximum global priority in sys class "
401*7c478bd9Sstevel@tonic-gate "(MAXCLSYSPRI)\n", v.v_maxsyspri);
402*7c478bd9Sstevel@tonic-gate printf("%8d maximum processes per user id (v.v_maxup)\n",
403*7c478bd9Sstevel@tonic-gate v.v_maxup);
404*7c478bd9Sstevel@tonic-gate printf("%8d auto update time limit in seconds (NAUTOUP)\n",
405*7c478bd9Sstevel@tonic-gate v.v_autoup);
406*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(tu)) {
407*7c478bd9Sstevel@tonic-gate MEMSEEK(tu);
408*7c478bd9Sstevel@tonic-gate MEMREAD(tune);
409*7c478bd9Sstevel@tonic-gate }
410*7c478bd9Sstevel@tonic-gate printf("%8d page stealing low water mark (GPGSLO)\n",
411*7c478bd9Sstevel@tonic-gate tune.t_gpgslo);
412*7c478bd9Sstevel@tonic-gate printf("%8d fsflush run rate (FSFLUSHR)\n",
413*7c478bd9Sstevel@tonic-gate tune.t_fsflushr);
414*7c478bd9Sstevel@tonic-gate printf("%8d minimum resident memory for avoiding "
415*7c478bd9Sstevel@tonic-gate "deadlock (MINARMEM)\n", tune.t_minarmem);
416*7c478bd9Sstevel@tonic-gate printf("%8d minimum swapable memory for avoiding deadlock "
417*7c478bd9Sstevel@tonic-gate "(MINASMEM)\n", tune.t_minasmem);
418*7c478bd9Sstevel@tonic-gate }
419*7c478bd9Sstevel@tonic-gate
420*7c478bd9Sstevel@tonic-gate printf("*\n* Utsname Tunables\n*\n");
421*7c478bd9Sstevel@tonic-gate if (sysfile && SYM_VALUE(utsnm)) {
422*7c478bd9Sstevel@tonic-gate MEMSEEK(utsnm);
423*7c478bd9Sstevel@tonic-gate MEMREAD(utsname);
424*7c478bd9Sstevel@tonic-gate }
425*7c478bd9Sstevel@tonic-gate printf("%8s release (REL)\n", utsname.release);
426*7c478bd9Sstevel@tonic-gate printf("%8s node name (NODE)\n", utsname.nodename);
427*7c478bd9Sstevel@tonic-gate printf("%8s system name (SYS)\n", utsname.sysname);
428*7c478bd9Sstevel@tonic-gate printf("%8s version (VER)\n", utsname.version);
429*7c478bd9Sstevel@tonic-gate
430*7c478bd9Sstevel@tonic-gate if (sysfile) {
431*7c478bd9Sstevel@tonic-gate printf("*\n* Process Resource Limit Tunables "
432*7c478bd9Sstevel@tonic-gate "(Current:Maximum)\n*\n");
433*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(fd_cur)) {
434*7c478bd9Sstevel@tonic-gate MEMSEEK(fd_cur);
435*7c478bd9Sstevel@tonic-gate MEMREAD(rlim_fd_cur);
436*7c478bd9Sstevel@tonic-gate }
437*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(fd_max)) {
438*7c478bd9Sstevel@tonic-gate MEMSEEK(fd_max);
439*7c478bd9Sstevel@tonic-gate MEMREAD(rlim_fd_max);
440*7c478bd9Sstevel@tonic-gate }
441*7c478bd9Sstevel@tonic-gate
442*7c478bd9Sstevel@tonic-gate printf("0x%16.16x:", rlim_fd_cur);
443*7c478bd9Sstevel@tonic-gate printf("0x%16.16x", rlim_fd_max);
444*7c478bd9Sstevel@tonic-gate printf("\tfile descriptors\n");
445*7c478bd9Sstevel@tonic-gate
446*7c478bd9Sstevel@tonic-gate printf("*\n* Streams Tunables\n*\n");
447*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(pnstrpush)) {
448*7c478bd9Sstevel@tonic-gate MEMSEEK(pnstrpush); MEMREAD(nstrpush);
449*7c478bd9Sstevel@tonic-gate printf("%6d maximum number of pushes allowed "
450*7c478bd9Sstevel@tonic-gate "(NSTRPUSH)\n", nstrpush);
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(pstrmsgsz)) {
453*7c478bd9Sstevel@tonic-gate MEMSEEK(pstrmsgsz); MEMREAD(strmsgsz);
454*7c478bd9Sstevel@tonic-gate printf("%6ld maximum stream message size "
455*7c478bd9Sstevel@tonic-gate "(STRMSGSZ)\n", strmsgsz);
456*7c478bd9Sstevel@tonic-gate }
457*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(pstrctlsz)) {
458*7c478bd9Sstevel@tonic-gate MEMSEEK(pstrctlsz); MEMREAD(strctlsz);
459*7c478bd9Sstevel@tonic-gate printf("%6ld max size of ctl part of message "
460*7c478bd9Sstevel@tonic-gate "(STRCTLSZ)\n", strctlsz);
461*7c478bd9Sstevel@tonic-gate }
462*7c478bd9Sstevel@tonic-gate }
463*7c478bd9Sstevel@tonic-gate
464*7c478bd9Sstevel@tonic-gate sysvipc("msgsys", "Messages");
465*7c478bd9Sstevel@tonic-gate sysvipc("semsys", "Semaphores");
466*7c478bd9Sstevel@tonic-gate sysvipc("shmsys", "Shared Memory");
467*7c478bd9Sstevel@tonic-gate
468*7c478bd9Sstevel@tonic-gate if (sysfile) {
469*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(pts_maxupri)) {
470*7c478bd9Sstevel@tonic-gate printf("*\n* Time Sharing Scheduler Tunables\n*\n");
471*7c478bd9Sstevel@tonic-gate MEMSEEK(pts_maxupri); MEMREAD(ts_maxupri);
472*7c478bd9Sstevel@tonic-gate printf("%d maximum time sharing user "
473*7c478bd9Sstevel@tonic-gate "priority (TSMAXUPRI)\n", ts_maxupri);
474*7c478bd9Sstevel@tonic-gate }
475*7c478bd9Sstevel@tonic-gate
476*7c478bd9Sstevel@tonic-gate if (SYM_VALUE(psys_name)) {
477*7c478bd9Sstevel@tonic-gate MEMSEEK(psys_name); MEMREAD(sys_name);
478*7c478bd9Sstevel@tonic-gate printf("%s system class name (SYS_NAME)\n",
479*7c478bd9Sstevel@tonic-gate sys_name);
480*7c478bd9Sstevel@tonic-gate }
481*7c478bd9Sstevel@tonic-gate
482*7c478bd9Sstevel@tonic-gate if (elfd)
483*7c478bd9Sstevel@tonic-gate elf_end(elfd);
484*7c478bd9Sstevel@tonic-gate }
485*7c478bd9Sstevel@tonic-gate return (0);
486*7c478bd9Sstevel@tonic-gate }
487*7c478bd9Sstevel@tonic-gate
488*7c478bd9Sstevel@tonic-gate /*
489*7c478bd9Sstevel@tonic-gate * setup - add an entry to a namelist structure array
490*7c478bd9Sstevel@tonic-gate */
491*7c478bd9Sstevel@tonic-gate int
setup(char * nam)492*7c478bd9Sstevel@tonic-gate setup(char *nam)
493*7c478bd9Sstevel@tonic-gate {
494*7c478bd9Sstevel@tonic-gate int idx;
495*7c478bd9Sstevel@tonic-gate
496*7c478bd9Sstevel@tonic-gate if (nlptr >= &nl[nlsize]) {
497*7c478bd9Sstevel@tonic-gate if ((nl = (struct nlist *)realloc(nl,
498*7c478bd9Sstevel@tonic-gate (nlsize + EXPAND) * sizeof (struct nlist))) == NULL) {
499*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Namelist space allocation failed\n");
500*7c478bd9Sstevel@tonic-gate exit(1);
501*7c478bd9Sstevel@tonic-gate }
502*7c478bd9Sstevel@tonic-gate nlptr = &nl[nlsize];
503*7c478bd9Sstevel@tonic-gate nlsize += EXPAND;
504*7c478bd9Sstevel@tonic-gate }
505*7c478bd9Sstevel@tonic-gate
506*7c478bd9Sstevel@tonic-gate nlptr->n_name = malloc(strlen(nam) + 1); /* pointer to next string */
507*7c478bd9Sstevel@tonic-gate strcpy(nlptr->n_name, nam); /* move name into string table */
508*7c478bd9Sstevel@tonic-gate nlptr->n_type = 0;
509*7c478bd9Sstevel@tonic-gate nlptr->n_value = 0;
510*7c478bd9Sstevel@tonic-gate idx = nlptr++ - nl;
511*7c478bd9Sstevel@tonic-gate return (idx);
512*7c478bd9Sstevel@tonic-gate }
513*7c478bd9Sstevel@tonic-gate
514*7c478bd9Sstevel@tonic-gate /*
515*7c478bd9Sstevel@tonic-gate * Handle the configured devices
516*7c478bd9Sstevel@tonic-gate */
517*7c478bd9Sstevel@tonic-gate void
devices(void)518*7c478bd9Sstevel@tonic-gate devices(void)
519*7c478bd9Sstevel@tonic-gate {
520*7c478bd9Sstevel@tonic-gate setegid(egid);
521*7c478bd9Sstevel@tonic-gate sysdef_devinfo();
522*7c478bd9Sstevel@tonic-gate setegid(getgid());
523*7c478bd9Sstevel@tonic-gate }
524*7c478bd9Sstevel@tonic-gate
525*7c478bd9Sstevel@tonic-gate char *LS_MODULES = "/bin/ls -R -p -i -1 ";
526*7c478bd9Sstevel@tonic-gate char *MODULES_TMPFILE = "/tmp/sysdef.sort.XXXXXX";
527*7c478bd9Sstevel@tonic-gate
528*7c478bd9Sstevel@tonic-gate void
modules()529*7c478bd9Sstevel@tonic-gate modules()
530*7c478bd9Sstevel@tonic-gate {
531*7c478bd9Sstevel@tonic-gate int i;
532*7c478bd9Sstevel@tonic-gate int n_dirs = 0;
533*7c478bd9Sstevel@tonic-gate ino_t *inodes;
534*7c478bd9Sstevel@tonic-gate char *curr, *next;
535*7c478bd9Sstevel@tonic-gate char **dirs;
536*7c478bd9Sstevel@tonic-gate char *modpath, *ls_cmd;
537*7c478bd9Sstevel@tonic-gate char *tmpf;
538*7c478bd9Sstevel@tonic-gate int curr_len, modpathlen;
539*7c478bd9Sstevel@tonic-gate int ls_cmd_len = strlen(LS_MODULES);
540*7c478bd9Sstevel@tonic-gate int sfd;
541*7c478bd9Sstevel@tonic-gate
542*7c478bd9Sstevel@tonic-gate if ((modctl(MODGETPATHLEN, NULL, &modpathlen)) != 0) {
543*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: fail to get module path length\n");
544*7c478bd9Sstevel@tonic-gate exit(1);
545*7c478bd9Sstevel@tonic-gate }
546*7c478bd9Sstevel@tonic-gate if ((modpath = malloc(modpathlen + 1)) == NULL) {
547*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: malloc failed\n");
548*7c478bd9Sstevel@tonic-gate exit(1);
549*7c478bd9Sstevel@tonic-gate }
550*7c478bd9Sstevel@tonic-gate if (modctl(MODGETPATH, NULL, modpath) != 0) {
551*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: fail to get module path\n");
552*7c478bd9Sstevel@tonic-gate exit(1);
553*7c478bd9Sstevel@tonic-gate }
554*7c478bd9Sstevel@tonic-gate
555*7c478bd9Sstevel@tonic-gate /*
556*7c478bd9Sstevel@tonic-gate * Figure out number of directory entries in modpath.
557*7c478bd9Sstevel@tonic-gate * Module paths are stored in a space separated string
558*7c478bd9Sstevel@tonic-gate */
559*7c478bd9Sstevel@tonic-gate curr = modpath;
560*7c478bd9Sstevel@tonic-gate while (curr) {
561*7c478bd9Sstevel@tonic-gate n_dirs++;
562*7c478bd9Sstevel@tonic-gate curr = strchr(curr + 1, ' ');
563*7c478bd9Sstevel@tonic-gate }
564*7c478bd9Sstevel@tonic-gate
565*7c478bd9Sstevel@tonic-gate if (((inodes = (ino_t *)malloc(n_dirs * sizeof (ino_t))) == NULL) ||
566*7c478bd9Sstevel@tonic-gate ((dirs = (char **)malloc(n_dirs * sizeof (char *))) == NULL)) {
567*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: malloc failed\n");
568*7c478bd9Sstevel@tonic-gate exit(1);
569*7c478bd9Sstevel@tonic-gate }
570*7c478bd9Sstevel@tonic-gate
571*7c478bd9Sstevel@tonic-gate if ((tmpf = malloc(strlen(MODULES_TMPFILE) + 1)) == NULL) {
572*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: malloc failed\n");
573*7c478bd9Sstevel@tonic-gate exit(1);
574*7c478bd9Sstevel@tonic-gate }
575*7c478bd9Sstevel@tonic-gate
576*7c478bd9Sstevel@tonic-gate curr = modpath;
577*7c478bd9Sstevel@tonic-gate for (i = 0; i < n_dirs; i++) {
578*7c478bd9Sstevel@tonic-gate int j, len, inode, ino;
579*7c478bd9Sstevel@tonic-gate char line[100], path[100], *pathptr = "";
580*7c478bd9Sstevel@tonic-gate char srtbuf[100], *sorted_fname;
581*7c478bd9Sstevel@tonic-gate FILE *lspipe, *srtpipe, *fp;
582*7c478bd9Sstevel@tonic-gate struct stat stat_buf;
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate if (next = strchr(curr, ' ')) {
585*7c478bd9Sstevel@tonic-gate *next = '\0';
586*7c478bd9Sstevel@tonic-gate }
587*7c478bd9Sstevel@tonic-gate
588*7c478bd9Sstevel@tonic-gate /*
589*7c478bd9Sstevel@tonic-gate * Make sure the module path is present.
590*7c478bd9Sstevel@tonic-gate */
591*7c478bd9Sstevel@tonic-gate if (stat(curr, &stat_buf) == -1) {
592*7c478bd9Sstevel@tonic-gate curr = next ? next + 1 : NULL;
593*7c478bd9Sstevel@tonic-gate inodes[i] = (ino_t)-1;
594*7c478bd9Sstevel@tonic-gate continue;
595*7c478bd9Sstevel@tonic-gate }
596*7c478bd9Sstevel@tonic-gate
597*7c478bd9Sstevel@tonic-gate /*
598*7c478bd9Sstevel@tonic-gate * On sparcs, /platform/SUNW,... can be symbolic link to
599*7c478bd9Sstevel@tonic-gate * /platform/sun4x. We check the inode number of directory
600*7c478bd9Sstevel@tonic-gate * and skip any duplication.
601*7c478bd9Sstevel@tonic-gate */
602*7c478bd9Sstevel@tonic-gate dirs[i] = curr;
603*7c478bd9Sstevel@tonic-gate inodes[i] = stat_buf.st_ino;
604*7c478bd9Sstevel@tonic-gate
605*7c478bd9Sstevel@tonic-gate for (j = 0; inodes[i] != inodes[j]; j++)
606*7c478bd9Sstevel@tonic-gate ;
607*7c478bd9Sstevel@tonic-gate if (j != i) {
608*7c478bd9Sstevel@tonic-gate curr = next ? next + 1 : NULL;
609*7c478bd9Sstevel@tonic-gate continue;
610*7c478bd9Sstevel@tonic-gate }
611*7c478bd9Sstevel@tonic-gate
612*7c478bd9Sstevel@tonic-gate printf("*\n* Loadable Object Path = %s\n*\n", curr);
613*7c478bd9Sstevel@tonic-gate
614*7c478bd9Sstevel@tonic-gate curr_len = strlen(curr);
615*7c478bd9Sstevel@tonic-gate if ((ls_cmd = malloc(ls_cmd_len + curr_len + 1)) == NULL) {
616*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: malloc failed\n");
617*7c478bd9Sstevel@tonic-gate exit(1);
618*7c478bd9Sstevel@tonic-gate }
619*7c478bd9Sstevel@tonic-gate
620*7c478bd9Sstevel@tonic-gate (void) sprintf(ls_cmd, "%s%s", LS_MODULES, curr);
621*7c478bd9Sstevel@tonic-gate
622*7c478bd9Sstevel@tonic-gate /*
623*7c478bd9Sstevel@tonic-gate * List the loadable objects in the directory tree, sorting
624*7c478bd9Sstevel@tonic-gate * them by inode so as to note any hard links. A temporary
625*7c478bd9Sstevel@tonic-gate * file in /tmp is used to store output from sort before
626*7c478bd9Sstevel@tonic-gate * listing.
627*7c478bd9Sstevel@tonic-gate */
628*7c478bd9Sstevel@tonic-gate if ((lspipe = popen(ls_cmd, "r")) == NULL) {
629*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: cannot open ls pipe\n");
630*7c478bd9Sstevel@tonic-gate exit(1);
631*7c478bd9Sstevel@tonic-gate }
632*7c478bd9Sstevel@tonic-gate free(ls_cmd);
633*7c478bd9Sstevel@tonic-gate
634*7c478bd9Sstevel@tonic-gate (void) strcpy(tmpf, MODULES_TMPFILE);
635*7c478bd9Sstevel@tonic-gate if ((sorted_fname = mktemp(tmpf)) == NULL ||
636*7c478bd9Sstevel@tonic-gate (strcmp(sorted_fname, "") == 0)) {
637*7c478bd9Sstevel@tonic-gate fprintf(stderr,
638*7c478bd9Sstevel@tonic-gate "sysdef: cannot create unique tmp file name\n");
639*7c478bd9Sstevel@tonic-gate exit(1);
640*7c478bd9Sstevel@tonic-gate }
641*7c478bd9Sstevel@tonic-gate
642*7c478bd9Sstevel@tonic-gate if ((sfd = open(sorted_fname, O_RDWR|O_CREAT|O_EXCL,
643*7c478bd9Sstevel@tonic-gate 0600)) == -1) {
644*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: cannot open %s\n",
645*7c478bd9Sstevel@tonic-gate sorted_fname);
646*7c478bd9Sstevel@tonic-gate exit(1);
647*7c478bd9Sstevel@tonic-gate }
648*7c478bd9Sstevel@tonic-gate
649*7c478bd9Sstevel@tonic-gate sprintf(srtbuf, "/bin/sort - > %s", sorted_fname);
650*7c478bd9Sstevel@tonic-gate if ((srtpipe = popen(srtbuf, "w")) == NULL) {
651*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: cannot open sort pipe\n");
652*7c478bd9Sstevel@tonic-gate exit(1);
653*7c478bd9Sstevel@tonic-gate }
654*7c478bd9Sstevel@tonic-gate
655*7c478bd9Sstevel@tonic-gate while (fgets(line, 99, lspipe) != NULL) {
656*7c478bd9Sstevel@tonic-gate char *tmp;
657*7c478bd9Sstevel@tonic-gate /*
658*7c478bd9Sstevel@tonic-gate * 'line' has <cr>, skip blank lines & dir entries
659*7c478bd9Sstevel@tonic-gate */
660*7c478bd9Sstevel@tonic-gate if (((len = strlen(line)) <= 1) ||
661*7c478bd9Sstevel@tonic-gate (line[len-2] == '/'))
662*7c478bd9Sstevel@tonic-gate continue;
663*7c478bd9Sstevel@tonic-gate
664*7c478bd9Sstevel@tonic-gate /* remember path of each subdirectory */
665*7c478bd9Sstevel@tonic-gate
666*7c478bd9Sstevel@tonic-gate if (line[0] == '/') {
667*7c478bd9Sstevel@tonic-gate (void) strcpy(path, &line[curr_len]);
668*7c478bd9Sstevel@tonic-gate tmp = strtok(&path[1], ":");
669*7c478bd9Sstevel@tonic-gate if ((tmp == NULL) || (tmp[0] == '\n')) {
670*7c478bd9Sstevel@tonic-gate continue;
671*7c478bd9Sstevel@tonic-gate }
672*7c478bd9Sstevel@tonic-gate pathptr = &path[1];
673*7c478bd9Sstevel@tonic-gate (void) strcat(pathptr, "/");
674*7c478bd9Sstevel@tonic-gate continue;
675*7c478bd9Sstevel@tonic-gate } else {
676*7c478bd9Sstevel@tonic-gate char *tmp1 = strtok(line, " ");
677*7c478bd9Sstevel@tonic-gate tmp = strtok(NULL, "\n");
678*7c478bd9Sstevel@tonic-gate /*
679*7c478bd9Sstevel@tonic-gate * eliminate .conf file
680*7c478bd9Sstevel@tonic-gate */
681*7c478bd9Sstevel@tonic-gate if (strstr(tmp, ".conf")) {
682*7c478bd9Sstevel@tonic-gate continue;
683*7c478bd9Sstevel@tonic-gate }
684*7c478bd9Sstevel@tonic-gate /*
685*7c478bd9Sstevel@tonic-gate * Printing the (inode, path, module)
686*7c478bd9Sstevel@tonic-gate * ripple.
687*7c478bd9Sstevel@tonic-gate */
688*7c478bd9Sstevel@tonic-gate fprintf(srtpipe, "%s %s%s\n",
689*7c478bd9Sstevel@tonic-gate tmp1, pathptr, tmp);
690*7c478bd9Sstevel@tonic-gate }
691*7c478bd9Sstevel@tonic-gate }
692*7c478bd9Sstevel@tonic-gate (void) pclose(lspipe);
693*7c478bd9Sstevel@tonic-gate (void) pclose(srtpipe);
694*7c478bd9Sstevel@tonic-gate
695*7c478bd9Sstevel@tonic-gate /*
696*7c478bd9Sstevel@tonic-gate * A note on data synchronization. We opened sfd above,
697*7c478bd9Sstevel@tonic-gate * before calling popen, to ensure that the tempfile
698*7c478bd9Sstevel@tonic-gate * was created exclusively to prevent a malicious user
699*7c478bd9Sstevel@tonic-gate * from creating a link in /tmp to make us overwrite
700*7c478bd9Sstevel@tonic-gate * another file. We have never read from sfd, there
701*7c478bd9Sstevel@tonic-gate * can be no stale data cached anywhere.
702*7c478bd9Sstevel@tonic-gate */
703*7c478bd9Sstevel@tonic-gate if ((fp = fdopen(sfd, "r")) == NULL) {
704*7c478bd9Sstevel@tonic-gate fprintf(stderr, "sysdef: cannot open sorted file: %s",
705*7c478bd9Sstevel@tonic-gate sorted_fname);
706*7c478bd9Sstevel@tonic-gate exit(1);
707*7c478bd9Sstevel@tonic-gate }
708*7c478bd9Sstevel@tonic-gate inode = -1;
709*7c478bd9Sstevel@tonic-gate while (fgets(line, 99, fp) != NULL) {
710*7c478bd9Sstevel@tonic-gate
711*7c478bd9Sstevel@tonic-gate sscanf(line, "%d %s", &ino, path);
712*7c478bd9Sstevel@tonic-gate if (ino == inode)
713*7c478bd9Sstevel@tonic-gate printf("\thard link: ");
714*7c478bd9Sstevel@tonic-gate printf("%s\n", path);
715*7c478bd9Sstevel@tonic-gate inode = ino;
716*7c478bd9Sstevel@tonic-gate }
717*7c478bd9Sstevel@tonic-gate (void) fclose(fp);
718*7c478bd9Sstevel@tonic-gate (void) unlink(sorted_fname);
719*7c478bd9Sstevel@tonic-gate curr = next ? next + 1 : NULL;
720*7c478bd9Sstevel@tonic-gate }
721*7c478bd9Sstevel@tonic-gate free(tmpf);
722*7c478bd9Sstevel@tonic-gate free(modpath);
723*7c478bd9Sstevel@tonic-gate }
724*7c478bd9Sstevel@tonic-gate
725*7c478bd9Sstevel@tonic-gate void
sysdev(void)726*7c478bd9Sstevel@tonic-gate sysdev(void)
727*7c478bd9Sstevel@tonic-gate {
728*7c478bd9Sstevel@tonic-gate printf(" swap files\n");
729*7c478bd9Sstevel@tonic-gate fflush(stdout);
730*7c478bd9Sstevel@tonic-gate if (system("/usr/sbin/swap -l") < 0)
731*7c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown swap file(s)\n");
732*7c478bd9Sstevel@tonic-gate }
733*7c478bd9Sstevel@tonic-gate
734*7c478bd9Sstevel@tonic-gate void
memseek(int sym)735*7c478bd9Sstevel@tonic-gate memseek(int sym)
736*7c478bd9Sstevel@tonic-gate {
737*7c478bd9Sstevel@tonic-gate Elf_Scn *scn;
738*7c478bd9Sstevel@tonic-gate Shdr *eshdr;
739*7c478bd9Sstevel@tonic-gate long eoff;
740*7c478bd9Sstevel@tonic-gate
741*7c478bd9Sstevel@tonic-gate if (incore) {
742*7c478bd9Sstevel@tonic-gate if ((fseek(memfile, nl[sym].n_value, 0)) != 0) {
743*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: fseek error (in memseek)\n", mem);
744*7c478bd9Sstevel@tonic-gate exit(1);
745*7c478bd9Sstevel@tonic-gate }
746*7c478bd9Sstevel@tonic-gate } else {
747*7c478bd9Sstevel@tonic-gate if ((scn = elf_getscn(elfd, nl[sym].n_scnum)) == NULL) {
748*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Error reading Scn %d (%s)\n",
749*7c478bd9Sstevel@tonic-gate os, nl[sym].n_scnum, elf_errmsg(-1));
750*7c478bd9Sstevel@tonic-gate exit(1);
751*7c478bd9Sstevel@tonic-gate }
752*7c478bd9Sstevel@tonic-gate
753*7c478bd9Sstevel@tonic-gate if ((eshdr = elf_getshdr(scn)) == NULL) {
754*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Error reading Shdr %d (%s)\n",
755*7c478bd9Sstevel@tonic-gate os, nl[sym].n_scnum, elf_errmsg(-1));
756*7c478bd9Sstevel@tonic-gate exit(1);
757*7c478bd9Sstevel@tonic-gate }
758*7c478bd9Sstevel@tonic-gate
759*7c478bd9Sstevel@tonic-gate eoff = (long)(nl[sym].n_value - eshdr->sh_addr +
760*7c478bd9Sstevel@tonic-gate eshdr->sh_offset);
761*7c478bd9Sstevel@tonic-gate
762*7c478bd9Sstevel@tonic-gate if ((fseek(sysfile, eoff, 0)) != 0) {
763*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: fseek error (in memseek)\n", os);
764*7c478bd9Sstevel@tonic-gate exit(1);
765*7c478bd9Sstevel@tonic-gate }
766*7c478bd9Sstevel@tonic-gate }
767*7c478bd9Sstevel@tonic-gate }
768*7c478bd9Sstevel@tonic-gate
769*7c478bd9Sstevel@tonic-gate /*
770*7c478bd9Sstevel@tonic-gate * filter out bss symbols if the reads are from the file
771*7c478bd9Sstevel@tonic-gate */
772*7c478bd9Sstevel@tonic-gate void
getnlist(void)773*7c478bd9Sstevel@tonic-gate getnlist(void)
774*7c478bd9Sstevel@tonic-gate {
775*7c478bd9Sstevel@tonic-gate struct nlist *p;
776*7c478bd9Sstevel@tonic-gate
777*7c478bd9Sstevel@tonic-gate nlist(os, nl);
778*7c478bd9Sstevel@tonic-gate
779*7c478bd9Sstevel@tonic-gate /*
780*7c478bd9Sstevel@tonic-gate * The nlist is done. If any symbol is a bss
781*7c478bd9Sstevel@tonic-gate * and we are not reading from incore, zero
782*7c478bd9Sstevel@tonic-gate * the n_value field. (Won't be printed if
783*7c478bd9Sstevel@tonic-gate * n_value == 0.)
784*7c478bd9Sstevel@tonic-gate */
785*7c478bd9Sstevel@tonic-gate if (!incore) {
786*7c478bd9Sstevel@tonic-gate for (p = nl; p->n_name && p->n_name[0]; p++) {
787*7c478bd9Sstevel@tonic-gate if (p->n_scnum == bss) {
788*7c478bd9Sstevel@tonic-gate p->n_value = 0;
789*7c478bd9Sstevel@tonic-gate }
790*7c478bd9Sstevel@tonic-gate }
791*7c478bd9Sstevel@tonic-gate }
792*7c478bd9Sstevel@tonic-gate }
793