~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/syscall_sysctl.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Copyright (C) 2002-2005 Novell/SUSE
 
3
 *
 
4
 *      This program is free software; you can redistribute it and/or
 
5
 *      modify it under the terms of the GNU General Public License as
 
6
 *      published by the Free Software Foundation, version 2 of the
 
7
 *      License.
 
8
 */
 
9
 
 
10
#include <stdio.h>
 
11
#include <unistd.h>
 
12
#include <sys/sysctl.h>
 
13
#include <errno.h>
 
14
#include <sys/types.h>
 
15
#include <sys/stat.h>
 
16
#include <string.h>
 
17
 
 
18
#define BUFSIZE 4096
 
19
int main(int argc, char *argv[])
 
20
{
 
21
        int save_max_threads, new_max_threads, read_new_max_threads;
 
22
        size_t save_sz = sizeof(save_max_threads);
 
23
        int name[] = {CTL_KERN, KERN_MAX_THREADS};
 
24
        int readonly = 0;
 
25
        
 
26
        if ((argc > 1) && strcmp(argv[1],"ro") == 0) 
 
27
                readonly = 1;
 
28
 
 
29
        if (sysctl(name, sizeof(name), &save_max_threads, &save_sz, NULL, 0) == -1){
 
30
                fprintf(stderr, "FAIL: sysctl read failed - %s\n",
 
31
                        strerror(errno));
 
32
                return 1;
 
33
        }
 
34
 
 
35
        /* printf("Kernel max threads (saved) is %d\n", save_max_threads); */
 
36
 
 
37
        if (readonly) {
 
38
                printf ("PASS\n");
 
39
                return 0;
 
40
        }
 
41
 
 
42
        new_max_threads = save_max_threads + 1024;
 
43
 
 
44
        if (sysctl(name, sizeof(name), NULL, 0, &new_max_threads, save_sz) == -1){
 
45
                fprintf(stderr, "FAIL: sysctl write failed - %s\n",
 
46
                        strerror(errno));
 
47
                return 1;
 
48
        }
 
49
 
 
50
        if (sysctl(name, sizeof(name), &read_new_max_threads, &save_sz, NULL, 0) == -1){
 
51
                fprintf(stderr, "FAIL: sysctl read failed - %s\n",
 
52
                        strerror(errno));
 
53
                return 1;
 
54
        }
 
55
 
 
56
        /* printf("Kernel max threads (new) is %d\n", read_new_max_threads); */
 
57
 
 
58
        if (read_new_max_threads != new_max_threads) {
 
59
                fprintf(stderr, "FAIL: read value does not match written values\n");
 
60
                return 1;
 
61
        }
 
62
 
 
63
        if (sysctl(name, sizeof(name), NULL, 0, &save_max_threads, save_sz) == -1){
 
64
                fprintf(stderr, "FAIL: sysctl write failed - %s\n",
 
65
                        strerror(errno));
 
66
                return 1;
 
67
        }
 
68
 
 
69
        if (sysctl(name, sizeof(name), &read_new_max_threads, &save_sz, NULL, 0) == -1){
 
70
                fprintf(stderr, "FAIL: sysctl read failed - %s\n",
 
71
                        strerror(errno));
 
72
                return 1;
 
73
        }
 
74
 
 
75
        /* printf("Kernel max threads (saved) is %d\n", read_new_max_threads);*/
 
76
 
 
77
        if (read_new_max_threads != save_max_threads) {
 
78
                fprintf(stderr, "FAIL: read value does not match written values\n");
 
79
                return 1;
 
80
        }
 
81
 
 
82
        printf("PASS\n");
 
83
 
 
84
        return 0;
 
85
}