/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/processor.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include <time.h>
#include <utmpx.h>
#include <assert.h>
static char *basename(char *);
static void
usage(void)
{
"usage: \n\t%s [-F] -f|-n|-i|-s [-v] processor_id ...\n"
}
/*
* Find base name of filename.
*/
static char *
{
char *sp;
return (sp + 1);
return (cp);
}
typedef struct _psr_action {
int p_op;
char *p_state;
char *p_action;
char *p_wtmp;
} psr_action_t;
};
static psr_action_t *
{
int i;
for (i = 0; i < psr_actions; ++i) {
return (&psr_action[i]);
}
}
return (NULL);
}
/*
* Set processor state.
* Return non-zero if a processor was found.
* Print messages and update wtmp and the system log.
* If mustexist is set, it is an error if a processor isn't there.
*/
static int
{
int old_state;
int err;
if (old_state < 0) {
return (0); /* no such processor */
return (-1);
}
(void) printf("%s: processor %d in faulted state; "
return (-1);
}
if (old_state < 0) {
return (0); /* no such processor */
return (-1);
}
if (verbose)
return (1); /* no change */
}
if (verbose)
/*
* Log the change.
*/
if (!log_open) {
log_open = 1;
}
/*
* Update wtmp.
*/
return (1); /* the processor exists and no errors occurred */
}
static int
{
int error = 0;
int rv;
int found_one = 0;
found_one = 1;
else if (rv < 0)
error = 1;
}
error = 1;
}
return (error);
}
int
{
int c;
int action = 0;
char *errptr;
int errors;
switch (c) {
case 'a': /* applies to all possible CPUs */
all_flag = 1;
break;
case 'F':
force = 1;
break;
case 'f':
case 'i':
case 'n':
case 's':
"%s: options -f, -n, -i, and -s are "
"mutually exclusive.\n", cmdname);
usage();
return (2);
}
action = c;
break;
case 'v':
verbose = 1;
break;
default:
usage();
return (2);
}
}
switch (action) {
case 'f':
break;
case 'i':
break;
case 'n':
break;
case 's':
break;
default:
if (force != 0) {
/*
* The -F option without other transition options
* puts processor(s) into faulted state.
*/
break;
}
"%s: option -f, -n, -s or -i must "
"be specified.\n", cmdname);
usage();
return (2);
}
errors = 0;
if (all_flag) {
usage();
return (2);
}
errors = 1;
}
} else {
if (argc <= 0) {
usage(); /* not enough arguments */
return (2);
}
/* individual processor id */
cpu = (processorid_t)
"%s: invalid processor"
errors = 2;
continue;
}
errors = 1;
} else {
/* range of processors */
first = (processorid_t)
if (*errptr++ != '-') {
"%s: invalid processor"
errors = 2;
continue;
}
last = (processorid_t)
"%s: invalid processor"
errors = 2;
continue;
}
errors = 1;
}
}
}
if (log_open) {
closelog();
}
return (errors);
}