/*
* 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/tspriocntl.h>
#include <libgen.h>
#include <limits.h>
#include <errno.h>
#include "priocntl.h"
/*
* This file contains the class specific code implementing
* the time-sharing priocntl sub-command.
*/
/*
* control flags
*/
static void print_tsinfo(void);
static int print_tsprocs(void);
static char usage[] =
"usage: priocntl -l\n\
priocntl -d [-d idtype] [idlist]\n\
priocntl -s [-c TS] [-m tsuprilim] [-p tsupri] [-i idtype] [idlist]\n\
priocntl -e [-c TS] [-m tsuprilim] [-p tsupri] command [argument(s)]\n";
int
{
int c;
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 'e':
eflag++;
break;
case 'c':
fatalerr("error: %s executed for %s class, %s"
" is actually sub-command for TS class\n",
break;
case 'i':
iflag++;
break;
case '?':
default:
break;
}
}
if (lflag) {
print_tsinfo();
} else if (dflag) {
return (print_tsprocs());
} else if (sflag) {
if (iflag) {
idtypnm);
} else {
}
if (mflag)
cflags |= TS_DOUPRILIM;
else
idargc = 0;
} else if (eflag) {
if (mflag)
cflags |= TS_DOUPRILIM;
} else {
}
return (0);
}
/*
* Print our class name and the configured user priority range.
*/
static void
print_tsinfo(void)
{
(void) printf("TS (Time Sharing)\n");
fatalerr("\tCan't get configured TS user priority range\n");
(void) printf("\tConfigured TS 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.
*/
static int
print_tsprocs(void)
{
int i;
int error = 0;
/*
* Read a list of pids from stdin.
*/
(void) printf(
"TIME SHARING PROCESSES:\n PID TSUPRILIM TSUPRI\n");
if (numread == 0)
for (i = 0; i < numread; i++) {
(void) printf(" %5d %5d\n",
} else {
error = 1;
/*
* Process from some class other than time
* sharing. 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 TS 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 TS_KEYCNT = 2 (key, value) pairs.
*/
static int
{
}
/*
* (if they aren't already time-sharing) and set their user priority limit
* and user priority to those specified by tsuprilim and tsupri.
*/
static int
{
int i;
int error = 0;
/*
* Get the time sharing class ID and max configured user priority.
*/
fatalerr("%s: Can't get TS class ID, priocntl system call"
/*
* Validate the tsuprilim and tsupri arguments.
*/
if ((cflags & TS_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 time sharing"
" parameters\npriocntl system call failed"
}
}
} else if (idargc == 0) {
args) == -1) {
" encountered on current %s.\n", idtypnm);
error = 1;
} else {
fatalerr("%s: Can't reset time sharing"
" 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"
error = 1;
} else {
fatalerr("%s: Can't reset time sharing"
" parameters\npriocntl system call"
" failed with errno %d\n",
}
TS_DOUPRI) {
}
}
}
return (error);
}
/*
* Execute the command pointed to by cmdargv as a time-sharing process
* with the user priority limit given by tsuprilim and user priority tsupri.
*/
static void
{
/*
* Get the time sharing class ID and max configured user priority.
*/
fatalerr("%s: Can't get TS class ID, priocntl system call"
if ((cflags & TS_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 time sharing 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",
}