~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/syscall_setscheduler.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: syscall_setscheduler.c 61 2006-05-19 18:32:14Z steve-beattie $ */
 
2
 
 
3
/*
 
4
 *      Copyright (C) 2002-2005 Novell/SUSE
 
5
 *
 
6
 *      This program is free software; you can redistribute it and/or
 
7
 *      modify it under the terms of the GNU General Public License as
 
8
 *      published by the Free Software Foundation, version 2 of the
 
9
 *      License.
 
10
 */
 
11
 
 
12
/* test whether the sched_setscheduler(2) syscall is allowed. */
 
13
 
 
14
#include <stdlib.h>
 
15
#include <stdio.h>
 
16
#include <string.h>
 
17
#include <errno.h>
 
18
#include <sched.h>
 
19
 
 
20
int
 
21
main (int argc, char * argv[]) {
 
22
        struct sched_param sp, saved_sp, new_sp;
 
23
        int saved_sched_policy, new_sched_policy;
 
24
 
 
25
        /* save the default policy and priority */
 
26
        memset(&saved_sp, 0, sizeof(saved_sp));
 
27
        saved_sched_policy = sched_getscheduler(0);
 
28
        if (saved_sched_policy < 0) {
 
29
                perror ("FAIL: Couldn't get scheduler policy\n");
 
30
                saved_sched_policy = SCHED_OTHER;
 
31
                return errno;
 
32
        }
 
33
        saved_sp.sched_priority = sched_get_priority_max(saved_sched_policy);
 
34
 
 
35
        memset(&sp, 0, sizeof(sp));
 
36
        sp.sched_priority = sched_get_priority_max(SCHED_RR) - 1;
 
37
        if (sched_setscheduler(0, SCHED_RR, &sp)) {
 
38
                perror("FAIL: Can't set SCHED_RR");
 
39
                return errno;
 
40
        }
 
41
 
 
42
        memset(&new_sp, 0, sizeof(new_sp));
 
43
        new_sched_policy = sched_getscheduler(0);
 
44
        if (new_sched_policy != SCHED_RR) {
 
45
                fprintf (stderr, "FAIL: set policy is %d, not SCHED_RR\n",
 
46
                        new_sched_policy);
 
47
                return 1;
 
48
        }
 
49
 
 
50
        printf ("PASS\n");
 
51
 
 
52
        return 0;
 
53
}