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

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/syscall_reboot.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 <errno.h>
 
13
#include <sys/types.h>
 
14
#include <sys/reboot.h>
 
15
#include <string.h>
 
16
 
 
17
int main(int argc, char *argv[])
 
18
{
 
19
        int cmd = RB_ENABLE_CAD;
 
20
        
 
21
        if (argc != 2) {
 
22
                fprintf(stderr, "Usage %s [on|off|reboot]\n", argv[0]);
 
23
                return 1;
 
24
        }
 
25
 
 
26
        if (strcmp(argv[1], "off") == 0) 
 
27
                cmd = RB_DISABLE_CAD;
 
28
        else if (strcmp(argv[1], "on") == 0) 
 
29
                /* dangerous, a CAD will do a forced reboot (no shutdown) */
 
30
                cmd = RB_ENABLE_CAD;
 
31
        else if (strcmp(argv[1], "reboot") == 0) 
 
32
                /* Aiieee, you could lose data if you do this */
 
33
                cmd = RB_AUTOBOOT;
 
34
        else {
 
35
                fprintf(stderr, "Usage %s [on|off|reboot]\n", argv[0]);
 
36
                return 1;
 
37
        }
 
38
                
 
39
        if (reboot(cmd) == -1){
 
40
                fprintf(stderr, "FAIL: reboot failed - %s\n",
 
41
                        strerror(errno));
 
42
                return 1;
 
43
        }
 
44
 
 
45
        printf("PASS\n");
 
46
 
 
47
        return 0;
 
48
}