setegid(getgid()); setgid(getgid());
if (c > 0) { (void)fprintf(stderr, "%s: undefined symbols:", __progname); for (c = 0; c < sizeof(namelist)/sizeof(namelist[0]); c++) if (namelist[c].n_type == 0) fprintf(stderr, " %s", namelist[c].n_name); (void)fputc('\n', stderr); exit(1); } else errx(1, "kvm_nlist: %s", kvm_geterr(kd)); } #ifdef notyet } #endif notyet
char	**choosedrives __P((char **));/* Namelist and memory file names. */char	*nlistf, *memf;extern char *__progname;intmain(argc, argv)	register int argc;	register char **argv;{	extern int optind;	extern char *optarg;	register int c, todo;	u_int interval;	int reps;	char errbuf[_POSIX2_LINE_MAX];	memf = nlistf = NULL;	interval = reps = todo = 0;	while ((c = getopt(argc, argv, "c:fiM:mN:stw:")) != -1) {		switch (c) {		case 'c':			reps = atoi(optarg);			break;		case 'f':			todo |= FORKSTAT;			break;		case 'i':			todo |= INTRSTAT;			break;		case 'M':			memf = optarg;			break;		case 'm':			todo |= MEMSTAT;			break;		case 'N':			nlistf = optarg;			break;		case 's':			todo |= SUMSTAT;			break;		case 't':			todo |= TIMESTAT;			break;		case 'w':			interval = atoi(optarg);			break;		case '?':		default:			usage();		}	}	argc -= optind;	argv += optind;	if (todo == 0)		todo = VMSTAT;	/*	 * Discard setgid privileges if not the running kernel so that bad	 * guys can't print interesting stuff from kernel memory.	 */	if (nlistf != NULL || memf != NULL) {		setegid(getgid());		setgid(getgid());	}	kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);	if (kd == 0)		errx(1, "kvm_openfiles: %s", errbuf);	if ((c = kvm_nlist(kd, namelist)) != 0) {		setegid(getgid());		setgid(getgid());		if (c > 0) {			(void)fprintf(stderr,			    "%s: undefined symbols:", __progname);			for (c = 0;			    c < sizeof(namelist)/sizeof(namelist[0]); c++)				if (namelist[c].n_type == 0)					fprintf(stderr, " %s",					    namelist[c].n_name);			(void)fputc('\n', stderr);			exit(1);		} else			errx(1, "kvm_nlist: %s", kvm_geterr(kd));	}	if (todo & VMSTAT) {		struct winsize winsize;		dkinit(0);	/* Initialize disk stats, no disks selected. */		argv = choosedrives(argv);	/* Select disks. */		winsize.ws_row = 0;		(void) ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize);		if (winsize.ws_row > 0)			winlines = winsize.ws_row;	}	setegid(getgid());	setgid(getgid());#define	BACKWARD_COMPATIBILITY#ifdef	BACKWARD_COMPATIBILITY	if (*argv) {		interval = atoi(*argv);		if (*++argv)			reps = atoi(*argv);	}#endif	if (interval) {		if (!reps)			reps = -1;	} else if (reps)		interval = 1;	if (todo & FORKSTAT)		doforkst();	if (todo & MEMSTAT) {		domem();		dopool();	}	if (todo & SUMSTAT)		dosum();	if (todo & TIMESTAT)		dotimes();	if (todo & INTRSTAT)		dointr();	if (todo & VMSTAT)		dovmstat(interval, reps);	exit(0);}char **choosedrives(argv)	char **argv;{	register int i;	/*	 * Choose drives to be displayed.  Priority goes to (in order) drives	 * supplied as arguments, default drives.  If everything isn't filled	 * in and there are drives not taken care of, display the first few	 * that fit.	 */#define BACKWARD_COMPATIBILITY	for (ndrives = 0; *argv; ++argv) {#ifdef	BACKWARD_COMPATIBILITY		if (isdigit(**argv))			break;#endif		for (i = 0; i < dk_ndrive; i++) {			if (strcmp(dr_name[i], *argv))				continue;			dk_select[i] = 1;			++ndrives;			break;		}	}	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {		if (dk_select[i])			continue;		dk_select[i] = 1;		++ndrives;	}	return(argv);}