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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/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
 
/* $Id: syscall_sysctl.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
 
#include <stdio.h>
13
 
#include <unistd.h>
14
 
#include <sys/sysctl.h>
15
 
#include <errno.h>
16
 
#include <sys/types.h>
17
 
#include <sys/stat.h>
18
 
#include <string.h>
19
 
 
20
 
#define BUFSIZE 4096
21
 
int main(int argc, char *argv[])
22
 
{
23
 
        int save_max_threads, new_max_threads, read_new_max_threads;
24
 
        size_t save_sz = sizeof(save_max_threads);
25
 
        int name[] = {CTL_KERN, KERN_MAX_THREADS};
26
 
        int readonly = 0;
27
 
        
28
 
        if ((argc > 1) && strcmp(argv[1],"ro") == 0) 
29
 
                readonly = 1;
30
 
 
31
 
        if (sysctl(name, sizeof(name), &save_max_threads, &save_sz, NULL, 0) == -1){
32
 
                fprintf(stderr, "FAIL: sysctl read failed - %s\n",
33
 
                        strerror(errno));
34
 
                return 1;
35
 
        }
36
 
 
37
 
        /* printf("Kernel max threads (saved) is %d\n", save_max_threads); */
38
 
 
39
 
        if (readonly) {
40
 
                printf ("PASS\n");
41
 
                return 0;
42
 
        }
43
 
 
44
 
        new_max_threads = save_max_threads + 1024;
45
 
 
46
 
        if (sysctl(name, sizeof(name), NULL, 0, &new_max_threads, save_sz) == -1){
47
 
                fprintf(stderr, "FAIL: sysctl write failed - %s\n",
48
 
                        strerror(errno));
49
 
                return 1;
50
 
        }
51
 
 
52
 
        if (sysctl(name, sizeof(name), &read_new_max_threads, &save_sz, NULL, 0) == -1){
53
 
                fprintf(stderr, "FAIL: sysctl read failed - %s\n",
54
 
                        strerror(errno));
55
 
                return 1;
56
 
        }
57
 
 
58
 
        /* printf("Kernel max threads (new) is %d\n", read_new_max_threads); */
59
 
 
60
 
        if (read_new_max_threads != new_max_threads) {
61
 
                fprintf(stderr, "FAIL: read value does not match written values\n");
62
 
                return 1;
63
 
        }
64
 
 
65
 
        if (sysctl(name, sizeof(name), NULL, 0, &save_max_threads, save_sz) == -1){
66
 
                fprintf(stderr, "FAIL: sysctl write failed - %s\n",
67
 
                        strerror(errno));
68
 
                return 1;
69
 
        }
70
 
 
71
 
        if (sysctl(name, sizeof(name), &read_new_max_threads, &save_sz, NULL, 0) == -1){
72
 
                fprintf(stderr, "FAIL: sysctl read failed - %s\n",
73
 
                        strerror(errno));
74
 
                return 1;
75
 
        }
76
 
 
77
 
        /* printf("Kernel max threads (saved) is %d\n", read_new_max_threads);*/
78
 
 
79
 
        if (read_new_max_threads != save_max_threads) {
80
 
                fprintf(stderr, "FAIL: read value does not match written values\n");
81
 
                return 1;
82
 
        }
83
 
 
84
 
        printf("PASS\n");
85
 
 
86
 
        return 0;
87
 
}