xref: /illumos-gate/usr/src/uts/common/syscall/nice.c (revision 4de2612967d06c4fdbf524a62556a1e8118a006f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 /*	Copyright (c) 1994 Sun Microsystems, Inc. */
25 
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* from SVr4.0 1.15 */
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/sysmacros.h>
32 #include <sys/systm.h>
33 #include <sys/errno.h>
34 #include <sys/cred.h>
35 #include <sys/proc.h>
36 #include <sys/debug.h>
37 #include <sys/class.h>
38 #include <sys/mutex.h>
39 
40 /*
41  * We support the nice system call for compatibility although
42  * the priocntl system call supports a superset of nice's functionality.
43  * We support nice only for time sharing threads.  It will fail
44  * if called by a thread from another class.
45  */
46 
47 int
48 nice(int niceness)
49 {
50 	int error = 0;
51 	int err, retval;
52 	kthread_id_t t;
53 	proc_t	*p = curproc;
54 
55 	mutex_enter(&p->p_lock);
56 	t = p->p_tlist;
57 	do {
58 		err = CL_DONICE(t, CRED(), niceness, &retval);
59 		if (error == 0 && err)
60 			error = set_errno(err);
61 	} while ((t = t->t_forw) != p->p_tlist);
62 	mutex_exit(&p->p_lock);
63 	if (error)
64 		return (error);
65 	return (retval);
66 }
67