17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
2334e48580Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*c3377ee9SJohn Levon /*
28*c3377ee9SJohn Levon * Copyright 2019 Joyent, Inc.
29*c3377ee9SJohn Levon */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/procset.h>
337c478bd9Sstevel@tonic-gate #include <sys/processor.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <stdio.h>
367c478bd9Sstevel@tonic-gate #include <stdlib.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <syslog.h>
407c478bd9Sstevel@tonic-gate #include <time.h>
417c478bd9Sstevel@tonic-gate #include <utmpx.h>
4234e48580Sdp #include <assert.h>
43*c3377ee9SJohn Levon #include <stdbool.h>
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate static char *cmdname; /* command name for messages */
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate static char verbose; /* non-zero if the -v option has been given */
487c478bd9Sstevel@tonic-gate static char all_flag; /* non-zero if the -a option has been given */
497c478bd9Sstevel@tonic-gate static char force; /* non-zero if the -F option has been given */
507c478bd9Sstevel@tonic-gate static char log_open; /* non-zero if openlog() has been called */
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate static struct utmpx ut; /* structure for logging to /etc/wtmpx. */
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate static char *basename(char *);
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate static void
usage(void)577c478bd9Sstevel@tonic-gate usage(void)
587c478bd9Sstevel@tonic-gate {
59*c3377ee9SJohn Levon (void) fprintf(stderr, "usage:\n"
60*c3377ee9SJohn Levon "\t%s [-F] -f|-n|-i|-s [-v] processor_id ...\n"
61*c3377ee9SJohn Levon "\t%s -a -f|-n|-i [-v]\n"
62*c3377ee9SJohn Levon "\t%s -aS [-v]\n",
63*c3377ee9SJohn Levon cmdname, cmdname, cmdname);
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate * Find base name of filename.
687c478bd9Sstevel@tonic-gate */
697c478bd9Sstevel@tonic-gate static char *
basename(char * cp)707c478bd9Sstevel@tonic-gate basename(char *cp)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate char *sp;
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate if ((sp = strrchr(cp, '/')) != NULL)
757c478bd9Sstevel@tonic-gate return (sp + 1);
767c478bd9Sstevel@tonic-gate return (cp);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate typedef struct _psr_action {
807c478bd9Sstevel@tonic-gate int p_op;
817c478bd9Sstevel@tonic-gate char *p_state;
827c478bd9Sstevel@tonic-gate char *p_action;
837c478bd9Sstevel@tonic-gate char *p_wtmp;
847c478bd9Sstevel@tonic-gate } psr_action_t;
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate static psr_action_t psr_action[] = {
877c478bd9Sstevel@tonic-gate { P_ONLINE, "on-line", "brought", "on" },
887c478bd9Sstevel@tonic-gate { P_OFFLINE, "off-line", "taken", "off" },
897c478bd9Sstevel@tonic-gate { P_NOINTR, "no-intr", "set to", "ni" },
907c478bd9Sstevel@tonic-gate { P_SPARE, "spare", "marked", "spr" },
917c478bd9Sstevel@tonic-gate { P_FAULTED, "faulted", "marked", "flt" },
92*c3377ee9SJohn Levon { P_DISABLED, "disabled", "set as", "dis" },
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate static int psr_actions = sizeof (psr_action) / sizeof (psr_action_t);
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate static psr_action_t *
psr_action_lookup(int action)987c478bd9Sstevel@tonic-gate psr_action_lookup(int action)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate int i;
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate for (i = 0; i < psr_actions; ++i) {
1037c478bd9Sstevel@tonic-gate if (psr_action[i].p_op == action) {
1047c478bd9Sstevel@tonic-gate return (&psr_action[i]);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate }
10734e48580Sdp return (NULL);
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate * Set processor state.
1127c478bd9Sstevel@tonic-gate * Return non-zero if a processor was found.
1137c478bd9Sstevel@tonic-gate * Print messages and update wtmp and the system log.
1147c478bd9Sstevel@tonic-gate * If mustexist is set, it is an error if a processor isn't there.
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate static int
psr_set_state(processorid_t cpu,int action,psr_action_t * pac,int mustexist)1187c478bd9Sstevel@tonic-gate psr_set_state(processorid_t cpu, int action, psr_action_t *pac, int mustexist)
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate int old_state;
1217c478bd9Sstevel@tonic-gate int err;
1227c478bd9Sstevel@tonic-gate time_t now;
1237c478bd9Sstevel@tonic-gate char buf[80];
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate old_state = p_online(cpu, P_STATUS);
1267c478bd9Sstevel@tonic-gate if (old_state < 0) {
1277c478bd9Sstevel@tonic-gate if (errno == EINVAL && !mustexist)
1287c478bd9Sstevel@tonic-gate return (0); /* no such processor */
1297c478bd9Sstevel@tonic-gate err = errno; /* in case sprintf smashes errno */
1307c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s: processor %d",
1317c478bd9Sstevel@tonic-gate cmdname, cpu);
1327c478bd9Sstevel@tonic-gate errno = err;
1337c478bd9Sstevel@tonic-gate perror(buf);
1347c478bd9Sstevel@tonic-gate return (-1);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate if (old_state == P_FAULTED && action != P_FAULTED && !force) {
1387c478bd9Sstevel@tonic-gate (void) printf("%s: processor %d in faulted state; "
1397c478bd9Sstevel@tonic-gate "add -F option to force change\n", cmdname, cpu);
1407c478bd9Sstevel@tonic-gate return (-1);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate old_state = p_online(cpu, force ? action | P_FORCED : action);
1447c478bd9Sstevel@tonic-gate if (old_state < 0) {
1457c478bd9Sstevel@tonic-gate if (errno == EINVAL && !mustexist)
1467c478bd9Sstevel@tonic-gate return (0); /* no such processor */
1477c478bd9Sstevel@tonic-gate err = errno;
1487c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s: processor %d",
1497c478bd9Sstevel@tonic-gate cmdname, cpu);
1507c478bd9Sstevel@tonic-gate errno = err;
1517c478bd9Sstevel@tonic-gate perror(buf);
1527c478bd9Sstevel@tonic-gate return (-1);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate if (old_state == action) {
1557c478bd9Sstevel@tonic-gate if (verbose)
1567c478bd9Sstevel@tonic-gate (void) printf("processor %d already %s.\n", cpu,
1577c478bd9Sstevel@tonic-gate pac->p_state);
1587c478bd9Sstevel@tonic-gate return (1); /* no change */
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "processor %d %s %s.",
1627c478bd9Sstevel@tonic-gate cpu, pac->p_action, pac->p_state);
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate if (verbose)
1657c478bd9Sstevel@tonic-gate (void) printf("%s\n", buf);
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * Log the change.
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate if (!log_open) {
1717c478bd9Sstevel@tonic-gate log_open = 1;
1727c478bd9Sstevel@tonic-gate openlog(cmdname, LOG_CONS, LOG_USER); /* open syslog */
1737c478bd9Sstevel@tonic-gate (void) setlogmask(LOG_UPTO(LOG_INFO));
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate ut.ut_pid = getpid();
1767c478bd9Sstevel@tonic-gate ut.ut_type = USER_PROCESS;
1777c478bd9Sstevel@tonic-gate (void) strncpy(ut.ut_user, "psradm", sizeof (ut.ut_user) - 1);
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate syslog(LOG_INFO, "%s", buf);
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * Update wtmp.
1847c478bd9Sstevel@tonic-gate */
1857c478bd9Sstevel@tonic-gate (void) snprintf(ut.ut_line, sizeof (ut.ut_line), PSRADM_MSG,
1867c478bd9Sstevel@tonic-gate cpu, pac->p_wtmp);
1877c478bd9Sstevel@tonic-gate (void) time(&now);
1887c478bd9Sstevel@tonic-gate ut.ut_xtime = now;
1897c478bd9Sstevel@tonic-gate updwtmpx(WTMPX_FILE, &ut);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate return (1); /* the processor exists and no errors occurred */
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate static int
do_range(processorid_t first,processorid_t last,int action,psr_action_t * pac)1957c478bd9Sstevel@tonic-gate do_range(processorid_t first, processorid_t last, int action,
1967c478bd9Sstevel@tonic-gate psr_action_t *pac)
1977c478bd9Sstevel@tonic-gate {
1987c478bd9Sstevel@tonic-gate processorid_t cpu;
1997c478bd9Sstevel@tonic-gate int error = 0;
2007c478bd9Sstevel@tonic-gate int rv;
2017c478bd9Sstevel@tonic-gate int found_one = 0;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate for (cpu = first; cpu <= last; cpu++) {
2047c478bd9Sstevel@tonic-gate if ((rv = psr_set_state(cpu, action, pac, 0)) > 0)
2057c478bd9Sstevel@tonic-gate found_one = 1;
2067c478bd9Sstevel@tonic-gate else if (rv < 0)
2077c478bd9Sstevel@tonic-gate error = 1;
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate if (!found_one && error == 0) {
2107c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: no processors in range %d-%d\n",
2117c478bd9Sstevel@tonic-gate cmdname, first, last);
2127c478bd9Sstevel@tonic-gate error = 1;
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate return (error);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])2187c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate int c;
2217c478bd9Sstevel@tonic-gate int action = 0;
2227c478bd9Sstevel@tonic-gate processorid_t cpu;
2237c478bd9Sstevel@tonic-gate processorid_t cpuid_max;
2247c478bd9Sstevel@tonic-gate char *errptr;
2257c478bd9Sstevel@tonic-gate int errors;
2267c478bd9Sstevel@tonic-gate psr_action_t *pac;
227*c3377ee9SJohn Levon bool disable_smt = 0;
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate cmdname = basename(argv[0]);
2307c478bd9Sstevel@tonic-gate
231*c3377ee9SJohn Levon while ((c = getopt(argc, argv, "afFinsSv")) != EOF) {
2327c478bd9Sstevel@tonic-gate switch (c) {
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate case 'a': /* applies to all possible CPUs */
2357c478bd9Sstevel@tonic-gate all_flag = 1;
2367c478bd9Sstevel@tonic-gate break;
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate case 'F':
2397c478bd9Sstevel@tonic-gate force = 1;
2407c478bd9Sstevel@tonic-gate break;
2417c478bd9Sstevel@tonic-gate
242*c3377ee9SJohn Levon case 'S':
243*c3377ee9SJohn Levon disable_smt = 1;
244*c3377ee9SJohn Levon break;
245*c3377ee9SJohn Levon
2467c478bd9Sstevel@tonic-gate case 'f':
2477c478bd9Sstevel@tonic-gate case 'i':
2487c478bd9Sstevel@tonic-gate case 'n':
2497c478bd9Sstevel@tonic-gate case 's':
2507c478bd9Sstevel@tonic-gate if (action != 0 && action != c) {
2517c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2527c478bd9Sstevel@tonic-gate "%s: options -f, -n, -i, and -s are "
2537c478bd9Sstevel@tonic-gate "mutually exclusive.\n", cmdname);
2547c478bd9Sstevel@tonic-gate usage();
2557c478bd9Sstevel@tonic-gate return (2);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate action = c;
2587c478bd9Sstevel@tonic-gate break;
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate case 'v':
2617c478bd9Sstevel@tonic-gate verbose = 1;
2627c478bd9Sstevel@tonic-gate break;
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate default:
2657c478bd9Sstevel@tonic-gate usage();
2667c478bd9Sstevel@tonic-gate return (2);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate
270*c3377ee9SJohn Levon if (disable_smt) {
271*c3377ee9SJohn Levon if (!all_flag) {
272*c3377ee9SJohn Levon fprintf(stderr, "%s: -S must be used with -a.\n",
273*c3377ee9SJohn Levon cmdname);
274*c3377ee9SJohn Levon usage();
275*c3377ee9SJohn Levon return (2);
276*c3377ee9SJohn Levon }
277*c3377ee9SJohn Levon
278*c3377ee9SJohn Levon if (force || action != 0 || argc != optind) {
279*c3377ee9SJohn Levon usage();
280*c3377ee9SJohn Levon return (2);
281*c3377ee9SJohn Levon }
282*c3377ee9SJohn Levon
283*c3377ee9SJohn Levon if (p_online(P_ALL_SIBLINGS, P_DISABLED) == -1) {
284*c3377ee9SJohn Levon fprintf(stderr, "Failed to disable simultaneous "
285*c3377ee9SJohn Levon "multi-threading: %s\n", strerror(errno));
286*c3377ee9SJohn Levon return (EXIT_FAILURE);
287*c3377ee9SJohn Levon }
288*c3377ee9SJohn Levon
289*c3377ee9SJohn Levon return (EXIT_SUCCESS);
290*c3377ee9SJohn Levon }
291*c3377ee9SJohn Levon
2927c478bd9Sstevel@tonic-gate switch (action) {
2937c478bd9Sstevel@tonic-gate case 'f':
2947c478bd9Sstevel@tonic-gate action = P_OFFLINE;
2957c478bd9Sstevel@tonic-gate break;
2967c478bd9Sstevel@tonic-gate case 'i':
2977c478bd9Sstevel@tonic-gate action = P_NOINTR;
2987c478bd9Sstevel@tonic-gate break;
2997c478bd9Sstevel@tonic-gate case 'n':
3007c478bd9Sstevel@tonic-gate action = P_ONLINE;
3017c478bd9Sstevel@tonic-gate break;
3027c478bd9Sstevel@tonic-gate case 's':
3037c478bd9Sstevel@tonic-gate action = P_SPARE;
3047c478bd9Sstevel@tonic-gate break;
3057c478bd9Sstevel@tonic-gate default:
3067c478bd9Sstevel@tonic-gate if (force != 0) {
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate * The -F option without other transition options
3097c478bd9Sstevel@tonic-gate * puts processor(s) into faulted state.
3107c478bd9Sstevel@tonic-gate */
3117c478bd9Sstevel@tonic-gate action = P_FAULTED;
3127c478bd9Sstevel@tonic-gate break;
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3157c478bd9Sstevel@tonic-gate "%s: option -f, -n, -s or -i must "
3167c478bd9Sstevel@tonic-gate "be specified.\n", cmdname);
3177c478bd9Sstevel@tonic-gate usage();
3187c478bd9Sstevel@tonic-gate return (2);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate pac = psr_action_lookup(action);
32234e48580Sdp assert(pac != NULL);
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate errors = 0;
3257c478bd9Sstevel@tonic-gate if (all_flag) {
3267c478bd9Sstevel@tonic-gate if (argc != optind) {
3277c478bd9Sstevel@tonic-gate usage();
3287c478bd9Sstevel@tonic-gate return (2);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate cpuid_max = (processorid_t)sysconf(_SC_CPUID_MAX);
3317c478bd9Sstevel@tonic-gate for (cpu = 0; cpu <= cpuid_max; cpu++) {
3327c478bd9Sstevel@tonic-gate if (psr_set_state(cpu, action, pac, 0) < 0)
3337c478bd9Sstevel@tonic-gate errors = 1;
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate } else {
3367c478bd9Sstevel@tonic-gate argc -= optind;
3377c478bd9Sstevel@tonic-gate if (argc <= 0) {
3387c478bd9Sstevel@tonic-gate usage(); /* not enough arguments */
3397c478bd9Sstevel@tonic-gate return (2);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate for (argv += optind; argc > 0; argv++, argc--) {
3427c478bd9Sstevel@tonic-gate if (strchr(*argv, '-') == NULL) {
3437c478bd9Sstevel@tonic-gate /* individual processor id */
3447c478bd9Sstevel@tonic-gate cpu = (processorid_t)
3457c478bd9Sstevel@tonic-gate strtol(*argv, &errptr, 10);
3467c478bd9Sstevel@tonic-gate if (errptr != NULL && *errptr != '\0') {
3477c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3487c478bd9Sstevel@tonic-gate "%s: invalid processor"
3497c478bd9Sstevel@tonic-gate " ID %s\n", cmdname, *argv);
3507c478bd9Sstevel@tonic-gate errors = 2;
3517c478bd9Sstevel@tonic-gate continue;
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate if (psr_set_state(cpu, action, pac, 1) < 0)
3547c478bd9Sstevel@tonic-gate errors = 1;
3557c478bd9Sstevel@tonic-gate } else {
3567c478bd9Sstevel@tonic-gate /* range of processors */
3577c478bd9Sstevel@tonic-gate processorid_t first, last;
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate first = (processorid_t)
3607c478bd9Sstevel@tonic-gate strtol(*argv, &errptr, 10);
3617c478bd9Sstevel@tonic-gate if (*errptr++ != '-') {
3627c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3637c478bd9Sstevel@tonic-gate "%s: invalid processor"
3647c478bd9Sstevel@tonic-gate " range %s\n", cmdname, *argv);
3657c478bd9Sstevel@tonic-gate errors = 2;
3667c478bd9Sstevel@tonic-gate continue;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate last = (processorid_t)
3697c478bd9Sstevel@tonic-gate strtol(errptr, &errptr, 10);
3707c478bd9Sstevel@tonic-gate if ((errptr != NULL && *errptr != '\0') ||
3717c478bd9Sstevel@tonic-gate last < first || first < 0) {
3727c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3737c478bd9Sstevel@tonic-gate "%s: invalid processor"
3747c478bd9Sstevel@tonic-gate " range %s\n", cmdname, *argv);
3757c478bd9Sstevel@tonic-gate errors = 2;
3767c478bd9Sstevel@tonic-gate continue;
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate if (do_range(first, last, action, pac))
3797c478bd9Sstevel@tonic-gate errors = 1;
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate }
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate if (log_open) {
3847c478bd9Sstevel@tonic-gate closelog();
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate return (errors);
3877c478bd9Sstevel@tonic-gate }
388