Fix incorrect usage of sched_setscheduler() in check_privs()

Fix code in check_privs() that passes NULL as parameter
to sched_setscheduler().

Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Clark Williams <williams@redhat.com>
This commit is contained in:
Clark Williams 2010-02-15 12:58:32 -06:00
parent 398445bc37
commit 527835d963
1 changed files with 9 additions and 4 deletions

View File

@ -53,7 +53,7 @@ char *get_debugfileprefix(void)
int check_privs(void)
{
int policy = sched_getscheduler(0);
struct sched_param param;
struct sched_param param, old_param;
/* if we're already running a realtime scheduler
* then we *should* be able to change things later
@ -61,6 +61,13 @@ int check_privs(void)
if (policy == SCHED_FIFO || policy == SCHED_RR)
return 0;
/* first get the current parameters */
if (sched_getparam(0, &old_param)) {
fprintf(stderr, "unable to get scheduler parameters\n");
return 1;
}
param = old_param;
/* try to change to SCHED_FIFO */
param.sched_priority = 1;
if (sched_setscheduler(0, SCHED_FIFO, &param)) {
@ -70,9 +77,7 @@ int check_privs(void)
}
/* we're good; change back and return success */
param.sched_priority = 0;
sched_setscheduler(0, policy, NULL);
return 0;
return sched_setscheduler(0, policy, &old_param);
}
void warn(char *fmt, ...)