fxpriocntl.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2001-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <sys/priocntl.h>
#include <sys/fxpriocntl.h>
#include <limits.h>
#include <errno.h>
#include "priocntl.h"
/*
* This file contains the class specific code implementing
* the fixed-priority priocntl sub-command.
*/
/*
* control flags
*/
static void print_fxinfo();
static int print_fxprocs();
long);
static char usage[] =
"usage: priocntl -l\n\
priocntl -d [-d idtype] [idlist]\n\
priocntl -s [-c FX] [-m fxuprilim] [-p fxupri] [-t tqntm [-r res]] \
[-i idtype] [idlist]\n\
priocntl -e [-c FX] [-m fxuprilim] [-p fxupri] [-t tqntm [-r res]] \
command [argument(s)]\n";
static char cmdpath[MAXPATHLEN];
int
{
extern char *optarg;
extern int optind;
int c;
int rflag;
char *idtypnm;
int idargc;
long res;
long tqntm;
rflag = 0;
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 FX class\n",
break;
case 'i':
iflag++;
break;
case 't':
tflag++;
if (errno)
fatalerr("%s: Invalid time quantum specified;"
" time quantum must be positive\n", basenm);
break;
case 'r':
rflag++;
if (errno)
fatalerr("%s: Invalid resolution specified;"
" resolution must be between"
" 1 and 1,000,000,000\n", basenm);
break;
case '?':
default:
break;
}
}
if (lflag) {
print_fxinfo();
} else if (dflag) {
return (print_fxprocs());
} else if (sflag) {
if (eflag)
if (iflag) {
idtypnm);
} else
if (mflag)
cflags |= FX_DOUPRILIM;
if (tflag)
if (rflag == 0)
res = 1000;
else
idargc = 0;
} else if (eflag) {
if (iflag)
if (mflag)
cflags |= FX_DOUPRILIM;
if (tflag)
if (rflag == 0)
res = 1000;
res);
} else {
}
return (0);
}
/*
* Print our class name and the configured user priority range.
*/
static void
{
(void) printf("FX (Fixed priority)\n");
fatalerr("\tCan't get configured FX user priority range\n");
(void) printf("\tConfigured FX User Priority Range: 0 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
{
int i;
int fx_tqnsecs;
int error = 0;
/*
* Read a list of pids from stdin.
*/
(void) printf("FIXED PRIORITY PROCESSES:\n PID FXUPRILIM "
"FXUPRI FXTQNTM\n");
if (numread == 0)
for (i = 0; i < numread; i++) {
&fx_tqnsecs, 0) != -1) {
if (fx_tqnsecs == FX_TQINF)
(void) printf(" FX_TQINF\n");
else
(void) printf(" %11lld\n",
fx_tqnsecs / 1000000);
} else {
error = 1;
/*
* Process from some class other than fixed priority.
* 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 FX 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 FX_KEYCNT = 4 (key, value) pairs.
*/
static int
{
}
/*
* (if they aren't already fixed-priority) and set their user priority limit
* and user priority to those specified by fxuprilim and fxupri.
*/
static int
{
char idtypnm[PC_IDTYPNMSZ];
int i;
int error = 0;
/*
* Get the fixed priority class ID and max configured user priority.
*/
fatalerr("%s: Can't get FX class ID, priocntl system call"
/*
* Validate the fxuprilim and fxupri arguments.
*/
if ((cflags & FX_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 fixed priority"
" 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 fixed priority"
" 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 {
}
== -1) {
"Permissions error encountered on"
error = 1;
} else {
fatalerr("%s: Can't reset fixed "
"priority"
" parameters\npriocntl system call"
" failed with errno %d\n",
}
FX_DOUPRI) {
}
}
}
return (error);
}
/*
* Execute the command pointed to by cmdargv as a fixed-priority process
* with the user priority limit given by fxuprilim and user priority fxupri.
*/
static void
{
/*
* Get the fixed priority class ID and max configured user priority.
*/
fatalerr("%s: Can't get FX class ID, priocntl system call"
if ((cflags & FX_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 fixed priority 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",
}