/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/resource.h>
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <project.h>
#include <nl_types.h>
#include <locale.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <zone.h>
#include <libzonecfg.h>
static void usage(void);
static int name2id(char *);
#define RENICE_PRIO_ABSOLUTE 0
typedef struct {
int id;
char *name;
} type_t;
{ PRIO_PROCESS, "pid" },
{ PRIO_PGRP, "pgid" },
{ PRIO_USER, "uid" },
{ PRIO_USER, "user" },
{ PRIO_TASK, "taskid" },
{ PRIO_PROJECT, "projid" },
{ PRIO_PROJECT, "project" },
{ PRIO_GROUP, "gid" },
{ PRIO_GROUP, "group" },
{ PRIO_SESSION, "sid" },
{ PRIO_ZONE, "zone" },
{ PRIO_ZONE, "zoneid" },
{ PRIO_CONTRACT, "ctid" },
{ 0, NULL }
};
/*
* Change the priority (nice) of processes
* or groups of processes which are already
* running.
*/
int
{
int c;
int optflag = 0;
int errs = 0;
char *end_ptr;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
if (argc < 2)
(void) usage();
/*
* There is ambiguity in the renice options spec.
* If argv[1] is in the valid range of priority values then
* treat it as a priority. Otherwise, treat it as a pid.
*/
argc--; /* renice pid ... */
argv++;
} else { /* renice priority ... */
}
} else { /* renice [-n increment] [-g|-p|-u] ID ... */
switch (c) {
case 'n':
if (*end_ptr != '\0')
usage();
break;
case 'g':
optflag++;
break;
case 'p':
optflag++;
break;
case 'u':
optflag++;
break;
case 'i':
optflag++;
break;
default:
usage();
}
}
usage();
}
/* if a zone id, make sure it is valid */
*argv);
continue;
}
}
switch (which) {
case PRIO_USER:
*argv);
} else {
gettext("renice: unknown user: %s\n"),
*argv);
errs++;
}
break;
case PRIO_GROUP:
*argv);
} else {
gettext("renice: unknown group: %s\n"),
*argv);
errs++;
}
break;
case PRIO_PROJECT:
*argv);
} else {
gettext("renice: unknown project: %s\n"),
*argv);
errs++;
}
break;
case PRIO_ZONE:
gettext("renice: unknown zone: %s\n"),
*argv);
errs++;
break;
}
break;
default:
/*
* In all other cases it is invalid id or name
*/
errs++;
}
}
return (errs != 0);
}
static int
{
int prio;
int errs = 0;
char *end_ptr;
argc--;
argv++;
if (argc < 2) {
usage();
}
if (*end_ptr != '\0') {
usage();
}
if (prio == 20) {
gettext("renice: nice value 20 rounded down to 19\n"));
}
argc--;
argv++;
continue;
}
continue;
}
continue;
}
gettext("renice: unknown user: %s\n"),
*argv);
errs++;
continue;
}
} else {
errs++;
continue;
}
}
}
return (errs != 0);
}
static int
{
int oldprio;
perror("getpriority");
return (1);
}
if (increment)
" Cannot lower nice value.\n"));
else
perror("setpriority");
return (1);
}
return (0);
}
static void
usage()
{
gettext("usage: renice [-n increment] [-i idtype] ID ...\n"));
gettext(" renice [-n increment] [-g | -p | -u] ID ...\n"));
gettext(" renice priority "
"[-p] pid ... [-g pgrp ...] [-p pid ...] [-u user ...]\n"));
gettext(" renice priority "
" -g pgrp ... [-g pgrp ...] [-p pid ...] [-u user ...]\n"));
gettext(" renice priority "
" -u user ... [-g pgrp ...] [-p pid ...] [-u user ...]\n"));
exit(2);
}
static int
{
type++;
}
exit(1);
/*NOTREACHED*/
}