rtpriocntl.c revision d4204c85a44d2589b9afff2c81db7044e97f2d1d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2008 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/rtpriocntl.h>
#include <signal.h>
#include <libgen.h>
#include <limits.h>
#include <errno.h>
#include "priocntl.h"
/*
* This file contains the class specific code implementing
* the real-time priocntl sub-command.
*/
/*
* control flags
*/
static void print_rtinfo(void);
static int print_rtprocs(void);
long, int);
static char usage[] =
"usage: priocntl -l\n"
" priocntl -d [-i idtype] [idlist]\n"
" priocntl -s [-c RT] [-p rtpri] [-t tqntm [-r res]] [-q tqsig]\n"
" [-i idtype] [idlist]\n"
" priocntl -e [-c RT] [-p rtpri] [-t tqntm [-r res]] [-q tqsig]\n"
" command [argument(s)]\n";
static char cmdpath[MAXPATHLEN];
int
{
int c;
long tqntm;
long res;
int tqsig;
char *idtypnm;
int idargc;
switch (c) {
case 'l':
lflag++;
break;
case 'd':
dflag++;
break;
case 's':
sflag++;
break;
case 'p':
pflag++;
if (errno)
fatalerr("%s: Specified real time priority %s"
" out of configured range\n",
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 'q':
qflag++;
fatalerr("%s: Invalid real time quantum signal"
" specified\n", basenm);
break;
case 'e':
eflag++;
break;
case 'c':
fatalerr("error: %s executed for %s class, %s"
" is actually sub-command for RT class\n",
break;
case 'i':
iflag++;
break;
case '?':
default:
break;
}
}
if (lflag) {
print_rtinfo();
} else if (dflag) {
return (print_rtprocs());
} else if (sflag) {
if (iflag) {
idtypnm);
} else {
}
if (tflag)
if (rflag == 0)
res = 1000;
else
idargc = 0;
if (qflag)
} else if (eflag) {
if (tflag)
if (rflag == 0)
res = 1000;
if (qflag)
} else {
}
return (0);
}
/*
* Print our class name and the configured user priority range.
*/
static void
print_rtinfo(void)
{
(void) printf("RT (Real Time)\n");
fatalerr("\tCan't get maximum configured RT priority\n");
(void) printf("\tConfigured RT User Priority Range: 0 through %d\n",
}
/*
* Read a list of pids from stdin and print the real-time priority and time
* quantum (in millisecond resolution) for each of the corresponding processes.
*/
static int
print_rtprocs(void)
{
int i;
int rt_tqnsecs;
int rt_tqsig;
int error = 0;
/*
* Read a list of pids from stdin.
*/
(void) printf("REAL TIME PROCESSES:\n"
" PID RTPRI TQNTM TQSIG\n");
if (numread == 0)
for (i = 0; i < numread; i++) {
if (rt_tqnsecs == RT_TQINF)
(void) printf(" RT_TQINF");
else
(void) printf(" %11lld",
rt_tqnsecs / 1000000);
} else {
error = 1;
/*
* Process from some class other than real time.
* 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 real time"
" parameters\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 RT_KEYCNT = 4 (key, value) pairs.
*/
static int
{
}
/*
* (if they aren't already real time) and set their real-time priority,
* real-time quantum and real-time quantum signal to those specified by
*/
static int
{
char idtypnm[PC_IDTYPNMSZ];
int i;
int error = 0;
/*
* Get the real time class ID and max configured RT priority.
*/
fatalerr("%s: Can't get RT class ID, priocntl system call"
/*
* Validate the rtpri and res arguments.
*/
fatalerr("%s: Specified real time priority %d out of"
}
}
*argsp = 0;
"Permissions error encountered"
" on one or more processes.\n");
error = 1;
} else {
fatalerr("%s: Can't reset real time parameters"
"\npriocntl system call failed with"
}
}
} else if (idargc == 0) {
args) == -1) {
" encountered on current %s.\n", idtypnm);
error = 1;
} else {
fatalerr("%s: Can't reset real time parameters"
"\npriocntl system call failed with"
}
}
} 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 real time"
" parameters\npriocntl system call"
" failed with errno %d\n",
}
}
}
}
return (error);
}
/*
* Execute the command pointed to by cmdargv as a real-time process
*/
static void
int rtqsig)
{
/*
* Get the real time class ID and max configured RT priority.
*/
fatalerr("%s: Can't get RT class ID, priocntl system call"
fatalerr("%s: Specified real time priority %d out of"
}
}
*argsp = 0;
fatalerr("%s: Can't reset real time parameters\n"
"priocntl system call failed with errno %d\n",
fatalerr("%s: Can't execute %s, exec failed with errno %d\n",
}