/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/priocntl.h>
#include <sys/iapriocntl.h>
#include <libgen.h>
#include <limits.h>
#include <errno.h>
#include "priocntl.h"
/*
* This file contains the class specific code implementing
* the interactive class priocntl sub-command.
*/
/*
* control flags
*/
static void print_iainfo(void);
static int print_iaprocs(void);
static char usage[] =
"usage: priocntl -l\n\
priocntl -d [-i idtype] [idlist]\n\
priocntl -s [-c IA] [-m iauprilim] [-p iaupri] [-t iamode]\n\
[-i idtype] [idlist]\n\
priocntl -e [-c IA] [-m iauprilim] [-p iaupri] [-t iamode]\n\
command [argument(s)]\n";
int
{
int c;
int iamode;
char *idtypnm;
int idargc;
switch (c) {
case 'l':
lflag++;
break;
case 'd':
dflag++;
break;
case 's':
sflag++;
break;
case 'm':
mflag++;
if (errno)
fatalerr("%s: Specified user priority limit %s"
" out of configured range\n",
break;
case 'p':
pflag++;
if (errno)
fatalerr("%s: Specified user priority %s out of"
break;
case 't':
tflag++;
iamode != IA_SET_INTERACTIVE))
fatalerr("%s: Specified illegal mode %s\n",
break;
case 'e':
eflag++;
break;
case 'c':
fatalerr("error: %s executed for %s class, %s"
" is actually sub-command for IA class\n",
break;
case 'i':
iflag++;
break;
case '?':
default:
break;
}
}
if (lflag) {
print_iainfo();
} else if (dflag) {
return (print_iaprocs());
} else if (sflag) {
if (iflag) {
idtypnm);
} else {
}
if (mflag)
cflags |= IA_DOUPRILIM;
if (tflag)
else
idargc = 0;
} else if (eflag) {
if (mflag)
cflags |= IA_DOUPRILIM;
if (tflag)
} else {
}
return (0);
}
/*
* Print our class name and the configured user priority range.
*/
static void
print_iainfo(void)
{
(void) printf("IA (Interactive)\n");
fatalerr("\tCan't get configured IA user priority range\n");
(void) printf("\tConfigured IA User Priority Range: -%d through %d\n",
}
/*
* Read a list of pids from stdin and print the user priority and user
* priority limit for each of the corresponding processes.
* print their interactive mode and nice values
*/
static int
print_iaprocs(void)
{
int i;
int ia_mode;
int error = 0;
/*
* Read a list of pids from stdin.
*/
(void) printf("INTERACTIVE CLASS PROCESSES:");
(void) printf("\n PID IAUPRILIM IAUPRI IAMODE\n");
if (numread == 0)
for (i = 0; i < numread; i++) {
(void) printf(" %5d %5d %5d\n",
} else {
error = 1;
/*
* Process from some class other than
* interactive. It has probably changed class
* while priocntl command was executing
* (otherwise we wouldn't have been passed its
* pid). Print the little we know about it.
*/
(void) printf("\tChanged to class %s while"
" priocntl command executing\n", clname);
else
(void) printf("\tCan't get IA user priority\n");
}
}
return (error);
}
/*
* Call priocntl() with command codes PC_SETXPARMS or PC_GETXPARMS.
* The first parameter behind the command code is always the class name.
* Each parameter is headed by a key, which determines the meaning of the
* following value. There are maximal IA_KEYCNT = 3 (key, value) pairs.
*/
static int
{
}
/*
* (if they aren't already interactive ) and set their user priority limit
* and user priority to those specified by iauprilim and iaupri.
*/
static int
{
int maxupri;
int i;
int error = 0;
/*
* Get the interactive class ID and max configured user priority.
*/
fatalerr("%s: Can't get IA class ID, priocntl system call"
/*
* Validate the iauprilim and iaupri arguments.
*/
if ((cflags & IA_DOUPRILIM) != 0) {
fatalerr("%s: Specified user priority limit %d out of"
}
fatalerr("%s: Specified user priority %d out of"
}
*argsp = 0;
"Permissions error encountered"
" on one or more processes.\n");
error = 1;
} else {
fatalerr("%s: Can't reset interactive"
" parameters\npriocntl system call failed"
}
}
} else if (idargc == 0) {
args) == -1) {
"Permissions error encountered"
" on current %s.\n", idtypnm);
error = 1;
} else {
fatalerr("%s: Can't reset interactive"
" parameters\npriocntl system call failed"
}
}
} else {
for (i = 0; i < idargc; i++) {
fatalerr("%s: Invalid or unconfigured"
" class %s, priocntl system call"
" failed with errno %d\n",
} else {
if (errno)
fatalerr("%s: Invalid id \"%s\"\n",
}
args) == -1) {
"Permissions error"
" encountered on %s %s.\n",
error = 1;
} else {
fatalerr("%s: Can't reset interactive"
" parameters\npriocntl system call"
" failed with errno %d\n",
}
IA_DOUPRI) {
}
}
}
return (error);
}
/*
* Execute the command pointed to by cmdargv as a interactive process
* with the user priority limit given by iauprilim and user priority iaupri.
*/
static void
int iamode)
{
/*
* Get the time sharing class ID and max configured user priority.
*/
fatalerr("%s: Can't get IA class ID, priocntl system call"
/*
* Validate the iauprilim and iaupri arguments.
*/
if ((cflags & IA_DOUPRILIM) != 0) {
fatalerr("%s: Specified user priority limit %d out of"
}
fatalerr("%s: Specified user priority %d out of"
}
*argsp = 0;
fatalerr("%s: Can't reset interactive parameters\n"
"priocntl system call failed with errno %d\n",
"%s: Specified user priority %d exceeds"
" limit %d; set to %d (pid %d)\n",
}
fatalerr("%s: Can't execute %s, exec failed with errno %d\n",
}