xref: /titanic_52/usr/src/cmd/psradm/psradm.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/procset.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/processor.h>
32*7c478bd9Sstevel@tonic-gate #include <unistd.h>
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <string.h>
36*7c478bd9Sstevel@tonic-gate #include <errno.h>
37*7c478bd9Sstevel@tonic-gate #include <syslog.h>
38*7c478bd9Sstevel@tonic-gate #include <time.h>
39*7c478bd9Sstevel@tonic-gate #include <utmpx.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate static char	*cmdname;	/* command name for messages */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate static char	verbose;	/* non-zero if the -v option has been given */
44*7c478bd9Sstevel@tonic-gate static char	all_flag;	/* non-zero if the -a option has been given */
45*7c478bd9Sstevel@tonic-gate static char	force;		/* non-zero if the -F option has been given */
46*7c478bd9Sstevel@tonic-gate static char	log_open;	/* non-zero if openlog() has been called */
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate static struct utmpx ut;		/* structure for logging to /etc/wtmpx. */
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static char	*basename(char *);
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate static void
53*7c478bd9Sstevel@tonic-gate usage(void)
54*7c478bd9Sstevel@tonic-gate {
55*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
56*7c478bd9Sstevel@tonic-gate 	    "usage: \n\t%s [-F] -f|-n|-i|-s [-v] processor_id ...\n"
57*7c478bd9Sstevel@tonic-gate 	    "\t%s -a -f|-n|-i [-v]\n", cmdname, cmdname);
58*7c478bd9Sstevel@tonic-gate }
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate  * Find base name of filename.
62*7c478bd9Sstevel@tonic-gate  */
63*7c478bd9Sstevel@tonic-gate static char *
64*7c478bd9Sstevel@tonic-gate basename(char *cp)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate 	char *sp;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	if ((sp = strrchr(cp, '/')) != NULL)
69*7c478bd9Sstevel@tonic-gate 		return (sp + 1);
70*7c478bd9Sstevel@tonic-gate 	return (cp);
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate typedef struct _psr_action {
74*7c478bd9Sstevel@tonic-gate 	int	p_op;
75*7c478bd9Sstevel@tonic-gate 	char	*p_state;
76*7c478bd9Sstevel@tonic-gate 	char	*p_action;
77*7c478bd9Sstevel@tonic-gate 	char	*p_wtmp;
78*7c478bd9Sstevel@tonic-gate } psr_action_t;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate static psr_action_t psr_action[] = {
81*7c478bd9Sstevel@tonic-gate 	{ P_ONLINE,	"on-line",	"brought",	"on"	},
82*7c478bd9Sstevel@tonic-gate 	{ P_OFFLINE,	"off-line",	"taken",	"off"	},
83*7c478bd9Sstevel@tonic-gate 	{ P_NOINTR,	"no-intr",	"set to",	"ni"	},
84*7c478bd9Sstevel@tonic-gate 	{ P_SPARE,	"spare",	"marked",	"spr"	},
85*7c478bd9Sstevel@tonic-gate 	{ P_FAULTED,	"faulted",	"marked",	"flt"	},
86*7c478bd9Sstevel@tonic-gate };
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate static int	psr_actions = sizeof (psr_action) / sizeof (psr_action_t);
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate static psr_action_t *
91*7c478bd9Sstevel@tonic-gate psr_action_lookup(int action)
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	int	i;
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < psr_actions; ++i) {
96*7c478bd9Sstevel@tonic-gate 		if (psr_action[i].p_op == action) {
97*7c478bd9Sstevel@tonic-gate 			return (&psr_action[i]);
98*7c478bd9Sstevel@tonic-gate 		}
99*7c478bd9Sstevel@tonic-gate 	}
100*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate /*
104*7c478bd9Sstevel@tonic-gate  * Set processor state.
105*7c478bd9Sstevel@tonic-gate  *	Return non-zero if a processor was found.
106*7c478bd9Sstevel@tonic-gate  *	Print messages and update wtmp and the system log.
107*7c478bd9Sstevel@tonic-gate  *	If mustexist is set, it is an error if a processor isn't there.
108*7c478bd9Sstevel@tonic-gate  */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate static int
111*7c478bd9Sstevel@tonic-gate psr_set_state(processorid_t cpu, int action, psr_action_t *pac, int mustexist)
112*7c478bd9Sstevel@tonic-gate {
113*7c478bd9Sstevel@tonic-gate 	int	old_state;
114*7c478bd9Sstevel@tonic-gate 	int	err;
115*7c478bd9Sstevel@tonic-gate 	time_t	now;
116*7c478bd9Sstevel@tonic-gate 	char	buf[80];
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	old_state = p_online(cpu, P_STATUS);
119*7c478bd9Sstevel@tonic-gate 	if (old_state < 0) {
120*7c478bd9Sstevel@tonic-gate 		if (errno == EINVAL && !mustexist)
121*7c478bd9Sstevel@tonic-gate 			return (0);	/* no such processor */
122*7c478bd9Sstevel@tonic-gate 		err = errno;		/* in case sprintf smashes errno */
123*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%s: processor %d",
124*7c478bd9Sstevel@tonic-gate 		    cmdname, cpu);
125*7c478bd9Sstevel@tonic-gate 		errno = err;
126*7c478bd9Sstevel@tonic-gate 		perror(buf);
127*7c478bd9Sstevel@tonic-gate 		return (-1);
128*7c478bd9Sstevel@tonic-gate 	}
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	if (old_state == P_FAULTED && action != P_FAULTED && !force) {
131*7c478bd9Sstevel@tonic-gate 		(void) printf("%s: processor %d in faulted state; "
132*7c478bd9Sstevel@tonic-gate 		    "add -F option to force change\n", cmdname, cpu);
133*7c478bd9Sstevel@tonic-gate 		return (-1);
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	old_state = p_online(cpu, force ? action | P_FORCED : action);
137*7c478bd9Sstevel@tonic-gate 	if (old_state < 0) {
138*7c478bd9Sstevel@tonic-gate 		if (errno == EINVAL && !mustexist)
139*7c478bd9Sstevel@tonic-gate 			return (0);	/* no such processor */
140*7c478bd9Sstevel@tonic-gate 		err = errno;
141*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%s: processor %d",
142*7c478bd9Sstevel@tonic-gate 		    cmdname, cpu);
143*7c478bd9Sstevel@tonic-gate 		errno = err;
144*7c478bd9Sstevel@tonic-gate 		perror(buf);
145*7c478bd9Sstevel@tonic-gate 		return (-1);
146*7c478bd9Sstevel@tonic-gate 	}
147*7c478bd9Sstevel@tonic-gate 	if (old_state == action) {
148*7c478bd9Sstevel@tonic-gate 		if (verbose)
149*7c478bd9Sstevel@tonic-gate 			(void) printf("processor %d already %s.\n", cpu,
150*7c478bd9Sstevel@tonic-gate 			    pac->p_state);
151*7c478bd9Sstevel@tonic-gate 		return (1);		/* no change */
152*7c478bd9Sstevel@tonic-gate 	}
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), "processor %d %s %s.",
155*7c478bd9Sstevel@tonic-gate 	    cpu, pac->p_action, pac->p_state);
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	if (verbose)
158*7c478bd9Sstevel@tonic-gate 		(void) printf("%s\n", buf);
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	/*
161*7c478bd9Sstevel@tonic-gate 	 * Log the change.
162*7c478bd9Sstevel@tonic-gate 	 */
163*7c478bd9Sstevel@tonic-gate 	if (!log_open) {
164*7c478bd9Sstevel@tonic-gate 		log_open = 1;
165*7c478bd9Sstevel@tonic-gate 		openlog(cmdname, LOG_CONS, LOG_USER);	/* open syslog */
166*7c478bd9Sstevel@tonic-gate 		(void) setlogmask(LOG_UPTO(LOG_INFO));
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 		ut.ut_pid = getpid();
169*7c478bd9Sstevel@tonic-gate 		ut.ut_type = USER_PROCESS;
170*7c478bd9Sstevel@tonic-gate 		(void) strncpy(ut.ut_user, "psradm", sizeof (ut.ut_user) - 1);
171*7c478bd9Sstevel@tonic-gate 	}
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 	syslog(LOG_INFO, "%s", buf);
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	/*
176*7c478bd9Sstevel@tonic-gate 	 * Update wtmp.
177*7c478bd9Sstevel@tonic-gate 	 */
178*7c478bd9Sstevel@tonic-gate 	(void) snprintf(ut.ut_line, sizeof (ut.ut_line), PSRADM_MSG,
179*7c478bd9Sstevel@tonic-gate 	    cpu, pac->p_wtmp);
180*7c478bd9Sstevel@tonic-gate 	(void) time(&now);
181*7c478bd9Sstevel@tonic-gate 	ut.ut_xtime = now;
182*7c478bd9Sstevel@tonic-gate 	updwtmpx(WTMPX_FILE, &ut);
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate 	return (1);	/* the processor exists and no errors occurred */
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate static int
188*7c478bd9Sstevel@tonic-gate do_range(processorid_t first, processorid_t last, int action,
189*7c478bd9Sstevel@tonic-gate     psr_action_t *pac)
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	processorid_t cpu;
192*7c478bd9Sstevel@tonic-gate 	int error = 0;
193*7c478bd9Sstevel@tonic-gate 	int rv;
194*7c478bd9Sstevel@tonic-gate 	int found_one = 0;
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 	for (cpu = first; cpu <= last; cpu++) {
197*7c478bd9Sstevel@tonic-gate 		if ((rv = psr_set_state(cpu, action, pac, 0)) > 0)
198*7c478bd9Sstevel@tonic-gate 			found_one = 1;
199*7c478bd9Sstevel@tonic-gate 		else if (rv < 0)
200*7c478bd9Sstevel@tonic-gate 			error = 1;
201*7c478bd9Sstevel@tonic-gate 	}
202*7c478bd9Sstevel@tonic-gate 	if (!found_one && error == 0) {
203*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: no processors in range %d-%d\n",
204*7c478bd9Sstevel@tonic-gate 		    cmdname, first, last);
205*7c478bd9Sstevel@tonic-gate 		error = 1;
206*7c478bd9Sstevel@tonic-gate 	}
207*7c478bd9Sstevel@tonic-gate 	return (error);
208*7c478bd9Sstevel@tonic-gate }
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate int
211*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
212*7c478bd9Sstevel@tonic-gate {
213*7c478bd9Sstevel@tonic-gate 	int	c;
214*7c478bd9Sstevel@tonic-gate 	int	action = 0;
215*7c478bd9Sstevel@tonic-gate 	processorid_t	cpu;
216*7c478bd9Sstevel@tonic-gate 	processorid_t	cpuid_max;
217*7c478bd9Sstevel@tonic-gate 	char	*errptr;
218*7c478bd9Sstevel@tonic-gate 	int	errors;
219*7c478bd9Sstevel@tonic-gate 	psr_action_t	*pac;
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	cmdname = basename(argv[0]);
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "afFinsv")) != EOF) {
224*7c478bd9Sstevel@tonic-gate 		switch (c) {
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 		case 'a':		/* applies to all possible CPUs */
227*7c478bd9Sstevel@tonic-gate 			all_flag = 1;
228*7c478bd9Sstevel@tonic-gate 			break;
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 		case 'F':
231*7c478bd9Sstevel@tonic-gate 			force = 1;
232*7c478bd9Sstevel@tonic-gate 			break;
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate 		case 'f':
235*7c478bd9Sstevel@tonic-gate 		case 'i':
236*7c478bd9Sstevel@tonic-gate 		case 'n':
237*7c478bd9Sstevel@tonic-gate 		case 's':
238*7c478bd9Sstevel@tonic-gate 			if (action != 0 && action != c) {
239*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
240*7c478bd9Sstevel@tonic-gate 				    "%s: options -f, -n, -i, and -s are "
241*7c478bd9Sstevel@tonic-gate 				    "mutually exclusive.\n", cmdname);
242*7c478bd9Sstevel@tonic-gate 				usage();
243*7c478bd9Sstevel@tonic-gate 				return (2);
244*7c478bd9Sstevel@tonic-gate 			}
245*7c478bd9Sstevel@tonic-gate 			action = c;
246*7c478bd9Sstevel@tonic-gate 			break;
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 		case 'v':
249*7c478bd9Sstevel@tonic-gate 			verbose = 1;
250*7c478bd9Sstevel@tonic-gate 			break;
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 		default:
253*7c478bd9Sstevel@tonic-gate 			usage();
254*7c478bd9Sstevel@tonic-gate 			return (2);
255*7c478bd9Sstevel@tonic-gate 		}
256*7c478bd9Sstevel@tonic-gate 	}
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	switch (action) {
259*7c478bd9Sstevel@tonic-gate 	case 'f':
260*7c478bd9Sstevel@tonic-gate 		action = P_OFFLINE;
261*7c478bd9Sstevel@tonic-gate 		break;
262*7c478bd9Sstevel@tonic-gate 	case 'i':
263*7c478bd9Sstevel@tonic-gate 		action = P_NOINTR;
264*7c478bd9Sstevel@tonic-gate 		break;
265*7c478bd9Sstevel@tonic-gate 	case 'n':
266*7c478bd9Sstevel@tonic-gate 		action = P_ONLINE;
267*7c478bd9Sstevel@tonic-gate 		break;
268*7c478bd9Sstevel@tonic-gate 	case 's':
269*7c478bd9Sstevel@tonic-gate 		action = P_SPARE;
270*7c478bd9Sstevel@tonic-gate 		break;
271*7c478bd9Sstevel@tonic-gate 	default:
272*7c478bd9Sstevel@tonic-gate 		if (force != 0) {
273*7c478bd9Sstevel@tonic-gate 			/*
274*7c478bd9Sstevel@tonic-gate 			 * The -F option without other transition options
275*7c478bd9Sstevel@tonic-gate 			 * puts processor(s) into faulted state.
276*7c478bd9Sstevel@tonic-gate 			 */
277*7c478bd9Sstevel@tonic-gate 			action = P_FAULTED;
278*7c478bd9Sstevel@tonic-gate 			break;
279*7c478bd9Sstevel@tonic-gate 		}
280*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
281*7c478bd9Sstevel@tonic-gate 		    "%s: option -f, -n, -s or -i must "
282*7c478bd9Sstevel@tonic-gate 		    "be specified.\n", cmdname);
283*7c478bd9Sstevel@tonic-gate 		usage();
284*7c478bd9Sstevel@tonic-gate 		return (2);
285*7c478bd9Sstevel@tonic-gate 	}
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate 	pac = psr_action_lookup(action);
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 	errors = 0;
290*7c478bd9Sstevel@tonic-gate 	if (all_flag) {
291*7c478bd9Sstevel@tonic-gate 		if (argc != optind) {
292*7c478bd9Sstevel@tonic-gate 			usage();
293*7c478bd9Sstevel@tonic-gate 			return (2);
294*7c478bd9Sstevel@tonic-gate 		}
295*7c478bd9Sstevel@tonic-gate 		cpuid_max = (processorid_t)sysconf(_SC_CPUID_MAX);
296*7c478bd9Sstevel@tonic-gate 		for (cpu = 0; cpu <= cpuid_max; cpu++) {
297*7c478bd9Sstevel@tonic-gate 			if (psr_set_state(cpu, action, pac, 0) < 0)
298*7c478bd9Sstevel@tonic-gate 				errors = 1;
299*7c478bd9Sstevel@tonic-gate 		}
300*7c478bd9Sstevel@tonic-gate 	} else {
301*7c478bd9Sstevel@tonic-gate 		argc -= optind;
302*7c478bd9Sstevel@tonic-gate 		if (argc <= 0) {
303*7c478bd9Sstevel@tonic-gate 			usage();	/* not enough arguments */
304*7c478bd9Sstevel@tonic-gate 			return (2);
305*7c478bd9Sstevel@tonic-gate 		}
306*7c478bd9Sstevel@tonic-gate 		for (argv += optind; argc > 0; argv++, argc--) {
307*7c478bd9Sstevel@tonic-gate 			if (strchr(*argv, '-') == NULL) {
308*7c478bd9Sstevel@tonic-gate 				/* individual processor id */
309*7c478bd9Sstevel@tonic-gate 				cpu = (processorid_t)
310*7c478bd9Sstevel@tonic-gate 				    strtol(*argv, &errptr, 10);
311*7c478bd9Sstevel@tonic-gate 				if (errptr != NULL && *errptr != '\0') {
312*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr,
313*7c478bd9Sstevel@tonic-gate 					    "%s: invalid processor"
314*7c478bd9Sstevel@tonic-gate 					    " ID %s\n", cmdname, *argv);
315*7c478bd9Sstevel@tonic-gate 					errors = 2;
316*7c478bd9Sstevel@tonic-gate 					continue;
317*7c478bd9Sstevel@tonic-gate 				}
318*7c478bd9Sstevel@tonic-gate 				if (psr_set_state(cpu, action, pac, 1) < 0)
319*7c478bd9Sstevel@tonic-gate 					errors = 1;
320*7c478bd9Sstevel@tonic-gate 			} else {
321*7c478bd9Sstevel@tonic-gate 				/* range of processors */
322*7c478bd9Sstevel@tonic-gate 				processorid_t first, last;
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate 				first = (processorid_t)
325*7c478bd9Sstevel@tonic-gate 				    strtol(*argv, &errptr, 10);
326*7c478bd9Sstevel@tonic-gate 				if (*errptr++ != '-') {
327*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr,
328*7c478bd9Sstevel@tonic-gate 					    "%s: invalid processor"
329*7c478bd9Sstevel@tonic-gate 					    " range %s\n", cmdname, *argv);
330*7c478bd9Sstevel@tonic-gate 					errors = 2;
331*7c478bd9Sstevel@tonic-gate 					continue;
332*7c478bd9Sstevel@tonic-gate 				}
333*7c478bd9Sstevel@tonic-gate 				last = (processorid_t)
334*7c478bd9Sstevel@tonic-gate 				    strtol(errptr, &errptr, 10);
335*7c478bd9Sstevel@tonic-gate 				if ((errptr != NULL && *errptr != '\0') ||
336*7c478bd9Sstevel@tonic-gate 				    last < first || first < 0) {
337*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr,
338*7c478bd9Sstevel@tonic-gate 					    "%s: invalid processor"
339*7c478bd9Sstevel@tonic-gate 					    " range %s\n", cmdname, *argv);
340*7c478bd9Sstevel@tonic-gate 					errors = 2;
341*7c478bd9Sstevel@tonic-gate 					continue;
342*7c478bd9Sstevel@tonic-gate 				}
343*7c478bd9Sstevel@tonic-gate 				if (do_range(first, last, action, pac))
344*7c478bd9Sstevel@tonic-gate 					errors = 1;
345*7c478bd9Sstevel@tonic-gate 			}
346*7c478bd9Sstevel@tonic-gate 		}
347*7c478bd9Sstevel@tonic-gate 	}
348*7c478bd9Sstevel@tonic-gate 	if (log_open) {
349*7c478bd9Sstevel@tonic-gate 		closelog();
350*7c478bd9Sstevel@tonic-gate 	}
351*7c478bd9Sstevel@tonic-gate 	return (errors);
352*7c478bd9Sstevel@tonic-gate }
353