asmlinkage long sys_setpriority(int which, int who, int niceval)
{
	struct task_struct *p;
	int error;

	if (which > 2 || which < 0)
		return -EINVAL;

	/* normalize: avoid signed division (rounding problems) */
	error = -ESRCH;
	if (niceval < -20)
		niceval = -20;
	if (niceval > 19)
		niceval = 19;

	read_lock(&tasklist_lock);
	for_each_task(p) {
		if (!proc_sel(p, which, who))
			continue;
		if (p->uid != current->euid &&
			p->uid != current->uid && !capable(CAP_SYS_NICE)) {
			error = -EPERM;
			continue;
		}
		if (error == -ESRCH)
			error = 0;
		if (niceval < p->nice && !capable(CAP_SYS_NICE))
			error = -EACCES;
		else
			p->nice = niceval;
	}
	read_unlock(&tasklist_lock);

	return error;
}
Exemple #2
0
asmlinkage int sys_setpriority(int which, int who, int niceval)
{
	struct task_struct **p;
	int error = ESRCH;
	int priority;

	if (which > 2 || which < 0)
		return -EINVAL;

	if ((priority = PZERO - niceval) <= 0)
		priority = 1;

	for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
		if (!*p || !proc_sel(*p, which, who))
			continue;
		if ((*p)->uid != current->euid &&
			(*p)->uid != current->uid && !suser()) {
			error = EPERM;
			continue;
		}
		if (error == ESRCH)
			error = 0;
		if (priority > (*p)->priority && !suser())
			error = EACCES;
		else
			(*p)->priority = priority;
	}
	return -error;
}
Exemple #3
0
asmlinkage int sys_getpriority(int which, int who)
{
	struct task_struct **p;
	int max_prio = 0;

	if (which > 2 || which < 0)
		return -EINVAL;

	for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
		if (!*p || !proc_sel(*p, which, who))
			continue;
		if ((*p)->priority > max_prio)
			max_prio = (*p)->priority;
	}
	return(max_prio ? max_prio : -ESRCH);
}
Exemple #4
0
/*
 * Ugh. To avoid negative return values, "getpriority()" will
 * not return the normal nice-value, but a value that has been
 * offset by 20 (ie it returns 0..40 instead of -20..20)
 */
asmlinkage int sys_getpriority(int which, int who)
{
    struct task_struct *p;
    long max_prio = -ESRCH;

    if (which > 2 || which < 0)
        return -EINVAL;

    for_each_task (p) {
        if (!proc_sel(p, which, who))
            continue;
        if (p->priority > max_prio)
            max_prio = p->priority;
    }

    /* scale the priority from timeslice to 0..40 */
    if (max_prio > 0)
        max_prio = (max_prio * 20 + DEF_PRIORITY/2) / DEF_PRIORITY;
    return max_prio;
}
/*
 * Ugh. To avoid negative return values, "getpriority()" will
 * not return the normal nice-value, but a negated value that
 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
 * to stay compatible.
 */
asmlinkage long sys_getpriority(int which, int who)
{
	struct task_struct *p;
	long retval = -ESRCH;

	if (which > 2 || which < 0)
		return -EINVAL;

	read_lock(&tasklist_lock);
	for_each_task (p) {
		long niceval;
		if (!proc_sel(p, which, who))
			continue;
		niceval = 20 - p->nice;
		if (niceval > retval)
			retval = niceval;
	}
	read_unlock(&tasklist_lock);

	return retval;
}
Exemple #6
0
asmlinkage int sys_setpriority(int which, int who, int niceval)
{
    struct task_struct *p;
    int error = ESRCH;
    unsigned int priority;

    if (which > 2 || which < 0)
        return -EINVAL;

    /* normalize: avoid signed division (rounding problems) */
    priority = niceval;
    if (niceval < 0)
        priority = -niceval;
    if (priority > 20)
        priority = 20;
    priority = (priority * DEF_PRIORITY + 10) / 20 + DEF_PRIORITY;

    if (niceval >= 0) {
        priority = 2*DEF_PRIORITY - priority;
        if (!priority)
            priority = 1;
    }

    for_each_task(p) {
        if (!proc_sel(p, which, who))
            continue;
        if (p->uid != current->euid &&
                p->uid != current->uid && !suser()) {
            error = EPERM;
            continue;
        }
        if (error == ESRCH)
            error = 0;
        if (priority > p->priority && !suser())
            error = EACCES;
        else
            p->priority = priority;
    }
    return -error;
}