diff options
author | Clark Williams <williams@redhat.com> | 2010-02-15 12:58:32 -0600 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2010-02-15 12:58:32 -0600 |
commit | 527835d9636163596eedf1e8cdd6ed3fad0fbecc (patch) | |
tree | 310fcc315f1efea0f207e16a43fb62731da73dc1 | |
parent | 398445bc3705b702238f711f73c58cff364c7153 (diff) | |
download | rt-tests-527835d9636163596eedf1e8cdd6ed3fad0fbecc.tar.gz |
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>
-rw-r--r-- | src/lib/rt-utils.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index b5a77de..da27a3a 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -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, ¶m)) { @@ -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, ...) |